Merge lp:~jml/quickly/template-cleanup into lp:quickly

Proposed by Jonathan Lange
Status: Merged
Merged at revision: not available
Proposed branch: lp:~jml/quickly/template-cleanup
Merge into: lp:quickly
Diff against target: 663 lines (+237/-202)
7 files modified
data/templates/ubuntu-application/bin/project_name (+42/-44)
data/templates/ubuntu-application/create.py (+1/-0)
data/templates/ubuntu-application/python/Aboutcamel_case_nameDialog.py (+26/-32)
data/templates/ubuntu-application/python/Preferencescamel_case_nameDialog.py (+75/-75)
data/templates/ubuntu-application/python/dialog_camel_case_nameDialog.py (+30/-37)
data/templates/ubuntu-application/python/helpers.py (+34/-0)
data/templates/ubuntu-application/python/python_nameconfig.py (+29/-14)
To merge this branch: bzr merge lp:~jml/quickly/template-cleanup
Reviewer Review Type Date Requested Status
Didier Roche-Tolomelli Approve
Review via email: mp+16684@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Jonathan Lange (jml) wrote :

This branch changes the Ubuntu application templates to be a little nicer for the average Python programmer.

 - All excess whitespace is deleted
 - PEP 8 is followed where possible
 - Repeated code has been extracted into a 'helpers' module
 - Spelling mistakes have been corrected
 - Docstrings now conform to Python's docstring standards.
 - Comments are written as full sentences.
 - Double underscore prefixes are now single underscore prefixes

Hope this helps,
jml

lp:~jml/quickly/template-cleanup updated
408. By Jonathan Lange

Install the helpers file.

Revision history for this message
Didier Roche-Tolomelli (didrocks) wrote :

Hey Jonathan, thanks for your path.

I really have to find a vim script to format PEP8 compliant a python code (I know, you use emacs and don't care ;))

Thanks for this part:
647 - if __python_name_data_directory__.startswith('/'):
648 - pathname = __python_name_data_directory__
649 - else:
650 - pathname = os.path.dirname(__file__) + '/' + __python_name_data_directory__
651 + # Get pathname absolute or relative.
652 + path = os.path.join(
653 + os.path.dirname(__file__), __python_name_data_directory__)
I didn't know that joining two absolute path only take the second. Handy trick :)

Just a question, what is the __all__ in python_nameconfig.py is for? I only know this for autoimporting module in __init__.py, and you seem to still import function one by one:
from python_name.python_nameconfig import get_data_file
So, I don't really see its usefulness ;)

also, why importing multiple module in a same line is wrong?
(cf commit 404)

BTW, merged, thanks! I'll try to go file by file to include PEP8 compliance, but this is a long term work :)

review: Approve
Revision history for this message
Jonathan Lange (jml) wrote :

On Thu, Dec 31, 2009 at 7:53 PM, Didier Roche <email address hidden> wrote:
> Review: Approve
> Hey Jonathan, thanks for your path.
>
> I really have to find a vim script to format PEP8 compliant a python code (I know, you use emacs and don't care ;))
>

Heh heh.

> Thanks for this part:
> 647     - if __python_name_data_directory__.startswith('/'):
> 648     - pathname = __python_name_data_directory__
> 649     - else:
> 650     - pathname = os.path.dirname(__file__) + '/' + __python_name_data_directory__
> 651     + # Get pathname absolute or relative.
> 652     + path = os.path.join(
> 653     + os.path.dirname(__file__), __python_name_data_directory__)
> I didn't know that joining two absolute path only take the second. Handy trick :)
>
> Just a question, what is the __all__ in python_nameconfig.py is for? I only know this for autoimporting module in __init__.py, and you seem to still import function one by one:
> from python_name.python_nameconfig import get_data_file
> So, I don't really see its usefulness ;)
>

Ahh OK. It's there to indicate which names in the module are really
public. We don't have to have it if you don't want. Launchpad uses it
to check that people aren't using private stuff (we have a utility
called "importfascist" that does this).

> also, why importing multiple module in a same line is wrong?
> (cf commit 404)
>

PEP 8 says so.

> BTW, merged, thanks! I'll try to go file by file to include PEP8 compliance, but this is a long term work :)
>

Going file-by-file is the best approach. I changed all of these
because I wanted to start a Quickly project and not have a bunch of
red warnings on my screen. :)

jml

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'data/templates/ubuntu-application/bin/project_name'
--- data/templates/ubuntu-application/bin/project_name 2009-12-26 14:40:43 +0000
+++ data/templates/ubuntu-application/bin/project_name 2009-12-31 02:05:23 +0000
@@ -8,104 +8,102 @@
8import os8import os
9import gtk9import gtk
1010
11# add project root directory (enable symlink, and trunk execution)11# Add project root directory (enable symlink, and trunk execution).
12project_bin_directory = os.path.dirname(os.path.realpath(sys.argv[0]))12PROJECT_ROOT_DIRECTORY = os.path.abspath(
13project_root_directory_name = os.path.dirname(project_bin_directory)13 os.path.dirname(os.path.dirname(os.path.realpath(sys.argv[0]))))
14project_root_directory = os.path.abspath(project_root_directory_name)14
15if os.path.exists(os.path.join(project_root_directory, 'python_name')) and project_root_directory not in sys.path:15if (os.path.exists(os.path.join(PROJECT_ROOT_DIRECTORY, 'python_name'))
16 sys.path.insert(0, project_root_directory)16 and PROJECT_ROOT_DIRECTORY not in sys.path):
17 os.putenv('PYTHONPATH', project_root_directory) # for subprocesses17 sys.path.insert(0, PROJECT_ROOT_DIRECTORY)
1818 os.putenv('PYTHONPATH', PROJECT_ROOT_DIRECTORY) # for subprocesses
19from python_name import Aboutcamel_case_nameDialog, Preferencescamel_case_nameDialog19
20from python_name.python_nameconfig import getdatapath20from python_name import (
21 Aboutcamel_case_nameDialog, Preferencescamel_case_nameDialog)
22from python_name.helpers import make_window
23
2124
22class camel_case_nameWindow(gtk.Window):25class camel_case_nameWindow(gtk.Window):
23 __gtype_name__ = "camel_case_nameWindow"26 __gtype_name__ = "camel_case_nameWindow"
2427
25 def __init__(self):28 def __init__(self):
26 """__init__ - This function is typically not called directly.29 """Construct a camel_case_nameWindow.
27 Creation a camel_case_nameWindow requires redeading the associated ui30
28 file and parsing the ui definition extrenally,31 This function is typically not called directly. Creation a
29 and then calling camel_case_nameWindow.finish_initializing().32 camel_case_nameWindow requires rereading the associated ui file and
33 parsing the ui definition externally, and then calling
34 camel_case_nameWindow.finish_initializing().
3035
31 Use the convenience function Newcamel_case_nameWindow to create36 Use the convenience function Newcamel_case_nameWindow to create
32 camel_case_nameWindow object.37 camel_case_nameWindow object.
33
34 """38 """
35 pass39 pass
3640
37 def finish_initializing(self, builder):41 def finish_initializing(self, builder):
38 """finish_initalizing should be called after parsing the ui definition42 """Called after we've finished initializing.
43
44 finish_initalizing should be called after parsing the UI definition
39 and creating a camel_case_nameWindow object with it in order to finish45 and creating a camel_case_nameWindow object with it in order to finish
40 initializing the start of the new camel_case_nameWindow instance.46 initializing the start of the new camel_case_nameWindow instance.
41
42 """47 """
43 #get a reference to the builder and set up the signals48 # Get a reference to the builder and set up the signals.
44 self.builder = builder49 self.builder = builder
45 self.builder.connect_signals(self)50 self.builder.connect_signals(self)
4651
47 #uncomment the following code to read in preferences at start up52 # Uncomment the following code to read in preferences at start up.
48 #dlg = Preferencescamel_case_nameDialog.NewPreferencescamel_case_nameDialog()53 #dlg = Preferencescamel_case_nameDialog.NewPreferencescamel_case_nameDialog()
49 #self.preferences = dlg.get_preferences()54 #self.preferences = dlg.get_preferences()
5055
51 #code for other initialization actions should be added here56 # Code for other initialization actions should be added here.
5257
53 def about(self, widget, data=None):58 def about(self, widget, data=None):
54 """about - display the about box for project_name """59 """Display the about box for project_name."""
55 about = Aboutcamel_case_nameDialog.NewAboutcamel_case_nameDialog()60 about = Aboutcamel_case_nameDialog.NewAboutcamel_case_nameDialog()
56 response = about.run()61 response = about.run()
57 about.destroy()62 about.destroy()
5863
59 def preferences(self, widget, data=None):64 def preferences(self, widget, data=None):
60 """preferences - display the preferences window for project_name """65 """Display the preferences window for project_name."""
61 prefs = Preferencescamel_case_nameDialog.NewPreferencescamel_case_nameDialog()66 prefs = Preferencescamel_case_nameDialog.NewPreferencescamel_case_nameDialog()
62 response = prefs.run()67 response = prefs.run()
63 if response == gtk.RESPONSE_OK:68 if response == gtk.RESPONSE_OK:
64 #make any updates based on changed preferences here69 # Make any updates based on changed preferences here.
65 pass70 pass
66 prefs.destroy()71 prefs.destroy()
6772
68 def quit(self, widget, data=None):73 def quit(self, widget, data=None):
69 """quit - signal handler for closing the camel_case_nameWindow"""74 """Signal handler for closing the camel_case_nameWindow."""
70 self.destroy()75 self.destroy()
7176
72 def on_destroy(self, widget, data=None):77 def on_destroy(self, widget, data=None):
73 """on_destroy - called when the camel_case_nameWindow is close. """78 """Called when the camel_case_nameWindow is closed."""
74 #clean up code for saving application state should be added here79 # Clean up code for saving application state should be added here.
75
76 gtk.main_quit()80 gtk.main_quit()
7781
82
78def Newcamel_case_nameWindow():83def Newcamel_case_nameWindow():
79 """Newcamel_case_nameWindow - returns a fully instantiated84 """Newcamel_case_nameWindow - returns a fully instantiated
80 camel_case_nameWindow object. Use this function rather than85 camel_case_nameWindow object. Use this function rather than
81 creating a camel_case_nameWindow directly.86 creating a camel_case_nameWindow directly.
82 """87 """
8388 return make_window('camel_case_nameWindow', "python_name_window")
84 #look for the ui file that describes the ui89
85 ui_filename = os.path.join(getdatapath(), 'ui', 'camel_case_nameWindow.ui')
86 if not os.path.exists(ui_filename):
87 ui_filename = None
88
89 builder = gtk.Builder()
90 builder.add_from_file(ui_filename)
91 window = builder.get_object("python_name_window")
92 window.finish_initializing(builder)
93 return window
9490
95if __name__ == "__main__":91if __name__ == "__main__":
96 #support for command line options92 # Support for command line options.
97 import logging, optparse93 import logging
94 import optparse
98 parser = optparse.OptionParser(version="%prog %ver")95 parser = optparse.OptionParser(version="%prog %ver")
99 parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="Show debug messages")96 parser.add_option(
97 "-v", "--verbose", action="store_true", dest="verbose",
98 help="Show debug messages")
100 (options, args) = parser.parse_args()99 (options, args) = parser.parse_args()
101100
102 #set the logging level to show debug messages101 # Set the logging level to show debug messages.
103 if options.verbose:102 if options.verbose:
104 logging.basicConfig(level=logging.DEBUG)103 logging.basicConfig(level=logging.DEBUG)
105 logging.debug('logging enabled')104 logging.debug('logging enabled')
106105
107 #run the application106 # Run the application.
108 window = Newcamel_case_nameWindow()107 window = Newcamel_case_nameWindow()
109 window.show()108 window.show()
110 gtk.main()109 gtk.main()
111
112110
=== modified file 'data/templates/ubuntu-application/create.py'
--- data/templates/ubuntu-application/create.py 2009-12-29 17:18:44 +0000
+++ data/templates/ubuntu-application/create.py 2009-12-31 02:05:23 +0000
@@ -120,6 +120,7 @@
120quicklyutils.file_from_template(template_python_dir, "Aboutcamel_case_nameDialog.py", target_python_dir, substitutions)120quicklyutils.file_from_template(template_python_dir, "Aboutcamel_case_nameDialog.py", target_python_dir, substitutions)
121quicklyutils.file_from_template(template_python_dir, "Preferencescamel_case_nameDialog.py", target_python_dir, substitutions)121quicklyutils.file_from_template(template_python_dir, "Preferencescamel_case_nameDialog.py", target_python_dir, substitutions)
122quicklyutils.file_from_template(template_python_dir, "python_nameconfig.py", target_python_dir, substitutions)122quicklyutils.file_from_template(template_python_dir, "python_nameconfig.py", target_python_dir, substitutions)
123quicklyutils.file_from_template(template_python_dir, 'helpers.py', target_python_dir, substitutions)
123124
124# copy the files needed for packaging125# copy the files needed for packaging
125quicklyutils.file_from_template(abs_path, "project_root/setup.py", ".", substitutions)126quicklyutils.file_from_template(abs_path, "project_root/setup.py", ".", substitutions)
126127
=== modified file 'data/templates/ubuntu-application/python/Aboutcamel_case_nameDialog.py'
--- data/templates/ubuntu-application/python/Aboutcamel_case_nameDialog.py 2009-12-26 14:40:43 +0000
+++ data/templates/ubuntu-application/python/Aboutcamel_case_nameDialog.py 2009-12-31 02:05:23 +0000
@@ -3,59 +3,53 @@
3# This file is in the public domain3# This file is in the public domain
4### END LICENSE4### END LICENSE
55
6import sys
7import os
8import gtk6import gtk
97
10from python_name.python_nameconfig import getdatapath8from python_name.helpers import make_window
9
1110
12class Aboutcamel_case_nameDialog(gtk.AboutDialog):11class Aboutcamel_case_nameDialog(gtk.AboutDialog):
13 __gtype_name__ = "Aboutcamel_case_nameDialog"12 __gtype_name__ = "Aboutcamel_case_nameDialog"
1413
15 def __init__(self):14 def __init__(self):
16 """__init__ - This function is typically not called directly.15 """Construct an Aboutcamel_case_nameDialog.
17 Creation of a Aboutcamel_case_nameDialog requires redeading the associated ui16
18 file and parsing the ui definition extrenally, 17 This function is typically not called directly. Creation of an
19 and then calling Aboutcamel_case_nameDialog.finish_initializing().18 Aboutcamel_case_nameDialog requires redeading the associated UI file
20 19 and parsing the UI definition externally, and then calling
21 Use the convenience function NewAboutcamel_case_nameDialog to create 20 Aboutcamel_case_nameDialog.finish_initializing().
21
22 Use the convenience function NewAboutcamel_case_nameDialog to create
22 NewAboutcamel_case_nameDialog objects.23 NewAboutcamel_case_nameDialog objects.
23
24 """24 """
25 pass25 pass
2626
27 def finish_initializing(self, builder):27 def finish_initializing(self, builder):
28 """finish_initalizing should be called after parsing the ui definition28 """Called after we've finished initializing.
29 and creating a Aboutcamel_case_nameDialog object with it in order to finish29
30 initializing the start of the new Aboutcamel_case_nameDialog instance.30 finish_initalizing should be called after parsing the ui definition
31 31 and creating a Aboutcamel_case_nameDialog object with it in order to
32 finish initializing the start of the new Aboutcamel_case_nameDialog
33 instance.
32 """34 """
33 #get a reference to the builder and set up the signals35 # Get a reference to the builder and set up the signals.
34 self.builder = builder36 self.builder = builder
35 self.builder.connect_signals(self)37 self.builder.connect_signals(self)
3638
37 #code for other initialization actions should be added here39 # Code for other initialization actions should be added here.
40
3841
39def NewAboutcamel_case_nameDialog():42def NewAboutcamel_case_nameDialog():
40 """NewAboutcamel_case_nameDialog - returns a fully instantiated43 """Returns a fully instantiated Aboutcamel_case_nameDialog object.
41 Aboutcamel_case_nameDialog object. Use this function rather than44
42 creating a Aboutcamel_case_nameDialog instance directly.45 Use this function rather than creating a Aboutcamel_case_nameDialog
43 46 instance directly.
44 """47 """
4548 return make_window(
46 #look for the ui file that describes the ui49 'Aboutcamel_case_nameDialog', "about_python_name_dialog")
47 ui_filename = os.path.join(getdatapath(), 'ui', 'Aboutcamel_case_nameDialog.ui')50
48 if not os.path.exists(ui_filename):
49 ui_filename = None
50
51 builder = gtk.Builder()
52 builder.add_from_file(ui_filename)
53 dialog = builder.get_object("about_python_name_dialog")
54 dialog.finish_initializing(builder)
55 return dialog
5651
57if __name__ == "__main__":52if __name__ == "__main__":
58 dialog = NewAboutcamel_case_nameDialog()53 dialog = NewAboutcamel_case_nameDialog()
59 dialog.show()54 dialog.show()
60 gtk.main()55 gtk.main()
61
6256
=== modified file 'data/templates/ubuntu-application/python/Preferencescamel_case_nameDialog.py'
--- data/templates/ubuntu-application/python/Preferencescamel_case_nameDialog.py 2009-12-26 14:40:43 +0000
+++ data/templates/ubuntu-application/python/Preferencescamel_case_nameDialog.py 2009-12-31 02:05:23 +0000
@@ -3,118 +3,118 @@
3# This file is in the public domain3# This file is in the public domain
4### END LICENSE4### END LICENSE
55
6import sys
7import os
8import gtk
9from desktopcouch.records.server import CouchDatabase6from desktopcouch.records.server import CouchDatabase
10from desktopcouch.records.record import Record7from desktopcouch.records.record import Record
118import gtk
12from python_name.python_nameconfig import getdatapath9
10from python_name.helpers import make_window
11
1312
14class Preferencescamel_case_nameDialog(gtk.Dialog):13class Preferencescamel_case_nameDialog(gtk.Dialog):
15 __gtype_name__ = "Preferencescamel_case_nameDialog"14 __gtype_name__ = "Preferencescamel_case_nameDialog"
16 prefernces = {}15 preferences = {}
1716
18 def __init__(self):17 def __init__(self):
19 """__init__ - This function is typically not called directly.18 """Construct a Preferencescamel_case_nameDialog.
20 Creation of a Preferencescamel_case_nameDialog requires redeading the associated ui19
21 file and parsing the ui definition extrenally,20 This function is typically not called directly. Creation of a
22 and then calling Preferencescamel_case_nameDialog.finish_initializing().21 Preferencescamel_case_nameDialog requires rereading the associated UI
2322 file and parsing the UI definition extrenally, and then calling
24 Use the convenience function NewPreferencescamel_case_nameDialog to create23 Preferencescamel_case_nameDialog.finish_initializing().
25 NewAboutcamel_case_nameDialog objects.24
25 Use the convenience function NewPreferencescamel_case_nameDialog to
26 create NewAboutcamel_case_nameDialog objects.
26 """27 """
27
28 pass28 pass
2929
30 def finish_initializing(self, builder):30 def finish_initializing(self, builder):
31 """finish_initalizing should be called after parsing the ui definition31 """Called after we've finished initializing.
32 and creating a Aboutcamel_case_nameDialog object with it in order to finish32
33 initializing the start of the new Aboutcamel_case_nameDialog instance.33 finish_initalizing should be called after parsing the ui definition
34 and creating a Aboutcamel_case_nameDialog object with it in order to
35 finish initializing the start of the new Aboutcamel_case_nameDialog
36 instance.
34 """37 """
3538
36 #get a reference to the builder and set up the signals39 # Get a reference to the builder and set up the signals.
37 self.builder = builder40 self.builder = builder
38 self.builder.connect_signals(self)41 self.builder.connect_signals(self)
3942
40 #set up couchdb and the preference info43 # Set up couchdb and the preference info.
41 self.__db_name = "project_name"44 self._db_name = "project_name"
42 self.__database = CouchDatabase(self.__db_name, create=True)45 self._database = CouchDatabase(self._db_name, create=True)
43 self.__preferences = None46 self._preferences = None
44 self.__key = None47 self._key = None
4548
46 #set the record type and then initalize the preferences49 # Set the record type and then initalize the preferences.
47 self.__record_type = "http://wiki.ubuntu.com/Quickly/RecordTypes/camel_case_name/Preferences"50 self._record_type = (
48 self.__preferences = self.get_preferences()51 "http://wiki.ubuntu.com/Quickly/RecordTypes/camel_case_name/"
49 #TODO:code for other initialization actions should be added here52 "Preferences")
53 self._preferences = self.get_preferences()
54 # TODO: code for other initialization actions should be added here
5055
51 def get_preferences(self):56 def get_preferences(self):
52 """get_preferences -returns a dictionary object that contain57 """Return a dict of preferences for project_name.
53 preferences for project_name. Creates a couchdb record if58
54 necessary.59 Creates a couchdb record if necessary.
55 """60 """
5661 if self._preferences == None:
57 if self.__preferences == None: #the dialog is initializing62 # The dialog is initializing.
58 self.__load_preferences()63 self._load_preferences()
59 64
60 #if there were no saved preference, this 65 # If there were no saved preference, this.
61 return self.__preferences66 return self._preferences
6267
63 def __load_preferences(self):68 def _load_preferences(self):
64 #TODO: add prefernces to the self.__preferences dict69 # TODO: add preferences to the self._preferences dict default
65 #default preferences that will be overwritten if some are saved70 # preferences that will be overwritten if some are saved
66 self.__preferences = {"record_type":self.__record_type}71 self._preferences = {"record_type": self._record_type}
67 72
68 results = self.__database.get_records(record_type=self.__record_type, create_view=True)73 results = self._database.get_records(
69 74 record_type=self._record_type, create_view=True)
75
70 if len(results.rows) == 0:76 if len(results.rows) == 0:
71 #no preferences have ever been saved77 # No preferences have ever been saved, save them before returning.
72 #save them before returning78 self._key = self._database.put_record(Record(self._preferences))
73 self.__key = self.__database.put_record(Record(self.__preferences))
74 else:79 else:
75 self.__preferences = results.rows[0].value80 self._preferences = results.rows[0].value
76 del self.__preferences['_rev']81 del self._preferences['_rev']
77 self.__key = results.rows[0].value["_id"]82 self._key = results.rows[0].value["_id"]
78 83
79 def __save_preferences(self):84 def _save_preferences(self):
80 self.__database.update_fields(self.__key, self.__preferences)85 self._database.update_fields(self._key, self._preferences)
8186
82 def ok(self, widget, data=None):87 def ok(self, widget, data=None):
83 """ok - The user has elected to save the changes.88 """The user has elected to save the changes.
89
84 Called before the dialog returns gtk.RESONSE_OK from run().90 Called before the dialog returns gtk.RESONSE_OK from run().
85 """91 """
8692
87 #make any updates to self.__preferences here93 # Make any updates to self._preferences here. e.g.
88 #self.__preferences["preference1"] = "value2"94 #self._preferences["preference1"] = "value2"
89 self.__save_preferences()95 self._save_preferences()
9096
91 def cancel(self, widget, data=None):97 def cancel(self, widget, data=None):
92 """cancel - The user has elected cancel changes.98 """The user has elected cancel changes.
99
93 Called before the dialog returns gtk.RESPONSE_CANCEL for run()100 Called before the dialog returns gtk.RESPONSE_CANCEL for run()
94 """101 """
95102 # Restore any changes to self._preferences here.
96 #restore any changes to self.__preferences here
97 pass103 pass
98104
105
99def NewPreferencescamel_case_nameDialog():106def NewPreferencescamel_case_nameDialog():
100 """NewPreferencescamel_case_nameDialog - returns a fully instantiated107 """Returns a fully instantiated Preferencescamel_case_nameDialog object.
101 Preferencescamel_case_nameDialog object. Use this function rather than108
102 creating a Preferencescamel_case_nameDialog instance directly.109 Use this function rather than creating a Preferencescamel_case_nameDialog
110 instance directly.
103 """111 """
104112 return make_window(
105 #look for the ui file that describes the ui113 'Preferencescamel_case_nameDialog',
106 ui_filename = os.path.join(getdatapath(), 'ui', 'Preferencescamel_case_nameDialog.ui')114 "preferences_python_name_dialog")
107 if not os.path.exists(ui_filename):115
108 ui_filename = None
109
110 builder = gtk.Builder()
111 builder.add_from_file(ui_filename)
112 dialog = builder.get_object("preferences_python_name_dialog")
113 dialog.finish_initializing(builder)
114 return dialog
115116
116if __name__ == "__main__":117if __name__ == "__main__":
117 dialog = NewPreferencescamel_case_nameDialog()118 dialog = NewPreferencescamel_case_nameDialog()
118 dialog.show()119 dialog.show()
119 gtk.main()120 gtk.main()
120
121121
=== modified file 'data/templates/ubuntu-application/python/dialog_camel_case_nameDialog.py'
--- data/templates/ubuntu-application/python/dialog_camel_case_nameDialog.py 2009-12-23 07:18:48 +0000
+++ data/templates/ubuntu-application/python/dialog_camel_case_nameDialog.py 2009-12-31 02:05:23 +0000
@@ -3,72 +3,65 @@
3# This file is in the public domain3# This file is in the public domain
4### END LICENSE4### END LICENSE
55
6import sys
7import os
8import gtk6import gtk
97
10from python_name.python_nameconfig import getdatapath8from python_name.helpers import make_window
9
1110
12class dialog_camel_case_nameDialog(gtk.Dialog):11class dialog_camel_case_nameDialog(gtk.Dialog):
13 __gtype_name__ = "dialog_camel_case_nameDialog"12 __gtype_name__ = "dialog_camel_case_nameDialog"
1413
15 def __init__(self):14 def __init__(self):
16 """__init__ - This function is typically not called directly.15 """Construct a dialog_camel_case_nameDialog.
17 Creation of a dialog_camel_case_nameDialog requires redeading the associated ui16
18 file and parsing the ui definition extrenally, 17 This function is typically not called directly. Creation of a
19 and then calling dialog_camel_case_nameDialog.finish_initializing().18 dialog_camel_case_nameDialog requires rereading the associated UI file
20 19 and parsing the UI definition externally, and then calling
21 Use the convenience function Newdialog_camel_case_nameDialog to create 20 dialog_camel_case_nameDialog.finish_initializing().
21
22 Use the convenience function Newdialog_camel_case_nameDialog to create
22 a dialog_camel_case_nameDialog object.23 a dialog_camel_case_nameDialog object.
23
24 """24 """
25 pass25 pass
2626
27 def finish_initializing(self, builder):27 def finish_initializing(self, builder):
28 """finish_initalizing should be called after parsing the ui definition28 """Called when we're finished initializing.
29 and creating a dialog_camel_case_nameDialog object with it in order to finish29
30 initializing the start of the new dialog_camel_case_nameDialog instance.30 finish_initalizing should be called after parsing the ui definition
31 31 and creating a dialog_camel_case_nameDialog object with it in order to
32 finish initializing the start of the new dialog_camel_case_nameDialog
33 instance.
32 """34 """
33 #get a reference to the builder and set up the signals35 # Get a reference to the builder and set up the signals.
34 self.builder = builder36 self.builder = builder
35 self.builder.connect_signals(self)37 self.builder.connect_signals(self)
3638
37
38 def ok(self, widget, data=None):39 def ok(self, widget, data=None):
39 """ok - The user has elected to save the changes.40 """The user has elected to save the changes.
41
40 Called before the dialog returns gtk.RESONSE_OK from run().42 Called before the dialog returns gtk.RESONSE_OK from run().
41
42 """43 """
43 pass44 pass
4445
45 def cancel(self, widget, data=None):46 def cancel(self, widget, data=None):
46 """cancel - The user has elected cancel changes.47 """The user has elected cancel changes.
48
47 Called before the dialog returns gtk.RESPONSE_CANCEL for run()49 Called before the dialog returns gtk.RESPONSE_CANCEL for run()
4850 """
49 """
50 pass51 pass
5152
53
52def Newdialog_camel_case_nameDialog():54def Newdialog_camel_case_nameDialog():
53 """Newdialog_camel_case_nameDialog - returns a fully instantiated55 """Return a fully instantiated dialog-camel_case_nameDialog object.
54 dialog-camel_case_nameDialog object. Use this function rather than56
55 creating dialog_camel_case_nameDialog instance directly.57 Use this function rather than creating dialog_camel_case_nameDialog
56 58 instance directly.
57 """59 """
5860 return make_window(
59 #look for the ui file that describes the ui61 'dialog_camel_case_nameDialog', "dialog_name_dialog")
60 ui_filename = os.path.join(getdatapath(), 'ui', 'dialog_camel_case_nameDialog.ui')62
61 if not os.path.exists(ui_filename):
62 ui_filename = None
63
64 builder = gtk.Builder()
65 builder.add_from_file(ui_filename)
66 dialog = builder.get_object("dialog_name_dialog")
67 dialog.finish_initializing(builder)
68 return dialog
6963
70if __name__ == "__main__":64if __name__ == "__main__":
71 dialog = Newdialog_camel_case_nameDialog()65 dialog = Newdialog_camel_case_nameDialog()
72 dialog.show()66 dialog.show()
73 gtk.main()67 gtk.main()
74
7568
=== added file 'data/templates/ubuntu-application/python/helpers.py'
--- data/templates/ubuntu-application/python/helpers.py 1970-01-01 00:00:00 +0000
+++ data/templates/ubuntu-application/python/helpers.py 2009-12-31 02:05:23 +0000
@@ -0,0 +1,34 @@
1# -*- coding: utf-8 -*-
2### BEGIN LICENSE
3# This file is in the public domain
4### END LICENSE
5
6"""Helpers for an Ubuntu application."""
7
8__all__ = [
9 'make_window',
10 ]
11
12import os
13import gtk
14
15from python_name.python_nameconfig import get_data_file
16
17
18def make_window(builder_file_name, window_name):
19 """Return a fully-instantiated window or dialog.
20
21 :param builder_file_name: The name of the builder file, without extension.
22 Assumed to be in the 'ui' directory under the data path.
23 :param window_name: The name of the window or dialog in the builder file.
24 """
25 # Look for the ui file that describes the user interface.
26 ui_filename = get_data_file('ui', '%s.ui' % (builder_file_name,))
27 if not os.path.exists(ui_filename):
28 ui_filename = None
29
30 builder = gtk.Builder()
31 builder.add_from_file(ui_filename)
32 dialog = builder.get_object(window_name)
33 dialog.finish_initializing(builder)
34 return dialog
035
=== modified file 'data/templates/ubuntu-application/python/python_nameconfig.py'
--- data/templates/ubuntu-application/python/python_nameconfig.py 2009-12-29 17:31:56 +0000
+++ data/templates/ubuntu-application/python/python_nameconfig.py 2009-12-31 02:05:23 +0000
@@ -8,17 +8,35 @@
8# Do not touch unless you know what you're doing.8# Do not touch unless you know what you're doing.
9# you're warned :)9# you're warned :)
1010
11# where your project will head for your data (for instance, images and ui files)11__all__ = [
12# by default, this is ../data, relative your trunk layout12 'project_path_not_found',
13 'get_data_file',
14 'get_data_path',
15 ]
16
17# Where your project will look for your data (for instance, images and ui
18# files). By default, this is ../data, relative your trunk layout
13__python_name_data_directory__ = '../data/'19__python_name_data_directory__ = '../data/'
14__license__ = ''20__license__ = ''
1521
16import os22import os
1723
24
18class project_path_not_found(Exception):25class project_path_not_found(Exception):
19 pass26 """Raised when we can't find the project directory."""
2027
21def getdatapath():28
29def get_data_file(*path_segments):
30 """Get the full path to a data file.
31
32 Returns the path to a file underneath the data directory (as defined by
33 `get_data_path`). Equivalent to os.path.join(get_data_path(),
34 *path_segments).
35 """
36 return os.path.join(get_data_path(), *path_segments)
37
38
39def get_data_path():
22 """Retrieve project_name data path40 """Retrieve project_name data path
2341
24 This path is by default <python_name_lib_path>/../data/ in trunk42 This path is by default <python_name_lib_path>/../data/ in trunk
@@ -26,15 +44,12 @@
26 is specified at installation time.44 is specified at installation time.
27 """45 """
2846
29 # get pathname absolute or relative47 # Get pathname absolute or relative.
30 if __python_name_data_directory__.startswith('/'):48 path = os.path.join(
31 pathname = __python_name_data_directory__49 os.path.dirname(__file__), __python_name_data_directory__)
32 else:
33 pathname = os.path.dirname(__file__) + '/' + __python_name_data_directory__
3450
35 abs_data_path = os.path.abspath(pathname)51 abs_data_path = os.path.abspath(path)
36 if os.path.exists(abs_data_path):52 if not os.path.exists(abs_data_path):
37 return abs_data_path
38 else:
39 raise project_path_not_found53 raise project_path_not_found
4054
55 return abs_data_path

Subscribers

People subscribed via source and target branches