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 from PyQt4 import QtCore
29
30 from camelot.view.model_thread import model_function
31 from camelot.core.utils import ugettext as _
32 from camelot.core.backup import BackupMechanism
33
34 _application_admin_ = []
40
42 """The Application Admin class defines how the application should look
43 like, it also ties python classes to their associated admin classes. It's
44 behaviour can be steered by overwriting its static attributes or it's
45 methods :
46
47 .. attribute:: name
48
49 The name of the application, as it will appear in the title of the main
50 window.
51
52 .. attribute:: sections
53
54 A list containing the various sections that should appear in the left panel
55 of the mainwindow.
56
57 .. image:: ../_static/picture2.png
58
59 .. attribute:: backup_mechanism
60
61 A subclass of camelot.core.backup.BackupMechanism that enables the application
62 to perform backups an restores.
63 """
64
65 backup_mechanism = BackupMechanism
66 name = 'Camelot'
67 sections = ['Relations', 'Configuration']
68 admins = {}
69
70 auth_changed_signal = QtCore.SIGNAL('sections_changed()')
71 """This signal is emitted whenever the sections are changed, and the views
72 should be updated"""
73
81
82 - def register(self, entity, admin_class):
83 self.admins[entity] = admin_class
84
85 @model_function
89
91 """Get the default entity admin for this entity, return None, if not
92 existant"""
93
94 admin_class = None
95 try:
96 admin_class = self.admins[entity]
97 except KeyError:
98 pass
99 if not admin_class and hasattr(entity, 'Admin'):
100 admin_class = entity.Admin
101 if admin_class:
102 try:
103 return self._object_admin_cache[admin_class]
104 except KeyError:
105 admin = admin_class(self, entity)
106 self._object_admin_cache[admin_class] = admin
107 return admin
108
110 """Get the root query for an entity"""
111 return entity.query
112
114 """create_main_window"""
115 from camelot.view.mainwindow import MainWindow
116 mainwindow = MainWindow(self)
117 return mainwindow
118
130
132 """:return: a list of camelot.admin.application_action.ApplicationAction objects
133 that should be added to the menu and the icon bar for this application
134 """
135 return []
136
138 """:return: the name of the application"""
139 return self.name
140
142 """:return: string representing version of the application"""
143 return '1.0'
144
146 """:return: the QIcon that should be used for the application"""
147 from camelot.view.art import Icon
148 return Icon('tango/32x32/apps/system-users.png').getQIcon()
149
154
156 return 'Conceptive Engineering'
157
159 return 'conceptive.be'
160
162 """:return: a QUrl pointing to the index page for help"""
163 from PyQt4.QtCore import QUrl
164 return QUrl('http://www.conceptive.be/projects/camelot/')
165
167 """:return: a widget that has a show() method """
168 return None
169
171 """:return: a QUrl pointing to an affiliated webpage
172
173 When this method returns a QUrl, an additional item will be available
174 in the 'Help' menu, when clicked the system browser will be opened
175 an pointing to this url.
176
177 This can be used to connect the user to a website that is used a lot
178 in the organization, but hard to remember.
179 """
180 return None
181
183 """:return: a QUrl pointing to a page to get remote support
184
185 When this method returns a QUrl, an additional item will be available
186 in the 'Help' menu, when clicked the system browser will be opened
187 an pointing to this url.
188
189 This can be used to connect the user to services like logmein.com, an
190 online ticketing system or others.
191 """
192 return None
193
195 """
196 :return: the qt stylesheet to be used for this application as a string
197 or None if no stylesheet needed
198 """
199 return None
200
202 """Reimplement this method to add application specific translations
203 to your application.
204
205 :return: a QTranslator that should be used to translate the application
206 """
207 return QtCore.QTranslator()
208
210 """:return: the content of the About dialog, a string with html
211 syntax"""
212 return """<b>Camelot Project</b>
213 <p>
214 Copyright © 2008-2009 Conceptive Engineering.
215 All rights reserved.
216 </p>
217 <p>
218 http://www.conceptive.be/projects/camelot
219 </p>
220 """
221
227
229 from PyQt4 import QtCore
230
231 def add_actions():
232 mainwin.windowMenu.clear()
233 mainwin.windowMenu.addAction(mainwin.closeAllAct)
234 mainwin.windowMenu.addAction(mainwin.cascadeAct)
235 mainwin.windowMenu.addAction(mainwin.separatorAct)
236
237 windows = mainwin.workspace.subWindowList()
238
239 mainwin.separatorAct.setVisible(len(windows) != 0)
240
241 for i, child in enumerate(windows):
242 title = child.windowTitle()
243 if i < 9:
244 text = _('&%s %s' % (i+1, title))
245 else:
246 text = _('%s %s' % (i+1, title))
247
248 action = mainwin.windowMenu.addAction(text)
249 action.setCheckable(True)
250 action.setChecked(child == mainwin.activeMdiChild())
251
252 def create_window_activator(window):
253
254 def activate_window():
255 mainwin.workspace.setActiveSubWindow(window)
256
257 return activate_window
258
259 mainwin.connect(
260 action,
261 QtCore.SIGNAL('triggered()'),
262 create_window_activator(child)
263 )
264
265 return add_actions
266