def __init__(self):


		app = QtWidgets.QApplication(sys.argv)
		MainWindow = QtWidgets.QMainWindow()
		ui = Ui_MainWindow()
		ui.setupUi(MainWindow)
		MainWindow.show()
		
		ui.btnWebCam.clicked.connect(self.webCamRecognition)
		ui.btnCanvas.clicked.connect(self.canvasRecognition)
		ui.btnImage.clicked.connect(self.imageRecognition)

		sys.exit(app.exec_())
示例#2
0
class MainWindow(QMainWindow):
    DB_PATH = "db"
    FILE_NAME_PATTERN = "yyyy-MM-dd"
    FILE_FORMAT = "diary"

    def __init__(self):
        super().__init__()
        self.current_document_name = ""
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.open_document(self.file_name_by_date(QDate.currentDate()))


    @pyqtSlot(QDate)
    def on_calendarView_clicked(self, date):
        self.open_document(self.file_name_by_date(date))

    def open_document(self, name):
        self.close_document()
        self.ui.documentView.clear()
        self.current_document_name = name
        if not QFile.exists(name):
            return
        reader = DocumentReader(name)
        reader.read(self.ui.documentView.document())
        if reader.is_error:
            QMessageBox.warning(self, "Ошибка",
                                "При попытке сохранить файл дневника произошла ошибка: " + reader.errorString)

    def close_document(self):
        qDebug("MainWindow.close_document()")
        qDebug("self.current_document_name is \"" + self.current_document_name + "\"")
        if len(self.current_document_name) == 0:
            qDebug("file not opened. finished")
            return
        doc = self.ui.documentView.document()
        if doc.isEmpty():
            qDebug("document is empty. finished")
            self.current_document_name = ""
            return
        qDebug("writing document")
        writer = DocumentWriter(self.current_document_name)
        writer.write(doc)
        if writer.is_error:
            QMessageBox.warning(self, "Ошибка",
                                "При попытке сохранить файл дневника произошла ошибка: " + writer.errorString)

    def file_name_by_date(self, date):
        return self.DB_PATH + "/" + date.toString(self.FILE_NAME_PATTERN) + "." + self.FILE_FORMAT
示例#3
0
    def __init__(self):
        QMainWindow.__init__(self)

        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        self.scene = NetworkViewer()
        self.ui.view.setScene(self.scene)
        self.ui.view.setRenderHint(QPainter.Antialiasing)
        self.test_data = None
        self.learning_data = None

        self.creator = None
示例#4
0
 def __init__(self):
     super().__init__()
     self.current_document_name = ""
     self.ui = Ui_MainWindow()
     self.ui.setupUi(self)
     self.open_document(self.file_name_by_date(QDate.currentDate()))
示例#5
0
class MainWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)

        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        self.scene = NetworkViewer()
        self.ui.view.setScene(self.scene)
        self.ui.view.setRenderHint(QPainter.Antialiasing)
        self.test_data = None
        self.learning_data = None

        self.creator = None

    def _show_network(self):
        self.scene.clear()
        self.scene.show_network(self.network)
        self.ui.view.fitInView(self.scene.sceneRect(), Qt.KeepAspectRatio)

    def _activate_actions(self):
        self.ui.launchAction.setEnabled(True)
        self.ui.editNetworkAction.setEnabled(True)
        self.ui.saveNetworkAction.setEnabled(True)
        self.ui.menuLearning.setEnabled(True)

    @pyqtSlot()
    def on_newNetworkAction_triggered(self):
        self.creator = NetworkCreatorDialog()
        result = self.creator.exec_()
        if result == QDialog.Accepted:
            self.network = self.creator.create_network()
            self._show_network()
            self._activate_actions()

    @pyqtSlot()
    def on_editNetworkAction_triggered(self):
        creator = NetworkCreatorDialog(NetworkModel.from_network(self.network))
        result = creator.exec_()
        if result == QDialog.Accepted:
            self.network = creator.create_network()
            self._show_network()

    @pyqtSlot()
    def on_launchAction_triggered(self):
        creator = SimulationLauncherDialog(self.network, self.test_data)
        creator.exec_()
        self.test_data = creator.get_model()

    @pyqtSlot()
    def on_openNetworkAction_triggered(self):
        filePath = QFileDialog().getOpenFileName(None, "Select input data file")
        try:
            with open(filePath, "r") as file:
                self.network = yaml.load(file)
                self._show_network()
                self._activate_actions()
        except Exception as e:
            print e

    @pyqtSlot()
    def on_saveNetworkAction_triggered(self):
        filePath = QFileDialog().getSaveFileName(None, "Select output file")
        try:
            with open(filePath, "w") as file:
                yaml.dump(self.network, file)
        except Exception as e:
            print e

    @pyqtSlot()
    def on_learnAction_triggered(self):
        launcher = LearningLauncher.dialog(self.network, self.learning_data)
        result = launcher.exec_()
        if result == QDialog.Accepted:
            self._show_network()
            self.learning_data = launcher.get_model()

    def resizeEvent(self, QResizeEvent):
        self.ui.view.fitInView(self.scene.sceneRect(), Qt.KeepAspectRatio)

    def show(self):
        QMainWindow.show(self)
        self.resizeEvent(None)