Beispiel #1
0
    def setup_indicator( self ):
        indicator = Indicator( id='amazonCheck-indicator',
                               icon_name='ind_act',
                               category=CATEGORY_APPLICATION_STATUS,
                               icon_theme_path=ICON_PATH,
                               )

        indicator.set_attention_icon( 'ind_att' )
        indicator.set_status( STATUS_ACTIVE )

        item_show      = gtk.MenuItem( 'Hide window'        )
        item_add_clip  = gtk.MenuItem( 'Add from clipboard' )
        item_seperator = gtk.SeparatorMenuItem()
        item_reset     = gtk.MenuItem( 'Reset'              )
        item_exit      = gtk.MenuItem( 'Exit'               )

        item_show.connect(     'activate', self.toggle_window_visible )
        item_add_clip.connect( 'activate', self.on_add_article        )
        item_exit.connect(     'activate', self.exit_application      )
        item_reset.connect(    'activate', self.set_ind_active        )

        menu = gtk.Menu()

        menu.append( item_show      )
        menu.append( item_add_clip  )
        menu.append( item_seperator )
        menu.append( item_reset     )
        menu.append( item_exit      )

        menu.show_all()

        indicator.set_menu( menu )

        return indicator
Beispiel #2
0
 def __init__(self):
     self.ind = Indicator("btsync-indicator", "btsync",
                          appindicator.CATEGORY_APPLICATION_STATUS,
                          '%s/icons/' % INSTALL_DIR)
     self.ind.set_attention_icon("btsync-inactive")
     self.ind.set_icon("btsync-ok")
     self.ind.set_status(appindicator.STATUS_ATTENTION)
     self.btsync_running = False
     self.btsync = None
     self.ind.set_menu(self.menu_setup())
     log.info("BitTorrentSync Indicator is running!")
Beispiel #3
0
 def __init__(self):
     self.ind = Indicator("timetracker-indicator", "timetracker",
                          appindicator.CATEGORY_APPLICATION_STATUS,
                          INSTALL_DIR)
     self.ind.set_attention_icon("pause")
     self.ind.set_icon("timer")
     self.ind.set_status(appindicator.STATUS_ATTENTION)
     self.ind.set_menu(self.menu_setup())
     self.timer = timedelta(seconds=0)
     self.total_timer = timedelta(hours=0)
     self.start_time = None
     self.pause_time = None
     self.pause_timer = timedelta(seconds=0)
Beispiel #4
0
class BtSyncIndicator:
    def __init__(self):
        self.ind = Indicator("btsync-indicator", "btsync",
                             appindicator.CATEGORY_APPLICATION_STATUS,
                             '%s/icons/' % INSTALL_DIR)
        self.ind.set_attention_icon("btsync-inactive")
        self.ind.set_icon("btsync-ok")
        self.ind.set_status(appindicator.STATUS_ATTENTION)
        self.btsync_running = False
        self.btsync = None
        self.ind.set_menu(self.menu_setup())
        log.info("BitTorrentSync Indicator is running!")

    def menu_setup(self):
        menu = gtk.Menu()
        sep1 = gtk.SeparatorMenuItem()
        sep1.show()
        menu.append(sep1)
        button = gtk.MenuItem("Start/Stop BitTorrent Sync")
        button.connect("activate", self.toggle_status)
        button.show()
        menu.append(button)
        sep2 = gtk.SeparatorMenuItem()
        sep2.show()
        menu.append(sep2)
        quit_item = gtk.MenuItem("Quit")
        quit_item.connect("activate", self.quit)
        quit_item.show()
        menu.append(quit_item)

        return menu

    def toggle_status(self, widget):
        self.stop_btsync() if self.btsync_running else self.start_btsync()

    def start_btsync(self):
        cmd = '%s/btsync' % INSTALL_DIR
        config_file = '%s/config.json' % INSTALL_DIR
        log_file = '%s/btsync.log' % INSTALL_DIR
        args = [cmd, '--config', config_file, '--log', log_file, '--nodaemon']
        log.info("Starting BitTorrentSync with command %s", ' '.join(args))
        self.btsync = subprocess.Popen(args)
        log.info("BitTorrentSync pid: %s", self.btsync.pid)

    def stop_btsync(self):
        if self.btsync_running and self.btsync:
            log.info("Stoping BitTorrentSync")
            self.btsync.terminate()
            self.btsync.wait()
            log.info("BtSync exit code: %s", self.btsync.returncode)
            self.btsync = None

    def update_status(self):
        result = subprocess.call("ps aux | grep 'btsync --config' | grep -v grep >/dev/null",
                                 shell=True)
        status = result == 0
        # log.info("Checking BtSync is running: %s", status)
        if status != self.btsync_running:
            msg = "RUNNING" if status else "NOT RUNNING"
            log.info("BitTorrentSync status changes now it's %s", msg)
        self.btsync_running = status
        gtk.timeout_add(TIMEOUT * 1000, self.update_status)
        self.toggle_icon()

    def toggle_icon(self):
        if self.btsync_running:
            self.ind.set_status(appindicator.STATUS_ACTIVE)
        else:
            self.ind.set_status(appindicator.STATUS_ATTENTION)

    def quit(self, widget):
        log.info("Exiting...")
        self.stop_btsync()
        sys.exit(0)
Beispiel #5
0
class TimeTrackerIndicator:
    PAUSE_MSG = "Pause: %s"
    TIMER_MSG = "Timer: %s"
    TOTAL_MSG = "Total timer: %s"

    def __init__(self):
        self.ind = Indicator("timetracker-indicator", "timetracker",
                             appindicator.CATEGORY_APPLICATION_STATUS,
                             INSTALL_DIR)
        self.ind.set_attention_icon("pause")
        self.ind.set_icon("timer")
        self.ind.set_status(appindicator.STATUS_ATTENTION)
        self.ind.set_menu(self.menu_setup())
        self.timer = timedelta(seconds=0)
        self.total_timer = timedelta(hours=0)
        self.start_time = None
        self.pause_time = None
        self.pause_timer = timedelta(seconds=0)

    def menu_setup(self):
        menu = gtk.Menu()
        # Commands
        button = gtk.MenuItem("Start/Stop Timer")
        button.connect("activate", self.toggle_timer)
        button.show()
        menu.append(button)
        button = gtk.MenuItem("+/- Timer")
        button.show()
        menu.append(button)
        submenu = gtk.Menu()
        button.set_submenu(submenu)
        button = gtk.MenuItem("Reset Timers")
        button.connect("activate", self.reset_timers)
        button.show()
        menu.append(button)
        # submenu
        button = gtk.MenuItem("- 5 min")
        button.connect("activate", self.tick_timers, timedelta(minutes=-5))
        button.show()
        submenu.append(button)
        button = gtk.MenuItem("- 10 min")
        button.connect("activate", self.tick_timers, timedelta(minutes=-10))
        button.show()
        submenu.append(button)
        sep = gtk.SeparatorMenuItem()
        sep.show()
        submenu.append(sep)
        button = gtk.MenuItem("+ 5 min")
        button.connect("activate", self.tick_timers, timedelta(minutes=5))
        button.show()
        submenu.append(button)
        button = gtk.MenuItem("+ 10 min")
        button.connect("activate", self.tick_timers, timedelta(minutes=10))
        button.show()
        submenu.append(button)
        button = gtk.MenuItem("+ 1 hour")
        button.connect("activate", self.tick_timers, timedelta(minutes=60))
        button.show()
        submenu.append(button)
        # Timers
        sep = gtk.SeparatorMenuItem()
        sep.show()
        menu.append(sep)
        self.pause_label = gtk.MenuItem()
        self.pause_label.connect("activate", self.toggle_timer)
        menu.append(self.pause_label)
        self.timer_label = gtk.MenuItem()
        self.timer_label.show()
        menu.append(self.timer_label)
        self.total_timer_label = gtk.MenuItem()
        self.total_timer_label.show()
        menu.append(self.total_timer_label)
        return menu

    def toggle_timer(self, widget):
        if self.start_time:
            self.ind.set_status(appindicator.STATUS_ATTENTION)
            self.start_time = None
            if widget.get_label().startswith("Start/Stop"):
                self.timer = timedelta(seconds=0)
            else:
                self.pause_timer = timedelta(seconds=0)
                self.pause_time = datetime.now()
        else:
            self.pause_time = None
            self.start_time = datetime.now()
            self.ind.set_status(appindicator.STATUS_ACTIVE)

    def reset_timers(self, widget):
        if self.start_time:
            self.toggle_timer(widget)
        self.pause_time = None
        self.timer = self.total_timer = self.pause_timer = timedelta(0)

    def update_counters(self):
        # compute timers
        if self.start_time:
            self.compute_timers()
        if self.pause_time:
            self.compute_pause_timer()
        # update labels
        self.update_pause_label()
        self.update_total_timer_label()
        self.update_timer_label()
        # repeat
        gtk.timeout_add(TIMEOUT * 1000, self.update_counters)

    def compute_timers(self):
        now = datetime.now()
        delta = now - self.start_time
        self.start_time = now
        self.tick_timers(delta=delta)

    def tick_timers(self, widget=None, delta=timedelta(seconds=0)):
        self.timer = self.timer + delta
        self.total_timer = self.total_timer + delta

    def compute_pause_timer(self):
        now = datetime.now()
        delta = now - self.pause_time
        self.pause_time = now
        self.pause_timer = self.pause_timer + delta

    def update_pause_label(self):
        if self.pause_time:
            self.pause_label.set_label(
                TimeTrackerIndicator.PAUSE_MSG % format_delta(self.pause_timer))
            self.pause_label.set_tooltip_text("Click to resume timer")
            self.pause_label.show()
        elif self.start_time:
            self.pause_label.set_label('Pause')
            self.pause_label.set_tooltip_text("Click to pause")
            self.pause_label.show()
        else:
            self.pause_label.hide()

    def update_timer_label(self):
        self.timer_label.set_label(
            TimeTrackerIndicator.TIMER_MSG % format_delta(self.timer))

    def update_total_timer_label(self):
        self.total_timer_label.set_label(
            TimeTrackerIndicator.TOTAL_MSG % format_delta(self.total_timer))