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
This commit is contained in:
Goffi 2015-11-11 18:32:59 +01:00
commit 73139e59ba

View file

@ -22,7 +22,7 @@ from sat.core import log as logging
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 @@ class Chat(PrimitivusWidget, QuickChat):
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)