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()))
|
||||
|
||||
def update_color(self, obj, constant, color_hex_label):
|
||||
color = obj.get_color()
|
||||
hexval = "#%02x%02x%02x" % (color.red/256,
|
||||
color.green/256,
|
||||
color.blue/256)
|
||||
rgba = obj.get_rgba()
|
||||
hexval = "#%02x%02x%02x" % (int(rgba.red * 255),
|
||||
int(rgba.green * 255),
|
||||
int(rgba.blue * 255))
|
||||
color_hex_label.set_text(hexval)
|
||||
self.__config.set(constant, hexval)
|
||||
|
||||
|
@ -231,8 +231,10 @@ class GuiColorOption(Gtk.ColorButton):
|
||||
def __init__(self, option, dbstate, uistate, track, override):
|
||||
self.__option = option
|
||||
value = self.__option.get_value()
|
||||
GObject.GObject.__init__(self)
|
||||
self.set_color(Gdk.color_parse(self.__option.get_value()))
|
||||
Gtk.ColorButton.__init__(self)
|
||||
rgba = Gdk.RGBA()
|
||||
rgba.parse(self.__option.get_value())
|
||||
self.set_rgba(rgba)
|
||||
|
||||
# Set up signal handlers when the widget value is changed
|
||||
# from user interaction or programmatically. When handling
|
||||
@ -247,11 +249,10 @@ class GuiColorOption(Gtk.ColorButton):
|
||||
"""
|
||||
Handle the change of color made by the user.
|
||||
"""
|
||||
colour = self.get_color()
|
||||
value = '#%02x%02x%02x' % (
|
||||
int(colour.red * 256 / 65536),
|
||||
int(colour.green * 256 / 65536),
|
||||
int(colour.blue * 256 / 65536))
|
||||
rgba = self.get_rgba()
|
||||
value = '#%02x%02x%02x' % (int(rgba.red * 255),
|
||||
int(rgba.green * 255),
|
||||
int(rgba.blue * 255))
|
||||
|
||||
self.__option.disable_signals()
|
||||
self.__option.set_value(value)
|
||||
@ -262,7 +263,9 @@ class GuiColorOption(Gtk.ColorButton):
|
||||
Handle the change made programmatically
|
||||
"""
|
||||
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)
|
||||
|
||||
def clean_up(self):
|
||||
@ -1520,20 +1523,19 @@ class GuiSurnameColorOption(Gtk.Box):
|
||||
# get the surname and colour value for this family
|
||||
i = self.__model.get_iter(path)
|
||||
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
|
||||
colour_dialog = Gtk.ColorSelectionDialog(title)
|
||||
colorsel = colour_dialog.get_color_selection()
|
||||
colorsel.set_current_color(colour)
|
||||
colour_dialog = Gtk.ColorChooserDialog(title)
|
||||
colour_dialog.set_rgba(rgba)
|
||||
response = colour_dialog.run()
|
||||
|
||||
if response == Gtk.ResponseType.OK:
|
||||
colour = colorsel.get_current_color()
|
||||
colour_name = '#%02x%02x%02x' % (
|
||||
int(colour.red *256/65536),
|
||||
int(colour.green*256/65536),
|
||||
int(colour.blue *256/65536))
|
||||
rgba = colour_dialog.get_rgba()
|
||||
colour_name = '#%02x%02x%02x' % (int(rgba.red * 255),
|
||||
int(rgba.green * 255),
|
||||
int(rgba.blue * 255))
|
||||
self.__model.set_value(i, 1, colour_name)
|
||||
|
||||
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))
|
||||
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):
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
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():
|
||||
ErrorDialog(
|
||||
@ -594,7 +598,9 @@ class EditTag(object):
|
||||
self.entry = Gtk.Entry()
|
||||
self.entry.set_text(self.tag.get_name())
|
||||
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")}
|
||||
self.color.set_title(title)
|
||||
hbox.pack_start(label, False, False, 5)
|
||||
|
@ -60,7 +60,7 @@ from .toolcomboentry import ToolComboEntry
|
||||
from .springseparator import SpringSeparatorAction
|
||||
from ..spell import Spell
|
||||
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.constfunc import has_display
|
||||
|
||||
@ -653,21 +653,23 @@ class StyledTextEditor(Gtk.TextView):
|
||||
current_value = self.textbuffer.get_style_at_cursor(style)
|
||||
|
||||
if style == StyledTextTagType.FONTCOLOR:
|
||||
color_dialog = Gtk.ColorSelectionDialog(_("Select font color"))
|
||||
color_dialog = Gtk.ColorChooserDialog(_("Select font color"))
|
||||
elif style == StyledTextTagType.HIGHLIGHT:
|
||||
color_dialog = Gtk.ColorSelectionDialog(_("Select "
|
||||
"background color"))
|
||||
color_dialog = Gtk.ColorChooserDialog(_("Select background color"))
|
||||
else:
|
||||
_LOG.debug("unknown style: '%d'" % style)
|
||||
return
|
||||
|
||||
color_selection = color_dialog.get_color_selection()
|
||||
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()
|
||||
color = color_selection.get_current_color()
|
||||
value = color_to_hex(color)
|
||||
rgba = color_dialog.get_rgba()
|
||||
value = '#%02x%02x%02x' % (int(rgba.red * 255),
|
||||
int(rgba.green * 255),
|
||||
int(rgba.blue * 255))
|
||||
color_dialog.destroy()
|
||||
|
||||
if response == Gtk.ResponseType.OK:
|
||||
|
Loading…
Reference in New Issue
Block a user