Package Camelot :: Package camelot :: Package view :: Module application_admin
[frames] | no frames]

Source Code for Module Camelot.camelot.view.application_admin

  1  #  ============================================================================ 
  2  # 
  3  #  Copyright (C) 2007-2008 Conceptive Engineering bvba. All rights reserved. 
  4  #  www.conceptive.be / project-camelot@conceptive.be 
  5  # 
  6  #  This file is part of the Camelot Library. 
  7  # 
  8  #  This file may be used under the terms of the GNU General Public 
  9  #  License version 2.0 as published by the Free Software Foundation 
 10  #  and appearing in the file LICENSE.GPL included in the packaging of 
 11  #  this file.  Please review the following information to ensure GNU 
 12  #  General Public Licensing requirements will be met: 
 13  #  http://www.trolltech.com/products/qt/opensource.html 
 14  # 
 15  #  If you are unsure which license is appropriate for your use, please 
 16  #  review the following information: 
 17  #  http://www.trolltech.com/products/qt/licensing.html or contact 
 18  #  project-camelot@conceptive.be. 
 19  # 
 20  #  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 
 21  #  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 
 22  # 
 23  #  For use of this library in commercial applications, please contact 
 24  #  project-camelot@conceptive.be 
 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_ = [] 
35 36 -def get_application_admin():
37 if not len(_application_admin_): 38 raise Exception('No application admin class has been constructed yet') 39 return _application_admin_[0]
40
41 -class ApplicationAdmin(QtCore.QObject):
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
74 - def __init__(self):
75 QtCore.QObject.__init__(self) 76 _application_admin_.append(self) 77 # 78 # Cache created ObjectAdmin objects 79 # 80 self._object_admin_cache = {}
81
82 - def register(self, entity, admin_class):
83 self.admins[entity] = admin_class
84 85 @model_function
86 - def get_sections(self):
89
90 - def get_entity_admin(self, entity):
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
109 - def get_entity_query(self, entity):
110 """Get the root query for an entity""" 111 return entity.query
112
113 - def create_main_window(self):
114 """create_main_window""" 115 from camelot.view.mainwindow import MainWindow 116 mainwindow = MainWindow(self) 117 return mainwindow
118
119 - def get_entities_and_queries_in_section(self, section):
120 """:return: a list of tuples of (admin, query) instances related to 121 the entities in this section. 122 """ 123 result = [(self.get_entity_admin(e), self.get_entity_query(e)) 124 for e, a in self.admins.items() 125 if hasattr(a, 'section') 126 and a.section == section] 127 result.sort(cmp = lambda x, y: cmp(x[0].get_verbose_name_plural(), 128 y[0].get_verbose_name_plural())) 129 return result
130
131 - def get_actions(self):
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
137 - def get_name(self):
138 """:return: the name of the application""" 139 return self.name
140
141 - def get_version(self):
142 """:return: string representing version of the application""" 143 return '1.0'
144
145 - def get_icon(self):
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
150 - def get_splashscreen(self):
151 """:return: a QtGui.QPixmap to be used as splash screen""" 152 from camelot.view.art import Pixmap 153 return Pixmap('splashscreen.png').getQPixmap()
154
155 - def get_organization_name(self):
156 return 'Conceptive Engineering'
157
158 - def get_organization_domain(self):
159 return 'conceptive.be'
160
161 - def get_help_url(self):
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
166 - def get_whats_new(self):
167 """:return: a widget that has a show() method """ 168 return None
169
170 - def get_affiliated_url(self):
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
182 - def get_remote_support_url(self):
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
194 - def get_stylesheet(self):
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
201 - def get_translator(self):
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
209 - def get_about(self):
210 """:return: the content of the About dialog, a string with html 211 syntax""" 212 return """<b>Camelot Project</b> 213 <p> 214 Copyright &copy; 2008-2009 Conceptive Engineering. 215 All rights reserved. 216 </p> 217 <p> 218 http://www.conceptive.be/projects/camelot 219 </p> 220 """
221
222 - def get_default_field_attributes(self, type_, field):
223 """Returns the default field attributes""" 224 from camelot.core.view.field_attributes import \ 225 _sqlalchemy_to_python_type_ 226 return _sqlalchemy_to_python_type_[type_](field)
227
228 - def update_window_menu(self, mainwin):
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