Mercurial > libervia-backend
changeset 1580:641cfd2faefe
Primitivus: better popups handling:
- widget to remove can now be specified in removePopUp: if it is not the current one, it will be removed from queue
- Primitivus.Alert method is a shortcut to display an Alert which will be removed on "OK" press
- showDialog is now obsolete and removed, if generic dialog creation is needed, XMLUI can be used
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 11 Nov 2015 18:32:59 +0100 |
parents | d5e332055d9f |
children | 8cc7d83141a4 |
files | frontends/src/primitivus/chat.py frontends/src/primitivus/primitivus frontends/src/primitivus/xmlui.py frontends/src/quick_frontend/quick_app.py |
diffstat | 4 files changed, 59 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/src/primitivus/chat.py Wed Nov 11 18:29:32 2015 +0100 +++ b/frontends/src/primitivus/chat.py Wed Nov 11 18:32:59 2015 +0100 @@ -22,7 +22,7 @@ log = logging.getLogger(__name__) import urwid from urwid_satext import sat_widgets -from urwid_satext.files_management import FileDialog +# from urwid_satext.files_management import FileDialog # FIXME from sat_frontends.quick_frontend import quick_widgets from sat_frontends.quick_frontend.quick_chat import QuickChat from sat_frontends.quick_frontend import quick_games @@ -378,27 +378,29 @@ def onSendFileRequest(self, menu): # TODO: move this to core with dynamic menus - dialog = FileDialog(ok_cb=self.onFileSelected, cancel_cb=self.host.removePopUp) - self.host.showPopUp(dialog, 80, 80) + pass + # dialog = FileDialog(ok_cb=self.onFileSelected, cancel_cb=self.host.removePopUp) # FIXME: to be removed + # self.host.showPopUp(dialog, 80, 80) # MISC EVENTS # - def onFileSelected(self, filepath): - self.host.removePopUp() - try: - filepath = filepath.decode('utf-8') # FIXME: correctly manage unicode - except UnicodeError: - log.error("FIXME: filepath with unicode error are not managed yet") - self.host.showDialog(_(u"File has a unicode error in its name, it's not yet managed by SàT"), title=_("Can't send file"), type_="error") - return - # FIXME: check last_resource: what if self.target.resource exists ? - last_resource = self.host.bridge.getMainResource(unicode(self.target.bare), self.profile) - if last_resource: - full_jid = jid.JID("%s/%s" % (self.target.bare, last_resource)) - else: - full_jid = self.target - progress_id = self.host.bridge.sendFile(full_jid, filepath, {}, self.profile) - self.host.addProgress(progress_id, filepath) - self.host.showDialog(_(u"You file request has been sent, we are waiting for your contact answer"), title=_("File request sent")) + # FIXME: to be removed + # def onFileSelected(self, filepath): + # self.host.removePopUp() + # try: + # filepath = filepath.decode('utf-8') # FIXME: correctly manage unicode + # except UnicodeError: + # log.error("FIXME: filepath with unicode error are not managed yet") + # self.host.showDialog(_(u"File has a unicode error in its name, it's not yet managed by SàT"), title=_("Can't send file"), type_="error") + # return + # # FIXME: check last_resource: what if self.target.resource exists ? + # last_resource = self.host.bridge.getMainResource(unicode(self.target.bare), self.profile) + # if last_resource: + # full_jid = jid.JID("%s/%s" % (self.target.bare, last_resource)) + # else: + # full_jid = self.target + # progress_id = self.host.bridge.sendFile(full_jid, filepath, {}, self.profile) + # self.host.addProgress(progress_id, filepath) + # self.host.showDialog(_(u"You file request has been sent, we are waiting for your contact answer"), title=_("File request sent")) def onDelete(self): QuickChat.onDelete(self)
--- a/frontends/src/primitivus/primitivus Wed Nov 11 18:29:32 2015 +0100 +++ b/frontends/src/primitivus/primitivus Wed Nov 11 18:32:59 2015 +0100 @@ -350,7 +350,7 @@ config.applyConfig(self) except Exception as e: log.error(u"configuration error: {}".format(e)) - popup = sat_widgets.Alert(_("Configuration Error"), _("Something went wrong while reading the configuration, please check :messages"), ok_cb=self.removePopUp) + popup = self.Alert(_(u"Configuration Error"), _(u"Something went wrong while reading the configuration, please check :messages")) if self.options.profile: self._early_popup = popup else: @@ -479,13 +479,38 @@ else: del self._early_popup + def Alert(self, title, message): + """Shortcut method to create an alert message + + Alert will have an "OK" button, which remove it if pressed + @param title(unicode): title of the dialog + @param message(unicode): body of the dialog + @return (urwid_satext.Alert): the create Alert instance + """ + popup = sat_widgets.Alert(title, message) + popup.setCallback('ok', lambda dummy: self.removePopUp(popup)) + self.showPopUp(popup) + return popup + def removePopUp(self, widget=None): - "Remove current pop-up, and if there is other in queue, show it" + """Remove current pop-up, and if there is other in queue, show it + + @param widget(None, urwid.Widget): if not None remove this popup from front or queue + """ + # TODO: refactor popup management in a cleaner way + if widget is not None: + if isinstance(self.loop.widget, urwid.Overlay): + current_popup = self.loop.widget.top_w + if not current_popup == widget: + self.notif_bar.removePopUp(widget) + return self.loop.widget = self.main_widget next_popup = self.notif_bar.getNextPopup() if next_popup: #we still have popup to show, we display it self.showPopUp(next_popup) + else: + self.redraw() def showPopUp(self, pop_up_widget, perc_width=40, perc_height=40, align='center', valign='middle'): "Show a pop-up window if possible, else put it in queue" @@ -569,26 +594,12 @@ answer_data = [data[1]] if data[1] else [] answer_cb(False, *answer_data) - def showDialog(self, message, title="", type_="info", answer_cb = None, answer_data = None): - if type_ == 'info': - popup = sat_widgets.Alert(unicode(title), unicode(message), ok_cb=answer_cb or self.removePopUp) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore - elif type_ == 'error': - popup = sat_widgets.Alert(unicode(title), unicode(message), ok_cb=answer_cb or self.removePopUp) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore - elif type_ == 'yes/no': - popup = sat_widgets.ConfirmDialog(unicode(message), - yes_cb=self._dialogOkCb, yes_value = (answer_cb, answer_data), - no_cb=self._dialogCancelCb, no_value = (answer_cb, answer_data)) - else: - popup = sat_widgets.Alert(unicode(title), unicode(message), ok_cb=answer_cb or self.removePopUp) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore - log.error(_('unmanaged dialog type: %s'), type_) - self.showPopUp(popup) - def dialogFailure(self, failure): """Show a failure that has been returned by an asynchronous bridge method. @param failure (defer.Failure): Failure instance """ - self.showPopUp(sat_widgets.Alert(failure.classname, failure.message, ok_cb=self.removePopUp)) + self.Alert(failure.classname, failure.message) def onNotification(self, notif_bar): """Called when a new notification has been received""" @@ -602,7 +613,7 @@ self.main_widget.show('notif_bar') def _actionManagerUnknownError(self): - self.showPopUp(sat_widgets.Alert(_("Error"), _(u"Unmanaged action"), ok_cb=self.removePopUp)) + self.Alert(_("Error"), _(u"Unmanaged action")) def askConfirmationHandler(self, confirmation_id, confirmation_type, data, profile): answer_data = {} @@ -659,7 +670,7 @@ ui.show('window') elif type_ == "ERROR": self.current_action_ids.remove(id) - self.showPopUp(sat_widgets.Alert(_("Error"), unicode(data["message"]), ok_cb=self.removePopUp)) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore + self.Alert(_("Error"), unicode(data["message"])) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore elif type_ == "RESULT": self.current_action_ids.remove(id) if self.current_action_ids_cb.has_key(id): @@ -702,7 +713,7 @@ ui.show() def failure(error): - self.showPopUp(sat_widgets.Alert(_("Error"), _("Can't get parameters (%s)") % error, ok_cb=self.removePopUp)) + self.Alert(_("Error"), _("Can't get parameters (%s)") % error) self.bridge.getParamsUI(app=C.APP_NAME, profile_key=self.current_profile, callback=success, errback=failure) def onExitRequest(self, menu): @@ -711,11 +722,12 @@ def onJoinRoomRequest(self, menu): """User wants to join a MUC room""" - pop_up_widget = sat_widgets.InputDialog(_("Entering a MUC room"), _("Please enter MUC's JID"), default_txt=self.bridge.getDefaultMUC(), cancel_cb=self.removePopUp, ok_cb=self.onJoinRoom) + pop_up_widget = sat_widgets.InputDialog(_("Entering a MUC room"), _("Please enter MUC's JID"), default_txt=self.bridge.getDefaultMUC(), ok_cb=self.onJoinRoom) + pop_up_widget.setCallback('cancel', lambda dummy: self.removePopUp(pop_up_widget)) self.showPopUp(pop_up_widget) def onAboutRequest(self, menu): - self.showPopUp(sat_widgets.Alert(_("About"), C.APP_NAME + " v" + self.bridge.getVersion(), ok_cb=self.removePopUp)) + self.Alert(_("About"), C.APP_NAME + " v" + self.bridge.getVersion()) #MISC CALLBACKS#
--- a/frontends/src/primitivus/xmlui.py Wed Nov 11 18:29:32 2015 +0100 +++ b/frontends/src/primitivus/xmlui.py Wed Nov 11 18:32:59 2015 +0100 @@ -328,7 +328,7 @@ self.host.showPopUp(self) def _xmluiClose(self): - self.host.removePopUp() + self.host.removePopUp(self) class PrimitivusMessageDialog(PrimitivusDialog, xmlui.MessageDialog, sat_widgets.Alert): @@ -455,7 +455,7 @@ if self._dest == 'window': self.host.removeWindow() elif self._dest == 'popup': - self.host.removePopUp() + self.host.removePopUp(self) else: raise exceptions.InternalError("self._dest unknown, are you sure you have called XMLUI.show ?")