Exemplo n.º 1
0
def createWindow(view_ids,
                 model,
                 res_id=False,
                 domain=None,
                 view_type='form',
                 window=None,
                 context=None,
                 mode=None,
                 name=False,
                 autoReload=False,
                 target='current'):

    if context is None:
        context = {}
    context.update(Rpc.session.context)

    if view_type == 'form':
        QApplication.setOverrideCursor(Qt.WaitCursor)
        mode = (mode or 'form,tree').split(',')
        try:
            widget = FormWidget(model,
                                res_id,
                                domain,
                                view_type=mode,
                                view_ids=(view_ids or []),
                                context=context,
                                name=name)
        except Rpc.RpcException as e:
            QApplication.restoreOverrideCursor()
            return
        if target == 'new':
            widget.setStatusBarVisible(False)
        widget.setAutoReload(autoReload)
        QApplication.restoreOverrideCursor()
        Api.instance.windowCreated(widget, target)
    elif view_type == 'tree':
        QApplication.setOverrideCursor(Qt.WaitCursor)
        try:
            if view_ids and view_ids[0]:
                view_base = Rpc.session.execute('/object', 'execute',
                                                'ir.ui.view', 'read',
                                                [view_ids[0]],
                                                ['model', 'type'], context)[0]
                model = view_base['model']
                view = Rpc.session.execute('/object', 'execute',
                                           view_base['model'],
                                           'fields_view_get', view_ids[0],
                                           view_base['type'], context)
            else:
                view = Rpc.session.execute('/object', 'execute', model,
                                           'fields_view_get', False, view_type,
                                           context)
            win = TreeWidget(view, model, domain, context, name=name)
        except Rpc.RpcException as e:
            QApplication.restoreOverrideCursor()
            return
        QApplication.restoreOverrideCursor()
        Api.instance.windowCreated(win, target)
    else:
        Debug.error('unknown view type: ' + view_type)
Exemplo n.º 2
0
 def tagStart(self, name, attrs):
     if name == 'tree':
         self.title = attrs.get('string', _('Tree'))
         self.toolbar = bool(attrs.get('toolbar', False))
     elif name == 'field':
         if 'icon' in attrs:
             self.fieldsOrder.append(str(attrs['icon']))
         self.fieldsOrder.append(str(attrs['name']))
     else:
         Debug.error('unknown tag: ' + str(name))
Exemplo n.º 3
0
    def evaluateExpression(self, dom, checkLoad=True, firstTry=True):
        """
        Evaluates the string expression given by dom. Before passing the dom
        expression to Rpc.session.evaluateExpression a context with
        'current_date', 'time', 'context', 'active_id' and 'parent'
        (if applies) is prepared.

        :param dom:
        :param checkLoad:
        :param firstTry:
        :return:
        """

        if not isinstance(dom, str):
            return dom
        if checkLoad:
            self.ensureIsLoaded()
        d = {}
        for name in self.values:
            d[name] = self.group.fieldObjects[name].get(self,
                                                        checkLoad=checkLoad)

        d['current_date'] = time.strftime('%Y-%m-%d')
        d['time'] = time
        d['context'] = self.context()
        # Avoid setting None in the context as it might be sent to
        # the server and RPC doesn't support None
        d['active_id'] = self.id or False
        # It seems that some modules depend on the existance of 'id'
        # instead of 'active_id'. It has solved, for example, a problem
        # with the c2c_budget module.
        d['id'] = self.id or False
        if self.parent:
            d['parent'] = EvalEnvironment(self.parent)
        try:
            val = Rpc.session.evaluateExpression(dom, d)
        except NameError as exception:
            # If evaluateExpression raises a NameError exception like this one:
            # NameError: name 'unit_amount' is not defined
            # It may be because not all fields are loaded yet, so we'll ensure
            # the model is loaded and re-evaluate. If that doesn't solve the
            # problem (that is firstTry == False) then raise the exception
            # because it's really an issue on the view definition.
            if firstTry:
                self.group.ensureRecordLoaded(self)
                val = self.evaluateExpression(dom, checkLoad, firstTry=False)
            else:
                Debug.error(
                    _('Error evaluating expression: %s') % exception.args)
                val = False
        return val
Exemplo n.º 4
0
 def __del__(self):
     self.rpc = None
     self.modified_fields = None
     self.parent = None
     self.setParent(None)
     for key, value in self.values.items():
         from .Group import RecordGroup
         if isinstance(value, RecordGroup):
             #value.parent.fieldObjects[key].disconnect( SIGNAL('modified'), value )
             value.__del__()
     self.values = {}
     self.invalidFields = []
     if self.id == 2:
         Debug.printReferrers(self)
     self.group = None
Exemplo n.º 5
0
    def __del__(self):
        self.rpc = None
        self.modified_fields = None
        self.parent = None
        self.setParent(None)
        for key, value in self.values.items():
            from .Group import RecordGroup
            if isinstance(value, RecordGroup):
                try:

                    value.parent.fields()[key].disconnect()
                    value.__del__()
                except Exception:
                    pass

        self.values = {}
        self.invalidFields = []
        if self.id == 2:
            Debug.printReferrers(self)
        self.group = None
Exemplo n.º 6
0
    def call(self, url, method, *args):
        pass


try:
    import Pyro.core
    isPyroAvailable = True
except:
    isPyroAvailable = False

isPyroSslAvailable = False
if isPyroAvailable:
    version = Pyro.core.Pyro.constants.VERSION.split('.')
    if int(version[0]) <= 3 and int(version[1]) <= 10:
        Debug.info('To use SSL, Pyro must be version 3.10 or higher; Pyro version %s was found.' %
                   Pyro.core.Pyro.constants.VERSION)
    else:
        try:
            from M2Crypto.SSL import SSLError
            from M2Crypto.SSL.Checker import WrongHost
            isPyroSslAvailable = True
        except:
            Debug.info(
                'M2Crypto not found. Consider installing in order to use Pryo with SSL.')

if not isPyroSslAvailable:
    # Create Dummy Exception so we do not have to complicate code in PyroConnection if
    # SSL is not available.
    class DummyException(Exception):
        pass
    WrongHost = DummyException
Exemplo n.º 7
0
                         target='current'):
            createWindow(view_ids, model, res_id, domain, view_type, window,
                         context, mode, name, autoReload, target)

        def createWebWindow(self, url, title):
            createWebWindow(url, title)

        def windowCreated(self, window, target):
            win.addWindow(window, target)

    Api.instance = KooApi()

    win.show()

    from Koo.Common import Debug
    Debug.installExceptionHook()

    if Settings.value('koo.pos_mode'):
        import Koo.Pos
        app.installEventFilter(Koo.Pos.PosEventFilter(win))

    if Settings.value('koo.enter_as_tab'):
        from Koo.Common import EnterEventFilter
        app.installEventFilter(EnterEventFilter.EnterEventFilter(win))

    if Settings.value('koo.fullscreen'):
        win.showFullScreen()

    if Settings.value('koo.enable_event_filters'):
        from Koo.Common import ArrowsEventFilter
        app.installEventFilter(ArrowsEventFilter.ArrowsEventFilter(win))