Package camelot :: Package camelot :: Package view :: Module application_admin
[hide private]
[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  """Admin class, specify how the main window should look like""" 
 29   
30 -class ApplicationAdmin(object):
31 32 sections = [] 33 admins = {} 34
35 - def __init__(self, main_sections):
36 """The main sections to be used in the navigation pane of the application, 37 all entities will be put in such a section, depending on the properties of 38 their EntityAdmin class, a list of tuples of strings and icons 39 [('section', ('Section display name',section_icon))] 40 """ 41 if main_sections: 42 self.sections = main_sections
43
44 - def register(self, entity, admin_class):
45 self.admins[entity] = admin_class
46
47 - def getSections(self):
48 return self.sections
49
50 - def getEntityAdmin(self, entity):
51 """Get the default entity admin for this entity, return None, if not 52 existant""" 53 try: 54 return self.admins[entity](self, entity) 55 except KeyError: 56 pass 57 if hasattr(entity, 'Admin'): 58 return entity.Admin(self, entity)
59
60 - def getEntityQuery(self, entity):
61 """Get the root query for an entity""" 62 return entity.query
63
64 - def getEntitiesAndQueriesInSection(self, section):
65 """ 66 @return: a list of tuples of (admin, query) instances related to 67 the entities in this section. 68 """ 69 result = [(self.getEntityAdmin(e), self.getEntityQuery(e)) 70 for e, a in self.admins.items() 71 if hasattr(a, 'section') 72 and a.section == section] 73 result.sort(cmp = lambda x, y: cmp(x[0].getName(), y[0].getName())) 74 return result
75
76 - def getActions(self):
77 """@return: a list of actions that should be added to the menu and the icon 78 bar for this application, each action is a tuple of (name, icon, callable), 79 where callable is a function taking no arguments that will be called when 80 the action is executed. Callable will be called in the model thread. 81 """ 82 return []
83
84 - def getName(self):
85 """@return: the name of the application""" 86 return "Project Camelot"
87
88 - def getIcon(self):
89 import art 90 return art.icon32('apps/system-users')
91
92 - def getAbout(self):
93 """@return: the content of the About dialog""" 94 return """<b>Camelot Project</b> 95 <p> 96 Copyright &copy; 2008 Conceptive Engineering. 97 All right reserved. 98 </p>"""
99