From 4f87999c42c52d4a99b2bef4db104f597ed0ab47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 2 Apr 2019 17:57:05 +0200 Subject: [PATCH] Replace ColorSelectionDialog by ColorChooserDialog The former is deprecated and use Gtk.Color while we need Gdk.RGBA. issue8231 review259261002 --- CHANGELOG | 1 + tryton/common/htmltextbuffer.py | 2 +- .../view_form/view/form_gtk/richtextbox.py | 23 +++++++++++-------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 7fa2d642a8..41dbf6eaf3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Replace ColorSelectionDialog by ColorChooserDialog * Support HTML widget * Use locale format for data import and export * Add day view on calendar diff --git a/tryton/common/htmltextbuffer.py b/tryton/common/htmltextbuffer.py index 391e2fc182..44344d9308 100644 --- a/tryton/common/htmltextbuffer.py +++ b/tryton/common/htmltextbuffer.py @@ -313,7 +313,7 @@ _TAGS.extend([('justification %s' % align, {'justification': justification}) def register_foreground(text_buffer, color): - name = 'foreground %s' % color + name = 'foreground %s' % color.to_string() tag_table = text_buffer.get_tag_table() tag = tag_table.lookup(name) if not tag: diff --git a/tryton/gui/window/view_form/view/form_gtk/richtextbox.py b/tryton/gui/window/view_form/view/form_gtk/richtextbox.py index a480b6583a..39ae47a418 100644 --- a/tryton/gui/window/view_form/view/form_gtk/richtextbox.py +++ b/tryton/gui/window/view_form/view/form_gtk/richtextbox.py @@ -3,7 +3,7 @@ from gettext import gettext as _ from weakref import WeakKeyDictionary -from gi.repository import Gtk +from gi.repository import Gtk, Gdk from .textbox import TextBox from tryton.common import get_toplevel_window, IconFactory @@ -207,6 +207,7 @@ class RichTextBox(TextBox): bolds, italics, underlines = set(), set(), set() families, sizes, justifications = set(), set(), set() + self.colors['foreground'] = 'black' iter_ = start.copy() while True: @@ -232,6 +233,8 @@ class RichTextBox(TextBox): size = SIZES.index(size) elif tag.props.name.startswith('justification'): _, justification = tag.props.name.split() + elif tag.props.name.startswith('foreground'): + _, self.colors['foreground'] = tag.props.name.split() bolds.add(bold) italics.add(italic) underlines.add(underline) @@ -324,16 +327,16 @@ class RichTextBox(TextBox): start = start.get_offset() end = end.get_offset() - dialog = Gtk.ColorSelectionDialog(_('Select a color')) - dialog.set_transient_for(get_toplevel_window()) - colorsel = dialog.get_color_selection() - colorsel.set_has_palette(True) - color = self.colors.get(name) - if color: - colorsel.set_current_color(color) + dialog = Gtk.ColorChooserDialog( + title=_('Select a color'), + transient_for=get_toplevel_window(), + use_alpha=False) + color = Gdk.RGBA() + if name in self.colors: + color.parse(self.colors[name]) + dialog.set_rgba(color) if dialog.run() == Gtk.ResponseType.OK: - color = colorsel.get_current_color() - self.colors[name] = color + color = dialog.get_rgba() if start is not None and end is not None: start = text_buffer.get_iter_at_offset(start) end = text_buffer.get_iter_at_offset(end)