Changeset 189
- Timestamp:
- 21.06.2008 12:39:59 (7 months ago)
- Files:
-
- trunk/conf/config-example.py (modified) (2 diffs)
- trunk/pycawm/button.py (modified) (3 diffs)
- trunk/pycawm/misc.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/conf/config-example.py
r170 r189 24 24 from pycawm import (Client, ClientUnderPointer, MoveUnderPointer, PycaWM, 25 25 ScreenshotUnderPointer) 26 from pycawm.button import ( CloseButton, MiniIconButton, ShadeButton,27 MaximizeButton, IconifyButton , PlopButton)26 from pycawm.button import (Button, CloseButton, MiniIconButton, ShadeButton, 27 MaximizeButton, IconifyButton) 28 28 from pycawm.hookmanager import add_post_hook, add_pre_hook 29 29 from pycawm.menu import (Menu, FocusesMenu, IconifiedClientsMenu, … … 215 215 dict(x=500, y=0, 216 216 buttons=[ 217 [ PlopButton('plop.png',217 [Button('plop.png', 218 218 action_1=lambda self, x, y: ApplicationMenu(pika, x=x, y=y+16)), 219 PlopButton('plop.png',219 Button('plop.png', 220 220 action_1=lambda self, x, y: ConfigMenu(pika, x=x, y=y+16)), 221 PlopButton('plop.png',221 Button('plop.png', 222 222 action_1=lambda self, x, y: ConfigMenu(pika, x=x, y=y+16))], 223 [ PlopButton('plop.png',223 [Button('plop.png', 224 224 action_1=lambda self, x, y: ConfigMenu(pika, x=x, y=y+16))], 225 [ PlopButton('plop.png',225 [Button('plop.png', 226 226 action_1=lambda self, x, y: ApplicationMenu(pika, x=x, y=y+16)), 227 PlopButton('plop.png',227 Button('plop.png', 228 228 action_1=lambda self, x, y: ConfigMenu(pika, x=x, y=y+16))]])) 229 229 trunk/pycawm/button.py
r151 r189 129 129 130 130 class PlopButton(Button): 131 def __init__(self, image): 132 Button.__init__(self, image) 133 131 134 def action_2(self): 132 135 print 'plop!' … … 136 139 137 140 class CloseButton(Button): 141 def __init__(self, image): 142 Button.__init__(self, image) 143 138 144 def action_1(self): 139 145 self.container.close() 140 146 141 147 class MiniIconButton(Button): 142 def __init__(self, *args, **kwargs):143 Button.__init__(self, *args, **kwargs)148 def __init__(self, image): 149 Button.__init__(self, image) 144 150 self.images['miniicon'] = Client.get_mini_icon 145 151 … … 150 156 151 157 class IconifyButton(Button): 158 def __init__(self, image): 159 Button.__init__(self, image) 160 152 161 def action_1(self): 153 162 self.container.iconify() trunk/pycawm/misc.py
r184 r189 25 25 from types import ClassType, TypeType, MethodType, FunctionType 26 26 27 import button 27 28 import focuses 28 29 import placements … … 93 94 94 95 defaults = fun.func_defaults 96 if defaults is None: 97 return None 98 95 99 indice = list(co.co_varnames).index(name) 96 100 offset = co.co_argcount - len(defaults) … … 99 103 return defaults[indice - offset] 100 104 return None 105 106 def is_arg_args(fun, name): 107 """Is the NAME argument for the method/function FUN a **args?""" 108 fun = get_func_object(fun) 109 if fun is None: 110 return False 111 112 co = fun.func_code 113 # no *args for this code object? 114 if not co.co_flags & 4: 115 return False 116 117 if name not in co.co_varnames: 118 return False 119 120 indice = list(co.co_varnames).index(name) 121 return indice == co.co_argcount 122 123 def is_arg_kwargs(fun, name): 124 """Is the NAME argument for the method/function FUN a **kwargs?""" 125 fun = get_func_object(fun) 126 if fun is None: 127 return False 128 129 co = fun.func_code 130 # no **kwargs for this code object? 131 if not co.co_flags & 8: 132 return False 133 134 if name not in co.co_varnames: 135 return False 136 137 indice = list(co.co_varnames).index(name) 138 return indice == co.co_argcount + 1 101 139 102 140 def is_class_valid(klass, base): … … 132 170 return [plugin for plugin in gen_plugs 133 171 if is_plugin_valid(plugin)] 172 173 def is_button_valid(button_): 174 try: 175 # do not use is_strict_subclass here, Button is a usable button too 176 return (issubclass(button_, button.Button) and 177 not button_.__name__.startswith('_')) 178 except TypeError: 179 return False 180 181 def find_default_buttons(): 182 """Find all the button classes in the "button" module.""" 183 gen_buttons = (button.__dict__.get(button_name) 184 for button_name in dir(button)) 185 return [button_ for button_ in gen_buttons 186 if is_button_valid(button_)]
