Changeset 177

Show
Ignore:
Timestamp:
08/06/2005 10:18:53 PM (3 years ago)
Author:
mwm
Message:

Move a lot of utilities code out of examples/plpwm.py into plwm/pane_utilities.py.
Some of this would be useful to non-paned wms, but the code needs to have the pane
dependencies removed for that to happen. I'm not up for doing it direct, but would
be willing to help someone tackling it.

Added "shortcut key" notes to the menu meta-menu.

Changed inspect to use /usr/bin/env isntead of invokeing python directly.

Location:
trunk
Files:
1 added
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/examples/plpwm.py

    r176 r177  
    11#!/usr/bin/env python 
    2 # $Id: plpwm.py,v 1.36 2005-08-06 05:35:21 mwm Exp $ 
    3 # 
    4 # plpwm.py -- Exemple PLWM window manager configuration with panes. 
     2# $Id: plpwm.py,v 1.37 2005-08-07 03:18:52 mwm Exp $ 
     3# 
     4# plpwm.py -- Example PLWM window manager configuration with panes. 
    55# 
    66#    Copyright (C) 2001  Mike Meyer <mwm@mired.org> 
     
    3535     border, color, font, menu, panes, cfilter, input, message 
    3636 
     37from plwm.pane_utilities import appmenu, codemenu, windowmenu, panesmenu, \ 
     38     runcommand, splitpane, numberpane, pullwindow, gotowindow, \ 
     39     split_pane, getapp 
    3740 
    3841class MyMenuHandler(menu.MenuCharHandler): 
     
    265268    def M4_m(my, event): 
    266269        codemenu(my.wm.panes_list[my.wm.panes_current], 
    267                  {"applications": (my.a, (event,)), 
    268                   "startup apps": (my.A, (event,)), 
    269                   "all windows": (my.b, (event,)), 
    270                   "current pane": (my.c, (event,)), 
    271                   "iconfified": (my.i, (event,)), 
    272                   "manager ops": (my.m, (event,)), 
    273                   "panes": (my.p, (event,)), 
    274                   "open in pane": (my.w, (event,)), 
    275                   "all in pane": (my.W, (event,))}) 
     270                 {"applications (a)": (my.a, (event,)), 
     271                  "startup apps (A)": (my.A, (event,)), 
     272                  "all windows (b)": (my.b, (event,)), 
     273                  "current pane (c)": (my.c, (event,)), 
     274                  "iconfified (i)": (my.i, (event,)), 
     275                  "manager ops (m)": (my.m, (event,)), 
     276                  "panes (p)": (my.p, (event,)), 
     277                  "open in pane (w)": (my.w, (event,)), 
     278                  "all in pane (W)": (my.W, (event,))}) 
    276279        my._cleanup() 
    277280 
    278281    Any_g = Any_Escape = keys.KeyGrabKeyboard._timeout 
    279282     
    280  
    281 class appmenu: 
    282     "Creates a menu of applications to run in a pane." 
    283  
    284     def __init__(my, pane, apps): 
    285         "Create and run the applications menu from the keys." 
    286  
    287         labels = apps.keys() 
    288         labels.sort() 
    289         width, height = pane.screen.menu_make(labels) 
    290         my.system = pane.screen.system 
    291         my.apps = apps 
    292         pane.screen.menu_run((pane.width - width) / 2 + pane.x, 
    293                          (pane.height - height) / 2 + pane.y, 
    294                          my) 
    295  
    296     def __call__(my, choice): 
    297         "Call the system function on the value of the given choice." 
    298  
    299         my.system(my.apps[choice] + " &") 
    300  
    301                                                                 
    302 class codemenu: 
    303     "Create a menu of Python actions to run." 
    304  
    305     def __init__(my, pane, actions): 
    306         "Create the menu and run it." 
    307  
    308         labels = actions.keys() 
    309         labels.sort() 
    310         width, height = pane.screen.menu_make(labels) 
    311         my.actions = actions 
    312         pane.screen.menu_run((pane.width - width) / 2 + pane.x, 
    313                          (pane.height - height) / 2 + pane.y, 
    314                          my) 
    315  
    316     def __call__(my, choice): 
    317         "Run the selection for the user." 
    318  
    319         apply(apply, my.actions[choice]) 
    320  
    321  
    322 class windowmenu: 
    323     "Create a menu of windows to add to a pane." 
    324  
    325     def __init__(my, pane, filter = cfilter.true, list = None): 
    326         labels = [] 
    327         clients = {} 
    328         i = 'a' 
    329         for c in list or pane.screen.query_clients(filter, 1): 
    330             l = "%c: %s" % (i, c.get_title()) 
    331             labels.append(l) 
    332             clients[l] = c 
    333             i = chr(ord(i) + 1) 
    334         if labels: 
    335             width, height = pane.screen.menu_make(labels, align = 'left') 
    336             my.add = pane.add_window 
    337             my.clients = clients 
    338             pane.screen.menu_run((pane.width - width) / 2 + pane.x, 
    339                                  (pane.height - height) / 2 + pane.y, 
    340                                  my) 
    341         else: 
    342             width, height = pane.screen.message_make("No windows") 
    343             pane.screen.message_display((pane.width - width) / 2 + pane.x, 
    344                                         (pane.height - height) / 2 + pane.y) 
    345  
    346     def __call__(my, choice): 
    347         "Add the selected window to the pane." 
    348  
    349         my.add(my.clients[choice]) 
    350  
    351  
    352 class panesmenu: 
    353     "Create a menu of all the panes." 
    354  
    355     def __init__(my, screen): 
    356         wm = screen.wm 
    357         labels = [] 
    358         panes = {} 
    359         for i in range(len(wm.panes_list)): 
    360             w = wm.panes_list[i].window 
    361             if w: l = "%d: %s" % (i, w.get_title()) 
    362             else: l = "%d: <EMPTY>" % i 
    363             labels.append(l) 
    364             panes[l] = i 
    365         width, height = screen.menu_make(labels, align = 'left') 
    366         my.goto = wm.panes_goto 
    367         my.panes = panes 
    368         screen.menu_run((screen.root_width - width) / 2, 
    369                         (screen.root_height - height) / 2, my) 
    370  
    371     def __call__(my, choice): 
    372         "Activate the selected pane." 
    373  
    374         my.goto(my.panes[choice]) 
    375              
    376283 
    377284class paneWindow(input.inputWindow): 
     
    383290    bordercolor = "Orange" 
    384291 
    385  
    386 class runcommand: 
    387     "Read a string from the user, and run it." 
    388  
    389     def __init__(my, pane): 
    390         my.system = pane.screen.system 
    391         window = paneWindow("! ", pane.screen, length = 50) 
    392         window.read(my, MyEditHandler, pane.x, pane.y) 
    393  
    394     def __call__(my, string): 
    395         my.system(string + " &") 
    396  
    397  
    398 class splitpane: 
    399     "Read in a fraction, and split that much off the current pane." 
    400  
    401     def __init__(my, pane, splitter): 
    402         my.pane, my.splitter = pane, splitter 
    403         window = paneWindow("Fraction: ", pane.screen, length = 50) 
    404         window.read(my, MyEditHandler, pane.x, pane.y) 
    405  
    406     def __call__(my, fraction): 
    407         try: 
    408             f = string.atof(fraction) 
    409             my.splitter(f) 
    410         except ValueError: 
    411             pass 
    412  
    413  
    414 class numberpane: 
    415     "Read a new number for the current pane." 
    416  
    417     def __init__(my, pane): 
    418         my.wm = pane.wm 
    419         window = paneWindow("New number: ", pane.screen) 
    420         window.read(my, MyEditHandler, pane.x, pane.y) 
    421  
    422     def __call__(my, name): 
    423         my.wm.panes_number(int(name)) 
    424  
    425 class pullwindow: 
    426     "Read a window's name, and pull it to the current pane." 
    427  
    428     def __init__(my, pane): 
    429         my.pane = pane 
    430         window = paneWindow("pull ", pane.screen) 
    431         window.read(my, MyEditHandler, pane.x, pane.y) 
    432  
    433     def __call__(my, name): 
    434         clients = my.pane.screen.query_clients(cfilter.re_title(name + ".*"), 1) 
    435         if len(clients) == 1: my.pane.add_window(clients[0]) 
    436         elif clients: windowmenu(my.pane, list = clients) 
    437         else: 
    438             width, height = my.pane.screen.message_make("No windows") 
    439             my.pane.screen.message_display(my.pane.x, my.pane.y) 
    440  
    441  
    442 class gotowindow: 
    443     "Emulate the rp 'goto' command." 
    444  
    445     def __init__(my, pane): 
    446         my.pane = pane 
    447         window = screenWindow("goto ", pane.screen) 
    448         window.read(my, MyEditHandler) 
    449  
    450     def __call__(my, name): 
    451         clients = my.pane.screen.query_clients(cfilter.re_title(name + ".*"), 1) 
    452         if clients: 
    453             window = clients[0] 
    454             if window.panes_pane.window and window.panes_pane.window == window: 
    455                 my.pane.wm.panes_activate(window.panes_pane) 
    456             else: 
    457                 my.pane.add_window(window) 
    458         else: 
    459             width, height = my.pane.screen.message_make("No windows") 
    460             my.pane.screen.message_display(0, 0) 
    461  
    462  
    463 def getapp(pane, name, command = None): 
    464     "Find a window starting with name, and run command if it doesn't exist." 
    465  
    466     clients = pane.screen.query_clients(cfilter.re_title(".*%s.*" % name), 1) 
    467     if len(clients) > 1: windowmenu(pane, list = clients) 
    468     elif clients: pane.add_window(clients[0]) 
    469     else: pane.screen.system((command or name) + " &") 
    470      
    471292 
    472293def restore(wm): 
     
    526347    wm.panes_restore() 
    527348 
    528 def split_pane(count, splitter): 
    529     "Split current pane into 2-9 equal-sized panes." 
    530  
    531     while count > 1: 
    532         splitter(1. / count) 
    533         count -= 1 
    534  
    535349 
    536350if __name__ == '__main__': 
  • trunk/utils/inspect_plwm.py

    r162 r177  
    1 #!/usr/bin/python 
     1#!/usr/bin/env python 
    22# 
    3 # $Id: inspect_plwm.py,v 1.3 2004-04-16 12:08:46 petli Exp $ 
     3# $Id: inspect_plwm.py,v 1.4 2005-08-07 03:18:53 mwm Exp $ 
    44# 
    55# inspect_plwm.py -- PLWM inspect client