comparison frontends/src/primitivus/primitivus @ 1582:a41cc0849008

primitivus: partly reverted commit 641cfd2faefe : - showDialog is actually still used and useful - updated the code to use the widget argument in removePopup
author Goffi <goffi@goffi.org>
date Fri, 13 Nov 2015 16:45:56 +0100
parents 641cfd2faefe
children 66f0e877625b
comparison
equal deleted inserted replaced
1581:8cc7d83141a4 1582:a41cc0849008
581 chat_widget = self.widgets.getOrCreateWidget(Chat, entity, on_new_widget=None, profile=contact_list.profile) 581 chat_widget = self.widgets.getOrCreateWidget(Chat, entity, on_new_widget=None, profile=contact_list.profile)
582 self.selectWidget(chat_widget) 582 self.selectWidget(chat_widget)
583 self.menu_roller.addMenu(_('Chat menu'), chat_widget.getMenu(), C.MENU_ID_WIDGET) 583 self.menu_roller.addMenu(_('Chat menu'), chat_widget.getMenu(), C.MENU_ID_WIDGET)
584 584
585 def _dialogOkCb(self, widget, data): 585 def _dialogOkCb(self, widget, data):
586 self.removePopUp() 586 popup, answer_cb, answer_data = data
587 answer_cb = data[0] 587 self.removePopUp(popup)
588 answer_data = [data[1]] if data[1] else []
589 answer_cb(True, *answer_data) 588 answer_cb(True, *answer_data)
590 589
591 def _dialogCancelCb(self, widget, data): 590 def _dialogCancelCb(self, widget, data):
592 self.removePopUp() 591 popup, answer_cb, answer_data = data
593 answer_cb = data[0] 592 self.removePopUp(popup)
594 answer_data = [data[1]] if data[1] else []
595 answer_cb(False, *answer_data) 593 answer_cb(False, *answer_data)
594
595 def showDialog(self, message, title="", type_="info", answer_cb = None, answer_data = None):
596 if type_ == 'info':
597 popup = sat_widgets.Alert(title, message, ok_cb=answer_cb)
598 if answer_cb is None:
599 popup.setCallback('ok', lambda dummy: self.removePopUp(popup))
600 elif type_ == 'error':
601 popup = sat_widgets.Alert(title, message, ok_cb=answer_cb)
602 if answer_cb is None:
603 popup.setCallback('ok', lambda dummy: self.removePopUp(popup))
604 elif type_ == 'yes/no':
605 popup = sat_widgets.ConfirmDialog(message,
606 yes_cb=self._dialogOkCb, yes_value = (popup, answer_cb, answer_data),
607 no_cb=self._dialogCancelCb, no_value = (popup, answer_cb, answer_data))
608 else:
609 popup = sat_widgets.Alert(title, message, ok_cb=answer_cb)
610 if answer_cb is None:
611 popup.setCallback('ok', lambda dummy: self.removePopUp(popup))
612 log.error(u'unmanaged dialog type: {}'.format(type_))
613 self.showPopUp(popup)
596 614
597 def dialogFailure(self, failure): 615 def dialogFailure(self, failure):
598 """Show a failure that has been returned by an asynchronous bridge method. 616 """Show a failure that has been returned by an asynchronous bridge method.
599 617
600 @param failure (defer.Failure): Failure instance 618 @param failure (defer.Failure): Failure instance