svgui/pyjs/jsonrpc/jsonrpc.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Mon, 18 Apr 2016 19:15:55 +0300
changeset 1481 5b294dcaae18
parent 728 e0424e96e3fd
child 1730 64d8f52bc8c8
permissions -rw-r--r--
fix issue, then it wasn't possible to view FBD programs

the reason for that is possible wx-3.0-gtk2 bug that happens if
ALWAYS_SHOW_SB is set.

Traceback (most recent call last):
File "Beremiz.py", line 1045, in OnProjectTreeItemActivated
IDEFrame.OnProjectTreeItemActivated(self, event)
File "IDEFrame.py", line 1667, in OnProjectTreeItemActivated
self.EditProjectElement(item_infos["type"], item_infos["tagname"])
File "IDEFrame.py", line 1752, in EditProjectElement
new_window = Viewer(self.TabsOpened, tagname, self, self.Controler)
File "editors/Viewer.py", line 611, in __init__
EditorPanel.__init__(self, parent, tagname, window, controler, debug)
File "editors/EditorPanel.py", line 68, in __init__
self._init_ctrls(parent)
File "editors/EditorPanel.py", line 52, in _init_ctrls
self._init_Editor(self)
File "editors/Viewer.py", line 603, in _init_Editor
style=wx.HSCROLL | wx.VSCROLL | wx.ALWAYS_SHOW_SB)
File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk2/wx/_windows.py", line 296, in __init__
_windows_.ScrolledWindow_swiginit(self,_windows_.new_ScrolledWindow(*args, **kwargs))
PyAssertionError: C++ assertion "scrolled" failed at ../src/gtk/scrolwin.cpp(205) in DoShowScrollbars(): window must be created
371
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     1
import gluon.contrib.simplejson as simplejson
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     2
import types
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     3
import sys
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     4
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     5
class JSONRPCServiceBase:
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     6
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     7
    def __init__(self):
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     8
        self.methods={}
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
     9
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    10
    def response(self, id, result):
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    11
        return simplejson.dumps({'version': '1.1', 'id':id,
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    12
                                 'result':result, 'error':None})
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    13
    def error(self, id, code, message):
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    14
        return simplejson.dumps({'id': id,
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    15
                                 'version': '1.1',
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    16
                                 'error': {'name': 'JSONRPCError',
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    17
                                           'code': code,
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    18
                                           'message': message
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    19
                                           }
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    20
                                     })
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    21
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    22
    def add_method(self, name, method):
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    23
        self.methods[name] = method
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    24
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    25
    def process(self, data):
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    26
        data = simplejson.loads(data)
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    27
        id, method, params = data["id"], data["method"], data["params"]
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    28
        if method in self.methods:
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    29
            try:
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    30
                result =self.methods[method](*params)
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    31
                return self.response(id, result)
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    32
            except BaseException:
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    33
                etype, eval, etb = sys.exc_info()
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    34
                return self.error(id, 100, '%s: %s' %(etype.__name__, eval))
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    35
            except:
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    36
                etype, eval, etb = sys.exc_info()
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    37
                return self.error(id, 100, 'Exception %s: %s' %(etype, eval))
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    38
        else:
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    39
            return self.error(id, 100, 'method "%s" does not exist' % method)
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    40
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    41
    def listmethods(self):
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    42
        return self.methods.keys() 
b7cb57a2da08 Adding new svgui support using twisted website HMI
laurent
parents:
diff changeset
    43