mirror of
https://github.com/dkmstr/openuds.git
synced 2025-01-18 06:03:54 +03:00
Merge remote-tracking branch 'origin/v2.1' into v2.2
This commit is contained in:
commit
4853729d7c
@ -32,7 +32,6 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from uds import ui
|
from uds import ui
|
||||||
from uds import browser
|
|
||||||
from uds.rest import RestRequest, RetryException
|
from uds.rest import RestRequest, RetryException
|
||||||
from uds.forward import forward
|
from uds.forward import forward
|
||||||
from uds import VERSION
|
from uds import VERSION
|
||||||
@ -41,7 +40,6 @@ from uds import tools
|
|||||||
|
|
||||||
import six
|
import six
|
||||||
import sys
|
import sys
|
||||||
import webbrowser
|
|
||||||
import pickle
|
import pickle
|
||||||
|
|
||||||
|
|
||||||
@ -83,7 +81,7 @@ def getWithRetry(rest, url, params=None):
|
|||||||
res = rest.get(url, params)
|
res = rest.get(url, params)
|
||||||
return res
|
return res
|
||||||
except RetryException as e:
|
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
|
continue
|
||||||
raise Exception('Cancelled by user')
|
raise Exception('Cancelled by user')
|
||||||
|
|
||||||
@ -127,8 +125,7 @@ if __name__ == "__main__":
|
|||||||
logger.debug('Got information {}'.format(res))
|
logger.debug('Got information {}'.format(res))
|
||||||
|
|
||||||
if res['requiredVersion'] > VERSION:
|
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.")
|
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")
|
||||||
webbrowser.open(res['downloadUrl'])
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
res = getWithRetry(rest, '/{}/{}'.format(ticket, scrambler), params={'hostname': tools.getHostName(), 'version': VERSION})
|
res = getWithRetry(rest, '/{}/{}'.format(ticket, scrambler), params={'hostname': tools.getHostName(), 'version': VERSION})
|
||||||
|
@ -31,9 +31,113 @@
|
|||||||
'''
|
'''
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
import pygtk
|
import pygtk
|
||||||
pygtk.require('2.0')
|
pygtk.require('2.0')
|
||||||
import gtk
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user