Massive clean up in UI update code. Update torrents info UI instantly when we
click on them in torrents list.
This commit is contained in:
parent
d07e8cddb6
commit
b5aff38295
145
src/interface.py
145
src/interface.py
|
@ -423,7 +423,6 @@ class DelugeGTK:
|
||||||
self.torrent_view.set_rules_hint(True)
|
self.torrent_view.set_rules_hint(True)
|
||||||
self.torrent_view.set_reorderable(True)
|
self.torrent_view.set_reorderable(True)
|
||||||
self.torrent_view.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
|
self.torrent_view.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
|
||||||
self.torrent_selected = None
|
|
||||||
|
|
||||||
def size(column, cell, model, iter, data):
|
def size(column, cell, model, iter, data):
|
||||||
size = long(model.get_value(iter, data))
|
size = long(model.get_value(iter, data))
|
||||||
|
@ -501,6 +500,8 @@ class DelugeGTK:
|
||||||
# Now for the File tab
|
# Now for the File tab
|
||||||
self.file_store.clear()
|
self.file_store.clear()
|
||||||
|
|
||||||
|
self.update_torrent_info_widget(unique_id)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def torrent_view_clicked(self, widget, event):
|
def torrent_view_clicked(self, widget, event):
|
||||||
|
@ -890,7 +891,7 @@ class DelugeGTK:
|
||||||
_("Connections") + ": " + str(connections) + " (" + str(max_connections) + ")" + "\n" + _("Down Speed") + ": " + \
|
_("Connections") + ": " + str(connections) + " (" + str(max_connections) + ")" + "\n" + _("Down Speed") + ": " + \
|
||||||
dlspeed + " (" + dlspeed_max + ")" + "\n" + _("Up Speed") + ": " + ulspeed + " (" + ulspeed_max + ")"
|
dlspeed + " (" + dlspeed_max + ")" + "\n" + _("Up Speed") + ": " + ulspeed + " (" + ulspeed_max + ")"
|
||||||
|
|
||||||
self.tray_icon.set_tooltip(msg)
|
self.tray_icon.set_tooltip(msg)
|
||||||
|
|
||||||
#Update any active plugins
|
#Update any active plugins
|
||||||
self.plugins.update_active_plugins()
|
self.plugins.update_active_plugins()
|
||||||
|
@ -901,44 +902,42 @@ class DelugeGTK:
|
||||||
self.statusbar.pop(1)
|
self.statusbar.pop(1)
|
||||||
self.statusbar.push(1, self.statusbar_temp_msg)
|
self.statusbar.push(1, self.statusbar_temp_msg)
|
||||||
|
|
||||||
# If no torrent is selected, select the first torrent:
|
|
||||||
if self.torrent_selected is None:
|
|
||||||
self.torrent_view.get_selection().select_path("0")
|
|
||||||
#Torrent List
|
#Torrent List
|
||||||
itr = self.torrent_model.get_iter_first()
|
itr = self.torrent_model.get_iter_first()
|
||||||
|
|
||||||
|
# Disable torrent options if there are no torrents
|
||||||
|
self.wtree.get_widget("menu_torrent").set_sensitive(itr is not None)
|
||||||
|
self.wtree.get_widget("toolbutton_remove").set_sensitive(itr is not None)
|
||||||
|
self.wtree.get_widget("toolbutton_pause").set_sensitive(itr is not None)
|
||||||
|
self.wtree.get_widget("toolbutton_up").set_sensitive(itr is not None)
|
||||||
|
self.wtree.get_widget("toolbutton_down").set_sensitive(itr is not None)
|
||||||
|
|
||||||
if itr is None:
|
if itr is None:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
while itr is not None:
|
while itr is not None:
|
||||||
uid = self.torrent_model.get_value(itr, 0)
|
uid = self.torrent_model.get_value(itr, 0)
|
||||||
try:
|
state = self.manager.get_torrent_state(uid)
|
||||||
state = self.manager.get_torrent_state(uid)
|
tlist = self.get_list_from_unique_id(uid)
|
||||||
tlist = self.get_list_from_unique_id(uid)
|
for i in range(len(tlist)):
|
||||||
for i in range(len(tlist)):
|
try:
|
||||||
try:
|
self.torrent_model.set_value(itr, i, tlist[i])
|
||||||
self.torrent_model.set_value(itr, i, tlist[i])
|
except:
|
||||||
except:
|
print "ERR", i, type(tlist[i]), tlist[i]
|
||||||
print "ERR", i, type(tlist[i]), tlist[i]
|
itr = self.torrent_model.iter_next(itr)
|
||||||
itr = self.torrent_model.iter_next(itr)
|
|
||||||
except core.InvalidUniqueIDError:
|
|
||||||
self.torrent_model.remove(itr)
|
|
||||||
if not self.torrent_model.iter_is_valid(itr):
|
|
||||||
itr = None
|
|
||||||
|
|
||||||
# Disable torrent options if no torrents are selected
|
|
||||||
torrent_selection = self.torrent_view.get_selection()
|
|
||||||
selection_count = torrent_selection.count_selected_rows()
|
|
||||||
|
|
||||||
self.wtree.get_widget("menu_torrent").set_sensitive(selection_count > 0)
|
|
||||||
self.wtree.get_widget("toolbutton_remove").set_sensitive(selection_count > 0)
|
|
||||||
self.wtree.get_widget("toolbutton_pause").set_sensitive(selection_count > 0)
|
|
||||||
self.wtree.get_widget("toolbutton_up").set_sensitive(selection_count > 0)
|
|
||||||
self.wtree.get_widget("toolbutton_down").set_sensitive(selection_count > 0)
|
|
||||||
|
|
||||||
# Disable moving top torrents up or bottom torrents down
|
# Disable moving top torrents up or bottom torrents down
|
||||||
top_torrents_selected = True
|
top_torrents_selected = True
|
||||||
bottom_torrents_selected = True
|
bottom_torrents_selected = True
|
||||||
|
|
||||||
|
torrent_selection = self.torrent_view.get_selection()
|
||||||
|
selection_count = torrent_selection.count_selected_rows()
|
||||||
|
|
||||||
|
# If no torrent is selected, select the first torrent:
|
||||||
|
if selection_count == 0:
|
||||||
|
torrent_selection.select_path("0")
|
||||||
|
selection_count = 1
|
||||||
|
|
||||||
for i in range(selection_count):
|
for i in range(selection_count):
|
||||||
if not torrent_selection.path_is_selected(i):
|
if not torrent_selection.path_is_selected(i):
|
||||||
top_torrents_selected = False
|
top_torrents_selected = False
|
||||||
|
@ -953,39 +952,43 @@ class DelugeGTK:
|
||||||
self.wtree.get_widget("toolbutton_up").set_sensitive(not top_torrents_selected)
|
self.wtree.get_widget("toolbutton_up").set_sensitive(not top_torrents_selected)
|
||||||
self.wtree.get_widget("toolbutton_down").set_sensitive(not bottom_torrents_selected)
|
self.wtree.get_widget("toolbutton_down").set_sensitive(not bottom_torrents_selected)
|
||||||
|
|
||||||
if selection_count == 0:
|
unique_id = None
|
||||||
return True
|
if selection_count == 1:
|
||||||
|
unique_id = self.get_selected_torrent()
|
||||||
try:
|
self.update_torrent_info_widget(unique_id)
|
||||||
if self.manager.get_torrent_state(self.get_selected_torrent())["is_paused"]:
|
else: # selection_count > 1
|
||||||
self.wtree.get_widget("toolbutton_pause").set_stock_id(gtk.STOCK_MEDIA_PLAY)
|
self.clear_details_pane()
|
||||||
self.wtree.get_widget("toolbutton_pause").set_label(_("Resume"))
|
|
||||||
else:
|
# Update tool buttons below based on the first selected torrent's state
|
||||||
self.wtree.get_widget("toolbutton_pause").set_stock_id(gtk.STOCK_MEDIA_PAUSE)
|
path = torrent_selection.get_selected_rows()[1][0]
|
||||||
self.wtree.get_widget("toolbutton_pause").set_label(_("Pause"))
|
unique_id = self.torrent_model.get_value(self.torrent_model.get_iter(path), 0)
|
||||||
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
if self.manager.get_torrent_state(unique_id)["is_paused"]:
|
||||||
state = self.manager.get_torrent_state(self.get_selected_torrent())
|
self.wtree.get_widget("toolbutton_pause").set_stock_id(gtk.STOCK_MEDIA_PLAY)
|
||||||
except core.InvalidUniqueIDError:
|
self.wtree.get_widget("toolbutton_pause").set_label(_("Resume"))
|
||||||
return True
|
else:
|
||||||
|
self.wtree.get_widget("toolbutton_pause").set_stock_id(gtk.STOCK_MEDIA_PAUSE)
|
||||||
|
self.wtree.get_widget("toolbutton_pause").set_label(_("Pause"))
|
||||||
|
|
||||||
if tab == 0: #Details Pane
|
return True
|
||||||
|
|
||||||
|
def update_torrent_info_widget(self, unique_id):
|
||||||
|
tab = self.wtree.get_widget("torrent_info").get_current_page()
|
||||||
|
state = self.manager.get_torrent_state(unique_id)
|
||||||
|
|
||||||
|
if tab == 0: #Details Pane
|
||||||
self.wtree.get_widget("summary_name").set_text(state['name'])
|
self.wtree.get_widget("summary_name").set_text(state['name'])
|
||||||
self.text_summary_total_size.set_text(common.fsize(state["total_size"]))
|
self.text_summary_total_size.set_text(common.fsize(state["total_size"]))
|
||||||
self.text_summary_pieces.set_text(str(state["num_pieces"]))
|
self.text_summary_pieces.set_text(str(state["num_pieces"]))
|
||||||
self.text_summary_total_downloaded.set_text(common.fsize(state["total_done"]) + " (" + common.fsize(state["total_download"]) + ")")
|
self.text_summary_total_downloaded.set_text(common.fsize(state["total_done"]) + " (" + common.fsize(state["total_download"]) + ")")
|
||||||
self.text_summary_total_uploaded.set_text(common.fsize(self.manager.unique_IDs[self.get_selected_torrent()].uploaded_memory + state["total_payload_upload"]) + " (" + common.fsize(state["total_upload"]) + ")")
|
self.text_summary_total_uploaded.set_text(common.fsize(self.manager.unique_IDs[unique_id].uploaded_memory + state["total_payload_upload"]) + " (" + common.fsize(state["total_upload"]) + ")")
|
||||||
self.text_summary_download_speed.set_text(common.fspeed(state["download_rate"]))
|
self.text_summary_download_speed.set_text(common.fspeed(state["download_rate"]))
|
||||||
self.text_summary_upload_speed.set_text(common.fspeed(state["upload_rate"]))
|
self.text_summary_upload_speed.set_text(common.fspeed(state["upload_rate"]))
|
||||||
self.text_summary_seeders.set_text(common.fseed(state))
|
self.text_summary_seeders.set_text(common.fseed(state))
|
||||||
self.text_summary_peers.set_text(common.fpeer(state))
|
self.text_summary_peers.set_text(common.fpeer(state))
|
||||||
self.wtree.get_widget("progressbar").set_fraction(float(state['progress']))
|
self.wtree.get_widget("progressbar").set_fraction(float(state['progress']))
|
||||||
self.wtree.get_widget("progressbar").set_text(common.fpcnt(state["progress"]))
|
self.wtree.get_widget("progressbar").set_text(common.fpcnt(state["progress"]))
|
||||||
self.text_summary_share_ratio.set_text('%.3f'%(self.calc_share_ratio(self.get_selected_torrent(), state)))
|
self.text_summary_share_ratio.set_text('%.3f'%(self.calc_share_ratio(unique_id, state)))
|
||||||
self.text_summary_tracker.set_text(str(state["tracker"]))
|
self.text_summary_tracker.set_text(str(state["tracker"]))
|
||||||
self.text_summary_tracker_status.set_text(str(state["tracker_ok"]))
|
self.text_summary_tracker_status.set_text(str(state["tracker_ok"]))
|
||||||
self.text_summary_next_announce.set_text(str(state["next_announce"]))
|
self.text_summary_next_announce.set_text(str(state["next_announce"]))
|
||||||
|
@ -1007,8 +1010,6 @@ class DelugeGTK:
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
unique_id = self.get_selected_torrent()
|
|
||||||
|
|
||||||
new_peer_info = self.manager.get_torrent_peer_info(unique_id)
|
new_peer_info = self.manager.get_torrent_peer_info(unique_id)
|
||||||
|
|
||||||
new_ips = {}
|
new_ips = {}
|
||||||
|
@ -1046,8 +1047,6 @@ class DelugeGTK:
|
||||||
peer["download_speed"],
|
peer["download_speed"],
|
||||||
peer["upload_speed"]])
|
peer["upload_speed"]])
|
||||||
elif tab == 2: #file tab
|
elif tab == 2: #file tab
|
||||||
unique_id = self.get_selected_torrent()
|
|
||||||
|
|
||||||
# Fill self.file_store with files only once and only when we click to
|
# Fill self.file_store with files only once and only when we click to
|
||||||
# file tab or it's already open
|
# file tab or it's already open
|
||||||
if not self.file_store.iter_n_children(None):
|
if not self.file_store.iter_n_children(None):
|
||||||
|
@ -1074,10 +1073,7 @@ class DelugeGTK:
|
||||||
if file['path'] in curr_files and \
|
if file['path'] in curr_files and \
|
||||||
self.file_store.get_value(iter, 3) != round(file['progress'], 2):
|
self.file_store.get_value(iter, 3) != round(file['progress'], 2):
|
||||||
self.file_store.set(iter, 3, file['progress'])
|
self.file_store.set(iter, 3, file['progress'])
|
||||||
else:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
def calc_share_ratio(self, unique_id, torrent_state):
|
def calc_share_ratio(self, unique_id, torrent_state):
|
||||||
r = float(self.manager.calc_ratio(unique_id, torrent_state))
|
r = float(self.manager.calc_ratio(unique_id, torrent_state))
|
||||||
|
@ -1087,11 +1083,14 @@ class DelugeGTK:
|
||||||
def get_selected_torrent(self):
|
def get_selected_torrent(self):
|
||||||
try:
|
try:
|
||||||
if self.torrent_view.get_selection().count_selected_rows() == 1:
|
if self.torrent_view.get_selection().count_selected_rows() == 1:
|
||||||
self.torrent_selected = self.torrent_view.get_selection().get_selected_rows()[1][0]
|
selected_path = self.torrent_view.get_selection().\
|
||||||
selected_torrent = self.torrent_model.get_value(self.torrent_model.get_iter(self.torrent_selected), 0)
|
get_selected_rows()[1][0]
|
||||||
return selected_torrent
|
selected_torrent = self.torrent_model.get_value(self.torrent_model.get_iter(selected_path), 0)
|
||||||
except TypeError, ValueError:
|
return selected_torrent
|
||||||
return None
|
except (TypeError, ValueError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
# Return a list of ids of the selected torrents
|
# Return a list of ids of the selected torrents
|
||||||
def get_selected_torrent_rows(self):
|
def get_selected_torrent_rows(self):
|
||||||
|
@ -1216,13 +1215,21 @@ class DelugeGTK:
|
||||||
|
|
||||||
response = asker.run()
|
response = asker.run()
|
||||||
asker.destroy()
|
asker.destroy()
|
||||||
if response == 1:
|
if response == 1:
|
||||||
torrent_list = self.get_selected_torrent_rows()
|
|
||||||
self.clear_details_pane()
|
self.clear_details_pane()
|
||||||
self.torrent_selected = None
|
|
||||||
for torrent in torrent_list:
|
torrents = self.get_selected_torrent_rows()
|
||||||
self.manager.remove_torrent(torrent, data_also.get_active(), torrent_also.get_active())
|
paths = self.torrent_view.get_selection().get_selected_rows()[1]
|
||||||
self.update()
|
row_references = [gtk.TreeRowReference(self.torrent_model, x)
|
||||||
|
for x in paths]
|
||||||
|
|
||||||
|
for unique_id, row_ref in izip(torrents, row_references):
|
||||||
|
self.manager.remove_torrent(unique_id, data_also.get_active(),
|
||||||
|
torrent_also.get_active())
|
||||||
|
iter = self.torrent_model.get_iter(row_ref.get_path())
|
||||||
|
self.torrent_model.remove(iter)
|
||||||
|
|
||||||
|
self.update()
|
||||||
|
|
||||||
def clear_details_pane(self):
|
def clear_details_pane(self):
|
||||||
self.wtree.get_widget("progressbar").set_text("")
|
self.wtree.get_widget("progressbar").set_text("")
|
||||||
|
|
Loading…
Reference in New Issue