How to use the stig.objects.localcfg.on_change function in stig

To help you get started, we’ve selected a few stig examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rndusr / stig / stig / hooks.py View on Github external
from .logging import make_logger
log = make_logger(__name__)

from .objects import (localcfg, srvapi, geoip)
from .utils import convert
from .views.torrent import COLUMNS as TORRENT_COLUMNS
from .views.file import COLUMNS as FILE_COLUMNS
from .views.peer import COLUMNS as PEER_COLUMNS


def _make_connection_callback(attr):
    def on_set(settings, name, value):
        log.debug('Setting rpc.%s=%r', attr, value)
        setattr(srvapi.rpc, attr, value)
    return on_set
localcfg.on_change(_make_connection_callback('host'),     name='connect.host',     autoremove=False)
localcfg.on_change(_make_connection_callback('port'),     name='connect.port',     autoremove=False)
localcfg.on_change(_make_connection_callback('path'),     name='connect.path',     autoremove=False)
localcfg.on_change(_make_connection_callback('user'),     name='connect.user',     autoremove=False)
localcfg.on_change(_make_connection_callback('password'), name='connect.password', autoremove=False)
localcfg.on_change(_make_connection_callback('tls'),      name='connect.tls',      autoremove=False)
localcfg.on_change(_make_connection_callback('timeout'),  name='connect.timeout',  autoremove=False)


_BANDWIDTH_COLUMNS = (TORRENT_COLUMNS['rate-up'], TORRENT_COLUMNS['rate-down'],
                      TORRENT_COLUMNS['limit-rate-up'], TORRENT_COLUMNS['limit-rate-down'],
                      PEER_COLUMNS['rate-up'], PEER_COLUMNS['rate-down'], PEER_COLUMNS['rate-est'])
def _set_bandwidth_unit(settings, name, value):
    convert.bandwidth.unit = value
    unit_short = convert.bandwidth.unit
    for column in _BANDWIDTH_COLUMNS:
        column.set_unit(unit_short)
github rndusr / stig / stig / hooks.py View on Github external
unit_short = convert.bandwidth.unit
    for column in _BANDWIDTH_COLUMNS:
        column.set_unit(unit_short)
        column.clearcache()
    srvapi.torrent.clearcache()
    srvapi.poll()
localcfg.on_change(_set_bandwidth_unit, name='unit.bandwidth')
_set_bandwidth_unit(localcfg, name='unit.bandwidth', value=localcfg['unit.bandwidth'])  # Init columns' units

def _set_bandwidth_prefix(settings, name, value):
    convert.bandwidth.prefix = value
    for column in _BANDWIDTH_COLUMNS:
        column.clearcache()
    srvapi.torrent.clearcache()
    srvapi.poll()
localcfg.on_change(_set_bandwidth_prefix, name='unitprefix.bandwidth')


_SIZE_COLUMNS = (TORRENT_COLUMNS['size'], TORRENT_COLUMNS['downloaded'],
                 TORRENT_COLUMNS['uploaded'], TORRENT_COLUMNS['available'],
                 FILE_COLUMNS['size'], FILE_COLUMNS['downloaded'])
def _set_size_unit(settings, name, value):
    convert.size.unit = value
    unit_short = convert.size.unit
    for column in _SIZE_COLUMNS:
        column.set_unit(unit_short)
        column.clearcache()
    srvapi.torrent.clearcache()
    srvapi.poll()
localcfg.on_change(_set_size_unit, name='unit.size')
_set_size_unit(localcfg, name='unit.size', value=localcfg['unit.size'])  # Init columns' units
github rndusr / stig / stig / hooks.py View on Github external
unit_short = convert.size.unit
    for column in _SIZE_COLUMNS:
        column.set_unit(unit_short)
        column.clearcache()
    srvapi.torrent.clearcache()
    srvapi.poll()
localcfg.on_change(_set_size_unit, name='unit.size')
_set_size_unit(localcfg, name='unit.size', value=localcfg['unit.size'])  # Init columns' units

def _set_size_prefix(settings, name, value):
    convert.size.prefix = value
    for column in _SIZE_COLUMNS:
        column.clearcache()
    srvapi.torrent.clearcache()
    srvapi.poll()
localcfg.on_change(_set_size_prefix, name='unitprefix.size')


def _set_geoip(settings, name, value):
    if value and not geoip.available:
        log.error('Missing geoip dependency: maxminddb')
        localcfg['geoip'] = value = False
    geoip.enabled = value
localcfg.on_change(_set_geoip, name='geoip')

def _set_geoip_dir(settings, name, value):
    geoip.cachedir = value.full_path
localcfg.on_change(_set_geoip_dir, name='geoip.dir')
github rndusr / stig / stig / tui / views / hooks.py View on Github external
from ...objects import localcfg
from .torrent import TUICOLUMNS as TCOLUMNS
from .file import TUICOLUMNS as FCOLUMNS
from .peer import TUICOLUMNS as PCOLUMNS


_BANDWIDTH_COLUMNS = (TCOLUMNS['rate-up'], TCOLUMNS['rate-down'],
                      TCOLUMNS['limit-rate-up'], TCOLUMNS['limit-rate-down'],
                      PCOLUMNS['rate-up'], PCOLUMNS['rate-down'], PCOLUMNS['rate-est'])
def _set_bandwidth_unit(settings, name, value):
    unit_short = {'bit': 'b', 'byte': 'B'}.get(value, value)
    unit_short += '/s'
    for column in _BANDWIDTH_COLUMNS:
        column.set_header(right=unit_short)
localcfg.on_change(_set_bandwidth_unit, name='unit.bandwidth')


_SIZE_COLUMNS = (TCOLUMNS['size'], TCOLUMNS['downloaded'],
                 TCOLUMNS['uploaded'], TCOLUMNS['available'],
                 FCOLUMNS['size'], FCOLUMNS['downloaded'])
def _set_size_unit(settings, name, value):
    unit_short = {'bit': 'b', 'byte': 'B'}.get(value, value)
    for column in _SIZE_COLUMNS:
        column.set_header(right=unit_short)
localcfg.on_change(_set_size_unit, name='unit.size')
github rndusr / stig / stig / hooks.py View on Github external
srvapi.poll()
localcfg.on_change(_set_bandwidth_prefix, name='unitprefix.bandwidth')


_SIZE_COLUMNS = (TORRENT_COLUMNS['size'], TORRENT_COLUMNS['downloaded'],
                 TORRENT_COLUMNS['uploaded'], TORRENT_COLUMNS['available'],
                 FILE_COLUMNS['size'], FILE_COLUMNS['downloaded'])
def _set_size_unit(settings, name, value):
    convert.size.unit = value
    unit_short = convert.size.unit
    for column in _SIZE_COLUMNS:
        column.set_unit(unit_short)
        column.clearcache()
    srvapi.torrent.clearcache()
    srvapi.poll()
localcfg.on_change(_set_size_unit, name='unit.size')
_set_size_unit(localcfg, name='unit.size', value=localcfg['unit.size'])  # Init columns' units

def _set_size_prefix(settings, name, value):
    convert.size.prefix = value
    for column in _SIZE_COLUMNS:
        column.clearcache()
    srvapi.torrent.clearcache()
    srvapi.poll()
localcfg.on_change(_set_size_prefix, name='unitprefix.size')


def _set_geoip(settings, name, value):
    if value and not geoip.available:
        log.error('Missing geoip dependency: maxminddb')
        localcfg['geoip'] = value = False
    geoip.enabled = value
github rndusr / stig / stig / tui / hooks.py View on Github external
def _set_theme(settings, name, value):
    try:
        tuiobjects.theme.load(value.full_path, tuiobjects.urwidscreen)
    except tuiobjects.theme.ThemeError as e:
        raise ValueError(e)
localcfg.on_change(_set_theme, name='tui.theme')


def _set_tui_marked_char(methodname, settings, name, value):
    getattr(TORRENT_COLUMNS['marked'], methodname)(value)
    getattr(FILE_COLUMNS['marked'], methodname)(value)
    for widget in tuiobjects.tabs:
        if isinstance(widget, (TorrentListWidget, FileListWidget)):
            widget.refresh_marks()
localcfg.on_change(partial(_set_tui_marked_char, 'set_marked_char'), name='tui.marked.on', autoremove=False)
localcfg.on_change(partial(_set_tui_marked_char, 'set_unmarked_char'), name='tui.marked.off', autoremove=False)
_set_tui_marked_char('set_marked_char', localcfg, name='tui.marked.on', value=localcfg['tui.marked.on'])
_set_tui_marked_char('set_unmarked_char', localcfg, name='tui.marked.off', value=localcfg['tui.marked.off'])


def _update_quickhelp(keymap):
    tuiobjects.topbar.help.update()
tuiobjects.keymap.on_bind_unbind(_update_quickhelp)


def _set_geoip(settings, name, value):
    if value:
        tuiobjects.load_geoip_db()
localcfg.on_change(_set_geoip, name='geoip')
github rndusr / stig / stig / tui / views / setting_list.py View on Github external
def __init__(self, srvapi, keymap, sort=None, columns=None, title='Settings'):
        super().__init__(srvapi, keymap, columns=columns, sort=sort, title=title)
        self._sort = sort
        self._secondary_filter = None
        objects.localcfg.on_change(self._handle_update)
        objects.remotecfg.on_update(self._handle_update)
        self.refresh()
github rndusr / stig / stig / tui / hooks.py View on Github external
localcfg.on_change(_reconnect, name='connect.tls')


def _update_pollers(rpc):
    srvapi.poll()
srvapi.rpc.on('connected', _update_pollers)
srvapi.rpc.on('disconnected', _update_pollers)


def _refresh_lists(settings, name, value):
    for widget in tuiobjects.tabs:
        if isinstance(widget, (TorrentListWidget, FileListWidget, PeerListWidget)):
            widget.clear()
            widget.refresh()
localcfg.on_change(_refresh_lists, name='unit.bandwidth')
localcfg.on_change(_refresh_lists, name='unit.size')
localcfg.on_change(_refresh_lists, name='unitprefix.bandwidth')
localcfg.on_change(_refresh_lists, name='unitprefix.size')
localcfg.on_change(_refresh_lists, name='reverse-dns')
localcfg.on_change(_refresh_lists, name='geoip')


def _set_poll_interval(settings, name, value):
    srvapi.interval = value
localcfg.on_change(_set_poll_interval, name='tui.poll')


def _set_cli_history_dir(settings, name, value):
    tuiobjects.cli.original_widget.history_file = os.path.join(value.full_path, 'commands')
localcfg.on_change(_set_cli_history_dir, name='tui.cli.history-dir')

def _set_cli_history_size(settings, name, value):
github rndusr / stig / stig / tui / hooks.py View on Github external
def _set_autohide_delay(settings, name, value):
    tuiobjects.logwidget.autohide_delay = value
localcfg.on_change(_set_autohide_delay, name='tui.log.autohide')


def _set_log_height(settings, name, value):
    tuiobjects.logwidget.height = int(value)
localcfg.on_change(_set_log_height, name='tui.log.height')


def _set_theme(settings, name, value):
    try:
        tuiobjects.theme.load(value.full_path, tuiobjects.urwidscreen)
    except tuiobjects.theme.ThemeError as e:
        raise ValueError(e)
localcfg.on_change(_set_theme, name='tui.theme')


def _set_tui_marked_char(methodname, settings, name, value):
    getattr(TORRENT_COLUMNS['marked'], methodname)(value)
    getattr(FILE_COLUMNS['marked'], methodname)(value)
    for widget in tuiobjects.tabs:
        if isinstance(widget, (TorrentListWidget, FileListWidget)):
            widget.refresh_marks()
localcfg.on_change(partial(_set_tui_marked_char, 'set_marked_char'), name='tui.marked.on', autoremove=False)
localcfg.on_change(partial(_set_tui_marked_char, 'set_unmarked_char'), name='tui.marked.off', autoremove=False)
_set_tui_marked_char('set_marked_char', localcfg, name='tui.marked.on', value=localcfg['tui.marked.on'])
_set_tui_marked_char('set_unmarked_char', localcfg, name='tui.marked.off', value=localcfg['tui.marked.off'])


def _update_quickhelp(keymap):
    tuiobjects.topbar.help.update()