Changeset 147

Show
Ignore:
Timestamp:
03/23/08 19:41:42 (10 months ago)
Author:
poillubo
Message:

* added a new submenu: DynamicAddPluginMenu?

DynamicAddPluginMenu? hooks the PycaWM.add_plugin method to store the
plugin/params and dynamicall reload them when needed

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/conf/config-example.py

    r146 r147  
    3232from pycawm.menu import (Menu, FocusesMenu, IconifiedClientsMenu, 
    3333                         ClientsSwitchMenu, ApplicationMenu, WindowManagerMenu, 
    34                          ConfigMenu, AddPluginMenu, RemovePluginMenu) 
     34                         ConfigMenu, AddPluginMenu, DynamicAddPluginMenu, 
     35                         RemovePluginMenu) 
    3536from pycawm.plugins import (ActionButtonBox, MiniIconBox, MovePos, Pager, 
    3637                            RemoteREPL, StickyRootEdges) 
     
    145146                                                     RemoteREPL: dict(), 
    146147                                                     Pager: dict(x=0, y=0)}))), 
     148                           ('Add Plugin (dynamic)', Menu.sub_menu, 
     149                            (lambda menu, x, y: 
     150                             DynamicAddPluginMenu(self, parent=menu, 
     151                                                  x=x, y=y))),        
    147152                           ('Remove Plugin', Menu.sub_menu, 
    148153                            lambda menu, x, y: RemovePluginMenu(self, 
     
    196201#   * the plugin class. 
    197202#   * the arguments we want to give to the plugin when the wm instantiates it. 
     203 
     204# DynamicAddPluginMenu is a menu which can dynamically reload plugins launched 
     205# by calling the PycaWM.add_plugin method 
     206DynamicAddPluginMenu.start(pika) 
    198207 
    199208# Put a pager at (0, 0) 
  • trunk/pycawm/menu.py

    r146 r147  
    3838from decorators import good_menu 
    3939from hookmanager import (add_pre_hook, remove_pre_hook, 
     40                         add_post_hook, remove_post_hook, 
    4041                         add_instance_overriding_hook, 
    4142                         remove_instance_overriding_hook) 
     
    774775        return elements 
    775776 
     777class DynamicAddPluginMenu(Menu): 
     778    elements = dict() 
     779 
     780    @classmethod 
     781    def start(cls, wm): 
     782        add_post_hook(wm.add_plugin, cls.add_plugin) 
     783 
     784    @classmethod 
     785    def add_plugin(cls, wm, plugin, params=dict(), name=None, force=False): 
     786        plugin_name = name if name is not None else plugin.__name__ 
     787        cls.elements[plugin_name] = \ 
     788            (('Add ' + plugin_name, Menu.python, 
     789              (lambda plugin=plugin, params=params, name=name, force=force: 
     790               wm.add_plugin(plugin, params, name=name, force=force)))) 
     791 
     792    @classmethod 
     793    def stop(cls, wm): 
     794        remove_post_hook(wm.add_plugin, cls.add_plugin) 
     795 
     796    def __init__(self, wm, x, y, parent=None): 
     797        Menu.__init__(self, wm, x, y, self.elements.values(), parent=parent) 
     798 
    776799class RemovePluginMenu(Menu): 
    777800    def __init__(self, wm, x, y, parent=None):