Customizing the Application

The ApplicationAdmin controls how the application behaves, it determines the sections in the left pane, the availability of help, the about box, the menu structure, etc.

The Application Admin

Each Camelot application should subclass camelot.admin.application_admin.ApplicationAdmin and overwrite some of its methods.

Example

class MyApplicationAdmin(ApplicationAdmin):

    name = 'Camelot Video Store'

# begin sections
    def get_sections(self):
        
        from camelot.model.batch_job import BatchJob
        from camelot.model.memento import Memento
        from camelot.model.party import ( Person, Organization, 
                                          PartyCategory )
        from camelot.model.i18n import Translation
        from camelot.model.batch_job import BatchJob, BatchJobType
        
        from camelot_example.model import Movie, Tag, VisitorReport
        from camelot_example.view import VisitorsPerDirector
# begin import action
        from camelot_example.importer import ImportCovers
# end import action
        
        return [
# begin section with action
                Section( _('Movies'),
                         self,
                         Icon('tango/22x22/mimetypes/x-office-presentation.png'),
                         items = [ Movie, 
                                   Tag, 
                                   VisitorReport, 
#                                   VisitorsPerDirector,
                                   ImportCovers() ]),
# end section with action
                Section( _('Relation'),
                         self,
                         Icon('tango/22x22/apps/system-users.png'),
                         items = [ Person, 
                                   Organization,
                                   PartyCategory ]),
                Section( _('Configuration'),
                         self,
                         Icon('tango/22x22/categories/preferences-system.png'),
                         items = [ Memento, 
                                   Translation,
                                   BatchJobType,
                                   BatchJob 
                                   ])
                ]
# end sections

# begin actions
    def get_actions(self):
        from camelot.admin.action import OpenNewView
        from camelot_example.model import Movie
        
        new_movie_action = OpenNewView( self.get_related_admin(Movie) )
        new_movie_action.icon = Icon('tango/22x22/mimetypes/x-office-presentation.png')

        return [new_movie_action]
# end actions

Example of a reduced application

By reimplementing the default get_sections(), get_main_menu() and get_toolbar_actions(), it is possible to create a completely differently looking Camelot application.

../_images/reduced_main_window.png
    def get_toolbar_actions( self, toolbar_area ):
        from PyQt4.QtCore import Qt
        from camelot.model.party import Person
        from camelot.admin.action import application_action, list_action
        from model import Movie
        
        movies_action = application_action.OpenTableView( self.get_related_admin( Movie ) )
        movies_action.icon = Icon('tango/22x22/mimetypes/x-office-presentation.png')
        persons_action = application_action.OpenTableView( self.get_related_admin( Person ) )
        persons_action.icon = Icon('tango/22x22/apps/system-users.png')
        
        if toolbar_area == Qt.LeftToolBarArea:
            return [ movies_action,
                     persons_action,
                     list_action.OpenNewView(),
                     list_action.OpenFormView(),
                     list_action.DeleteSelection(),
                     application_action.Exit(),]
            
    def get_actions( self ):
        return []
    
    def get_sections( self ):
        return None
    
    def get_main_menu( self ):
        return None
    
    def get_stylesheet(self):
        from camelot.view import art
        return art.read('stylesheet/black.qss')