I am developing desktop software based on:
Now, I need implement async feature:
Need your advices about the elegant solution.
Very simple solution :
However, I need to hard code the time and once I have long operation such as downloading files from FTP, its issue for me
Code of the solution:
templateManager.js
function _loadNewTemplates() {
var deferred = $.Deferred();
asyncManager.run($.proxy( _loadNewTemplatesCallback, null, deferred ), "get_new_templates_list" );
return deferred;
}
function _loadNewTemplatesCallback ( deferred, response ) {
template.newList = response.result;
deferred.resolve();
}
app_mamager.py
@QtCore.Slot(int, result=str)
def get_new_templates_list(self, id):
thread.start_new_thread(get_new_templates_list,
(id,))
utils.py
def get_new_templates_list(id):
config.set_response(id, json.dumps({'result': _get_new_templates_list(), 'error': None}, MyEncoder))
def _get_new_templates_list():
request = {'category': PRODUCT_CODE}
response = requests.post(URL,
data=request,
headers=HEADERS)
return json.loads(response.text)
config.py
def set_response(id, request):
'''
Put pair (id, request) to the internal dictionary
:param id - int, request id:
:param request - string, request string:
:return:
'''
global _async_request
_async_request[id] = request
def get_response(id):
'''
Returns request or empty string if request does not exist
:param id - int
:return - string, request string:
'''
global _async_request
if _async_request.has_key(id):
return _async_request.pop(id)
else:
return ''
Here is what you can do:
stat
/ stat.ST_SIZE
, chunk
size, PySide.QtGui.QProgressBar.setRange()
with the correct range, which is 0 to number of blocks ( filesize / ftp transfer chunk size ) for binary files or number of lines for text files. ftplib.FTP.storbinary()
or ftplib.FTP.storlines()
so that each block / line transferred increases your progress bar accordingly with PySide.QtGui.QProgressBar.setValue()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.