[nvda-addons] commit/addonTemplate: norrumar: Added a global plugin to append Open addons documentation item to NVDA's help menu.

  • From: commits-noreply@xxxxxxxxxxxxx
  • To: nvda-addons@xxxxxxxxxxxxx
  • Date: Thu, 23 May 2013 18:19:38 -0000

1 new commit in addonTemplate:

https://bitbucket.org/nvdaaddonteam/addontemplate/commits/c6e89822152b/
Changeset:   c6e89822152b
Branch:      addonDocSupport
User:        norrumar
Date:        2013-05-23 20:18:30
Summary:     Added a global plugin to append Open addons documentation item to 
NVDA's help menu.

Affected #:  2 files

diff --git a/README.md b/README.md
index 1a6d239..b203bcb 100644
--- a/README.md
+++ b/README.md
@@ -34,7 +34,7 @@ To create a new NVDA add-on, taking advantage of this 
template:
 - Put your code in the usual folders for NVDA extension, under the **addon** 
folder. For instance: globalPlugins, synthDrivers, etc. You can delete folders 
you don't need for your particular add-on package.
 - Gettext translations must be placed into 
addon\locale\<lang>/LC_MESSAGES\nvda.po. 
 - Documentation files must be placed into addon\doc\<lang>/fileName, 
readme.html by default.
-- You can copy docHandler.py to a globalPlugins or appModules folder. Then 
import it and use docHandler.openDocPath() to open the documentation file 
corresponding to NVDA's current language, or English by default.
+- Assign a unique name to **docHandler.py** file, found under 
**addon\globalPlugins**, for instance **yourAddonName_docHandler**. This plugin 
will append an item to NVDA's help menu for opening your addon documentation in 
the current language, or English by default.
 - To package the add-on for distribution, open a command line, change to the 
folder that has the **SCONSTRUCT** file and run the **scons** command. The 
created add-on, if there were no errors, is placed in the current directory.
 - You can further customize variables in the **buildVars.py** file.
 

diff --git a/addon/globalPlugins/docHandler.py 
b/addon/globalPlugins/docHandler.py
new file mode 100644
index 0000000..cafcc5a
--- /dev/null
+++ b/addon/globalPlugins/docHandler.py
@@ -0,0 +1,70 @@
+# -*- coding: UTF-8 -*-
+
+# docHandler: module for managing addons documentation
+# See: http://community.nvda-project.org/ticket/2694
+
+import os
+import languageHandler
+import addonHandler
+import globalPluginHandler
+import gui
+import wx
+
+addonHandler.initTranslation()
+
+_addonDir = os.path.join(os.path.dirname(__file__), "..") # The root of an 
addon folder
+_docFileName = "readme.html" # The name of an addon documentation file
+_curAddon = addonHandler.Addon(_addonDir) # Addon instance
+_addonSummary = _curAddon.manifest['summary']
+_addonVersion = _curAddon.manifest['version']
+_addonName = _curAddon.manifest['name']
+
+def getDocFolder(addonDir=_addonDir):
+       langs = [languageHandler.getLanguage(), "en"]
+       for lang in langs:
+               docFolder = os.path.join(addonDir, "doc", lang)
+               if os.path.isdir(docFolder):
+                       return docFolder
+               if "_" in lang:
+                       tryLang = lang.split("_")[0]
+                       docFolder = os.path.join(addonDir, "doc", tryLang)
+                       if os.path.isdir(docFolder):
+                               return docFolder
+                       if tryLang == "en":
+                               break
+               if lang == "en":
+                       break
+       return None
+
+def getDocPath(docFileName=_docFileName):
+       docPath = getDocFolder()
+       if docPath is not None:
+               docFile = os.path.join(docPath, docFileName)
+               if os.path.isfile(docFile):
+                       docPath = docFile
+       return docPath
+
+def openDocPath():
+       try:
+               os.startfile(getDocPath())
+       except WindowsError:
+               pass
+
+class GlobalPlugin(globalPluginHandler.GlobalPlugin):
+
+       def __init__(self):
+               super(globalPluginHandler.GlobalPlugin, self).__init__()
+               self.help = gui.mainFrame.sysTrayIcon.helpMenu
+               self.helpItem = self.help.Append(wx.ID_ANY, "{summary} 
{version}".format(summary=_addonSummary, version=_addonVersion),
+               # Translators: Tooltip for an addon menu item.
+               _("Open documentation for %s") % _addonName)
+               gui.mainFrame.sysTrayIcon.Bind(wx.EVT_MENU, self.onHelp, 
self.helpItem)
+
+       def onHelp(self, evt):
+               openDocPath()
+
+       def terminate(self):
+               try:
+                       self.help.RemoveItem(self.helpItem)
+               except wx.PyDeadObjectError:
+                       pass

Repository URL: https://bitbucket.org/nvdaaddonteam/addontemplate/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
----------------------------------------------------------------

NVDA add-ons Central: A list for discussing NVDA add-ons

To post a message, send an email to nvda-addons@xxxxxxxxxxxxx.

To unsubscribe, send an email with the subject line of "unsubscribe" (without 
quotes) to nvda-addons-request@xxxxxxxxxxxxx.

If you have questions for list moderators, please send a message to 
nvda-addons-moderators@xxxxxxxxxxxxx.

Community addons can be found here: http://addons.nvda-project.org

Other related posts:

  • » [nvda-addons] commit/addonTemplate: norrumar: Added a global plugin to append Open addons documentation item to NVDA's help menu. - commits-noreply