Changeset 92

Show
Ignore:
Timestamp:
12/14/07 13:55:28
Author:
slee
Message:

add/remove children

Files:

Legend:

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

    r91 r92  
    2626      if child.is_interactive or child.is_group: 
    2727        self.items.append(child) 
    28         print '%s %s%s ' % (child._acc, ('i' if child.is_interactive else ''), 
    29                                          ('g' if child.is_group else '')) 
     28#        print '%s %s%s ' % (child._acc, ('i' if child.is_interactive else ''), 
     29#                                         ('g' if child.is_group else '')) 
    3030      elif child.hasStates(pyatspi.STATE_SHOWING): 
    3131        self._populateChildren(child) 
     
    108108    if iter is None: 
    109109      parent_acc = self.root_acc 
     110      path = () 
    110111    else: 
    111112      parent_acc = self[iter][self.COL_ACC] 
     113      path = self.get_path(iter) 
    112114 
    113115    ag = ActionGroup(parent_acc) 
    114     for child in ag
     116    for child, i in zip(ag, xrange(len(ag)))
    115117      self._appendChild(iter, child) 
    116       print child 
    117       sel.acc.cache[id(child)] = child 
     118      self.acc_cache[child._acc] = path +(i,) 
    118119         
    119120    if iter: 
     
    149150    iter_valid = bool(child_iter) 
    150151    while iter_valid and (all or not self[child_iter][self.COL_DUMMY]): 
     152      child = self[child_iter][ActionModel.COL_ACC] 
     153      if child is not None: 
     154        child = child._acc 
     155        del self.acc_cache[child] 
    151156      iter_valid = self.remove(child_iter) 
    152       child = self[child_iter][ActionModel.COL_ACC] 
    153       print child 
    154       del self.acc_cache[id(child)] 
    155157    self[iter][self.COL_FILLED] = False 
    156158 
     
    179181  def getAccPath(self, acc): 
    180182    try: 
    181       print acc 
    182       return self.acc_cache(id(acc)) 
    183     except LookupError: 
     183      if isinstance(acc, AccDecorator): 
     184        ac = acc._acc 
     185      path = self.acc_cache[acc] 
     186      return path 
     187    except KeyError: 
    184188      return None 
  • action_groups/trunk/ActionTree.py

    r91 r92  
    3535 
    3636    self.app = None 
     37    self.adding_children = False 
    3738    #self.set_property('fixed-height-mode', True) # speed display 
    3839 
     
    105106      acc.grabFocus() 
    106107 
     108  def _onChildAddTimeout(self): 
     109    self.adding_children = False 
     110    return False 
     111     
    107112  def _onATSPIEvent(self, event): 
    108113    if event.source.getApplication() <> self.app: 
     
    142147                                        pyatspi.ROLE_FRAME) 
    143148      try: 
     149        model = self.get_model() 
    144150        root = model.getRootAcc() 
    145151        root.parent  # access it 
     
    151157        WindowActivateMessage(top).send() 
    152158 
    153     elif event.type in ('object:children-changed:add', 'object:children-changed:remove')
     159    elif event.type == 'object:children-changed:remove'
    154160      PrintMessage(s).send() 
    155161      model = self.get_model() 
    156       if model.getAccPath(source_acc) is not None: 
    157         ChildChangedMessage(source_acc).send() 
    158        
     162      path = model.getAccPath(source_acc)  
     163      if path is None: 
     164        path = model.getAccPath(source_acc.parent) 
     165      if path is not None: 
     166        ChildChangedMessage(path).send() 
     167    elif event.type == 'object:children-changed:add': 
     168      if not self.adding_children: 
     169        # hack to ignore bunch of adds 
     170        self.adding_children = True 
     171        PrintMessage(s).send() 
     172        ChildChangedMessage(None).send() 
     173        self.id = gobject.timeout_add(500, self._onChildAddTimeout) 
     174         
    159175    elif event.source.getRole() == pyatspi.ROLE_MENU: 
    160176      if event.type == 'object:state-changed:selected': 
     
    178194    self.next() 
    179195 
    180   def _onChildChanged(self, parent): 
     196  def _onChildChanged(self, path): 
     197    #a child of a acc in the model has changed 
    181198    print 'ChildChange' 
    182199    model, iter, acc = self._getSelection() 
    183200    if iter is None: return 
    184     acc_path = model.getAccPath(parent) 
    185201    sel_path = model.get_path(iter) 
    186     print '%s %s' % (acc_path, sel_path) 
    187     if acc_path and len(acc_path) < len(sel_path): 
    188       #a child of a acc in the model has changed 
    189       self.setModel(model.getRootAcc()) 
    190       print 'zzz' + str(path) 
    191       self.get_model().popToPath(path) 
    192       self.goToPath(path) 
    193     #self.next() 
     202    self.setModel(model.getRootAcc()) 
     203    self.get_model().popToPath(sel_path) 
     204    self.goToPath(sel_path) 
    194205 
    195206  def _onShowMenu(self, event=None):