fixed an error with edit list

This commit is contained in:
Adolfo Gómez García 2016-04-14 05:14:58 +02:00
parent 63364f4e72
commit 273b2a59c4
2 changed files with 34 additions and 17 deletions

View File

@ -54,6 +54,9 @@ class UDSClient(QtGui.QMainWindow):
ticket = None ticket = None
scrambler = None scrambler = None
withError = False withError = False
animTimer = None
anim = 0
animInc = 1
def __init__(self): def __init__(self):
QtGui.QMainWindow.__init__(self) QtGui.QMainWindow.__init__(self)
@ -73,8 +76,14 @@ class UDSClient(QtGui.QMainWindow):
vpos = (screen.height() - mysize.height() - mysize.height()) / 2 vpos = (screen.height() - mysize.height() - mysize.height()) / 2
self.move(hpos, vpos) self.move(hpos, vpos)
self.animTimer = QtCore.QTimer()
QtCore.QObject.connect(self.animTimer, QtCore.SIGNAL('timeout()'), self.updateAnim)
self.activateWindow() self.activateWindow()
self.startAnim()
def closeWindow(self): def closeWindow(self):
self.close() self.close()
@ -90,6 +99,7 @@ class UDSClient(QtGui.QMainWindow):
# return # return
def showError(self, e): def showError(self, e):
self.stopAnim()
self.ui.progressBar.setValue(100) self.ui.progressBar.setValue(100)
self.ui.info.setText('Error') self.ui.info.setText('Error')
QtGui.QMessageBox.critical(self, 'Error', six.text_type(e), QtGui.QMessageBox.Ok) QtGui.QMessageBox.critical(self, 'Error', six.text_type(e), QtGui.QMessageBox.Ok)
@ -99,12 +109,24 @@ class UDSClient(QtGui.QMainWindow):
def cancelPushed(self): def cancelPushed(self):
self.close() self.close()
def _updateProgressBar(self, increment, maximum=100): @QtCore.pyqtSlot()
val = self.ui.progressBar.value() def updateAnim(self):
val += increment self.anim += self.animInc
if val > maximum: if self.anim < 1 or self.anim > 99:
val = maximum self.ui.progressBar.invertedAppearance = not self.ui.progressBar.invertedAppearance
self.ui.progressBar.setValue(val) self.animInc = -self.animInc
self.ui.progressBar.setValue(self.anim)
def startAnim(self):
self.ui.progressBar.invertedAppearance = False
self.anim = 0
self.animInc = 1
self.animTimer.start(40)
def stopAnim(self):
self.ui.progressBar.invertedAppearance = False
self.animTimer.stop()
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def getVersion(self): def getVersion(self):
@ -114,10 +136,7 @@ class UDSClient(QtGui.QMainWindow):
@QtCore.pyqtSlot(dict) @QtCore.pyqtSlot(dict)
def version(self, data): def version(self, data):
try: try:
self.ui.progressBar.setValue(20)
self.processError(data) self.processError(data)
self.ui.info.setText('Processing...') self.ui.info.setText('Processing...')
if data['result']['requiredVersion'] > VERSION: if data['result']['requiredVersion'] > VERSION:
@ -128,13 +147,13 @@ class UDSClient(QtGui.QMainWindow):
self.getTransportData() self.getTransportData()
except RetryException as e: except RetryException as e:
self._updateProgressBar(5, 80)
self.ui.info.setText(six.text_type(e)) self.ui.info.setText(six.text_type(e))
QtCore.QTimer.singleShot(1000, self.getVersion) QtCore.QTimer.singleShot(1000, self.getVersion)
except Exception as e: except Exception as e:
self.showError(e) self.showError(e)
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def getTransportData(self): def getTransportData(self):
self.req = RestRequest('/{}/{}'.format(self.ticket, self.scrambler), self, self.transportDataReceived, params={'hostname': tools.getHostName(), 'version': VERSION}) self.req = RestRequest('/{}/{}'.format(self.ticket, self.scrambler), self, self.transportDataReceived, params={'hostname': tools.getHostName(), 'version': VERSION})
@ -147,11 +166,10 @@ class UDSClient(QtGui.QMainWindow):
try: try:
self.processError(data) self.processError(data)
self.ui.progressBar.setValue(80)
script = data['result'].decode('base64').decode('bz2') script = data['result'].decode('base64').decode('bz2')
self.ui.progressBar.setValue(100) self.stopAnim()
if 'darwin' in sys.platform: if 'darwin' in sys.platform:
self.showMinimized() self.showMinimized()
@ -161,7 +179,6 @@ class UDSClient(QtGui.QMainWindow):
six.exec_(script, globals(), {'parent': self}) six.exec_(script, globals(), {'parent': self})
except RetryException as e: except RetryException as e:
self._updateProgressBar(5, 80)
self.ui.info.setText(six.text_type(e) + ', retrying access...') self.ui.info.setText(six.text_type(e) + ', retrying access...')
# Retry operation in ten seconds # Retry operation in ten seconds
QtCore.QTimer.singleShot(10000, self.getTransportData) QtCore.QTimer.singleShot(10000, self.getTransportData)

View File

@ -1,7 +1,7 @@
{% extends "uds/admin/tmpl/fld/form-group.html" %} {% extends "uds/admin/tmpl/fld/form-group.html" %}
{% load i18n %} {% load i18n %}
{% block field %}{% verbatim %} {% block field %}{% verbatim %}
<input name="{{ name }}_nonused1" type="text" id="{{ name }}_field_txt" class="form-control cursor-pointer" value="{{ truncatechars 64 value }}" readonly tabindex="{{ index }}"> <input name="{{ name }}_nonused1" type="text" id="{{ name }}_field_txt" class="form-control cursor-pointer" value="{{ truncatechars 64 value }}" readonly>
{{! We use a Select to get an array of selected values on ".val()" }} {{! We use a Select to get an array of selected values on ".val()" }}
<select id="{{ name }}_field_hdn" class="{{ css }} hidden" name="{{ name }}" multiple> <select id="{{ name }}_field_hdn" class="{{ css }} hidden" name="{{ name }}" multiple>
{{# each value }} {{# each value }}
@ -14,8 +14,8 @@
(function(){ (function(){
"use strict"; "use strict";
var id = '{{ name }}_field_'; var id = '{{ name }}_field_';
var idTxt = 'input#' + id + 'txt'; var idTxt = '#' + id + 'txt';
var idHidden = 'input#' + id + 'hdn'; var idHidden = '#' + id + 'hdn';
$(idTxt).tooltip({ $(idTxt).tooltip({
placement: 'bottom', placement: 'bottom',
title: "{% endverbatim %}{% trans 'Click to edit list' %}{% verbatim %}", title: "{% endverbatim %}{% trans 'Click to edit list' %}{% verbatim %}",