All pastes #748890 Raw Edit

Mine

public text v1 · immutable
#748890 ·published 2007-10-25 08:10 UTC
rendered paste body
+    def update_buttons(self):
+        log.debug("update_buttons")
+        # If all the selected torrents are paused, then disable the 'Pause' button.
+        # The same goes for the 'Resume' button.
+        pause = False
+        resume = False
+
+        # Disable the 'Clear Finished' button if there's no finished torrent
+        finished = False
+
+        selecteds = component.get('TorrentView').get_selected_torrents()
+        if not selecteds : selecteds  = []
+
+        for torrent in  selecteds :
+            status = client.get_torrent_status(torrent, ['state'])['state']
+            if status == self.STATE_PAUSED:
+                resume = True
+            elif status not in [self.STATE_FINISHED, self.STATE_SEEDING]:
+                pause = True
+            else:
+                finished = True
+            if pause and resume:    break
+
+        # Enable the 'Remove Torrent' button only if there's some selected torrent.
+        remove = (len(selecteds ) > 0)
+
+        if not finished:
+            torrents = client.get_session_state()
+            for torrent in torrents:
+                if torrent in selecteds: continue
+                status = client.get_torrent_status(torrent, ['state'])['state']
+                if status in [self.STATE_FINISHED, self.STATE_SEEDING]:
+                    finished = True
+                    break
+
+        for name, sensitive in (("toolbutton_pause", pause),
+                                ("toolbutton_resume", resume),
+                                ("toolbutton_remove", remove),
+                                ("toolbutton_clear", finished)):
+            self.window.main_glade.get_widget(name).set_sensitive(sensitive)
+
+        return False
+