コード例 #1
0
    def __init__(self, **kwargs):
        super(StatusIcons, self).__init__(**kwargs)

        self._status_icons = OrderedDict()

        # Warnings Icon #
        # FIXME: More elegant way to do this?
        warnings_icon = StatusIcon('Warnings', WARNINGS_MODES)

        def _warnings_message():
            output = ''

            warnings = self.platforms.warnings()
            if len(warnings):
                output += template('warnings',
                                   warnings=warnings,
                                   status_icon=warnings_icon)
            return output

        warnings_icon.status_message = _warnings_message

        warnings_old_current_icon = warnings_icon.current_icon

        def _warnings_icon():
            warnings_state = self.platforms.warnings_state()
            LOGGER.debug('warnings_state: ' + str(warnings_state))
            return warnings_old_current_icon(warnings_state)

        warnings_icon.current_icon = _warnings_icon

        self._status_icons[warnings_icon.internal_name] = warnings_icon

        # Power Consumption Icon #
        power_consumption_icon = StatusIcon('Power Consumption', POWER_MODES)

        power_consumption_old_current_icon = power_consumption_icon.current_icon

        def _power_consumption_icon():
            power_consumption_state = self.manager.networks[
                0].power_consumption_state()
            return power_consumption_old_current_icon(power_consumption_state)

        power_consumption_icon.current_icon = _power_consumption_icon
        self._status_icons[
            power_consumption_icon.internal_name] = power_consumption_icon

        # System Status Icon #
        system_status_icon = StatusIcon('System Status', SYSTEM_MODES)
        self._status_icons[
            system_status_icon.internal_name] = system_status_icon
コード例 #2
0
    def status_icons(self):
        """ Fetch Status Icons """
        output = copy.deepcopy(self._status_icons)

        insert_icon = None
        if len(self.platforms.select_nodes('active')):
            current_url = self.url()
            if self.url('live_data') in current_url:
                # Display Options Icon #
                display_options_icon = StatusIcon('Table Display Options',
                                                  DISPLAY_OPTIONS_MODES,
                                                  enable_legend=False)

                def _display_options_message():
                    _output = '<h3>' + display_options_icon.title + '</h3>'
                    group = self.get_group()
                    _output += template('table_units',
                                        group=group,
                                        page_type='live')
                    return _output

                display_options_icon.status_message = _display_options_message
                insert_icon = display_options_icon

            elif self.url('logs_data') in current_url:
                # Log Export Icon #
                log_export_icon = StatusIcon('Log Export',
                                             LOG_EXPORT_MODES,
                                             enable_legend=False)

                def _log_export_message():
                    group = self.get_group()
                    _output = self.template_html(None,
                                                 'log_export',
                                                 group=group)
                    return _output

                log_export_icon.status_message = _log_export_message
                insert_icon = log_export_icon

        if insert_icon is not None:

            _old_current_icon = insert_icon.current_icon

            def _insert_icon_current_icon():
                active_nodes = self.platforms.select_nodes('active')
                active_state = int(bool(len(active_nodes)))
                return _old_current_icon(active_state)

            insert_icon.current_icon = _insert_icon_current_icon

            output.insert_before(output.keys()[0],
                                 (insert_icon.internal_name, insert_icon))

        return output
コード例 #3
0
def main():
    '''Load settings, start status icon and get to work.'''
    from addressbook import AddressBook
    from status_icon import StatusIcon
    # try to load settings
    conf = Conf()

    # load data and fill AddressBook
    addressbook = AddressBook(conf)
    addressbook.reload()

    # show status icon
    status_icon = StatusIcon(addressbook, conf)

    # check every 60 seconds for new day
    # TODO: update until end of day according to current clock settings?
    #       (might not the best idea if user changes current time)
    import gobject
    gobject.timeout_add(60000, status_icon.check_new_day)
    gtk.main()
コード例 #4
0
ファイル: core.py プロジェクト: yaniv-aknin/pay4bytes
class Pay4BytesCore(Service):
    IReactorTimeProvider = reactor
    updateInterval = 1
    menuItems = (
                    ('Quit', lambda widget: reactor.stop()),
                )
    def __init__(self):
        self.statusIcon = StatusIcon(self.menuItems)
        self.configuration = Configuration()
        self.connectionRegistry = None
        self.timer = LoopingCall(self.updateStatistics)
        self.timer.clock = self.IReactorTimeProvider

    def startService(self):
        Service.startService(self)
        self.configuration.load()
        self.connectionRegistry = \
            ConnectionRegistry( self.createConfiguredDeviceMap())
        self.timer.start(self.updateInterval).addErrback(log.err)
        self.statusIcon.show()

    def stopService(self):
        self.statusIcon.hide()
        # HACK: the timer should always be running and there's no need for this
        #        check; however, during development the service might be
        #        uncleanly with the timer not running, and then we'd rather
        #        avoid 'trying to stop a timer which isn't running' exception
        if self.timer.running:
            self.timer.stop()
        self.connectionRegistry.updateConfiguration()
        self.configuration.save()
        Service.stopService(self)

    def updateStatistics(self):
        statisticsMap = readNetworkDevicesStatisticsMap()
        self.connectionRegistry.updateConnections(statisticsMap)
        self.statusIcon.updateTooltip(self.connectionRegistry)

    def createConfiguredDeviceMap(self):
        result = {}
        for configuredDevice in self.configuration:
            pattern = re.compile(configuredDevice.get(DEVICE_NAME_PATTERN))
            result[pattern] = configuredDevice
        return result
コード例 #5
0
ファイル: core.py プロジェクト: yaniv-aknin/pay4bytes
 def __init__(self):
     self.statusIcon = StatusIcon(self.menuItems)
     self.configuration = Configuration()
     self.connectionRegistry = None
     self.timer = LoopingCall(self.updateStatistics)
     self.timer.clock = self.IReactorTimeProvider