[Extractor] Update gtkui from libglade to gtkbuilder

This commit is contained in:
DjLegolas 2017-08-06 13:04:55 +03:00 committed by Calum Lind
parent 1259eca8ad
commit 470490769f
2 changed files with 63 additions and 45 deletions

View File

@ -1,31 +1,37 @@
<?xml version="1.0"?> <?xml version="1.0" encoding="UTF-8"?>
<glade-interface> <interface>
<!-- interface-requires gtk+ 2.6 --> <requires lib="gtk+" version="2.24"/>
<!-- interface-naming-policy toplevel-contextual --> <!-- interface-naming-policy toplevel-contextual -->
<widget class="GtkWindow" id="window1"> <object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<child> <child>
<widget class="GtkVBox" id="extractor_prefs_box"> <object class="GtkVBox" id="extractor_prefs_box">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">5</property> <property name="spacing">5</property>
<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="vbox1"> <object class="GtkVBox" id="vbox1">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">5</property> <property name="border_width">5</property>
<property name="spacing">5</property> <property name="spacing">5</property>
<child> <child>
<widget class="GtkHBox" id="hbox1"> <object class="GtkHBox" id="hbox1">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">5</property> <property name="spacing">5</property>
<child> <child>
<widget class="GtkLabel" id="label2"> <object class="GtkLabel" id="label2">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Extract to:</property> <property name="label" translatable="yes">Extract to:</property>
</widget> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
@ -33,31 +39,43 @@
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkHBox" id="hbox2"> <object class="GtkHBox" id="hbox2">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property>
<child> <child>
<widget class="GtkFileChooserButton" id="folderchooser_path"> <object class="GtkFileChooserButton" id="folderchooser_path">
<property name="can_focus">False</property>
<property name="action">select-folder</property> <property name="action">select-folder</property>
<property name="title" translatable="yes">Select A Folder</property> <property name="title" translatable="yes">Select A Folder</property>
</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="GtkEntry" id="entry_path"> <object class="GtkEntry" id="entry_path">
<property name="can_focus">True</property> <property name="can_focus">True</property>
</widget> <property name="primary_icon_activatable">False</property>
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
</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>
<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>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
@ -65,38 +83,38 @@
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkCheckButton" id="chk_use_name"> <object class="GtkCheckButton" id="chk_use_name">
<property name="label" translatable="yes">Create torrent name sub-folder</property> <property name="label" translatable="yes">Create torrent name sub-folder</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="receives_default">False</property> <property name="receives_default">False</property>
<property name="tooltip" translatable="yes">This option will create a sub-folder using the torrent's name within the selected extract folder and put the extracted files there.</property> <property name="tooltip_text" translatable="yes">This option will create a sub-folder using the torrent's name within the selected extract folder and put the extracted files there.</property>
<property name="draw_indicator">True</property> <property name="draw_indicator">True</property>
</widget> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
</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;General&lt;/b&gt;</property> <property name="label" translatable="yes">&lt;b&gt;General&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>
</widget> </object>
</child> </child>
</widget> </object>
</glade-interface> </interface>

View File

@ -16,7 +16,6 @@ from __future__ import unicode_literals
import logging import logging
import gtk import gtk
import gtk.glade
import deluge.component as component import deluge.component as component
from deluge.plugins.pluginbase import GtkPluginBase from deluge.plugins.pluginbase import GtkPluginBase
@ -29,9 +28,10 @@ log = logging.getLogger(__name__)
class GtkUI(GtkPluginBase): class GtkUI(GtkPluginBase):
def enable(self): def enable(self):
self.glade = gtk.glade.XML(get_resource('extractor_prefs.glade')) self.builder = gtk.Builder()
self.builder.add_from_file(get_resource('extractor_prefs.ui'))
component.get('Preferences').add_page(_('Extractor'), self.glade.get_widget('extractor_prefs_box')) component.get('Preferences').add_page(_('Extractor'), self.builder.get_object('extractor_prefs_box'))
component.get('PluginManager').register_hook('on_apply_prefs', self.on_apply_prefs) component.get('PluginManager').register_hook('on_apply_prefs', self.on_apply_prefs)
component.get('PluginManager').register_hook('on_show_prefs', self.on_show_prefs) component.get('PluginManager').register_hook('on_show_prefs', self.on_show_prefs)
self.on_show_prefs() self.on_show_prefs()
@ -40,36 +40,36 @@ class GtkUI(GtkPluginBase):
component.get('Preferences').remove_page(_('Extractor')) component.get('Preferences').remove_page(_('Extractor'))
component.get('PluginManager').deregister_hook('on_apply_prefs', self.on_apply_prefs) component.get('PluginManager').deregister_hook('on_apply_prefs', self.on_apply_prefs)
component.get('PluginManager').deregister_hook('on_show_prefs', self.on_show_prefs) component.get('PluginManager').deregister_hook('on_show_prefs', self.on_show_prefs)
del self.glade del self.builder
def on_apply_prefs(self): def on_apply_prefs(self):
log.debug('applying prefs for Extractor') log.debug('applying prefs for Extractor')
if client.is_localhost(): if client.is_localhost():
path = self.glade.get_widget('folderchooser_path').get_filename() path = self.builder.get_object('folderchooser_path').get_filename()
else: else:
path = self.glade.get_widget('entry_path').get_text() path = self.builder.get_object('entry_path').get_text()
config = { config = {
'extract_path': path, 'extract_path': path,
'use_name_folder': self.glade.get_widget('chk_use_name').get_active() 'use_name_folder': self.builder.get_object('chk_use_name').get_active()
} }
client.extractor.set_config(config) client.extractor.set_config(config)
def on_show_prefs(self): def on_show_prefs(self):
if client.is_localhost(): if client.is_localhost():
self.glade.get_widget('folderchooser_path').show() self.builder.get_object('folderchooser_path').show()
self.glade.get_widget('entry_path').hide() self.builder.get_object('entry_path').hide()
else: else:
self.glade.get_widget('folderchooser_path').hide() self.builder.get_object('folderchooser_path').hide()
self.glade.get_widget('entry_path').show() self.builder.get_object('entry_path').show()
def on_get_config(config): def on_get_config(config):
if client.is_localhost(): if client.is_localhost():
self.glade.get_widget('folderchooser_path').set_current_folder(config['extract_path']) self.builder.get_object('folderchooser_path').set_current_folder(config['extract_path'])
else: else:
self.glade.get_widget('entry_path').set_text(config['extract_path']) self.builder.get_object('entry_path').set_text(config['extract_path'])
self.glade.get_widget('chk_use_name').set_active(config['use_name_folder']) self.builder.get_object('chk_use_name').set_active(config['use_name_folder'])
client.extractor.get_config().addCallback(on_get_config) client.extractor.get_config().addCallback(on_get_config)