Пример #1
0
def execute(action, datas, state='init', parent=None, context=None):
    if context is None:
        context = {}
    if not 'form' in datas:
        datas['form'] = {}
    wiz_id = rpc.session.rpc_exec_auth('/wizard', 'create', action)

    while state!='end':
        class wizard_progress(object):
            def __init__(self, parent=None):
                self.res = None
                self.error = False
                self.parent = parent
                self.exception = None

            def run(self):
                def go(wiz_id, datas, state):
                    ctx = context.copy()
                    ctx.update(rpc.session.context)
                    try:
                        self.res = rpc.session.rpc_exec_auth_try('/wizard', 'execute', wiz_id, datas, state, ctx)
                    except Exception, e:
                        self.error = True
                        self.res = False
                        self.exception = e
                        return True
                    if not self.res:
                        self.error = True
                    return True

                thread.start_new_thread(go, (wiz_id, datas, state))

                i = 0
                win = None
                pb = None
                while (not self.res) and (not self.error):
                    time.sleep(0.1)
                    i += 1
                    if i > 10:
                        if not win or not pb:
                            win = gtk.Window(type=gtk.WINDOW_TOPLEVEL)
                            win.set_title(_('OpenERP Computing'))
                            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('gtk-dialog-info', 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,\nthis operation may take a while...")), expand=True, fill=False)
                            hbox.pack_start(vbox2, expand=True, fill=True)
                            vbox.pack_start(hbox)
                            pb = gtk.ProgressBar()
                            pb.set_orientation(gtk.PROGRESS_LEFT_TO_RIGHT)
                            vbox.pack_start(pb, expand=True, fill=False)
                            win.add(vbox)
                            if not self.parent:
                                self.parent = service.LocalService('gui.main').window
                            win.set_transient_for(self.parent)
                            win.show_all()
                        pb.pulse()
                        gtk.main_iteration()
                if win:
                    win.destroy()
                    gtk.main_iteration()
                if self.exception:
                    import xmlrpclib
                    import socket
                    from rpc import rpc_exception, CONCURRENCY_CHECK_FIELD
                    import tiny_socket
                    try:
                        raise self.exception
                    except socket.error, e:
                        common.message(str(e), title=_('Connection refused !'), type=gtk.MESSAGE_ERROR)
                    except xmlrpclib.Fault, err:
                        a = rpc_exception(err.faultCode, err.faultString)
                        if a.type in ('warning', 'UserError'):
                            if a.message in ('ConcurrencyException') and len(args) > 4:
                                if common.concurrency(args[0], args[2][0], args[4]):
                                    if CONCURRENCY_CHECK_FIELD in args[4]:
                                        del args[4][CONCURRENCY_CHECK_FIELD]
                                    return self.rpc_exec_auth(obj, method, *args)
                            else:
                                common.warning(a.data, a.message)
                        else:
                            common.error(_('Application Error'), err.faultCode, err.faultString)
                    except tiny_socket.Myexception, err:
                        a = rpc_exception(err.faultCode, err.faultString)
                        if a.type in ('warning', 'UserError'):
                            common.warning(a.data, a.message)
                        else:
                            common.error(_('Application Error'), err.faultCode, err.faultString)
                    except Exception, e:
                        common.error(_('Application Error'), _('View details'), str(e))
Пример #2
0
        class wizard_progress(object):
            def __init__(self, parent=None):
                self.res = None
                self.error = False
                self.parent = parent
                self.exception = None

            def run(self):
                def go(wiz_id, datas, state):
                    ctx = context.copy()
                    ctx.update(rpc.session.context)
                    try:
                        self.res = rpc.session.rpc_exec_auth_try(
                            '/wizard', 'execute', wiz_id, datas, state, ctx)
                    except Exception, e:
                        self.error = True
                        self.res = False
                        self.exception = e
                        return True
                    if not self.res:
                        self.error = True
                    return True

                thread.start_new_thread(go, (wiz_id, datas, state))

                i = 0
                win = None
                pb = None
                while (not self.res) and (not self.error):
                    time.sleep(0.1)
                    i += 1
                    if i > 10:
                        if not win or not pb:
                            win = gtk.Window(type=gtk.WINDOW_TOPLEVEL)
                            win.set_title(_('OpenERP Computing'))
                            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('gtk-dialog-info',
                                               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,\nthis operation may take a while..."
                                  )),
                                             expand=True,
                                             fill=False)
                            hbox.pack_start(vbox2, expand=True, fill=True)
                            vbox.pack_start(hbox)
                            pb = gtk.ProgressBar()
                            pb.set_orientation(gtk.PROGRESS_LEFT_TO_RIGHT)
                            vbox.pack_start(pb, expand=True, fill=False)
                            win.add(vbox)
                            if not self.parent:
                                self.parent = service.LocalService(
                                    'gui.main').window
                            win.set_transient_for(self.parent)
                            win.show_all()
                        pb.pulse()
                        gtk.main_iteration()
                if win:
                    win.destroy()
                    gtk.main_iteration()
                if self.exception:
                    import xmlrpclib
                    import socket
                    from rpc import rpc_exception, CONCURRENCY_CHECK_FIELD
                    import tiny_socket
                    try:
                        raise self.exception
                    except socket.error, e:
                        common.message(str(e),
                                       title=_('Connection refused !'),
                                       type=gtk.MESSAGE_ERROR)
                    except xmlrpclib.Fault, err:
                        a = rpc_exception(err.faultCode, err.faultString)
                        if a.type in ('warning', 'UserError'):
                            if a.message in (
                                    'ConcurrencyException') and len(args) > 4:
                                if common.concurrency(args[0], args[2][0],
                                                      args[4]):
                                    if CONCURRENCY_CHECK_FIELD in args[4]:
                                        del args[4][CONCURRENCY_CHECK_FIELD]
                                    return self.rpc_exec_auth(
                                        obj, method, *args)
                            else:
                                common.warning(a.data, a.message)
                        else:
                            common.error(_('Application Error'), err.faultCode,
                                         err.faultString)
Пример #3
0
        class wizard_progress(object):
            def __init__(self, parent=None):
                self.res = None
                self.error = False
                self.parent = parent
                self.exception = None

            def run(self):
                def go(wiz_id, datas, state):
                    ctx = context.copy()
                    ctx.update(rpc.session.context)
                    try:
                        self.res = rpc.session.rpc_exec_auth_try(
                            '/wizard', 'execute', wiz_id, datas, state, ctx)
                    except Exception, e:
                        self.error = True
                        self.res = False
                        self.exception = e
                        return True
                    if not self.res:
                        self.error = True
                    return True

                thread.start_new_thread(go, (wiz_id, datas, state))

                i = 0
                win = None
                pb = None
                while (not self.res) and (not self.error):
                    time.sleep(0.1)
                    i += 1
                    if i > 10:
                        if not win or not pb:
                            win, pb = common.OpenERP_Progressbar(self.parent)
                        pb.pulse()
                        gtk.main_iteration()
                if win:
                    win.destroy()
                    gtk.main_iteration()
                if self.exception:
                    import xmlrpclib
                    import socket
                    from rpc import rpc_exception, CONCURRENCY_CHECK_FIELD
                    import tiny_socket
                    try:
                        raise self.exception
                    except socket.error, e:
                        common.message(str(e),
                                       title=_('Connection refused !'),
                                       type=gtk.MESSAGE_ERROR,
                                       parent=self.parent)
                    except xmlrpclib.Fault, err:
                        a = rpc_exception(err.faultCode, err.faultString)
                        if a.type in ('warning', 'UserError'):
                            if a.message in (
                                    'ConcurrencyException') and len(args) > 4:
                                if common.concurrency(args[0], args[2][0],
                                                      args[4]):
                                    if CONCURRENCY_CHECK_FIELD in args[4]:
                                        del args[4][CONCURRENCY_CHECK_FIELD]
                                    return self.rpc_exec_auth(
                                        obj, method, *args)
                            else:
                                common.warning(a.data,
                                               a.message,
                                               parent=self.parent)
                        else:
                            common.error(_('Application Error'), err.faultCode,
                                         err.faultString)
Пример #4
0
def execute(action, datas, state='init', parent=None, context=None):
    if context is None:
        context = {}
    if not 'form' in datas:
        datas['form'] = {}
    wiz_id = rpc.session.rpc_exec_auth('/wizard', 'create', action)

    while state!='end':
        class wizard_progress(object):
            def __init__(self, parent=None):
                self.res = None
                self.error = False
                self.parent = parent
                self.exception = None

            def run(self):
                def go(wiz_id, datas, state):
                    ctx = context.copy()
                    ctx.update(rpc.session.context)
                    try:
                        self.res = rpc.session.rpc_exec_auth_try('/wizard', 'execute', wiz_id, datas, state, ctx)
                    except Exception, e:
                        self.error = True
                        self.res = False
                        self.exception = e
                        return True
                    if not self.res:
                        self.error = True
                    return True

                thread.start_new_thread(go, (wiz_id, datas, state))

                i = 0
                win = None
                pb = None
                while (not self.res) and (not self.error):
                    time.sleep(0.1)
                    i += 1
                    if i > 10:
                        if not win or not pb:
                            win, pb = common.OpenERP_Progressbar(self.parent)
                        pb.pulse()
                        gtk.main_iteration()
                if win:
                    win.destroy()
                    gtk.main_iteration()
                if self.exception:
                    import xmlrpclib
                    import socket
                    from rpc import rpc_exception, CONCURRENCY_CHECK_FIELD
                    import tiny_socket
                    try:
                        raise self.exception
                    except socket.error, e:
                        common.message(str(e), title=_('Connection refused !'), type=gtk.MESSAGE_ERROR, parent=self.parent)
                    except xmlrpclib.Fault, err:
                        a = rpc_exception(err.faultCode, err.faultString)
                        if a.type in ('warning', 'UserError'):
                            if a.message in ('ConcurrencyException') and len(args) > 4:
                                if common.concurrency(args[0], args[2][0], args[4]):
                                    if CONCURRENCY_CHECK_FIELD in args[4]:
                                        del args[4][CONCURRENCY_CHECK_FIELD]
                                    return self.rpc_exec_auth(obj, method, *args)
                            else:
                                common.warning(a.data, a.message, parent=self.parent)
                        else:
                            common.error(_('Application Error'), err.faultCode, err.faultString)
                    except tiny_socket.Myexception, err:
                        a = rpc_exception(err.faultCode, err.faultString)
                        if a.type in ('warning', 'UserError'):
                            common.warning(a.data, a.message, parent=self.parent)
                        else:
                            common.error(_('Application Error'), err.faultCode, err.faultString)
                    except Exception, e:
                        common.error(_('Application Error'), _('View details'), str(e))