connected frontend to backend

This commit is contained in:
Zach Tibbitts 2007-01-11 00:58:23 +00:00
parent ba4eaf7f7e
commit eafe924107
4 changed files with 77 additions and 35 deletions

View File

@ -75,6 +75,15 @@ PREF_FUNCTIONS = {
"max_download_rate" : deluge_core.set_download_rate_limit,
"max_upload_rate" : deluge_core.set_upload_rate_limit
}
STATE_MESSAGES = ( "Queued",
"Checking",
"Connecting",
"Downloading Metadata",
"Downloading",
"Finished",
"Seeding",
"Allocating"
)
# Exceptions
@ -143,7 +152,7 @@ class persistent_state:
# The manager for the torrent system
class manager:
class Manager:
# blank_slate mode ignores the two pickle files and DHT state file, i.e. you start
# completely fresh. When quitting, the old files will be overwritten
def __init__(self, client_ID, version, user_agent, base_dir, blank_slate=False):

View File

@ -29,10 +29,18 @@ import pygtk
pygtk.require('2.0')
import gtk
import gtk.glade
import gobject
import xdg, xdg.BaseDirectory
class DelugeGTK:
def __init__(self):
#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:
self.gladefile = dcommon.get_glade_file("delugegtk.glade")
self.wtree = gtk.glade.XML(self.gladefile)
self.window = self.wtree.get_widget("main_window")
@ -110,49 +118,56 @@ class DelugeGTK:
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)
## Interface created
## add torrents in manager to interface
for uid in self.manager.get_unique_IDs():
self.store.append(self.get_list_from_uid(uid))
## Start the timer that updates the interface
def start(self):
pass
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"]
def new_torrent(self, obj=None):
pass
def add_torrent(self, obj=None):
pass
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))
def quit(self, obj=None):
self.manager.quit()
self.window.destroy()
## Call via a timer to update the interface
def update(self):
pass
## For testing purposes, create a copy of the interface
if __name__ == "__main__":
deluge = DelugeGTK()
## Test the interface by adding a few fake torrents
deluge.store.append([0,1,"Deluge Torrent","700MB",50,"Downloading","10 (50)", "15 (30)", "50 KB/s", "10 KB/s", "2 h", "100%"])
deluge.store.append([1,2,"Sample Torrent","350MB",75,"Queued","10 (20)","20 (20)","0 KB/s", "0 KB/s", "und", "0%"])
deluge.store.append([2,3,"Deluge Torrent","700MB",55,"Downloading","10 (50)", "15 (30)", "50 KB/s", "10 KB/s", "2 h", "300%"])
deluge.store.append([3,4,"Sample Torrent","350MB",65,"Queued","10 (20)","20 (20)","0 KB/s", "0 KB/s", "und", "10%"])
deluge.store.append([4,5,"Deluge Torrent","700MB",50,"Downloading","10 (50)", "15 (30)", "50 KB/s", "10 KB/s", "2 h", "120%"])
deluge.store.append([5,6,"Sample Torrent","350MB",95,"Queued","10 (20)","20 (20)","0 KB/s", "0 KB/s", "und", "110%"])
deluge.file_store.append(["Sample_Filename.ext", True])
deluge.file_store.append(["Second_Filename.ext", True])
deluge.peer_store.append(["192.168.0.1", "Deluge 0.3.1", "100%", "30 KB/s", "0 KB/s"])
deluge.peer_store.append(["192.168.0.2", "Deluge 0.4.0", "76%", "13 KB/s", "0 KB/s"])
deluge.peer_store.append(["192.168.0.3", "Deluge 0.3.0", "74%", "12 KB/s", "3 KB/s"])
deluge.peer_store.append(["192.168.0.4", "Deluge 0.3.99.2", "50%", "9 KB/s", "0 KB/s"])
deluge.peer_store.append(["192.168.0.5", "Deluge 0.4.0", "90%", "0 KB/s", "20 KB/s"])
## Done with sample lines
interface = DelugeGTK()
interface.start()
gtk.main()

16
dgtk.py
View File

@ -131,6 +131,22 @@ class PreferencesDialog:
self.prf.run()
self.prf.hide_all()
## A simple file open dialog. I'm going to improve it later,
## this is a quick implementation for testing.
def show_file_open_dialog():
chooser = gtk.FileChooserDialog("Open", None, gtk.FILE_CHOOSER_ACTION_OPEN,
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
response = chooser.run()
if response == gtk.RESPONSE_OK:
result = chooser.get_filename()
else:
result = None
chooser.destroy()
return result
## Functions to create columns
def add_text_column(view, header, cid):

10
test.py
View File

@ -13,14 +13,14 @@ import deluge
from time import sleep
import os
manager = deluge.manager("DL", "0500", "deluge - testing only",
manager = deluge.Manager("DL", "0500", "deluge - testing only",
os.path.expanduser("~") + "/Temp")# blank_slate=True)
#manager.set_pref('max_upload_rate', 6*1024)
my_torrent = manager.add_torrent("ubuntu.iso.torrent", ".", True)
##my_torrent = manager.add_torrent("ubuntu.iso.torrent", ".", True)
print "Unique ID:", my_torrent
##print "Unique ID:", my_torrent
print "PREFS:", manager.prefs
@ -29,7 +29,9 @@ try:
print "STATE:", manager.get_state()
print "# torrents:", manager.get_num_torrents()
for unique_ID in manager.get_unique_IDs():
print unique_ID, manager.get_torrent_state(unique_ID)
state = manager.get_torrent_state(unique_ID)
for key in state.keys():
print key, state[key]
manager.handle_events()
print ""
sleep(2)