forked from 1966bc/pyggybank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyggy.py
92 lines (70 loc) · 2.34 KB
/
pyggy.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
#!/usr/bin/env python
#-----------------------------------------------------------------------------
# project: pyggybank
# module: pyggy.py
# authors: 1966bc
# mailto: [giuseppe.costanzi@gmail.com]
# modify: 29/05/2015
# version: 0.4
# copyright: GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
# license: wxWindows License
#-----------------------------------------------------------------------------
"""
Lanch script of PyggyBank
"""
import wx
import sys
import os
import traceback
from engine import Engine
import frames.main
def ExceptionHook(exctype, value, trace):
#trace = traceback.format_exc().splitlines()
exc = traceback.format_exception(exctype, value, trace)
ftrace = "".join(exc)
app = wx.GetApp()
if app:
msg = "Houstonn\n we've had a problem\n%s"% ftrace
wx.MessageBox(msg,wx.GetApp().GetAppName(),style = wx.ICON_ERROR|wx.OK)
else:
sys.stderr.write(ftrace)
class PyggyBank(wx.App):
"""The PyggyBank Object"""
def OnInit(self):
self.SetAppName("PyggyBank")
self.engine = Engine()
sys.excepthook = ExceptionHook
#control app istance
self.instance = wx.SingleInstanceChecker('client_lock',os.getcwd())
if self.instance.IsAnotherRunning():
msg = "Okay, Houston, we've had a problem here.\nAnother instance is running"
wx.MessageBox(msg,wx.GetApp().GetAppName(),style = wx.ICON_ERROR|wx.OK)
return False
try:
obj = frames.main.MainFrame()
self.SetTopWindow(obj)
obj.OnOpen()
obj.Show()
return True
except:
print sys.exc_info()[0]
print sys.exc_info()[1]
print sys.exc_info()[2]
return False
def OnExit(self):
try:
wx.GetApp().engine.con.close()
except:
pass
for window in wx.GetTopLevelWindows():
if window != self:
window.Destroy()
wx.GetApp().Exit()
return False
def main():
wx.SetDefaultPyEncoding('latin-1')
wx.Log.EnableLogging(False)
app = PyggyBank(True,"log.txt")
app.MainLoop()
if __name__ == '__main__':
main()