Convert WizardProgress into RPCProgress
Use RPCProgress for database creation
This commit is contained in:
1 parent
2744ea1405
commit
9015bb48b3
3 files changed
+82
-82
No files matched your search
@@ -18,6 +18,7 @@ import tryton.rpc as rpc
|
||||
import locale
|
||||
import socket
|
||||
from tryton.version import VERSION
|
||||
import thread
|
||||
|
||||
_ = gettext.gettext
|
||||
|
||||
@@ -729,6 +730,75 @@ def generateColorscheme(masterColor, keys, light=0.06):
|
||||
return dict([(key, lighten(r, g, b, light * i))
|
||||
for i, key in enumerate(keys)])
|
||||
|
||||
|
||||
class RPCProgress(object):
|
||||
|
||||
def __init__(self, method, args, parent):
|
||||
self.method = method
|
||||
self.args = args
|
||||
self.parent = parent
|
||||
self.res = None
|
||||
self.error = False
|
||||
self.exception = None
|
||||
|
||||
def start(self):
|
||||
try:
|
||||
self.res = getattr(rpc, self.method)(*self.args)
|
||||
except Exception, exception:
|
||||
self.error = True
|
||||
self.res = False
|
||||
self.exception = exception
|
||||
return True
|
||||
if not self.res:
|
||||
self.error = True
|
||||
return True
|
||||
|
||||
def run(self):
|
||||
thread.start_new_thread(self.start, ())
|
||||
|
||||
i = 0
|
||||
win = None
|
||||
progressbar = None
|
||||
while (not self.res) and (not self.error):
|
||||
time.sleep(0.1)
|
||||
i += 1
|
||||
if i > 10:
|
||||
if not win or not progressbar:
|
||||
win = gtk.Window(type=gtk.WINDOW_TOPLEVEL)
|
||||
win.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
|
||||
vbox = gtk.VBox(False, 0)
|
||||
hbox = gtk.HBox(False, 13)
|
||||
hbox.set_border_width(10)
|
||||
img = gtk.Image()
|
||||
img.set_from_stock('tryton-dialog-information',
|
||||
gtk.ICON_SIZE_DIALOG)
|
||||
hbox.pack_start(img, expand=True, fill=False)
|
||||
vbox2 = gtk.VBox(False, 0)
|
||||
label = gtk.Label()
|
||||
label.set_markup('<b>'+_('Operation in progress')+'</b>')
|
||||
label.set_alignment(0.0, 0.5)
|
||||
vbox2.pack_start(label, expand=True, fill=False)
|
||||
vbox2.pack_start(gtk.HSeparator(), expand=True, fill=True)
|
||||
vbox2.pack_start(gtk.Label(_("Please wait,\n" \
|
||||
"this operation may take a while...")),
|
||||
expand=True, fill=False)
|
||||
hbox.pack_start(vbox2, expand=True, fill=True)
|
||||
vbox.pack_start(hbox)
|
||||
progressbar = gtk.ProgressBar()
|
||||
progressbar.set_orientation(gtk.PROGRESS_LEFT_TO_RIGHT)
|
||||
vbox.pack_start(progressbar, expand=True, fill=False)
|
||||
win.add(vbox)
|
||||
win.set_transient_for(self.parent)
|
||||
win.show_all()
|
||||
progressbar.pulse()
|
||||
gtk.main_iteration()
|
||||
if win:
|
||||
win.destroy()
|
||||
gtk.main_iteration()
|
||||
if self.exception:
|
||||
raise self.exception
|
||||
return self.res
|
||||
|
||||
COLOR_SCHEMES = {
|
||||
'red': '#cf1d1d',
|
||||
'green': '#3fb41b',
|
||||
|
||||
@@ -347,11 +347,11 @@ class DBCreate(object):
|
||||
and langreal \
|
||||
and passwd \
|
||||
and admin_passwd.get_text():
|
||||
if rpc.db_exec( url_m.group(1), int(url_m.group(2)), \
|
||||
if rpc.db_exec(url_m.group(1), int(url_m.group(2)),
|
||||
'db_exist', dbname):
|
||||
common.warning(_("Database with the same name " \
|
||||
"already exists.\n" \
|
||||
"Try another database name."), parent, \
|
||||
"Try another database name."), parent,
|
||||
_("Databasename already exist!"))
|
||||
self.entry_dbname.set_text("")
|
||||
self.entry_dbname.grab_focus()
|
||||
@@ -361,8 +361,12 @@ class DBCreate(object):
|
||||
CONFIG['login.port'] = port = url_m.group(2)
|
||||
CONFIG["login.login"] = "admin"
|
||||
try:
|
||||
rpc.db_exec(host, int(port), 'create', passwd, \
|
||||
dbname, langreal, admin_passwd.get_text())
|
||||
rpcprogress = common.RPCProgress('db_exec',
|
||||
(host, int(port), 'create', passwd,
|
||||
dbname, langreal,
|
||||
admin_passwd.get_text()),
|
||||
parent)
|
||||
rpcprogress.run()
|
||||
except Exception, exception:
|
||||
if str(exception[0]) == "AccessDenied":
|
||||
common.warning(_("Sorry, the Tryton server " \
|
||||
|
||||
+4
-78
@@ -157,11 +157,12 @@ class Wizard(object):
|
||||
dia = None
|
||||
while state != 'end':
|
||||
ctx = context.copy()
|
||||
ctx.update(rpc.CONTEXT)
|
||||
ctx['active_id'] = datas.get('id')
|
||||
ctx['active_ids'] = datas.get('ids')
|
||||
wizardprogress = WizardProgress(wiz_id, state, datas,
|
||||
parent, ctx)
|
||||
res = wizardprogress.run()
|
||||
rpcprogress = common.RPCProgress('execute', ('wizard',
|
||||
'execute', wiz_id, datas, state, ctx), parent)
|
||||
res = rpcprogress.run()
|
||||
if not res:
|
||||
if dia:
|
||||
res = {'type': 'form'}
|
||||
@@ -217,78 +218,3 @@ class Wizard(object):
|
||||
rpc.context_reload()
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
class WizardProgress(object):
|
||||
|
||||
def __init__(self, wizard_id, state, datas, parent, context):
|
||||
self.res = None
|
||||
self.error = False
|
||||
self.wizard_id = wizard_id
|
||||
self.state = state
|
||||
self.datas = datas
|
||||
self.parent = parent
|
||||
self.context = context
|
||||
self.exception = None
|
||||
|
||||
def run(self):
|
||||
|
||||
def start(wiz_id, datas, state, context):
|
||||
ctx = rpc.CONTEXT.copy()
|
||||
ctx.update(context)
|
||||
try:
|
||||
self.res = rpc.execute('wizard',
|
||||
'execute', wiz_id, datas, state, ctx)
|
||||
except Exception, exception:
|
||||
self.error = True
|
||||
self.res = False
|
||||
self.exception = exception
|
||||
return True
|
||||
if not self.res:
|
||||
self.error = True
|
||||
return True
|
||||
|
||||
thread.start_new_thread(start,
|
||||
(self.wizard_id, self.datas, self.state, self.context))
|
||||
|
||||
i = 0
|
||||
win = None
|
||||
progressbar = None
|
||||
while (not self.res) and (not self.error):
|
||||
time.sleep(0.1)
|
||||
i += 1
|
||||
if i > 10:
|
||||
if not win or not progressbar:
|
||||
win = gtk.Window(type=gtk.WINDOW_TOPLEVEL)
|
||||
win.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
|
||||
vbox = gtk.VBox(False, 0)
|
||||
hbox = gtk.HBox(False, 13)
|
||||
hbox.set_border_width(10)
|
||||
img = gtk.Image()
|
||||
img.set_from_stock('tryton-dialog-information', gtk.ICON_SIZE_DIALOG)
|
||||
hbox.pack_start(img, expand=True, fill=False)
|
||||
vbox2 = gtk.VBox(False, 0)
|
||||
label = gtk.Label()
|
||||
label.set_markup('<b>'+_('Operation in progress')+'</b>')
|
||||
label.set_alignment(0.0, 0.5)
|
||||
vbox2.pack_start(label, expand=True, fill=False)
|
||||
vbox2.pack_start(gtk.HSeparator(), expand=True, fill=True)
|
||||
vbox2.pack_start(gtk.Label(_("Please wait,\n" \
|
||||
"this operation may take a while...")),
|
||||
expand=True, fill=False)
|
||||
hbox.pack_start(vbox2, expand=True, fill=True)
|
||||
vbox.pack_start(hbox)
|
||||
progressbar = gtk.ProgressBar()
|
||||
progressbar.set_orientation(gtk.PROGRESS_LEFT_TO_RIGHT)
|
||||
vbox.pack_start(progressbar, expand=True, fill=False)
|
||||
win.add(vbox)
|
||||
win.set_transient_for(self.parent)
|
||||
win.show_all()
|
||||
progressbar.pulse()
|
||||
gtk.main_iteration()
|
||||
if win:
|
||||
win.destroy()
|
||||
gtk.main_iteration()
|
||||
if self.exception:
|
||||
common.process_exception(self.exception, self.parent)
|
||||
return self.res
|
||||
Reference in new issue
Block a user