Skip to content

Commit dc59989

Browse files
fix problem with non-classic UI and allow multiple tracker selection
1 parent b2fea6d commit dc59989

File tree

2 files changed

+33
-19
lines changed

2 files changed

+33
-19
lines changed

defaulttrackers/gtkui.py

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
from deluge.ui.client import client
4545
from deluge.plugins.pluginbase import GtkPluginBase
4646
import deluge.component as component
47-
#import deluge.common
4847
from deluge.ui.gtkui import dialogs
4948
#from pprint import pprint
5049

@@ -153,6 +152,8 @@ def enable(self):
153152
scrolled_window = self.glade.get_widget("scrolledwindow1")
154153
self.store = self.create_model()
155154
self.tree_view = gtk.TreeView(self.store)
155+
tree_selection = self.tree_view.get_selection()
156+
tree_selection.set_mode(gtk.SELECTION_MULTIPLE)
156157
self.tree_view.connect("cursor-changed", self.on_listitem_activated)
157158
self.tree_view.connect("row-activated", self.on_edit_button_clicked)
158159
self.tree_view.set_rules_hint(True)
@@ -181,7 +182,7 @@ def on_show_prefs(self):
181182

182183
def cb_get_config(self, config):
183184
"callback for on show_prefs"
184-
self.trackers = config["trackers"]
185+
self.trackers = list(config["trackers"])
185186
self.store.clear()
186187
for tracker in self.trackers:
187188
self.store.append([tracker["url"]])
@@ -200,8 +201,8 @@ def create_model(self):
200201
return store
201202

202203
def on_listitem_activated(self, treeview):
203-
tree, tree_id = self.tree_view.get_selection().get_selected()
204-
if tree_id:
204+
tree, tree_paths = self.tree_view.get_selection().get_selected_rows()
205+
if tree_paths:
205206
self.glade.get_widget("edit_button").set_sensitive(True)
206207
self.glade.get_widget("remove_button").set_sensitive(True)
207208
self.glade.get_widget("up_button").set_sensitive(True)
@@ -216,30 +217,43 @@ def on_add_button_clicked(self, widget):
216217
self.opts_dialog.show()
217218

218219
def on_remove_button_clicked(self, widget):
219-
tree, tree_id = self.tree_view.get_selection().get_selected()
220-
index = self.tree_view.get_selection().get_selected_rows()[1][0][0]
221-
self.store.remove(tree_id)
222-
del self.trackers[index]
220+
tree, tree_paths = self.tree_view.get_selection().get_selected_rows()
221+
to_remove = []
222+
for tree_path in tree_paths:
223+
tree_id = tree.get_iter(tree_path)
224+
index = tree_path[0]
225+
to_remove.append((index, tree_id))
226+
for index, tree_id in sorted(to_remove, reverse=True):
227+
# we need to delete the indices in reverse order to avoid offsets
228+
del self.trackers[index]
229+
self.store.remove(tree_id)
223230

224231
def on_edit_button_clicked(self, widget):
225-
tree, tree_id = self.tree_view.get_selection().get_selected()
226-
index = self.tree_view.get_selection().get_selected_rows()[1][0][0]
227-
url = str(self.store.get_value(tree_id, 0))
228-
if url:
229-
self.opts_dialog.show({
230-
"url": url,
231-
}, tree_id, index)
232+
tree, tree_paths = self.tree_view.get_selection().get_selected_rows()
233+
if tree_paths:
234+
tree_path = tree_paths[0]
235+
tree_id = tree.get_iter(tree_path)
236+
index = tree_path[0]
237+
url = str(self.store.get_value(tree_id, 0))
238+
if url:
239+
self.opts_dialog.show({
240+
"url": url,
241+
}, tree_id, index)
232242

233243
def on_up_button_clicked(self, widget):
234-
tree, tree_id = self.tree_view.get_selection().get_selected()
235-
if tree_id is not None:
244+
tree, tree_paths = self.tree_view.get_selection().get_selected_rows()
245+
if tree_paths:
246+
tree_path = tree_paths[0]
247+
tree_id = tree.get_iter(tree_path)
236248
prev = iter_prev(tree_id, self.store)
237249
if prev is not None:
238250
self.store.swap(prev, tree_id)
239251

240252
def on_down_button_clicked(self, widget):
241-
tree, tree_id = self.tree_view.get_selection().get_selected()
242-
if tree_id is not None:
253+
tree, tree_paths = self.tree_view.get_selection().get_selected_rows()
254+
if tree_paths:
255+
tree_path = tree_paths[0]
256+
tree_id = tree.get_iter(tree_path)
243257
nexti = self.store.iter_next(tree_id)
244258
if nexti is not None:
245259
self.store.swap(tree_id, nexti)

egg/DefaultTrackers-0.1-py2.7.egg

266 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)