[AutoAdd] Update gtkui from libglade to gtkbuilder

This commit is contained in:
DjLegolas 2017-08-29 11:29:39 +03:00 committed by Calum Lind
parent d190f149d1
commit 510a8b50b2
3 changed files with 483 additions and 464 deletions

View File

@ -1,116 +1,129 @@
<?xml version="1.0"?> <?xml version="1.0" encoding="UTF-8"?>
<glade-interface> <interface>
<!-- interface-requires gtk+ 2.16 --> <requires lib="gtk+" version="2.24"/>
<!-- interface-naming-policy toplevel-contextual --> <!-- interface-naming-policy toplevel-contextual -->
<widget class="GtkWindow" id="prefs_window"> <object class="GtkWindow" id="prefs_window">
<property name="can_focus">False</property>
<child> <child>
<widget class="GtkHBox" id="hbox9"> <object class="GtkHBox" id="hbox9">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property>
<child> <child>
<placeholder/> <placeholder/>
</child> </child>
<child> <child>
<widget class="GtkAlignment" id="prefs_box_1"> <object class="GtkAlignment" id="prefs_box_1">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property>
<child> <child>
<widget class="GtkVBox" id="prefs_box"> <object class="GtkVBox" id="prefs_box">
<property name="width_request">340</property> <property name="width_request">340</property>
<property name="height_request">390</property> <property name="height_request">390</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">3</property> <property name="border_width">3</property>
<property name="orientation">vertical</property>
<signal name="parent_set" handler="on_parent_set"/>
<child> <child>
<widget class="GtkFrame" id="frame1"> <object class="GtkFrame" id="frame1">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property> <property name="label_xalign">0</property>
<property name="shadow_type">none</property> <property name="shadow_type">none</property>
<child> <child>
<widget class="GtkVBox" id="watchdirs_vbox"> <object class="GtkVBox" id="watchdirs_vbox">
<property name="visible">True</property> <property name="visible">True</property>
<property name="orientation">vertical</property> <property name="can_focus">False</property>
<property name="homogeneous">True</property> <property name="homogeneous">True</property>
<child> <child>
<placeholder/> <placeholder/>
</child> </child>
</widget> </object>
</child> </child>
<child> <child type="label">
<widget class="GtkLabel" id="label1"> <object class="GtkLabel" id="label1">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">&lt;b&gt;Watch Folders:&lt;/b&gt;</property> <property name="label" translatable="yes">&lt;b&gt;Watch Folders:&lt;/b&gt;</property>
<property name="use_markup">True</property> <property name="use_markup">True</property>
</widget> </object>
<packing>
<property name="type">label_item</property>
</packing>
</child> </child>
</widget> </object>
<packing> <packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property> <property name="position">0</property>
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkHButtonBox" id="hbuttonbox1"> <object class="GtkHButtonBox" id="hbuttonbox1">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property>
<child> <child>
<widget class="GtkButton" id="add_button"> <object class="GtkButton" id="add_button">
<property name="label" translatable="no">gtk-add</property> <property name="label">gtk-add</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="can_default">True</property> <property name="can_default">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="use_stock">True</property> <property name="use_stock">True</property>
<signal name="clicked" handler="on_add_button_clicked"/> <signal name="clicked" handler="on_add_button_clicked" swapped="no"/>
</widget> </object>
<packing> <packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property> <property name="position">0</property>
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkButton" id="remove_button"> <object class="GtkButton" id="remove_button">
<property name="label" translatable="no">gtk-remove</property> <property name="label">gtk-remove</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="sensitive">False</property> <property name="sensitive">False</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="can_default">True</property> <property name="can_default">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="use_stock">True</property> <property name="use_stock">True</property>
<signal name="clicked" handler="on_remove_button_clicked"/> <signal name="clicked" handler="on_remove_button_clicked" swapped="no"/>
</widget> </object>
<packing> <packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkButton" id="edit_button"> <object class="GtkButton" id="edit_button">
<property name="label" translatable="no">gtk-edit</property> <property name="label">gtk-edit</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="sensitive">False</property> <property name="sensitive">False</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="can_default">True</property> <property name="can_default">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="use_stock">True</property> <property name="use_stock">True</property>
<signal name="clicked" handler="on_edit_button_clicked"/> <signal name="clicked" handler="on_edit_button_clicked" swapped="no"/>
</widget> </object>
<packing> <packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property> <property name="position">2</property>
</packing> </packing>
</child> </child>
</widget> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
</widget> </object>
</child> </child>
</widget> </object>
<packing> <packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
</widget> </object>
</child> </child>
</widget> </object>
</glade-interface> </interface>

View File

@ -18,7 +18,6 @@ import logging
import os import os
import gtk import gtk
import gtk.glade
import deluge.common import deluge.common
import deluge.component as component import deluge.component as component
@ -49,127 +48,128 @@ class OptionsDialog(object):
def show(self, options=None, watchdir_id=None): def show(self, options=None, watchdir_id=None):
if options is None: if options is None:
options = {} options = {}
self.glade = gtk.glade.XML(get_resource('autoadd_options.glade')) self.builder = gtk.Builder()
self.glade.signal_autoconnect({ self.builder.add_from_file(get_resource('autoadd_options.ui'))
self.builder.connect_signals({
'on_opts_add': self.on_add, 'on_opts_add': self.on_add,
'on_opts_apply': self.on_apply, 'on_opts_apply': self.on_apply,
'on_opts_cancel': self.on_cancel, 'on_opts_cancel': self.on_cancel,
'on_options_dialog_close': self.on_cancel, 'on_options_dialog_close': self.on_cancel,
'on_toggle_toggled': self.on_toggle_toggled 'on_toggle_toggled': self.on_toggle_toggled
}) })
self.dialog = self.glade.get_widget('options_dialog') self.dialog = self.builder.get_object('options_dialog')
self.dialog.set_transient_for(component.get('Preferences').pref_dialog) self.dialog.set_transient_for(component.get('Preferences').pref_dialog)
if watchdir_id: if watchdir_id:
# We have an existing watchdir_id, we are editing # We have an existing watchdir_id, we are editing
self.glade.get_widget('opts_add_button').hide() self.builder.get_object('opts_add_button').hide()
self.glade.get_widget('opts_apply_button').show() self.builder.get_object('opts_apply_button').show()
self.watchdir_id = watchdir_id self.watchdir_id = watchdir_id
else: else:
# We don't have an id, adding # We don't have an id, adding
self.glade.get_widget('opts_add_button').show() self.builder.get_object('opts_add_button').show()
self.glade.get_widget('opts_apply_button').hide() self.builder.get_object('opts_apply_button').hide()
self.watchdir_id = None self.watchdir_id = None
self.load_options(options) self.load_options(options)
self.dialog.run() self.dialog.run()
def load_options(self, options): def load_options(self, options):
self.glade.get_widget('enabled').set_active(options.get('enabled', True)) self.builder.get_object('enabled').set_active(options.get('enabled', True))
self.glade.get_widget('append_extension_toggle').set_active( self.builder.get_object('append_extension_toggle').set_active(
options.get('append_extension_toggle', False) options.get('append_extension_toggle', False)
) )
self.glade.get_widget('append_extension').set_text( self.builder.get_object('append_extension').set_text(
options.get('append_extension', '.added') options.get('append_extension', '.added')
) )
self.glade.get_widget('download_location_toggle').set_active( self.builder.get_object('download_location_toggle').set_active(
options.get('download_location_toggle', False) options.get('download_location_toggle', False)
) )
self.glade.get_widget('copy_torrent_toggle').set_active( self.builder.get_object('copy_torrent_toggle').set_active(
options.get('copy_torrent_toggle', False) options.get('copy_torrent_toggle', False)
) )
self.glade.get_widget('delete_copy_torrent_toggle').set_active( self.builder.get_object('delete_copy_torrent_toggle').set_active(
options.get('delete_copy_torrent_toggle', False) options.get('delete_copy_torrent_toggle', False)
) )
self.glade.get_widget('seed_mode').set_active( self.builder.get_object('seed_mode').set_active(
options.get('seed_mode', False) options.get('seed_mode', False)
) )
self.accounts.clear() self.accounts.clear()
self.labels.clear() self.labels.clear()
combobox = self.glade.get_widget('OwnerCombobox') combobox = self.builder.get_object('OwnerCombobox')
combobox_render = gtk.CellRendererText() combobox_render = gtk.CellRendererText()
combobox.pack_start(combobox_render, True) combobox.pack_start(combobox_render, True)
combobox.add_attribute(combobox_render, 'text', 0) combobox.add_attribute(combobox_render, 'text', 0)
combobox.set_model(self.accounts) combobox.set_model(self.accounts)
label_widget = self.glade.get_widget('label') label_widget = self.builder.get_object('label')
label_widget.child.set_text(options.get('label', '')) label_widget.child.set_text(options.get('label', ''))
label_widget.set_model(self.labels) label_widget.set_model(self.labels)
label_widget.set_text_column(0) label_widget.set_entry_text_column(0)
self.glade.get_widget('label_toggle').set_active(options.get('label_toggle', False)) self.builder.get_object('label_toggle').set_active(options.get('label_toggle', False))
for spin_id in self.spin_ids + self.spin_int_ids: for spin_id in self.spin_ids + self.spin_int_ids:
self.glade.get_widget(spin_id).set_value(options.get(spin_id, 0)) self.builder.get_object(spin_id).set_value(options.get(spin_id, 0))
self.glade.get_widget(spin_id + '_toggle').set_active(options.get(spin_id + '_toggle', False)) self.builder.get_object(spin_id + '_toggle').set_active(options.get(spin_id + '_toggle', False))
for chk_id in self.chk_ids: for chk_id in self.chk_ids:
self.glade.get_widget(chk_id).set_active(bool(options.get(chk_id, True))) self.builder.get_object(chk_id).set_active(bool(options.get(chk_id, True)))
self.glade.get_widget(chk_id + '_toggle').set_active(options.get(chk_id + '_toggle', False)) self.builder.get_object(chk_id + '_toggle').set_active(options.get(chk_id + '_toggle', False))
if not options.get('add_paused', True): if not options.get('add_paused', True):
self.glade.get_widget('isnt_add_paused').set_active(True) self.builder.get_object('isnt_add_paused').set_active(True)
if not options.get('queue_to_top', True): if not options.get('queue_to_top', True):
self.glade.get_widget('isnt_queue_to_top').set_active(True) self.builder.get_object('isnt_queue_to_top').set_active(True)
if not options.get('auto_managed', True): if not options.get('auto_managed', True):
self.glade.get_widget('isnt_auto_managed').set_active(True) self.builder.get_object('isnt_auto_managed').set_active(True)
for field in ['move_completed_path', 'path', 'download_location', for field in ['move_completed_path', 'path', 'download_location',
'copy_torrent']: 'copy_torrent']:
if client.is_localhost(): if client.is_localhost():
self.glade.get_widget(field + '_chooser').set_current_folder( self.builder.get_object(field + '_chooser').set_current_folder(
options.get(field, os.path.expanduser('~')) options.get(field, os.path.expanduser('~'))
) )
self.glade.get_widget(field + '_chooser').show() self.builder.get_object(field + '_chooser').show()
self.glade.get_widget(field + '_entry').hide() self.builder.get_object(field + '_entry').hide()
else: else:
self.glade.get_widget(field + '_entry').set_text( self.builder.get_object(field + '_entry').set_text(
options.get(field, '') options.get(field, '')
) )
self.glade.get_widget(field + '_entry').show() self.builder.get_object(field + '_entry').show()
self.glade.get_widget(field + '_chooser').hide() self.builder.get_object(field + '_chooser').hide()
self.set_sensitive() self.set_sensitive()
def on_core_config(config): def on_core_config(config):
if client.is_localhost(): if client.is_localhost():
self.glade.get_widget('download_location_chooser').set_current_folder( self.builder.get_object('download_location_chooser').set_current_folder(
options.get('download_location', config['download_location']) options.get('download_location', config['download_location'])
) )
if options.get('move_completed_toggle', config['move_completed']): if options.get('move_completed_toggle', config['move_completed']):
self.glade.get_widget('move_completed_toggle').set_active(True) self.builder.get_object('move_completed_toggle').set_active(True)
self.glade.get_widget('move_completed_path_chooser').set_current_folder( self.builder.get_object('move_completed_path_chooser').set_current_folder(
options.get('move_completed_path', config['move_completed_path']) options.get('move_completed_path', config['move_completed_path'])
) )
if options.get('copy_torrent_toggle', config['copy_torrent_file']): if options.get('copy_torrent_toggle', config['copy_torrent_file']):
self.glade.get_widget('copy_torrent_toggle').set_active(True) self.builder.get_object('copy_torrent_toggle').set_active(True)
self.glade.get_widget('copy_torrent_chooser').set_current_folder( self.builder.get_object('copy_torrent_chooser').set_current_folder(
options.get('copy_torrent', config['torrentfiles_location']) options.get('copy_torrent', config['torrentfiles_location'])
) )
else: else:
self.glade.get_widget('download_location_entry').set_text( self.builder.get_object('download_location_entry').set_text(
options.get('download_location', config['download_location']) options.get('download_location', config['download_location'])
) )
if options.get('move_completed_toggle', config['move_completed']): if options.get('move_completed_toggle', config['move_completed']):
self.glade.get_widget('move_completed_toggle').set_active( self.builder.get_object('move_completed_toggle').set_active(
options.get('move_completed_toggle', False) options.get('move_completed_toggle', False)
) )
self.glade.get_widget('move_completed_path_entry').set_text( self.builder.get_object('move_completed_path_entry').set_text(
options.get('move_completed_path', config['move_completed_path']) options.get('move_completed_path', config['move_completed_path'])
) )
if options.get('copy_torrent_toggle', config['copy_torrent_file']): if options.get('copy_torrent_toggle', config['copy_torrent_file']):
self.glade.get_widget('copy_torrent_toggle').set_active(True) self.builder.get_object('copy_torrent_toggle').set_active(True)
self.glade.get_widget('copy_torrent_entry').set_text( self.builder.get_object('copy_torrent_entry').set_text(
options.get('copy_torrent', config['torrentfiles_location']) options.get('copy_torrent', config['torrentfiles_location'])
) )
if options.get('delete_copy_torrent_toggle', config['del_copy_torrent_file']): if options.get('delete_copy_torrent_toggle', config['del_copy_torrent_file']):
self.glade.get_widget('delete_copy_torrent_toggle').set_active(True) self.builder.get_object('delete_copy_torrent_toggle').set_active(True)
if not options: if not options:
client.core.get_config().addCallback(on_core_config) client.core.get_config().addCallback(on_core_config)
@ -184,33 +184,33 @@ class OptionsDialog(object):
) )
if account['username'] == owner: if account['username'] == owner:
selected_iter = acc_iter selected_iter = acc_iter
self.glade.get_widget('OwnerCombobox').set_active_iter(selected_iter) self.builder.get_object('OwnerCombobox').set_active_iter(selected_iter)
def on_accounts_failure(failure): def on_accounts_failure(failure):
log.debug('Failed to get accounts!!! %s', failure) log.debug('Failed to get accounts!!! %s', failure)
acc_iter = self.accounts.append() acc_iter = self.accounts.append()
self.accounts.set_value(acc_iter, 0, client.get_auth_user()) self.accounts.set_value(acc_iter, 0, client.get_auth_user())
self.glade.get_widget('OwnerCombobox').set_active(0) self.builder.get_object('OwnerCombobox').set_active(0)
self.glade.get_widget('OwnerCombobox').set_sensitive(False) self.builder.get_object('OwnerCombobox').set_sensitive(False)
def on_labels(labels): def on_labels(labels):
log.debug('Got Labels: %s', labels) log.debug('Got Labels: %s', labels)
for label in labels: for label in labels:
self.labels.set_value(self.labels.append(), 0, label) self.labels.set_value(self.labels.append(), 0, label)
label_widget = self.glade.get_widget('label') label_widget = self.builder.get_object('label')
label_widget.set_model(self.labels) label_widget.set_model(self.labels)
label_widget.set_text_column(0) label_widget.set_entry_text_column(0)
def on_failure(failure): def on_failure(failure):
log.exception(failure) log.exception(failure)
def on_get_enabled_plugins(result): def on_get_enabled_plugins(result):
if 'Label' in result: if 'Label' in result:
self.glade.get_widget('label_frame').show() self.builder.get_object('label_frame').show()
client.label.get_labels().addCallback(on_labels).addErrback(on_failure) client.label.get_labels().addCallback(on_labels).addErrback(on_failure)
else: else:
self.glade.get_widget('label_frame').hide() self.builder.get_object('label_frame').hide()
self.glade.get_widget('label_toggle').set_active(False) self.builder.get_object('label_toggle').set_active(False)
client.core.get_enabled_plugins().addCallback(on_get_enabled_plugins) client.core.get_enabled_plugins().addCallback(on_get_enabled_plugins)
if client.get_auth_level() == deluge.common.AUTH_LEVEL_ADMIN: if client.get_auth_level() == deluge.common.AUTH_LEVEL_ADMIN:
@ -220,8 +220,8 @@ class OptionsDialog(object):
else: else:
acc_iter = self.accounts.append() acc_iter = self.accounts.append()
self.accounts.set_value(acc_iter, 0, client.get_auth_user()) self.accounts.set_value(acc_iter, 0, client.get_auth_user())
self.glade.get_widget('OwnerCombobox').set_active(0) self.builder.get_object('OwnerCombobox').set_active(0)
self.glade.get_widget('OwnerCombobox').set_sensitive(False) self.builder.get_object('OwnerCombobox').set_sensitive(False)
def set_sensitive(self): def set_sensitive(self):
maintoggles = ['download_location', 'append_extension', maintoggles = ['download_location', 'append_extension',
@ -230,49 +230,49 @@ class OptionsDialog(object):
'max_upload_slots', 'add_paused', 'auto_managed', 'max_upload_slots', 'add_paused', 'auto_managed',
'stop_at_ratio', 'queue_to_top', 'copy_torrent'] 'stop_at_ratio', 'queue_to_top', 'copy_torrent']
for maintoggle in maintoggles: for maintoggle in maintoggles:
self.on_toggle_toggled(self.glade.get_widget(maintoggle + '_toggle')) self.on_toggle_toggled(self.builder.get_object(maintoggle + '_toggle'))
def on_toggle_toggled(self, tb): def on_toggle_toggled(self, tb):
toggle = str(tb.name).replace('_toggle', '') toggle = str(tb.name).replace('_toggle', '')
isactive = tb.get_active() isactive = tb.get_active()
if toggle == 'download_location': if toggle == 'download_location':
self.glade.get_widget('download_location_chooser').set_sensitive(isactive) self.builder.get_object('download_location_chooser').set_sensitive(isactive)
self.glade.get_widget('download_location_entry').set_sensitive(isactive) self.builder.get_object('download_location_entry').set_sensitive(isactive)
elif toggle == 'append_extension': elif toggle == 'append_extension':
self.glade.get_widget('append_extension').set_sensitive(isactive) self.builder.get_object('append_extension').set_sensitive(isactive)
elif toggle == 'copy_torrent': elif toggle == 'copy_torrent':
self.glade.get_widget('copy_torrent_entry').set_sensitive(isactive) self.builder.get_object('copy_torrent_entry').set_sensitive(isactive)
self.glade.get_widget('copy_torrent_chooser').set_sensitive(isactive) self.builder.get_object('copy_torrent_chooser').set_sensitive(isactive)
self.glade.get_widget('delete_copy_torrent_toggle').set_sensitive(isactive) self.builder.get_object('delete_copy_torrent_toggle').set_sensitive(isactive)
elif toggle == 'move_completed': elif toggle == 'move_completed':
self.glade.get_widget('move_completed_path_chooser').set_sensitive(isactive) self.builder.get_object('move_completed_path_chooser').set_sensitive(isactive)
self.glade.get_widget('move_completed_path_entry').set_sensitive(isactive) self.builder.get_object('move_completed_path_entry').set_sensitive(isactive)
self.glade.get_widget('move_completed').set_active(isactive) self.builder.get_object('move_completed').set_active(isactive)
elif toggle == 'label': elif toggle == 'label':
self.glade.get_widget('label').set_sensitive(isactive) self.builder.get_object('label').set_sensitive(isactive)
elif toggle == 'max_download_speed': elif toggle == 'max_download_speed':
self.glade.get_widget('max_download_speed').set_sensitive(isactive) self.builder.get_object('max_download_speed').set_sensitive(isactive)
elif toggle == 'max_upload_speed': elif toggle == 'max_upload_speed':
self.glade.get_widget('max_upload_speed').set_sensitive(isactive) self.builder.get_object('max_upload_speed').set_sensitive(isactive)
elif toggle == 'max_connections': elif toggle == 'max_connections':
self.glade.get_widget('max_connections').set_sensitive(isactive) self.builder.get_object('max_connections').set_sensitive(isactive)
elif toggle == 'max_upload_slots': elif toggle == 'max_upload_slots':
self.glade.get_widget('max_upload_slots').set_sensitive(isactive) self.builder.get_object('max_upload_slots').set_sensitive(isactive)
elif toggle == 'add_paused': elif toggle == 'add_paused':
self.glade.get_widget('add_paused').set_sensitive(isactive) self.builder.get_object('add_paused').set_sensitive(isactive)
self.glade.get_widget('isnt_add_paused').set_sensitive(isactive) self.builder.get_object('isnt_add_paused').set_sensitive(isactive)
elif toggle == 'queue_to_top': elif toggle == 'queue_to_top':
self.glade.get_widget('queue_to_top').set_sensitive(isactive) self.builder.get_object('queue_to_top').set_sensitive(isactive)
self.glade.get_widget('isnt_queue_to_top').set_sensitive(isactive) self.builder.get_object('isnt_queue_to_top').set_sensitive(isactive)
elif toggle == 'auto_managed': elif toggle == 'auto_managed':
self.glade.get_widget('auto_managed').set_sensitive(isactive) self.builder.get_object('auto_managed').set_sensitive(isactive)
self.glade.get_widget('isnt_auto_managed').set_sensitive(isactive) self.builder.get_object('isnt_auto_managed').set_sensitive(isactive)
elif toggle == 'stop_at_ratio': elif toggle == 'stop_at_ratio':
self.glade.get_widget('remove_at_ratio_toggle').set_active(isactive) self.builder.get_object('remove_at_ratio_toggle').set_active(isactive)
self.glade.get_widget('stop_ratio_toggle').set_active(isactive) self.builder.get_object('stop_ratio_toggle').set_active(isactive)
self.glade.get_widget('stop_at_ratio').set_active(isactive) self.builder.get_object('stop_at_ratio').set_active(isactive)
self.glade.get_widget('stop_ratio').set_sensitive(isactive) self.builder.get_object('stop_ratio').set_sensitive(isactive)
self.glade.get_widget('remove_at_ratio').set_sensitive(isactive) self.builder.get_object('remove_at_ratio').set_sensitive(isactive)
def on_apply(self, event=None): def on_apply(self, event=None):
try: try:
@ -304,43 +304,43 @@ class OptionsDialog(object):
def generate_opts(self): def generate_opts(self):
# generate options dict based on gtk objects # generate options dict based on gtk objects
options = {} options = {}
options['enabled'] = self.glade.get_widget('enabled').get_active() options['enabled'] = self.builder.get_object('enabled').get_active()
if client.is_localhost(): if client.is_localhost():
options['path'] = self.glade.get_widget('path_chooser').get_filename() options['path'] = self.builder.get_object('path_chooser').get_filename()
options['download_location'] = self.glade.get_widget( options['download_location'] = self.builder.get_object(
'download_location_chooser').get_filename() 'download_location_chooser').get_filename()
options['move_completed_path'] = self.glade.get_widget( options['move_completed_path'] = self.builder.get_object(
'move_completed_path_chooser').get_filename() 'move_completed_path_chooser').get_filename()
options['copy_torrent'] = self.glade.get_widget( options['copy_torrent'] = self.builder.get_object(
'copy_torrent_chooser').get_filename() 'copy_torrent_chooser').get_filename()
else: else:
options['path'] = self.glade.get_widget('path_entry').get_text() options['path'] = self.builder.get_object('path_entry').get_text()
options['download_location'] = self.glade.get_widget( options['download_location'] = self.builder.get_object(
'download_location_entry').get_text() 'download_location_entry').get_text()
options['move_completed_path'] = self.glade.get_widget( options['move_completed_path'] = self.builder.get_object(
'move_completed_path_entry').get_text() 'move_completed_path_entry').get_text()
options['copy_torrent'] = self.glade.get_widget( options['copy_torrent'] = self.builder.get_object(
'copy_torrent_entry').get_text() 'copy_torrent_entry').get_text()
options['label'] = self.glade.get_widget('label').child.get_text().lower() options['label'] = self.builder.get_object('label').child.get_text().lower()
options['append_extension'] = self.glade.get_widget('append_extension').get_text() options['append_extension'] = self.builder.get_object('append_extension').get_text()
options['owner'] = self.accounts[ options['owner'] = self.accounts[
self.glade.get_widget('OwnerCombobox').get_active()][0] self.builder.get_object('OwnerCombobox').get_active()][0]
for key in ['append_extension_toggle', 'download_location_toggle', for key in ['append_extension_toggle', 'download_location_toggle',
'label_toggle', 'copy_torrent_toggle', 'label_toggle', 'copy_torrent_toggle',
'delete_copy_torrent_toggle', 'seed_mode']: 'delete_copy_torrent_toggle', 'seed_mode']:
options[key] = self.glade.get_widget(key).get_active() options[key] = self.builder.get_object(key).get_active()
for spin_id in self.spin_ids: for spin_id in self.spin_ids:
options[spin_id] = self.glade.get_widget(spin_id).get_value() options[spin_id] = self.builder.get_object(spin_id).get_value()
options[spin_id + '_toggle'] = self.glade.get_widget(spin_id + '_toggle').get_active() options[spin_id + '_toggle'] = self.builder.get_object(spin_id + '_toggle').get_active()
for spin_int_id in self.spin_int_ids: for spin_int_id in self.spin_int_ids:
options[spin_int_id] = self.glade.get_widget(spin_int_id).get_value_as_int() options[spin_int_id] = self.builder.get_object(spin_int_id).get_value_as_int()
options[spin_int_id + '_toggle'] = self.glade.get_widget(spin_int_id + '_toggle').get_active() options[spin_int_id + '_toggle'] = self.builder.get_object(spin_int_id + '_toggle').get_active()
for chk_id in self.chk_ids: for chk_id in self.chk_ids:
options[chk_id] = self.glade.get_widget(chk_id).get_active() options[chk_id] = self.builder.get_object(chk_id).get_active()
options[chk_id + '_toggle'] = self.glade.get_widget(chk_id + '_toggle').get_active() options[chk_id + '_toggle'] = self.builder.get_object(chk_id + '_toggle').get_active()
if options['copy_torrent_toggle'] and options['path'] == options['copy_torrent']: if options['copy_torrent_toggle'] and options['path'] == options['copy_torrent']:
raise IncompatibleOption(_('"Watch Folder" directory and "Copy of .torrent' raise IncompatibleOption(_('"Watch Folder" directory and "Copy of .torrent'
@ -351,12 +351,9 @@ class OptionsDialog(object):
class GtkUI(GtkPluginBase): class GtkUI(GtkPluginBase):
def enable(self): def enable(self):
self.glade = gtk.glade.XML(get_resource('config.glade')) self.builder = gtk.Builder()
self.glade.signal_autoconnect({ self.builder.add_from_file(get_resource('config.ui'))
'on_add_button_clicked': self.on_add_button_clicked, self.builder.connect_signals(self)
'on_edit_button_clicked': self.on_edit_button_clicked,
'on_remove_button_clicked': self.on_remove_button_clicked
})
self.opts_dialog = OptionsDialog() self.opts_dialog = OptionsDialog()
component.get('PluginManager').register_hook( component.get('PluginManager').register_hook(
@ -371,7 +368,7 @@ class GtkUI(GtkPluginBase):
self.watchdirs = {} self.watchdirs = {}
vbox = self.glade.get_widget('watchdirs_vbox') vbox = self.builder.get_object('watchdirs_vbox')
sw = gtk.ScrolledWindow() sw = gtk.ScrolledWindow()
sw.set_shadow_type(gtk.SHADOW_ETCHED_IN) sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
@ -389,7 +386,7 @@ class GtkUI(GtkPluginBase):
sw.add(self.treeView) sw.add(self.treeView)
sw.show_all() sw.show_all()
component.get('Preferences').add_page( component.get('Preferences').add_page(
_('AutoAdd'), self.glade.get_widget('prefs_box') _('AutoAdd'), self.builder.get_object('prefs_box')
) )
def disable(self): def disable(self):
@ -468,11 +465,11 @@ class GtkUI(GtkPluginBase):
def on_listitem_activated(self, treeview): def on_listitem_activated(self, treeview):
tree, tree_id = self.treeView.get_selection().get_selected() tree, tree_id = self.treeView.get_selection().get_selected()
if tree_id: if tree_id:
self.glade.get_widget('edit_button').set_sensitive(True) self.builder.get_object('edit_button').set_sensitive(True)
self.glade.get_widget('remove_button').set_sensitive(True) self.builder.get_object('remove_button').set_sensitive(True)
else: else:
self.glade.get_widget('edit_button').set_sensitive(False) self.builder.get_object('edit_button').set_sensitive(False)
self.glade.get_widget('remove_button').set_sensitive(False) self.builder.get_object('remove_button').set_sensitive(False)
def on_apply_prefs(self): def on_apply_prefs(self):
log.debug('applying prefs for AutoAdd') log.debug('applying prefs for AutoAdd')
@ -496,7 +493,7 @@ class GtkUI(GtkPluginBase):
watchdir.get('owner', 'localclient'), watchdir['path'] watchdir.get('owner', 'localclient'), watchdir['path']
]) ])
# Workaround for cached glade signal appearing when re-enabling plugin in same session # Workaround for cached glade signal appearing when re-enabling plugin in same session
if self.glade.get_widget('edit_button'): if self.builder.get_object('edit_button'):
# Disable the remove and edit buttons, because nothing in the store is selected # Disable the remove and edit buttons, because nothing in the store is selected
self.glade.get_widget('remove_button').set_sensitive(False) self.builder.get_object('remove_button').set_sensitive(False)
self.glade.get_widget('edit_button').set_sensitive(False) self.builder.get_object('edit_button').set_sensitive(False)