How to use the stig.commands.tui._mixin 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 / commands / tui / config.py View on Github external
setting_name = widget.focused_widget.name
                super().run((setting_name,))


class SetCmd(base.SetCmdbase,
             mixin.create_list_widget):
    provides = {'tui'}

    def make_setting_list(self, sort, columns):
        from ...tui.views.setting_list import SettingListWidget
        self.create_list_widget(SettingListWidget, theme_name='settinglist',
                                sort=sort, columns=columns)


class RateLimitCmd(base.RateLimitCmdbase,
                   mixin.make_request, mixin.select_torrents, mixin.polling_frenzy):
    provides = {'tui'}

    async def _set_limits(self, TORRENT_FILTER, directions, limit, adjust=False, quiet=False):
        if TORRENT_FILTER == ['global']:
            await self._set_global_limits(directions, limit,
                                          adjust=adjust, quiet=quiet)
        else:
            await self._set_individual_limits(TORRENT_FILTER, directions, limit,
                                              adjust=adjust, quiet=quiet)

    async def _show_limits(self, TORRENT_FILTER, directions):
        if TORRENT_FILTER == ['global']:
            await self._show_global_limits(directions)
        else:
            await self._show_individual_limits(TORRENT_FILTER, directions)
github rndusr / stig / stig / commands / tui / tui.py View on Github external
'setcommand move {{location}}/',
        '\tMove the focused torrent, using the current path as default.',
        '',
        'setcommand move id={{id}} {{location}}/',
        ('\tSame as above, but make sure to move the correct torrent in case '
         'it is removed from the list while typing in the new path, e.g. if '
         'we\'re listing active torrents and the focused torrent stops being active.'),
    )
    argspecs = (
        { 'names': ('COMMAND',), 'nargs': 'REMAINDER',
          'description': 'Command the can user edit before executing it (see PLACEHOLDERS)' },
        { 'names': ('--trailing-space', '-s'), 'action': 'store_true',
          'description': 'Append a space at the end of COMMAND' },
    )
    more_sections = {
        'PLACEHOLDERS': mixin.placeholders.HELP,
    }

    async def run(self, COMMAND, trailing_space):
        log.debug('Unresolved command: %r', COMMAND)
        args = await self.parse_placeholders(*COMMAND)
        log.debug('Command with resolved placeholders: %r', args)

        if args:
            cmdstr = ' '.join(shlex.quote(str(arg)) for arg in args)
            if trailing_space:
                cmdstr += ' '
            from ...tui.tuiobjects import widgets
            widgets.show('cli')
            widgets.cli.base_widget.edit_text = cmdstr
            widgets.cli.base_widget.edit_pos = len(cmdstr)
github rndusr / stig / stig / commands / tui / tracker.py View on Github external
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details
# http://www.gnu.org/licenses/gpl-3.0.txt

from ..base import tracker as base
from . import _mixin as mixin


class ListTrackersCmd(base.ListTrackersCmdbase,
                      mixin.make_request,
                      mixin.select_torrents,
                      mixin.create_list_widget):
    provides = {'tui'}

    def make_tracker_list(self, torfilter, trkfilter, sort, columns):
        from ...tui.views.tracker_list import TrackerListWidget
        self.create_list_widget(TrackerListWidget, theme_name='trackerlist',
                                torfilter=torfilter, trkfilter=trkfilter,
                                sort=sort, columns=columns,
                                markable_items=False)


class AnnounceCmd(base.AnnounceCmdbase,
                  mixin.make_request, mixin.select_torrents):
    provides = {'tui'}


class TrackerCmd(base.TrackerCmdbase,
github rndusr / stig / stig / commands / tui / torrent.py View on Github external
curarg = args.curarg
        if len(args) >= 3:
            if args.curarg_index == 1:
                return await candidates.torrent_filter(curarg)
            elif args.curarg_index == 2:
                return dest_path_candidates(curarg)
        elif len(args) == 2:
            # Single argument may be a path or a filter
            filter_cands = await candidates.torrent_filter(curarg)
            path_cands = dest_path_candidates(curarg)
            return (path_cands,) + filter_cands


class RemoveTorrentsCmd(base.RemoveTorrentsCmdbase,
                        mixin.polling_frenzy, mixin.make_request, mixin.select_torrents,
                        mixin.ask_yes_no):
    provides = {'tui'}
    CONFIRMATION_TAB_TITLE = 'Removal Confirmation'

    async def show_list_of_hits(self, tfilter):
        from ...objects import cmdmgr
        cmd = 'tab --title %r ls --sort name %s' % (self.CONFIRMATION_TAB_TITLE, tfilter)
        await cmdmgr.run_async(cmd)

    async def remove_list_of_hits(self):
        from ...objects import cmdmgr
        cmd = 'tab --close %r --focus left' % self.CONFIRMATION_TAB_TITLE
        await cmdmgr.run_async(cmd)


class RenameCmd(base.RenameCmdbase,
                mixin.polling_frenzy, mixin.make_request, mixin.select_torrents, mixin.select_files):
github rndusr / stig / stig / commands / tui / tracker.py View on Github external
def make_tracker_list(self, torfilter, trkfilter, sort, columns):
        from ...tui.views.tracker_list import TrackerListWidget
        self.create_list_widget(TrackerListWidget, theme_name='trackerlist',
                                torfilter=torfilter, trkfilter=trkfilter,
                                sort=sort, columns=columns,
                                markable_items=False)


class AnnounceCmd(base.AnnounceCmdbase,
                  mixin.make_request, mixin.select_torrents):
    provides = {'tui'}


class TrackerCmd(base.TrackerCmdbase,
                 mixin.make_request, mixin.polling_frenzy, mixin.select_torrents):
    provides = {'tui'}
github rndusr / stig / stig / commands / tui / tui.py View on Github external
sortcls = self.SettingSorter
            else:
                raise CmdError('Current tab is not sortable.')

            try:
                new_sort = sortcls(utils.listify_args(ORDER))
            except ValueError as e:
                raise CmdError(e)

            if add and current_tab.sort is not None:
                current_tab.sort += new_sort
            else:
                current_tab.sort = new_sort


class TabCmd(mixin.select_torrents, metaclass=InitCommand):
    name = 'tab'
    provides = {'tui'}
    category = 'tui'
    description = 'Open, close and focus tabs'
    usage = ('tab []',
             'tab [] ')
    examples = ('tab',
                'tab -c',
                'tab -c active',
                'tab ls active',
                'tab -b ls active',
                'tab -f active',
                'tab -f 3 ls active',
                'tab -b -f -1 ls active')
    argspecs = (
        { 'names': ('--background', '-b'), 'action': 'store_true',
github rndusr / stig / stig / commands / tui / file.py View on Github external
class ListFilesCmd(base.ListFilesCmdbase,
                   mixin.make_request,
                   mixin.select_torrents, mixin.select_files,
                   mixin.create_list_widget):
    provides = {'tui'}

    def make_file_list(self, tfilter, ffilter, columns):
        from ...tui.views.file_list import FileListWidget
        self.create_list_widget(FileListWidget, theme_name='filelist',
                                tfilter=tfilter, ffilter=ffilter,
                                columns=columns,
                                markable_items=True)


class PriorityCmd(base.PriorityCmdbase,
                  mixin.polling_frenzy, mixin.make_request, mixin.select_torrents, mixin.select_files):
    provides = {'tui'}
github rndusr / stig / stig / commands / tui / peer.py View on Github external
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details
# http://www.gnu.org/licenses/gpl-3.0.txt

from ..base import peer as base
from . import _mixin as mixin


class ListPeersCmd(base.ListPeersCmdbase,
                   mixin.make_request,
                   mixin.select_torrents,
                   mixin.create_list_widget):
    provides = {'tui'}

    def make_peer_list(self, tfilter, pfilter, sort, columns):
        from ...tui.views.peer_list import PeerListWidget
        self.create_list_widget(PeerListWidget, theme_name='peerlist',
                                tfilter=tfilter, pfilter=pfilter,
                                sort=sort, columns=columns,
                                markable_items=False)
github rndusr / stig / stig / commands / tui / file.py View on Github external
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details
# http://www.gnu.org/licenses/gpl-3.0.txt

from ..base import file as base
from . import _mixin as mixin


class ListFilesCmd(base.ListFilesCmdbase,
                   mixin.make_request,
                   mixin.select_torrents, mixin.select_files,
                   mixin.create_list_widget):
    provides = {'tui'}

    def make_file_list(self, tfilter, ffilter, columns):
        from ...tui.views.file_list import FileListWidget
        self.create_list_widget(FileListWidget, theme_name='filelist',
                                tfilter=tfilter, ffilter=ffilter,
                                columns=columns,
                                markable_items=True)


class PriorityCmd(base.PriorityCmdbase,
                  mixin.polling_frenzy, mixin.make_request, mixin.select_torrents, mixin.select_files):
    provides = {'tui'}