label-plugin:fix unload

This commit is contained in:
Martijn Voncken 2008-10-14 20:04:23 +00:00
parent 4e79fe3f7d
commit cba021a19e
5 changed files with 29 additions and 15 deletions

View File

@ -125,6 +125,7 @@ class Core(CorePluginBase):
self.plugin.deregister_status_field("label") self.plugin.deregister_status_field("label")
self.plugin.deregister_hook("post_torrent_add", self.post_torrent_add) self.plugin.deregister_hook("post_torrent_add", self.post_torrent_add)
self.plugin.deregister_hook("post_torrent_remove", self.post_torrent_remove) self.plugin.deregister_hook("post_torrent_remove", self.post_torrent_remove)
component.get("FilterManager").deregister_tree_field("label")
def update(self): def update(self):
pass pass

View File

@ -64,18 +64,23 @@ class GtkUI(ui.UI):
self.load_interface() self.load_interface()
def disable(self): def disable(self):
self.labelcfg.unload()
try: try:
torrentmenu = component.get("MenuBar").torrentmenu
torrentmenu.remove(self.label_menu) # ok
self.labelcfg.unload() # ok
self.sidebar_menu.unload()
del self.sidebar_menu
component.get("TorrentView").remove_column(_("Label")) component.get("TorrentView").remove_column(_("Label"))
log.debug(1.1) log.debug(1.1)
component.get("TorrentView").create_model_filter() #todo:improve. component.get("TorrentView").create_model_filter() #todo:improve.
except Exception, e:
log.debug(e) #fix this!
log.debug(1.2) except Exception, e:
#disabled: log.debug(e)
#self.sidebar_menu.unload()
log.debug(2)
def get_pixmap(self, fname): def get_pixmap(self, fname):
"""Returns a pixmap file included with plugin""" """Returns a pixmap file included with plugin"""

View File

@ -116,6 +116,16 @@ class LabelSidebarMenu(object):
for item in self.items: for item in self.items:
item.hide() item.hide()
def unload(self):
log.debug("disable01")
for item in list(self.items):
item.hide()
item.destroy()
log.debug("disable02")
self.items = []
#dialogs: #dialogs:
class AddDialog(object): class AddDialog(object):

View File

@ -45,16 +45,13 @@ config = ConfigManager("label.conf")
GTK_ALFA = config.get("gtk_alfa") GTK_ALFA = config.get("gtk_alfa")
NO_LABEL = "No Label" NO_LABEL = "No Label"
def cb_none(args):
"hack for empty callbacks."
pass
class LabelMenu(gtk.MenuItem): class LabelMenu(gtk.MenuItem):
def __init__(self): def __init__(self):
gtk.MenuItem.__init__(self, _("Label")) gtk.MenuItem.__init__(self, _("Label"))
self.sub_menu = gtk.Menu() self.sub_menu = gtk.Menu()
self.set_submenu(self.sub_menu) self.set_submenu(self.sub_menu)
self.items = []
#attach.. #attach..
torrentmenu = component.get("MenuBar").torrentmenu torrentmenu = component.get("MenuBar").torrentmenu
@ -86,13 +83,10 @@ class LabelMenu(gtk.MenuItem):
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(cb_none, torrent_id, label_id) aclient.label_set_torrent(None, torrent_id, label_id)
#aclient.force_call(block=True) #aclient.force_call(block=True)

View File

@ -25,6 +25,10 @@ test_filter(None)
if not (sclient.get_torrents_status({}, KEYS) == sclient.get_torrents_status(None, KEYS)): if not (sclient.get_torrents_status({}, KEYS) == sclient.get_torrents_status(None, KEYS)):
raise Exception("should be equal") raise Exception("should be equal")
print "#test keyword:"
test_filter({"keyword":["keyword1","prison"]})
print "#torrent_id filter:" print "#torrent_id filter:"
test_filter({"id":[torrent_id, torrent_id2]}) test_filter({"id":[torrent_id, torrent_id2]})