Remove duplicate code.

This commit is contained in:
Pedro Algarvio 2011-06-05 16:23:09 +01:00
parent 8933ac3123
commit 4aab110aaf
2 changed files with 11 additions and 18 deletions

View File

@ -33,15 +33,15 @@
# #
# #
import os
import gtk import gtk
import logging import logging
import pkg_resources
from deluge.ui.client import client from deluge.ui.client import client
from deluge.plugins.pluginbase import GtkPluginBase from deluge.plugins.pluginbase import GtkPluginBase
import deluge.component as component import deluge.component as component
import deluge.common
# Relative import
from . import common
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -62,7 +62,7 @@ class ExecutePreferences(object):
def load(self): def load(self):
log.debug("Adding Execute Preferences page") log.debug("Adding Execute Preferences page")
self.glade = gtk.glade.XML(self.get_resource("execute_prefs.glade")) self.glade = gtk.glade.XML(common.get_resource("execute_prefs.glade"))
self.glade.signal_autoconnect({ self.glade.signal_autoconnect({
"on_add_button_clicked": self.on_add_button_clicked "on_add_button_clicked": self.on_add_button_clicked
}) })
@ -91,11 +91,6 @@ class ExecutePreferences(object):
self.plugin.deregister_hook("on_apply_prefs", self.on_apply_prefs) self.plugin.deregister_hook("on_apply_prefs", self.on_apply_prefs)
self.plugin.deregister_hook("on_show_prefs", self.load_commands) self.plugin.deregister_hook("on_show_prefs", self.load_commands)
def get_resource(self, filename):
return pkg_resources.resource_filename(
"deluge.plugins.execute", os.path.join("data", filename)
)
def add_command(self, command_id, event, command): def add_command(self, command_id, event, command):
log.debug("Adding command `%s`", command_id) log.debug("Adding command `%s`", command_id)
vbox = self.glade.get_widget("commands_vbox") vbox = self.glade.get_widget("commands_vbox")

View File

@ -45,14 +45,17 @@
# but you are not obligated to do so. If you do not wish to do so, delete # but you are not obligated to do so. If you do not wish to do so, delete
# this exception statement from your version. If you delete this exception # this exception statement from your version. If you delete this exception
import os
import gtk import gtk
import gobject
import logging import logging
from gtk.glade import XML from gtk.glade import XML
from twisted.internet import defer from twisted.internet import defer
import graph # Relative imports
from . import common
from . import graph
from deluge import component from deluge import component
from deluge.common import fspeed from deluge.common import fspeed
from deluge.ui.client import client from deluge.ui.client import client
@ -118,13 +121,13 @@ class GraphsTab(Tab):
class GtkUI(GtkPluginBase): class GtkUI(GtkPluginBase):
def enable(self): def enable(self):
log.debug("Stats plugin enable called") log.debug("Stats plugin enable called")
self.glade = XML(self.get_resource("config.glade")) self.glade = XML(common.get_resource("config.glade"))
component.get("Preferences").add_page("Stats", self.glade.get_widget("prefs_box")) component.get("Preferences").add_page("Stats", self.glade.get_widget("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()
self.graphs_tab = GraphsTab(XML(self.get_resource("tabs.glade"))) self.graphs_tab = GraphsTab(XML(common.get_resource("tabs.glade")))
self.torrent_details = component.get('TorrentDetails') self.torrent_details = component.get('TorrentDetails')
self.torrent_details.add_tab(self.graphs_tab) self.torrent_details.add_tab(self.graphs_tab)
@ -148,8 +151,3 @@ class GtkUI(GtkPluginBase):
"callback for on show_prefs" "callback for on show_prefs"
self.glade.get_widget("txt_test").set_text(config["test"]) self.glade.get_widget("txt_test").set_text(config["test"])
def get_resource(self, filename):
import pkg_resources, os
return pkg_resources.resource_filename(
"deluge.plugins.stats", os.path.join("data", filename)
)