示例#1
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
示例#2
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))
示例#3
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)