~macaco-dev/macaco/trunk

« back to all changes in this revision

Viewing changes to bin/harmony

  • Committer: Manuel de la Pena
  • Date: 2009-11-16 20:43:50 UTC
  • Revision ID: mandel@themacaque.com-20091116204350-w93baxclnr9axcub
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 harmony import AboutHarmonyDialog, PreferencesHarmonyDialog
 
23
from harmony.harmonyconfig import getdatapath
 
24
 
 
25
class HarmonyWindow(gtk.Window):
 
26
    __gtype_name__ = "HarmonyWindow"
 
27
 
 
28
    def __init__(self):
 
29
        """__init__ - This function is typically not called directly.
 
30
        Creation a HarmonyWindow requires redeading the associated ui
 
31
        file and parsing the ui definition extrenally,
 
32
        and then calling HarmonyWindow.finish_initializing().
 
33
 
 
34
        Use the convenience function NewHarmonyWindow to create
 
35
        HarmonyWindow 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 HarmonyWindow object with it in order to finish
 
43
        initializing the start of the new HarmonyWindow 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 = PreferencesHarmonyDialog.NewPreferencesHarmonyDialog()
 
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 harmony """
 
58
        about = AboutHarmonyDialog.NewAboutHarmonyDialog()
 
59
        response = about.run()
 
60
        about.destroy()
 
61
 
 
62
    def preferences(self, widget, data=None):
 
63
        """preferences - display the preferences window for harmony """
 
64
        prefs = PreferencesHarmonyDialog.NewPreferencesHarmonyDialog()
 
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 HarmonyWindow"""
 
73
        self.destroy()
 
74
 
 
75
    def on_destroy(self, widget, data=None):
 
76
        """on_destroy - called when the HarmonyWindow is close. """
 
77
        #clean up code for saving application state should be added here
 
78
 
 
79
        gtk.main_quit()
 
80
 
 
81
def NewHarmonyWindow():
 
82
    """NewHarmonyWindow - returns a fully instantiated
 
83
    HarmonyWindow object. Use this function rather than
 
84
    creating a HarmonyWindow directly.
 
85
    """
 
86
 
 
87
    #look for the ui file that describes the ui
 
88
    ui_filename = os.path.join(getdatapath(), 'ui', 'HarmonyWindow.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("harmony_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 = NewHarmonyWindow()
 
112
    window.show()
 
113
    gtk.main()
 
114