Exemple #1
0
    def __init__(self):
        builtins.super(self.__class__, self).__init__([])

        self.window = QtGui.QWidget()
        self.tray_icon = AnimatedSystemTrayIcon('icon.svg', parent=self.window)

        self.omni_sync = Omnisync(self.handle_sync_progress)
        self.progress = {syncer: 1.0 for syncer in
                         self.omni_sync.sync_manager.syncers.values()}
        self.progress_menu_items = {}

        # We need to do this with a signal because the animation must be
        # triggered from the main thread.
        self.start_animation.connect(
            #self.tray_icon.get_animator('shrink', minimum=0.4))
            self.tray_icon.get_animator('rotate'))

        self.build_gui()
Exemple #2
0
class Gui(QtGui.QApplication):
    # signals need to be class variables
    start_animation = QtCore.pyqtSignal()

    def __init__(self):
        builtins.super(self.__class__, self).__init__([])

        self.window = QtGui.QWidget()
        self.tray_icon = AnimatedSystemTrayIcon('icon.svg', parent=self.window)

        self.omni_sync = Omnisync(self.handle_sync_progress)
        self.progress = {syncer: 1.0 for syncer in
                         self.omni_sync.sync_manager.syncers.values()}
        self.progress_menu_items = {}

        # We need to do this with a signal because the animation must be
        # triggered from the main thread.
        self.start_animation.connect(
            #self.tray_icon.get_animator('shrink', minimum=0.4))
            self.tray_icon.get_animator('rotate'))

        self.build_gui()

    def show_progress(self):
        for syncer, val in self.progress.items():
            item = self.progress_menu_items.get(syncer.name, None)
            if item:
                item.setText(
                    '%s: %0.0f%% (queue: %s)'
                    % (syncer.name, val * 100, syncer.queue.qsize())
                )

    def handle_sync_progress(self, syncer, file, progress):
        self.progress[syncer] = progress
        progresses = self.progress.values()
        if any([val == 0.0 for val in progresses]):
            self.start_animation.emit()
        if all([val == 1.0 for val in progresses]):
            self.tray_icon.stop_animation()
        self.show_progress()

    def build_gui(self):
        menu = QtGui.QMenu()
        for (entry, action) in [
            ('start rotate', self.tray_icon.get_animator('rotate')),
            ('stop animation', self.tray_icon.stop_animation),
            ('quit', self.quit),
        ]:
            q_action = QtGui.QAction(entry, self)
            q_action.triggered.connect(action)
            menu.addAction(q_action)

        menu.addSeparator()
        menu.setSeparatorsCollapsible(True)
        for syncer in self.progress:
            q_action = QtGui.QAction(syncer.name, self)
            self.progress_menu_items[syncer.name] = q_action
            menu.addAction(q_action)

        self.tray_icon.setContextMenu(menu)
        self.tray_icon.show()

    def quit(self, *args, **kwargs):
        self.omni_sync.stop()
        QtGui.qApp.quit()