Merge pull request #538 from mwhudson/move-stretchy-signals
move stretchy signals from overlay to stretchy itself
This commit is contained in:
commit
f82864ef72
|
@ -51,7 +51,10 @@ import urwid
|
|||
from subiquitycore.ui.container import ListBox, Pile
|
||||
|
||||
|
||||
class Stretchy:
|
||||
class Stretchy(metaclass=urwid.MetaSignals):
|
||||
|
||||
signals = ['opened', 'closed']
|
||||
|
||||
def __init__(self, title, widgets, stretchy_index, focus_index):
|
||||
"""
|
||||
title: goes in the LineBox
|
||||
|
@ -64,6 +67,13 @@ class Stretchy:
|
|||
self.stretchy_index = stretchy_index
|
||||
self.focus_index = focus_index
|
||||
|
||||
def opened(self):
|
||||
"""Called when the stretchy is placed on the screen."""
|
||||
pass
|
||||
|
||||
def closed(self):
|
||||
"""Called when the stretchy is removed from the screen."""
|
||||
|
||||
@property
|
||||
def stretchy_w(self):
|
||||
return self.widgets[self.stretchy_index]
|
||||
|
@ -73,8 +83,6 @@ class StretchyOverlay(urwid.Widget):
|
|||
_selectable = True
|
||||
_sizing = frozenset([urwid.BOX])
|
||||
|
||||
signals = ['closed']
|
||||
|
||||
def __init__(self, bottom_w, stretchy):
|
||||
self.bottom_w = bottom_w
|
||||
self.stretchy = stretchy
|
||||
|
|
|
@ -18,7 +18,11 @@
|
|||
Contains some default key navigations
|
||||
"""
|
||||
|
||||
from urwid import Overlay, Text
|
||||
from urwid import (
|
||||
emit_signal,
|
||||
Overlay,
|
||||
Text,
|
||||
)
|
||||
|
||||
from subiquitycore.ui.container import (
|
||||
Columns,
|
||||
|
@ -60,12 +64,14 @@ class BaseView(WidgetWrap):
|
|||
self._w = Overlay(top_w=top, bottom_w=disabled(self._w), **args)
|
||||
|
||||
def show_stretchy_overlay(self, stretchy):
|
||||
emit_signal(stretchy, 'opened')
|
||||
stretchy.opened()
|
||||
self._w = StretchyOverlay(disabled(self._w), stretchy)
|
||||
return self._w
|
||||
|
||||
def remove_overlay(self):
|
||||
if isinstance(self._w, StretchyOverlay):
|
||||
self._w._emit('closed')
|
||||
emit_signal(self._w.stretchy, 'closed')
|
||||
self._w.stretchy.closed()
|
||||
# disabled() wraps a widget in two decorations.
|
||||
self._w = self._w.bottom_w.original_widget.original_widget
|
||||
|
||||
|
|
Loading…
Reference in New Issue