From c7ed7ab38a1e6ec36e45084020ff9e997b640312 Mon Sep 17 00:00:00 2001 From: "Cody A.W. Somerville" Date: Tue, 8 Mar 2016 01:50:55 -0500 Subject: [PATCH] Make 'title' attribute available on dialog widgets Gertty uses WidgetWraps around the LineBox widget for popup widgets. Add LineBoxTitlePropertyMixin which adds property and setter for title attribute, accessing the underlying title_widget on the wrapped LineBox widget. We use the popup method in the controller to display these dialogs. It uses an Overlay widget to display our dialog widget on top of the current view. If the widget to be displayed by the Overlay widget has title attribute, copy it to the Overlay widget. Change-Id: I4c6ecbc7ed87867cd67cd93c1125384dd5d4b9af --- gertty/app.py | 2 ++ gertty/mywid.py | 18 ++++++++++++++---- gertty/view/change.py | 4 ++-- gertty/view/diff.py | 2 +- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/gertty/app.py b/gertty/app.py index 1794d10..4227094 100644 --- a/gertty/app.py +++ b/gertty/app.py @@ -453,6 +453,8 @@ class App(object): 'center', width, 'middle', height, min_width=min_width, min_height=min_height) + if hasattr(widget, 'title'): + overlay.title = widget.title self.log.debug("Overlaying %s on screen %s" % (widget, self.frame.body)) self.screens.append(self.frame.body) self.frame.body = overlay diff --git a/gertty/mywid.py b/gertty/mywid.py index 521c33a..02dab27 100644 --- a/gertty/mywid.py +++ b/gertty/mywid.py @@ -128,13 +128,23 @@ class MyEdit(urwid.Edit): self.ring.kill(text) return super(MyEdit, self).keypress(size, key) -class SystemMessage(urwid.WidgetWrap): +class LineBoxTitlePropertyMixin(object): + + @property + def title(self): + return self._w.title_widget.text.strip() + + @title.setter + def title(self, text): + return self._w.set_title(text) + +class SystemMessage(urwid.WidgetWrap, LineBoxTitlePropertyMixin): def __init__(self, message): w = urwid.Filler(urwid.Text(message, align='center')) - super(SystemMessage, self).__init__(urwid.LineBox(w)) + super(SystemMessage, self).__init__(urwid.LineBox(w, u'System Message')) @mouse_scroll_decorator.ScrollByWheel -class ButtonDialog(urwid.WidgetWrap): +class ButtonDialog(urwid.WidgetWrap, LineBoxTitlePropertyMixin): def __init__(self, title, message, entry_prompt=None, entry_text='', buttons=[], ring=None): button_widgets = [] @@ -180,7 +190,7 @@ class LineEditDialog(ButtonDialog): return None return key -class TextEditDialog(urwid.WidgetWrap): +class TextEditDialog(urwid.WidgetWrap, LineBoxTitlePropertyMixin): signals = ['save', 'cancel'] def __init__(self, title, prompt, button, text, ring=None): save_button = FixedButton(button) diff --git a/gertty/view/change.py b/gertty/view/change.py index 330f15b..7b1ad0a 100644 --- a/gertty/view/change.py +++ b/gertty/view/change.py @@ -56,7 +56,7 @@ class EditTopicDialog(mywid.ButtonDialog): return None return key -class CherryPickDialog(urwid.WidgetWrap): +class CherryPickDialog(urwid.WidgetWrap, mywid.LineBoxTitlePropertyMixin): signals = ['save', 'cancel'] def __init__(self, app, change): save_button = mywid.FixedButton('Propose Change') @@ -87,7 +87,7 @@ class CherryPickDialog(urwid.WidgetWrap): super(CherryPickDialog, self).__init__(urwid.LineBox(fill, 'Propose Change to Branch')) -class ReviewDialog(urwid.WidgetWrap): +class ReviewDialog(urwid.WidgetWrap, mywid.LineBoxTitlePropertyMixin): signals = ['submit', 'save', 'cancel'] def __init__(self, app, revision_key): self.revision_key = revision_key diff --git a/gertty/view/diff.py b/gertty/view/diff.py index 6a12e67..483f06d 100644 --- a/gertty/view/diff.py +++ b/gertty/view/diff.py @@ -24,7 +24,7 @@ from gertty import gitrepo from gertty import sync from gertty.view import mouse_scroll_decorator -class PatchsetDialog(urwid.WidgetWrap): +class PatchsetDialog(urwid.WidgetWrap, mywid.LineBoxTitlePropertyMixin): signals = ['ok', 'cancel'] def __init__(self, patchsets, old, new):