Changeset 81

Show
Ignore:
Timestamp:
12/12/07 10:12:12
Author:
slee
Message:

more stability

Files:

Legend:

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

    r80 r81  
    102102  def _onGenerate(self, button): 
    103103    if self.acc is not None: 
    104       app = self.acc.getApplication() 
    105       self.groups_tree.set_top_acc(app, self.acc) 
     104      if self.acc == self.acc.getApplication(): 
     105        acc = self.acc[0] # first frame 
     106      self.groups_tree.set_top_acc(acc) 
    106107      self.groups_tree.next() 
    107108 
  • action_groups/trunk/ActionModel.py

    r80 r81  
    5050      or role == pyatspi.ROLE_MENU: 
    5151      return False 
    52     if role in (pyatspi.ROLE_DOCUMENT_FRAME, pyatspi.ROLE_FRAME): 
     52    if role in (pyatspi.ROLE_DOCUMENT_FRAME, pyatspi.ROLE_FRAME, pyatspi.ROLE_DIALOG): 
    5353      return True 
    5454    #if role == pyatspi.ROLE_FRAME: 
     
    155155    self[iter][self.COL_FILLED] = False 
    156156 
    157   def iter_parent_with_role(self, iter, role): 
     157  def iter_parent_with_role(self, iter, *roles): 
    158158    while iter is not None: 
    159       if self[iter][ActionModel.COL_ACC].getRole() == role
     159      if self[iter][ActionModel.COL_ACC].getRole() in roles
    160160        return iter 
    161161      iter = self.iter_parent(iter) 
    162162    return None 
    163  
     163   
  • action_groups/trunk/ActionTree.py

    r80 r81  
    77from ActionModel import ActionModel 
    88from AccDecorator import AccDecorator 
     9from MessageTransport import Message 
    910 
    1011_ = lambda x: x 
    1112 
    12 _DISPATCH_PRINT, _DISPATCH_SHOW_MENU, _DISPATCH_HIDE_MENU  = range(3) 
     13__metaclass__ = type 
    1314 
    1415class ActionTree(gtk.TreeView): 
     
    6970    return acc 
    7071 
    71   def set_top_acc(self, app, acc): 
    72     if self.app is not None: 
    73       pyatspi.Registry.deregisterEventListener(self._onATSPIEvent, *ActionTree.EVENTS) 
    74     self.app = app 
     72  def set_top_acc(self, acc): 
    7573    model = ActionModel(acc) 
    7674    model.popLevel(None) # top 
    7775    self.set_model(model) 
    78     pyatspi.Registry.registerEventListener(self._onATSPIEvent, *ActionTree.EVENTS) 
     76    if self.app is None: 
     77      self.app = acc.getApplication() 
     78      pyatspi.Registry.registerEventListener(self._onATSPIEvent, *ActionTree.EVENTS) 
    7979 
    8080  def _onDestroy(self, object): 
     
    111111      return 
    112112     
    113     # assume added functions are processed in order  
     113    class PrintMessage(Message): 
     114      _handler = self._onPrint 
     115    class ShowMenuMessage(Message): 
     116      _handler = self._onShowMenu 
     117    class HideMenuMessage(Message): 
     118      _handler = self._onHideMenu 
     119    class WindowActivateMessage(Message): 
     120      _handler = self._onWindowActivate 
     121     
    114122    s = formatEvent(event) 
    115     self._dispatchEvent(_DISPATCH_PRINT, None, s) 
    116  
    117     if self._menu is not None: 
    118       if event.source.getRole() == pyatspi.ROLE_MENU and \ 
    119        event.source.name == self._menu.name and \ 
    120        event.type  == 'object:state-changed:selected': 
    121         selected = bool(event.detail1) 
    122         if selected: 
    123           self._dispatchEvent(_DISPATCH_SHOW_MENU) 
    124         else: 
    125           self._dispatchEvent(_DISPATCH_HIDE_MENU) 
    126       elif event.type == 'focus:' and \ 
    127            not (event.source.getRole() == pyatspi.ROLE_MENU and \ 
    128                 event.source.name == self._menu.name): 
    129         self._dispatchEvent(_DISPATCH_HIDE_MENU) 
    130  
    131     elif self._menu is None and \ 
    132          event.type == 'focus:' and \ 
    133          event.source.getRole() == pyatspi.ROLE_MENU: 
    134       self._dispatchEvent(_DISPATCH_PRINT, None, 'ZZZ') 
    135       self._menu = event.source 
    136       self._dispatchEvent(_DISPATCH_SHOW_MENU) 
     123    #PrintMessage(s).send() 
     124 
     125    if event.type == 'focus:' and \ 
     126        not (event.source.getRole() == pyatspi.ROLE_MENU): 
     127      PrintMessage(s).send() 
     128      HideMenuMessage(True).send() 
    137129       
    138   def _dispatchEvent(self, what, event=None, data=None): 
    139     gobject.idle_add(self._dispatchEventOnIdle, what, event, data) 
    140      
    141   def _dispatchEventOnIdle(self, what, event, data): 
    142     model, iter, acc = self._getSelection() 
    143     if acc is None:  
    144       return False 
    145  
    146     if what == _DISPATCH_SHOW_MENU: 
    147       if acc.hasRoleIn(pyatspi.ROLE_MENU): 
    148         model.makeExpandable(iter) 
    149         model.popLevel(iter) 
    150         path = model.get_path(iter) 
    151         self.expand_row(path, False) 
    152         acc.is_group = True 
    153         self.next() 
    154         self.focus() 
    155         #AccDecorator(event.source).dumpAccTree() 
     130    elif event.type in ('window:activate', 'window:restore'): 
     131      PrintMessage(s).send() 
     132      def parent_acc_with_role(acc, *roles): 
     133        while acc is not None: 
     134          if acc.getRole() in roles: 
     135            return acc 
     136          acc = acc.parent 
     137        return None 
     138      model = self.get_model() 
     139      root_acc = model.getRootAcc()  
     140      top = parent_acc_with_role(event.source, pyatspi.ROLE_DIALOG, pyatspi.ROLE_FRAME) 
     141      print '%s %s' % (root_acc, top) 
     142      # for some reason they are not the same accessible (well I can't see how they ever are) 
     143      if not(top.getRole() == root_acc.getRole() and top.name == root_acc.name): 
     144        WindowActivateMessage(top).send() 
     145 
     146    elif event.source.getRole() == pyatspi.ROLE_MENU and \ 
     147      event.type  == 'object:state-changed:selected': 
     148      PrintMessage(s).send() 
     149      selected = bool(event.detail1) 
     150      if selected: 
     151        ShowMenuMessage(event).send() 
     152      else: 
     153        HideMenuMessage().send() 
     154 
     155  def _onPrint(self, data): 
     156    print data 
     157 
     158  def _onWindowActivate(self, top): 
     159    print 'Activate' 
     160    self.set_top_acc(top) 
     161    self.next() 
     162 
     163  def _onShowMenu(self, event=None): 
     164    print 'ShowMenu' 
     165    model, iter, acc = self._getSelection() 
     166    if acc is None: return False 
     167    if acc.hasRoleIn(pyatspi.ROLE_MENU): 
     168      model.makeExpandable(iter) 
     169      model.popLevel(iter) 
     170      path = model.get_path(iter) 
     171      self.expand_row(path, False) 
     172      acc.is_group = True 
     173      self.next() 
     174      #self.focus() 
     175      #AccDecorator(event.source).dumpAccTree() 
    156176       
    157     elif what == _DISPATCH_HIDE_MENU: 
    158       menu_iter = model.iter_parent_with_role(iter, pyatspi.ROLE_MENU) 
    159       if menu_iter: 
    160         menu_path = model.get_path(menu_iter) 
    161         if self.row_expanded(menu_path): 
    162           self.collapse_row(menu_path) 
    163           model.dePopLevel(menu_iter, all=True) 
    164           acc.is_group = False 
    165           self.get_selection().select_iter(menu_iter) 
    166           self._menu = None 
    167            
    168     elif what == _DISPATCH_PRINT: 
    169       print data 
    170  
    171     return False  # remove this from idle processing 
    172      
     177  def _onHideMenu(self, all=False): 
     178    print 'HideMenu' 
     179    model, iter, acc = self._getSelection() 
     180    if None in (acc, iter): 
     181      return 
     182    menu_iter = None 
     183    while True: 
     184      next_menu_iter = model.iter_parent_with_role(iter, pyatspi.ROLE_MENU) 
     185      if next_menu_iter is None: 
     186        break 
     187      menu_iter = next_menu_iter 
     188      menu_path = model.get_path(menu_iter) 
     189      if self.row_expanded(menu_path): 
     190        self.collapse_row(menu_path) 
     191        model.dePopLevel(menu_iter, all=True) 
     192        acc.is_group = False 
     193      if all: 
     194        iter = model.iter_parent(menu_iter) 
     195      else: 
     196        break 
     197    if menu_iter is not None: 
     198      self.get_selection().select_iter(menu_iter) 
     199 
    173200  def do_action(self): 
    174201    model, iter, acc = self._getSelection() 
    175202    if acc is None: return 
    176203    path = model.get_path(iter) 
    177     acc.grabFocus() 
     204#    acc.grabFocus() 
    178205  
    179206    if acc.isEditable(): 
     
    189216          self._menu = acc 
    190217        if acc.hasRoleIn(pyatspi.ROLE_MENU, pyatspi.ROLE_MENU_ITEM) and acc.hasToolkitIn('Gecko'): 
     218 #       if acc.hasRoleIn(pyatspi.ROLE_MENU_ITEM): 
     219#          sendKeyCombination('Space', '')          
    191220          acc.generateClick() 
    192221        else: 
     
    215244        if acc.getRole() == pyatspi.ROLE_MENU: 
    216245          from KeyGenerator import sendKeyCombination 
     246          print 'Esc' 
    217247          sendKeyCombination('Escape', '')          
    218248        else: 
     
    220250      elif model.iter_has_child(iter): 
    221251        self.expand_row(path, False) 
    222         self.next() 
     252        self.next() # select 1st item 
    223253 
    224254  def goToPath(self, path): 
     
    248278  t = int(os.times()[-1] % 10000) 
    249279  ad = event.any_data 
    250   if isinstance(ad, pyatspi.Accessibility.BoundingBox): 
    251     sad = '\n\t%s,%s,%s,%s' % (ad.x, ad.y, ad.width, ad.height) 
     280  if False: 
     281    pass 
     282#  elif isinstance(ad, pyatspi.Accessibility.BoundingBox): 
     283#    sad = '\n\t%s,%s,%s,%s' % (ad.x, ad.y, ad.width, ad.height) 
    252284  elif ad: 
    253285    sad = str(ad) 
     
    257289                                   event.source, parent, sad)  
    258290  return s 
     291