2
# -*- coding: utf-8 -*-
4
# This file is in the public domain
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])
17
fullPath = os.getcwd() + "/" + os.path.dirname(sys.argv[0])
19
fullPath = os.getcwd()
20
sys.path.insert(0, os.path.dirname(fullPath))
22
from harmony import AboutHarmonyDialog, PreferencesHarmonyDialog
23
from harmony.harmonyconfig import getdatapath
25
class HarmonyWindow(gtk.Window):
26
__gtype_name__ = "HarmonyWindow"
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().
34
Use the convenience function NewHarmonyWindow to create
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.
46
#get a reference to the builder and set up the signals
47
self.builder = builder
48
self.builder.connect_signals(self)
50
#uncomment the following code to read in preferences at start up
51
#dlg = PreferencesHarmonyDialog.NewPreferencesHarmonyDialog()
52
#self.preferences = dlg.get_preferences()
54
#code for other initialization actions should be added here
56
def about(self, widget, data=None):
57
"""about - display the about box for harmony """
58
about = AboutHarmonyDialog.NewAboutHarmonyDialog()
59
response = about.run()
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
71
def quit(self, widget, data=None):
72
"""quit - signal handler for closing the HarmonyWindow"""
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
81
def NewHarmonyWindow():
82
"""NewHarmonyWindow - returns a fully instantiated
83
HarmonyWindow object. Use this function rather than
84
creating a HarmonyWindow directly.
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):
92
builder = gtk.Builder()
93
builder.add_from_file(ui_filename)
94
window = builder.get_object("harmony_window")
95
window.finish_initializing(builder)
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()
105
#set the logging level to show debug messages
107
logging.basicConfig(level=logging.DEBUG)
108
logging.debug('logging enabled')
111
window = NewHarmonyWindow()