Changeset 217 for trunk/examples/examplewm.py
- Timestamp:
- 07/23/2008 01:59:10 PM (6 months ago)
- Files:
-
- 1 modified
-
trunk/examples/examplewm.py (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/examples/examplewm.py
r215 r217 19 19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 20 21 ''' Example PLWM window manager 22 23 This example demonstrates basic window manager construction and some of the 24 more common window manager concepts such as a mode window, multiple views, 25 and window decorations. 26 ''' 21 27 22 28 import sys … … 47 53 outline.XorOutlineClient, 48 54 modestatus.ModeFocusedTitleClient): 55 ''' Example client class 56 57 This class adds an XOR outline for moving/resizing windows and a hook to 58 display the title of the currently-focused window in the mode window. It 59 also specifies a list of clients that should start in an iconified 60 (withdrawn) state and specifies default pointer positions for a couple of 61 programs. 62 ''' 49 63 50 64 # Put a frame around all client windows … … 63 77 views.XMW_ViewHandler, 64 78 modestatus.ModeFocusedTitleScreen): 79 ''' Example screen class 80 81 This class adds support for colors(FIXME), views, and a mode window, and 82 adds support to the mode window for displaying status(FIXME: clarify), 83 movement and resizing information, the current view, and the title of the 84 currently-focused window. 85 ''' 65 86 66 87 view_always_visible_clients = Or(name('XClock'), … … 69 90 70 91 class WMConfig: 92 ''' Example window manager configuration class 93 94 Installs the BasicKeys key map into the window manager. 95 96 TODO: Why is this not included in PLWM below? Should it be moved there? 97 ''' 71 98 def __wm_init__(self): 72 99 # Install the basic key map … … 82 109 inspect.InspectServer, 83 110 WMConfig): 111 ''' Example window manager class 112 113 This class sets up the configuration for the window manager, including font 114 support, sloppy focus, focus movement support, a clock and mail notifier 115 for the mode window, and inspection support. It also sets the client class 116 and screen class to use. 117 ''' 84 118 85 119 client_class = MyClient … … 88 122 89 123 class BasicKeys(keys.KeyHandler): 124 ''' Basic key bindings 125 126 This class defines all key-bindings for the example window manager. 127 ''' 128 90 129 def F1(self, event): 130 ''' Find a view containing an XTerm. 131 ''' 91 132 self.wm.current_screen.view_find_with_client(name('XTerm')) 92 133 93 134 def S_F1(self, event): 135 ''' Start an XTerm. 136 ''' 94 137 self.wm.system('xterm -geometry 80x50+200+100') 95 138 96 139 def C_S_F1(self, event): 140 ''' Start an XTerm in a new view. 141 ''' 97 142 self.wm.current_screen.view_new() 98 143 self.wm.system('xterm -geometry 80x50+200+100') 99 144 100 145 def F2(self, event): 146 ''' Find a view containing an Emacs window. 147 ''' 101 148 self.wm.current_screen.view_find_with_client(name('Emacs')) 102 149 103 150 def S_F2(self, event): 151 ''' Start Emacs. 152 ''' 104 153 self.wm.system('emacs') 105 154 106 155 def C_S_F2(self, event): 156 ''' Start Emacs in a new view. 157 ''' 107 158 self.wm.current_screen.view_new() 108 159 self.wm.system('emacs') 109 160 110 161 def F3(self, event): 162 ''' Find a view containing a Netscape window. 163 ''' 111 164 self.wm.current_screen.view_find_with_client(name('Netscape')) 112 165 113 166 def S_F3(self, event): 167 ''' Start Netscape. 168 ''' 114 169 self.wm.system('netscape') 115 170 116 171 def C_S_F3(self, event): 172 ''' Start Netscape in a new view. 173 ''' 117 174 self.wm.current_screen.view_new() 118 175 self.wm.system('netscape') 119 176 120 177 def F5(self, event): 178 ''' Switch to the next view with the tag 'F5'. 179 ''' 121 180 self.wm.current_screen.view_find_tag('F5') 122 181 123 182 def S_F5(self, event): 183 ''' Set the current view's tag to 'F5'. 184 ''' 124 185 self.wm.current_screen.view_tag('F5') 125 186 126 187 def F6(self, event): 188 ''' Switch to the next view with the tag 'F6'. 189 ''' 127 190 self.wm.current_screen.view_find_tag('F6') 128 191 129 192 def S_F6(self, event): 193 ''' Set the current view's tag to 'F6'. 194 ''' 130 195 self.wm.current_screen.view_tag('F6') 131 196 132 197 def F7(self, event): 198 ''' Switch to the next view with the tag 'F7'. 199 ''' 133 200 self.wm.current_screen.view_find_tag('F7') 134 201 135 202 def S_F7(self, event): 203 ''' Set the current view's tag to 'F7'. 204 ''' 136 205 self.wm.current_screen.view_tag('F7') 137 206 138 207 def F8(self, event): 208 ''' Switch to the next view with the tag 'F8'. 209 ''' 139 210 self.wm.current_screen.view_find_tag('F8') 140 211 141 212 def S_F8(self, event): 213 ''' Set the current view's tag to 'F8'. 214 ''' 142 215 self.wm.current_screen.view_tag('F8') 143 216 144 217 # Simulate mouse clicks 145 218 def Any_F9(self, evt): 219 ''' Simulate a primary (usually, left) mouse button click. 220 ''' 146 221 self.wm.fake_button_click(1) 147 222 148 223 def Any_F10(self, evt): 224 ''' Simulate a secondary (usually, right) mouse button click. 225 ''' 149 226 self.wm.fake_button_click(2) 150 227 151 228 def Any_F11(self, evt): 229 ''' Simulate a tertiary (usually, middle) mouse button click. 230 ''' 152 231 self.wm.fake_button_click(3) 153 232 154 233 155 234 def F12(self, evt): 235 ''' Toggle inspect mode. 236 ''' 156 237 self.wm.inspect_toggle() 157 238 158 239 def S_F12(self, evt): 240 ''' Toggle inspect mode, forcing if needed. 241 ''' 159 242 self.wm.inspect_toggle(force = 1) 160 243 161 # Drop all keygrabs until Scroll_Lock is pressed again, to allow162 # clients to recieve keys used by plwm163 164 244 def S_Pause(self, evt): 245 ''' Drop all keygrabs until Scroll_Lock is pressed again. 246 247 Allows clients to recieve keys used by plwm. 248 ''' 165 249 wmanager.debug('keys', 'dropping keygrabs temporarily') 166 250 … … 173 257 174 258 def KP_Begin(self, event): 259 ''' Start moving / resizing the current window. 260 ''' 175 261 MyMoveResizeKeys(self, event) 176 262 177 263 178 264 def C_Tab(self, event): 265 ''' Cycle through minimized windows. 266 ''' 179 267 CycleUMKeys(self, event) 180 268 181 269 def KP_Insert(self, event): 270 ''' Iconify the current window. 271 ''' 182 272 wmanager.debug('keys', 'Iconifying') 183 273 if self.wm.current_client: … … 185 275 186 276 def KP_Subtract(self, event): 277 ''' Switch to the previous view. 278 ''' 187 279 wmanager.debug('keys', 'Prev view') 188 280 self.wm.current_screen.view_prev() 189 281 190 282 def KP_Add(self, event): 283 ''' Switch to the next view. 284 ''' 191 285 wmanager.debug('keys', 'Next view') 192 286 self.wm.current_screen.view_next() 193 287 194 288 def C_KP_Add(self, event): 289 ''' Create a new view. 290 ''' 195 291 wmanager.debug('keys', 'New view') 196 292 self.wm.current_screen.view_new() 197 293 198 294 def KP_Left(self, event): 295 ''' Move the pointer to the left. 296 ''' 199 297 self.wm.display.warp_pointer(-delta.get(event.time), 0) 200 298 201 299 def KP_Right(self, event): 300 ''' Move the pointer to the right. 301 ''' 202 302 self.wm.display.warp_pointer(delta.get(event.time), 0) 203 303 204 304 def KP_Up(self, event): 305 ''' Move the pointer up. 306 ''' 205 307 self.wm.display.warp_pointer(0, -delta.get(event.time)) 206 308 207 309 def KP_Down(self, event): 310 ''' Move the pointer down. 311 ''' 208 312 self.wm.display.warp_pointer(0, delta.get(event.time)) 209 313 210 314 def KP_Home(self, event): 315 ''' Move the pointer up and to the left. 316 ''' 211 317 d = delta.get(event.time) 212 318 self.wm.display.warp_pointer(-d, -d) 213 319 214 320 def KP_End(self, event): 321 ''' Move the pointer down and to the left. 322 ''' 215 323 d = delta.get(event.time) 216 324 self.wm.display.warp_pointer(-d, d) 217 325 218 326 def KP_Prior(self, event): 327 ''' Move the pointer up and to the right. 328 ''' 219 329 d = delta.get(event.time) 220 330 self.wm.display.warp_pointer(d, -d) 221 331 222 332 def KP_Next(self, event): 333 ''' Move the pointer down and to the right. 334 ''' 223 335 d = delta.get(event.time) 224 336 self.wm.display.warp_pointer(d, d) 225 337 226 338 def KP_Enter(self, event): 339 ''' Raise or lower the current window. 340 ''' 227 341 if self.wm.current_client: 228 342 self.wm.current_client.raiselower() … … 232 346 233 347 def C_KP_Subtract(self, event): 348 ''' Lock the screen with xlock. 349 ''' 234 350 self.wm.system('xlock -mode blank') 235 351 236 352 def C_M_Escape(self, event): 353 ''' Quit the window manager. 354 ''' 237 355 self.wm.quit() 238 356 239 357 def C_KP_Delete(self, event): 358 ''' Close the current window. 359 ''' 240 360 if self.wm.current_client: 241 361 self.wm.current_client.delete(1) 242 362 243 363 def C_S_KP_Delete(self, event): 364 ''' Kill the current client. 365 ''' 244 366 if self.wm.current_client: 245 367 self.wm.current_client.destroy() 246 368 247 369 def C_KP_Left(self, event): 370 ''' Focus the next window to the left of the current one. 371 ''' 248 372 self.wm.move_focus(focus.MOVE_LEFT) 249 373 250 374 def C_KP_Right(self, event): 375 ''' Focus the next window to the right of the current one. 376 ''' 251 377 self.wm.move_focus(focus.MOVE_RIGHT) 252 378 253 379 def C_KP_Up(self, event): 380 ''' Focus the next window above the current one. 381 ''' 254 382 self.wm.move_focus(focus.MOVE_UP) 255 383 256 384 def C_KP_Down(self, event): 385 ''' Focus the next window below the current one. 386 ''' 257 387 self.wm.move_focus(focus.MOVE_DOWN) 258 388 259 389 def C_less(self, event): 390 ''' Focus the next window to the left of the current one. 391 ''' 260 392 self.wm.move_focus(focus.MOVE_LEFT) 261 393 262 394 def C_S_less(self, event): 395 ''' Focus the next window to the right of the current one. 396 ''' 263 397 self.wm.move_focus(focus.MOVE_RIGHT) 264 398 265 399 266 400 class BypassHandler(keys.KeyHandler): 401 ''' Surrogate key handler to bypass the window manager's key bindings. 402 403 Allows clients to receive key presses normally handled by the WM. 404 ''' 267 405 propagate_keys = 0 268 406 … … 275 413 276 414 def Pause(self, evt): 415 ''' Restore normal key bindings. 416 ''' 277 417 wmanager.debug('keys', 'reinstalling keygrabs') 278 418 … … 294 434 295 435 class MyMoveResizeKeys(MoveResizeKeys): 436 ''' Keys for moving and resizing the current window. 437 ''' 296 438 KP_Left = MoveResizeKeys._move_w 297 439 KP_Right = MoveResizeKeys._move_e … … 330 472 331 473 class CycleUMKeys(CycleKeys): 474 ''' Keys to cycle through all iconified windows. 475 ''' 332 476 _cycle_filter = iconified 333 477
