Ejemplo n.º 1
0
 def actionDuplicate(self, par, obj):
     if obj is not None:
         inx = par.index(obj) + 1
         new = Jso.JIndex(inx, Jso.copyObject(obj.value))
         par.append(new, inx)
         self.treeView.refresh()
         self.flow.add(copy.deepcopy(self.jsonData))
Ejemplo n.º 2
0
 def getData(self):
     if self.paramType == ParamType.Param or self.paramType == ParamType.JSON:
         return Jso.toDict(self.jsonView.jsonData)
     elif self.paramType == ParamType.XML:
         return copy.copy(self.xmlView.xmlData)
     elif self.paramType == ParamType.Table:
         return Jso.toDict(self.tableView.jsonData)
Ejemplo n.º 3
0
 def actionAddValue(self, par, obj):
     if obj is not None:
         inx = par.index(obj) + 1
         new = Jso.JIndex(inx, Jso.copyObject(obj.value))
     else:
         inx = -1
         new = Jso.JIndex(par.count(), self.createLine())
     par.append(new, inx)
     self.treeView.refresh()
     self.flow.add(copy.deepcopy(self.jsonData))
Ejemplo n.º 4
0
 def keyDecode(self, text: str):
     if text == '@null':
         return None
     elif text == '@{}':
         return Jso.JObject()
     elif text == '@[]':
         return Jso.JList()
     elif text.isnumeric():
         return int(text)
     elif text.startswith("'"):
         return text[1:]
     else:
         return text
Ejemplo n.º 5
0
 def actionAddValue(self, par, obj):
     if isinstance(par, Jso.JObject):
         new = Jso.JKey("<new key>", "")
         if obj is not None:
             inx = par.index(obj) + 1
         else:
             inx = -1
         par.addKey(new, inx)
     elif isinstance(par, Jso.JList):
         if obj is not None:
             inx = par.index(obj) + 1
             new = Jso.JIndex(inx, "")
         else:
             inx = -1
             new = Jso.JIndex(par.count(), "")
         par.append(new, inx)
     self.treeView.refresh()
     self.flow.add(copy.deepcopy(self.jsonData))
Ejemplo n.º 6
0
 def actionPasteAsJSON(self):
     import clipboard
     text = clipboard.paste()
     try:
         obj = Jso.fromString(text)
         self.jsonData = obj
         self.treeView.pushSignal()
         self.treeView.refresh()
         self.flow.add(copy.deepcopy(self.jsonData))
     except Exception as ex:
         logging.exception(ex)
         self.treeView.error.emit(str(ex))
Ejemplo n.º 7
0
 def setData(self, param):
     if self.paramType == ParamType.Param or self.paramType == ParamType.JSON:
         if param is not None or isinstance(param, dict) or isinstance(
                 param, list):
             param = Jso.fromObject(param)
         else:
             param = Jso.JObject()
         self.jsonView.setData(param)
     elif self.paramType == ParamType.XML:
         if param is not None:
             if isinstance(param, Et.Element):
                 self.xmlView.setData(param)
             else:
                 # xml = Et.Element('root')
                 self.xmlView.setData(None)
         else:
             # xml = Et.Element('root')
             self.xmlView.setData(None)
     elif self.paramType == ParamType.Table:
         if param is not None and isinstance(param, list):
             param = Jso.fromObject(param)
         else:
             param = Jso.fromObject([])
         self.tableView.setData(self.headerData, param)
Ejemplo n.º 8
0
 def createJsonUi(self, obj, parent: QStandardItem):
     if isinstance(obj.value, Jso.JObject):
         items = []
         for h in self.headerData:
             if h['key'] in obj.value:
                 item = QStandardItem(
                     obj.value.getItem(h['key']).getValueStr())
                 item.setEditable(h['editable'])
                 item.setData(
                     self.getItemData(obj.value.getItem(h['key']), obj))
             else:
                 key = Jso.JKey(h['key'], "")
                 obj.value.addKey(key)
                 item = QStandardItem('')
                 item.setEditable(True)
                 item.setData(self.getItemData(key, obj))
             items.append(item)
         parent.appendRow(items)
Ejemplo n.º 9
0
 def actionAddList(self, par, obj):
     if isinstance(par, Jso.JObject):
         child = Jso.JList()
         new_item = Jso.JIndex(0, "")
         child.append(new_item)
         new = Jso.JKey("<new key>", child)
         if obj is not None:
             inx = par.index(obj) + 1
         else:
             inx = -1
         par.addKey(new, inx)
     elif isinstance(par, Jso.JList):
         child = Jso.JList()
         new_item = Jso.JIndex(0, "")
         child.append(new_item)
         if obj is not None:
             inx = par.index(obj) + 1
             new = Jso.JIndex(inx, child)
         else:
             inx = -1
             new = Jso.JIndex(par.count(), child)
         par.append(new, inx)
     self.treeView.refresh()
     self.flow.add(copy.deepcopy(self.jsonData))
Ejemplo n.º 10
0
 def __init__(self, treeView, model):
     self.treeView: ParamEditor.ParamEditor = treeView
     self.model = model
     self.jsonData = Jso.fromObject([])
     self.headerData = []
     self.flow = ParamEditor.ActionFlow()
Ejemplo n.º 11
0
 def createLine(self):
     obj = Jso.JObject()
     for col in self.headerData:
         obj.addKey(Jso.JKey(col['key'], ""))
     return obj
Ejemplo n.º 12
0
 def actionClearAll(self):
     self.jsonData = Jso.fromObject([])
     self.treeView.refresh()
     self.treeView.pushSignal()
     self.flow.add(copy.deepcopy(self.jsonData))
Ejemplo n.º 13
0
 def actionCopyAsJSON(self):
     text = Jso.toString(self.jsonData.get('JSON'))
     import clipboard
     clipboard.copy(text)
Ejemplo n.º 14
0
    def createMenu(self, position, tpe, par, obj, item):
        # global
        undoAction = QAction('Undo', self.treeView)
        undoAction.setEnabled(not self.flow.isEnd())
        redoAction = QAction('Redo', self.treeView)
        redoAction.setEnabled(not self.flow.isFirst())
        copyAsJSON = QAction('Copy as JSON', self.treeView)

        pasteAsJSON = QAction('Paste as JSON', self.treeView)
        clearAll = QAction('Clear table', self.treeView)

        # delete
        copyTextAction = QAction('Copy text', self.treeView)
        pasteTextAction = QAction("Paste text", self.treeView)

        deleteKeyAction = QAction('Delete key', self.treeView)

        # duplicate
        duplicateAction = QAction('Duplicate', self.treeView)

        # add
        addKeyMenu = QMenu("Add..")
        Utilities.Style.applyStyle(addKeyMenu)

        # add value
        addValueAction = QAction('Add Value', self.treeView)

        # add object
        addObjectAction = QAction('Add Object', self.treeView)

        # add list
        addListAction = QAction('Add List', self.treeView)

        addKeyMenu.addAction(addValueAction)
        if self.treeView.paramType != ParamEditor.ParamType.Param:
            addKeyMenu.addAction(addObjectAction)
            addKeyMenu.addAction(addListAction)

        # insert
        insertKeyMenu = QMenu("Insert..")
        Utilities.Style.applyStyle(insertKeyMenu)

        # insert value
        insertValueAction = QAction('Insert Value', self.treeView)

        # insert object
        insertObjectAction = QAction('Insert Object', self.treeView)

        # insert list
        insertListAction = QAction('Insert List', self.treeView)

        insertKeyMenu.addAction(insertValueAction)
        insertKeyMenu.addAction(insertObjectAction)
        insertKeyMenu.addAction(insertListAction)

        menu = QMenu()
        Utilities.Style.applyStyle(menu)
        menu.addAction(copyAsJSON)
        if self.treeView.editable:
            menu.addAction(undoAction)
            menu.addAction(redoAction)
            menu.addAction(pasteAsJSON)
            menu.addAction(clearAll)
            menu.addSeparator()

        if self.treeView.editable:
            if tpe == 0:  # index
                menu.addAction(copyTextAction)
                menu.addAction(pasteTextAction)
                menu.addAction(duplicateAction)
                if self.treeView.paramType != ParamEditor.ParamType.Param:
                    menu.addMenu(insertKeyMenu)
                menu.addMenu(addKeyMenu)
                menu.addAction(deleteKeyAction)
            elif tpe == 1:  # key
                menu.addAction(copyTextAction)
                menu.addAction(pasteTextAction)
                if obj.isEmpty(
                ) and self.treeView.paramType != ParamEditor.ParamType.Param:
                    menu.addMenu(insertKeyMenu)
                menu.addMenu(addKeyMenu)
                menu.addAction(deleteKeyAction)
            elif tpe == 2:  # obj
                menu.addAction(copyTextAction)
                menu.addAction(pasteTextAction)
                if self.treeView.paramType != ParamEditor.ParamType.Param:
                    menu.addMenu(insertKeyMenu)
                menu.addMenu(addKeyMenu)
                menu.addAction(deleteKeyAction)
            else:  # table
                menu.addMenu(addKeyMenu)
        else:
            if tpe == 0 or tpe == 1 or tpe == 2:
                menu.addAction(copyTextAction)
        action = menu.exec_(self.treeView.viewport().mapToGlobal(position))

        if action == undoAction:
            self.flowAction(1)
        elif action == redoAction:
            self.flowAction(0)
        elif action == copyAsJSON:
            self.actionCopyAsJSON()
        elif action == pasteAsJSON:
            self.actionPasteAsJSON()
        elif action == clearAll:
            self.actionClearAll()
        elif action == copyTextAction:
            self.actionCopyText(item)
        elif action == pasteTextAction:
            self.actionPasteText(item)
        elif action == deleteKeyAction:
            self.actionDelete(par, obj)
        elif action == duplicateAction:
            self.actionDuplicate(par, obj)
        elif action == addValueAction:
            self.actionAddValue(par, obj)
        elif action == addObjectAction:
            self.actionAddObject(par, obj)
        elif action == addListAction:
            self.actionAddList(par, obj)
        elif action == insertValueAction:
            if obj.isEmpty():
                obj.value = Jso.JObject()
            self.actionAddValue(obj.value, None)
        elif action == insertObjectAction:
            if obj.isEmpty():
                obj.value = Jso.JObject()
            self.actionAddObject(obj.value, None)
        elif action == insertListAction:
            if obj.isEmpty():
                obj.value = Jso.JList()
            self.actionAddList(obj.value, None)
Ejemplo n.º 15
0
 def __init__(self, treeView, model):
     self.treeView: ParamEditor.ParamEditor = treeView
     self.model = model
     self.jsonData = Jso.JObject()
     self.flow = ParamEditor.ActionFlow()