Changeset 1471

Show
Ignore:
Timestamp:
07/08/08 12:20:56 (2 months ago)
Author:
rob
Message:

Fixed #480: added DescribeKey? action
* modified keystroke processing to send an action to a callback rather than processing the action
* updated the keystroke definition to use the built-in keystrokes from wx itself rather than a hard-coded list here in the source
* changed some default key bindings to C-h for Help

Location:
trunk/peppy
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/peppy/lib/wxemacskeybindings.py

    r1433 r1471  
    2121import wx 
    2222 
    23 wxkeynames = ( 
    24     "BACK", "TAB", "RETURN", "ESCAPE", "SPACE", "DELETE", "START", 
    25     "LBUTTON", "RBUTTON", "CANCEL", "MBUTTON", "CLEAR", "PAUSE", 
    26     "CAPITAL", "PRIOR", "NEXT", "END", "HOME", "LEFT", "UP", "RIGHT", 
    27     "DOWN", "SELECT", "PRINT", "EXECUTE", "SNAPSHOT", "INSERT", "HELP", 
    28     "NUMPAD0", "NUMPAD1", "NUMPAD2", "NUMPAD3", "NUMPAD4", "NUMPAD5", 
    29     "NUMPAD6", "NUMPAD7", "NUMPAD8", "NUMPAD9", "MULTIPLY", "ADD", 
    30     "SEPARATOR", "SUBTRACT", "DECIMAL", "DIVIDE", "F1", "F2", "F3", "F4", 
    31     "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "F13", "F14", 
    32     "F15", "F16", "F17", "F18", "F19", "F20", "F21", "F22", "F23", "F24", 
    33     "NUMLOCK", "SCROLL", "PAGEUP", "PAGEDOWN", "NUMPAD_SPACE", 
    34     "NUMPAD_TAB", "NUMPAD_ENTER", "NUMPAD_F1", "NUMPAD_F2", "NUMPAD_F3", 
    35     "NUMPAD_F4", "NUMPAD_HOME", "NUMPAD_LEFT", "NUMPAD_UP", 
    36     "NUMPAD_RIGHT", "NUMPAD_DOWN", "NUMPAD_PRIOR", "NUMPAD_PAGEUP", 
    37     "NUMPAD_NEXT", "NUMPAD_PAGEDOWN", "NUMPAD_END", "NUMPAD_BEGIN", 
    38     "NUMPAD_INSERT", "NUMPAD_DELETE", "NUMPAD_EQUAL", "NUMPAD_MULTIPLY", 
    39     "NUMPAD_ADD", "NUMPAD_SEPARATOR", "NUMPAD_SUBTRACT", "NUMPAD_DECIMAL", 
    40     "NUMPAD_DIVIDE", 
    41     ) 
     23# The list of all the wx keynames (without the WXK_ prefix) is needed by both 
     24# KeyMap and KeyProcessor objects 
     25wxkeynames = [i[4:] for i in dir(wx) if i.startswith('WXK_')] 
     26 
    4227 
    4328class DuplicateKeyError(Exception): 
     
    333318    """ 
    334319    debug = False 
    335      
     320 
     321    # Mapping of wx keystroke numbers to keystroke names 
     322    wxkeys = {} 
     323    for i in wxkeynames: 
     324        wxkeys[getattr(wx, "WXK_"+i)] = i 
     325    for i in ("SHIFT", "ALT", "COMMAND", "CONTROL", "MENU"): 
     326        if wx.Platform == '__WXGTK__': 
     327            # unix doesn't create a keystroke when a modifier key 
     328            # is also modified by another modifier key, so we 
     329            # create entries here so that decode() doesn't have to 
     330            # have platform-specific code 
     331            wxkeys[getattr(wx, "WXK_"+i)] = i[0:1]+'-' 
     332        else: 
     333            wxkeys[getattr(wx, "WXK_"+i)] = '' 
     334 
    336335    def __init__(self,status=None): 
    337336        self.keymaps=[] 
     
    367366        self.universalArgument="C-U" 
    368367        self.processingArgument=0 
     368         
     369        # If reportNext is not None, instead of being processed the next action 
     370        # is reported to a caller by using reportNext as a callback. 
     371        self.reportNext = None 
    369372 
    370373        self.hasshown=False 
    371374        self.reset() 
    372  
    373         # Mapping of wx keystroke numbers to keystroke names 
    374         self.wxkeys={} 
    375         # set up the wxkeys{} dict 
    376         self.wxkeymap() 
    377  
    378     def wxkeymap(self): 
    379         for i in wxkeynames: 
    380             self.wxkeys[getattr(wx, "WXK_"+i)] = i 
    381         for i in ("SHIFT", "ALT", "COMMAND", "MENU"): 
    382             if wx.Platform == '__WXGTK__': 
    383                 # unix doesn't create a keystroke when a modifier key 
    384                 # is also modified by another modifier key, so we 
    385                 # create entries here so that decode() doesn't have to 
    386                 # have platform-specific code 
    387                 self.wxkeys[getattr(wx, "WXK_"+i)] = i[0:1]+'-' 
    388             else: 
    389                 self.wxkeys[getattr(wx, "WXK_"+i)] = '' 
    390375 
    391376    def findStickyMeta(self): 
     
    486471                keyname = chr(keycode) 
    487472            else: 
    488                 keyname = "(%s)unknown" % keycode 
     473                keyname = "unknown-%s" % keycode 
    489474        if self.debug: print("modifiers: raw=%d processed='%s' keyname=%s keycode=%s key=%s" % (emods, modifiers, keyname, keycode, modifiers+keyname)) 
    490475        return modifiers + keyname 
     
    514499        """ 
    515500        if self.status: 
     501            if self.reportNext: 
     502                text = "Describe Key: %s" % text 
    516503            self.status.SetStatusText(text) 
    517504            self.hasshown=True 
     
    608595            self.args+=key + ' ' 
    609596            self.processingArgument+=1 
     597     
     598    def setReportNext(self, callback): 
     599        self.reportNext = callback 
     600        self.show('') 
    610601 
    611602    def process(self, evt): 
     
    635626                skip, unknown, function = self.add(key) 
    636627            self.reset() 
    637             self.show("Quit") 
    638             if function: 
    639                 function(evt, printable=False) 
     628            if self.reportNext: 
     629                self.reportNext(function) 
     630                self.reportNext = None 
     631            else: 
     632                self.show("Quit") 
     633                if function: 
     634                    function(evt, printable=False) 
    640635        elif self.metaNext: 
    641636            # OK, the meta sticky key is down, but it's not a quit 
     
    679674                    printable = not self.modifier 
    680675                    self.reset() 
    681                     if save is not None: 
    682                         function(evt,save, printable=printable) 
     676                    if self.reportNext: 
     677                        self.reportNext(function) 
     678                        self.reportNext = None 
    683679                    else: 
    684                         function(evt, printable=printable) 
     680                        if save is not None: 
     681                            function(evt,save, printable=printable) 
     682                        else: 
     683                            function(evt, printable=printable) 
    685684                elif unknown: 
    686685                    # This is an unknown keystroke combo 
    687686                    sf = "%s not defined."%(self.sofar) 
    688687                    self.reset() 
     688                    if self.reportNext: 
     689                        self.reportNext(None) 
     690                        self.reportNext = None 
    689691                    self.show(sf) 
    690692                elif skip: 
     
    693695                    # to get processed elsewhere. 
    694696                    self.reset() 
    695                     evt.Skip() 
     697                    if self.reportNext: 
     698                        self.reportNext(None) 
     699                        self.reportNext = None 
     700                    else: 
     701                        evt.Skip() 
    696702                else: 
    697703                    self.show(self.args+self.sofar) 
  • trunk/peppy/mainmenu.py

    r1460 r1471  
    799799    tooltip = "Describe an action by name" 
    800800    default_menu = ("&Help", -200) 
     801    key_bindings = {'emacs': "C-h a", } 
    801802 
    802803    def __init__(self, *args, **kwargs): 
     
    825826 
    826827 
     828class DescribeKey(SelectAction): 
     829    """Look up the action from the keystroke""" 
     830    name = "&Describe Key" 
     831    alias = "describe-key" 
     832    default_menu = ("&Help", 201) 
     833    key_bindings = {'emacs': "C-h k", } 
     834 
     835    def action(self, index=-1, multiplier=1): 
     836        self.frame.keys.setReportNext(self.displayAction) 
     837 
     838    def displayAction(self, action): 
     839        if action: 
     840            dprint("looking up docs for %s" % action) 
     841            Publisher().sendMessage('peppy.log.info', action.getHelp()) 
     842            self.frame.SetStatusText("Keystroke found.") 
     843        else: 
     844            self.frame.SetStatusText("Unbound keystroke.") 
     845 
     846 
    827847class CancelMinibuffer(SelectAction): 
    828848    alias = "cancel-minibuffer" 
     
    841861    tooltip = "Show help for the currently active minibuffer" 
    842862    default_menu = ("&Help", 210) 
    843     key_bindings = {'emacs': "M-S-/ m", } 
     863    key_bindings = {'emacs': "C-h m", } 
    844864     
    845865    def isEnabled(self): 
     
    903923                NewWindow, DeleteWindow, WindowList, 
    904924                 
    905                 ExecuteActionByName, DescribeAction, HelpMinibuffer, 
     925                ExecuteActionByName, DescribeAction, DescribeKey, HelpMinibuffer, 
    906926                 
    907927                CancelMinibuffer, 
  • trunk/peppy/plugins/keyboard.py

    r1290 r1471  
    2525    alias = "describe-keys" 
    2626    default_menu = ("&Help", 210) 
    27     key_bindings = {'emacs': "M-/ B", } 
     27    key_bindings = {'emacs': "C-h b", } 
    2828 
    2929    def action(self, index=-1, multiplier=1):