示例#1
0
import logging

# third party imports
from PySide import QtGui, QtCore

# local imports
from main_window import MainWindow

app = QtGui.QApplication([])

# Set up QSettings
app.setOrganizationName("Scott J Maddox")
app.setApplicationName("Plot Liberator")
settings = QtCore.QSettings()

# Set up logging
logging_level = settings.value("logging/level", logging.DEBUG)
logging.basicConfig(level=logging_level)

# Create main window
w = MainWindow()
w.show()
w.activateWindow()
w.raise_()

## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()
示例#2
0
class Tray(QtWidgets.QWidget):
    trigger = QtCore.pyqtSignal()

    def __init__(self, app, app_config, fallback):
        super().__init__()
        self.app = app
        self.config = app_config
        self.fallback = fallback
        self.canvas_window = None
        self.main_window = None
        self.onclick_overlay = OnclickOverlay(self)

        SignalWakeupHandler(self.app, self)

        signal.signal(signal.SIGCONT,
                      lambda x, _: self.init_capture_check(False, 0))

        self.chz_ico = QtGui.QIcon(
            os.path.join(sys.path[0], 'img', 'ico_colored.png'))
        _set_ico = self.config.parse['config']['icon']
        self.chz_ico_tray = QtGui.QIcon(
            os.path.join(sys.path[0], 'img', f'ico_{_set_ico}.png'))
        self.img_toolkit = ImageToolkit(self.app, self.config)

        self.last_out = ''
        self.last_url = ''

        self.setGeometry(0, 0, 0, 0)
        self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint
                            | QtCore.Qt.FramelessWindowHint
                            | QtCore.Qt.X11BypassWindowManagerHint)
        self.trigger.connect(self.init_capture)
        self.init_tray()
        self.init_capture()
        # self.init_screen()

    def init_tray(self):
        self.tray_icon = QtWidgets.QSystemTrayIcon(self)
        self.tray_icon.setIcon(self.chz_ico_tray)
        self.app.setApplicationName('Chizuhoru')

        self.tray_icon.activated.connect(self.tray_clicked)
        capture_action = QtWidgets.QAction("Capture", self)
        show_action = QtWidgets.QAction("Show", self)
        quit_action = QtWidgets.QAction("Exit", self)

        capture_action.triggered.connect(self.init_capture_check)
        show_action.triggered.connect(self.init_main_check)
        quit_action.triggered.connect(self.close)

        tray_menu = QtWidgets.QMenu()
        capture_menu = QtWidgets.QMenu("Delay", tray_menu)
        _5_sec = QtWidgets.QAction("5 sec.", capture_menu)
        _5_sec.triggered.connect(lambda _: self.init_capture_check(delay=5))
        _10_sec = QtWidgets.QAction("10 sec.", capture_menu)
        _10_sec.triggered.connect(lambda _: self.init_capture_check(delay=10))
        _15_sec = QtWidgets.QAction("15 sec.", capture_menu)
        _15_sec.triggered.connect(lambda _: self.init_capture_check(delay=15))
        onclick = QtWidgets.QAction("On click", capture_menu)
        onclick.triggered.connect(self.invoke_onclick)
        capture_menu.addAction(_5_sec)
        capture_menu.addAction(_10_sec)
        capture_menu.addAction(_15_sec)
        capture_menu.addAction(onclick)

        tray_menu.addAction(capture_action)
        tray_menu.addMenu(capture_menu)
        tray_menu.addAction(show_action)
        tray_menu.addAction(quit_action)

        self.tray_icon.setContextMenu(tray_menu)
        self.tray_icon.show()

    def closeEvent(self, event):
        exit(0)

    def invoke_onclick(self):
        self.onclick_overlay.show()

    def tray_clicked(self, reason):
        if reason == 3:
            self.init_capture_check(default_delay=False)

    @QtCore.pyqtSlot()
    def init_capture_check(self, default_delay=True, delay=0):
        gc.collect()
        try:
            if self.canvas_window and self.canvas_window.isVisible():
                print("Dialog already exists")
            elif self.canvas_window and self.canvas_window.thread:
                if self.canvas_window.thread.isRunning():
                    pass
            else:
                if delay:
                    sleep(delay)
                elif default_delay:
                    sleep(self.config.parse["config"]["default_delay"])
                self.init_capture()
        except RuntimeError:
            # C++ window destroyed
            if delay:
                sleep(delay)
            elif default_delay:
                sleep(self.config.parse["config"]["default_delay"])
            self.init_capture()

    def init_main_check(self):
        gc.collect()
        if self.main_window and self.main_window.isVisible():
            print("Dialog already exists")
        elif self.main_window and self.main_window.was_hidden:
            self.main_window.show()
        else:
            self.init_screen()

    def init_capture(self):
        try:
            del self.canvas_window
        except AttributeError:
            pass
        self.canvas_window = ScreenWindow(self, self.app, self.config,
                                          self.img_toolkit, self.fallback)
        self.canvas_window.show()
        self.canvas_window.activateWindow()
        self.canvas_window.raise_()

    def init_screen(self):
        try:
            del self.main_window
        except AttributeError:
            pass
        self.main_window = MainWindow(self, self.app, self.config,
                                      self.img_toolkit)
        self.main_window.setWindowIcon(self.chz_ico)
        self.main_window.show()
        self.main_window.activateWindow()
        self.main_window.raise_()
示例#3
0
class Application:
    """
    Taken from https://gist.github.com/hogelog/5338905
    """
    def __init__(self):
        self.app = QSingleApplication("BlobBackup", sys.argv)
        self.app.setQuitOnLastWindowClosed(False)
        self.app.setStyle("Fusion")
        self.window = MainWindow(self)
        self.scheduler = Scheduler(self.app)

        self.show_minimize_message = not Settings.get_param("minimize")

        self.app.start_backup.connect(self.window.go_backup)

        if self.app.isRunning():
            QMessageBox.warning(
                None, "BlobBackup already running",
                "An instance of BlobBackup is already running. Check your status bar."
            )
            sys.exit()

        menu = QMenu()
        window_action = menu.addAction("BlobBackup")
        window_action.triggered.connect(self.show_window)
        quit_action = menu.addAction("Exit")

        quit_action.triggered.connect(self.quit_action)

        self.tray = QSystemTrayIcon()
        self.tray.setIcon(QIcon(get_resource_path("images/logo.ico")))
        self.tray.setContextMenu(menu)
        self.tray.show()
        self.tray.setToolTip("BlobBackup")

        self.tray.activated.connect(self.tray_activated)

        self.show_window()

    def tray_activated(self, reason):
        if reason == QSystemTrayIcon.DoubleClick:
            self.show_window()

    def quit_action(self):
        reply = QMessageBox.question(
            self.window, "Exit BlobBackup?",
            "Are you sure you want to exit? Your scheduled backups will not take place.",
            QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
        if reply == QMessageBox.Yes:
            self.scheduler.shutdown()
            self.window.log_file_thread.terminate_gracefully()
            self.window.log_file_thread.terminate()
            sys.exit()

    def run(self):
        self.app.exec_()
        sys.exit()

    def show_window(self):
        self.window.show()
        self.window.activateWindow()
        self.window.raise_()

    def notify(self, message):
        self.tray.showMessage("BlobBackup", message)