Fixed audio upload dialog

This commit is contained in:
Manuel Cortez 2016-04-30 06:16:16 -05:00
parent 2268619101
commit 8988d63f33
4 changed files with 12 additions and 10 deletions

View File

@ -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()

View File

@ -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 = []

View File

@ -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):

View File

@ -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()