From 7776ebb5a0d546b258533b391b42ee50796395f6 Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Wed, 24 Oct 2007 11:06:11 -0400 Subject: [PATCH] Minor refinements. --- example/delugent/delugent.py | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/example/delugent/delugent.py b/example/delugent/delugent.py index 29c1c20..a508046 100755 --- a/example/delugent/delugent.py +++ b/example/delugent/delugent.py @@ -272,14 +272,28 @@ def dummy(item): def show_dl_preferences(item): pass -config_convert = { - "max_connections_global" : int, - "max_download_speed" : float, - "max_upload_speed" : float, - "max_upload_slots_global" : int, - "max_connections_per_torrent" : int, - "max_upload_slots_per_torrent" : int, -} +def refine_config_value(config, value): + """Return the value of the configuration in correct type.""" + config_convert = { + "max_connections_global" : int, + "max_download_speed" : float, + "max_upload_speed" : float, + "max_upload_slots_global" : int, + "max_connections_per_torrent" : int, + "max_upload_slots_per_torrent" : int, + "listen_ports" : int, + "enc_in_policy" : int, + "enc_out_policy" : int, + "enc_level" : int, + } + if config in config_convert: + conv = config_convert[config] + if isinstance(value, list): + for iter in range(0, len(value)): + value[iter] = conv(value[iter]) + else: + value = conv(value) + return value def pref_window(title): win = gnt.Window() @@ -351,9 +365,7 @@ def show_bandwidth_pref(item): oldv = entry.get_data("config-value") value = entry.get_text() if oldv != value: - if config in config_convert: - conv = config_convert[config] - value = conv(value) + value = refine_config_value(config, value) newconfigs[config] = value sys.stderr.write("Changing " + config + " to " + str(value) + "\n") try: @@ -362,6 +374,7 @@ def show_bandwidth_pref(item): except Exception, exc: log.error(str(exc)) save.connect('activate', save_prefs, win) + win.add_widget(gnt.Line(False)) win.add_widget(pack_widget(False, [save, cancel])) win.show() @@ -385,7 +398,7 @@ def show_network_pref(item): add_section(win, "Ports") randport = create_checkbox("Use Random Ports", "random_port") - win.add_widget(randport) + win.add_widget(pack_widget(False, [randport, gnt.Label(" (Active Port: " + str(client.get_listen_port()) + ")")])) add_section(win, "DHT") dht = create_checkbox("Enable Mainline DHT", "dht") @@ -408,6 +421,7 @@ def show_network_pref(item): client.set_config(newconfigs) window.destroy() save.connect('activate', save_callback, win) + win.add_widget(gnt.Line(False)) win.add_widget(pack_widget(False, [save, cancel])) win.show() -- 2.11.4.GIT