Skip to content

Commit

Permalink
Avoid deprecated code, fix #48
Browse files Browse the repository at this point in the history
Up to Gtk 3.22 (excluded), i.e. we use GdkScreen and not GdkDisplay + GdkMonitor
  • Loading branch information
Cimbali committed Dec 20, 2017
1 parent 81c89cf commit 2738811
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 32 deletions.
34 changes: 12 additions & 22 deletions pympress/talk_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -51,13 +51,18 @@ 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 = []

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")
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
18 changes: 9 additions & 9 deletions pympress/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pympress/vlcvideo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 2738811

Please sign in to comment.