OSDN Git Service

Added app module for Poedit.
authorMesar Hameed <mhameed@src.gnome.org>
Fri, 20 Jan 2012 08:42:18 +0000 (08:42 +0000)
committerMesar Hameed <mhameed@src.gnome.org>
Fri, 20 Jan 2012 08:42:18 +0000 (08:42 +0000)
Fixes #1811.

source/appModules/poedit.py [new file with mode: 0644]
user_docs/en/changes.t2t

diff --git a/source/appModules/poedit.py b/source/appModules/poedit.py
new file mode 100644 (file)
index 0000000..f217a56
--- /dev/null
@@ -0,0 +1,146 @@
+#appModules/poedit.py\r
+#A part of NonVisual Desktop Access (NVDA)\r
+#Copyright (C) 2012 Mesar Hameed <mhameed@src.gnome.org>\r
+#This file is covered by the GNU General Public License.\r
+#See the file COPYING for more details.\r
+\r
+"""App module for Poedit.\r
+"""\r
+\r
+import api\r
+import appModuleHandler\r
+import controlTypes\r
+import displayModel\r
+import textInfos\r
+import tones\r
+import ui\r
+from NVDAObjects.IAccessible import sysListView32\r
+\r
+\r
+def getPath(obj, ancestor):\r
+       """Gets the path of the object with respect to its ancestor.\r
+       the ancestor is typically the forground object.\r
+\r
+       @returns: A list of coordinates relative to the ansestor.\r
+       @rtype: L{list}\r
+       """\r
+       path = []\r
+       cancel = 0\r
+       if obj == stopObj: return []\r
+       p = obj\r
+       while p != stopObj:\r
+               counter = 0\r
+               while p.previous:\r
+                       p = p.previous\r
+                       counter += 1\r
+                       cancel += 1\r
+                       # Looks like we have an infinite ancestry, so get out\r
+                       if cancel == 50: return [-1]\r
+               path.append(counter)\r
+               p = p.parent\r
+       path.reverse()\r
+       return path\r
+\r
+def fetchObject(obj, path):\r
+       """Fetch the child object  described by path.\r
+       @returns: requested object if found, or None\r
+       @rtype: L{NVDAObjects.NVDAObject}\r
+       """\r
+       path.reverse()\r
+       p = obj\r
+       while len(path) and p.firstChild:\r
+               p = p.firstChild\r
+               steps = path.pop()\r
+               i=0\r
+               while i<steps and p.next: \r
+                       p = p.next\r
+                       i += 1\r
+               # the path requests us to look for further siblings, but none found.\r
+               if i<steps: return None\r
+       # the path requests us to look for further children, but none found.\r
+       if len(path): return None\r
+       return p\r
+\r
+\r
+class AppModule(appModuleHandler.AppModule):\r
+\r
+       def script_reportAutoCommentsWindow(self,gesture):\r
+               obj = fetchObject(api.getForegroundObject(), [2, 0, 1, 0, 1, 0, 0, 0])\r
+               # check the controlid, because in certain situations \r
+               # autoComments and comment windows change places.\r
+               if obj and obj.windowControlID == 102:\r
+                       try:\r
+                               ui.message(obj.name + " " + obj.value)\r
+                       except:\r
+                               # Translators: this message is reported when there are no \r
+                               # comments to be presented to the user in the automatic \r
+                               # comments window in poedit.\r
+                               ui.message(_("No automatic comments."))\r
+               else:\r
+                       # Translators: this message is reported when NVDA is unable to find \r
+                       # the 'automatic comments' window in poedit.\r
+                       ui.message(_("Could not find automatic comments window."))\r
+\r
+       def script_reportCommentsWindow(self,gesture):\r
+               obj = fetchObject(api.getForegroundObject(), [2, 0, 1, 0, 1, 0, 1, 0])\r
+               # if it isnt in the normal location, try to find it in the\r
+               # location of the automatic window.\r
+               if not obj: \r
+                       obj = fetchObject(api.getForegroundObject(), [2, 0, 1, 0, 1, 0, 0, 0])\r
+               if obj and obj.windowControlID == 105:\r
+                       try:\r
+                               ui.message(obj.name + " " + obj.value)\r
+                       except:\r
+                               # Translators: this message is reported when there are no\r
+                               # comments to be presented to the user in the translator\r
+                               # comments window in poedit.\r
+                               ui.message(_("No comment."))\r
+               else:\r
+                       # Translators: this message is reported when NVDA is unable to find\r
+                       # the 'comments' window in poedit.\r
+                       ui.message(_("Could not find comment window."))\r
+\r
+       __gestures = {\r
+               "kb:control+shift+c": "reportCommentsWindow",\r
+               "kb:control+shift+a": "reportAutoCommentsWindow",\r
+       }\r
+\r
+       def chooseNVDAObjectOverlayClasses(self, obj, clsList):\r
+               if "SysListView32" in obj.windowClassName and obj.role==controlTypes.ROLE_LISTITEM:\r
+                       clsList.insert(0,PoeditListItem)\r
+               if obj.role == controlTypes.ROLE_EDITABLETEXT:\r
+                       if obj.windowControlID == 102:\r
+                               # Translators: Automatic comments is the name of the poedit \r
+                               # window that displays comments extracted from code.\r
+                               obj.name =  _("Automatic comments:")\r
+                       if obj.windowControlID == 104:\r
+                               # Translators: this is the label for the edit area in poedit \r
+                               # that contains a translation.\r
+                               obj.name = _("Translation:")\r
+                       if obj.windowControlID == 105:\r
+                               # Translators: 'comments:' is the name of the poedit window \r
+                               # that displays comments entered by the translator.\r
+                               obj.name = _("Comments:")\r
+\r
+class PoeditListItem(sysListView32.ListItem):\r
+\r
+       def _get_isBold(self):\r
+               info=displayModel.DisplayModelTextInfo(self,position=textInfos.POSITION_FIRST)\r
+               info.expand(textInfos.UNIT_LINE)\r
+               fields=info.getTextWithFields()\r
+               try:\r
+                       return fields[1].field['bold']\r
+               except:\r
+                       return False\r
+\r
+       def _get_name(self):\r
+               # If this item is untranslated or fuzzy, then it will be bold.\r
+               # Other info on the web says that the background color of \r
+               # the item changes, but this doesn't seem to be true while testing.\r
+               name = super(PoeditListItem,self).name\r
+               return "* " + name if self.isBold else name\r
+\r
+       def event_gainFocus(self):\r
+               super(sysListView32.ListItem, self).event_gainFocus()\r
+               if self.isBold:\r
+                       tones.beep(550, 50)\r
index b1abd1b..5895299 100644 (file)
@@ -25,6 +25,8 @@ Highlights of this release include features for more fluent reading of braille;
 - New braille translation table: Portuguese grade 2. (#2014)\r
 - You can now configure whether frames in documents are reported from the Document Formatting preferences dialog. (#1900)\r
 - Sleep mode is automatically enabled when using OpenBook. (#1209)\r
+- Added app module for Poedit, translators can now read automatically extracted comments, and translator added comments. \r
+Messages that are untranslated or are fuzzy are marked with a star and a beep is heard when you navigate onto them (#1811).\r
 \r
 \r
 == Changes ==\r