def update_ui_time(self, widget): """ Displays the value of the progress slider in the text boxes as time. """ track = player.get_current_track() if not track: log.debug("update_ui_time: track was None.") return val = int(self.progress_scale.get_value()) if self._application_settings.titlebar_remaining_time: total = self.progress_scale.get_adjustment().get_upper() remaining_secs: int = int((total - val)) current_text = seconds_to_str(val, total) remaining_text = seconds_to_str(remaining_secs, total) else: remaining_secs = int((track.length / self.ui.speed.get_speed()) - val) remaining_text = seconds_to_str(remaining_secs, track.length) current_text = seconds_to_str(val, track.length) self.current_label.set_markup("<tt><b>" + current_text + "</b></tt>") self.remaining_label.set_markup("<tt><b>-" + remaining_text + "</b></tt>") if self.ui.book_overview.book and self.current_book.id == self.ui.book_overview.book.id: self.ui.book_overview.update_time()
def _on_progress_scale_changed(self, _): position = int(self.progress_scale.get_value()) total = self.progress_scale.get_adjustment().get_upper() remaining_secs: int = int(total - position) current_text = seconds_to_str(position, total) remaining_text = seconds_to_str(remaining_secs, total) self.current_label.set_markup("<span font_features='tnum'>" + current_text + "</span>") self.remaining_label.set_markup("<span font_features='tnum'>-" + remaining_text + "</span>")
def __init__(self, t, book): self.track = t self.ui = cozy.ui.main_view.CozyUI() self.book = book super().__init__() self.connect("enter-notify-event", self._on_enter_notify) self.connect("leave-notify-event", self._on_leave_notify) self.connect("button-press-event", self.__on_button_press) self.set_tooltip_text(_("Play this part")) self.props.width_request = 400 # This box contains all content self.box = Gtk.Box() self.box.set_orientation(Gtk.Orientation.HORIZONTAL) self.box.set_spacing(3) self.box.set_halign(Gtk.Align.FILL) self.box.set_valign(Gtk.Align.CENTER) # These are the widgets that contain data self.play_img = Gtk.Image() no_label = Gtk.Label() title_label = Gtk.Label() dur_label = Gtk.Label() self.play_img.set_margin_right(5) self.play_img.props.width_request = 16 no_label.set_text(str(self.track.number)) no_label.props.margin = 4 no_label.set_margin_right(7) no_label.set_margin_left(0) no_label.set_size_request(30, -1) no_label.set_xalign(1) title_label.set_text(self.track.name) title_label.get_style_context().add_class("semi-bold") title_label.set_halign(Gtk.Align.START) title_label.props.margin = 4 title_label.props.hexpand = True title_label.props.hexpand_set = True title_label.set_margin_right(7) title_label.props.width_request = 100 title_label.props.xalign = 0.0 title_label.set_ellipsize(Pango.EllipsizeMode.MIDDLE) dur_label.set_text(seconds_to_str(self.track.length)) dur_label.get_style_context().add_class("monospace") dur_label.set_halign(Gtk.Align.END) dur_label.props.margin = 4 dur_label.set_margin_left(60) self.box.add(self.play_img) self.box.add(no_label) self.box.pack_start(title_label, True, True, 0) self.box.pack_end(dur_label, False, False, 0) self.add(self.box)