preference dialog values saved and loaded
This commit is contained in:
parent
b091500124
commit
d2ecf8a433
|
@ -44,17 +44,6 @@
|
|||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkCheckButton" id="chk_use_tray">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Enable system tray icon</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
<signal name="toggled" handler="tray_toggle"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="right_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkCheckButton" id="chk_min_on_close">
|
||||
<property name="visible">True</property>
|
||||
|
@ -68,6 +57,18 @@
|
|||
<property name="x_padding">12</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkCheckButton" id="chk_use_tray">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Enable system tray icon</property>
|
||||
<property name="active">True</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
<signal name="toggled" handler="tray_toggle"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="right_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
|
@ -94,15 +95,13 @@
|
|||
<property name="n_rows">2</property>
|
||||
<property name="n_columns">2</property>
|
||||
<child>
|
||||
<widget class="GtkFileChooserButton" id="filechooserbutton1">
|
||||
<property name="action">GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER</property>
|
||||
<widget class="GtkRadioButton" id="radio_ask_save">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Ask me where to save each download</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">1</property>
|
||||
<property name="bottom_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
|
@ -118,13 +117,15 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkRadioButton" id="radio_ask_save">
|
||||
<widget class="GtkFileChooserButton" id="download_path_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Ask me where to save each download</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
<property name="action">GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">1</property>
|
||||
<property name="bottom_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
|
@ -153,6 +154,14 @@
|
|||
<property name="visible">True</property>
|
||||
<property name="n_rows">1</property>
|
||||
<property name="n_columns">2</property>
|
||||
<child>
|
||||
<widget class="GtkCheckButton" id="chk_autoseed">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Stop seeding torrents when
|
||||
their share ratio reaches:</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkSpinButton" id="ratio_spinner">
|
||||
<property name="visible">True</property>
|
||||
|
@ -167,14 +176,6 @@
|
|||
<property name="right_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkCheckButton" id="chk_autoseed">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Stop seeding torrents when
|
||||
their share ratio reaches:</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
|
@ -268,51 +269,13 @@ their share ratio reaches:</property>
|
|||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label25">
|
||||
<widget class="GtkButton" id="btn_test_port">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Try from:</property>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label26">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">to:</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">2</property>
|
||||
<property name="right_attach">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkSpinButton" id="spin_port_min">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="adjustment">0 0 100 1 10 10</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkSpinButton" id="spin_port_max">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="adjustment">0 0 100 1 10 10</property>
|
||||
<property name="label" translatable="yes">Test Port</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">3</property>
|
||||
<property name="right_attach">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label27">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Active port:</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">1</property>
|
||||
<property name="bottom_attach">2</property>
|
||||
</packing>
|
||||
|
@ -330,17 +293,55 @@ their share ratio reaches:</property>
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkButton" id="btn_test_port">
|
||||
<widget class="GtkLabel" id="label27">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Test Port</property>
|
||||
<property name="label" translatable="yes">Active port:</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">1</property>
|
||||
<property name="bottom_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkSpinButton" id="spin_port_max">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="adjustment">0 0 100 1 10 10</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">3</property>
|
||||
<property name="right_attach">4</property>
|
||||
<property name="top_attach">1</property>
|
||||
<property name="bottom_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkSpinButton" id="spin_port_min">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="adjustment">0 0 100 1 10 10</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label26">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">to:</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">2</property>
|
||||
<property name="right_attach">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label25">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Try from:</property>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
|
@ -367,20 +368,47 @@ their share ratio reaches:</property>
|
|||
<property name="n_rows">4</property>
|
||||
<property name="n_columns">2</property>
|
||||
<child>
|
||||
<widget class="GtkSpinButton" id="spinbutton4">
|
||||
<widget class="GtkLabel" id="label4">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="adjustment">0 0 100 1 10 10</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="label" translatable="yes">Maximum Upload Rate:</property>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label3">
|
||||
<property name="visible">True</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="label" translatable="yes">Maximum number of Uploads:</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="top_attach">1</property>
|
||||
<property name="bottom_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label2">
|
||||
<property name="visible">True</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="label" translatable="yes">Maximum Download Rate:</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="top_attach">2</property>
|
||||
<property name="bottom_attach">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label1">
|
||||
<property name="visible">True</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="label" translatable="yes">Maximum number of Downloads:</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">3</property>
|
||||
<property name="bottom_attach">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkSpinButton" id="spin_num_download">
|
||||
<widget class="GtkSpinButton" id="spin_max_upload">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="adjustment">0 0 100 1 10 10</property>
|
||||
|
@ -388,8 +416,6 @@ their share ratio reaches:</property>
|
|||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">2</property>
|
||||
<property name="bottom_attach">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
|
@ -406,7 +432,7 @@ their share ratio reaches:</property>
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkSpinButton" id="spin_max_upload">
|
||||
<widget class="GtkSpinButton" id="spin_max_download">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="adjustment">0 0 100 1 10 10</property>
|
||||
|
@ -414,48 +440,23 @@ their share ratio reaches:</property>
|
|||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label1">
|
||||
<property name="visible">True</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="label" translatable="yes">Maximum number of Downloads:</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="top_attach">3</property>
|
||||
<property name="bottom_attach">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label2">
|
||||
<property name="visible">True</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="label" translatable="yes">Maximum Download Rate:</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="top_attach">2</property>
|
||||
<property name="bottom_attach">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label3">
|
||||
<widget class="GtkSpinButton" id="spin_num_download">
|
||||
<property name="visible">True</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="label" translatable="yes">Maximum number of Uploads:</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="adjustment">0 0 100 1 10 10</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="top_attach">1</property>
|
||||
<property name="bottom_attach">2</property>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">3</property>
|
||||
<property name="bottom_attach">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label4">
|
||||
<property name="visible">True</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="label" translatable="yes">Maximum Upload Rate:</property>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
|
@ -520,6 +521,7 @@ their share ratio reaches:</property>
|
|||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">gtk-ok</property>
|
||||
<property name="use_stock">True</property>
|
||||
<property name="response_id">1</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
|
@ -555,16 +557,11 @@ their share ratio reaches:</property>
|
|||
<property name="n_rows">2</property>
|
||||
<property name="n_columns">2</property>
|
||||
<child>
|
||||
<widget class="GtkTextView" id="plugin_text1">
|
||||
<widget class="GtkTreeView" id="plugin_view1">
|
||||
<property name="visible">True</property>
|
||||
<property name="editable">False</property>
|
||||
<property name="wrap_mode">GTK_WRAP_WORD</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="x_padding">10</property>
|
||||
<property name="y_padding">10</property>
|
||||
<property name="bottom_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
|
@ -599,11 +596,16 @@ their share ratio reaches:</property>
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkTreeView" id="plugin_view1">
|
||||
<widget class="GtkTextView" id="plugin_text1">
|
||||
<property name="visible">True</property>
|
||||
<property name="editable">False</property>
|
||||
<property name="wrap_mode">GTK_WRAP_WORD</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="bottom_attach">2</property>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="x_padding">10</property>
|
||||
<property name="y_padding">10</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
|
|
|
@ -34,8 +34,29 @@ class DelugePreferences:
|
|||
def set(self, key, value):
|
||||
self.pref[key] = value
|
||||
|
||||
def get(self, key):
|
||||
return self.pref[key]
|
||||
def get(self, key, kind=None):
|
||||
result = self.pref[key]
|
||||
if kind == None:
|
||||
return result
|
||||
elif kind == bool:
|
||||
# Python interprets bool("False") as True, so we must compensate for this
|
||||
if isinstance(result, str):
|
||||
return (result.lower() == "true")
|
||||
elif isinstance(result, int):
|
||||
return not (result == 0)
|
||||
else:
|
||||
return False
|
||||
elif kind == str:
|
||||
return str(result)
|
||||
elif kind == int:
|
||||
try:
|
||||
return int(result)
|
||||
except ValueError:
|
||||
return int(float(result))
|
||||
elif kind == float:
|
||||
return float(result)
|
||||
else:
|
||||
return result
|
||||
|
||||
def keys(self):
|
||||
return self.pref.keys()
|
||||
|
@ -43,18 +64,23 @@ class DelugePreferences:
|
|||
def load_from_file(self, filename):
|
||||
f = open(filename, mode='r')
|
||||
for line in f:
|
||||
(key, value) = line.split("=")
|
||||
key = key.strip(" \n")
|
||||
value = value.strip(" \n")
|
||||
self.pref[key] = value
|
||||
try:
|
||||
(key, value) = line.split("=")
|
||||
key = key.strip(" \n")
|
||||
value = value.strip(" \n")
|
||||
self.pref[key] = value
|
||||
print 'Read option %s with a value of %s'%(key, value)
|
||||
except ValueError:
|
||||
print "Empty Line"
|
||||
f.close()
|
||||
|
||||
def save_to_file(self, filename):
|
||||
f = open(filename, mode='w')
|
||||
f.write('#%s preferences file\n\n'%PROGRAM_NAME)
|
||||
for key in self.pref.keys():
|
||||
f.write(key)
|
||||
f.write(' = ')
|
||||
f.write(self.pref[key])
|
||||
f.write(str(self.pref[key]))
|
||||
f.write('\n')
|
||||
f.flush()
|
||||
f.close()
|
||||
|
|
|
@ -211,9 +211,46 @@ class DelugeGTK(dbus.service.Object):
|
|||
self.abt.hide_all()
|
||||
|
||||
def show_pref_dialog(self, arg=None):
|
||||
#Try to get current settings from pref, if an error occurs, the default settings will be used:
|
||||
try:
|
||||
# Page 1
|
||||
self.prf_glade.get_widget("chk_use_tray").set_active(self.pref.get("enable_system_tray", bool))
|
||||
self.prf_glade.get_widget("chk_min_on_close").set_active(self.pref.get("close_to_tray", bool))
|
||||
self.prf_glade.get_widget("radio_ask_save").set_active(self.pref.get("ask_download_dir_each_torrent", bool))
|
||||
self.prf_glade.get_widget("download_path_button").set_filename(self.pref.get("default_download_path", str))
|
||||
self.prf_glade.get_widget("chk_autoseed").set_active(self.pref.get("auto_end_seeding", bool))
|
||||
self.prf_glade.get_widget("ratio_spinner").set_value(self.pref.get("end_seed_ratio", float))
|
||||
self.prf_glade.get_widget("chk_compact").set_active(self.pref.get("use_compact_storage", bool))
|
||||
# Page 2
|
||||
self.prf_glade.get_widget("spin_port_min").set_value(self.pref.get("tcp_port_range_lower", int))
|
||||
self.prf_glade.get_widget("spin_port_max").set_value(self.pref.get("tcp_port_range_upper", int))
|
||||
self.prf_glade.get_widget("spin_max_upload").set_value(self.pref.get("max_upload_rate", int))
|
||||
self.prf_glade.get_widget("spin_num_upload").set_value(self.pref.get("max_number_uploads", int))
|
||||
self.prf_glade.get_widget("spin_max_download").set_value(self.pref.get("max_download_rate", int))
|
||||
self.prf_glade.get_widget("spin_num_download").set_value(self.pref.get("max_number_downloads", int))
|
||||
except KeyError:
|
||||
pass
|
||||
self.prf.show_all()
|
||||
self.prf.run()
|
||||
result = self.prf.run()
|
||||
self.prf.hide_all()
|
||||
print result
|
||||
if result == 1:
|
||||
self.pref.set("enable_system_tray", self.prf_glade.get_widget("chk_use_tray").get_active())
|
||||
self.pref.set("close_to_tray", self.prf_glade.get_widget("chk_min_on_close").get_active())
|
||||
self.pref.set("ask_download_dir_each_torrent", self.prf_glade.get_widget("radio_ask_save").get_active())
|
||||
self.pref.set("default_download_path", self.prf_glade.get_widget("download_path_button").get_filename())
|
||||
self.pref.set("auto_end_seeding", self.prf_glade.get_widget("chk_autoseed").get_active())
|
||||
self.pref.set("end_seed_ratio", self.prf_glade.get_widget("ratio_spinner").get_value())
|
||||
self.pref.set("use_compact_storage", self.prf_glade.get_widget("chk_compact").get_active())
|
||||
|
||||
self.pref.set("tcp_port_range_lower", self.prf_glade.get_widget("spin_port_min").get_value())
|
||||
self.pref.set("tcp_port_range_upper", self.prf_glade.get_widget("spin_port_max").get_value())
|
||||
self.pref.set("max_upload_rate", self.prf_glade.get_widget("spin_max_upload").get_value())
|
||||
self.pref.set("max_number_uploads", self.prf_glade.get_widget("spin_num_upload").get_value())
|
||||
self.pref.set("max_download_rate", self.prf_glade.get_widget("spin_max_download").get_value())
|
||||
self.pref.set("max_number_downloads", self.prf_glade.get_widget("spin_num_download").get_value())
|
||||
|
||||
self.pref.save_to_file(self.conf_file)
|
||||
self.apply_prefs()
|
||||
|
||||
def show_plugin_dialog(self, arg=None):
|
||||
|
@ -221,9 +258,9 @@ class DelugeGTK(dbus.service.Object):
|
|||
|
||||
def tray_toggle(self, obj):
|
||||
if obj.get_active():
|
||||
self.wtree.get_widget("chk_min_on_close").set_sensitive(True)
|
||||
self.prf_glade.get_widget("chk_min_on_close").set_sensitive(True)
|
||||
else:
|
||||
self.wtree.get_widget("chk_min_on_close").set_sensitive(False)
|
||||
self.prf_glade.get_widget("chk_min_on_close").set_sensitive(False)
|
||||
|
||||
|
||||
|
||||
|
@ -321,9 +358,11 @@ class DelugeGTK(dbus.service.Object):
|
|||
self.store.remove(itr)
|
||||
if not self.store.iter_is_valid(itr):
|
||||
itr = None
|
||||
if tab == 0: #Details Paneself.text_summary_seeders = self.wtree.get_widget("summary_seeders")
|
||||
|
||||
state = self.manager.get_torrent_state(self.get_selected_torrent())
|
||||
if tab == 0: #Details Pane
|
||||
try:
|
||||
state = self.manager.get_torrent_state(self.get_selected_torrent())
|
||||
except deluge.InvalidUniqueIDError:
|
||||
return True
|
||||
self.text_summary_title.set_text(str(state["name"]))
|
||||
self.text_summary_total_size.set_text(dcommon.fsize(state["total_size"]))
|
||||
self.text_summary_pieces.set_text(str(state["pieces"]))
|
||||
|
|
Loading…
Reference in New Issue