Esempio n. 1
0
    def run(params: list) -> int:
        """
        Starts the application.
        :return: Error code. If no error occurred returns 0.
        """
        for item in params:
            if str(item).lower() == "--verbose":
                Config.set_executed_type(ExecutedType.Verbose)
                break

        result = -1
        try:
            exec_real_path = os.path.realpath(params[0])
            exec_dir = os.path.dirname(exec_real_path)
            Config.set_root_dir(exec_dir)

            app = QApplication(params)

            Tools.check_paths()

            window = MainWindow()
            window.show()

            result = app.exec_()
        except Exception as ex:  # wildcard for an app crash
            Tools.write_log(ex)
            result = -2
        finally:
            Tools.write_verbose("Application error code is %s" % result)

        return result
Esempio n. 2
0
    def exec(self, query_string: str) -> QSqlQuery:
        """
        Executes query.
        :param query_string: Query to execute.
        :return: Executed query.
        """
        query = self.__get_query()
        Tools.write_verbose(query_string)
        query.exec(query_string)
        Tools.write_log(query.lastError().text())

        return query
Esempio n. 3
0
    def __init_db(self):
        self.__db = QSqlDatabase.addDatabase(Config.DB_TYPE)
        self.db.setDatabaseName(self.__db_path)

        if not self.db.isValid():
            Tools.write_log(self.db.lastError().text())
        if self.db.isOpenError():
            Tools.write_log(self.db.lastError().text())

        self.db.open()
        tables = self.db.tables()

        if not tables:
            self.__create_db()
Esempio n. 4
0
 def __create_db(self):
     Tools.write_log("Creating tables...")
     self.exec(Resources.CREATE_TABLE_Event)
     self.exec(Resources.CREATE_TABLE_ReminderEvent)
     Tools.write_log("Done.")