Skip to content

Commit

Permalink
move stretchy signals from overlay to stretchy itself
Browse files Browse the repository at this point in the history
Also add overridable opened/closed hooks.
  • Loading branch information
mwhudson committed Sep 12, 2019
1 parent 8e29d93 commit 947f14a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
14 changes: 11 additions & 3 deletions subiquitycore/ui/stretchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@
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
Expand All @@ -64,6 +67,13 @@ def __init__(self, title, widgets, stretchy_index, focus_index):
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]
Expand All @@ -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
Expand Down
12 changes: 9 additions & 3 deletions subiquitycore/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -60,12 +64,14 @@ def show_overlay(self, overlay_widget, **kw):
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

Expand Down

0 comments on commit 947f14a

Please sign in to comment.