Mercurial > libervia-backend
comparison frontends/src/primitivus/primitivus @ 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 | 731fbed0b9cf |
children | a41cc0849008 |
comparison
equal
deleted
inserted
replaced
1579:d5e332055d9f | 1580:641cfd2faefe |
---|---|
348 def postInit(self): | 348 def postInit(self): |
349 try: | 349 try: |
350 config.applyConfig(self) | 350 config.applyConfig(self) |
351 except Exception as e: | 351 except Exception as e: |
352 log.error(u"configuration error: {}".format(e)) | 352 log.error(u"configuration error: {}".format(e)) |
353 popup = sat_widgets.Alert(_("Configuration Error"), _("Something went wrong while reading the configuration, please check :messages"), ok_cb=self.removePopUp) | 353 popup = self.Alert(_(u"Configuration Error"), _(u"Something went wrong while reading the configuration, please check :messages")) |
354 if self.options.profile: | 354 if self.options.profile: |
355 self._early_popup = popup | 355 self._early_popup = popup |
356 else: | 356 else: |
357 self.showPopUp(popup) | 357 self.showPopUp(popup) |
358 super(PrimitivusApp, self).postInit(self.main_widget) | 358 super(PrimitivusApp, self).postInit(self.main_widget) |
477 except AttributeError: | 477 except AttributeError: |
478 pass | 478 pass |
479 else: | 479 else: |
480 del self._early_popup | 480 del self._early_popup |
481 | 481 |
482 def Alert(self, title, message): | |
483 """Shortcut method to create an alert message | |
484 | |
485 Alert will have an "OK" button, which remove it if pressed | |
486 @param title(unicode): title of the dialog | |
487 @param message(unicode): body of the dialog | |
488 @return (urwid_satext.Alert): the create Alert instance | |
489 """ | |
490 popup = sat_widgets.Alert(title, message) | |
491 popup.setCallback('ok', lambda dummy: self.removePopUp(popup)) | |
492 self.showPopUp(popup) | |
493 return popup | |
494 | |
482 def removePopUp(self, widget=None): | 495 def removePopUp(self, widget=None): |
483 "Remove current pop-up, and if there is other in queue, show it" | 496 """Remove current pop-up, and if there is other in queue, show it |
497 | |
498 @param widget(None, urwid.Widget): if not None remove this popup from front or queue | |
499 """ | |
500 # TODO: refactor popup management in a cleaner way | |
501 if widget is not None: | |
502 if isinstance(self.loop.widget, urwid.Overlay): | |
503 current_popup = self.loop.widget.top_w | |
504 if not current_popup == widget: | |
505 self.notif_bar.removePopUp(widget) | |
506 return | |
484 self.loop.widget = self.main_widget | 507 self.loop.widget = self.main_widget |
485 next_popup = self.notif_bar.getNextPopup() | 508 next_popup = self.notif_bar.getNextPopup() |
486 if next_popup: | 509 if next_popup: |
487 #we still have popup to show, we display it | 510 #we still have popup to show, we display it |
488 self.showPopUp(next_popup) | 511 self.showPopUp(next_popup) |
512 else: | |
513 self.redraw() | |
489 | 514 |
490 def showPopUp(self, pop_up_widget, perc_width=40, perc_height=40, align='center', valign='middle'): | 515 def showPopUp(self, pop_up_widget, perc_width=40, perc_height=40, align='center', valign='middle'): |
491 "Show a pop-up window if possible, else put it in queue" | 516 "Show a pop-up window if possible, else put it in queue" |
492 if not isinstance(self.loop.widget, urwid.Overlay): | 517 if not isinstance(self.loop.widget, urwid.Overlay): |
493 display_widget = urwid.Overlay(pop_up_widget, self.main_widget, align, ('relative', perc_width), valign, ('relative', perc_height)) | 518 display_widget = urwid.Overlay(pop_up_widget, self.main_widget, align, ('relative', perc_width), valign, ('relative', perc_height)) |
567 self.removePopUp() | 592 self.removePopUp() |
568 answer_cb = data[0] | 593 answer_cb = data[0] |
569 answer_data = [data[1]] if data[1] else [] | 594 answer_data = [data[1]] if data[1] else [] |
570 answer_cb(False, *answer_data) | 595 answer_cb(False, *answer_data) |
571 | 596 |
572 def showDialog(self, message, title="", type_="info", answer_cb = None, answer_data = None): | |
573 if type_ == 'info': | |
574 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 | |
575 elif type_ == 'error': | |
576 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 | |
577 elif type_ == 'yes/no': | |
578 popup = sat_widgets.ConfirmDialog(unicode(message), | |
579 yes_cb=self._dialogOkCb, yes_value = (answer_cb, answer_data), | |
580 no_cb=self._dialogCancelCb, no_value = (answer_cb, answer_data)) | |
581 else: | |
582 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 | |
583 log.error(_('unmanaged dialog type: %s'), type_) | |
584 self.showPopUp(popup) | |
585 | |
586 def dialogFailure(self, failure): | 597 def dialogFailure(self, failure): |
587 """Show a failure that has been returned by an asynchronous bridge method. | 598 """Show a failure that has been returned by an asynchronous bridge method. |
588 | 599 |
589 @param failure (defer.Failure): Failure instance | 600 @param failure (defer.Failure): Failure instance |
590 """ | 601 """ |
591 self.showPopUp(sat_widgets.Alert(failure.classname, failure.message, ok_cb=self.removePopUp)) | 602 self.Alert(failure.classname, failure.message) |
592 | 603 |
593 def onNotification(self, notif_bar): | 604 def onNotification(self, notif_bar): |
594 """Called when a new notification has been received""" | 605 """Called when a new notification has been received""" |
595 if not isinstance(self.main_widget, PrimitivusTopWidget): | 606 if not isinstance(self.main_widget, PrimitivusTopWidget): |
596 #if we are not in the main configuration, we ignore the notifications bar | 607 #if we are not in the main configuration, we ignore the notifications bar |
600 self.main_widget.hide('notif_bar') | 611 self.main_widget.hide('notif_bar') |
601 else: | 612 else: |
602 self.main_widget.show('notif_bar') | 613 self.main_widget.show('notif_bar') |
603 | 614 |
604 def _actionManagerUnknownError(self): | 615 def _actionManagerUnknownError(self): |
605 self.showPopUp(sat_widgets.Alert(_("Error"), _(u"Unmanaged action"), ok_cb=self.removePopUp)) | 616 self.Alert(_("Error"), _(u"Unmanaged action")) |
606 | 617 |
607 def askConfirmationHandler(self, confirmation_id, confirmation_type, data, profile): | 618 def askConfirmationHandler(self, confirmation_id, confirmation_type, data, profile): |
608 answer_data = {} | 619 answer_data = {} |
609 | 620 |
610 def dir_selected_cb(path): | 621 def dir_selected_cb(path): |
657 ui.show('popup') | 668 ui.show('popup') |
658 else: | 669 else: |
659 ui.show('window') | 670 ui.show('window') |
660 elif type_ == "ERROR": | 671 elif type_ == "ERROR": |
661 self.current_action_ids.remove(id) | 672 self.current_action_ids.remove(id) |
662 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 | 673 self.Alert(_("Error"), unicode(data["message"])) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore |
663 elif type_ == "RESULT": | 674 elif type_ == "RESULT": |
664 self.current_action_ids.remove(id) | 675 self.current_action_ids.remove(id) |
665 if self.current_action_ids_cb.has_key(id): | 676 if self.current_action_ids_cb.has_key(id): |
666 callback = self.current_action_ids_cb[id] | 677 callback = self.current_action_ids_cb[id] |
667 del self.current_action_ids_cb[id] | 678 del self.current_action_ids_cb[id] |
700 def success(params): | 711 def success(params): |
701 ui = xmlui.create(self, xml_data=params, profile=self.current_profile) | 712 ui = xmlui.create(self, xml_data=params, profile=self.current_profile) |
702 ui.show() | 713 ui.show() |
703 | 714 |
704 def failure(error): | 715 def failure(error): |
705 self.showPopUp(sat_widgets.Alert(_("Error"), _("Can't get parameters (%s)") % error, ok_cb=self.removePopUp)) | 716 self.Alert(_("Error"), _("Can't get parameters (%s)") % error) |
706 self.bridge.getParamsUI(app=C.APP_NAME, profile_key=self.current_profile, callback=success, errback=failure) | 717 self.bridge.getParamsUI(app=C.APP_NAME, profile_key=self.current_profile, callback=success, errback=failure) |
707 | 718 |
708 def onExitRequest(self, menu): | 719 def onExitRequest(self, menu): |
709 QuickApp.onExit(self) | 720 QuickApp.onExit(self) |
710 raise urwid.ExitMainLoop() | 721 raise urwid.ExitMainLoop() |
711 | 722 |
712 def onJoinRoomRequest(self, menu): | 723 def onJoinRoomRequest(self, menu): |
713 """User wants to join a MUC room""" | 724 """User wants to join a MUC room""" |
714 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) | 725 pop_up_widget = sat_widgets.InputDialog(_("Entering a MUC room"), _("Please enter MUC's JID"), default_txt=self.bridge.getDefaultMUC(), ok_cb=self.onJoinRoom) |
726 pop_up_widget.setCallback('cancel', lambda dummy: self.removePopUp(pop_up_widget)) | |
715 self.showPopUp(pop_up_widget) | 727 self.showPopUp(pop_up_widget) |
716 | 728 |
717 def onAboutRequest(self, menu): | 729 def onAboutRequest(self, menu): |
718 self.showPopUp(sat_widgets.Alert(_("About"), C.APP_NAME + " v" + self.bridge.getVersion(), ok_cb=self.removePopUp)) | 730 self.Alert(_("About"), C.APP_NAME + " v" + self.bridge.getVersion()) |
719 | 731 |
720 #MISC CALLBACKS# | 732 #MISC CALLBACKS# |
721 | 733 |
722 def setPresenceStatus(self, show='', status=None, profile=C.PROF_KEY_NONE): | 734 def setPresenceStatus(self, show='', status=None, profile=C.PROF_KEY_NONE): |
723 self.contact_lists[profile].status_bar.setPresenceStatus(show, status) | 735 self.contact_lists[profile].status_bar.setPresenceStatus(show, status) |