Package bitfling ::
Module guihelper
|
|
1
2
3
4
5
6
7
8
9
10 """Various convenience functions and widgets to assist the gui"""
11
12 import time
13 import os
14 import sys
15 import StringIO
16 import traceback
17
18
19 import wx
20
21
23 """Are we running on Windows?
24
25 @rtype: Bool"""
26 return wx.Platform=='__WXMSW__'
27
29 """Are we running on GTK (Linux)
30
31 @rtype: Bool"""
32 return wx.Platform=='__WXGTK__'
33
35 """Are we running on Mac
36
37 @rtype: Bool"""
38 return wx.Platform=='__WXMAC__'
39
41
43 wx.Panel.__init__(self,parent, -1, style=wx.NO_FULL_REPAINT_ON_RESIZE)
44 self.tb=wx.TextCtrl(self, 1, style=wx.TE_MULTILINE|wx.TE_RICH2|wx.NO_FULL_REPAINT_ON_RESIZE|wx.TE_DONTWRAP|wx.TE_READONLY)
45 f=wx.Font(10, wx.MODERN, wx.NORMAL, wx.NORMAL )
46 ta=wx.TextAttr(font=f)
47 self.tb.SetDefaultStyle(ta)
48 self.sizer=wx.BoxSizer(wx.VERTICAL)
49 self.sizer.Add(self.tb, 1, wx.EXPAND)
50 self.SetSizer(self.sizer)
51 self.SetAutoLayout(True)
52 self.sizer.Fit(self)
53 wx.EVT_IDLE(self, self.OnIdle)
54 self.outstandingtext=""
55
58
60 if len(self.outstandingtext):
61 self.tb.AppendText(self.outstandingtext)
62 self.outstandingtext=""
63 self.tb.ScrollLines(-1)
64
66 now=time.time()
67 t=time.localtime(now)
68 if len(str)==0 or str[0]=="&":
69 self.outstandingtext+=str[1:]+"\r\n"
70 else:
71 self.outstandingtext+="%d:%02d:%02d.%03d: %s\r\n" % ( t[3], t[4], t[5], int((now-int(now))*1000), str)
72
76
77
126
127
128
129 if IsMac():
130 p=os.getcwd()
131 else:
132 p=sys.path[0]
133 if p.lower().endswith(".zip"):
134 p=os.path.dirname(p)
135 resourcedirectory=os.path.join(os.path.abspath(p), "resources")
136
138 """Returns name of file by adding it to resource directory pathname
139
140 No attempt is made to verify the file exists
141 @rtype: string
142 """
143 return os.path.join(resourcedirectory, filename)
144
146 """Execute the command.
147
148 The path is searched"""
149 sl=os.spawnl
150 if sys.platform!='win32':
151 sl=os.spawnlp
152 ret=apply(sl, (os.P_WAIT,args[0])+args)
153 else:
154
155
156 str=""
157 for a in args:
158 if len(a)==0:
159 str+=' ""'
160 elif a.find(' ')>=0:
161 str+=' "'+a+'"'
162 else:
163 str+=" "+a
164 str=str[1:]
165
166
167
168
169
170 ret=os.system('start /b /wait "%s" %s' % (args[0], str))
171 return ret
172