From 2738811ffe33b83d14898ff9e2f15b1759600948 Mon Sep 17 00:00:00 2001 From: Cimbali Date: Wed, 20 Dec 2017 09:38:40 +0100 Subject: [PATCH] Avoid deprecated code, fix #48 Up to Gtk 3.22 (excluded), i.e. we use GdkScreen and not GdkDisplay + GdkMonitor --- pympress/talk_time.py | 34 ++++++++++++---------------------- pympress/ui.py | 18 +++++++++--------- pympress/vlcvideo.py | 2 +- 3 files changed, 22 insertions(+), 32 deletions(-) diff --git a/pympress/talk_time.py b/pympress/talk_time.py index 4dc2874a..5f72fefc 100644 --- a/pympress/talk_time.py +++ b/pympress/talk_time.py @@ -31,7 +31,7 @@ import gi gi.require_version('Gtk', '3.0') -from gi.repository import Gtk, Gdk, GObject +from gi.repository import Gtk, Gdk, GLib import time from pympress import editable_label @@ -51,6 +51,9 @@ class TimeLabelColorer(object): #: :class:`~Gdk.RGBA` The default color of the info labels label_color_default = None + #: :class:`~Gtk.CssProvider` affecting the style context of the labels + color_override = None + #: `list` of tuples (`int`, :class:`~Gdk.RGBA`), which are the desired colors at the corresponding timestamps. Sorted on the timestamps. color_map = [] @@ -58,6 +61,8 @@ def __init__(self, label_time): self.label_time = label_time style_context = self.label_time.get_style_context() + self.color_override = Gtk.CssProvider() + style_context.add_provider(self.color_override, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION + 1) self.label_color_default = self.load_color_from_css(style_context) label_color_ett_reached = self.load_color_from_css(style_context, "ett-reached") @@ -98,24 +103,7 @@ def load_color_from_css(self, style_context, class_name = None): def default_color(self): """ Forces to reset the default colors on the label. """ - self.label_time.override_color(Gtk.StateType.NORMAL, self.label_color_default) - - - def calc_color(self, from_color, to_color, position): - """ Compute the interpolation between two colors. - - Args: - from_color (:class:`~Gdk.RGBA`): the color when position = 0 - to_color (:class:`~Gdk.RGBA`): the color when position = 1 - position (`float`): A value between 0 and 1 expressing how far from - - Returns: - :class:`~Gdk.RGBA`: The color that is between from_color and to_color - """ - color_tuple = lambda color: ( color.red, color.green, color.blue, color.alpha ) - interpolate = lambda start, end: start + (end - start) * position - - return Gdk.RGBA(*map(interpolate, color_tuple(from_color), color_tuple(to_color))) + self.color_override.load_from_data(''.encode('ascii')) def update_time_color(self, remaining): @@ -142,9 +130,11 @@ def update_time_color(self, remaining): if prev_color: position = (remaining - prev_time) / (timestamp - prev_time) - color = self.calc_color(prev_color, color, position) + color_spec = '* {{color: mix({}, {}, {})}}'.format(prev_color.to_string(), color.to_string(), position) + else: + color_spec = '* {color: {}}'.format(color.to_string()) - self.label_time.override_color(Gtk.StateType.NORMAL, color) + self.color_override.load_from_data(color_spec.encode('ascii')) class TimeCounter(object): @@ -183,7 +173,7 @@ def __init__(self, builder, ett): builder.load_widgets(self) # Setup timer for clocks - GObject.timeout_add(250, self.update_time) + GLib.timeout_add(250, self.update_time) def switch_pause(self, widget, event = None): diff --git a/pympress/ui.py b/pympress/ui.py index 6a195a27..f780c982 100644 --- a/pympress/ui.py +++ b/pympress/ui.py @@ -537,9 +537,9 @@ def pick_file(self, *args): """ Ask the user which file he means to open. """ # Use a GTK file dialog to choose file - dialog = Gtk.FileChooserDialog(_('Open...'), self.p_win, - Gtk.FileChooserAction.OPEN, - (Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) + dialog = Gtk.FileChooserDialog(title = _('Open...'), transient_for = self.p_win, + action = Gtk.FileChooserAction.OPEN) + dialog.add_buttons(Gtk.STOCK_OPEN, Gtk.ResponseType.OK) dialog.set_default_response(Gtk.ResponseType.OK) dialog.set_position(Gtk.WindowPosition.CENTER) @@ -571,8 +571,9 @@ def error_opening_file(self, filename): msg=_('Could not find the file "{}"').format(filename) else: msg=_('Error opening the file "{}"').format(filename) - dialog = Gtk.MessageDialog(self.p_win, Gtk.DialogFlags.MODAL, - Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, msg) + dialog = Gtk.MessageDialog(transient_for = self.p_win, flags = Gtk.DialogFlags.MODAL, + message_type = Gtk.MessageType.ERROR, message_format = msg) + dialog.add_buttons(Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE) dialog.set_position(Gtk.WindowPosition.CENTER) dialog.run() dialog.destroy() @@ -1098,14 +1099,13 @@ def adjust_frame_position(self, *args): val = self.c_frame.get_property(prop) button = Gtk.SpinButton() - button.set_adjustment(Gtk.Adjustment(lower=0.0, upper=1.0, step_incr=0.01)) + button.set_adjustment(Gtk.Adjustment(lower=0.0, upper=1.0, step_increment=0.01)) button.set_digits(2) button.set_value(val) button.connect("value-changed", self.update_frame_position, prop) - popup = Gtk.Dialog(_("Adjust alignment of slides in projector screen"), self.p_win, 0, - (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, - Gtk.STOCK_OK, Gtk.ResponseType.OK)) + popup = Gtk.Dialog(title = _("Adjust alignment of slides in projector screen"), transient_for = self.p_win) + popup.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK) box = popup.get_content_area() box.add(button) diff --git a/pympress/vlcvideo.py b/pympress/vlcvideo.py index c9c7ce6d..8ca13b74 100644 --- a/pympress/vlcvideo.py +++ b/pympress/vlcvideo.py @@ -135,7 +135,7 @@ def __init__(self, container, show_controls, relative_margins, callback_getter): self.load_ui('vlcvideo') self.toolbar.set_visible(show_controls) - self.progress.set_adjustment(Gtk.Adjustment(0., 0., 1., .001, .01, .01)) + self.progress.set_adjustment(Gtk.Adjustment(value = 0., lower = 0., upper = 1., step_increment=0.01)) self.play = callback_getter('play') self.hide = callback_getter('hide')