Convert deprecated color widgets
This commit is contained in:
parent
e80445127f
commit
f540f2a511
@ -251,10 +251,10 @@ class ConfigureDialog(ManagedWindow):
|
|||||||
self.__config.set(constant, conv_to_unicode(obj.get_text()))
|
self.__config.set(constant, conv_to_unicode(obj.get_text()))
|
||||||
|
|
||||||
def update_color(self, obj, constant, color_hex_label):
|
def update_color(self, obj, constant, color_hex_label):
|
||||||
color = obj.get_color()
|
rgba = obj.get_rgba()
|
||||||
hexval = "#%02x%02x%02x" % (color.red/256,
|
hexval = "#%02x%02x%02x" % (int(rgba.red * 255),
|
||||||
color.green/256,
|
int(rgba.green * 255),
|
||||||
color.blue/256)
|
int(rgba.blue * 255))
|
||||||
color_hex_label.set_text(hexval)
|
color_hex_label.set_text(hexval)
|
||||||
self.__config.set(constant, hexval)
|
self.__config.set(constant, hexval)
|
||||||
|
|
||||||
|
@ -231,8 +231,10 @@ class GuiColorOption(Gtk.ColorButton):
|
|||||||
def __init__(self, option, dbstate, uistate, track, override):
|
def __init__(self, option, dbstate, uistate, track, override):
|
||||||
self.__option = option
|
self.__option = option
|
||||||
value = self.__option.get_value()
|
value = self.__option.get_value()
|
||||||
GObject.GObject.__init__(self)
|
Gtk.ColorButton.__init__(self)
|
||||||
self.set_color(Gdk.color_parse(self.__option.get_value()))
|
rgba = Gdk.RGBA()
|
||||||
|
rgba.parse(self.__option.get_value())
|
||||||
|
self.set_rgba(rgba)
|
||||||
|
|
||||||
# Set up signal handlers when the widget value is changed
|
# Set up signal handlers when the widget value is changed
|
||||||
# from user interaction or programmatically. When handling
|
# from user interaction or programmatically. When handling
|
||||||
@ -247,11 +249,10 @@ class GuiColorOption(Gtk.ColorButton):
|
|||||||
"""
|
"""
|
||||||
Handle the change of color made by the user.
|
Handle the change of color made by the user.
|
||||||
"""
|
"""
|
||||||
colour = self.get_color()
|
rgba = self.get_rgba()
|
||||||
value = '#%02x%02x%02x' % (
|
value = '#%02x%02x%02x' % (int(rgba.red * 255),
|
||||||
int(colour.red * 256 / 65536),
|
int(rgba.green * 255),
|
||||||
int(colour.green * 256 / 65536),
|
int(rgba.blue * 255))
|
||||||
int(colour.blue * 256 / 65536))
|
|
||||||
|
|
||||||
self.__option.disable_signals()
|
self.__option.disable_signals()
|
||||||
self.__option.set_value(value)
|
self.__option.set_value(value)
|
||||||
@ -262,7 +263,9 @@ class GuiColorOption(Gtk.ColorButton):
|
|||||||
Handle the change made programmatically
|
Handle the change made programmatically
|
||||||
"""
|
"""
|
||||||
self.handler_block(self.changekey)
|
self.handler_block(self.changekey)
|
||||||
self.set_color(Gdk.color_parse(self.__option.get_value()))
|
rgba = Gdk.RGBA()
|
||||||
|
rgba.parse(self.__option.get_value())
|
||||||
|
self.set_rgba(rgba)
|
||||||
self.handler_unblock(self.changekey)
|
self.handler_unblock(self.changekey)
|
||||||
|
|
||||||
def clean_up(self):
|
def clean_up(self):
|
||||||
@ -1520,20 +1523,19 @@ class GuiSurnameColorOption(Gtk.Box):
|
|||||||
# get the surname and colour value for this family
|
# get the surname and colour value for this family
|
||||||
i = self.__model.get_iter(path)
|
i = self.__model.get_iter(path)
|
||||||
surname = self.__model.get_value(i, 0)
|
surname = self.__model.get_value(i, 0)
|
||||||
colour = Gdk.color_parse(self.__model.get_value(i, 1))
|
rgba = Gdk.RGBA()
|
||||||
|
rgba.parse(self.__model.get_value(i, 1))
|
||||||
|
|
||||||
title = _('Select color for %s') % surname
|
title = _('Select color for %s') % surname
|
||||||
colour_dialog = Gtk.ColorSelectionDialog(title)
|
colour_dialog = Gtk.ColorChooserDialog(title)
|
||||||
colorsel = colour_dialog.get_color_selection()
|
colour_dialog.set_rgba(rgba)
|
||||||
colorsel.set_current_color(colour)
|
|
||||||
response = colour_dialog.run()
|
response = colour_dialog.run()
|
||||||
|
|
||||||
if response == Gtk.ResponseType.OK:
|
if response == Gtk.ResponseType.OK:
|
||||||
colour = colorsel.get_current_color()
|
rgba = colour_dialog.get_rgba()
|
||||||
colour_name = '#%02x%02x%02x' % (
|
colour_name = '#%02x%02x%02x' % (int(rgba.red * 255),
|
||||||
int(colour.red *256/65536),
|
int(rgba.green * 255),
|
||||||
int(colour.green*256/65536),
|
int(rgba.blue * 255))
|
||||||
int(colour.blue *256/65536))
|
|
||||||
self.__model.set_value(i, 1, colour_name)
|
self.__model.set_value(i, 1, colour_name)
|
||||||
|
|
||||||
colour_dialog.destroy()
|
colour_dialog.destroy()
|
||||||
|
@ -540,22 +540,6 @@ def rgb_to_hex(rgb):
|
|||||||
rgbint = (int(rgb[0] * 255), int(rgb[1] * 255), int(rgb[2] * 255))
|
rgbint = (int(rgb[0] * 255), int(rgb[1] * 255), int(rgb[2] * 255))
|
||||||
return '#%02x%02x%02x' % rgbint
|
return '#%02x%02x%02x' % rgbint
|
||||||
|
|
||||||
def color_to_hex(color):
|
|
||||||
"""Convert Gdk.Color to hex string."""
|
|
||||||
hexstring = ""
|
|
||||||
for col in 'red', 'green', 'blue':
|
|
||||||
hexfrag = hex(getattr(color, col) // (16 * 16)).split("x")[1]
|
|
||||||
if len(hexfrag) < 2:
|
|
||||||
hexfrag = "0" + hexfrag
|
|
||||||
hexstring += hexfrag
|
|
||||||
return '#' + hexstring
|
|
||||||
|
|
||||||
def hex_to_color(hex):
|
|
||||||
"""Convert hex string to Gdk.Color."""
|
|
||||||
from gi.repository import Gdk
|
|
||||||
color = Gdk.color_parse(hex)
|
|
||||||
return color
|
|
||||||
|
|
||||||
def edit_object(dbstate, uistate, reftype, ref):
|
def edit_object(dbstate, uistate, reftype, ref):
|
||||||
"""
|
"""
|
||||||
Invokes the appropriate editor for an object type and given handle.
|
Invokes the appropriate editor for an object type and given handle.
|
||||||
|
@ -553,7 +553,11 @@ class EditTag(object):
|
|||||||
Save the changes made to the tag.
|
Save the changes made to the tag.
|
||||||
"""
|
"""
|
||||||
self.tag.set_name(cuni(self.entry.get_text()))
|
self.tag.set_name(cuni(self.entry.get_text()))
|
||||||
self.tag.set_color(self.color.get_color().to_string())
|
rgba = self.color.get_rgba()
|
||||||
|
hexval = "#%02x%02x%02x" % (int(rgba.red * 255),
|
||||||
|
int(rgba.green * 255),
|
||||||
|
int(rgba.blue * 255))
|
||||||
|
self.tag.set_color(hexval)
|
||||||
|
|
||||||
if not self.tag.get_name():
|
if not self.tag.get_name():
|
||||||
ErrorDialog(
|
ErrorDialog(
|
||||||
@ -594,7 +598,9 @@ class EditTag(object):
|
|||||||
self.entry = Gtk.Entry()
|
self.entry = Gtk.Entry()
|
||||||
self.entry.set_text(self.tag.get_name())
|
self.entry.set_text(self.tag.get_name())
|
||||||
self.color = Gtk.ColorButton()
|
self.color = Gtk.ColorButton()
|
||||||
self.color.set_color(Gdk.color_parse(self.tag.get_color()))
|
rgba = Gdk.RGBA()
|
||||||
|
rgba.parse(self.tag.get_color())
|
||||||
|
self.color.set_rgba(rgba)
|
||||||
title = _("%(title)s - Gramps") % {'title': _("Pick a Color")}
|
title = _("%(title)s - Gramps") % {'title': _("Pick a Color")}
|
||||||
self.color.set_title(title)
|
self.color.set_title(title)
|
||||||
hbox.pack_start(label, False, False, 5)
|
hbox.pack_start(label, False, False, 5)
|
||||||
|
@ -60,7 +60,7 @@ from .toolcomboentry import ToolComboEntry
|
|||||||
from .springseparator import SpringSeparatorAction
|
from .springseparator import SpringSeparatorAction
|
||||||
from ..spell import Spell
|
from ..spell import Spell
|
||||||
from ..display import display_url
|
from ..display import display_url
|
||||||
from ..utils import SystemFonts, rgb_to_hex, hex_to_color, color_to_hex
|
from ..utils import SystemFonts, rgb_to_hex
|
||||||
from gramps.gen.config import config
|
from gramps.gen.config import config
|
||||||
from gramps.gen.constfunc import has_display
|
from gramps.gen.constfunc import has_display
|
||||||
|
|
||||||
@ -653,21 +653,23 @@ class StyledTextEditor(Gtk.TextView):
|
|||||||
current_value = self.textbuffer.get_style_at_cursor(style)
|
current_value = self.textbuffer.get_style_at_cursor(style)
|
||||||
|
|
||||||
if style == StyledTextTagType.FONTCOLOR:
|
if style == StyledTextTagType.FONTCOLOR:
|
||||||
color_dialog = Gtk.ColorSelectionDialog(_("Select font color"))
|
color_dialog = Gtk.ColorChooserDialog(_("Select font color"))
|
||||||
elif style == StyledTextTagType.HIGHLIGHT:
|
elif style == StyledTextTagType.HIGHLIGHT:
|
||||||
color_dialog = Gtk.ColorSelectionDialog(_("Select "
|
color_dialog = Gtk.ColorChooserDialog(_("Select background color"))
|
||||||
"background color"))
|
|
||||||
else:
|
else:
|
||||||
_LOG.debug("unknown style: '%d'" % style)
|
_LOG.debug("unknown style: '%d'" % style)
|
||||||
return
|
return
|
||||||
|
|
||||||
color_selection = color_dialog.get_color_selection()
|
|
||||||
if current_value:
|
if current_value:
|
||||||
color_selection.set_current_color(hex_to_color(current_value))
|
rgba = Gdk.RGBA()
|
||||||
|
rgba.parse(current_value)
|
||||||
|
color_dialog.set_rgba(rgba)
|
||||||
|
|
||||||
response = color_dialog.run()
|
response = color_dialog.run()
|
||||||
color = color_selection.get_current_color()
|
rgba = color_dialog.get_rgba()
|
||||||
value = color_to_hex(color)
|
value = '#%02x%02x%02x' % (int(rgba.red * 255),
|
||||||
|
int(rgba.green * 255),
|
||||||
|
int(rgba.blue * 255))
|
||||||
color_dialog.destroy()
|
color_dialog.destroy()
|
||||||
|
|
||||||
if response == Gtk.ResponseType.OK:
|
if response == Gtk.ResponseType.OK:
|
||||||
|
Loading…
Reference in New Issue
Block a user