Changeset 69

Show
Ignore:
Timestamp:
11/16/07 12:53:05
Author:
slee
Message:

pop menus

Files:

Legend:

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

    r68 r69  
    4242    top_hbox.pack_start(scrolled_window) 
    4343 
    44     generate_button = gtk.Button('Generate'
     44    generate_button = gtk.Button('_Generate', use_underline=True
    4545    generate_button.connect('clicked', self._onGenerate) 
    4646    bottom_hbox.pack_start(generate_button, False) 
    4747 
    48     examine_button = gtk.Button('Examine'
     48    examine_button = gtk.Button('E_xamine', use_underline=True
    4949    examine_button.connect('clicked', self._onExamine) 
    5050    bottom_hbox.pack_start(examine_button, False) 
    5151 
    52     scan_button = gtk.Button('Start Scan'
     52    scan_button = gtk.Button('Start _Scan', use_underline=True
    5353    scan_button.connect('clicked', self._onScan) 
    5454    bottom_hbox.pack_start(scan_button, False) 
    5555 
    56     action_button = gtk.Button('Action') 
     56    action_button = gtk.Button('_Action',  
     57                               use_underline=True) 
    5758    action_button.connect('clicked', self._onAction) 
    5859    bottom_hbox.pack_start(action_button, False) 
     
    7374      gobject.timeout_add(1000, self._onScanStep) 
    7475    self.is_scanning = not self.is_scanning 
    75     label = ('Stop Scan' if self.is_scanning else 'Start Scan') 
     76    label = ('Stop _Scan' if self.is_scanning else 'Start _Scan') 
    7677    button.set_label(label) 
    7778     
     
    192193class ActionGroup(object): 
    193194  def __init__(self, root_acc): 
    194     assert root_acc 
     195    assert root_acc is not None 
    195196    #REVIEW test if is a valid action group and throw if not ? 
    196197    self.parent_acc = root_acc 
     
    200201  def _populateChildren(self, parent_acc): 
    201202    for child_acc in parent_acc: 
     203      if child_acc is None: continue 
    202204      child = AccDecorator(child_acc) 
    203205      child.is_group = self.isActionGroup(child) 
     
    294296      self.remove(first_iter) 
    295297 
    296   def dePopLevel(self, iter): 
     298  def dePopLevel(self, iter, all=False): 
    297299    self.append(iter, ['', '', None, True, False]) 
    298300    child_iter = self.iter_children(iter) 
    299301    iter_valid = bool(child_iter) 
    300     while iter_valid and not self[child_iter][self.COL_DUMMY]
     302    while iter_valid and (all or not self[child_iter][self.COL_DUMMY])
    301303      iter_valid = self.remove(child_iter) 
    302304    self[iter][self.COL_FILLED] = False 
     
    328330  def _onExpanded(self, treeview, iter, path): 
    329331    # don't repopulate if it has been filled before 
    330  #   print 'expanding %s' % path 
    331332    if self.get_model()[iter][ProgressiveTreeModel.COL_FILLED]: 
    332333      return 
     
    338339  def _getSelection(self, selection=None): 
    339340    selection = selection or self.get_selection() 
     341#    if selection is None: 
     342#      return (self.get_model(), None, None) 
    340343    model, iter = selection.get_selected() 
    341344    if iter: 
     
    346349   
    347350  def get_selected_acc(self, selection=None): 
    348     model, iter, acc = self._getSelection(
     351    model, iter, acc = self._getSelection(selection
    349352    return acc 
    350353   
    351354  def get_acc_from_path(self, path): 
    352     return self.model[path][ProgressiveTreeModel.COL_ACC] 
     355    if not self.get_model(): 
     356      return None 
     357    return self.get_model()[path][ProgressiveTreeModel.COL_ACC] 
    353358 
    354359  def set_top_acc(self, acc): 
     
    356361    model.popLevel(None) # top 
    357362    self.set_model(model) 
    358  
     363    pyatspi.Registry.registerEventListener(self._onAccEventState, 'object:state-changed') 
     364 
     365  def __del__(self): 
     366    self.deRegisterEventListener(self._onAccEventState, 'object:state-changed') 
     367     
    359368  def select(self, iter): 
    360369    selection = self.get_selection() 
     
    364373    selection = self.get_selection() 
    365374    model, iter = selection.get_selected() 
    366     if not iter:  
     375    if iter is None:  
    367376      nextiter = model.get_iter_root() 
    368     elif self.next_children
     377    elif self.row_expanded(model.get_path(iter))
    369378      nextiter = model.iter_children(iter) 
    370       self.next_children = False; 
    371379    else: 
    372380      nextiter = model.iter_next(iter) 
    373       if not nextiter
     381      if nextiter is None
    374382        nextiter = model.iter_parent(iter) 
    375         if not nextiter
     383        if nextiter is None
    376384          nextiter = model.get_iter_root() 
    377385        else: 
     
    379387    self.select(nextiter) 
    380388      
     389  def _onAccEventState(self, event): 
     390    ''' 
     391    Callback for accessible state changes. Repopulates the states model. 
     392     
     393    @param event: Event that triggered this callback. 
     394    @type event: Accessibility.Event 
     395    ''' 
     396    if not self.get_model(): 
     397      return 
     398    if event.source.getApplication() <> self.get_acc_from_path(0).getApplication(): 
     399      return 
     400    model, iter, acc = self._getSelection() 
     401    if acc is None:  
     402      return 
     403    print event.type, event.detail1, event.detail2, event.source, acc,  event.source.parent 
     404    if acc.getRole() == pyatspi.ROLE_MENU : 
     405      print 'menu' 
     406      if event.source.parent == acc._acc : 
     407        print 'parent' 
     408        if event.type in ('object:state-changed:showing'): 
     409          showing = event.detail1 
     410          path = model.get_path(iter) 
     411          if showing == 1 \ 
     412             and not model.iter_has_child(iter): 
     413            model.makeExpandable(iter) 
     414            model.popLevel(iter) 
     415            self.expand_row(path, False) 
     416          elif showing == 0 \ 
     417               and self.row_expanded(path): 
     418              self.collapse_row(path) 
     419              model.dePopLevel(iter, all=True) 
     420     
    381421  def do_action(self): 
    382422    model, iter, acc = self._getSelection() 
    383     if not acc: return 
     423    if acc is None: return 
    384424    path = model.get_path(iter) 
    385     print 'path', path 
    386425    is_interactive = acc.isInteractive() 
    387426    if is_interactive: 
     
    389428        action_if = acc.queryAction() 
    390429        action_if.doAction(0) 
    391         # assume menu for now 
    392         if self.row_expanded(path): 
    393           self.collapse_row(path) 
    394         else: 
    395           model.makeExpandable(iter) 
    396           model.popLevel(model.get_iter(path)) 
    397           self.expand_row(path, False) 
    398430      except: 
    399431        pass