console: more consistent view stack management

This commit is contained in:
Aldo Cortesi 2015-04-17 13:06:45 +12:00
parent e963a9da48
commit d20069fcd2

View File

@ -231,8 +231,9 @@ class ConsoleMaster(flow.FlowMaster):
self.loop.set_alarm_in(seconds, cb) self.loop.set_alarm_in(seconds, cb)
def sig_pop_view_state(self, sender): def sig_pop_view_state(self, sender):
if self.view_stack: if len(self.view_stack) > 1:
self.loop.widget = self.view_stack.pop() self.view_stack.pop()
self.loop.widget = self.view_stack[-1]
else: else:
signals.status_prompt_onekey.send( signals.status_prompt_onekey.send(
self, self,
@ -244,8 +245,10 @@ class ConsoleMaster(flow.FlowMaster):
callback = self.quit, callback = self.quit,
) )
def sig_push_view_state(self, sender): def sig_push_view_state(self, sender, window):
self.view_stack.append(self.loop.widget) self.view_stack.append(window)
self.loop.widget = window
self.loop.draw_screen()
def start_stream_to_path(self, path, mode="wb"): def start_stream_to_path(self, path, mode="wb"):
path = os.path.expanduser(path) path = os.path.expanduser(path)
@ -463,46 +466,54 @@ class ConsoleMaster(flow.FlowMaster):
self.shutdown() self.shutdown()
def view_help(self, helpctx): def view_help(self, helpctx):
signals.push_view_state.send(self) signals.push_view_state.send(
self.loop.widget = window.Window(
self, self,
help.HelpView(helpctx), window = window.Window(
None, self,
statusbar.StatusBar(self, help.footer), help.HelpView(helpctx),
None None,
statusbar.StatusBar(self, help.footer),
None
)
) )
def view_options(self): def view_options(self):
for i in self.view_stack: for i in self.view_stack:
if isinstance(i["body"], options.Options): if isinstance(i["body"], options.Options):
return return
signals.push_view_state.send(self) signals.push_view_state.send(
self.loop.widget = window.Window(
self, self,
options.Options(self), window = window.Window(
None, self,
statusbar.StatusBar(self, options.footer), options.Options(self),
options.help_context, None,
statusbar.StatusBar(self, options.footer),
options.help_context,
)
) )
def view_palette_picker(self): def view_palette_picker(self):
signals.push_view_state.send(self) signals.push_view_state.send(
self.loop.widget = window.Window(
self, self,
palettepicker.PalettePicker(self), window = window.Window(
None, self,
statusbar.StatusBar(self, palettepicker.footer), palettepicker.PalettePicker(self),
palettepicker.help_context, None,
statusbar.StatusBar(self, palettepicker.footer),
palettepicker.help_context,
)
) )
def view_grideditor(self, ge): def view_grideditor(self, ge):
signals.push_view_state.send(self) signals.push_view_state.send(
self.loop.widget = window.Window(
self, self,
ge, window = window.Window(
None, self,
statusbar.StatusBar(self, grideditor.FOOTER), ge,
ge.make_help() None,
statusbar.StatusBar(self, grideditor.FOOTER),
ge.make_help()
)
) )
def view_flowlist(self): def view_flowlist(self):
@ -516,24 +527,28 @@ class ConsoleMaster(flow.FlowMaster):
else: else:
body = flowlist.FlowListBox(self) body = flowlist.FlowListBox(self)
self.loop.widget = window.Window( signals.push_view_state.send(
self, self,
body, window = window.Window(
None, self,
statusbar.StatusBar(self, flowlist.footer), body,
flowlist.help_context None,
statusbar.StatusBar(self, flowlist.footer),
flowlist.help_context
)
) )
self.loop.draw_screen()
def view_flow(self, flow, tab_offset=0): def view_flow(self, flow, tab_offset=0):
signals.push_view_state.send(self)
self.state.set_focus_flow(flow) self.state.set_focus_flow(flow)
self.loop.widget = window.Window( signals.push_view_state.send(
self, self,
flowview.FlowView(self, self.state, flow, tab_offset), window = window.Window(
flowview.FlowViewHeader(self, flow), self,
statusbar.StatusBar(self, flowview.footer), flowview.FlowView(self, self.state, flow, tab_offset),
flowview.help_context flowview.FlowViewHeader(self, flow),
statusbar.StatusBar(self, flowview.footer),
flowview.help_context
)
) )
def _write_flows(self, path, flows): def _write_flows(self, path, flows):