-
Notifications
You must be signed in to change notification settings - Fork 14
/
docHandler.py
68 lines (57 loc) · 1.85 KB
/
docHandler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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