Mercurial > libervia-backend
changeset 1181:ca8ce5a47969
Primitivus: main_widget is now in its own class (PrimitivusTopWidget), menu and notification bar (un)hidding is cleaner
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 08 Sep 2014 15:50:51 +0200 (2014-09-08) |
parents | 69aace10b46d |
children | 4be53c14845e |
files | frontends/src/primitivus/primitivus |
diffstat | 1 files changed, 70 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/src/primitivus/primitivus Mon Sep 08 15:50:51 2014 +0200 +++ b/frontends/src/primitivus/primitivus Mon Sep 08 15:50:51 2014 +0200 @@ -177,6 +177,60 @@ return super(EditBar, self).keypress(size, key) +class PrimitivusTopWidget(sat_widgets.FocusPile): + """Top most widget used in Primitivus""" + _focus_inversed = True + positions = ('menu', 'body', 'notif_bar', 'edit_bar') + can_hide = ('menu', 'notif_bar') + + def __init__(self, body, menu, notif_bar, edit_bar): + self._body = body + self._menu = menu + self._notif_bar = notif_bar + self._edit_bar = edit_bar + self._hidden = {'notif_bar'} + super(PrimitivusTopWidget, self).__init__([('pack', self._menu), self._body, ('pack', self._edit_bar)]) + for position in self.positions: + setattr(self, + position, + property(lambda: self, self.widgetGet(position=position), + lambda pos, new_wid: self.widgetSet(new_wid, position=pos)) + ) + self.focus_position = len(self.contents)-1 + + def widgetGet(self, position): + if not position in self.positions: + raise ValueError("Unknown position {}".format(position)) + return getattr(self, "_{}".format(position)) + + def widgetSet(self, widget, position): + if not position in self.positions: + raise ValueError("Unknown position {}".format(position)) + return setattr(self, "_{}".format(position), widget) + + def hideSwitch(self, position): + if not position in self.can_hide: + raise ValueError("Can't switch position {}".format(position)) + hide = not position in self._hidden + visible_positions = [pos for pos in self.positions if pos == position or pos not in self._hidden] # we need to keep position to find its index + widget = self.widgetGet(position) + idx = visible_positions.index(position) + if hide: + del self.contents[idx] + self._hidden.add(position) + else: + self.contents.insert(idx, (widget, ('pack', None))) + self._hidden.remove(position) + + def show(self, position): + if position in self._hidden: + self.hideSwitch(position) + + def hide(self, position): + if not position in self._hidden: + self.hideSwitch(position) + + class PrimitivusApp(QuickApp, InputHistory): def __init__(self): @@ -188,10 +242,10 @@ ##misc setup## self.chat_wins = ChatList(self) - self.notBar = sat_widgets.NotificationBar() - urwid.connect_signal(self.notBar, 'change', self.onNotification) + self.notif_bar = sat_widgets.NotificationBar() + urwid.connect_signal(self.notif_bar, 'change', self.onNotification) self.progress_wid = Progress(self) - urwid.connect_signal(self.notBar.progress, 'click', lambda x: self.addWindow(self.progress_wid)) + urwid.connect_signal(self.notif_bar.progress, 'click', lambda x: self.addWindow(self.progress_wid)) self.__saved_overlay = None self.x_notify = Notify() @@ -268,15 +322,12 @@ if input_ == a_key['MENU_HIDE']: """User want to (un)hide the menu roller""" try: - if self.main_widget.header == None: - self.main_widget.header = self.menu_roller - else: - self.main_widget.header = None + self.main_widget.hideSwitch('menu') except AttributeError: pass elif input_ == a_key['NOTIFICATION_NEXT']: """User wants to see next notification""" - self.notBar.showNext() + self.notif_bar.showNext() elif input_ == a_key['OVERLAY_HIDE']: """User wants to (un)hide overlay window""" if isinstance(self.loop.widget,urwid.Overlay): @@ -357,7 +408,7 @@ self.editBar = EditBar(self) self.menu_roller = self._buildMenuRoller() - self.main_widget = sat_widgets.FocusFrame(self.center_part, header=self.menu_roller, footer=self.editBar, focus_part='footer') + self.main_widget = PrimitivusTopWidget(self.center_part, self.menu_roller, self.notif_bar, self.editBar) return self.main_widget def plug_profile_1(self, profile_key='@DEFAULT@'): @@ -375,7 +426,7 @@ def removePopUp(self, widget=None): "Remove current pop-up, and if there is other in queue, show it" self.loop.widget = self.main_widget - next_popup = self.notBar.getNextPopup() + next_popup = self.notif_bar.getNextPopup() if next_popup: #we still have popup to show, we display it self.showPopUp(next_popup) @@ -387,11 +438,11 @@ self.loop.widget = display_widget self.redraw() else: - self.notBar.addPopUp(pop_up_widget) + self.notif_bar.addPopUp(pop_up_widget) def notify(self, message): """"Notify message to user via notification bar""" - self.notBar.addMessage(message) + self.notif_bar.addMessage(message) self.redraw() def addWindow(self, widget): @@ -422,7 +473,7 @@ def setProgress(self, percentage): """Set the progression shown in notification bar""" - self.notBar.setProgress(percentage) + self.notif_bar.setProgress(percentage) def contactSelected(self, contact_list): contact = contact_list.getContact() @@ -469,23 +520,16 @@ log.error(_('unmanaged dialog type: %s'), type_) self.showPopUp(popup) - def onNotification(self, notBar): + def onNotification(self, notif_bar): """Called when a new notification has been received""" - if not isinstance(self.main_widget, sat_widgets.FocusFrame): + if not isinstance(self.main_widget, PrimitivusTopWidget): #if we are not in the main configuration, we ignore the notifications bar return - if isinstance(self.main_widget.footer,sat_widgets.AdvancedEdit): - if not self.notBar.canHide(): - #the notification bar is not visible and has usefull informations, we show it - pile = urwid.Pile([self.notBar, self.editBar]) - self.main_widget.footer = pile + if self.notif_bar.canHide(): + #No notification left, we can hide the bar + self.main_widget.hide('notif_bar') else: - if not isinstance(self.main_widget.footer, urwid.Pile): - log.error(_("INTERNAL ERROR: Unexpected class for main widget's footer")) - assert(False) - if self.notBar.canHide(): - #No notification left, we can hide the bar - self.main_widget.footer = self.editBar + self.main_widget.show('notif_bar') def launchAction(self, callback_id, data=None, profile_key="@NONE@"): """ Launch a dynamic action