-
Notifications
You must be signed in to change notification settings - Fork 0
/
HelpDialog.py
112 lines (88 loc) · 3.66 KB
/
HelpDialog.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env python
import wx
import wx.html
import sys
import os
import builtins as __builtin__
import inspect
moduleList = {'osvmGlobals':'globs'}
for k,v in moduleList.items():
print('Loading: %s as %s' % (k,v))
mod = __import__(k, fromlist=[None])
globals()[v] = globals().pop('mod') # Rename module in globals()
####
#print(__name__)
defHelpText = """<p>Sorry, the Help file cannot be found on your system. Please check your installation for file <b>help.htm</b>"""
class HtmlWindow(wx.html.HtmlWindow):
def __init__(self, parent, id, size=(600,400)):
wx.html.HtmlWindow.__init__(self, parent, id, size=size)
if "gtk2" in wx.PlatformInfo:
self.SetStandardFonts()
def OnLinkClicked(self, link):
wx.LaunchDefaultBrowser(link.GetHref())
class HelpDialog(wx.Dialog):
def __init__(self, parent):
myStyle = wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.TAB_TRAVERSAL
wx.Dialog.__init__(self, None, wx.ID_ANY, "Help on %s" % (globs.myLongName), style=myStyle)
self.panel1 = wx.Panel(id=wx.ID_ANY, name='panel1', parent=self,
size=wx.DefaultSize, style=wx.TAB_TRAVERSAL)
# Create a HTML window
self.hwin = HtmlWindow(parent=self.panel1, id=wx.ID_ANY, size=(800,600))
# Open the file containing the HTML info
try:
f = open(globs.helpPath, 'r', encoding="ISO-8859-1")
except IOError as e:
msg = "HelpDialog(): I/O error %s %s" % ("({0}): {1}".format(e.errno, e.strerror), globs.helpPath)
print(msg)
helpText = defHelpText
else:
helpText = f.read()
f.close()
# Display the HTML page
self.hwin.SetPage(helpText)
# Button to close the Help dialog
self.btnClose = wx.Button(label='Close', id=wx.ID_CLOSE, parent=self.panel1, style=0)
self.btnClose.Bind(wx.EVT_BUTTON, self.OnBtnClose)
# Everything in a BoxSizer
self.topBoxSizer = wx.BoxSizer(orient=wx.VERTICAL)
self.topBoxSizer.Add(self.hwin, 0, border=0, flag=0)
self.topBoxSizer.Add(4, 4, 0, border=0, flag=0)
self.topBoxSizer.Add(self.btnClose, 0, border=0, flag=wx.ALL | wx.EXPAND)
self.panel1.SetSizerAndFit(self.topBoxSizer)
self.SetClientSize(self.topBoxSizer.GetSize())
self.Centre()
self.SetFocus()
def OnBtnClose(self, event):
self.Close()
event.Skip()
########################
def module_path(local_function):
''' returns the module path without the use of __file__.
Requires a function defined locally in the module.
from http://stackoverflow.com/questions/729583/getting-file-path-of-imported-module'''
return os.path.abspath(inspect.getsourcefile(local_function))
def myprint(*args, **kwargs):
"""My custom print() function."""
# Adding new arguments to the print function signature
# is probably a bad idea.
# Instead consider testing if custom argument keywords
# are present in kwargs
__builtin__.print('%s():' % inspect.stack()[1][3], *args, **kwargs)
class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)
dlg = HelpDialog(self)
dlg.ShowModal()
dlg.Destroy()
self.Destroy()
def main():
# Init Globals instance
globs.modPath = module_path(main)
globs.helpPath = os.path.join(os.path.dirname(globs.modPath), 'help.htm')
# Create frame, passing globals instance as parameter
app = wx.App(False)
frame = MyFrame(None, -1, title="Test")
frame.Show()
app.MainLoop()
if __name__ == "__main__":
main()