commit/unicodeBrailleInput: pzajda: Use new addon template to provide documentation under NVDA help menu.

  • From: commits-noreply@xxxxxxxxxxxxx
  • To: nvda-addons-commits@xxxxxxxxxxxxx
  • Date: Mon, 02 Sep 2013 10:18:05 -0000

1 new commit in unicodeBrailleInput:

https://bitbucket.org/nvdaaddonteam/unicodebrailleinput/commits/6b5ac1b2e3b4/
Changeset:   6b5ac1b2e3b4
Branch:      master
User:        pzajda
Date:        2013-09-02 12:16:43
Summary:     Use new addon template to provide documentation under NVDA help 
menu.

Affected #:  6 files

diff --git a/.gitignore b/.gitignore
index ec3b8fe..5f03a4c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,7 @@
 *.nvda-addon
 *.ini
 .sconsign.dblite
+addon/doc/*.css
+addon/doc/
+*_docHandler.py
+*.html

diff --git a/docHandler.py b/docHandler.py
new file mode 100644
index 0000000..c142e42
--- /dev/null
+++ b/docHandler.py
@@ -0,0 +1,68 @@
+# -*- 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, u"{summary} 
{version}".format(summary=_addonSummary, version=_addonVersion), _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

diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..fbf9e2f
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,31 @@
+[[!meta title="UnicodeBrailleInput"]]
+* Authors: Mesar Hameed, Patrick Zajda.
+* Download: [version 1.01][1]
+
+This add-on allows you to convert text from braille (E.G. 1345-1236-145-1) to 
Unicode braille 
+characters.
+
+The purpose of this specialized addon is to make it easier to help to improve 
liblouis tables 
+and to add automatic tests for your language.
+
+## Usage ##
+
+* Open a unicode aware text editor (for example Notepad plus plus)
+* Press NVDA+Ctrl+U
+* Type your braille text in numeric form.
+* Press OK.
+* The required unicode characters will be copied to your clipboard ready for 
you to  paste.
+
+## Changes for 1.1-dev ##
+
+* Improve delay to allow announcements to be heard correctly.
+* New languages: Aragonese, Arabic, Brazilian Portuguese, Dutch, Finnish, 
German, Galician, Hungarian, Italian, Japanese, Nepali, Russian, Slovak, 
Slovenian, Spanish.
+* Use the new addon template so provide documentation under NVDA help menu.
+
+## Changes for 1.0 ##
+
+* Initial release
+* New Languages: French
+
+
+[1]: http://addons.nvda-project.org/files/get.php?file=ubi

diff --git a/readme.mdwn b/readme.mdwn
deleted file mode 100644
index bd1037f..0000000
--- a/readme.mdwn
+++ /dev/null
@@ -1,30 +0,0 @@
-[[!meta title="UnicodeBrailleInput"]]
-* Authors: Mesar Hameed, Patrick Zajda.
-* Download: [version 1.01][1]
-
-This add-on allows you to convert text from braille (E.G. 1345-1236-145-1) to 
Unicode braille 
-characters.
-
-The purpose of this specialized addon is to make it easier to help to improve 
liblouis tables 
-and to add automatic tests for your language.
-
-## Usage ##
-
-* Open a unicode aware text editor (for example Notepad plus plus)
-* Press NVDA+Ctrl+U
-* Type your braille text in numeric form.
-* Press OK.
-* The required unicode characters will be copied to your clipboard ready for 
you to  paste.
-
-## Changes for 1.1-dev ##
-
-* Improve delay to allow announcements to be heard correctly.
-* New languages: Aragonese, Arabic, Brazilian Portuguese, Dutch, Finnish, 
German, Galician, Hungarian, Italian, Japanese, Nepali, Russian, Slovak, 
Slovenian, Spanish.
-
-## Changes for 1.0 ##
-
-* Initial release
-* New Languages: French
-
-
-[1]: http://addons.nvda-project.org/files/get.php?file=ubi

diff --git a/sconstruct b/sconstruct
index 4366cca..9754cf5 100644
--- a/sconstruct
+++ b/sconstruct
@@ -5,6 +5,7 @@
 
 import codecs
 import gettext
+import os
 import os.path
 import zipfile
 import configobj
@@ -12,7 +13,46 @@ import configobj
 import buildVars
 
 
-env = Environment(ENV=os.environ)
+def md2html(source, dest):
+       import markdown
+       lang = os.path.basename(os.path.dirname(source)).replace('_', '-')
+       title="{addonSummary} 
{addonVersion}".format(addonSummary=buildVars.addon_info["addon-summary"], 
addonVersion=buildVars.addon_info["addon-version"])
+       headerDic = {
+               "[[!meta title=\"": "# ",
+               "\"]]": " #",
+       }
+       with codecs.open(source, "r", "utf-8") as f:
+               mdText = f.read()
+               for k, v in headerDic.iteritems():
+                       mdText = mdText.replace(k, v, 1)
+               htmlText = markdown.markdown(mdText)
+       with codecs.open(dest, "w", "utf-8") as f:
+               f.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+                       "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 
Strict//EN\"\n" +
+                       "    
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\";>\n" +
+                       "<html xmlns=\"http://www.w3.org/1999/xhtml\"; 
xml:lang=\"%s\" lang=\"%s\">\n" % (lang, lang) +
+                       "<head>\n" +
+                       "<meta http-equiv=\"Content-Type\" content=\"text/html; 
charset=UTF-8\"/>\n" +
+                       "<link rel=\"stylesheet\" type=\"text/css\" 
href=\"../style.css\" media=\"screen\"/>\n" +
+                       "<title>%s</title>\n" % title +
+                       "</head>\n<body>\n"
+               )
+               f.write(htmlText)
+               f.write("\n</body>\n</html>")
+
+def mdTool(env):
+       mdAction=env.Action(
+               lambda target,source,env: md2html(source[0].path, 
target[0].path),
+               lambda target,source,env: 'Generating %s'%target[0],
+       )
+       mdBuilder=env.Builder(
+               action=mdAction,
+               suffix='.html',
+               src_suffix='.md',
+       )
+       env['BUILDERS']['markdown']=mdBuilder
+
+env = Environment(ENV=os.environ, tools=[mdTool])
 
 
 addonFile = 
env.File("{addon-name}-{addon-version}.nvda-addon".format(**buildVars.addon_info))
@@ -56,8 +96,28 @@ env['BUILDERS']['gettextMergePotFile']=env.Builder(
        ], lambda t, s, e : "Generating pot file %s" % t[0]),
        suffix=".pot")
 
+def createAddonHelp(dir):
+       if not os.path.isfile("docHandler.py"):
+               return
+       plugindir = os.path.join(dir, "globalPlugins")
+       docFilename = 
"{addonName}_docHandler.py".format(addonName=buildVars.addon_info["addon-name"])
+       docPath = os.path.join(plugindir, docFilename)
+       docFileTarget = env.Command(docPath, "docHandler.py", Copy("$TARGET", 
"$SOURCE"))
+       env.Depends(addon, docFileTarget)
+       docsDir = os.path.join(dir, "doc")
+       if os.path.isfile("style.css"):
+               cssPath = os.path.join(docsDir, "style.css")
+               cssTarget = env.Command(cssPath, "style.css", Copy("$TARGET", 
"$SOURCE"))
+               env.Depends(addon, cssTarget)
+       if os.path.isfile("README.md"):
+               readmePath = os.path.join(docsDir, "en", "README.md")
+               readmeTarget = env.Command(readmePath, "README.md", 
Copy("$TARGET", "$SOURCE"))
+               env.Depends(addon, readmeTarget)
+
+
+
 def createAddonBundleFromPath(path, dest):
-       """ Creates a bundle from a directory that contains a a addon manifest 
file."""
+       """ Creates a bundle from a directory that contains an addon manifest 
file."""
        basedir = os.path.abspath(path)
        with zipfile.ZipFile(dest, 'w', zipfile.ZIP_DEFLATED) as z:
                # FIXME: the include/exclude feature may or may not be useful. 
Also python files can be pre-compiled.
@@ -100,12 +160,20 @@ for dir in langDirs:
        moFile=env.gettextMoFile(poFile)
        env.Depends(moFile, poFile)
        translatedManifest = 
env.NVDATranslatedManifest(dir.File("manifest.ini"), [moFile, 
os.path.join("manifest-translated.ini.tpl")])
+       env.Depends(translatedManifest, ["buildVars.py"])
        env.Depends(addon, [translatedManifest, moFile])
 
 pythonFiles = expandGlobs(buildVars.pythonSources)
 for file in pythonFiles:
        env.Depends(addon, file)
 
+#Convert markdown files to html
+createAddonHelp("addon") # We need at least doc in English and should append 
an item to Help menu
+for mdFile in env.Glob(os.path.join('addon', 'doc', '*', '*.md')):
+       htmlFile = env.markdown(mdFile)
+       env.Depends(htmlFile, mdFile)
+       env.Depends(addon, htmlFile)
+
 # Pot target
 i18nFiles = expandGlobs(buildVars.i18nSources)
 pot = env.gettextPotFile("%s.pot" % 
"{addon-name}".format(**buildVars.addon_info), i18nFiles)

diff --git a/style.css b/style.css
new file mode 100644
index 0000000..373283f
--- /dev/null
+++ b/style.css
@@ -0,0 +1,30 @@
+@charset "utf-8";
+body { 
+font-family : Verdana, Arial, Helvetica, Sans-serif;
+color : #FFFFFF;
+background-color : #000000;
+line-height: 1.2em;
+} 
+h1, h2 {text-align: center}
+dt { 
+font-weight : bold; 
+float : left; 
+width: 10%;
+clear: left
+} 
+dd { 
+margin : 0 0 0.4em 0; 
+float : left;
+width: 90%;
+display: block;
+} 
+p { clear : both; 
+} 
+a { text-decoration : underline; 
+} 
+:active { 
+text-decoration : none; 
+}
+a:focus, a:hover {outline: solid}
+:link {color: #0000FF;
+background-color: #FFFFFF}

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

--

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

Other related posts:

  • » commit/unicodeBrailleInput: pzajda: Use new addon template to provide documentation under NVDA help menu. - commits-noreply