From c9a09754464e27a5f34295d8a1c0b435248c104c Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sun, 22 Mar 2015 15:11:54 +1300 Subject: [PATCH] console: observe state objects for changes, fire event to update status bar. --- libmproxy/console/__init__.py | 9 +++++++++ libmproxy/console/signals.py | 3 +++ libmproxy/console/statusbar.py | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py index 34abe6f4f..b593d2821 100644 --- a/libmproxy/console/__init__.py +++ b/libmproxy/console/__init__.py @@ -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) diff --git a/libmproxy/console/signals.py b/libmproxy/console/signals.py index e8944afb6..a62b2a4e1 100644 --- a/libmproxy/console/signals.py +++ b/libmproxy/console/signals.py @@ -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() diff --git a/libmproxy/console/statusbar.py b/libmproxy/console/statusbar.py index 30819188e..7663ee44b 100644 --- a/libmproxy/console/statusbar.py +++ b/libmproxy/console/statusbar.py @@ -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)