console: C to clear all options, correct footer in options screen

This commit is contained in:
Aldo Cortesi 2015-04-03 14:47:55 +13:00
parent 57bdb89342
commit 41a1a0bef3
2 changed files with 28 additions and 4 deletions

View File

@ -471,7 +471,7 @@ class ConsoleMaster(flow.FlowMaster):
self,
options.Options(self),
None,
statusbar.StatusBar(self, help.footer),
statusbar.StatusBar(self, options.footer),
None
)

View File

@ -3,6 +3,10 @@ import urwid
from . import common, signals
help_context = None
footer = [
('heading_key', "enter/space"), ":toggle ",
('heading_key', "C"), ":clear all ",
]
class OptionWidget(urwid.WidgetWrap):
@ -12,6 +16,7 @@ class OptionWidget(urwid.WidgetWrap):
keyattr = "key"
if focus and active:
textattr = "option_active_selected"
keyattr = "option_selected_key"
elif focus:
textattr = "option_selected"
keyattr = "option_selected_key"
@ -74,10 +79,10 @@ class OptionListBox(urwid.ListBox):
self.keymap[i.shortcut] = i
def keypress(self, size, key):
key = common.shortcuts(key)
if key == "enter":
if key == "enter" or key == " ":
self.get_focus()[0].option.activate()
return None
key = common.shortcuts(key)
if key in self.keymap:
self.keymap[key].activate()
self.set_focus(self.options.index(self.keymap[key]))
@ -104,7 +109,7 @@ class Options(urwid.WidgetWrap):
[
Option(
"Anti-Cache",
"C",
"a",
lambda: master.anticache,
self.toggle_anticache
),
@ -156,6 +161,25 @@ class Options(urwid.WidgetWrap):
)
self.master.loop.widget.footer.update("")
def keypress(self, size, key):
if key == "C":
self.clearall()
return None
return super(self.__class__, self).keypress(size, key)
def clearall(self):
self.master.anticache = False
self.master.anticomp = False
self.master.killextra = False
self.master.showhost = False
self.master.refresh_server_playback = True
self.master.server.config.no_upstream_cert = False
signals.update_settings.send(self)
signals.status_message.send(
message = "All options cleared",
expire = 1
)
def toggle_anticache(self):
self.master.anticache = not self.master.anticache