AudioUploader: some code cleaning, optimizations and bug fixes

This commit is contained in:
Jose Manuel Delicado 2016-05-06 17:38:17 +02:00
parent ff49bd2488
commit b3cac85c4e
3 changed files with 5 additions and 37 deletions

View File

@ -57,13 +57,11 @@ class audioUploader(object):
url = base_url + '?apikey=' + self.config['sound']['sndup_api_key']
else:
url = base_url
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(obj=self, 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.uploaderFunction.perform_threaded()
def get_available_services(self):
services = []
@ -116,8 +114,9 @@ class audioUploader(object):
if self.playing:
self._stop()
if self.recording != None:
self.dialog.disable_control("attach")
self.dialog.disable_control("play")
self.cleanup()
self.dialog.disable_control("attach")
self.dialog.disable_control("play")
self.file = None
self.dialog.enable_control("record")
self.dialog.enable_control("attach_exists")
@ -174,10 +173,6 @@ class audioUploader(object):
os.remove(self.file)
if hasattr(self, 'wav_file'):
os.remove(self.wav_file)
del(self.wav_file)
if hasattr(self, 'wav_file') and os.path.exists(self.file):
os.remove(self.file)
def on_attach_exists(self, *args, **kwargs):
self.file = self.dialog.get_file()

View File

@ -38,9 +38,6 @@ class Transfer(object):
progress = {}
progress["total"] = up_total
progress["current"] = up_current
# else:
# print "Killed function"
# return
if progress["current"] == 0:
progress["percent"] = 0
self.transfer_rate = 0
@ -94,14 +91,3 @@ class Upload(Transfer):
def get_url(self):
return json.loads(self.response['body'])['url']
class Download(Transfer):
def __init__(self, follow_location=True, *args, **kwargs):
super(Download, self).__init__(*args, **kwargs)
self.download_file = open(self.filename, 'wb')
self.curl.setopt(self.curl.WRITEFUNCTION, self.download_file.write)
def complete_transfer(self):
self.download_file.close()
super(DownloadDialog, self).complete_transfer()

View File

@ -3,7 +3,7 @@ import wx
from utils import *
import widgetUtils
class TransferDialog(widgetUtils.BaseDialog):
class UploadDialog(widgetUtils.BaseDialog):
def __init__(self, filename, *args, **kwargs):
super(TransferDialog, self).__init__(parent=None, id=wx.NewId(), *args, **kwargs)
@ -59,16 +59,3 @@ class TransferDialog(widgetUtils.BaseDialog):
def get_response(self, fn):
wx.CallAfter(fn, 0.01)
self.ShowModal()
def destroy(self):
self.Destroy()
class UploadDialog(TransferDialog):
def __init__(self, filename=None, *args, **kwargs):
super(UploadDialog, self).__init__(filename=filename, *args, **kwargs)
class DownloadDialog(TransferDialog):
def __init__(self, *args, **kwargs):
super(Download, self).__init__(*args, **kwargs)