class HookandlineHookMatrix: def __init__(self): qInstallMessageHandler(FramUtil.qt_msg_handler) self.rpc = RpcClient() appGuid = 'F3FF80BA-BA05-4277-8063-82A6DB9245A3' self.app = QtSingleApplication(appGuid, sys.argv) self.app.setWindowIcon(QtGui.QIcon("resources/ico/hooklogger.ico")) splash = HookMatrixSplash() splash.show() if self.app.isRunning(): sys.exit(0) self.engine = QQmlApplicationEngine() self.context = self.engine.rootContext() self.context.setContextProperty('rpc', self.rpc) self.db = HookAndLineHookMatrixDB() self.context.setContextProperty('db', self.db) self.state_machine = StateMachine(app=self, db=self.db) self.context.setContextProperty('stateMachine', self.state_machine) self.serial_port_manager = SerialPortManager(app=self, db=self.db) self.context.setContextProperty('serialPortManager', self.serial_port_manager) self.label_printer = LabelPrinter(app=self, db=self.db) self.context.setContextProperty('labelPrinter', self.label_printer) self.sites = Sites(app=self, db=self.db) self.context.setContextProperty('sites', self.sites) self.drops = Drops(app=self, db=self.db) self.context.setContextProperty('drops', self.drops) self.hooks = Hooks(app=self, db=self.db) self.context.setContextProperty('hooks', self.hooks) self.gear_performance = GearPerformance(app=self, db=self.db) self.context.setContextProperty('gearPerformance', self.gear_performance) self.notes = Notes(app=self, db=self.db) self.context.setContextProperty("notes", self.notes) self.settings = Settings(app=self, db=self.db) self.context.setContextProperty("settings", self.settings) self.engine.load(QUrl('qrc:/qml/hookandline_hookmatrix/main_hookmatrix.qml')) splash.close() self.engine.quit.connect(self.app.quit) sys.exit(self.app.exec_())
class HookandlineFpc(QObject): def __init__(self): super().__init__() qInstallMessageHandler(FramUtil.qt_msg_handler) # self.app = QApplication(sys.argv) appGuid = 'F3FF80BA-BA05-4277-8063-82A6DB9245A2' self.app = QtSingleApplication(appGuid, sys.argv) self.app.setWindowIcon(QtGui.QIcon("resources/ico/hooklogger_v2.ico")) splash = FpcSplash() splash.show() if self.app.isRunning(): sys.exit(0) # qmlRegisterType(FramTreeItem, 'FramTreeItem', 1, 0, 'FramTreeItem') self.engine = QQmlApplicationEngine() qmlRegisterType(TextFieldDoubleValidator, "FRAM", 1, 0, "TextFieldDoubleValidator") self.context = self.engine.rootContext() fl = FramLog() self.context.setContextProperty('framLog', fl) db = HookandlineFpcDB() self.context.setContextProperty('db', db) # self.textfield_double_validator = TextFieldDoubleValidator() # self.context.setContextProperty('TextFieldDoubleValidator', self.textfield_double_validator) # PyQt5 Threading approach self._rpc_thread = QThread() self._rpc_worker = RpcServer() self._rpc_worker.moveToThread(self._rpc_thread) self._rpc_worker.speciesChanged.connect(self._species_changed) self._rpc_thread.started.connect(self._rpc_worker.run) self._rpc_thread.start() logging.info(f"\tRPC thread and worker established") # Technique that works - traditional python threading, although the queue is not needed anymore # self._queue = Queue() # self._rpc_server = threading.Thread(target=RpcServer, kwargs={'queue': self._queue}) # self._rpc_server.setDaemon(True) # self._rpc_server.start() self.fpc_main = FpcMain(app=self) self.settings = Settings(db=db) self.serial_port_manager = SerialPortManager(app=self, db=db) self.serial_port_simulator = SerialPortSimulator(app=self, db=db) self.data_converter = DataConverter(app=self, db=db) self.sensor_data_feeds = SensorDataFeeds(app=self, db=db) self.species_review = SpeciesReview(app=self, db=db) self.end_of_site_validation = EndOfSiteValidation(app=self, db=db) logging.info(f"\tComponent classes all initialized") self.context.setContextProperty('fpcMain', self.fpc_main) self.context.setContextProperty('settings', self.settings) self.context.setContextProperty('serialPortManager', self.serial_port_manager) self.context.setContextProperty('serialPortSimulator', self.serial_port_simulator) self.context.setContextProperty('dataConverter', self.data_converter) self.context.setContextProperty('sensorDataFeeds', self.sensor_data_feeds) self.context.setContextProperty('speciesReview', self.species_review) self.context.setContextProperty('endOfSiteValidation', self.end_of_site_validation) logging.info(f"\tContext Properties all set") # self.widget = self.app.instance() # self.widget.setAttribute(QtCore.Qt.WA_OpaquePaintEvent) # self.widget.setAttribute(QtCore.Qt.WA_NoSystemBackground) # self.view = QQuickView() # self.view.setSource(QUrl('qrc:/qml/hookandline/main_fpc.qml')) # self.view.show() try: self.engine.load(QUrl('qrc:/qml/hookandline/main_fpc.qml')) splash.close() self.win = self.engine.rootObjects()[0] self.msg_box = self.win.findChild(QObject, "dlgUnhandledException") logging.info(f"\tmain_fpc.qml loaded") self.engine.quit.connect(self.app.quit) sys.exit(self.app.exec_()) except Exception as ex: logging.error(f"error loading the application: {ex}") def _species_changed(self, station, set_id, adh): """ Method called when a species is changed by the HookMatrix or the CutterStation and we need to dynamically update the SpeciesReviewDialog :param station: HookMatrix or CutterStation :param set: The set number :param adh: 3-character value, i.e. the ADH could be A21, A34 :return: """ self.species_review.species_changed(station=station, set_id=set_id, adh=adh) def exception_caught(self, except_type, except_value, traceback_obj): tbinfofile = io.StringIO() traceback.print_tb(traceback_obj, None, tbinfofile) tbinfofile.seek(0) tbinfo = tbinfofile.read() log_filename = "survey_backdeck_debug.log" log_filepath = os.path.join(os.getcwd(), log_filename) msg = f"Exception occurred at {arrow.now().format('MM/DD/YYYY HH:mm:ss')}\n\n Please check log file at:\n{log_filepath}\n\n{except_type}: {except_value}\n\n{tbinfo}" logging.info(f"{msg}") self.msg_box.show(msg) logging.info( f"Survey Backdeck is quitting at {arrow.now().format('MM/DD/YYYY HH:mm:ss')}" )
class Backdeck: def __init__(self): qInstallMessageHandler(FramUtil.qt_msg_handler) self.rpc = RpcClient() # self.app = QApplication(sys.argv) appGuid = 'F3FF80BA-BA05-4277-8063-82A6DB9245A5' self.app = QtSingleApplication(appGuid, sys.argv) self.app.setWindowIcon(QtGui.QIcon("resources/ico/cutter.ico")) # splash screen to launch before loading, close later splash = BackdeckSplash() splash.show() if self.app.isRunning(): sys.exit(0) self.app.unhandledExceptionCaught.connect(self.exception_caught) qmlRegisterType(SortFilterProxyModel, "SortFilterProxyModel", 0, 1, "SortFilterProxyModel") self.engine = QQmlApplicationEngine() self.context = self.engine.rootContext() # qmlRegisterType(FramTreeItem, 'FramTreeItem', 1, 0, 'FramTreeItem') # Set Contexts # wfs = WindowFrameSize() # self.context.setContextProperty('wfs', wfs) fl = FramLog() self.context.setContextProperty('framLog', fl) db = HookAndLineHookCutterDB() self.context.setContextProperty('db', db) self.state_machine = StateMachine(app=self, db=db) self.sound_player = SoundPlayer(app=self, db=db) self.serial_port_manager = SerialPortManager(app=self, db=db) self.sites = Sites(app=self, db=db) self.fish_sampling = FishSampling(app=self, db=db) self.label_printer = LabelPrinter(app=self, db=db) self.notes = Notes(app=self, db=db) # self.qaqc = QAQC(app=self, db=db) self.settings = Settings(app=self, db=db) self.context.setContextProperty("soundPlayer", self.sound_player) self.context.setContextProperty("stateMachine", self.state_machine) self.context.setContextProperty("sites", self.sites) self.context.setContextProperty("fishSampling", self.fish_sampling) self.context.setContextProperty("serialPortManager", self.serial_port_manager) self.context.setContextProperty("labelPrinter", self.label_printer) self.context.setContextProperty("notes", self.notes) # self.context.setContextProperty("qaqc", self.qaqc) self.context.setContextProperty("settings", self.settings) # self.setAttribute(QtCore.Qt.WA_DeleteOnClose) try: self.engine.load( QUrl('qrc:/qml/survey_backdeck/main_backdeck.qml')) splash.close() self.win = self.engine.rootObjects()[0] self.msg_box = self.win.findChild(QObject, "dlgUnhandledException") self.engine.quit.connect(self.app.quit) sys.exit(self.app.exec_()) except Exception as ex: logging.error(f"bad stuff happening: {ex}") def exception_caught(self, except_type, except_value, traceback_obj): tbinfofile = io.StringIO() traceback.print_tb(traceback_obj, None, tbinfofile) tbinfofile.seek(0) tbinfo = tbinfofile.read() log_filename = "survey_backdeck_debug.log" log_filepath = os.path.join(os.getcwd(), log_filename) msg = f"Exception occurred at {arrow.now().format('MM/DD/YYYY HH:mm:ss')}\n\n Please check log file at:\n{log_filepath}\n\n{except_type}: {except_value}\n\n{tbinfo}" logging.info(f"{msg}") self.msg_box.show(msg) logging.info( f"Survey Backdeck is quitting at {arrow.now().format('MM/DD/YYYY HH:mm:ss')}" )