Changeset 72

Show
Ignore:
Timestamp:
11/16/07 20:10:03
Author:
slee
Message:

fixed menu problems

Files:

Legend:

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

    r70 r72  
    102102  def _onExamine(self, button): 
    103103    acc = self.groups_tree.get_selected_acc() 
    104     if acc
     104    if acc is not None
    105105      self.node.update(acc) 
    106106     
     
    127127  def _onSelectionChanged(self, selection): 
    128128    acc = self.groups_tree.get_selected_acc(selection) 
    129     if acc: 
    130       Blinker(acc) 
     129    if acc is not None: 
     130      try: 
     131        ci = acc.queryComponent() 
     132      except: 
     133        return 
     134      extents = ci.getExtents(pyatspi.DESKTOP_COORDS) 
     135      print extents 
     136      Blinker(extents) 
    131137 
    132138  def _onSwitchDown(self, widget, device, switch): 
     
    153159    self.append_column(tvc) 
    154160 
    155     self.next_children = False; 
     161    pyatspi.Registry.registerEventListener(self._onAccEventState, 'object:state-changed') 
    156162    #self.set_property('fixed-height-mode', True) # speed display 
    157163 
     
    171177  def _getSelection(self, selection=None): 
    172178    selection = selection or self.get_selection() 
    173 #    if selection is None: 
    174 #      return (self.get_model(), None, None) 
    175179    model, iter = selection.get_selected() 
    176     if iter
     180    if iter is not None
    177181      acc = model[iter][ProgressiveTreeModel.COL_ACC] 
    178182    else: 
     
    185189   
    186190  def get_acc_from_path(self, path): 
    187     if not self.get_model(): 
     191    try: 
     192      acc = self.get_model()[path][ProgressiveTreeModel.COL_ACC] 
     193    except: 
    188194      return None 
    189     return self.get_model()[path][ProgressiveTreeModel.COL_ACC] 
    190  
     195    return acc 
     196   
    191197  def set_top_acc(self, acc): 
    192198    model = ProgressiveTreeModel(acc) 
    193199    model.popLevel(None) # top 
    194200    self.set_model(model) 
    195     pyatspi.Registry.registerEventListener(self._onAccEventState, 'object:state-changed') 
    196201 
    197202  def __del__(self): 
     
    218223          self.next_children = True; 
    219224    self.select(nextiter) 
    220       
     225   
    221226  def _onAccEventState(self, event): 
    222227    ''' 
     
    233238    if acc is None:  
    234239      return 
    235     print event.type, event.detail1, event.detail2, event.source, acc, event.source.parent 
    236     if acc.getRole() == pyatspi.ROLE_MENU : 
    237       print 'menu' 
    238       if event.source.parent == acc._acc : 
    239         print 'parent' 
    240         if event.type in ('object:state-changed:showing'): 
    241           showing = event.detail1 
    242           path = model.get_path(iter) 
    243           if showing == 1 \ 
    244              and not model.iter_has_child(iter): 
    245             model.makeExpandable(iter) 
    246             model.popLevel(iter
    247             self.expand_row(path, False) 
    248           elif showing == 0 \ 
    249                and self.row_expanded(path): 
    250               self.collapse_row(path) 
    251               model.dePopLevel(iter, all=True) 
    252      
     240    print event.type, event.detail1, event.detail2, event.source, acc, repr(event.source.getRole()) 
     241    if event.source.getRole() == pyatspi.ROLE_WINDOW \ 
     242        and event.type in ('object:state-changed:showing'): 
     243      showing = bool(event.detail1) 
     244      path = model.get_path(iter) 
     245      if showing \ 
     246         and not model.iter_has_child(iter): 
     247        model.makeExpandable(iter) 
     248        model.popLevel(iter) 
     249        self.expand_row(path, False) 
     250      elif not showing: 
     251        menu_iter = model.iter_parent_with_role(iter, pyatspi.ROLE_MENU
     252        if menu_iter: 
     253          menu_path = model.get_path(menu_iter) 
     254          if self.row_expanded(menu_path): 
     255            self.collapse_row(menu_path) 
     256            model.dePopLevel(menu_iter, all=True) 
     257             
    253258  def do_action(self): 
    254259    model, iter, acc = self._getSelection() 
     
    271276class Blinker(object): 
    272277  max_blinks = 6 
    273   def __init__(self, acc): 
     278  def __init__(self, extents): 
     279    self.extents = extents 
    274280    display = gtk.gdk.display_get_default() 
    275281    screen = display.get_default_screen() 
     
    282288    self.inv = gtk.Invisible() 
    283289    self.inv.set_screen(screen) 
    284      
    285     try: 
    286       ci = acc.queryComponent() 
    287     except: 
    288       return 
    289  
    290     self.extents = ci.getExtents(pyatspi.DESKTOP_COORDS) 
     290   
    291291    self.blinks = 0 
    292292    gobject.timeout_add(30, self._drawRectangle) 
  • action_groups/trunk/action_tree.py

    r71 r72  
    4747    return req_states.issubset(act_states) 
    4848     
     49  def getStates(self, *states): 
     50    return self._acc.getState().getStates() 
     51     
    4952  def hasStateIn(self, *states): 
    5053    act_states = set(self._acc.getState().getStates()) 
     
    8184 
    8285  def isInteractive(self): 
    83     if not self.hasStates(pyatspi.STATE_SHOWING): 
    84       return False 
     86    if self.hasRoleIn(pyatspi.ROLE_SEPARATOR) \ 
     87       or not self.hasStates(pyatspi.STATE_SHOWING, pyatspi.STATE_VISIBLE, pyatspi.STATE_SENSITIVE): 
     88      return False 
     89    #print self, self.getStates() 
    8590    return self.isSelectable() or self.hasInterfaceIn('Action','EditableText') 
    8691 
     
    119124      child.is_group = self.isActionGroup(child) 
    120125      if child.isInteractive() or child.is_group: 
    121         print child 
    122126        self.items.append(child) 
    123127      else: 
     
    140144   
    141145  def isActionGroup(self, acc): 
    142     if not acc.hasStates(pyatspi.STATE_SHOWING): 
     146    if not acc.hasStates(pyatspi.STATE_SHOWING) \ 
     147      or acc.getRole() == pyatspi.ROLE_MENU: 
    143148      return False 
    144149    if acc.getRole() == pyatspi.ROLE_DOCUMENT_FRAME: 
     
    214219    self[iter][self.COL_FILLED] = False 
    215220 
     221  def iter_parent_with_role(self, iter, role): 
     222    while iter is not None: 
     223      if self[iter][ProgressiveTreeModel.COL_ACC].getRole() == role: 
     224        return iter 
     225      iter = self.iter_parent(iter) 
     226    return None 
     227