Exemplo n.º 1
0
    def initializePage(self):
        # self.field('database_configure') does not matter
        self.worker = DatabaseSetupWorker()
        self.worker.start()

        self.worker.stateProgress.connect(self.onStateProgressSignal)
        self.worker.stateError.connect(self.onStateErrorSignal)

        self.worker.stateRun.emit(self.worker.STATE_INIT)
Exemplo n.º 2
0
 def initializePage(self):
     # self.field('database_configure') does not matter
     self.worker = DatabaseSetupWorker()
     self.worker.start()
     
     self.worker.stateProgress.connect(self.onStateProgressSignal)
     self.worker.stateError.connect(self.onStateErrorSignal)
     
     self.worker.stateRun.emit(self.worker.STATE_INIT)
Exemplo n.º 3
0
class DatabaseSetupWizardPage(BaseWizardPage):
    def __init__(self, parent=None):
        super(DatabaseSetupWizardPage, self).__init__(parent)

        dsw = DatabaseSetupWorker

        statesLayout = QtGui.QGridLayout()

        self.stateIcons = {}
        self.stateLabels = {}
        self.stateDetails = {}

        labels = {
            dsw.STATE_INIT: "Initialize database",
            dsw.STATE_LOAD: "Load database",
            dsw.STATE_CREATE: "Create models",
            dsw.STATE_TEST: "Insert test data",
            dsw.STATE_DONE: "Finished setting up database"
        }

        for i, state in enumerate(
            (dsw.STATE_INIT, dsw.STATE_LOAD, dsw.STATE_CREATE, dsw.STATE_TEST,
             dsw.STATE_DONE)):
            self.stateIcons[state] = icon = QtGui.QLabel(self)
            self.stateLabels[state] = label = QtGui.QLabel(labels[state], self)
            self.stateDetails[state] = details = QtGui.QLabel(self)
            self.stateDetails[state].setWordWrap(True)

            statesLayout.addWidget(icon, i, 0)
            statesLayout.addWidget(label, i, 1)
            statesLayout.addWidget(details, i, 2)

        statesLayout.setColumnStretch(0, 0)
        statesLayout.setColumnStretch(1, 0)
        statesLayout.setColumnStretch(2, 1)

        self.progress = QtGui.QProgressBar(self)
        self.progress.setRange(0, 100)
        self.progress.setTextVisible(True)

        self.questionBox = QtGui.QGroupBox(self)
        self.questionBox.hide()

        self.prompt = QtGui.QLabel(self.questionBox)

        self.buttonBox = QtGui.QDialogButtonBox(
            QtGui.QDialogButtonBox.Yes | QtGui.QDialogButtonBox.No,
            QtCore.Qt.Horizontal, self.questionBox)

        self.buttonBox.accepted.connect(self.onPromptAccept)
        self.buttonBox.rejected.connect(self.onPromptReject)

        questionLayout = QtGui.QVBoxLayout()
        questionLayout.addWidget(self.prompt)
        questionLayout.addWidget(self.buttonBox)
        self.questionBox.setLayout(questionLayout)

        layout = QtGui.QVBoxLayout()
        layout.setSpacing(10)

        layout.addLayout(statesLayout)
        layout.addWidget(self.progress)
        layout.addStretch(1)
        layout.addWidget(self.questionBox)

        self.setLayout(layout)

        self.worker = None
        self.__error_occured = False

    def initializePage(self):
        # self.field('database_configure') does not matter
        self.worker = DatabaseSetupWorker()
        self.worker.start()

        self.worker.stateProgress.connect(self.onStateProgressSignal)
        self.worker.stateError.connect(self.onStateErrorSignal)

        self.worker.stateRun.emit(self.worker.STATE_INIT)

    def cleanupPage(self):
        self.worker.quit()
        self.worker.wait()
        # TODO: error when opening connection in a thread and closing it in another thread.
        # TODO: error when pressing back and coming back (looks like database tables are not cleared)

        for iconLbl in self.stateIcons.itervalues():
            iconLbl.setPixmap(None)

        for detailsLbl in self.stateDetails.itervalues():
            detailsLbl.setText("")

    def validatePage(self):
        if self.__error_occured:
            return False

        if self.worker.isRunning():
            return False

        return True

    def isComplete(self):
        if self.worker.isRunning():
            return False
        else:
            return super(DatabaseSetupWizardPage, self).isComplete()

    def onStateErrorSignal(self, state, exception):

        if state == self.worker.STATE_INIT:
            message = "Could not connect to database!"
        elif state == self.worker.STATE_LOAD:
            message = "Error loading models!"
        elif state == self.worker.STATE_CREATE:
            message = "Error creating tables!"
        elif state == self.worker.STATE_TEST:
            message = "Error inserting test values!"
        else:
            message = "An error occured!"

        self.__error_occured = True

        self.setMessage(
            state, -1, "<b>{message}</b><br />{exception}".format(
                message=message, exception=str(exception)))
        self.setProgress(self.worker.STATE_DONE, self.worker.DONE)
        self.worker.quit()

        self.completeChanged.emit()

    def onStateProgressSignal(self, state, progress):
        self.setProgress(state, progress)

        if state == self.worker.STATE_INIT:
            # First, connect to the database
            if progress == self.worker.START:
                self.setMessage(state, progress, "Connecting to database...")
            elif progress == self.worker.DONE:
                self.setMessage(state, progress, "Connected to database.")
                self.worker.stateRun.emit(self.worker.STATE_LOAD)
        elif state == self.worker.STATE_LOAD:
            # Second, load the models
            if progress == self.worker.START:
                self.setMessage(state, progress, "Loading models...")
            elif progress == self.worker.DONE:
                self.setMessage(state, progress, "Models loaded.")
                self.setPrompt(question="""Reconfigure Database?
This will drop the tables in the database you chose and recreate it.""",
                               onAccept=self.worker.STATE_CREATE,
                               onReject=self.worker.STATE_DONE)
        elif state == self.worker.STATE_CREATE:
            # Third, create the tables
            if progress == self.worker.START:
                self.setMessage(state, progress, "Creating tables...")
            elif progress == self.worker.DONE:
                self.setMessage(state, progress, "Tables created.")
                self.setPrompt(question="""Insert test values?""",
                               onAccept=self.worker.STATE_TEST,
                               onReject=self.worker.STATE_DONE)
        elif state == self.worker.STATE_TEST:
            # Fourth, insert the test values
            if progress == self.worker.START:
                self.setMessage(state, progress, "Inserting test values...")
            elif progress == self.worker.DONE:
                self.setMessage(state, progress, "Inserted test values.")
                self.worker.stateRun.emit(self.worker.STATE_DONE)
        elif state == self.worker.STATE_DONE and progress == self.worker.DONE:
            # Fifth, we are done
            self.setMessage(state, progress, "Done.")

        self.completeChanged.emit()

    def setPrompt(self, question, onAccept, onReject):
        self.questionBox.show()
        self.prompt.setText(question)

        self.__question_accept_callback = lambda sig=onAccept: self.worker.stateRun.emit(
            sig)
        self.__question_reject_callback = lambda sig=onReject: self.worker.stateRun.emit(
            sig)

    def onPromptAccept(self):
        self.__question_accept_callback()

        self.questionBox.hide()

    def onPromptReject(self):
        self.__question_reject_callback()

        self.questionBox.hide()

    def setMessage(self, state, stage, text):
        self.stateDetails[state].setText(text)
        if stage == self.worker.START:
            pass
        elif stage == self.worker.DONE:
            icon = QtGui.QIcon.fromTheme("dialog-ok-apply")
            pixmap = icon.pixmap(16, 16)
            self.stateIcons[state].setPixmap(pixmap)
        elif stage < self.worker.START:
            icon = QtGui.QIcon.fromTheme("dialog-close")
            pixmap = icon.pixmap(16, 16)
            self.stateIcons[state].setPixmap(pixmap)

    def setProgress(self, state, progress):
        self.progress.setValue((state - 1 + (progress / self.worker.DONE)) *
                               100.0 / self.worker.STATE_DONE)
Exemplo n.º 4
0
class DatabaseSetupWizardPage(BaseWizardPage):
    def __init__(self, parent=None):
        super(DatabaseSetupWizardPage, self).__init__(parent)
        
        dsw = DatabaseSetupWorker
        
        statesLayout = QtGui.QGridLayout()
        
        self.stateIcons = {}
        self.stateLabels = {}
        self.stateDetails = {}
        
        labels = {dsw.STATE_INIT: "Initialize database",
                  dsw.STATE_LOAD: "Load database",
                  dsw.STATE_CREATE: "Create models",
                  dsw.STATE_TEST: "Insert test data",
                  dsw.STATE_DONE: "Finished setting up database"
                  }
        
        for i, state in enumerate((dsw.STATE_INIT, dsw.STATE_LOAD, dsw.STATE_CREATE, dsw.STATE_TEST, dsw.STATE_DONE)):
            self.stateIcons[state] = icon = QtGui.QLabel(self)
            self.stateLabels[state] = label = QtGui.QLabel(labels[state], self)
            self.stateDetails[state] = details = QtGui.QLabel(self)
            self.stateDetails[state].setWordWrap(True)
            
            statesLayout.addWidget(icon, i, 0)
            statesLayout.addWidget(label, i, 1)
            statesLayout.addWidget(details, i, 2)
        
        statesLayout.setColumnStretch(0, 0)
        statesLayout.setColumnStretch(1, 0)
        statesLayout.setColumnStretch(2, 1)
        
        self.progress = QtGui.QProgressBar(self)
        self.progress.setRange(0, 100)
        self.progress.setTextVisible(True)
        
        self.questionBox = QtGui.QGroupBox(self)
        self.questionBox.hide()
        
        self.prompt = QtGui.QLabel(self.questionBox)
        
        self.buttonBox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Yes | 
                                                QtGui.QDialogButtonBox.No,
                                                QtCore.Qt.Horizontal,
                                                self.questionBox)
        
        self.buttonBox.accepted.connect(self.onPromptAccept)
        self.buttonBox.rejected.connect(self.onPromptReject)
        
        questionLayout = QtGui.QVBoxLayout()
        questionLayout.addWidget(self.prompt)
        questionLayout.addWidget(self.buttonBox)
        self.questionBox.setLayout(questionLayout)
        
        layout = QtGui.QVBoxLayout()
        layout.setSpacing(10)
        
        layout.addLayout(statesLayout)
        layout.addWidget(self.progress)
        layout.addStretch(1)
        layout.addWidget(self.questionBox)
        
        self.setLayout(layout)
        
        self.worker = None
        self.__error_occured = False
    
    def initializePage(self):
        # self.field('database_configure') does not matter
        self.worker = DatabaseSetupWorker()
        self.worker.start()
        
        self.worker.stateProgress.connect(self.onStateProgressSignal)
        self.worker.stateError.connect(self.onStateErrorSignal)
        
        self.worker.stateRun.emit(self.worker.STATE_INIT)
    
    def cleanupPage(self):
        self.worker.quit()
        self.worker.wait()
        # TODO: error when opening connection in a thread and closing it in another thread.
        # TODO: error when pressing back and coming back (looks like database tables are not cleared)
        
        for iconLbl in self.stateIcons.itervalues():
            iconLbl.setPixmap(None)
        
        for detailsLbl in self.stateDetails.itervalues():
            detailsLbl.setText("")
    
    def validatePage(self):
        if self.__error_occured:
            return False
        
        if self.worker.isRunning():
            return False
        
        return True
    
    def isComplete(self):
        if self.worker.isRunning():
            return False
        else:
            return super(DatabaseSetupWizardPage, self).isComplete()
    
    def onStateErrorSignal(self, state, exception):
        
        if state == self.worker.STATE_INIT:
            message = "Could not connect to database!"
        elif state == self.worker.STATE_LOAD:
            message = "Error loading models!"
        elif state == self.worker.STATE_CREATE:
            message = "Error creating tables!"
        elif state == self.worker.STATE_TEST:
            message = "Error inserting test values!"
        else:
            message = "An error occured!"
        
        self.__error_occured = True
        
        self.setMessage(state, -1, "<b>{message}</b><br />{exception}".format(
                    message=message,
                    exception=str(exception)
        ))
        self.setProgress(self.worker.STATE_DONE, self.worker.DONE)
        self.worker.quit()
        
        self.completeChanged.emit()
    
    def onStateProgressSignal(self, state, progress):
        self.setProgress(state, progress)
        
        if state == self.worker.STATE_INIT:
            # First, connect to the database
            if progress == self.worker.START:
                self.setMessage(state, progress, "Connecting to database...")
            elif progress == self.worker.DONE:
                self.setMessage(state, progress, "Connected to database.")
                self.worker.stateRun.emit(self.worker.STATE_LOAD)
        elif state == self.worker.STATE_LOAD:
            # Second, load the models
            if progress == self.worker.START:
                self.setMessage(state, progress, "Loading models...")
            elif progress == self.worker.DONE:
                self.setMessage(state, progress, "Models loaded.")
                self.setPrompt(question="""Reconfigure Database?
This will drop the tables in the database you chose and recreate it.""",
                               onAccept=self.worker.STATE_CREATE,
                               onReject=self.worker.STATE_DONE
                               )
        elif state == self.worker.STATE_CREATE:
            # Third, create the tables
            if progress == self.worker.START:
                self.setMessage(state, progress, "Creating tables...")
            elif progress == self.worker.DONE:
                self.setMessage(state, progress, "Tables created.")
                self.setPrompt(question="""Insert test values?""",
                               onAccept=self.worker.STATE_TEST,
                               onReject=self.worker.STATE_DONE
                               )
        elif state == self.worker.STATE_TEST:
            # Fourth, insert the test values
            if progress == self.worker.START:
                self.setMessage(state, progress, "Inserting test values...")
            elif progress == self.worker.DONE:
                self.setMessage(state, progress, "Inserted test values.")
                self.worker.stateRun.emit(self.worker.STATE_DONE)
        elif state == self.worker.STATE_DONE and progress == self.worker.DONE:
            # Fifth, we are done
            self.setMessage(state, progress, "Done.")
        
        self.completeChanged.emit()
    
    def setPrompt(self, question, onAccept, onReject):
        self.questionBox.show()
        self.prompt.setText(question)
        
        self.__question_accept_callback = lambda sig=onAccept: self.worker.stateRun.emit(sig)
        self.__question_reject_callback = lambda sig=onReject: self.worker.stateRun.emit(sig) 
    
    def onPromptAccept(self):
        self.__question_accept_callback()
        
        self.questionBox.hide()
    
    def onPromptReject(self):
        self.__question_reject_callback()
        
        self.questionBox.hide()
    
    def setMessage(self, state, stage, text):
        self.stateDetails[state].setText(text)
        if stage == self.worker.START:
            pass
        elif stage == self.worker.DONE:
            icon = QtGui.QIcon.fromTheme("dialog-ok-apply")
            pixmap = icon.pixmap(16, 16)
            self.stateIcons[state].setPixmap(pixmap)
        elif stage < self.worker.START:
            icon = QtGui.QIcon.fromTheme("dialog-close")
            pixmap = icon.pixmap(16, 16)
            self.stateIcons[state].setPixmap(pixmap)
    
    def setProgress(self, state, progress):
        self.progress.setValue((state - 1 + (progress/self.worker.DONE)) * 100.0 / self.worker.STATE_DONE)