code cleanup - 9.55/10

This commit is contained in:
Marcos Pinto 2007-08-26 07:09:49 +00:00
parent ca89e7d18e
commit 63bd654c86

View File

@ -1,3 +1,6 @@
"""
this is our wizard which aids configuration for new users
"""
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# Copyright (C) Marcos Pinto 2007 <markybob@gmail.com> # Copyright (C) Marcos Pinto 2007 <markybob@gmail.com>
@ -29,6 +32,9 @@
# statement from all source files in the program, then also delete it here. # statement from all source files in the program, then also delete it here.
class WizardGTK: class WizardGTK:
"""
the main window for our configuration wizard
"""
def __init__(self): def __init__(self):
import gtk import gtk
import gtk.glade import gtk.glade
@ -36,7 +42,8 @@ class WizardGTK:
import deluge import deluge
import deluge.common import deluge.common
import deluge.pref import deluge.pref
self.wtree = gtk.glade.XML(deluge.common.get_glade_file("wizard.glade"), domain='deluge') self.wtree = gtk.glade.XML(deluge.common.get_glade_file("wizard.glade")\
, domain='deluge')
self.wtree.signal_autoconnect({'apply_prefs': self.apply_prefs, self.wtree.signal_autoconnect({'apply_prefs': self.apply_prefs,
'cancel': self.cancel, 'cancel': self.cancel,
'toggle': self.toggle, 'toggle': self.toggle,
@ -48,7 +55,8 @@ class WizardGTK:
self.window.set_page_complete(self.wtree.get_widget('vbox1'), True) self.window.set_page_complete(self.wtree.get_widget('vbox1'), True)
self.window.set_page_complete(self.wtree.get_widget('vbox2'), True) self.window.set_page_complete(self.wtree.get_widget('vbox2'), True)
self.window.set_page_complete(self.wtree.get_widget('vbox3'), True) self.window.set_page_complete(self.wtree.get_widget('vbox3'), True)
self.window.set_page_complete(self.wtree.get_widget('chk_send_info'), True) self.window.set_page_complete(self.wtree.get_widget('chk_send_info'), \
True)
config_file = deluge.common.CONFIG_DIR + "/prefs.state" config_file = deluge.common.CONFIG_DIR + "/prefs.state"
self.config = deluge.pref.Preferences(config_file, False, self.config = deluge.pref.Preferences(config_file, False,
defaults={"listen_on" : [6881,6889], defaults={"listen_on" : [6881,6889],
@ -66,142 +74,226 @@ class WizardGTK:
except IOError: except IOError:
pass pass
else: else:
self.wtree.get_widget('spin_port_min').set_value(self.config.get("listen_on")[0]) self.wtree.get_widget('spin_port_min').set_value(self.config.\
self.wtree.get_widget('spin_port_max').set_value(self.config.get("listen_on")[1]) get("listen_on")[0])
self.wtree.get_widget('chk_send_info').set_active(self.config.get("send_info")) self.wtree.get_widget('spin_port_max').set_value(self.config.\
self.wtree.get_widget('chk_random_ports').set_active(self.config.get("random_port")) get("listen_on")[1])
self.wtree.get_widget('radio_save_all_to').set_active(self.config.get("use_default_dir")) self.wtree.get_widget('chk_send_info').set_active(self.config.\
self.wtree.get_widget('download_path_button').set_filename(self.config.get("default_download_path")) get("send_info"))
self.wtree.get_widget('spin_max_connections_global').set_value(self.config.get("max_connections_global")) self.wtree.get_widget('chk_random_ports').set_active(self.config.\
self.wtree.get_widget('spin_max_upload_slots_global').set_value(self.config.get("max_upload_slots_global")) get("random_port"))
self.wtree.get_widget('spin_max_upload').set_value(self.config.get("max_upload_speed")) self.wtree.get_widget('radio_save_all_to').set_active(self.config.\
self.wtree.get_widget('spin_torrents').set_value(self.config.get("max_active_torrents")) get("use_default_dir"))
self.wtree.get_widget('download_path_button').set_filename(self.\
config.get("default_download_path"))
self.wtree.get_widget('spin_max_connections_global').set_value(\
self.config.get("max_connections_global"))
self.wtree.get_widget('spin_max_upload_slots_global').set_value(\
self.config.get("max_upload_slots_global"))
self.wtree.get_widget('spin_max_upload').set_value(self.config.\
get("max_upload_speed"))
self.wtree.get_widget('spin_torrents').set_value(self.config.\
get("max_active_torrents"))
#show wizard #show wizard
self.window.show() self.window.show()
gtk.main() gtk.main()
def toggle(self, args=None): def toggle(self, *args):
"""
updates the gui with preferences according to user input
"""
self.wtree.get_widget('spin_port_min').set_sensitive( self.wtree.get_widget('spin_port_min').set_sensitive(
not self.wtree.get_widget('chk_random_ports').get_active()) not self.wtree.get_widget('chk_random_ports').get_active())
self.wtree.get_widget('spin_port_max').set_sensitive( self.wtree.get_widget('spin_port_max').set_sensitive(
not self.wtree.get_widget('chk_random_ports').get_active()) not self.wtree.get_widget('chk_random_ports').get_active())
if self.wtree.get_widget('combo_upload_line').get_active_text() == "28k": if self.wtree.get_widget('combo_upload_line').get_active_text() == \
self.wtree.get_widget('spin_max_connections_global').set_value(float('25')) "28k":
self.wtree.get_widget('spin_max_upload_slots_global').set_value(float('1')) self.wtree.get_widget('spin_max_connections_global').set_value(\
float('25'))
self.wtree.get_widget('spin_max_upload_slots_global').set_value(\
float('1'))
self.wtree.get_widget('spin_max_upload').set_value(float('2')) self.wtree.get_widget('spin_max_upload').set_value(float('2'))
self.wtree.get_widget('spin_torrents').set_value(float('1')) self.wtree.get_widget('spin_torrents').set_value(float('1'))
elif self.wtree.get_widget('combo_upload_line').get_active_text() == "56k": elif self.wtree.get_widget('combo_upload_line').get_active_text() == \
self.wtree.get_widget('spin_max_connections_global').set_value(float('30')) "56k":
self.wtree.get_widget('spin_max_upload_slots_global').set_value(float('3')) self.wtree.get_widget('spin_max_connections_global').set_value(\
float('30'))
self.wtree.get_widget('spin_max_upload_slots_global').set_value(\
float('3'))
self.wtree.get_widget('spin_max_upload').set_value(float('2')) self.wtree.get_widget('spin_max_upload').set_value(float('2'))
self.wtree.get_widget('spin_torrents').set_value(float('1')) self.wtree.get_widget('spin_torrents').set_value(float('1'))
elif self.wtree.get_widget('combo_upload_line').get_active_text() == "64k": elif self.wtree.get_widget('combo_upload_line').get_active_text() == \
self.wtree.get_widget('spin_max_connections_global').set_value(float('75')) "64k":
self.wtree.get_widget('spin_max_upload_slots_global').set_value(float('2')) self.wtree.get_widget('spin_max_connections_global').set_value(\
float('75'))
self.wtree.get_widget('spin_max_upload_slots_global').set_value(\
float('2'))
self.wtree.get_widget('spin_max_upload').set_value(float('5')) self.wtree.get_widget('spin_max_upload').set_value(float('5'))
self.wtree.get_widget('spin_torrents').set_value(float('1')) self.wtree.get_widget('spin_torrents').set_value(float('1'))
elif self.wtree.get_widget('combo_upload_line').get_active_text() == "96k": elif self.wtree.get_widget('combo_upload_line').get_active_text() == \
self.wtree.get_widget('spin_max_connections_global').set_value(float('75')) "96k":
self.wtree.get_widget('spin_max_upload_slots_global').set_value(float('3')) self.wtree.get_widget('spin_max_connections_global').set_value(\
float('75'))
self.wtree.get_widget('spin_max_upload_slots_global').set_value(\
float('3'))
self.wtree.get_widget('spin_max_upload').set_value(float('7')) self.wtree.get_widget('spin_max_upload').set_value(float('7'))
self.wtree.get_widget('spin_torrents').set_value(float('1')) self.wtree.get_widget('spin_torrents').set_value(float('1'))
elif self.wtree.get_widget('combo_upload_line').get_active_text() == "128k": elif self.wtree.get_widget('combo_upload_line').get_active_text() == \
self.wtree.get_widget('spin_max_connections_global').set_value(float('88')) "128k":
self.wtree.get_widget('spin_max_upload_slots_global').set_value(float('3')) self.wtree.get_widget('spin_max_connections_global').set_value(\
float('88'))
self.wtree.get_widget('spin_max_upload_slots_global').set_value(\
float('3'))
self.wtree.get_widget('spin_max_upload').set_value(float('9')) self.wtree.get_widget('spin_max_upload').set_value(float('9'))
self.wtree.get_widget('spin_torrents').set_value(float('1')) self.wtree.get_widget('spin_torrents').set_value(float('1'))
elif self.wtree.get_widget('combo_upload_line').get_active_text() == "192k": elif self.wtree.get_widget('combo_upload_line').get_active_text() == \
self.wtree.get_widget('spin_max_connections_global').set_value(float('90')) "192k":
self.wtree.get_widget('spin_max_upload_slots_global').set_value(float('3')) self.wtree.get_widget('spin_max_connections_global').set_value(\
float('90'))
self.wtree.get_widget('spin_max_upload_slots_global').set_value(\
float('3'))
self.wtree.get_widget('spin_max_upload').set_value(float('17')) self.wtree.get_widget('spin_max_upload').set_value(float('17'))
self.wtree.get_widget('spin_torrents').set_value(float('1')) self.wtree.get_widget('spin_torrents').set_value(float('1'))
elif self.wtree.get_widget('combo_upload_line').get_active_text() == "256k": elif self.wtree.get_widget('combo_upload_line').get_active_text() == \
self.wtree.get_widget('spin_max_connections_global').set_value(float('130')) "256k":
self.wtree.get_widget('spin_max_upload_slots_global').set_value(float('3')) self.wtree.get_widget('spin_max_connections_global').set_value(\
float('130'))
self.wtree.get_widget('spin_max_upload_slots_global').set_value(\
float('3'))
self.wtree.get_widget('spin_max_upload').set_value(float('17')) self.wtree.get_widget('spin_max_upload').set_value(float('17'))
self.wtree.get_widget('spin_torrents').set_value(float('1')) self.wtree.get_widget('spin_torrents').set_value(float('1'))
elif self.wtree.get_widget('combo_upload_line').get_active_text() == "384k": elif self.wtree.get_widget('combo_upload_line').get_active_text() == \
self.wtree.get_widget('spin_max_connections_global').set_value(float('230')) "384k":
self.wtree.get_widget('spin_max_upload_slots_global').set_value(float('4')) self.wtree.get_widget('spin_max_connections_global').set_value(\
float('230'))
self.wtree.get_widget('spin_max_upload_slots_global').set_value(\
float('4'))
self.wtree.get_widget('spin_max_upload').set_value(float('35')) self.wtree.get_widget('spin_max_upload').set_value(float('35'))
self.wtree.get_widget('spin_torrents').set_value(float('3')) self.wtree.get_widget('spin_torrents').set_value(float('3'))
elif self.wtree.get_widget('combo_upload_line').get_active_text() == "512k": elif self.wtree.get_widget('combo_upload_line').get_active_text() == \
self.wtree.get_widget('spin_max_connections_global').set_value(float('250')) "512k":
self.wtree.get_widget('spin_max_upload_slots_global').set_value(float('4')) self.wtree.get_widget('spin_max_connections_global').set_value(\
float('250'))
self.wtree.get_widget('spin_max_upload_slots_global').set_value(\
float('4'))
self.wtree.get_widget('spin_max_upload').set_value(float('47')) self.wtree.get_widget('spin_max_upload').set_value(float('47'))
self.wtree.get_widget('spin_torrents').set_value(float('3')) self.wtree.get_widget('spin_torrents').set_value(float('3'))
elif self.wtree.get_widget('combo_upload_line').get_active_text() == "640k": elif self.wtree.get_widget('combo_upload_line').get_active_text() == \
self.wtree.get_widget('spin_max_connections_global').set_value(float('375')) "640k":
self.wtree.get_widget('spin_max_upload_slots_global').set_value(float('4')) self.wtree.get_widget('spin_max_connections_global').set_value(\
float('375'))
self.wtree.get_widget('spin_max_upload_slots_global').set_value(\
float('4'))
self.wtree.get_widget('spin_max_upload').set_value(float('60')) self.wtree.get_widget('spin_max_upload').set_value(float('60'))
self.wtree.get_widget('spin_torrents').set_value(float('4')) self.wtree.get_widget('spin_torrents').set_value(float('4'))
elif self.wtree.get_widget('combo_upload_line').get_active_text() == "768k": elif self.wtree.get_widget('combo_upload_line').get_active_text() == \
self.wtree.get_widget('spin_max_connections_global').set_value(float('450')) "768k":
self.wtree.get_widget('spin_max_upload_slots_global').set_value(float('5')) self.wtree.get_widget('spin_max_connections_global').set_value(\
float('450'))
self.wtree.get_widget('spin_max_upload_slots_global').set_value(\
float('5'))
self.wtree.get_widget('spin_max_upload').set_value(float('72')) self.wtree.get_widget('spin_max_upload').set_value(float('72'))
self.wtree.get_widget('spin_torrents').set_value(float('5')) self.wtree.get_widget('spin_torrents').set_value(float('5'))
elif self.wtree.get_widget('combo_upload_line').get_active_text() == "1Mbit": elif self.wtree.get_widget('combo_upload_line').get_active_text() == \
self.wtree.get_widget('spin_max_connections_global').set_value(float('600')) "1Mbit":
self.wtree.get_widget('spin_max_upload_slots_global').set_value(float('6')) self.wtree.get_widget('spin_max_connections_global').set_value(\
float('600'))
self.wtree.get_widget('spin_max_upload_slots_global').set_value(\
float('6'))
self.wtree.get_widget('spin_max_upload').set_value(float('92')) self.wtree.get_widget('spin_max_upload').set_value(float('92'))
self.wtree.get_widget('spin_torrents').set_value(float('5')) self.wtree.get_widget('spin_torrents').set_value(float('5'))
elif self.wtree.get_widget('combo_upload_line').get_active_text() == "2Mbit": elif self.wtree.get_widget('combo_upload_line').get_active_text() == \
self.wtree.get_widget('spin_max_connections_global').set_value(float('750')) "2Mbit":
self.wtree.get_widget('spin_max_upload_slots_global').set_value(float('8')) self.wtree.get_widget('spin_max_connections_global').set_value(\
float('750'))
self.wtree.get_widget('spin_max_upload_slots_global').set_value(\
float('8'))
self.wtree.get_widget('spin_max_upload').set_value(float('186')) self.wtree.get_widget('spin_max_upload').set_value(float('186'))
self.wtree.get_widget('spin_torrents').set_value(float('9')) self.wtree.get_widget('spin_torrents').set_value(float('9'))
elif self.wtree.get_widget('combo_upload_line').get_active_text() == "10Mbit": elif self.wtree.get_widget('combo_upload_line').get_active_text() == \
self.wtree.get_widget('spin_max_connections_global').set_value(float('800')) "10Mbit":
self.wtree.get_widget('spin_max_upload_slots_global').set_value(float('25')) self.wtree.get_widget('spin_max_connections_global').set_value(\
float('800'))
self.wtree.get_widget('spin_max_upload_slots_global').set_value(\
float('25'))
self.wtree.get_widget('spin_max_upload').set_value(float('1120')) self.wtree.get_widget('spin_max_upload').set_value(float('1120'))
self.wtree.get_widget('spin_torrents').set_value(float('15')) self.wtree.get_widget('spin_torrents').set_value(float('15'))
elif self.wtree.get_widget('combo_upload_line').get_active_text() == "20Mbit": elif self.wtree.get_widget('combo_upload_line').get_active_text() == \
self.wtree.get_widget('spin_max_connections_global').set_value(float('850')) "20Mbit":
self.wtree.get_widget('spin_max_upload_slots_global').set_value(float('30')) self.wtree.get_widget('spin_max_connections_global').set_value(\
float('850'))
self.wtree.get_widget('spin_max_upload_slots_global').set_value(\
float('30'))
self.wtree.get_widget('spin_max_upload').set_value(float('2240')) self.wtree.get_widget('spin_max_upload').set_value(float('2240'))
self.wtree.get_widget('spin_torrents').set_value(float('15')) self.wtree.get_widget('spin_torrents').set_value(float('15'))
elif self.wtree.get_widget('combo_upload_line').get_active_text() == "40Mbit": elif self.wtree.get_widget('combo_upload_line').get_active_text() == \
self.wtree.get_widget('spin_max_connections_global').set_value(float('900')) "40Mbit":
self.wtree.get_widget('spin_max_upload_slots_global').set_value(float('35')) self.wtree.get_widget('spin_max_connections_global').set_value(\
float('900'))
self.wtree.get_widget('spin_max_upload_slots_global').set_value(\
float('35'))
self.wtree.get_widget('spin_max_upload').set_value(float('4480')) self.wtree.get_widget('spin_max_upload').set_value(float('4480'))
self.wtree.get_widget('spin_torrents').set_value(float('15')) self.wtree.get_widget('spin_torrents').set_value(float('15'))
elif self.wtree.get_widget('combo_upload_line').get_active_text() == "50Mbit": elif self.wtree.get_widget('combo_upload_line').get_active_text() == \
self.wtree.get_widget('spin_max_connections_global').set_value(float('950')) "50Mbit":
self.wtree.get_widget('spin_max_upload_slots_global').set_value(float('50')) self.wtree.get_widget('spin_max_connections_global').set_value(\
float('950'))
self.wtree.get_widget('spin_max_upload_slots_global').set_value(\
float('50'))
self.wtree.get_widget('spin_max_upload').set_value(float('5600')) self.wtree.get_widget('spin_max_upload').set_value(float('5600'))
self.wtree.get_widget('spin_torrents').set_value(float('20')) self.wtree.get_widget('spin_torrents').set_value(float('20'))
elif self.wtree.get_widget('combo_upload_line').get_active_text() == "100Mbit": elif self.wtree.get_widget('combo_upload_line').get_active_text() == \
self.wtree.get_widget('spin_max_connections_global').set_value(float('1000')) "100Mbit":
self.wtree.get_widget('spin_max_upload_slots_global').set_value(float('50')) self.wtree.get_widget('spin_max_connections_global').set_value(\
float('1000'))
self.wtree.get_widget('spin_max_upload_slots_global').set_value(\
float('50'))
self.wtree.get_widget('spin_max_upload').set_value(float('11200')) self.wtree.get_widget('spin_max_upload').set_value(float('11200'))
self.wtree.get_widget('spin_torrents').set_value(float('25')) self.wtree.get_widget('spin_torrents').set_value(float('25'))
def create_file(self): def create_file(self):
"""
creates file that we check for to know if we need to run the wizard or
not
"""
import os import os
import deluge
import deluge.common import deluge.common
f = open(os.path.join(deluge.common.CONFIG_DIR, 'firstrun'), 'w') firstrun = open(os.path.join(deluge.common.CONFIG_DIR, 'firstrun'), 'w')
f.write("") firstrun.write("")
f.close
def cancel(self, args=None): def cancel(self, *args):
"""
exits the wizard and creates file so we dont re-run
"""
import gtk import gtk
self.create_file() self.create_file()
self.window.destroy() self.window.destroy()
gtk.main_quit() gtk.main_quit()
def apply_prefs(self, args=None): def apply_prefs(self, *args):
"""
saves configuration settings
"""
import gtk import gtk
self.create_file() self.create_file()
self.config.set('random_port', self.wtree.get_widget('chk_random_ports').get_active()) self.config.set("random_port", self.wtree.get_widget('chk_random_ports'\
self.config.set("listen_on", [self.wtree.get_widget("spin_port_min").get_value(), self.wtree.get_widget("spin_port_max").get_value()]) ).get_active())
self.config.set("send_info", self.wtree.get_widget("chk_send_info").get_active()) self.config.set("listen_on", [self.wtree.get_widget("spin_port_min")\
self.config.set("max_connections_global", int(self.wtree.get_widget('spin_max_connections_global').get_value())) .get_value(), self.wtree.get_widget("spin_port_max").get_value()])
self.config.set("max_upload_slots_global", int(self.wtree.get_widget('spin_max_upload_slots_global').get_value())) self.config.set("send_info", self.wtree.get_widget("chk_send_info").\
self.config.set("max_upload_speed", int(self.wtree.get_widget('spin_max_upload').get_value())) get_active())
self.config.set("max_active_torrents", int(self.wtree.get_widget('spin_torrents').get_value())) self.config.set("max_connections_global", int(self.wtree.get_widget\
self.config.set("use_default_dir", self.wtree.get_widget('radio_save_all_to').get_active()) ('spin_max_connections_global').get_value()))
self.config.set("default_download_path", self.wtree.get_widget('download_path_button').get_filename()) self.config.set("max_upload_slots_global", int(self.wtree.get_widget\
('spin_max_upload_slots_global').get_value()))
self.config.set("max_upload_speed", int(self.wtree.get_widget(\
'spin_max_upload').get_value()))
self.config.set("max_active_torrents", int(self.wtree.get_widget(\
'spin_torrents').get_value()))
self.config.set("use_default_dir", self.wtree.get_widget(\
'radio_save_all_to').get_active())
self.config.set("default_download_path", self.wtree.get_widget(\
'download_path_button').get_filename())
self.config.save() self.config.save()
gtk.main_quit() gtk.main_quit()