Get Label plugin working in the GtkUI

This commit is contained in:
Andrew Resch 2009-02-27 17:12:53 +00:00
commit 3f03cb967a
12 changed files with 52 additions and 250 deletions

View file

@ -38,10 +38,14 @@ class Component(object):
self._interval = interval self._interval = interval
self._timer = None self._timer = None
self._state = COMPONENT_STATE.index("Stopped") self._state = COMPONENT_STATE.index("Stopped")
self._name = name
def get_state(self): def get_state(self):
return self._state return self._state
def get_component_name(self):
return self._name
def start(self): def start(self):
pass pass

View file

@ -197,7 +197,8 @@ class FilterManager(component.Component):
self.tree_fields[field] = init_func self.tree_fields[field] = init_func
def deregister_tree_field(self, field): def deregister_tree_field(self, field):
del self.tree_fields[field] if field in self.tree_fields:
del self.tree_fields[field]
def filter_state_active(self, torrent_ids): def filter_state_active(self, torrent_ids):
get_status = self.core.get_torrent_status get_status = self.core.get_torrent_status

View file

@ -121,6 +121,8 @@ class PluginManagerBase:
log.error("Unable to instantiate plugin!") log.error("Unable to instantiate plugin!")
log.exception(e) log.exception(e)
instance.enable() instance.enable()
if self.get_state() == "Started":
component.start(instance.get_component_name())
plugin_name = plugin_name.replace("-", " ") plugin_name = plugin_name.replace("-", " ")
self.plugins[plugin_name] = instance self.plugins[plugin_name] = instance
if plugin_name not in self.config["enabled_plugins"]: if plugin_name not in self.config["enabled_plugins"]:

View file

@ -22,33 +22,13 @@
# Boston, MA 02110-1301, USA. # Boston, MA 02110-1301, USA.
# #
from deluge.plugins.init import PluginInitBase
from deluge.log import LOG as log class CorePlugin(PluginInitBase):
from deluge.plugins.init import PluginBase from core import Core as _plugin_cls
class CorePlugin(PluginBase): class GtkUIPlugin(PluginInitBase):
def __init__(self, plugin_api, plugin_name): from gtkui import GtkUI as _plugin_cls
# Load the Core portion of the plugin
try:
from core import Core
self.plugin = Core(plugin_api, plugin_name)
except Exception, e:
log.debug("Did not load a Core plugin: %s", e)
class WebUIPlugin(PluginBase):
def __init__(self, plugin_api, plugin_name):
try:
from webui import WebUI
self.plugin = WebUI(plugin_api, plugin_name)
except Exception, e:
log.debug("Did not load a WebUI plugin: %s", e)
class GtkUIPlugin(PluginBase):
def __init__(self, plugin_api, plugin_name):
# Load the GtkUI portion of the plugin
try:
from gtkui import GtkUI
self.plugin = GtkUI(plugin_api, plugin_name)
except Exception, e:
log.debug("Did not load a GtkUI plugin: %s", e)
class WebUIPlugin(PluginInitBase):
from webui import WebUI as _plugin_cls

View file

@ -27,7 +27,7 @@ adds a status field for tracker.
""" """
from deluge.log import LOG as log from deluge.log import LOG as log
from deluge.plugins.corepluginbase import CorePluginBase from deluge.plugins.pluginbase import CorePluginBase
from deluge.core.rpcserver import export from deluge.core.rpcserver import export
from deluge.configmanager import ConfigManager from deluge.configmanager import ConfigManager
import deluge.component as component import deluge.component as component
@ -84,7 +84,7 @@ class Core(CorePluginBase):
""" """
def enable(self): def enable(self):
log.info("*** Start Label plugin ***") log.info("*** Start Label plugin ***")
self.plugin = component.get("CorePluginManager")
self.plugin.register_status_field("label", self._status_get_label) self.plugin.register_status_field("label", self._status_get_label)
#__init__ #__init__
@ -177,12 +177,12 @@ class Core(CorePluginBase):
if changed: if changed:
self.config.save() self.config.save()
@export @export()
def get_labels(self): def get_labels(self):
return sorted(self.labels.keys()) return sorted(self.labels.keys())
#Labels: #Labels:
@export @export()
def add(self, label_id): def add(self, label_id):
"""add a label """add a label
see label_set_options for more options. see label_set_options for more options.
@ -238,7 +238,7 @@ class Core(CorePluginBase):
return True return True
return False return False
@export @export()
def set_options(self, label_id, options_dict , apply = False): def set_options(self, label_id, options_dict , apply = False):
"""update the label options """update the label options
@ -275,12 +275,12 @@ class Core(CorePluginBase):
self.config.save() self.config.save()
@export @export()
def get_options(self, label_id): def get_options(self, label_id):
"""returns the label options""" """returns the label options"""
return self.labels[label_id] return self.labels[label_id]
@export @export()
def set_torrent(self, torrent_id , label_id): def set_torrent(self, torrent_id , label_id):
""" """
assign a label to a torrent assign a label to a torrent
@ -302,12 +302,12 @@ class Core(CorePluginBase):
self.config.save() self.config.save()
@export @export()
def get_config(self): def get_config(self):
"see : label_set_config" "see : label_set_config"
return dict((key, self.config[key]) for key in CORE_OPTIONS if key in self.config.config) return dict((key, self.config[key]) for key in CORE_OPTIONS if key in self.config.config)
@export @export()
def set_config(self, options): def set_config(self, options):
"""global_options:""" """global_options:"""
if options: if options:

View file

@ -27,9 +27,9 @@ import os
import pkg_resources # access plugin egg import pkg_resources # access plugin egg
from deluge.log import LOG as log from deluge.log import LOG as log
from deluge import component # for systray from deluge import component # for systray
import ui from deluge.plugins.pluginbase import GtkPluginBase
import gtk, gobject import gtk, gobject
from deluge.ui.client import aclient from deluge.ui.client import client
import sidebar_menu import sidebar_menu
import label_config import label_config
@ -43,16 +43,16 @@ NO_LABEL = "No Label"
def cell_data_label(column, cell, model, row, data): def cell_data_label(column, cell, model, row, data):
cell.set_property('text', str(model.get_value(row, data))) cell.set_property('text', str(model.get_value(row, data)))
class GtkUI(ui.UI): class GtkUI(GtkPluginBase):
def __init__(self, plugin_api, plugin_name): def start(self):
log.debug("Calling UI init") if self.label_menu:
# Call UI constructor self.label_menu.on_show()
ui.UI.__init__(self, plugin_api, plugin_name)
log.debug("Label GtkUI plugin initalized..")
self.labelcfg = None
self.sidebar_menu = None
def enable(self): def enable(self):
self.plugin = component.get("PluginManager")
self.label_menu = None
self.labelcfg = None
self.sidebar_menu = None
self.load_interface() self.load_interface()
def disable(self): def disable(self):

View file

@ -29,7 +29,7 @@ import pkg_resources # access plugin egg
import deluge.component as component import deluge.component as component
import deluge.common import deluge.common
from deluge.log import LOG as log from deluge.log import LOG as log
from deluge.ui.client import aclient from deluge.ui.client import client
class LabelConfig(object): class LabelConfig(object):
@ -60,7 +60,7 @@ class LabelConfig(object):
return pkg_resources.resource_filename("label", os.path.join("data", filename)) return pkg_resources.resource_filename("label", os.path.join("data", filename))
def load_settings(self, widget=None, data=None): def load_settings(self, widget=None, data=None):
aclient.label.get_config(self.cb_global_options) client.label.get_config().addCallback(self.cb_global_options)
def cb_global_options(self, options): def cb_global_options(self, options):
log.debug("options=%s" % options) log.debug("options=%s" % options)
@ -72,4 +72,4 @@ class LabelConfig(object):
def on_apply_prefs(self): def on_apply_prefs(self):
options = {} options = {}
#update options dict here. #update options dict here.
aclient.label.set_config(None, options) client.label.set_config(options)

View file

@ -30,7 +30,7 @@ import gtk.glade
import deluge.component as component import deluge.component as component
import deluge.common import deluge.common
from deluge.log import LOG as log from deluge.log import LOG as log
from deluge.ui.client import aclient from deluge.ui.client import client
NO_LABEL = "No Label" NO_LABEL = "No Label"
@ -81,7 +81,7 @@ class LabelSidebarMenu(object):
self.add_dialog.show() self.add_dialog.show()
def on_remove(self, event=None): def on_remove(self, event=None):
aclient.label.remove(None, self.treeview.value) client.label.remove(self.treeview.value)
def on_options (self, event=None): def on_options (self, event=None):
self.options_dialog.show(self.treeview.value) self.options_dialog.show(self.treeview.value)
@ -137,7 +137,7 @@ class AddDialog(object):
def on_ok(self, event=None): def on_ok(self, event=None):
value = self.glade.get_widget("txt_add").get_text() value = self.glade.get_widget("txt_add").get_text()
aclient.label.add(None, value) client.label.add(value)
self.dialog.destroy() self.dialog.destroy()
def on_cancel(self, event=None): def on_cancel(self, event=None):
@ -179,7 +179,7 @@ class OptionsDialog(object):
chk = self.glade.get_widget(chk_id) chk = self.glade.get_widget(chk_id)
chk.connect("toggled",self.apply_sensitivity) chk.connect("toggled",self.apply_sensitivity)
aclient.label.get_options(self.load_options, self.label) client.label.get_options(self.label).addCallback(self.load_options)
self.dialog.run() self.dialog.run()
@ -212,7 +212,7 @@ class OptionsDialog(object):
options["auto_add_trackers"] = [x for x in tracker_lst if x] #filter out empty lines. options["auto_add_trackers"] = [x for x in tracker_lst if x] #filter out empty lines.
log.debug(options) log.debug(options)
aclient.label.set_options(None, self.label, options) client.label.set_options(self.label, options)
self.dialog.destroy() self.dialog.destroy()
def apply_sensitivity(self, event=None): def apply_sensitivity(self, event=None):

View file

@ -27,9 +27,8 @@ import os
import pkg_resources # access plugin egg import pkg_resources # access plugin egg
from deluge.log import LOG as log from deluge.log import LOG as log
from deluge import component # for systray from deluge import component # for systray
import ui
import gtk, gobject import gtk, gobject
from deluge.ui.client import aclient from deluge.ui.client import client
from deluge.configmanager import ConfigManager from deluge.configmanager import ConfigManager
config = ConfigManager("label.conf") config = ConfigManager("label.conf")
@ -46,22 +45,15 @@ class LabelMenu(gtk.MenuItem):
#attach.. #attach..
torrentmenu = component.get("MenuBar").torrentmenu torrentmenu = component.get("MenuBar").torrentmenu
self.sub_menu.connect("show", self.on_show, None) self.sub_menu.connect("show", self.on_show, None)
aclient.connect_on_new_core(self._on_new_core)
def _on_new_core(self, data = None):
self.on_show()
def get_torrent_ids(self): def get_torrent_ids(self):
return component.get("TorrentView").get_selected_torrents() return component.get("TorrentView").get_selected_torrents()
def on_show(self, widget=None, data=None): def on_show(self, widget=None, data=None):
log.debug("label-on-show") log.debug("label-on-show")
aclient.label.get_labels(self.cb_labels) client.label.get_labels().addCallback(self.cb_labels)
aclient.force_call(block=True)
def cb_labels(self , labels): def cb_labels(self, labels):
for child in self.sub_menu.get_children(): for child in self.sub_menu.get_children():
self.sub_menu.remove(child) self.sub_menu.remove(child)
for label in [NO_LABEL] + labels: for label in [NO_LABEL] + labels:
@ -70,8 +62,7 @@ class LabelMenu(gtk.MenuItem):
self.sub_menu.append(item) self.sub_menu.append(item)
self.show_all() self.show_all()
def on_select_label(self, widget=None, label_id = None): def on_select_label(self, widget=None, label_id=None):
log.debug("select label:%s,%s" % (label_id ,self.get_torrent_ids()) ) log.debug("select label:%s,%s" % (label_id ,self.get_torrent_ids()) )
for torrent_id in self.get_torrent_ids(): for torrent_id in self.get_torrent_ids():
aclient.label.set_torrent(None, torrent_id, label_id) client.label.set_torrent(torrent_id, label_id)
#aclient.force_call(block=True)

View file

@ -1,43 +0,0 @@
#
# ui.py
#
# Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com>
# Copyright (C) 2008 Mark Stahler ('kramed') <markstahler@gmail.com>
#
# Deluge is free software.
#
# You may redistribute it and/or modify it under the terms of the
# GNU General Public License, as published by the Free Software
# Foundation; either version 3 of the License, or (at your option)
# any later version.
#
# deluge is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with deluge. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
import gettext
import locale
import pkg_resources
import deluge.component
from deluge.ui.client import aclient as client
from deluge.log import LOG as log
class UI:
def __init__(self, plugin_api, plugin_name):
self.plugin = plugin_api
def enable(self):
pass
def disable(self):
pass

View file

@ -29,145 +29,15 @@
import os import os
from deluge.common import fspeed from deluge.common import fspeed
from deluge.log import LOG as log from deluge.log import LOG as log
from deluge.ui.client import sclient, aclient from deluge.ui.client import client
from deluge.plugins.webuipluginbase import WebUIPluginBase from deluge.plugins.pluginbase import WebPluginBase
from deluge import component from deluge import component
api = component.get("WebPluginApi")
forms = api.forms
#pages: class WebUI(WebPluginBase):
class options:
def page(self, label_id, options , error=None):
options_form = OptionsForm(options)
options_form.label_id = label_id
options_form.full_clean()
return api.render.label.options(label_id, options_form)
@api.deco.deluge_page
def GET(self, label_id):
return self.page(label_id, sclient.label.get_options(label_id))
@api.deco.check_session
def POST(self, label_id):
post_options = api.utils.get_newforms_data(OptionsForm)
options = sclient.label.get_options(label_id)
log.debug(options)
options.update(dict(post_options))
log.debug(options)
options_form = OptionsForm(options)
options_form.label_id = label_id
if not options_form.is_valid():
return self.page(label_id, options, _("Error setting label options"))
else:
error = None
sclient.label.set_options(label_id, options_form.cleaned_data)
api.utils.seeother("/config/label")
class add:
@api.deco.deluge_page
def GET(self, label_id):
return api.render.label.options(label_id)
class remove:
@api.deco.deluge_page
def GET(self, label_id):
return api.render.label.options(label_id)
class config_page:
"""for ajaxui."""
@api.deco.deluge_page
def GET(self, args):
labels = sclient.label.get_labels()
return api.render.label.config_page(labels)
class WebUI(WebUIPluginBase):
include_javascript = ["/label/data/label.js"]
urls = [
('/label/options/(.*)', options),
('/label/add', add),
('/label/remove/(.*)', remove),
('/label/config', config_page)
]
def enable(self): def enable(self):
api.config_page_manager.register('plugins', 'label' ,ConfigForm) pass
def disable(self): def disable(self):
api.config_page_manager.deregister('label') pass
#options:
"""
todo (see gtkui)
sensitive_groups = [
("apply_max", ["max_download_speed", "max_upload_speed", "max_upload_slots", "max_connections"]),
("apply_queue", ["is_auto_managed", "stop_at_ratio"]),
("stop_at_ratio", ["remove_at_ratio", "stop_ratio"]), #nested
("apply_move_completed", ["move_completed"]),
("move_completed", ["move_completed_path"]), #nested
("auto_add", ["auto_add_trackers"])
]
"""
class OptionsForm(forms.Form):
#load/save:
def initial_data(self):
return sclient.label.get_options(self.label_id)
#maximum:
apply_max = forms.CheckBox(_("apply_max"))
max_download_speed = forms.DelugeInt(_("max_download_speed"))
max_upload_speed = forms.DelugeInt(_("max_upload_speed"))
max_upload_slots = forms.DelugeInt(_("max_upload_slots"))
max_connections = forms.DelugeInt(_("max_connections"))
#queue:
apply_queue = forms.CheckBox(_("apply_queue"))
is_auto_managed = forms.CheckBox(_("is_auto_managed"))
stop_at_ratio = forms.CheckBox(_("stop_at_ratio"))
stop_ratio = forms.DelugeFloat(_("stop_ratio"), required=False)
remove_at_ratio = forms.CheckBox(_("remove_at_ratio"))
#location:
apply_move_completed = forms.CheckBox(_("apply_move_completed"))
move_completed = forms.CheckBox(_("move_completed"))
move_completed_path = forms.CharField(label=_("move_completed_path"), required=False)
#tracker:
auto_add = forms.CheckBox(_("auto_add"))
auto_add_trackers = forms.StringList(_("auto_add_trackers"))
#config:
class ConfigForm(forms.Form):
"""
custom config page
too complex for the default config framework
"""
#meta:
title = _("Label")
info = _("Work in progress..")
#load/save:
def initial_data(self):
return sclient.label.get_config()
def save(self, data):
cfg = dict(data)
sclient.label.set_config(cfg)
def pre_html(self):
""" custom config html/template"""
labels = sclient.label.get_labels()
return api.render.label.config(labels)
#django newforms magic: define config fields:
#test = forms.CharField(label=_("Test config value"))

View file

@ -38,16 +38,13 @@ class CorePluginBase(PluginBase):
# Register RPC methods # Register RPC methods
component.get("RPCServer").register_object(self, plugin_name.lower()) component.get("RPCServer").register_object(self, plugin_name.lower())
log.debug("CorePlugin initialized..") log.debug("CorePlugin initialized..")
component.start("CorePlugin." + plugin_name)
class GtkPluginBase(PluginBase): class GtkPluginBase(PluginBase):
def __init__(self, plugin_name): def __init__(self, plugin_name):
component.Component.__init__(self, "GtkPlugin." + plugin_name) component.Component.__init__(self, "GtkPlugin." + plugin_name)
log.debug("GtkPlugin initialized..") log.debug("GtkPlugin initialized..")
component.start("GtkPlugin." + plugin_name)
class WebPluginBase(PluginBase): class WebPluginBase(PluginBase):
def __init__(self, plugin_name): def __init__(self, plugin_name):
component.Component.__init__(self, "WebPlugin." + plugin_name) component.Component.__init__(self, "WebPlugin." + plugin_name)
log.debug("WebPlugin initialized..") log.debug("WebPlugin initialized..")
component.start("WebPlugin." + plugin_name)