Replace ColorSelectionDialog by ColorChooserDialog

The former is deprecated and use Gtk.Color while we need Gdk.RGBA.

issue8231
review259261002
This commit is contained in:
Cédric Krier committed 2019-04-02 17:57:05 +02:00
1 parent 13dd7a7738
commit 4f87999c42
3 files changed
+15 -11

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
* Replace ColorSelectionDialog by ColorChooserDialog
* Support HTML widget
* Use locale format for data import and export
* Add day view on calendar
+1 -1
View File
@@ -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:
@@ -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)