deluge/delugegtk.py

173 lines
5.8 KiB
Python
Raw Normal View History

2006-12-08 19:06:49 +00:00
#!/usr/bin/env python
2006-11-28 22:28:37 +00:00
#
# delugegtk.py
#
# Copyright (C) Zach Tibbitts 2006 <zach@collegegeek.org>
2007-01-08 19:38:19 +00:00
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
2007-01-08 19:38:19 +00:00
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
2007-01-08 19:38:19 +00:00
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
2007-01-08 19:38:19 +00:00
# along with this program. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
2006-11-28 22:28:37 +00:00
2007-01-10 22:09:03 +00:00
import deluge
2006-12-08 19:02:22 +00:00
import dcommon, dgtk
2006-11-28 22:28:37 +00:00
import sys, os, gettext
import pygtk
pygtk.require('2.0')
import gtk
import gtk.glade
2007-01-11 00:58:23 +00:00
import gobject
import xdg, xdg.BaseDirectory
2006-11-28 22:28:37 +00:00
class DelugeGTK:
def __init__(self):
2007-01-11 00:58:23 +00:00
#Start the Deluge Manager:
self.manager = deluge.Manager("DL", "0500", "Deluge 0.5.0",
os.path.expanduser("~") + "/Temp")
#xdg.BaseDirectory.save_config_path("deluge-svn"))
#Set up the interface:
2006-11-28 22:28:37 +00:00
self.gladefile = dcommon.get_glade_file("delugegtk.glade")
self.wtree = gtk.glade.XML(self.gladefile)
self.window = self.wtree.get_widget("main_window")
2006-12-22 23:24:42 +00:00
self.toolbar = self.wtree.get_widget("tb_middle")
2006-11-28 22:28:37 +00:00
if(self.window):
self.window.connect("destroy", gtk.main_quit)
2006-11-30 11:01:29 +00:00
self.window.set_title(dcommon.PROGRAM_NAME + " " + dcommon.PROGRAM_VERSION)
2006-11-28 22:28:37 +00:00
self.window.set_icon_from_file(dcommon.get_pixmap("deluge32.png"))
2006-12-08 19:02:22 +00:00
## Create the system tray icon
self.tray = dgtk.TrayIcon(self)
## Create the about dialog
self.abt = dgtk.AboutDialog()
## Create the preferences dialog
2006-12-08 20:26:35 +00:00
self.prf = dgtk.PreferencesDialog()
2006-12-08 19:02:22 +00:00
2006-11-28 22:28:37 +00:00
actions = {
## File Menu
"new_torrent": self.new_torrent,
"add_torrent": self.add_torrent,
2006-12-22 23:24:42 +00:00
"menu_quit": self.quit,
## Edit Menu
2006-12-08 20:26:35 +00:00
"pref_clicked": self.prf.show_pref,
"plugins_clicked": self.prf.show_plugins,
2006-12-04 23:59:45 +00:00
## Torrent Menu
2006-11-28 22:28:37 +00:00
## Help Menu
2006-12-08 19:02:22 +00:00
"show_about_dialog": self.abt.show,
2006-11-28 22:28:37 +00:00
}
self.wtree.signal_autoconnect(actions)
## Create the torrent listview
2006-12-22 23:24:42 +00:00
self.view = self.wtree.get_widget("torrent_view")
# UID, Q#, Name, Size, Progress, Message, Seeders, Peers, DL, UL, ETA, Share
self.store = gtk.ListStore(int, int, str, str, int, str, str, str, str, str, str, str)
self.view.set_model(self.store)
2006-12-23 03:30:25 +00:00
self.view.set_rules_hint(True)
2006-12-08 19:02:22 +00:00
2006-12-24 04:08:34 +00:00
## Initializes the columns for the torrent_view
2006-12-08 20:26:35 +00:00
2006-12-22 23:24:42 +00:00
self.queue_column = dgtk.add_text_column(self.view, "#", 1)
self.name_column = dgtk.add_text_column(self.view, "Name", 2)
self.size_column = dgtk.add_text_column(self.view, "Size", 3)
self.status_column = dgtk.add_progress_column(self.view, "Status", 4, 5)
self.seed_column = dgtk.add_text_column(self.view, "Seeders", 6)
self.peer_column = dgtk.add_text_column(self.view, "Peers", 7)
self.dl_column = dgtk.add_text_column(self.view, "Download", 8)
self.ul_column = dgtk.add_text_column(self.view, "Upload", 9)
2006-12-23 04:35:06 +00:00
self.eta_column = dgtk.add_text_column(self.view, "ETA", 10)
2006-12-22 23:24:42 +00:00
self.share_column = dgtk.add_text_column(self.view, "Share Ratio", 11)
2006-11-28 22:28:37 +00:00
2006-12-24 04:08:34 +00:00
self.status_column.set_expand(True)
self.file_view = self.wtree.get_widget("file_view")
self.file_store = gtk.ListStore(str, bool)
self.file_view.set_model(self.file_store)
self.filename_column = dgtk.add_text_column(self.file_view, "Filename", 0)
self.filetoggle_column = dgtk.add_toggle_column(self.file_view, "DL?", 0)
self.filename_column.set_expand(True)
2007-01-07 22:50:26 +00:00
## Should probably use rules-hint for other treevies as well
2006-12-24 04:08:34 +00:00
self.peer_view = self.wtree.get_widget("peer_view")
self.peer_store = gtk.ListStore(str, str, str, str, str)
self.peer_view.set_model(self.peer_store)
self.peer_ip_column = dgtk.add_text_column(self.peer_view, "IP Address", 0)
self.peer_client_column = dgtk.add_text_column(self.peer_view, "Client", 1)
## Note: change this column to use a progress column before 0.5 is released
self.peer_complete_column = dgtk.add_text_column(self.peer_view, "Percent Complete", 2)
self.peer_download_column = dgtk.add_text_column(self.peer_view, "Download Rate", 3)
self.peer_upload_column = dgtk.add_text_column(self.peer_view, "Upload Rate", 4)
2007-01-11 00:58:23 +00:00
## Interface created
2006-12-24 04:08:34 +00:00
2007-01-11 00:58:23 +00:00
## add torrents in manager to interface
for uid in self.manager.get_unique_IDs():
self.store.append(self.get_list_from_uid(uid))
2006-12-24 04:08:34 +00:00
2007-01-11 00:58:23 +00:00
## Start the timer that updates the interface
2006-12-22 23:24:42 +00:00
def start(self):
2007-01-11 00:58:23 +00:00
gobject.timeout_add(1000, self.update)
## Call via a timer to update the interface
def update(self):
itr = self.store.get_iter_first()
while itr is not None:
uid = self.store.get_value(itr, 0)
tlist = self.get_list_from_uid(uid)
for i in range(12):
self.store.set_value(itr, i, tlist[i])
itr = self.store.iter_next(itr)
return True
# UID, Q#, Name, Size, Progress, Message, Seeders, Peers, DL, UL, ETA, Share
def get_list_from_uid(self, unique_id):
state = self.manager.get_torrent_state(unique_id)
return [unique_id, state['queue_pos'], state['name'], state['total_size'],
int(state['progress'] * 100), deluge.STATE_MESSAGES[state['state']], state['total_seeds'],
state['total_peers'], state['download_rate'], state['upload_rate'],
"NULL", "NULL"]
2006-12-22 23:24:42 +00:00
def new_torrent(self, obj=None):
2006-11-28 22:28:37 +00:00
pass
2006-12-22 23:24:42 +00:00
def add_torrent(self, obj=None):
2007-01-11 00:58:23 +00:00
torrent = dgtk.show_file_open_dialog()
if torrent is not None:
uid = self.manager.add_torrent(torrent, ".", True)
self.store.append(self.get_list_from_uid(uid))
2006-12-22 23:24:42 +00:00
def quit(self, obj=None):
2007-01-11 00:58:23 +00:00
self.manager.quit()
2006-12-22 23:24:42 +00:00
self.window.destroy()
2007-01-11 00:58:23 +00:00
2006-12-04 23:59:45 +00:00
2006-12-08 20:26:35 +00:00
## For testing purposes, create a copy of the interface
2006-11-28 22:28:37 +00:00
if __name__ == "__main__":
2007-01-11 00:58:23 +00:00
interface = DelugeGTK()
interface.start()
2006-12-22 23:24:42 +00:00
2006-11-28 22:28:37 +00:00
gtk.main()