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
113
114
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
### BEGIN LICENSE
# This file is in the public domain
### END LICENSE
import sys
import os
import gtk
# Check if we are working in the source tree or from the installed
# package and mangle the python path accordingly
if os.path.dirname(sys.argv[0]) != ".":
if sys.argv[0][0] == "/":
fullPath = os.path.dirname(sys.argv[0])
else:
fullPath = os.getcwd() + "/" + os.path.dirname(sys.argv[0])
else:
fullPath = os.getcwd()
sys.path.insert(0, os.path.dirname(fullPath))
from acire import AboutAcireDialog, PreferencesAcireDialog
from acire.acireconfig import getdatapath
class AcireWindow(gtk.Window):
__gtype_name__ = "AcireWindow"
def __init__(self):
"""__init__ - This function is typically not called directly.
Creation a AcireWindow requires redeading the associated ui
file and parsing the ui definition extrenally,
and then calling AcireWindow.finish_initializing().
Use the convenience function NewAcireWindow to create
AcireWindow object.
"""
pass
def finish_initializing(self, builder):
"""finish_initalizing should be called after parsing the ui definition
and creating a AcireWindow object with it in order to finish
initializing the start of the new AcireWindow instance.
"""
#get a reference to the builder and set up the signals
self.builder = builder
self.builder.connect_signals(self)
#uncomment the following code to read in preferences at start up
#dlg = PreferencesAcireDialog.NewPreferencesAcireDialog()
#self.preferences = dlg.get_preferences()
#code for other initialization actions should be added here
def about(self, widget, data=None):
"""about - display the about box for acire """
about = AboutAcireDialog.NewAboutAcireDialog()
response = about.run()
about.destroy()
def preferences(self, widget, data=None):
"""preferences - display the preferences window for acire """
prefs = PreferencesAcireDialog.NewPreferencesAcireDialog()
response = prefs.run()
if response == gtk.RESPONSE_OK:
#make any updates based on changed preferences here
pass
prefs.destroy()
def quit(self, widget, data=None):
"""quit - signal handler for closing the AcireWindow"""
self.destroy()
def on_destroy(self, widget, data=None):
"""on_destroy - called when the AcireWindow is close. """
#clean up code for saving application state should be added here
gtk.main_quit()
def NewAcireWindow():
"""NewAcireWindow - returns a fully instantiated
AcireWindow object. Use this function rather than
creating a AcireWindow directly.
"""
#look for the ui file that describes the ui
ui_filename = os.path.join(getdatapath(), 'ui', 'AcireWindow.ui')
if not os.path.exists(ui_filename):
ui_filename = None
builder = gtk.Builder()
builder.add_from_file(ui_filename)
window = builder.get_object("acire_window")
window.finish_initializing(builder)
return window
if __name__ == "__main__":
#support for command line options
import logging, optparse
parser = optparse.OptionParser(version="%prog %ver")
parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="Show debug messages")
(options, args) = parser.parse_args()
#set the logging level to show debug messages
if options.verbose:
logging.basicConfig(level=logging.DEBUG)
logging.debug('logging enabled')
#run the application
window = NewAcireWindow()
window.show()
gtk.main()
|