class TaskWidget(Gtk.HBox): """ Displays a task. """ def __init__(self, task): super(TaskWidget, self).__init__(spacing=2) self.task = task self.label = Gtk.Label() self.label.set_alignment(1.0, 0.5) self.label.set_ellipsize(Pango.EllipsizeMode.END) self.pack_start(self.label, True, True, 12) self.progress = Gtk.ProgressBar() self.progress.set_size_request(100, -1) self.pack_start(self.progress, True, True, 0) self.pause = SmallImageToggleButton() self.pause.add( Gtk.Image.new_from_icon_name(Icons.MEDIA_PLAYBACK_PAUSE, Gtk.IconSize.MENU)) self.pause.connect('toggled', self.__pause_toggled) self.pack_start(self.pause, False, True, 0) self.stop = SmallImageButton() self.stop.add( Gtk.Image.new_from_icon_name(Icons.MEDIA_PLAYBACK_STOP, Gtk.IconSize.MENU)) self.stop.connect('clicked', self.__stop_clicked) self.pack_start(self.stop, False, True, 0) def __pause_toggled(self, btn): if self.task.pausable: self.task.paused = btn.props.active def __stop_clicked(self, btn): if self.task.stoppable: self.task.stop() def update(self): formatted_label = "<small><b>%s</b>\n%s</small>" % (self.task.source, self.task.desc) self.label.set_markup(formatted_label) if self.task.frac is not None: self.progress.set_fraction(self.task.frac) else: self.progress.pulse() if self.pause.props.sensitive != self.task.pausable: self.pause.props.sensitive = self.task.pausable show_as_active = (self.task.pausable and self.task.paused) if self.pause.props.active != show_as_active: self.pause.props.active = show_as_active if self.stop.props.sensitive != self.task.stoppable: self.stop.props.sensitive = self.task.stoppable