Use new hook mass unloading
authorJack Miller <jack@codezen.org>
Sun, 23 Nov 2014 04:47:04 +0000 (22:47 -0600)
committerJack Miller <jack@codezen.org>
Sun, 23 Nov 2014 07:35:40 +0000 (01:35 -0600)
canto_curses/reader.py
canto_curses/story.py
canto_curses/tag.py
canto_curses/taglist.py
canto_curses/text.py

index 5b7a08a..d97ab82 100644 (file)
@@ -7,7 +7,7 @@
 #   published by the Free Software Foundation.
 
 from canto_next.plugins import Plugin
-from canto_next.hooks import on_hook, remove_hook
+from canto_next.hooks import on_hook, remove_hook, unhook_all
 
 from .command import register_commands, register_arg_types, unregister_all, _int_range
 from .parser import prep_for_display
@@ -28,8 +28,8 @@ class Reader(TextBox):
         TextBox.init(self, pad, callbacks)
 
         self.quote_rgx = re.compile("[\\\"](.*?)[\\\"]")
-        on_hook("curses_opt_change", self.on_opt_change)
-        on_hook("curses_var_change", self.on_var_change)
+        on_hook("curses_opt_change", self.on_opt_change, self)
+        on_hook("curses_var_change", self.on_var_change, self)
 
         args = {
             "link-list" : ("", self.type_link_list),
@@ -50,8 +50,7 @@ class Reader(TextBox):
         self.update_plugin_lookups()
 
     def die(self):
-        remove_hook("curses_opt_change", self.on_opt_change)
-        remove_hook("curses_var_change", self.on_var_change)
+        unhook_all(self)
         unregister_all(self)
 
     def on_opt_change(self, change):
@@ -116,7 +115,7 @@ class Reader(TextBox):
                 if attr not in sel.content:
                     tag_updater.request_attributes(sel.id, l)
                     s += "%BWaiting for content...%b\n"
-                    on_hook("curses_attributes", self.on_attributes)
+                    on_hook("curses_attributes", self.on_attributes, self)
                     break
             else:
                 # Grab text content over description, as it's likely got more
index d2dd966..36e16f4 100644 (file)
@@ -7,7 +7,7 @@
 #   published by the Free Software Foundation.
 
 from canto_next.plugins import Plugin, PluginHandler
-from canto_next.hooks import on_hook, remove_hook
+from canto_next.hooks import on_hook, unhook_all
 
 from .theme import FakePad, WrapPad, theme_print, theme_len, theme_reset, theme_border
 from .parser import try_parse, try_eval, prep_for_display
@@ -65,9 +65,9 @@ class Story(PluginHandler):
         # This should exist before the hook is setup, or the hook will fail.
         self.content = {}
 
-        on_hook("curses_opt_change", self.on_opt_change)
-        on_hook("curses_tag_opt_change", self.on_tag_opt_change)
-        on_hook("curses_attributes", self.on_attributes)
+        on_hook("curses_opt_change", self.on_opt_change, self)
+        on_hook("curses_tag_opt_change", self.on_tag_opt_change, self)
+        on_hook("curses_attributes", self.on_attributes, self)
 
         # Grab initial content, if any, the rest will be handled by the
         # attributes hook
@@ -80,9 +80,7 @@ class Story(PluginHandler):
 
     def die(self):
         self.parent_tag = None
-        remove_hook("curses_opt_change", self.on_opt_change)
-        remove_hook("curses_tag_opt_change", self.on_tag_opt_change)
-        remove_hook("curses_attributes", self.on_attributes)
+        unhook_all(self)
 
     def __eq__(self, other):
         if not other:
index 2f11614..418da89 100644 (file)
@@ -6,7 +6,7 @@
 #   it under the terms of the GNU General Public License version 2 as 
 #   published by the Free Software Foundation.
 
-from canto_next.hooks import call_hook, on_hook, remove_hook
+from canto_next.hooks import call_hook, on_hook, unhook_all
 from canto_next.plugins import Plugin, PluginHandler
 from canto_next.rwlock import read_lock
 
@@ -92,9 +92,9 @@ class Tag(PluginHandler, list):
         self.tag_offset = 0
         self.sel_offset = 0
 
-        on_hook("curses_opt_change", self.on_opt_change)
-        on_hook("curses_tag_opt_change", self.on_tag_opt_change)
-        on_hook("curses_attributes", self.on_attributes)
+        on_hook("curses_opt_change", self.on_opt_change, self)
+        on_hook("curses_tag_opt_change", self.on_tag_opt_change, self)
+        on_hook("curses_attributes", self.on_attributes, self)
 
         # Upon creation, this Tag adds itself to the
         # list of all tags.
@@ -118,9 +118,7 @@ class Tag(PluginHandler, list):
             s.die()
         del self[:]
 
-        remove_hook("curses_opt_change", self.on_opt_change)
-        remove_hook("curses_tag_opt_change", self.on_tag_opt_change)
-        remove_hook("curses_attributes", self.on_attributes)
+        unhook_all(self)
 
     def on_item_state_change(self, item):
         self.need_redraw()
index 41a428e..f1bf52e 100644 (file)
@@ -6,7 +6,7 @@
 #   it under the terms of the GNU General Public License version 2 as 
 #   published by the Free Software Foundation.
 
-from canto_next.hooks import on_hook, remove_hook
+from canto_next.hooks import on_hook, remove_hook, unhook_all
 from canto_next.plugins import Plugin
 
 from .command import register_commands, register_arg_types, unregister_all, _int_range, _int_check, _string
@@ -72,13 +72,13 @@ class TagList(GuiBase):
         self.update_tag_lists()
 
         # Hooks
-        on_hook("curses_eval_tags_changed", self.on_eval_tags_changed)
-        on_hook("curses_items_added", self.on_items_added)
-        on_hook("curses_stories_added", self.on_stories_added)
-        on_hook("curses_stories_removed", self.on_stories_removed)
-        on_hook("curses_opt_change", self.on_opt_change)
-        on_hook("curses_new_tagcore", self.on_new_tagcore)
-        on_hook("curses_update_complete", self.on_update_complete)
+        on_hook("curses_eval_tags_changed", self.on_eval_tags_changed, self)
+        on_hook("curses_items_added", self.on_items_added, self)
+        on_hook("curses_stories_added", self.on_stories_added, self)
+        on_hook("curses_stories_removed", self.on_stories_removed, self)
+        on_hook("curses_opt_change", self.on_opt_change, self)
+        on_hook("curses_new_tagcore", self.on_new_tagcore, self)
+        on_hook("curses_update_complete", self.on_update_complete, self)
 
         config_lock.release_write()
 
@@ -167,12 +167,7 @@ class TagList(GuiBase):
 
     def die(self):
         log.debug("Cleaning up hooks...")
-        remove_hook("curses_eval_tags_changed", self.on_eval_tags_changed)
-        remove_hook("curses_items_added", self.on_items_added)
-        remove_hook("curses_stories_added", self.on_stories_added)
-        remove_hook("curses_stories_removed", self.on_stories_removed)
-        remove_hook("curses_opt_change", self.on_opt_change)
-        remove_hook("curses_new_tagcore", self.on_new_tagcore)
+        unhook_all(self)
         unregister_all(self)
 
     def tag_by_item(self, item):
@@ -202,7 +197,7 @@ class TagList(GuiBase):
         if not self.callbacks["get_opt"]("story.enumerated"):
             self.callbacks["set_opt"]("story.enumerated", True)
             self.callbacks["release_gui"]()
-            on_hook("curses_var_change", self.unhook_item_list)
+            on_hook("curses_var_change", self.unhook_item_list, self)
 
     def type_item_list(self):
         all_items = []
@@ -260,7 +255,7 @@ class TagList(GuiBase):
         if not self.callbacks["get_opt"]("taglist.tags_enumerated"):
             self.callbacks["set_opt"]("taglist.tags_enumerated", True)
             self.callbacks["release_gui"]()
-            on_hook("curses_var_change", self.unhook_tag_list)
+            on_hook("curses_var_change", self.unhook_tag_list, self)
 
     def type_tag_list(self):
         vtags = self.callbacks["get_var"]("taglist_visible_tags")
index a9c3034..0a7e2e4 100644 (file)
@@ -6,7 +6,7 @@
 #   it under the terms of the GNU General Public License version 2 as 
 #   published by the Free Software Foundation.
 
-from canto_next.hooks import on_hook, remove_hook
+from canto_next.hooks import on_hook, unhook_all
 
 from .theme import FakePad, WrapPad, theme_print, theme_lstrip, theme_border, theme_reset
 from .command import register_commands, unregister_command
@@ -213,7 +213,7 @@ class VarBox(TextBox):
         self.var = var
         self.value = self.callbacks["get_var"](var)
 
-        on_hook("curses_var_change", self.on_var_change)
+        on_hook("curses_var_change", self.on_var_change, self)
 
     def on_var_change(self, change):
         if self.var in change:
@@ -223,7 +223,7 @@ class VarBox(TextBox):
             self.callbacks["set_var"]("needs_refresh", True)
 
     def cmd_destroy(self):
-        remove_hook("curses_var_change", self.on_var_change)
+        unhook_all(self)
         TextBox.cmd_destroy(self)
 
 class InfoBox(VarBox):