def __update(self, volume): """ Sets the volume level indicator """ icon_name = 'audio-volume-muted' tooltip = _('Muted') if volume > 0: i = clamp(int(round(volume * 2)), 0, len(self.icon_names) - 1) icon_name = 'audio-volume-%s' % self.icon_names[i] #TRANSLATORS: Volume percentage tooltip = _('%d%%') % (volume * 100) else: volume = 0 if volume == 1.0: tooltip = _('Full Volume') if volume > 0: self.button.set_active(False) self.button_image.set_from_icon_name(icon_name, Gtk.IconSize.BUTTON) self.button.set_tooltip_text(tooltip) self.slider.set_value(volume) self.slider.set_tooltip_text(tooltip)
def _on_autoscroll_timeout(self): """ Automatically scrolls during drag operations Adapted from gtk_tree_view_vertical_autoscroll() in gtktreeview.c """ x, y, modifier = self.props.window.get_pointer() x, y = self.widget_to_tree_coords(x, y) visible_rect = self.get_visible_rect() # Calculate offset from the top edge offset = y - (visible_rect.y + 3 * self._SCROLL_EDGE_SIZE) # 3: Scroll faster upwards # Check if we are near the bottom edge instead if offset > 0: # Calculate offset based on the bottom edge offset = y - (visible_rect.y + visible_rect.height - 2 * self._SCROLL_EDGE_SIZE) # Skip if we are not near to top or bottom edge if offset < 0: return True vadjustment = self.get_vadjustment() vadjustment.value = common.clamp(vadjustment.value + offset, 0, vadjustment.upper - vadjustment.page_size) self.set_vadjustment(vadjustment) return True
def _step(self): '''Steps the progress bar''' self.count += 1 self._progress.set_fraction( clamp(self.count / float(self.total), 0, 1)) self._label.set_markup(self.text % { 'count': self.count, 'total': self.total })
def step(self): self.count += 1 self._progress.set_fraction( common.clamp(self.count / float(self.total), 0, 1)) self._label.set_markup(self.text % { 'count': self.count, 'total': self.total }) while Gtk.events_pending(): Gtk.main_iteration()
def on_progress_update(self, thread, percent): """ Called when the progress has been updated """ if percent > 0: self._progress_updated = True fraction = clamp(float(percent) / 100, 0, 1) self.progressbar.set_fraction(fraction) self.progressbar.set_text('%d%%' % percent)
def do_set_property(self, property, value): """ Setter for custom properties """ if property.name == "rating": if value == self._rating: value = 0 else: value = clamp(value, 0, settings.get_option("rating/maximum", 5)) self._rating = value self._image.set_from_pixbuf(icons.MANAGER.pixbuf_from_rating(value).pixbuf) self.emit("rating-changed", value) else: raise AttributeError("unkown property %s" % property.name)
def on_scroll_event(self, widget, event): """ Seek on scroll as VLC does """ if not self.__player.current: return True if self.__player.current.get_tag_raw('__length') is None: return True progress = self.__player.get_progress() progress_delta = 0.05 # 5% of track length progress_delta_small = 0.005 # 0.5% of track length if ( event.direction == Gdk.ScrollDirection.DOWN or event.direction == Gdk.ScrollDirection.LEFT ): if event.get_state() & Gdk.ModifierType.SHIFT_MASK: new_progress = progress - progress_delta_small else: new_progress = progress - progress_delta elif ( event.direction == Gdk.ScrollDirection.UP or event.direction == Gdk.ScrollDirection.RIGHT ): if event.get_state() & Gdk.ModifierType.SHIFT_MASK: new_progress = progress + progress_delta_small else: new_progress = progress + progress_delta elif event.direction == Gdk.ScrollDirection.SMOOTH: if event.get_state() & Gdk.ModifierType.SHIFT_MASK: new_progress = progress + progress_delta_small * ( event.deltax + event.deltay ) else: new_progress = progress + progress_delta * (event.deltax + event.deltay) self.__player.set_progress(clamp(new_progress, 0, 1)) self.update_progress() return True
def on_progress_update(self, thread, progress): """ Called when the progress has been updated """ if progress is None: return # Accept a tuple or number between 0 and 100 if hasattr(progress, '__len__'): step, total = progress percent = int(((step+1)/total)*100) else: percent = int(progress) if percent > 0: self._progress_updated = True fraction = clamp(percent / 100.0, 0, 1) self.progressbar.set_fraction(fraction) self.progressbar.set_text('%d%%' % percent)
def __update(self, volume): """ Sets the volume level indicator """ icon_name = 'audio-volume-muted' tooltip = _('Muted') if volume > 0: i = clamp(int(round(volume * 2)), 0, len(self.icon_names) - 1) icon_name = 'audio-volume-%s' % self.icon_names[i] #TRANSLATORS: Volume percentage tooltip = _('%d%%') % (volume * 100) if volume == 1.0: tooltip = _('Full Volume') if volume > 0: self.button.set_active(False) self.button_image.set_from_icon_name(icon_name, gtk.ICON_SIZE_BUTTON) self.button.set_tooltip_text(tooltip) self.slider.set_value(volume) self.slider.set_tooltip_text(tooltip)
def on_scroll_event(self, widget, event): """ Seek on scroll as VLC does """ if not self.__player.current: return True if self.__player.current.get_tag_raw('__length') is None: return True progress = self.__player.get_progress() progress_delta = 0.05 # 5% of track length progress_delta_small = 0.005 # 0.5% of track length if event.direction == Gdk.ScrollDirection.DOWN or \ event.direction == Gdk.ScrollDirection.LEFT: if event.get_state() & Gdk.ModifierType.SHIFT_MASK: new_progress = progress - progress_delta_small else: new_progress = progress - progress_delta elif event.direction == Gdk.ScrollDirection.UP or \ event.direction == Gdk.ScrollDirection.RIGHT: if event.get_state() & Gdk.ModifierType.SHIFT_MASK: new_progress = progress + progress_delta_small else: new_progress = progress + progress_delta elif event.direction == Gdk.ScrollDirection.SMOOTH: if event.get_state() & Gdk.ModifierType.SHIFT_MASK: new_progress = progress \ + progress_delta_small * (event.deltax + event.deltay) else: new_progress = progress \ + progress_delta * (event.deltax + event.deltay) self.__player.set_progress(clamp(new_progress, 0, 1)) self.update_progress() return True
def step(self): self.count += 1 self._progress.set_fraction(common.clamp(self.count / float(self.total), 0, 1)) self._label.set_markup(self.text % {'count': self.count, 'total': self.total}) while Gtk.events_pending(): Gtk.main_iteration()