Changeset 96

Show
Ignore:
Timestamp:
12/20/07 17:58:03
Author:
slee
Message:

added keyboard operated scanning

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • action_groups/trunk/ActionBrowser.py

    r94 r96  
    1616from ActionTree import ActionTree 
    1717from Blinker import Blinker 
     18import MessageTransport 
    1819 
    1920_ = lambda x: x 
     21 
     22ACTION_KEY_DOWN, ACTION_SWITCH_DOWN, ACTION_MOUSE_CLICK = xrange(3) 
     23 
     24_mt = MessageTransport.MessageTransport() 
     25class DeviceMessage(MessageTransport.Message): 
     26  transport = _mt 
    2027 
    2128if not is_plugin: 
     
    105112 
    106113    self.show_all() 
     114 
     115    pyatspi.Registry.registerKeystrokeListener( 
     116      self._onKeyDown, 
     117      kind=(pyatspi.KEY_PRESSED_EVENT,)) 
    107118 
    108119  def _onGenerate(self, button): 
     
    158169    self.bl.start() 
    159170 
     171  def _onKeyDown(self, event): 
     172    gm = DeviceMessage(ACTION_KEY_DOWN, event.id) 
     173    gm.send(handler=self._onDeviceAction) 
     174 
    160175  def _onSwitchDown(self, widget, device, switch): 
    161     if switch in (0, 4): 
    162       self.groups_tree.next() 
    163     elif switch in (1, 6): 
    164       self.groups_tree.do_action() 
    165        
     176    gm = DeviceMessage(ACTION_SWITCH_DOWN, switch) 
     177    gm.send(handler=self._onDeviceAction) 
     178 
    166179  def _onButtonPressEvent(self, widget, event): 
    167180    SINGLE, DOUBLE = event.type == gtk.gdk.BUTTON_PRESS \ 
     
    170183                          , event.button == 3 \ 
    171184                          , event.button == 2 
    172     ALT, CONTROL, SHIFT = event.state & gtk.gdk.MOD1_MASK <> 0 \ 
    173                           , event.state & gtk.gdk.CONTROL_MASK <> 0 \ 
    174                           , event.state & gtk.gdk.SHIFT_MASK <> 0 
    175     x, y = int(event.x), int(event.y) 
    176      
    177     if MIDDLE and SINGLE: 
    178       self.groups_tree.next() 
    179       return False 
    180      
    181     elif RIGHT and SINGLE: 
    182       self.groups_tree.do_action() 
     185    if SINGLE and (MIDDLE or RIGHT): 
     186      gm = DeviceMessage(ACTION_MOUSE_CLICK, event.button) 
     187      gm.send(handler=self._onDeviceAction) 
    183188      return False 
    184189       
    185190    return True 
     191 
     192  def _onDeviceAction(self, action, id): 
     193    LEFT, RIGHT, MIDDLE = 1, 3, 2 
     194     
     195    # map gestures to actions 
     196    if (action == ACTION_KEY_DOWN and id in (gtk.keysyms.Control_L,)) or \ 
     197       (action == ACTION_SWITCH_DOWN and id in (0, 4)) or \ 
     198       (action == ACTION_MOUSE_CLICK) and id == MIDDLE: 
     199      self.groups_tree.next() 
     200    elif (action == ACTION_KEY_DOWN and id in (gtk.keysyms.space,)) or \ 
     201       (action == ACTION_SWITCH_DOWN and id in (1, 6)) or \ 
     202       (action == ACTION_MOUSE_CLICK) and id == RIGHT: 
     203      self.groups_tree.do_action() 
     204    return True 
  • action_groups/trunk/ActionModel.py

    r95 r96  
    228228   
    229229class Scrollable(AccDecorator): 
     230  V_SCROLLBAR, H_SCROLLBAR = xrange(2) 
    230231  def __init__(self, acc): 
    231232    AccDecorator.__init__(self, acc) 
     
    239240      return None 
    240241  def scrollIntoView(y): 
    241     self.getScrollbar().currentValue = y 
     242    self.getVScrollbar().currentValue = y 
    242243     
    243244class ScrollableSelection(Scrollable): 
  • action_groups/trunk/ActionTree.py

    r95 r96  
    77from ActionModel import ActionModel 
    88from AccDecorator import AccDecorator 
    9 from MessageTransport import Message 
     9import MessageTransport 
    1010from KeyGenerator import sendKeyCombination 
    1111 
     
    3636    self.app = None 
    3737    self.adding_children = False 
     38    self.mt = MessageTransport.MessageTransport() 
    3839    #self.set_property('fixed-height-mode', True) # speed display 
    3940 
     
    142143 
    143144    source_acc = AccDecorator(event.source) 
    144      
    145     class PrintMessage(Message): 
    146       _handler = self._onPrint 
    147     class ShowMenuMessage(Message): 
    148       _handler = self._onShowMenu 
    149     class HideMenuMessage(Message): 
    150       _handler = self._onHideMenu 
    151     class WindowActivateMessage(Message): 
    152       _handler = self._onWindowActivate 
    153     class ChildChangedMessage(Message): 
    154       _handler = self._onChildChanged 
     145 
     146    class MyMessage(MessageTransport.Message): 
     147      transport = self.mt 
     148    class PrintMessage(MyMessage): 
     149      handler = self._onPrint 
     150    class ShowMenuMessage(MyMessage): 
     151      handler = self._onShowMenu 
     152    class HideMenuMessage(MyMessage): 
     153      handler = self._onHideMenu 
     154    class WindowActivateMessage(MyMessage): 
     155      handler = self._onWindowActivate 
     156    class ChildChangedMessage(MyMessage): 
     157      handler = self._onChildChanged 
    155158     
    156159    s = formatEvent(event) 
     
    225228 
    226229  def _onPrint(self, data): 
    227     print data 
     230    #print data 
     231    pass 
    228232 
    229233  def _onWindowActivate(self, top): 
  • action_groups/trunk/MessageTransport.py

    r81 r96  
    99class MessageTransport(): 
    1010  '''sending events from a ATSP Listener to a handler ''' 
    11   def __init__(self, handler): 
     11  def __init__(self, handler=lambda msg: msg.handle()): 
    1212    self._queue = [] 
    1313    self._handler = handler 
     
    2929    return False  # remove this from idle processing 
    3030 
    31 mt = MessageTransport(lambda msg: msg.handle()) 
    32  
    3331class Message(): 
    3432  ''' ABC for messages ''' 
    35   _handler = None  # defined in subclass 
     33  transport = None       # defined in subclass 
     34  handler = None  # defined in subclass 
    3635  def __init__(self, *data): 
    3736    self._data = data 
     37  def setTransport(self, transport): 
     38    self.transport = transport 
     39  def setHandler(self, handler): 
     40    self.handler = handler 
    3841  def handle(self): 
    39     self._handler(*self._data) 
    40   def send(self): 
    41     mt.send(self) 
     42    self.handler(*self._data) 
     43  def send(self, transport=None, handler=None): 
     44    if transport: self.transport=transport 
     45    if handler: self.handler=handler 
     46    self.transport.send(self) 
  • action_groups/trunk/README

    r88 r96  
    55Make sure gedit is already open and make it the active application again to be safe. 
    66 
    7 You really need a couple of USB switches as menus get messed with the mouse; 
    8 However if you leave the pointer in the spaces between the buttons then middle click is next and right click is action. 
    9 Or use scan and right click 
     7Gestures 
     8-------- 
     9Thanks to Eitan Isaacson you can operate using the keyboard 
     10 
     11next item -> Left Ctrl key, USB Switch 0 or 4, middle mouse button 
     12action item -> space key, USB switch 1 or 6, right mouse button 
     13 
     14For mouse you need to leave the pointer in the spaces between the buttons and menus do not display properly. 
    1015 
    1116Known Bugs