Merge remote-tracking branch 'origin/v2.2'

This commit is contained in:
Adolfo Gómez García 2017-08-04 15:20:12 +02:00
commit 0d13156edf
3 changed files with 107 additions and 6 deletions

View File

@ -32,7 +32,6 @@
from __future__ import unicode_literals
from uds import ui
from uds import browser
from uds.rest import RestRequest, RetryException
from uds.forward import forward
from uds import VERSION
@ -41,7 +40,6 @@ from uds import tools
import six
import sys
import webbrowser
import pickle
@ -83,7 +81,7 @@ def getWithRetry(rest, url, params=None):
res = rest.get(url, params)
return res
except RetryException as e:
if ui.question('Service not available', '{}\nPlease, wait a minute and press "OK" to retry, or CANCEL to abort') is True:
if ui.question('Service not available', 'Error {}.\nPlease, wait a minute and press "OK" to retry, or "CANCEL" to abort'.format(e)) is True:
continue
raise Exception('Cancelled by user')
@ -127,8 +125,7 @@ if __name__ == "__main__":
logger.debug('Got information {}'.format(res))
if res['requiredVersion'] > VERSION:
ui.message("New UDS Client available", "A new uds version is needed in order to access this version of UDS. A browser will be opened for this download.")
webbrowser.open(res['downloadUrl'])
ui.message("New UDS Client available", "A new uds version is needed in order to access this version of UDS.\nPlease, download and install it")
sys.exit(1)
res = getWithRetry(rest, '/{}/{}'.format(ticket, scrambler), params={'hostname': tools.getHostName(), 'version': VERSION})

View File

@ -31,9 +31,113 @@
'''
from __future__ import unicode_literals
import re
import pygtk
pygtk.require('2.0')
import gtk
import gobject
LINE_LEN = 65
class Dialog():
def __init__(self, title, message, timeout=-1, withCancel=True):
self.title = title
self.message = message
self.timeout = timeout
self.withCancel = withCancel
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_position(gtk.WIN_POS_CENTER)
# self.window.set_size_request(320, 200)
self.window.set_title(self.title)
self.create_widgets()
self.connect_signals()
self.window.show_all()
self.window.connect("destroy", self.destroy)
# Setup "auto OK" timer
if timeout != -1:
self.timerId = gobject.timeout_add(self.timeout * 1000, self.callback_timer)
else:
self.timerId = -1
self.result = False
gtk.main()
@property
def adapted_message(self):
msg = ''
for l in re.sub(r'<p[^>]*>', '', self.message).replace('</p>', '\n').split('\n'):
words = []
length = 0
for word in l.split(' '):
if length + len(word) >= LINE_LEN:
msg += ' '.join(words) + '\n'
words = []
length = 0
length += len(word) + 1
words.append(word)
msg += ' '.join(words) + '\n'
return msg
def create_widgets(self):
self.vbox = gtk.VBox(spacing=10)
self.vbox.set_size_request(490, -1)
self.messageLabel = gtk.Label()
# Fix message markup
# self.message = re.sub(r'<p[^>]*>', '<span font_weight="bold">', self.message).replace('</p>', '</span>\n' )
# Set as simple markup
self.messageLabel.set_markup('\n' + self.adapted_message + '\n')
self.messageLabel.set_alignment(xalign=0.5, yalign=1)
self.hbox = gtk.HBox(spacing=10)
self.button_ok = gtk.Button("OK")
self.hbox.pack_start(self.button_ok)
if self.withCancel:
self.button_cancel = gtk.Button("Cancel")
self.hbox.pack_start(self.button_cancel)
self.vbox.pack_start(self.messageLabel)
self.vbox.pack_start(self.hbox)
self.window.add(self.vbox)
def connect_signals(self):
self.button_ok.connect("clicked", self.callback_ok)
if self.withCancel:
self.button_cancel.connect("clicked", self.callback_cancel)
def destroy(self, widget, data=None):
self.setResult(False)
def setResult(self, val):
if self.timerId != -1:
gobject.source_remove(self.timerId)
self.timerId = -1
self.result = val
self.window.hide()
gtk.main_quit()
raise Exception('not available')
def callback_ok(self, widget, callback_data=None):
self.setResult(True)
def callback_cancel(self, widget, callback_data=None):
self.setResult(False)
def callback_timer(self):
self.setResult(True)
def message(title, message):
Dialog(title, message, withCancel=False)
def question(title, message):
dlg = Dialog(title, message, timeout=30, withCancel=True)
return dlg.result