~jonobacon/acire/trunk

« back to all changes in this revision

Viewing changes to bin/acire

  • Committer: Jono Bacon
  • Date: 2009-12-29 12:07:58 UTC
  • Revision ID: jono@ubuntu.com-20091229120758-ezp270vgx2i3fkny
Initial project creation with Quickly!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# -*- coding: utf-8 -*-
 
3
### BEGIN LICENSE
 
4
# This file is in the public domain
 
5
### END LICENSE
 
6
 
 
7
import sys
 
8
import os
 
9
import gtk
 
10
 
 
11
# Check if we are working in the source tree or from the installed 
 
12
# package and mangle the python path accordingly
 
13
if os.path.dirname(sys.argv[0]) != ".":
 
14
    if sys.argv[0][0] == "/":
 
15
        fullPath = os.path.dirname(sys.argv[0])
 
16
    else:
 
17
        fullPath = os.getcwd() + "/" + os.path.dirname(sys.argv[0])
 
18
else:
 
19
    fullPath = os.getcwd()
 
20
sys.path.insert(0, os.path.dirname(fullPath))
 
21
 
 
22
from acire import AboutAcireDialog, PreferencesAcireDialog
 
23
from acire.acireconfig import getdatapath
 
24
 
 
25
class AcireWindow(gtk.Window):
 
26
    __gtype_name__ = "AcireWindow"
 
27
 
 
28
    def __init__(self):
 
29
        """__init__ - This function is typically not called directly.
 
30
        Creation a AcireWindow requires redeading the associated ui
 
31
        file and parsing the ui definition extrenally,
 
32
        and then calling AcireWindow.finish_initializing().
 
33
 
 
34
        Use the convenience function NewAcireWindow to create
 
35
        AcireWindow object.
 
36
 
 
37
        """
 
38
        pass
 
39
 
 
40
    def finish_initializing(self, builder):
 
41
        """finish_initalizing should be called after parsing the ui definition
 
42
        and creating a AcireWindow object with it in order to finish
 
43
        initializing the start of the new AcireWindow instance.
 
44
 
 
45
        """
 
46
        #get a reference to the builder and set up the signals
 
47
        self.builder = builder
 
48
        self.builder.connect_signals(self)
 
49
 
 
50
        #uncomment the following code to read in preferences at start up
 
51
        #dlg = PreferencesAcireDialog.NewPreferencesAcireDialog()
 
52
        #self.preferences = dlg.get_preferences()
 
53
 
 
54
        #code for other initialization actions should be added here
 
55
 
 
56
    def about(self, widget, data=None):
 
57
        """about - display the about box for acire """
 
58
        about = AboutAcireDialog.NewAboutAcireDialog()
 
59
        response = about.run()
 
60
        about.destroy()
 
61
 
 
62
    def preferences(self, widget, data=None):
 
63
        """preferences - display the preferences window for acire """
 
64
        prefs = PreferencesAcireDialog.NewPreferencesAcireDialog()
 
65
        response = prefs.run()
 
66
        if response == gtk.RESPONSE_OK:
 
67
            #make any updates based on changed preferences here
 
68
            pass
 
69
        prefs.destroy()
 
70
 
 
71
    def quit(self, widget, data=None):
 
72
        """quit - signal handler for closing the AcireWindow"""
 
73
        self.destroy()
 
74
 
 
75
    def on_destroy(self, widget, data=None):
 
76
        """on_destroy - called when the AcireWindow is close. """
 
77
        #clean up code for saving application state should be added here
 
78
 
 
79
        gtk.main_quit()
 
80
 
 
81
def NewAcireWindow():
 
82
    """NewAcireWindow - returns a fully instantiated
 
83
    AcireWindow object. Use this function rather than
 
84
    creating a AcireWindow directly.
 
85
    """
 
86
 
 
87
    #look for the ui file that describes the ui
 
88
    ui_filename = os.path.join(getdatapath(), 'ui', 'AcireWindow.ui')
 
89
    if not os.path.exists(ui_filename):
 
90
        ui_filename = None
 
91
 
 
92
    builder = gtk.Builder()
 
93
    builder.add_from_file(ui_filename)
 
94
    window = builder.get_object("acire_window")
 
95
    window.finish_initializing(builder)
 
96
    return window
 
97
 
 
98
if __name__ == "__main__":
 
99
    #support for command line options
 
100
    import logging, optparse
 
101
    parser = optparse.OptionParser(version="%prog %ver")
 
102
    parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="Show debug messages")
 
103
    (options, args) = parser.parse_args()
 
104
 
 
105
    #set the logging level to show debug messages
 
106
    if options.verbose:
 
107
        logging.basicConfig(level=logging.DEBUG)
 
108
        logging.debug('logging enabled')
 
109
 
 
110
    #run the application
 
111
    window = NewAcireWindow()
 
112
    window.show()
 
113
    gtk.main()
 
114