From 8988d63f3321c2c1e90517a0a08c6d9a165cebeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Cort=C3=A9z?= Date: Sat, 30 Apr 2016 06:16:16 -0500 Subject: [PATCH] Fixed audio upload dialog --- src/controller/messages.py | 2 +- src/extra/AudioUploader/audioUploader.py | 8 ++++---- src/extra/AudioUploader/transfer.py | 7 ++++--- src/extra/AudioUploader/wx_transfer_dialogs.py | 5 +++-- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/controller/messages.py b/src/controller/messages.py index 0a4aba36..ff64aaa8 100644 --- a/src/controller/messages.py +++ b/src/controller/messages.py @@ -102,7 +102,7 @@ class basicTweet(object): self.message.text_focus() def attach(self, *args, **kwargs): - def completed_callback(): + def completed_callback(dlg): url = dlg.uploaderFunction.get_url() pub.unsubscribe(dlg.uploaderDialog.update, "uploading") dlg.uploaderDialog.destroy() diff --git a/src/extra/AudioUploader/audioUploader.py b/src/extra/AudioUploader/audioUploader.py index 73299df6..4c62c5c7 100644 --- a/src/extra/AudioUploader/audioUploader.py +++ b/src/extra/AudioUploader/audioUploader.py @@ -57,13 +57,13 @@ class audioUploader(object): url = base_url + '?apikey=' + self.config['sound']['sndup_api_key'] else: url = base_url - self.uploaderFunction = transfer.Upload(field='file', url=url, filename=self.file, completed_callback=completed_callback) + self.uploaderFunction = transfer.Upload(obj=self, field='file', url=url, filename=self.file, completed_callback=completed_callback) elif self.dialog.get("services") == "TwUp": url = "http://api.twup.me/post.json" - self.uploaderFunction = transfer.Upload(field='file', url=url, filename=self.file, completed_callback=completed_callback) + self.uploaderFunction = transfer.Upload(obj=self, field='file', url=url, filename=self.file, completed_callback=completed_callback) pub.subscribe(self.uploaderDialog.update, "uploading") - self.uploaderDialog.get_response() - self.uploaderFunction.perform_threaded() + self.uploaderDialog.get_response(self.uploaderFunction.perform_threaded) +# self.uploaderFunction.perform_threaded() def get_available_services(self): services = [] diff --git a/src/extra/AudioUploader/transfer.py b/src/extra/AudioUploader/transfer.py index 2b80a94e..b8dc8b22 100644 --- a/src/extra/AudioUploader/transfer.py +++ b/src/extra/AudioUploader/transfer.py @@ -11,7 +11,7 @@ from pubsub import pub log = logging.getLogger("extra.AudioUploader.transfer") class Transfer(object): - def __init__(self, url=None, filename=None, follow_location=True, completed_callback=None, verbose=False, *args, **kwargs): + def __init__(self, obj=None, url=None, filename=None, follow_location=True, completed_callback=None, verbose=False, *args, **kwargs): self.url = url self.filename = filename log.debug("Uploading audio to %s, filename %s" % (url, filename)) @@ -27,6 +27,7 @@ class Transfer(object): self.curl.setopt(self.curl.FOLLOWLOCATION, int(follow_location)) self.curl.setopt(self.curl.VERBOSE, int(verbose)) super(Transfer, self).__init__(*args, **kwargs) + self.obj = obj def elapsed_time(self): if not self.start_time: @@ -61,7 +62,7 @@ class Transfer(object): log.debug("Upload finished.") self.complete_transfer() - def perform_threaded(self): + def perform_threaded(self, *args, **kwargs): self.background_thread = threading.Thread(target=self.perform_transfer) self.background_thread.daemon = True self.background_thread.start() @@ -69,7 +70,7 @@ class Transfer(object): def complete_transfer(self): if callable(self.completed_callback): self.curl.close() - self.completed_callback() + self.completed_callback(self.obj) class Upload(Transfer): diff --git a/src/extra/AudioUploader/wx_transfer_dialogs.py b/src/extra/AudioUploader/wx_transfer_dialogs.py index 18ecbd1c..035e0cc1 100644 --- a/src/extra/AudioUploader/wx_transfer_dialogs.py +++ b/src/extra/AudioUploader/wx_transfer_dialogs.py @@ -56,8 +56,9 @@ class TransferDialog(widgetUtils.BaseDialog): def create_buttons(self): self.cancel_button = wx.Button(parent=self.pane, id=wx.ID_CANCEL) - def get_response(self): - self.Show() + def get_response(self, fn): + wx.CallAfter(fn, 0.01) + self.ShowModal() def destroy(self): self.Destroy()