Changeset 179

Show
Ignore:
Timestamp:
08/10/2005 08:30:38 AM (3 years ago)
Author:
mwm
Message:

Add websearch class that reads a string from the user, then launches a web search
for that string. Inspired by similar facilities in Peter Maurer's "Butler" launcher
for OS X.

Add hot keys for google, google directory, google images, webster dictionary and webster
thesaurus web searches.

Location:
trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/examples/plpwm.py

    r178 r179  
    11#!/usr/bin/env python 
    2 # $Id: plpwm.py,v 1.38 2005-08-07 04:22:18 mwm Exp $ 
     2# $Id: plpwm.py,v 1.39 2005-08-10 13:30:36 mwm Exp $ 
    33# 
    44# plpwm.py -- Example PLWM window manager configuration with panes. 
     
    3636 
    3737from plwm.pane_utilities import appmenu, codemenu, windowmenu, panesmenu, \ 
    38      runcommand, splitpane, numberpane, pullwindow, gotowindow, \ 
     38     runcommand, splitpane, numberpane, pullwindow, gotowindow, websearch, \ 
    3939     split_pane, getapp 
     40 
    4041 
    4142class MyMenuHandler(menu.MenuCharHandler): 
     
    9798 
    9899 
     100class paneWindow(input.inputWindow): 
     101    bordercolor = "Goldenrod" 
     102    editHandler = MyEditHandler 
     103 
     104 
     105class screenWindow(input.inputWindow): 
     106    borderwidth = 5 
     107    bordercolor = "Orange" 
     108    editHandler = MyEditHandler 
     109 
     110 
    99111class PaneKeys(keys.KeyHandler): 
    100112    "The pane control keys." 
     
    146158        getapp(my.wm.panes_list[my.wm.panes_current], "xclipboard") 
    147159 
     160    def M4_d(my, event): 
     161        websearch(my.wm.panes_list[my.wm.panes_current], MyEditHandler, 
     162                  "Google Directory", paneWindow, 
     163                  "http://www.google.com/search?q=%s&it=ISO-8859-1&oe=ISO-8859-1&cat=gwd%%2FTop") 
     164 
    148165    def M4_e(my, event): 
    149166        my.wm.panes_goto(0)     # always run emacs in pane 0. 
    150167        getapp(my.wm.panes_list[my.wm.panes_current], "emacs", "xemacs") 
    151168 
     169    def M4_f(my, event): 
     170        getapp(my.wm.panes_list[my.wm.panes_current], "Firefox", "firefox") 
     171 
    152172    def M4_g(my, event): 
     173        websearch(my.wm.panes_list[my.wm.panes_current], MyEditHandler, 
     174                  "Google", paneWindow, 
     175                  'http://www.google.com/search?q=%s&hl=en&safe=off') 
     176 
     177    def M4_G(my, event): 
    153178        getapp(my.wm.panes_list[my.wm.panes_current], 
    154179               "GnuCash", "gnucash") 
    155180 
    156181    def M4_i(my, event): 
     182        def firefox(url): 
     183            assert "'" not in url 
     184            my.wm.system("firefox '%s' &" % url) 
     185 
     186        websearch(my.wm.panes_list[my.wm.panes_current], MyEditHandler, 
     187                  "Google Images", paneWindow, 
     188                  'http://images.google.com/images?q=%s&ie=ISO-8859-1&oe=ISO-8859-1', 
     189                  firefox) 
     190 
     191    def M4_I(my, event): 
    157192        getapp(my.wm.panes_list[my.wm.panes_current], 
    158193               "/home/mwm/axhome/axMail/Inbox.sp", "applix -inbox") 
     
    161196        getapp(my.wm.panes_list[my.wm.panes_current], "J-Pilot", "jpilot") 
    162197 
    163     def M4_f(my, event): 
    164         getapp(my.wm.panes_list[my.wm.panes_current], "Mozilla", "mozilla") 
     198    def M4_t(my, event): 
     199        websearch(my.wm.panes_list[my.wm.panes_current], MyEditHandler, 
     200                  "Webster Thesaurus", paneWindow, 
     201                  "http://www.webster.com/cgi-bin/thesaurus?book=Thesaurus&va=%s") 
     202 
     203    def M4_w(my, event): 
     204        websearch(my.wm.panes_list[my.wm.panes_current], MyEditHandler, 
     205                  "Webster Dictionary", paneWindow, 
     206                  "http://www.webster.com/cgi-bin/dictionary?book=Dictionary&va=%s") 
    165207 
    166208    # Keystrokes for window manager operations 
     
    174216        gotowindow(my.wm.panes_list[my.wm.panes_current], screenWindow) 
    175217 
    176     def M4_Return(my, event): 
     218    def M4_space(my, event): 
    177219        my.wm.panes_list[my.wm.panes_current].prev_window() 
    178220 
    179     def S_M4_Return(my, event): 
     221    def S_M4_space(my, event): 
    180222        my.wm.panes_list[my.wm.panes_current].next_window() 
    181223 
     
    194236    def M4_x(my, event): 
    195237        my.wm.panes_list[my.wm.panes_current].iconify_window() 
    196  
    197     # Aliases for some of the keystrokes 
    198     M4_space = M4_Return 
    199     S_M4_space = S_M4_Return 
    200238 
    201239 
     
    278316    Any_g = Any_Escape = keys.KeyGrabKeyboard._timeout 
    279317     
    280  
    281 class paneWindow(input.inputWindow): 
    282     bordercolor = "Goldenrod" 
    283     editHandler = MyEditHandler 
    284  
    285  
    286 class screenWindow(input.inputWindow): 
    287     borderwidth = 5 
    288     bordercolor = "Orange" 
    289     editHandler = MyEditHandler 
    290  
    291318 
    292319def restore(wm): 
  • trunk/plwm/keys.py

    r103 r179  
    1 # $Id: keys.py,v 1.8 2002-01-16 12:38:27 petli Exp $ 
     1# $Id: keys.py,v 1.9 2005-08-10 13:30:37 mwm Exp $ 
    22# 
    33# keys.py -- Base keypress handlers 
     
    142142             
    143143         
     144        wmanager.debug('mem', 'Initing keyhandler %s', self) 
     145 
    144146        # Figure out if we have been added to a WindowManager, Screen 
    145147        # or Client object.  Set up KeygrabManager objects if not 
  • trunk/plwm/menu.py

    r163 r179  
    1 # $Id: menu.py,v 1.12 2004-10-25 17:47:13 mtigges Exp $ 
     1# $Id: menu.py,v 1.13 2005-08-10 13:30:38 mwm Exp $ 
    22# 
    33# menu.py -- Screen mixin to provide menus. 
     
    4747 
    4848    def _do(my, event): 
     49        my._cleanup() 
    4950        my.menu.do() 
    50         my._cleanup() 
    5151 
    5252    def _abort(my, event): 
  • trunk/plwm/pane_utilities.py

    r178 r179  
    11#!/usr/bin/env python 
    2 # $Id: pane_utilities.py,v 1.2 2005-08-07 04:22:18 mwm Exp $ 
     2# $Id: pane_utilities.py,v 1.3 2005-08-10 13:30:38 mwm Exp $ 
    33# 
    44# pane_utilities.py -- Utility clases and functions for use with panes 
     
    2121 
    2222import cfilter 
     23from webbrowser import open_new 
     24from urllib import quote 
    2325 
    2426class appmenu: 
     
    119121             
    120122 
     123class websearch: 
     124    "Launch a browser with a web search from the user." 
     125 
     126    def __init__(my, pane, editHandler, name, winclass, format, browser = None): 
     127        my.format = format 
     128        my.browser = browser 
     129        my.pane = pane 
     130        window = winclass("Search %s: " % name, pane.screen, length = 50) 
     131        window.read(my, editHandler, pane.x, pane.y) 
     132 
     133    def __call__(my, string): 
     134        query = my.format % quote(string) 
     135        if my.browser: 
     136            my.browser(query) 
     137        else: 
     138            open_new(query) 
     139             
     140 
    121141class runcommand: 
    122142    "Read a string from the user, and run it."