def __init__(self, parent=None):
        super(LConfigurationManagerWizard, self).__init__(parent)
        self.debug = (DEBUG & WIDGET)
        self.actions = LActions(None, self)

        self.setPage(INTRO_PAGE_ID, LIntroductionPage())
        self.setPage(SAVE_PAGE_ID, LSavePage())
        self.setPage(RESTORE_PAGE_ID, LRestorePage())
        self.setPage(COMPARE_PAGE_ID, LComparePage())
        self.setPage(LIST_PAGE_ID, LListPage())
        self.setStartId(INTRO_PAGE_ID)
        self.helpRequested.connect(self.showHelp)
class LConfigurationManagerWizard(QWizard):
    ''' Help the operator walk through the config manager '''
    def __init__(self, parent=None):
        super(LConfigurationManagerWizard, self).__init__(parent)
        self.debug = (DEBUG & WIDGET)
        self.actions = LActions(None, self)

        self.setPage(INTRO_PAGE_ID, LIntroductionPage())
        self.setPage(SAVE_PAGE_ID, LSavePage())
        self.setPage(RESTORE_PAGE_ID, LRestorePage())
        self.setPage(COMPARE_PAGE_ID, LComparePage())
        self.setPage(LIST_PAGE_ID, LListPage())
        self.setStartId(INTRO_PAGE_ID)
        self.helpRequested.connect(self.showHelp)

    @LInAndOut(DEBUG & WIDGET)
    def setupUi(self):
        ''' Setup GUI '''
        self.setPixmap(QWizard.LogoPixmap, QPixmap(":/qrc/images/logo.png"))
        self.setPixmap(QWizard.BannerPixmap, QPixmap(":/qrc/images/banner.png"))
        self.setPixmap(QWizard.BackgroundPixmap, QPixmap(":/qrc/images/background.png"))
        self.setOption(QWizard.HaveHelpButton, SHOW_HELP_BUTTON)
    
    @LInAndOut(DEBUG & WIDGET)
    def nextId(self):
        ''' next id page '''
        FINISHED = -1
        currentId = self.currentId()
        if self.verboseLevel :
            print "currentId = %d" % currentId
            print "INTRO(%d),COMPARE(%d),SAVE(%d),RESTORE(%d)" % (
                INTRO_PAGE_ID, COMPARE_PAGE_ID, SAVE_PAGE_ID, RESTORE_PAGE_ID
                )
        if currentId == INTRO_PAGE_ID:
            if self.field("operation.save").toBool(): 
                nextId = SAVE_PAGE_ID
            if self.field("operation.restore").toBool(): 
                nextId = RESTORE_PAGE_ID
            if self.field("operation.compare").toBool(): 
                nextId = COMPARE_PAGE_ID
            if self.field("operation.list").toBool(): 
                nextId = LIST_PAGE_ID
        elif currentId == SAVE_PAGE_ID:
            nextId = FINISHED
        elif currentId == RESTORE_PAGE_ID:
            nextId = FINISHED
            print "nextId = %d" % nextId
        elif currentId == COMPARE_PAGE_ID:
            nextId = FINISHED
        elif currentId == LIST_PAGE_ID:
            nextId = SAVE_PAGE_ID
        else :
            nextId = -1
        if self.debug :
            print "nextId    = %d" % nextId
        return nextId

    def showHelp(self):
        self.actions.on_startHelpBrowserAction_triggered()

    def accept(self):
        ''' when clicking on finish button '''
        command = self.getCommand()
        if self.dryRun :
            print "command : %s" % command
        else:
            self.executeCommand(command)
        #Required!
        super(LConfigurationManagerWizard, self).accept()
        
    def setOptions(self, options):
        ''' Set options from command line or other '''
        self.verboseLevel = getattr(options,"verboseLevel",0)
        self.setWindowTitle(getattr(options,"windowTitle",WINDOW_TITLE))
        self.dryRun = getattr(options,"dryRun",False)
        
    def setArguments(self, arguments):
        ''' Set arguments from command line '''
        pass

    def getCommand(self):
        ''' Returns command to execute when finish button is clicked '''
        if self.field("operation.save").toBool() :
            command = "cm save"
            command+= " -D '%s'" % self.field("save.description").toString()
        elif self.field("operation.restore").toBool() :
            command = "cm restore"
            command+= " -I -%d" % self.field("restore.description").toString()
        elif self.field("operation.compare").toBool() :
            command = "cm compare"
        else :  command = "cm list"
        return command
        
    def executeCommand(self, command):
        ''' Excute command passed as a parameter '''
        p1 = subprocess.Popen(command, shell=True, 
                              stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        # Wait for process to complete
        p1.wait()
        if self.verboseLevel >=2 :
            print time.asctime()
            exitCode = p1.returncode
            stdout, stderr = p1.communicate()
            print "p1: stdout:   %s" % stdout[:-1]
            print "p1: stderr:   %s" % stderr[:-1]
            print "p1: exitCode: %d" % exitCode
        

    #----------------------------------------------------------------------
    # Events

    @LInAndOut(DEBUG & WIDGET)
    def contextMenuEvent(self, event):
        ''' Display the contextual menu '''
        menu = self.actions.getContextMenu()
        menu.exec_(event.globalPos())