예제 #1
0
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.dobby = DobbyApplication()
        self.session = self.dobby.dobby.Session()
        self.qaStop.setVisible(False)

        # Scenario Models
        self.scenarioModel = ScenarioModel(self.session)
        self.qlvScenarios.setModel(self.scenarioModel)
        self.scenarioCommandModel = ScenarioCommandModel(self.session)
        self.qlvScenarioCommands.setModel(self.scenarioCommandModel)
        self.scenarioActionModel = ScenarioActionModel(self.session)
        self.qlvScenarioActions.setModel(self.scenarioActionModel)

        # Action Model
        self.actionModel = ActionModel(self.session)
        self.qlvActions.setModel(self.actionModel)

        # Scenario Signals
        self.qpbScenarioAdd.clicked.connect(self.addScenario)
        self.qpbScenarioRemove.clicked.connect(self.removeScenario)
        self.qpbScenarioCommandAdd.clicked.connect(self.addScenarioCommand)
        self.qpbScenarioCommandRemove.clicked.connect(
            self.removeScenarioCommand)
        self.qlvScenarios.selectionModel().selectionChanged.connect(
            self.changeScenario)
        self.qlvScenarioActions.doubleClicked.connect(
            self.removeScenarioAction)

        # Action Signals
        self.qpbActionAdd.clicked.connect(self.addAction)
        self.qpbActionRemove.clicked.connect(self.removeAction)
        self.qlvActions.doubleClicked.connect(self.editAction)

        # Dobby Signals
        self.qaStart.triggered.connect(self.startDobby)
        self.qaStop.triggered.connect(self.stopDobby)

        # Config Signals
        self.qaConfigure.triggered.connect(self.configure)

        # Others
        self.qaAbout.triggered.connect(self.about)
예제 #2
0
파일: app.py 프로젝트: Diaoul/Dobby
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.dobby = DobbyApplication()
        self.session = self.dobby.dobby.Session()
        self.qaStop.setVisible(False)

        # Scenario Models
        self.scenarioModel = ScenarioModel(self.session)
        self.qlvScenarios.setModel(self.scenarioModel)
        self.scenarioCommandModel = ScenarioCommandModel(self.session)
        self.qlvScenarioCommands.setModel(self.scenarioCommandModel)
        self.scenarioActionModel = ScenarioActionModel(self.session)
        self.qlvScenarioActions.setModel(self.scenarioActionModel)

        # Action Model
        self.actionModel = ActionModel(self.session)
        self.qlvActions.setModel(self.actionModel)

        # Scenario Signals
        self.qpbScenarioAdd.clicked.connect(self.addScenario)
        self.qpbScenarioRemove.clicked.connect(self.removeScenario)
        self.qpbScenarioCommandAdd.clicked.connect(self.addScenarioCommand)
        self.qpbScenarioCommandRemove.clicked.connect(self.removeScenarioCommand)
        self.qlvScenarios.selectionModel().selectionChanged.connect(self.changeScenario)
        self.qlvScenarioActions.doubleClicked.connect(self.removeScenarioAction)

        # Action Signals
        self.qpbActionAdd.clicked.connect(self.addAction)
        self.qpbActionRemove.clicked.connect(self.removeAction)
        self.qlvActions.doubleClicked.connect(self.editAction)

        # Dobby Signals
        self.qaStart.triggered.connect(self.startDobby)
        self.qaStop.triggered.connect(self.stopDobby)
        
        # Config Signals
        self.qaConfigure.triggered.connect(self.configure)
        
        # Others
        self.qaAbout.triggered.connect(self.about)
예제 #3
0
class MainWindow(QMainWindow, Ui_MainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.dobby = DobbyApplication()
        self.session = self.dobby.dobby.Session()
        self.qaStop.setVisible(False)

        # Scenario Models
        self.scenarioModel = ScenarioModel(self.session)
        self.qlvScenarios.setModel(self.scenarioModel)
        self.scenarioCommandModel = ScenarioCommandModel(self.session)
        self.qlvScenarioCommands.setModel(self.scenarioCommandModel)
        self.scenarioActionModel = ScenarioActionModel(self.session)
        self.qlvScenarioActions.setModel(self.scenarioActionModel)

        # Action Model
        self.actionModel = ActionModel(self.session)
        self.qlvActions.setModel(self.actionModel)

        # Scenario Signals
        self.qpbScenarioAdd.clicked.connect(self.addScenario)
        self.qpbScenarioRemove.clicked.connect(self.removeScenario)
        self.qpbScenarioCommandAdd.clicked.connect(self.addScenarioCommand)
        self.qpbScenarioCommandRemove.clicked.connect(
            self.removeScenarioCommand)
        self.qlvScenarios.selectionModel().selectionChanged.connect(
            self.changeScenario)
        self.qlvScenarioActions.doubleClicked.connect(
            self.removeScenarioAction)

        # Action Signals
        self.qpbActionAdd.clicked.connect(self.addAction)
        self.qpbActionRemove.clicked.connect(self.removeAction)
        self.qlvActions.doubleClicked.connect(self.editAction)

        # Dobby Signals
        self.qaStart.triggered.connect(self.startDobby)
        self.qaStop.triggered.connect(self.stopDobby)

        # Config Signals
        self.qaConfigure.triggered.connect(self.configure)

        # Others
        self.qaAbout.triggered.connect(self.about)

    @Slot()
    def about(self):
        QMessageBox.about(
            self, 'About Dobby', 'Dobby v' + dobby.infos.__version__ + '\n\n' +
            'Dobby is free! (GPLv3 licensed software)')

    @Slot(QModelIndex, QModelIndex)
    def changeScenario(self, selected, deselected):
        self.scenarioCommandModel.setCommands(
            self.scenarioModel.scenarios[selected.indexes()[0].row()].commands)
        self.scenarioActionModel.setActions(
            self.scenarioModel.scenarios[selected.indexes()[0].row()].actions)

    @Slot()
    def addScenario(self):
        text = self.qleScenario.text()
        if not text:
            return
        self.scenarioModel.addScenario(text)
        self.qleScenario.clear()

    @Slot()
    def removeScenario(self):
        self.scenarioModel.removeScenarios(
            self.qlvScenarios.currentIndex().row())

    @Slot()
    def addScenarioCommand(self):
        text = self.qleScenarioCommand.text()
        if not text:
            return
        self.scenarioCommandModel.addNewCommand(text)
        self.qleScenarioCommand.clear()

    @Slot()
    def removeScenarioCommand(self):
        self.scenarioCommandModel.removeCommands(
            self.qlvScenarioCommands.currentIndex().row())

    @Slot()
    def removeScenarioAction(self):
        self.scenarioActionModel.removeActions(
            self.qlvScenarioActions.currentIndex().row())

    @Slot()
    def addAction(self):
        if self.qcbActionType.currentText() == 'Weather':
            dialog = ActionWeatherForm(self)
        elif self.qcbActionType.currentText() == 'Datetime':
            dialog = ActionDatetimeForm(self)
        elif self.qcbActionType.currentText() == 'Feed':
            dialog = ActionFeedForm(self)
        result = dialog.exec_()
        if result != QDialog.Accepted:
            return
        self.actionModel.appendAction(dialog.getAction())

    @Slot()
    def removeAction(self):
        self.actionModel.removeActions(self.qlvActions.currentIndex().row())

    @Slot(QModelIndex)
    def editAction(self, index):
        action = self.actionModel.actions[index.row()]
        if isinstance(action, Weather):
            dialog = ActionWeatherForm(self)
        elif isinstance(action, Datetime):
            dialog = ActionDatetimeForm(self)
        elif isinstance(action, Feed):
            dialog = ActionFeedForm(self)
        dialog.fromAction(self.actionModel.actions[index.row()])
        result = dialog.exec_()
        if result != QDialog.Accepted:
            return
        self.session.add(dialog.getAction())
        self.session.commit()

    @Slot()
    def configure(self):
        dialog = ConfigForm(self.dobby.dobby.config, self)
        result = dialog.exec_()
        if result != QDialog.Accepted:
            return

    def startDobby(self):
        try:
            self.dobby.start()
        #TODO: Check for the recognizer in dobby before 'run'
        except pyjulius.exceptions.ConnectionError:
            QMessageBox.question(self, 'Error',
                                 'Did you start the recognizer?',
                                 QMessageBox.Ok)
        except:
            raise
        self.qaStart.setVisible(False)
        self.qaStop.setVisible(True)

    def stopDobby(self):
        self.dobby.stop()
        self.qaStop.setVisible(False)
        self.qaStart.setVisible(True)

    def closeEvent(self, event):
        #FIXME
        self.hide()
        self.quit()
        event.accept()
        return
        reply = QMessageBox.question(self, 'Message', 'Are you sure to quit?',
                                     QMessageBox.Yes | QMessageBox.No,
                                     QMessageBox.No)
        if reply == QMessageBox.Yes:
            self.hide()
            self.quit()
            event.accept()
        else:
            event.ignore()

    def quit(self):
        self.stopDobby()
        qApp.quit
예제 #4
0
파일: app.py 프로젝트: Diaoul/Dobby
class MainWindow(QMainWindow, Ui_MainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.dobby = DobbyApplication()
        self.session = self.dobby.dobby.Session()
        self.qaStop.setVisible(False)

        # Scenario Models
        self.scenarioModel = ScenarioModel(self.session)
        self.qlvScenarios.setModel(self.scenarioModel)
        self.scenarioCommandModel = ScenarioCommandModel(self.session)
        self.qlvScenarioCommands.setModel(self.scenarioCommandModel)
        self.scenarioActionModel = ScenarioActionModel(self.session)
        self.qlvScenarioActions.setModel(self.scenarioActionModel)

        # Action Model
        self.actionModel = ActionModel(self.session)
        self.qlvActions.setModel(self.actionModel)

        # Scenario Signals
        self.qpbScenarioAdd.clicked.connect(self.addScenario)
        self.qpbScenarioRemove.clicked.connect(self.removeScenario)
        self.qpbScenarioCommandAdd.clicked.connect(self.addScenarioCommand)
        self.qpbScenarioCommandRemove.clicked.connect(self.removeScenarioCommand)
        self.qlvScenarios.selectionModel().selectionChanged.connect(self.changeScenario)
        self.qlvScenarioActions.doubleClicked.connect(self.removeScenarioAction)

        # Action Signals
        self.qpbActionAdd.clicked.connect(self.addAction)
        self.qpbActionRemove.clicked.connect(self.removeAction)
        self.qlvActions.doubleClicked.connect(self.editAction)

        # Dobby Signals
        self.qaStart.triggered.connect(self.startDobby)
        self.qaStop.triggered.connect(self.stopDobby)
        
        # Config Signals
        self.qaConfigure.triggered.connect(self.configure)
        
        # Others
        self.qaAbout.triggered.connect(self.about)

    @Slot()
    def about(self):
        QMessageBox.about(self, 'About Dobby', 'Dobby v' + dobby.infos.__version__ + '\n\n' + 'Dobby is free! (GPLv3 licensed software)')

    @Slot(QModelIndex, QModelIndex)
    def changeScenario(self, selected, deselected):
        self.scenarioCommandModel.setCommands(self.scenarioModel.scenarios[selected.indexes()[0].row()].commands)
        self.scenarioActionModel.setActions(self.scenarioModel.scenarios[selected.indexes()[0].row()].actions)

    @Slot()
    def addScenario(self):
        text = self.qleScenario.text()
        if not text:
            return 
        self.scenarioModel.addScenario(text)
        self.qleScenario.clear()

    @Slot()
    def removeScenario(self):
        self.scenarioModel.removeScenarios(self.qlvScenarios.currentIndex().row())

    @Slot()
    def addScenarioCommand(self):
        text = self.qleScenarioCommand.text()
        if not text:
            return
        self.scenarioCommandModel.addNewCommand(text)
        self.qleScenarioCommand.clear()

    @Slot()
    def removeScenarioCommand(self):
        self.scenarioCommandModel.removeCommands(self.qlvScenarioCommands.currentIndex().row())

    @Slot()
    def removeScenarioAction(self):
        self.scenarioActionModel.removeActions(self.qlvScenarioActions.currentIndex().row())

    @Slot()
    def addAction(self):
        if self.qcbActionType.currentText() == 'Weather':
            dialog = ActionWeatherForm(self)
        elif self.qcbActionType.currentText() == 'Datetime':
            dialog = ActionDatetimeForm(self)
        elif self.qcbActionType.currentText() == 'Feed':
            dialog = ActionFeedForm(self)
        result = dialog.exec_()
        if result != QDialog.Accepted:
            return
        self.actionModel.appendAction(dialog.getAction())

    @Slot()
    def removeAction(self):
        self.actionModel.removeActions(self.qlvActions.currentIndex().row())

    @Slot(QModelIndex)
    def editAction(self, index):
        action = self.actionModel.actions[index.row()]
        if isinstance(action, Weather):
            dialog = ActionWeatherForm(self)
        elif isinstance(action, Datetime):
            dialog = ActionDatetimeForm(self)
        elif isinstance(action, Feed):
            dialog = ActionFeedForm(self)
        dialog.fromAction(self.actionModel.actions[index.row()])
        result = dialog.exec_()
        if result != QDialog.Accepted:
            return
        self.session.add(dialog.getAction())
        self.session.commit()

    @Slot()
    def configure(self):
        dialog = ConfigForm(self.dobby.dobby.config, self)
        result = dialog.exec_()
        if result != QDialog.Accepted:
            return

    def startDobby(self):
        try:
            self.dobby.start()
        #TODO: Check for the recognizer in dobby before 'run'
        except pyjulius.exceptions.ConnectionError:
            QMessageBox.question(self, 'Error', 'Did you start the recognizer?', QMessageBox.Ok)
        except:
            raise
        self.qaStart.setVisible(False)
        self.qaStop.setVisible(True)
 
    def stopDobby(self):
        self.dobby.stop()
        self.qaStop.setVisible(False)
        self.qaStart.setVisible(True)

    def closeEvent(self, event):
        #FIXME
        self.hide()
        self.quit()
        event.accept()
        return
        reply = QMessageBox.question(self, 'Message', 'Are you sure to quit?',
                                           QMessageBox.Yes | QMessageBox.No,
                                           QMessageBox.No)
        if reply == QMessageBox.Yes:
            self.hide()
            self.quit()
            event.accept()
        else:
            event.ignore()

    def quit(self):
        self.stopDobby()
        qApp.quit