Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def find_id_by_title(string):
for index,title in enumerate(tabs.titles):
if string in title.original_widget.text:
return tabs.get_id(index)
if focus is not None:
log.debug('Focusing tab %r', tabid_focus)
tabs.focus_id = tabid_focus
if close_all is not False:
log.debug('Closing all tabs')
tabs.clear()
elif close is not False:
log.debug('Closing tab %r', tabid_close)
tabs.remove(tabid_close)
# If no tabs were closed or focused, open a new one
if close is False and close_all is False and focus is None:
titlew = make_tab_title_widget(title or 'Empty tab',
attr_unfocused='tabs.unfocused',
attr_focused='tabs.focused')
tabs.insert(titlew, position='right')
log.debug('Inserted new tab at position %d: %r', tabs.focus_position, titlew.base_widget.text)
# Maybe provide a user-specified tab title to the new command
if title:
cmd_attrs['title'] = title
if COMMAND:
# Execute command
cmd_str = ' '.join(shlex.quote(arg) for arg in COMMAND)
log.debug('Running command in tab %s with args %s: %r',
tabs.focus_position,
', '.join('%s=%r' % (k,v) for k,v in cmd_attrs.items()),
cmd_str)
success = await objects.cmdmgr.run_async(cmd_str, **cmd_attrs)
else:
if tabid_close is None:
raise CmdError('No such tab: %r' % (close,))
# COMMAND may get additional hidden arguments as instance attributes
cmd_attrs = {}
# Apply close/focus operations
if focus is not None:
log.debug('Focusing tab %r', tabid_focus)
tabs.focus_id = tabid_focus
if close_all is not False:
log.debug('Closing all tabs')
tabs.clear()
elif close is not False:
log.debug('Closing tab %r', tabid_close)
tabs.remove(tabid_close)
# If no tabs were closed or focused, open a new one
if close is False and close_all is False and focus is None:
titlew = make_tab_title_widget(title or 'Empty tab',
attr_unfocused='tabs.unfocused',
attr_focused='tabs.focused')
tabs.insert(titlew, position='right')
log.debug('Inserted new tab at position %d: %r', tabs.focus_position, titlew.base_widget.text)
# Maybe provide a user-specified tab title to the new command
if title:
cmd_attrs['title'] = title
if COMMAND:
# Execute command
cmd_str = ' '.join(shlex.quote(arg) for arg in COMMAND)
def _get_current_or_previous_tab(cls):
"""Return currently focused tab content if not empty, the previous one or None"""
from ...tui.tuiobjects import tabs
widget = tabs.focus
if widget is not None:
return widget
else:
return tabs.prev_focus
def tab_titles():
"""Titles (strings) of TUI tabs"""
from ..tui.tuiobjects import tabs
return Candidates((widget.original_widget.text
for widget in tabs.titles), label='Tab Titles')
def run(self, clear, FILTER):
from ...tui.tuiobjects import tabs
content = tabs.focus.base_widget
if not hasattr(content, 'secondary_filter'):
raise CmdError('This tab does not support limiting.')
else:
if clear or not FILTER:
content.secondary_filter = None
else:
try:
content.secondary_filter = FILTER
except ValueError as e:
raise CmdError(e)
from ...tui import tuiobjects
if hasattr(self, 'title'):
titlew = make_tab_title_widget(str(self.title),
attr_unfocused='tabs.help.unfocused',
attr_focused='tabs.help.focused')
else:
titlew = make_tab_title_widget(','.join(topics),
attr_unfocused='tabs.help.unfocused',
attr_focused='tabs.help.focused')
helptext_widget_cls = tuiobjects.keymap.wrap(SearchableText, context='helptext')
helptext_widget = helptext_widget_cls(lines)
textw = tuiobjects.urwid.AttrMap(helptext_widget, 'helptext')
contentw = tuiobjects.urwid.AttrMap(ScrollBar(textw), 'helptext.scrollbar')
tuiobjects.tabs.load(titlew, contentw)
# Start logging to TUI widget instead of stdout/stderr
tuiobjects.logwidget.enable()
tuiobjects.topbar.help.update()
# If no tab has been opened by cli or rc file, open default tabs
if len(tuiobjects.tabs) <= 0:
for cmd in ('tab ls -c seeds,status,ratio,path,name,tracker',
'tab ls active|incomplete',
'tab ls downloading -c size,downloaded,%downloaded,rate-down,completed,eta,path,name',
'tab ls uploading -c size,ratio,uploaded,rate-up,peers,seeds,tracker,path,name',
'tab -t peers lsp -s torrent',
'tab ls stopped -s ratio,path -c size,%downloaded,seeds,ratio,activity,path,name',
'tab ls isolated -c error,tracker,path,name -s tracker'):
objects.cmdmgr.run_sync(cmd, on_error=log.error)
tuiobjects.tabs.focus_position = 1
try:
# Start polling torrent lists, counters, bandwidth usage, etc.
objects.aioloop.run_until_complete(objects.srvapi.start_polling())
old = tuiobjects.urwidscreen.tty_signal_keys('undefined','undefined',
'undefined','undefined','undefined')
tuiobjects.urwidloop.run()
finally:
tuiobjects.urwidscreen.tty_signal_keys(*old)
tuiobjects.logwidget.disable()
objects.aioloop.run_until_complete(objects.srvapi.stop_polling())
return True
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)
def _get_current_or_previous_tab(cls):
"""Return currently focused tab content if not empty, the previous one or None"""
from ...tui.tuiobjects import tabs
widget = tabs.focus
if widget is not None:
return widget
else:
return tabs.prev_focus