Changed Preferences.get() to not set a type or default value.
If a default value is needed, it should be set in the DEFAULT_PREFS dictionary in pref.py.
This commit is contained in:
parent
7024caa6f3
commit
65f1f32771
|
@ -49,42 +49,42 @@ class PreferencesDlg:
|
|||
def show(self):
|
||||
# Load settings into dialog
|
||||
try:
|
||||
self.glade.get_widget("combo_encin").set_active(self.preferences.get("encin_state", int, default=common.EncState.enabled))
|
||||
self.glade.get_widget("combo_encout").set_active(self.preferences.get("encout_state", int, default=common.EncState.enabled))
|
||||
self.glade.get_widget("combo_enclevel").set_active(self.preferences.get("enclevel_type", int, default=common.EncLevel.both))
|
||||
self.glade.get_widget("combo_proxy_type").set_active(self.preferences.get("proxy_type", int, default=common.ProxyType.none))
|
||||
self.glade.get_widget("chk_pref_rc4").set_active(self.preferences.get("pref_rc4", bool, default=True))
|
||||
self.glade.get_widget("chk_upnp").set_active(self.preferences.get("use_upnp", bool, default=True))
|
||||
self.glade.get_widget("chk_natpmp").set_active(self.preferences.get("use_natpmp", bool, default=True))
|
||||
self.glade.get_widget("chk_utpex").set_active(self.preferences.get("use_utpex", bool, default=True))
|
||||
self.glade.get_widget("chk_use_tray").set_active(self.preferences.get("enable_system_tray", bool, default=True))
|
||||
self.glade.get_widget("chk_min_on_close").set_active(self.preferences.get("close_to_tray", bool, default=False))
|
||||
self.glade.get_widget("chk_lock_tray").set_active(self.preferences.get("lock_tray", bool, default=False))
|
||||
self.glade.get_widget("txt_tray_passwd").set_text(self.preferences.get("tray_passwd", default=""))
|
||||
self.glade.get_widget("txt_proxy_hostname").set_text(self.preferences.get("proxy_hostname", default=""))
|
||||
self.glade.get_widget("txt_proxy_username").set_text(self.preferences.get("proxy_username", default=""))
|
||||
self.glade.get_widget("txt_proxy_password").set_text(self.preferences.get("proxy_password", default=""))
|
||||
if(self.preferences.get("use_default_dir", bool, False)):
|
||||
self.glade.get_widget("combo_encin").set_active(self.preferences.get("encin_state"))
|
||||
self.glade.get_widget("combo_encout").set_active(self.preferences.get("encout_state"))
|
||||
self.glade.get_widget("combo_enclevel").set_active(self.preferences.get("enclevel_type"))
|
||||
self.glade.get_widget("combo_proxy_type").set_active(self.preferences.get("proxy_type"))
|
||||
self.glade.get_widget("chk_pref_rc4").set_active(self.preferences.get("pref_rc4"))
|
||||
self.glade.get_widget("chk_upnp").set_active(self.preferences.get("use_upnp"))
|
||||
self.glade.get_widget("chk_natpmp").set_active(self.preferences.get("use_natpmp"))
|
||||
self.glade.get_widget("chk_utpex").set_active(self.preferences.get("use_utpex"))
|
||||
self.glade.get_widget("chk_use_tray").set_active(self.preferences.get("enable_system_tray"))
|
||||
self.glade.get_widget("chk_min_on_close").set_active(self.preferences.get("close_to_tray"))
|
||||
self.glade.get_widget("chk_lock_tray").set_active(self.preferences.get("lock_tray"))
|
||||
self.glade.get_widget("txt_tray_passwd").set_text(self.preferences.get("tray_passwd"))
|
||||
self.glade.get_widget("txt_proxy_hostname").set_text(self.preferences.get("proxy_hostname"))
|
||||
self.glade.get_widget("txt_proxy_username").set_text(self.preferences.get("proxy_username"))
|
||||
self.glade.get_widget("txt_proxy_password").set_text(self.preferences.get("proxy_password"))
|
||||
if(self.preferences.get("use_default_dir")):
|
||||
self.glade.get_widget("radio_save_all_to").set_active(True)
|
||||
else:
|
||||
self.glade.get_widget("radio_ask_save").set_active(True)
|
||||
|
||||
self.glade.get_widget("download_path_button").set_filename(self.preferences.get("default_download_path", str, default=os.path.expandvars('$HOME')))
|
||||
self.glade.get_widget("chk_compact").set_active(self.preferences.get("use_compact_storage", bool, default=False))
|
||||
self.glade.get_widget("download_path_button").set_filename(self.preferences.get("default_download_path"))
|
||||
self.glade.get_widget("chk_compact").set_active(self.preferences.get("use_compact_storage"))
|
||||
self.glade.get_widget("active_port_label").set_text(str(self.parent.manager.get_state()['port']))
|
||||
self.glade.get_widget("spin_port_min").set_value(self.preferences.get("listen_on", default=6881)[0])
|
||||
self.glade.get_widget("spin_port_max").set_value(self.preferences.get("listen_on", default=6889)[1])
|
||||
self.glade.get_widget("spin_max_upload").set_value(self.preferences.get("max_upload_rate", int, default=-1))
|
||||
self.glade.get_widget("spin_num_upload").set_value(self.preferences.get("max_number_uploads", int, default=-1))
|
||||
self.glade.get_widget("spin_max_download").set_value(self.preferences.get("max_download_rate", int, default=-1))
|
||||
self.glade.get_widget("spin_max_connections").set_value(self.preferences.get("max_connections", int, default=-1))
|
||||
self.glade.get_widget("spin_proxy_port").set_value(self.preferences.get("proxy_port", int, default=8080))
|
||||
self.glade.get_widget("spin_torrents").set_value(self.preferences.get("max_number_torrents", int, default=-1))
|
||||
self.glade.get_widget("chk_seedbottom").set_active(self.preferences.get("queue_seeds_to_bottom", bool, default=False))
|
||||
self.glade.get_widget("chk_autoseed").set_active(self.preferences.get("auto_end_seeding", bool, default=False))
|
||||
self.glade.get_widget("spin_port_min").set_value(self.preferences.get("listen_on")[0])
|
||||
self.glade.get_widget("spin_port_max").set_value(self.preferences.get("listen_on")[1])
|
||||
self.glade.get_widget("spin_max_upload").set_value(self.preferences.get("max_upload_rate"))
|
||||
self.glade.get_widget("spin_num_upload").set_value(self.preferences.get("max_number_uploads"))
|
||||
self.glade.get_widget("spin_max_download").set_value(self.preferences.get("max_download_rate"))
|
||||
self.glade.get_widget("spin_max_connections").set_value(self.preferences.get("max_connections"))
|
||||
self.glade.get_widget("spin_proxy_port").set_value(self.preferences.get("proxy_port"))
|
||||
self.glade.get_widget("spin_torrents").set_value(self.preferences.get("max_number_torrents"))
|
||||
self.glade.get_widget("chk_seedbottom").set_active(self.preferences.get("queue_seeds_to_bottom"))
|
||||
self.glade.get_widget("chk_autoseed").set_active(self.preferences.get("auto_end_seeding"))
|
||||
self.glade.get_widget("ratio_spinner").set_value(self.preferences.get("auto_seed_ratio"))
|
||||
self.glade.get_widget("chk_dht").set_active(self.preferences.get("enable_dht", bool, default=True))
|
||||
self.glade.get_widget("spin_gui").set_value(self.preferences.get("gui_update_interval", float, default=1.0))
|
||||
self.glade.get_widget("chk_dht").set_active(self.preferences.get("enable_dht"))
|
||||
self.glade.get_widget("spin_gui").set_value(self.preferences.get("gui_update_interval"))
|
||||
|
||||
except KeyError:
|
||||
pass
|
||||
|
|
|
@ -296,7 +296,7 @@ class DelugeGTK:
|
|||
tray_lock.vbox.pack_start(entered_pass)
|
||||
tray_lock.show_all()
|
||||
if tray_lock.run() == gtk.RESPONSE_ACCEPT:
|
||||
if self.config.get("tray_passwd", default="") == entered_pass.get_text():
|
||||
if self.config.get("tray_passwd") == entered_pass.get_text():
|
||||
if comingnext == "mainwinshow":
|
||||
self.window.show()
|
||||
elif comingnext == "prefwinshow":
|
||||
|
@ -318,7 +318,7 @@ class DelugeGTK:
|
|||
else:
|
||||
self.window.present()
|
||||
else:
|
||||
if self.config.get("lock_tray", bool, default=False) == True:
|
||||
if self.config.get("lock_tray") == True:
|
||||
self.unlock_tray("mainwinshow")
|
||||
else:
|
||||
self.load_window_geometry()
|
||||
|
@ -328,7 +328,7 @@ class DelugeGTK:
|
|||
if self.window.get_property("visible"):
|
||||
self.window.hide()
|
||||
else:
|
||||
if self.config.get("lock_tray", bool, default=False) == True:
|
||||
if self.config.get("lock_tray") == True:
|
||||
self.unlock_tray("mainwinshow")
|
||||
else:
|
||||
self.window.show()
|
||||
|
@ -679,7 +679,7 @@ class DelugeGTK:
|
|||
self.config.save()
|
||||
|
||||
else:
|
||||
if self.config.get("lock_tray", bool, default=False) == True:
|
||||
if self.config.get("lock_tray") == True:
|
||||
self.unlock_tray("prefwinshow")
|
||||
else:
|
||||
self.preferences_dialog.show()
|
||||
|
@ -722,8 +722,8 @@ class DelugeGTK:
|
|||
|
||||
# Apply the preferences in the core
|
||||
self.manager.apply_prefs()
|
||||
self.manager.pe_settings(self.config.get("encout_state", int, default=common.EncState.enabled), self.config.get("encin_state", int, default=common.EncState.enabled), self.config.get("enclevel_type", int, default=common.EncLevel.both), self.config.get("pref_rc4", bool, default=True))
|
||||
self.manager.proxy_settings(self.config.get("proxy_hostname"), self.config.get("proxy_username"), self.config.get("proxy_password"), int(self.config.get("proxy_port")), self.config.get("proxy_type", int, default=common.ProxyType.none))
|
||||
self.manager.pe_settings(self.config.get("encout_state"), self.config.get("encin_state"), self.config.get("enclevel_type"), self.config.get("pref_rc4"))
|
||||
self.manager.proxy_settings(self.config.get("proxy_hostname"), self.config.get("proxy_username"), self.config.get("proxy_password"), int(self.config.get("proxy_port")), self.config.get("proxy_type"))
|
||||
|
||||
def get_message_from_state(self, torrent_state):
|
||||
state = torrent_state['state']
|
||||
|
@ -803,7 +803,7 @@ class DelugeGTK:
|
|||
self.manager.quit()
|
||||
|
||||
def load_plugins(self):
|
||||
enable_plugins = self.config.get('enabled_plugins', str, default="").split(':')
|
||||
enable_plugins = self.config.get('enabled_plugins').split(':')
|
||||
for plugin in enable_plugins:
|
||||
try:
|
||||
self.plugins.enable_plugin(plugin)
|
||||
|
@ -1069,14 +1069,14 @@ class DelugeGTK:
|
|||
self.interactive_add_torrent(path)
|
||||
|
||||
def interactive_add_torrent(self, torrent, append=True):
|
||||
if self.config.get('use_default_dir', bool, default=False):
|
||||
path = self.config.get('default_download_path', default=os.path.expandvars('$HOME'))
|
||||
if self.config.get('use_default_dir'):
|
||||
path = self.config.get('default_download_path')
|
||||
else:
|
||||
path = dialogs.show_directory_chooser_dialog(self.window)
|
||||
if path is None:
|
||||
return
|
||||
try:
|
||||
unique_id = self.manager.add_torrent(torrent, path, self.config.get('use_compact_storage', bool, default=False))
|
||||
unique_id = self.manager.add_torrent(torrent, path, self.config.get('use_compact_storage'))
|
||||
|
||||
if append:
|
||||
self.torrent_model.append(self.get_list_from_unique_id(unique_id))
|
||||
|
@ -1271,16 +1271,16 @@ class DelugeGTK:
|
|||
self.share_column.set_visible(obj.get_active())
|
||||
|
||||
def load_window_settings(self):
|
||||
self.wtree.get_widget("chk_infopane").set_active(self.config.get("show_infopane", bool, default=True))
|
||||
self.wtree.get_widget("chk_toolbar").set_active(self.config.get("show_toolbar", bool, default=True))
|
||||
self.wtree.get_widget("chk_size").set_active(self.config.get("show_size", bool, default=True))
|
||||
self.wtree.get_widget("chk_status").set_active(self.config.get("show_status", bool, default=True))
|
||||
self.wtree.get_widget("chk_seed").set_active(self.config.get("show_seeders", bool, default=True))
|
||||
self.wtree.get_widget("chk_peer").set_active(self.config.get("show_peers", bool, default=True))
|
||||
self.wtree.get_widget("chk_download").set_active(self.config.get("show_dl", bool, default=True))
|
||||
self.wtree.get_widget("chk_upload").set_active(self.config.get("show_ul", bool, default=True))
|
||||
self.wtree.get_widget("chk_eta").set_active(self.config.get("show_eta", bool, default=True))
|
||||
self.wtree.get_widget("chk_ratio").set_active(self.config.get("show_share", bool, default=True))
|
||||
self.wtree.get_widget("chk_infopane").set_active(self.config.get("show_infopane"))
|
||||
self.wtree.get_widget("chk_toolbar").set_active(self.config.get("show_toolbar"))
|
||||
self.wtree.get_widget("chk_size").set_active(self.config.get("show_size",))
|
||||
self.wtree.get_widget("chk_status").set_active(self.config.get("show_status"))
|
||||
self.wtree.get_widget("chk_seed").set_active(self.config.get("show_seeders",))
|
||||
self.wtree.get_widget("chk_peer").set_active(self.config.get("show_peers",))
|
||||
self.wtree.get_widget("chk_download").set_active(self.config.get("show_dl",))
|
||||
self.wtree.get_widget("chk_upload").set_active(self.config.get("show_ul",))
|
||||
self.wtree.get_widget("chk_eta").set_active(self.config.get("show_eta",))
|
||||
self.wtree.get_widget("chk_ratio").set_active(self.config.get("show_share",))
|
||||
self.wtree.get_widget("vpaned1").set_position(self.config.get("window_height") - self.config.get("window_pane_position"))
|
||||
|
||||
def save_window_settings(self):
|
||||
|
@ -1322,7 +1322,7 @@ class DelugeGTK:
|
|||
self.window.maximize()
|
||||
|
||||
def close(self, widget, event):
|
||||
if self.config.get("close_to_tray", bool, default=False) and self.config.get("enable_system_tray", bool, default=True) and self.has_tray:
|
||||
if self.config.get("close_to_tray") and self.config.get("enable_system_tray") and self.has_tray:
|
||||
self.window.hide()
|
||||
return True
|
||||
else:
|
||||
|
@ -1333,7 +1333,7 @@ class DelugeGTK:
|
|||
self.window.hide()
|
||||
self.shutdown()
|
||||
else:
|
||||
if self.config.get("lock_tray", bool, default=False) == True:
|
||||
if self.config.get("lock_tray") == True:
|
||||
self.unlock_tray("quitus")
|
||||
else:
|
||||
self.window.hide()
|
||||
|
|
36
src/pref.py
36
src/pref.py
|
@ -154,36 +154,12 @@ class Preferences:
|
|||
def set(self, key, value):
|
||||
self.mapping[key] = value
|
||||
|
||||
def get(self, key, kind=None, default=None):
|
||||
if not key in self.mapping.keys():
|
||||
if default is not None:
|
||||
self.mapping[key] = default
|
||||
return default
|
||||
else:
|
||||
raise KeyError
|
||||
result = self.mapping[key]
|
||||
if kind == None:
|
||||
pass
|
||||
elif kind == bool:
|
||||
if isinstance(result, str):
|
||||
result = not (result.lower() == "false")
|
||||
elif isinstance(result, int):
|
||||
result = not (result == 0)
|
||||
else:
|
||||
result = False
|
||||
elif kind == int:
|
||||
try:
|
||||
result = int(result)
|
||||
except ValueError:
|
||||
result = int(float(result))
|
||||
elif kind == float:
|
||||
result = float(result)
|
||||
elif kind == str:
|
||||
result = str(result)
|
||||
else:
|
||||
pass
|
||||
|
||||
return result
|
||||
def get(self, key):
|
||||
try:
|
||||
value = self.mapping[key]
|
||||
return value
|
||||
except KeyError:
|
||||
return None
|
||||
|
||||
def remove(self, key):
|
||||
self.mapping.pop(key)
|
||||
|
|
Loading…
Reference in New Issue