console: observe state objects for changes, fire event to update status bar.

This commit is contained in:
Aldo Cortesi 2015-03-22 15:11:54 +13:00
parent 200498e7aa
commit c9a0975446
3 changed files with 16 additions and 0 deletions

View File

@ -33,6 +33,10 @@ class ConsoleState(flow.State):
self.flowsettings = weakref.WeakKeyDictionary()
def __setattr__(self, name, value):
self.__dict__[name] = value
signals.update_settings.send(self)
def add_flow_setting(self, flow, key, value):
d = self.flowsettings.setdefault(flow, {})
d[key] = value
@ -212,6 +216,10 @@ class ConsoleMaster(flow.FlowMaster):
self.start_app(self.options.app_host, self.options.app_port)
signals.call_in.connect(self.sig_call_in)
def __setattr__(self, name, value):
self.__dict__[name] = value
signals.update_settings.send(self)
def sig_call_in(self, sender, seconds, callback, args=()):
def cb(*_):
return callback(*args)
@ -598,6 +606,7 @@ class ConsoleMaster(flow.FlowMaster):
elif a == "u":
self.server.config.no_upstream_cert =\
not self.server.config.no_upstream_cert
signals.update_settings.send(self)
def shutdown(self):
self.state.killall(self)

View File

@ -17,3 +17,6 @@ call_in = blinker.Signal()
# Focus the body, footer or header of the main window
focus = blinker.Signal()
# Fired when settings change
update_settings = blinker.Signal()

View File

@ -113,6 +113,10 @@ class StatusBar(urwid.WidgetWrap):
self.ab = ActionBar()
self.ib = urwid.WidgetWrap(urwid.Text(""))
self._w = urwid.Pile([self.ib, self.ab])
signals.update_settings.connect(self.sig_update_settings)
def sig_update_settings(self, sender):
self.redraw()
def keypress(self, *args, **kwargs):
return self.ab.keypress(*args, **kwargs)