~quickly-committers/quickly/trunk

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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/python
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
### BEGIN LICENSE
# This file is in the public domain
### END LICENSE

import sys
import os
import gtk

import gettext
from gettext import gettext as _
gettext.textdomain('project_name')

# optional Launchpad integration
# this shouldn't crash if not found as it is simply used for bug reporting
try:
    import LaunchpadIntegration
    launchpad_available = True
except:
    launchpad_available = False

# Add project root directory (enable symlink, and trunk execution).
PROJECT_ROOT_DIRECTORY = os.path.abspath(
    os.path.dirname(os.path.dirname(os.path.realpath(sys.argv[0]))))

if (os.path.exists(os.path.join(PROJECT_ROOT_DIRECTORY, 'python_name'))
    and PROJECT_ROOT_DIRECTORY not in sys.path):
    sys.path.insert(0, PROJECT_ROOT_DIRECTORY)
    os.putenv('PYTHONPATH', PROJECT_ROOT_DIRECTORY) # for subprocesses

from python_name import (
    Aboutcamel_case_nameDialog, Preferencescamel_case_nameDialog)
from python_name.helpers import get_builder
#Try adding AppIndicator. Will work after "qucikly add indicator"
try:
    from python_name import indicator
except:
    indicator = False


class camel_case_nameWindow(gtk.Window):
    __gtype_name__ = "camel_case_nameWindow"
    
    # To construct a new instance of this method, the following notable 
    # methods are called in this order:
    # __new__(cls)
    # __init__(self)
    # finish_initializing(self, builder)
    # __init__(self)
    #
    # For this reason, it's recommended you leave __init__ empty and put
    # your inialization code in finish_intializing
    
    def __new__(cls):
        """Special static method that's automatically called by Python when 
        constructing a new instance of this class.
        
        Returns a fully instantiated camel_case_nameWindow object.
        """
        builder = get_builder('camel_case_nameWindow')
        new_object = builder.get_object("python_name_window")
        new_object.finish_initializing(builder)
        return new_object

    def finish_initializing(self, builder):
        """Called while initializing this instance in __new__

        finish_initalizing should be called after parsing the UI definition
        and creating a camel_case_nameWindow object with it in order to finish
        initializing the start of the new camel_case_nameWindow instance.
        
        Put your initilization code in here and leave __init__ undefined.
        """
        # Get a reference to the builder and set up the signals.
        self.builder = builder
        self.builder.connect_signals(self)

        global launchpad_available
        if launchpad_available:
            # see https://wiki.ubuntu.com/UbuntuDevelopment/Internationalisation/Coding for more information
            # about LaunchpadIntegration
            helpmenu = self.builder.get_object('helpMenu')
            if helpmenu:
                LaunchpadIntegration.set_sourcepackagename('project_name')
                LaunchpadIntegration.add_items(helpmenu, 0, False, True)
            else:
                launchpad_available = False
            
        
        #AppIndicator support
        #see http://owaislone.org/quickly-add-indicator/ 
        # use 'quickly add indicator' to get started
        # self is passed so methods of this class can be called from indicator.py
        # Comment to disable appindicator
        if indicator:
            self.indicator = indicator.new_application_indicator(self)
        # self.indicator is an appindicator instance.
        # learn more about it here http://LINK-to-AppIndicator-Docs
        
        
        # Uncomment the following code to read in preferences at start up.
        #dlg = Preferencescamel_case_nameDialog.Preferencescamel_case_nameDialog()
        #self.preferences = dlg.get_preferences()

        # Code for other initialization actions should be added here.

    def about(self, widget, data=None):
        """Display the about box for project_name."""
        about = Aboutcamel_case_nameDialog.Aboutcamel_case_nameDialog()
        response = about.run()
        about.destroy()

    def preferences(self, widget, data=None):
        """Display the preferences window for project_name."""
        prefs = Preferencescamel_case_nameDialog.Preferencescamel_case_nameDialog()
        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):
        """Signal handler for closing the camel_case_nameWindow."""
        self.destroy()

    def on_destroy(self, widget, data=None):
        """Called when the camel_case_nameWindow is closed."""
        # Clean up code for saving application state should be added here.
        gtk.main_quit()

if __name__ == "__main__":
    # Support for command line options.
    import logging
    import 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 = camel_case_nameWindow()
    window.show()
    gtk.main()