The startup process of an application depends on two factors.Is this and application for making other applications or is this a standalone application. The folder structure is the same for both types, but when it comes to making an application for making other applications or holding sub applications, this one contains several new steps when starting up. This documents consists only of the first part. The other part can be found in another document.

The first startup path without sub applications

from debcore.errors import DG3Exception
from debcore.paths import getpaths
from debcore.settings import getsettings
from dereporter.reportermain import DEReporter

appdef = {
    'type' : 'application',
    'title' : 'DE Reporter',
    'appname' : 'DEReporter',
    'appversion' : '@getappversion()',
    'orgname' : '4ThePeople Ltd',
    'orgdomain' : 'dataease.com',
    'appicon' : 'icon:DE8Reporter_32.png',
}

try:
# code is properly divided between Application(DG3Designer), DG3MainWindow and MainWindow
    getpaths(startpath='My DEReporter',prefix='DEReporter') # Initialize paths with reporter parameters
    getsettings() # Initialize settings with reporter defaults
    app = DEReporter(appdef)
    app.run()
except DG3Exception as e:
    print "Error in loading DE Reporter\n%s" % e.formaterror(allinfo=True)

Typical bootstrap code

The steps are:

  1. Create the global application paths using the getpaths command
  2. Load or create global settings based on the global paths and if the application has been started before
  3. Create the application object using the appdef object
  4. Run the application

The application startup code consists of a class based on Application and a main window factory that loads a main window.

from debguiqt.app import Application

class DEReporter(Application):
    def __init__(self, eldef):
        self.__repo = None
        Application.__init__(self,eldef=eldef,mainwinfactory=self._mainwinfactory)

    def _mainwinfactory(self,eldef):
        return DEReporterMainWindow()

The application startup code

The steps are:

  1. Do internal setup
  2. Do init of super application object with a main window factory for creating your custom main window
  3. Add code for the factory that creates and return the windows object with the application object as definition

The main window startup code uses a template stored in the template path (described in the global path document)

from debguiqt import MainWindow

class DEReporterMainWindow(MainWindow):
    def __init__(self, eldef=None):
        MainWindow.__init__(self,pagename='main/DEReporterMainWindow')

    def _runatstartup(self):
        bounds = self.app.settings.globalsettings.get('bounds')
        states = self.app.settings.globalsettings.get('windowstates')
        if bounds and states:
            self.setbounds(*bounds)
            self.setwindowstates(states)
        else:
            self.qobj.showMaximized()
            self.setwindowstates('active')
        super(MainWindow, self)._runatstartup()

The main window will also look for a _runatstartup method that is run when the window is shown and the application message queue are started. It you override it make sure you call the super version as well since that one also looks in the window definition for a doafterstartup  actions.