configurable columns

This commit is contained in:
Zach Tibbitts 2007-01-11 21:53:25 +00:00
parent 29ab4c0ba3
commit fe540d225c
4 changed files with 763 additions and 729 deletions

View File

@ -106,6 +106,8 @@ class DuplicateTorrentError(DelugeError):
class InvalidTorrentError(DelugeError): class InvalidTorrentError(DelugeError):
pass pass
class InvalidUniqueIDError(DelugeError):
pass
# A cached data item # A cached data item
@ -343,6 +345,10 @@ class Manager:
# This is the EXTERNAL function, for the GUI. It returns the core_state + supp_state # This is the EXTERNAL function, for the GUI. It returns the core_state + supp_state
def get_torrent_state(self, unique_ID): def get_torrent_state(self, unique_ID):
# Check to see if unique_ID exists:
if self.state.queue.count(unique_ID) == 0:
raise InvalidUniqueIDError("Asked for a torrent that doesn't exist")
ret = self.get_core_torrent_state(unique_ID, True).copy() ret = self.get_core_torrent_state(unique_ID, True).copy()
# Add the deluge-level things to the deluge_core data # Add the deluge-level things to the deluge_core data
@ -590,7 +596,7 @@ class Manager:
ret = unique_ID ret = unique_ID
self.unique_IDs[unique_ID] = torrent self.unique_IDs[unique_ID] = torrent
print torrents_with_unique_ID # print torrents_with_unique_ID
# Remove torrents from core, unique_IDs and queue # Remove torrents from core, unique_IDs and queue
to_delete = [] to_delete = []
for unique_ID in self.unique_IDs.keys(): for unique_ID in self.unique_IDs.keys():

View File

@ -20,24 +20,18 @@
# 51 Franklin Street, Fifth Floor # 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA. # Boston, MA 02110-1301, USA.
import deluge
import dcommon, dgtk
import sys, os, gettext import sys, os, gettext
import deluge, dcommon, dgtk
import pygtk import pygtk
pygtk.require('2.0') pygtk.require('2.0')
import gtk import gtk, gtk.glade, gobject
import gtk.glade
import gobject
import xdg, xdg.BaseDirectory import xdg, xdg.BaseDirectory
class DelugeGTK: class DelugeGTK:
def __init__(self): def __init__(self):
#Start the Deluge Manager: #Start the Deluge Manager:
self.manager = deluge.Manager("DL", "0500", "Deluge 0.5.0", self.manager = deluge.Manager("DE", "0500", "Deluge 0.5.0",
os.path.expanduser("~") + "/Temp") os.path.expanduser("~") + "/Temp")
#xdg.BaseDirectory.save_config_path("deluge-svn")) #xdg.BaseDirectory.save_config_path("deluge-svn"))
#Set up the interface: #Set up the interface:
@ -46,7 +40,7 @@ class DelugeGTK:
self.window = self.wtree.get_widget("main_window") self.window = self.wtree.get_widget("main_window")
self.toolbar = self.wtree.get_widget("tb_middle") self.toolbar = self.wtree.get_widget("tb_middle")
if(self.window): if(self.window):
self.window.connect("destroy", gtk.main_quit) self.window.connect("destroy", self.quit)
self.window.set_title(dcommon.PROGRAM_NAME + " " + dcommon.PROGRAM_VERSION) self.window.set_title(dcommon.PROGRAM_NAME + " " + dcommon.PROGRAM_VERSION)
self.window.set_icon_from_file(dcommon.get_pixmap("deluge32.png")) self.window.set_icon_from_file(dcommon.get_pixmap("deluge32.png"))
@ -68,9 +62,19 @@ class DelugeGTK:
## Edit Menu ## Edit Menu
"pref_clicked": self.prf.show_pref, "pref_clicked": self.prf.show_pref,
"plugins_clicked": self.prf.show_plugins, "plugins_clicked": self.prf.show_plugins,
## Torrent Menu ## View Menu
"size_toggle": self.size_toggle,
"status_toggle": self.status_toggle,
"seeders_toggle": self.seeders_toggle,
"peers_toggle": self.peers_toggle,
"dl_toggle": self.dl_toggle,
"ul_toggle": self.ul_toggle,
"eta_toggle": self.eta_toggle,
"share_toggle": self.share_toggle,
## Help Menu ## Help Menu
"show_about_dialog": self.abt.show, "show_about_dialog": self.abt.show,
## Other events
"torrentrow_click": self.torrentview_clicked,
} }
self.wtree.signal_autoconnect(actions) self.wtree.signal_autoconnect(actions)
@ -123,7 +127,7 @@ class DelugeGTK:
## add torrents in manager to interface ## add torrents in manager to interface
for uid in self.manager.get_unique_IDs(): for uid in self.manager.get_unique_IDs():
self.store.append(self.get_list_from_uid(uid)) self.store.append(self.get_list_from_unique_id(uid))
## Start the timer that updates the interface ## Start the timer that updates the interface
@ -132,34 +136,41 @@ class DelugeGTK:
## Call via a timer to update the interface ## Call via a timer to update the interface
def update(self): def update(self):
itr = self.store.get_iter_first() # Make sure that the interface still exists
while itr is not None: try:
uid = self.store.get_value(itr, 0)
try:
state = self.manager.get_torrent_state(uid)
except deluge.DelugeError:
print "Removing Torrent"
self.store.remove(itr)
tab = self.wtree.get_widget("torrent_info").get_current_page() tab = self.wtree.get_widget("torrent_info").get_current_page()
if tab == 0: #Torrent List except AttributeError:
tlist = self.get_list_from_uid(uid) return False
for i in range(12): if tab == 0: #Torrent List
self.store.set_value(itr, i, tlist[i]) itr = self.store.get_iter_first()
itr = self.store.iter_next(itr) while itr is not None:
elif tab == 1: #Details Pane uid = self.store.get_value(itr, 0)
pass try:
elif tab == 2: #Peers List state = self.manager.get_torrent_state(uid)
pass tlist = self.get_list_from_unique_id(uid)
elif tab == 3: #File List for i in range(12):
pass self.store.set_value(itr, i, tlist[i])
itr = self.store.iter_next(itr)
except deluge.InvalidUniqueIDError:
self.store.remove(itr)
if not self.store.iter_is_valid(itr):
itr = None
elif tab == 1: #Details Pane
pass
elif tab == 2: #Peers List
pass
elif tab == 3: #File List
pass
else:
pass
return True return True
def get_selected_torrent(self): def get_selected_torrent(self):
return self.store.get_value(self.view.get_selection().get_selected()[1], 0) return self.store.get_value(self.view.get_selection().get_selected()[1], 0)
# UID, Q#, Name, Size, Progress, Message, Seeders, Peers, DL, UL, ETA, Share # UID, Q#, Name, Size, Progress, Message, Seeders, Peers, DL, UL, ETA, Share
def get_list_from_uid(self, unique_id): def get_list_from_unique_id(self, unique_id):
state = self.manager.get_torrent_state(unique_id) state = self.manager.get_torrent_state(unique_id)
queue = int(state['queue_pos']) + 1 queue = int(state['queue_pos']) + 1
name = state['name'] name = state['name']
@ -182,14 +193,43 @@ class DelugeGTK:
torrent = dgtk.show_file_open_dialog() torrent = dgtk.show_file_open_dialog()
if torrent is not None: if torrent is not None:
uid = self.manager.add_torrent(torrent, ".", True) uid = self.manager.add_torrent(torrent, ".", True)
self.store.append(self.get_list_from_uid(uid)) self.store.append(self.get_list_from_unique_id(uid))
def remove_torrent(self, obj=None): def remove_torrent(self, obj=None):
self.manager.remove_torrent(self.get_selected_torrent(), False) self.manager.remove_torrent(self.get_selected_torrent(), False)
def torrentview_clicked(self, widget, event):
pass
def size_toggle(self, obj):
self.size_column.set_visible(obj.get_active())
def status_toggle(self, obj):
self.status_column.set_visible(obj.get_active())
def seeders_toggle(self, obj):
self.seed_column.set_visible(obj.get_active())
def peers_toggle(self, obj):
self.peer_column.set_visible(obj.get_active())
def dl_toggle(self, obj):
self.dl_column.set_visible(obj.get_active())
def ul_toggle(self, obj):
self.ul_column.set_visible(obj.get_active())
def eta_toggle(self, obj):
self.eta_column.set_visible(obj.get_active())
def share_toggle(self, obj):
self.share_column.set_visible(obj.get_active())
def quit(self, obj=None): def quit(self, obj=None):
self.manager.quit() self.manager.quit()
self.window.destroy() gtk.main_quit()
@ -198,5 +238,4 @@ class DelugeGTK:
if __name__ == "__main__": if __name__ == "__main__":
interface = DelugeGTK() interface = DelugeGTK()
interface.start() interface.start()
gtk.main() gtk.main()

22
dgtk.py
View File

@ -41,24 +41,7 @@ class TrayIcon:
self.tray.set_from_file(dcommon.get_pixmap("deluge32.png")) self.tray.set_from_file(dcommon.get_pixmap("deluge32.png"))
self.tray.set_tooltip("Deluge Bittorrent Client") self.tray.set_tooltip("Deluge Bittorrent Client")
class TorrentPopup:
def __init__(self, parent):
self.parent = parent
self.gladefile = dcommon.get_glade_file("dgtkpopups.glade")
self.wtree = gtk.glade.XML(self.gladefile)
self.menu = self.wtree.get_widget("torrent_popup")
dic = {
"size_toggle": self.size,
"status_toggle": self.status,
"seeders_toggle": self.seeders,
"peers_toggle": self.peers,
"dl_toggle": self.dl,
"ul_toggle": self.ul,
"eta_toggle": self.eta,
"share_toggle": self.share
}
self.wtree.signal_autoconnect(dic)
def popup(self): def popup(self):
pass pass
@ -152,6 +135,7 @@ def show_file_open_dialog():
def add_text_column(view, header, cid): def add_text_column(view, header, cid):
render = gtk.CellRendererText() render = gtk.CellRendererText()
column = gtk.TreeViewColumn(header, render, text=cid) column = gtk.TreeViewColumn(header, render, text=cid)
column.set_clickable(True)
column.set_resizable(True) column.set_resizable(True)
column.set_expand(False) column.set_expand(False)
view.append_column(column) view.append_column(column)
@ -160,6 +144,7 @@ def add_text_column(view, header, cid):
def add_progress_column(view, header, pid, mid): def add_progress_column(view, header, pid, mid):
render = gtk.CellRendererProgress() render = gtk.CellRendererProgress()
column = gtk.TreeViewColumn(header, render, value=pid, text=mid) column = gtk.TreeViewColumn(header, render, value=pid, text=mid)
column.set_clickable(True)
column.set_resizable(True) column.set_resizable(True)
column.set_expand(False) column.set_expand(False)
view.append_column(column) view.append_column(column)
@ -169,6 +154,7 @@ def add_toggle_column(view, header, cid, toggled_signal=None):
render = gtk.CellRendererToggle() render = gtk.CellRendererToggle()
render.set_property('activatable', True) render.set_property('activatable', True)
column = gtk.TreeViewColumn(header, render, active=cid) column = gtk.TreeViewColumn(header, render, active=cid)
column.set_clickable(True)
column.set_resizable(True) column.set_resizable(True)
column.set_expand(False) column.set_expand(False)
view.append_column(column) view.append_column(column)

File diff suppressed because it is too large Load Diff