| 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() |
|---|
| 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() |
|---|
| 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 | |
|---|
| 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) |
|---|