root/gaphor/tags/release-0.10.2/gaphor/__init__.py

Revision 1200, 2.7 kB (checked in by arj..@yirdis.nl, 2 years ago)

Fixed install error

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 #!/usr/bin/env python
2 # vim:sw=4
3 """This is Gaphor, a Python based UML editor.
4 """
5
6 __all__ = [ 'main', 'resource', 'GaphorError' ]
7
8 import os
9
10 import misc.logger
11
12 from misc.resource import Resource
13
14 if os.name == 'nt':
15     home = 'USERPROFILE'
16 else:
17     home = 'HOME'
18
19 user_data_dir = os.path.join(os.getenv(home), '.gaphor')
20
21
22 # Application wide resources can be stored in the 'resource' like this
23 #
24 # >>> resource('myResource', some_value)
25 #
26 # If the resource doesn't already exist, it is created, otherwise the existing
27 # resource is returned.
28 resource = Resource(initial_resources={
29                         'Name': 'gaphor',
30                         'UserDataDir': user_data_dir,
31                         'ui.toolbox.classes': True,
32                     })
33
34
35 class GaphorError(Exception):
36     """
37     Gaphor specific exception class
38     """
39     def __init__(self, args=None):
40             Exception.__init__(self)
41             self.args = args
42
43
44 def new_main(gaphor_file=None):
45     """
46     Not yet used. see main() below.
47     """
48     from gaphor.application import Application
49     Application.init()
50
51     # backwards compatible
52     main_window = resource("MainWindow", Application.main_window)
53
54     if gaphor_file:
55         main_window.set_filename(gaphor_file)
56         main_window.execute_action('FileRevert')
57     else:
58         main_window.execute_action('FileNew')
59     Application.run()
60     Application.shutdown()
61
62
63 def main(gaphor_file=None):
64     """
65     Start the interactive application.
66
67     This involves importing plugins and creating the main window.
68     """
69     import pkg_resources
70
71     resource('Version', pkg_resources.get_distribution('gaphor').version)
72     resource('DataDir', os.path.join(pkg_resources.get_distribution('gaphor').location, 'gaphor', 'data'))
73
74     # Import GUI stuff here, since the user might not need all the GUI stuff
75     import gtk
76     import ui
77     import adapters
78     import actions
79     # Load plugin definitions:
80     import services.pluginmanager
81     import services.undomanager
82
83     from ui.mainwindow import MainWindow
84
85     resource('PluginManager').init(None)
86
87     ui.load_accel_map()
88
89     # should we set a default icon here or something?
90     main_window = resource(MainWindow)
91     main_window.construct()
92
93     # When the state changes to CLOSED, quit the application
94     main_window.connect(lambda win: win.get_state() == MainWindow.STATE_CLOSED and gtk.main_quit())
95
96     if gaphor_file:
97         main_window.set_filename(gaphor_file)
98         main_window.execute_action('FileRevert')
99     else:
100         main_window.execute_action('FileNew')
101
102     gtk.main()
103     #gtk.threads_leave()
104
105     resource.save()
106
107     ui.save_accel_map()
108
109     log.info('Bye!')
110
111
112 # TODO: Remove this
113 import __builtin__
114 __builtin__.__dict__['log'] = misc.logger.Logger()
115
116 if __debug__:
117     refs = []
118
Note: See TracBrowser for help on using the browser.