From f0316d3e316de9820a46ae06d1f61debcd521823 Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Sun, 6 Aug 2017 13:03:55 +0300 Subject: [PATCH] [Blocklist] Update gtkui from libglade to gtkbuilder --- ...blocklist_pref.glade => blocklist_pref.ui} | 281 +++++++++--------- .../deluge/plugins/blocklist/gtkui.py | 68 ++--- 2 files changed, 168 insertions(+), 181 deletions(-) rename deluge/plugins/Blocklist/deluge/plugins/blocklist/data/{blocklist_pref.glade => blocklist_pref.ui} (79%) diff --git a/deluge/plugins/Blocklist/deluge/plugins/blocklist/data/blocklist_pref.glade b/deluge/plugins/Blocklist/deluge/plugins/blocklist/data/blocklist_pref.ui similarity index 79% rename from deluge/plugins/Blocklist/deluge/plugins/blocklist/data/blocklist_pref.glade rename to deluge/plugins/Blocklist/deluge/plugins/blocklist/data/blocklist_pref.ui index 914587204..ac5da9db7 100644 --- a/deluge/plugins/Blocklist/deluge/plugins/blocklist/data/blocklist_pref.glade +++ b/deluge/plugins/Blocklist/deluge/plugins/blocklist/data/blocklist_pref.ui @@ -1,36 +1,43 @@ - - + + - + + 1 + 100 + 1 + 1 + 10 + + False - + True False 5 - + True False 0 none - + True False 12 - + True False 5 - + True False URL: - + False False @@ -38,7 +45,7 @@ - + True True @@ -46,30 +53,27 @@ False True True - + True True 1 - + - + - - + + True False 5 <b>General</b> True - - - label_item - + - + False False @@ -77,72 +81,72 @@ - + True False 0 none - + True False 12 - + True False 5 - + True False 3 5 5 - + True False 0 Days - + 2 3 GTK_FILL - + - + True True False False True True - 1 1 100 1 10 0 - + adjustment1 + 1 2 GTK_FILL - + - + True False 0 Check for new list every: - + GTK_FILL - + - + False False @@ -150,37 +154,33 @@ - + Import blocklist on startup True True False - False True - + False False 1 - + - + - - + + True False 5 <b>Settings</b> True - - - label_item - + - + False False @@ -188,45 +188,44 @@ - + True False 0 none - + True False 0 0 12 - + True False - + True False - + True True True - Download the blocklist file if necessary and import the file. - False - + Download the blocklist file if necessary and import the file. + - + True False 5 - + True False gtk-missing-image - + False False @@ -234,20 +233,20 @@ - + True False Check Download and Import - + False False 1 - + - + False False @@ -255,24 +254,23 @@ - + True True True - Download a new blocklist file and import it. - False - + Download a new blocklist file and import it. + - + True False 5 - + True False gtk-missing-image - + False False @@ -280,27 +278,27 @@ - + True False Force Download and Import - + False False 1 - + - + False False 1 - + True True @@ -308,36 +306,33 @@ - + False - Blocklist is up to date + Blocklist is up to date 0.15000000596046448 2 gtk-yes - + True True 1 - + - + - - + + True False 5 <b>Options</b> True - - - label_item - + - + False False @@ -345,26 +340,26 @@ - + True False 0 none - + True False 5 12 - + True False - + True False - + True True @@ -372,18 +367,18 @@ - + True False 4 2 5 - + True False 0 - + 1 2 @@ -392,11 +387,11 @@ - + True False 0 - + 1 2 @@ -405,11 +400,11 @@ - + True False 0 - + 1 2 @@ -418,23 +413,23 @@ - + True False 0 - + 1 2 - + True False 0 URL: - + 3 4 @@ -442,12 +437,12 @@ - + True False 0 Type: - + 2 3 @@ -455,12 +450,12 @@ - + True False 0 Date: - + 1 2 @@ -468,39 +463,36 @@ - + True False 0 File Size: - + GTK_FILL - + False False 1 - + - + - - + + True False <b>Info</b> True - - - label_item - + - + False False @@ -508,35 +500,35 @@ - + True False 0 none - + True False 12 - + True False - + True True automatic automatic - + True True False False - + - + True True @@ -544,21 +536,20 @@ - + True False True start - + gtk-add True True True - False True - - + + False False @@ -566,51 +557,47 @@ - + gtk-delete True True True - False True - - + + False False 1 - + False True 1 - + - + - - + + True False <b>Whitelist</b> True - - - label_item - + - + True True 4 - + - - + + diff --git a/deluge/plugins/Blocklist/deluge/plugins/blocklist/gtkui.py b/deluge/plugins/Blocklist/deluge/plugins/blocklist/gtkui.py index cf3d58324..390c928a5 100644 --- a/deluge/plugins/Blocklist/deluge/plugins/blocklist/gtkui.py +++ b/deluge/plugins/Blocklist/deluge/plugins/blocklist/gtkui.py @@ -13,7 +13,6 @@ import logging from datetime import datetime import gtk -import gtk.glade import deluge.common import deluge.component as component @@ -63,9 +62,9 @@ class GtkUI(GtkPluginBase): def _on_get_status(status): if status['state'] == 'Downloading': self.table_info.hide() - self.glade.get_widget('button_check_download').set_sensitive(False) - self.glade.get_widget('button_force_download').set_sensitive(False) - self.glade.get_widget('image_up_to_date').hide() + self.builder.get_object('button_check_download').set_sensitive(False) + self.builder.get_object('button_force_download').set_sensitive(False) + self.builder.get_object('image_up_to_date').hide() self.status_item.set_text( 'Downloading %.2f%%' % (status['file_progress'] * 100)) @@ -75,9 +74,9 @@ class GtkUI(GtkPluginBase): elif status['state'] == 'Importing': self.table_info.hide() - self.glade.get_widget('button_check_download').set_sensitive(False) - self.glade.get_widget('button_force_download').set_sensitive(False) - self.glade.get_widget('image_up_to_date').hide() + self.builder.get_object('button_check_download').set_sensitive(False) + self.builder.get_object('button_force_download').set_sensitive(False) + self.builder.get_object('image_up_to_date').hide() self.status_item.set_text( 'Importing ' + str(status['num_blocked'])) @@ -87,22 +86,22 @@ class GtkUI(GtkPluginBase): elif status['state'] == 'Idle': self.progress_bar.hide() - self.glade.get_widget('button_check_download').set_sensitive(True) - self.glade.get_widget('button_force_download').set_sensitive(True) + self.builder.get_object('button_check_download').set_sensitive(True) + self.builder.get_object('button_force_download').set_sensitive(True) if status['up_to_date']: - self.glade.get_widget('image_up_to_date').show() + self.builder.get_object('image_up_to_date').show() else: - self.glade.get_widget('image_up_to_date').hide() + self.builder.get_object('image_up_to_date').hide() self.table_info.show() self.status_item.set_text('%(num_blocked)s/%(num_whited)s' % status) - self.glade.get_widget('label_filesize').set_text( + self.builder.get_object('label_filesize').set_text( deluge.common.fsize(status['file_size'])) - self.glade.get_widget('label_modified').set_text( + self.builder.get_object('label_modified').set_text( datetime.fromtimestamp(status['file_date']).strftime('%c')) - self.glade.get_widget('label_type').set_text(status['file_type']) - self.glade.get_widget('label_url').set_text( + self.builder.get_object('label_type').set_text(status['file_type']) + self.builder.get_object('label_url').set_text( status['file_url']) client.blocklist.get_status().addCallback(_on_get_status) @@ -110,18 +109,18 @@ class GtkUI(GtkPluginBase): def _on_show_prefs(self): def _on_get_config(config): log.trace('Loaded config: %s', config) - self.glade.get_widget('entry_url').set_text(config['url']) - self.glade.get_widget('spin_check_days').set_value(config['check_after_days']) - self.glade.get_widget('chk_import_on_start').set_active(config['load_on_start']) + self.builder.get_object('entry_url').set_text(config['url']) + self.builder.get_object('spin_check_days').set_value(config['check_after_days']) + self.builder.get_object('chk_import_on_start').set_active(config['load_on_start']) self.populate_whitelist(config['whitelisted']) client.blocklist.get_config().addCallback(_on_get_config) def _on_apply_prefs(self): config = {} - config['url'] = self.glade.get_widget('entry_url').get_text().strip() - config['check_after_days'] = self.glade.get_widget('spin_check_days').get_value_as_int() - config['load_on_start'] = self.glade.get_widget('chk_import_on_start').get_active() + config['url'] = self.builder.get_object('entry_url').get_text().strip() + config['check_after_days'] = self.builder.get_object('spin_check_days').get_value_as_int() + config['load_on_start'] = self.builder.get_object('chk_import_on_start').get_active() config['whitelisted'] = [ip[0] for ip in self.whitelist_model if ip[0] != 'IP HERE'] client.blocklist.set_config(config) @@ -139,11 +138,12 @@ class GtkUI(GtkPluginBase): def load_preferences_page(self): """Initializes the preferences page and adds it to the preferences dialog""" # Load the preferences page - self.glade = gtk.glade.XML(common.get_resource('blocklist_pref.glade')) + self.builder = gtk.Builder() + self.builder.add_from_file(common.get_resource('blocklist_pref.ui')) - self.whitelist_frame = self.glade.get_widget('whitelist_frame') - self.progress_bar = self.glade.get_widget('progressbar') - self.table_info = self.glade.get_widget('table_info') + self.whitelist_frame = self.builder.get_object('whitelist_frame') + self.progress_bar = self.builder.get_object('progressbar') + self.table_info = self.builder.get_object('table_info') # Hide the progress bar initially self.progress_bar.hide() @@ -152,7 +152,7 @@ class GtkUI(GtkPluginBase): # Create the whitelisted model self.build_whitelist_model_treeview() - self.glade.signal_autoconnect({ + self.builder.connect_signals({ 'on_button_check_download_clicked': self._on_button_check_download_clicked, 'on_button_force_download_clicked': self._on_button_force_download_clicked, 'on_whitelist_add_clicked': (self.on_add_button_clicked, @@ -162,10 +162,10 @@ class GtkUI(GtkPluginBase): }) # Set button icons - self.glade.get_widget('image_download').set_from_file( + self.builder.get_object('image_download').set_from_file( common.get_resource('blocklist_download24.png')) - self.glade.get_widget('image_import').set_from_file( + self.builder.get_object('image_import').set_from_file( common.get_resource('blocklist_import24.png')) # Update the preferences page with config values from the core @@ -174,10 +174,10 @@ class GtkUI(GtkPluginBase): # Add the page to the preferences dialog self.plugin.add_preferences_page( _('Blocklist'), - self.glade.get_widget('blocklist_prefs_box')) + self.builder.get_object('blocklist_prefs_box')) def build_whitelist_model_treeview(self): - self.whitelist_treeview = self.glade.get_widget('whitelist_treeview') + self.whitelist_treeview = self.builder.get_object('whitelist_treeview') treeview_selection = self.whitelist_treeview.get_selection() treeview_selection.connect( 'changed', self.on_whitelist_treeview_selection_changed @@ -207,11 +207,11 @@ class GtkUI(GtkPluginBase): def on_whitelist_treeview_selection_changed(self, selection): model, selected_connection_iter = selection.get_selected() if selected_connection_iter: - self.glade.get_widget('whitelist_delete').set_property('sensitive', - True) + self.builder.get_object('whitelist_delete').set_property('sensitive', + True) else: - self.glade.get_widget('whitelist_delete').set_property('sensitive', - False) + self.builder.get_object('whitelist_delete').set_property('sensitive', + False) def on_add_button_clicked(self, widget, treeview): model = treeview.get_model()