예제 #1
0
    def __init__(self, log_queue: Queue):
        super().__init__(QtGui.QIcon(MiscUtils.get_app_icon_path()))
        self.log_queue = log_queue
        self.preferences_window: PreferencesWindow = None
        self.log_window: LogWindow = None
        self.indexing_stop_event: Event = None
        self.observer = None
        self.indexDB = IndexDB()
        self.threadpool: QtCore.QThreadPool = QtCore.QThreadPool()
        self.__logger.debug("QT multithreading with thread pool size: %s",
                            self.threadpool.maxThreadCount())

        self.setToolTip("Batch Media Compressor")
        self.activated.connect(self.trayIcon_activated)

        tray_menu = QtWidgets.QMenu('Main Menu')
        self.startIndexAction = tray_menu.addAction(
            'Start Processing', self.startIndexAction_triggered)
        self.stopIndexAction = tray_menu.addAction(
            'Stop Processing', self.stopIndexAction_triggered)
        self.stopIndexAction.setEnabled(False)
        tray_menu.addSeparator()
        self.clearIndexAction = tray_menu.addAction(
            'Clear Indexed Files', self.clearIndexAction_triggered)
        self.clearOutputDirsAction = tray_menu.addAction(
            'Clear Ouput Directories', self.clearOutputDirsAction_triggered)
        tray_menu.addSeparator()
        self.editPrefAction = tray_menu.addAction(
            'Edit Preferences', self.editPreferencesAction_triggered)
        self.viewLogsAction = tray_menu.addAction(
            'View Logs', self.viewLogsAction_triggered)
        tray_menu.addSeparator()
        self.updateCheckAction = tray_menu.addAction(
            'Check for Updates', self.updateCheckAction_triggered)
        self.coffeeAction = tray_menu.addAction('Buy me a Coffee',
                                                self.coffeeAction_triggered)
        tray_menu.addSeparator()
        tray_menu.addAction('Quit', self.quitMenuAction_triggered)
        self.setContextMenu(tray_menu)

        self.apply_process_changed_setting()
        if self.indexDB.get_settings().auto_update_check:
            self.update_check_worker = QWorker(self.auto_update_check)
            self.threadpool.start(self.update_check_worker)
예제 #2
0
if __name__ == "__main__":
    if MiscUtils.running_in_pyinstaller_bundle():
        freeze_support()

    multiprocessing.set_start_method('spawn')
    QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_ShareOpenGLContexts)
    QtGui.QGuiApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)

    MiscUtils.configure_logging()
    log_queue = Manager().Queue()
    logger_thread = threading.Thread(target=MiscUtils.logger_thread_exec,
                                     args=(log_queue, ))
    logger_thread.start()

    app = QtWidgets.QApplication(sys.argv)
    app.setWindowIcon(QtGui.QIcon(MiscUtils.get_app_icon_path()))
    app.setApplicationDisplayName(
        "Batch Media Compressor")  # TODO test + add org / ver
    app.setQuitOnLastWindowClosed(False)

    try:
        lock = LockFile(MiscUtils.get_lock_file_path())
        tray_icon = TrayIcon(log_queue)
        tray_icon.show()
        return_code = app.exec_()
        tray_icon.cleanup()
        lock.close()
    except LockError:
        error_msg = "Cannot acquire lock on file {}.\n\nAnother instance of the application is probably running.".format(
            MiscUtils.get_lock_file_path())
        logging.fatal(error_msg)