~stomato463/+junk/nvdajp

« back to all changes in this revision

Viewing changes to source/NVDAObjects/IAccessible/qt.py

  • Committer: Masataka Shinke
  • Date: 2011-10-25 12:35:26 UTC
  • mfrom: (4185 jpmain)
  • mto: This revision was merged to the branch mainline in revision 4211.
  • Revision ID: mshinke@users.sourceforge.jp-20111025123526-ze527a2rl3z0g2ky
lp:~nishimotz/nvdajp/main : 4185 をマージ

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
#This file is covered by the GNU General Public License.
5
5
#See the file COPYING for more details.
6
6
 
7
 
import re
8
7
from comtypes import COMError
9
8
import controlTypes
10
9
from NVDAObjects.IAccessible import IAccessible
11
10
import eventHandler
 
11
from scriptHandler import isScriptWaiting
12
12
 
13
13
class Client(IAccessible):
14
14
 
 
15
        def _get__containedWidget(self):
 
16
                widget = self.firstChild
 
17
                if not widget:
 
18
                        return None
 
19
 
 
20
                wnext = widget.next
 
21
                if not wnext:
 
22
                        # There is only one child, so this is probably a widget container.
 
23
                        return widget
 
24
 
 
25
                try:
 
26
                        if wnext.firstChild.role == controlTypes.ROLE_SCROLLBAR:
 
27
                                # There is only one child plus a scrollbar, so this is probably a widget container.
 
28
                                return widget
 
29
                except AttributeError:
 
30
                        pass
 
31
 
 
32
                # This is not a widget container.
 
33
                return None
 
34
 
15
35
        def event_gainFocus(self):
16
36
                if eventHandler.isPendingEvents("gainFocus"):
17
37
                        return
18
38
 
19
 
                # If there is only one child, this is probably a widget container.
20
 
                child = self.firstChild
21
 
                if child and not child.next:
22
 
                        # Redirect the focus, since QT doesn't do it properly.
 
39
                widget = self._containedWidget
 
40
                if widget:
 
41
                        # This is a widget container.
 
42
                        # Redirect the focus to the contained widget, since QT doesn't do it properly.
23
43
                        self.event_focusEntered()
24
 
                        eventHandler.executeEvent("gainFocus", child)
 
44
                        eventHandler.executeEvent("gainFocus", widget)
25
45
                        return
26
46
 
27
47
                return super(Client, self).event_gainFocus()
51
71
 
52
72
                return super(Container, self).event_gainFocus()
53
73
 
 
74
 
 
75
class TableRow(Container):
 
76
 
 
77
        value=None
 
78
        description=None
 
79
 
 
80
        def _get_activeChild(self):
 
81
                # QT doesn't do accFocus properly, so find the active child ourselves.
 
82
                child = self.firstChild
 
83
                while child:
 
84
                        states = child.states
 
85
                        if controlTypes.STATE_FOCUSED in states:
 
86
                                return child
 
87
                        child = child.next
 
88
                return None
 
89
 
 
90
 
 
91
class TableCell(IAccessible):
 
92
 
 
93
        value=None
 
94
 
 
95
        def script_nextColumn(self,gesture):
 
96
                gesture.send()
 
97
                if not isScriptWaiting():
 
98
                        next=self.next
 
99
                        if next and controlTypes.STATE_FOCUSED in next.states:
 
100
                                eventHandler.executeEvent("gainFocus", next)
 
101
 
 
102
        def script_previousColumn(self,gesture):
 
103
                gesture.send()
 
104
                if not isScriptWaiting():
 
105
                        previous=self.previous
 
106
                        if previous and controlTypes.STATE_FOCUSED in previous.states:
 
107
                                eventHandler.executeEvent("gainFocus", previous)
 
108
 
 
109
        __gestures = {
 
110
                "kb:tab": "nextColumn",
 
111
                "kb:rightArrow": "nextColumn",
 
112
                "kb:shift+tab": "previousColumn",
 
113
                "kb:leftArrow": "previousColumn",
 
114
        }
 
115
 
 
116
 
54
117
class TreeViewItem(IAccessible):
55
 
        RE_POSITION_INFO = re.compile(r"L(?P<level>\d+), (?P<indexInGroup>\d+) of (?P<similarItemsInGroup>\d+) with \d+")
56
118
 
57
 
        # The description and value should not be user visible.
58
 
        description = None
59
119
        value = None
60
120
 
61
 
        def _get_positionInfo(self):
62
 
                # QT encodes the position info in the accDescription.
63
 
                try:
64
 
                        desc = self.IAccessibleObject.accDescription(self.IAccessibleChildID)
65
 
                except COMError:
66
 
                        return super(TreeViewItem, self).positionInfo
67
 
 
68
 
                m = self.RE_POSITION_INFO.match(desc)
69
 
                if m:
70
 
                        return m.groupdict()
71
 
 
72
 
                return super(TreeViewItem, self).positionInfo
 
121
        hasEncodedAccDescription=True
73
122
 
74
123
class Menu(IAccessible):
75
124
        # QT incorrectly fires a focus event on the parent menu immediately after (correctly) firing focus on the menu item.