Ejemplo n.º 1
0
    def __init__(self, parent: QWidget):
        super().__init__(parent)

        x = parent.x() + parent.width() / 2 - 200
        y = parent.y() + parent.height() / 2 - 100
        window_rect = QRect(x, y, 400, 300)
        self.setGeometry(window_rect)

        self.tableLink = ParamEditor(ParamType.Param)
        self.tableLink.setHeaderVisible(False)
        self.tableLink.setEditable(False)

        self.closeButton = PClose()
        self.closeButton.pressed.connect(lambda: self.completeDestroy(0))

        self.addWindowAction(self.closeButton)

        layout = QVBoxLayout()
        layout.addWidget(self.tableLink)

        widget = QWidget()
        widget.setLayout(layout)
        widget.setObjectName(Parapluie.Object_Raised_Off)

        self.setCentralWidget(widget)
        self.setWindowTitle("XuCompa - Request")
        Utilities.Style.applyWindowIcon(self)

        self.tableLink.setData(appInformation.app)
        self.tableLink.refresh()
Ejemplo n.º 2
0
    def __init__(self, parent: QWidget, rect: QRect = None):
        super().__init__(parent)

        if rect is None:
            x = parent.x() + parent.width() / 2 - 200
            y = parent.y() + parent.height() / 2 - 150
            window_rect = QRect(x, y, 400, 300)
        else:
            x = rect.x() + rect.width() / 2 - 200
            y = rect.y() + rect.height() / 2 - 150
            window_rect = QRect(x, y, 400, 300)
        self.setGeometry(window_rect)

        self.tableLink = ParamEditor(ParamType.Table)
        self.tableLink.setHeaderData([{
            'key': 'name',
            'name': 'NAME',
            'editable': True,
            'data-type': str.__class__
        }, {
            'key': 'url',
            'name': 'LINK',
            'editable': True,
            'data-type': str.__class__
        }])

        self.closeButton = QPushButton("Close")
        self.closeButton.pressed.connect(lambda: self.completeDestroy(0))
        self.saveButton = QPushButton("Save")
        self.saveButton.setObjectName(Parapluie.Object_OptimizeButton)
        self.saveButton.pressed.connect(self.save)

        bottomLayout = QHBoxLayout()
        bottomLayout.setContentsMargins(0, 4, 0, 0)
        bottomLayout.setAlignment(Qt.AlignRight)
        bottomLayout.addWidget(self.closeButton)
        bottomLayout.addWidget(self.saveButton)

        layout = QVBoxLayout()
        layout.setContentsMargins(10, 10, 10, 0)
        layout.addWidget(self.tableLink)
        layout.addLayout(bottomLayout)

        widget = QWidget()
        widget.setLayout(layout)
        widget.setObjectName(Parapluie.Object_Raised_Off)
        self.setCentralWidget(widget)
        self.setWindowTitle("API Link define")
        Utilities.Style.applyWindowIcon(self)

        self.listLink = []
        self.loadData()
Ejemplo n.º 3
0
    def __init__(self):
        super().__init__()
        self.setObjectName(Parapluie.Object_Raised)
        self.setMinimumHeight(400)
        self.resizable(True)
        self.setSizeBox(400, 1000, 200)
        self.sizeBox.setValue(800)

        self.header = ParamEditor(ParamType.Param)
        self.header.setEditable(False)

        self.analysis = ParamEditor(ParamType.JSON)
        self.analysis.setEditable(False)

        self.result = ParamEditor(ParamType.JSON)

        self.editor = TextEditWidget(save=True)
        self.editor.setTitle('Result')
        self.editor.title.setVisible(False)
        self.editor.alert.connect(
            lambda a, b, c, d: self.alert.emit(a, b, c, d))

        self.paramConnect = ParamEditorConnect(self.result, self.editor)
        self.editor.setEditorType(EditorType.Text)

        self.webView = QWebEngineView()

        splitter = QSplitter()
        splitter.addWidget(self.editor)
        splitter.addWidget(self.result)
        splitter.setObjectName(Parapluie.Object_QSplitter)

        self.addTab(splitter, "Data")
        self.addTab(self.webView, "Preview")
        self.addTab(self.header, "Header")
        self.addTab(self.analysis, "Analysis")

        self.response: APIResponse = APIResponse()
        self.data: APIData = APIData()
        self.currentChanged.connect(self.tabChanged)
Ejemplo n.º 4
0
    def __init__(self):
        super().__init__()
        self.setObjectName(Parapluie.Object_Raised)

        self.editor = TextEditWidget(save=False)

        self.paramEditor = ParamEditor()
        self.paramConnect = ParamEditorConnect(self.paramEditor, self.editor)
        self.editor.setEditorType(EditorType.Text)

        l3 = QSplitter()
        l3.setObjectName(Parapluie.Object_QSplitter)
        l3.setOrientation(Qt.Horizontal)
        l3.addWidget(self.editor)
        l3.addWidget(self.paramEditor)

        layout = QVBoxLayout()
        layout.addWidget(l3)
        self.setLayout(layout)
        self.layout().setContentsMargins(0, 8, 0, 0)
Ejemplo n.º 5
0
class RequestResult(PTabWidget):
    alert = pyqtSignal(str, str, object, object)

    def __init__(self):
        super().__init__()
        self.setObjectName(Parapluie.Object_Raised)
        self.setMinimumHeight(400)
        self.resizable(True)
        self.setSizeBox(400, 1000, 200)
        self.sizeBox.setValue(800)

        self.header = ParamEditor(ParamType.Param)
        self.header.setEditable(False)

        self.analysis = ParamEditor(ParamType.JSON)
        self.analysis.setEditable(False)

        self.result = ParamEditor(ParamType.JSON)

        self.editor = TextEditWidget(save=True)
        self.editor.setTitle('Result')
        self.editor.title.setVisible(False)
        self.editor.alert.connect(
            lambda a, b, c, d: self.alert.emit(a, b, c, d))

        self.paramConnect = ParamEditorConnect(self.result, self.editor)
        self.editor.setEditorType(EditorType.Text)

        self.webView = QWebEngineView()

        splitter = QSplitter()
        splitter.addWidget(self.editor)
        splitter.addWidget(self.result)
        splitter.setObjectName(Parapluie.Object_QSplitter)

        self.addTab(splitter, "Data")
        self.addTab(self.webView, "Preview")
        self.addTab(self.header, "Header")
        self.addTab(self.analysis, "Analysis")

        self.response: APIResponse = APIResponse()
        self.data: APIData = APIData()
        self.currentChanged.connect(self.tabChanged)

    def pushAlert(self, text, tpe=Parapluie.Alert_Error):
        self.alert.emit(text, tpe, None, None)

    def setResponse(self, apiData):
        if apiData is not None:
            self.response = apiData.parseResponse()
            self.data = apiData
        else:
            self.response = APIResponse()
            self.data = APIData()
        self.editor.setTitle(self.data.parseConfig().api())
        self.refresh()

    def refresh(self):
        if self.response is None:
            self.response: APIResponse = APIResponse()
            self.clearData()
        else:
            try:
                if "Content-Type" in self.response.header():
                    contentType, charset = BodyType.getContentType(
                        self.response.header()['Content-Type'])
                    if contentType.startswith("image"):
                        self.editor.setData({})
                        url = QUrl(self.response.parseAnalysis().url())
                        self.webView.load(url)
                        self.editor.setEditorType(EditorType.Text)
                        self.editor.blockEditorType(True)
                        self.editor.setText(str(self.response.content()))
                    else:
                        self.editor.blockEditorType(False)
                        if isinstance(self.response.content(), bytes):
                            if charset is not None:
                                content = str(
                                    self.response.content().decode(charset))
                            else:
                                try:
                                    content = str(
                                        self.response.content().decode(
                                            'utf-8'))
                                except Exception as ex:
                                    logging.exception(ex)
                                    self.pushAlert(str(ex))
                                    content = str(self.response.content())
                        else:
                            content = self.response.content()

                        if self.currentIndex() == 0:  # data
                            if "json" in contentType:
                                self.editor.setEditorType(EditorType.JSON)
                                self.editor.setText(content)
                            elif "xml" in contentType:
                                self.editor.setEditorType(EditorType.XML)
                                self.editor.setText(content)
                            elif "html" in contentType:
                                self.editor.setEditorType(EditorType.HTML)
                                self.editor.setText(content)
                            elif "javascript" in contentType:
                                self.editor.setEditorType(
                                    EditorType.Javascript)
                                self.editor.setText(content)
                            else:
                                self.editor.setEditorType(EditorType.Text)
                                self.editor.setText(content)
                        elif self.currentIndex() == 1:  # preview
                            url = QUrl(self.response.parseAnalysis().url())
                            if "html" in contentType:
                                self.webView.setHtml(content, url)
                            else:
                                html = "<div>" + content + "</div>"
                                self.webView.setHtml(html, url)
                    if self.currentIndex() == 2:  # header
                        self.header.setData(self.response.header())
                        self.header.refresh()
                    elif self.currentIndex() == 3:  # analysis
                        data = self.__analysis()
                        self.analysis.setData(data)
                        self.analysis.refresh()
                else:
                    if self.response.header() != {}:
                        self.pushAlert("Content-Type error, see Header")
                        self.header.setData(self.response.header())
                        data = self.__analysis()
                        self.analysis.setData(data)
                        self.analysis.refresh()
            except Exception as ex:
                logging.exception(ex)
                self.pushAlert(str(ex))

    def clearData(self):
        self.editor.setData({})
        self.header.setData({})
        self.analysis.setData({})
        self.webView.setHtml("<html></html>")

    def tabChanged(self, index):
        self.refresh()

    def __analysis(self):
        header = self.data.parseConfig().header()
        data = self.response.parseAnalysis()
        data.setSendHeader(header)
        return data.analysis
Ejemplo n.º 6
0
class RequestLink(PSticky):
    alert = pyqtSignal(str, str, object, object)

    def __init__(self, parent: QWidget, rect: QRect = None):
        super().__init__(parent)

        if rect is None:
            x = parent.x() + parent.width() / 2 - 200
            y = parent.y() + parent.height() / 2 - 150
            window_rect = QRect(x, y, 400, 300)
        else:
            x = rect.x() + rect.width() / 2 - 200
            y = rect.y() + rect.height() / 2 - 150
            window_rect = QRect(x, y, 400, 300)
        self.setGeometry(window_rect)

        self.tableLink = ParamEditor(ParamType.Table)
        self.tableLink.setHeaderData([{
            'key': 'name',
            'name': 'NAME',
            'editable': True,
            'data-type': str.__class__
        }, {
            'key': 'url',
            'name': 'LINK',
            'editable': True,
            'data-type': str.__class__
        }])

        self.closeButton = QPushButton("Close")
        self.closeButton.pressed.connect(lambda: self.completeDestroy(0))
        self.saveButton = QPushButton("Save")
        self.saveButton.setObjectName(Parapluie.Object_OptimizeButton)
        self.saveButton.pressed.connect(self.save)

        bottomLayout = QHBoxLayout()
        bottomLayout.setContentsMargins(0, 4, 0, 0)
        bottomLayout.setAlignment(Qt.AlignRight)
        bottomLayout.addWidget(self.closeButton)
        bottomLayout.addWidget(self.saveButton)

        layout = QVBoxLayout()
        layout.setContentsMargins(10, 10, 10, 0)
        layout.addWidget(self.tableLink)
        layout.addLayout(bottomLayout)

        widget = QWidget()
        widget.setLayout(layout)
        widget.setObjectName(Parapluie.Object_Raised_Off)
        self.setCentralWidget(widget)
        self.setWindowTitle("API Link define")
        Utilities.Style.applyWindowIcon(self)

        self.listLink = []
        self.loadData()

    def loadData(self):
        self.getData()
        self.tableLink.setData(self.listLink)
        self.tableLink.refresh()

    def getData(self):
        try:
            path = Config.getAPILinkFile()
            file = open(path, 'r', encoding='utf-8')
            data = file.read()
            file.close()
            self.listLink = json.loads(data)
        except Exception as ex:
            logging.exception(ex)
            self.alert.emit(str(ex))

    def save(self):
        self.listLink = self.tableLink.getData()
        try:
            path = Config.getAPILinkFile()
            file = open(path, 'w', encoding='utf-8')
            file.write(Formatter.dumps(self.listLink, EditorType.JSON, None))
            file.close()
            self.completeDestroy(1)
        except Exception as ex:
            logging.exception(ex)
            self.alert.emit(str(ex))
Ejemplo n.º 7
0
    def __init__(self):
        super().__init__()

        # line 1
        self.apiType = PComboBox()
        self.apiType.setFixedWidth(100)
        self.apiType.setView(listView())
        self.apiType.addItem("GET")
        self.apiType.addItem("POST")
        self.apiType.addItem("PUT")
        self.apiType.addItem("HEAD")
        self.apiType.addItem("DELETE")
        self.apiType.addItem("PATCH")
        self.apiType.addItem("OPTIONS")
        self.apiType.setObjectName(Parapluie.Object_ColorComboBox)

        self.apiURL = QLineEdit()
        self.apiURL.setPlaceholderText("API..")

        l1 = QHBoxLayout()
        l1.setSpacing(10)
        l1.addWidget(self.apiType)
        l1.addWidget(self.apiURL)

        # line 2
        addLink = QToolButton()
        addLink.setIcon(PResource.defaultIcon(Parapluie.Icon_Plus_Svg))
        addLink.setIconSize(QSize(12, 12))
        addLink.setFixedSize(32, 32)
        addLink.pressed.connect(self.openApiLinkEdit)

        self.apiLink = PComboBox()
        self.apiLink.setView(listView())
        self.apiLink.setSizeAdjustPolicy(
            QComboBox.AdjustToMinimumContentsLength)

        apiBar = QHBoxLayout()
        apiBar.setSpacing(6)
        apiBar.setContentsMargins(0, 0, 0, 0)
        apiBar.addWidget(self.apiLink, stretch=1)
        apiBar.addWidget(addLink)

        l2 = QFormLayout()
        l2.setVerticalSpacing(6)
        l2.setHorizontalSpacing(10)

        l2.addRow(formLabel("API Link:"), apiBar)

        # line 3
        self.bodyWidget = RequestBody()
        self.bodyWidget.editor.alert.connect(
            lambda a, b, c, d: self.alert.emit(a, b, c, d))

        self.paramWidget = ParamEditor(ParamType.Param)

        self.headerWidget = ParamEditor(ParamType.Param)

        self.tab = PTabWidget()
        self.tab.resizable(True)
        self.tab.setSizeBox(300, 1000, 200)
        self.tab.sizeBox.setValue(400)
        self.tab.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.tab.addTab(self.headerWidget, "Header")
        self.tab.addTab(self.paramWidget, "Param")
        self.tab.addTab(self.bodyWidget, "Body")

        lLeft = QVBoxLayout()
        lLeft.setContentsMargins(0, 0, 0, 0)
        lLeft.setAlignment(Qt.AlignTop)
        lLeft.addLayout(l1)
        lLeft.addLayout(l2)
        lLeft.addSpacing(15)
        lLeft.addWidget(self.tab)

        wLeft = PWidget()
        wLeft.setLayout(lLeft)
        wLeft.setObjectName(Parapluie.Object_Raised)

        self.description = QTextEdit()
        self.description.setMinimumHeight(300)
        self.description.setMaximumHeight(300)

        self.categories = PEditor()

        form = QFormLayout()
        form.setVerticalSpacing(6)
        form.setHorizontalSpacing(6)

        form.addRow(formLabel("Categories:", False), self.categories)
        form.addRow(formLabel("Description:", False), self.description)

        lRight = QVBoxLayout()
        lRight.setContentsMargins(0, 0, 10, 0)
        lRight.addLayout(form)
        lRight.addStretch()
        lRight.addStretch()

        wRight = PWidget()
        wRight.setLayout(lRight)
        wRight.setObjectName(Parapluie.Object_Raised)

        self.addWidget(wLeft)
        self.addWidget(wRight)
        self.setObjectName(Parapluie.Object_QSplitter)
        self.setChildrenCollapsible(False)
        self.setStretchFactor(0, 4)
        self.setStretchFactor(1, 3)

        self.dialog = RequestLink(
            self, QRect(QPoint(0, 0),
                        QApplication.primaryScreen().size()))
        self.dialog.getData()
        self.updateAPILink()
Ejemplo n.º 8
0
class RequestParam(QSplitter):
    alert = pyqtSignal(str, str, object, object)

    def __init__(self):
        super().__init__()

        # line 1
        self.apiType = PComboBox()
        self.apiType.setFixedWidth(100)
        self.apiType.setView(listView())
        self.apiType.addItem("GET")
        self.apiType.addItem("POST")
        self.apiType.addItem("PUT")
        self.apiType.addItem("HEAD")
        self.apiType.addItem("DELETE")
        self.apiType.addItem("PATCH")
        self.apiType.addItem("OPTIONS")
        self.apiType.setObjectName(Parapluie.Object_ColorComboBox)

        self.apiURL = QLineEdit()
        self.apiURL.setPlaceholderText("API..")

        l1 = QHBoxLayout()
        l1.setSpacing(10)
        l1.addWidget(self.apiType)
        l1.addWidget(self.apiURL)

        # line 2
        addLink = QToolButton()
        addLink.setIcon(PResource.defaultIcon(Parapluie.Icon_Plus_Svg))
        addLink.setIconSize(QSize(12, 12))
        addLink.setFixedSize(32, 32)
        addLink.pressed.connect(self.openApiLinkEdit)

        self.apiLink = PComboBox()
        self.apiLink.setView(listView())
        self.apiLink.setSizeAdjustPolicy(
            QComboBox.AdjustToMinimumContentsLength)

        apiBar = QHBoxLayout()
        apiBar.setSpacing(6)
        apiBar.setContentsMargins(0, 0, 0, 0)
        apiBar.addWidget(self.apiLink, stretch=1)
        apiBar.addWidget(addLink)

        l2 = QFormLayout()
        l2.setVerticalSpacing(6)
        l2.setHorizontalSpacing(10)

        l2.addRow(formLabel("API Link:"), apiBar)

        # line 3
        self.bodyWidget = RequestBody()
        self.bodyWidget.editor.alert.connect(
            lambda a, b, c, d: self.alert.emit(a, b, c, d))

        self.paramWidget = ParamEditor(ParamType.Param)

        self.headerWidget = ParamEditor(ParamType.Param)

        self.tab = PTabWidget()
        self.tab.resizable(True)
        self.tab.setSizeBox(300, 1000, 200)
        self.tab.sizeBox.setValue(400)
        self.tab.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.tab.addTab(self.headerWidget, "Header")
        self.tab.addTab(self.paramWidget, "Param")
        self.tab.addTab(self.bodyWidget, "Body")

        lLeft = QVBoxLayout()
        lLeft.setContentsMargins(0, 0, 0, 0)
        lLeft.setAlignment(Qt.AlignTop)
        lLeft.addLayout(l1)
        lLeft.addLayout(l2)
        lLeft.addSpacing(15)
        lLeft.addWidget(self.tab)

        wLeft = PWidget()
        wLeft.setLayout(lLeft)
        wLeft.setObjectName(Parapluie.Object_Raised)

        self.description = QTextEdit()
        self.description.setMinimumHeight(300)
        self.description.setMaximumHeight(300)

        self.categories = PEditor()

        form = QFormLayout()
        form.setVerticalSpacing(6)
        form.setHorizontalSpacing(6)

        form.addRow(formLabel("Categories:", False), self.categories)
        form.addRow(formLabel("Description:", False), self.description)

        lRight = QVBoxLayout()
        lRight.setContentsMargins(0, 0, 10, 0)
        lRight.addLayout(form)
        lRight.addStretch()
        lRight.addStretch()

        wRight = PWidget()
        wRight.setLayout(lRight)
        wRight.setObjectName(Parapluie.Object_Raised)

        self.addWidget(wLeft)
        self.addWidget(wRight)
        self.setObjectName(Parapluie.Object_QSplitter)
        self.setChildrenCollapsible(False)
        self.setStretchFactor(0, 4)
        self.setStretchFactor(1, 3)

        self.dialog = RequestLink(
            self, QRect(QPoint(0, 0),
                        QApplication.primaryScreen().size()))
        self.dialog.getData()
        self.updateAPILink()

    def openApiLinkEdit(self):
        self.dialog.loadData()
        rs = self.dialog.exec_()
        if rs == 1:
            self.updateAPILink()

    def pushAlert(self, text, tpe=Parapluie.Alert_Error):
        self.alert.emit(text, tpe, None, None)

    def getData(self, save=False) -> APIConfig:
        config = APIConfig()
        api = self.getURL()
        link = self.getLink()
        protocol = self.getProtocol()
        param = self.paramWidget.getData()
        header = self.headerWidget.getData()
        body, tpe = self.bodyWidget.getData()

        description = self.description.toPlainText()

        config.setAPI(api)
        config.setLink(link)
        config.setProtocol(protocol)
        config.setBody(body, tpe)
        config.setParam(param)
        config.setHeader(header)
        config.setDescription(description)

        if not save:
            if api == "" or api.isspace():
                self.pushAlert("API URL can not empty!", Parapluie.Alert_Error)
            else:
                if protocol is None:
                    self.pushAlert("Protocol error!")
                else:
                    return config
        else:
            return config

    # get
    def getProtocol(self) -> str:
        return self.apiType.currentText().title().upper()

    def getURL(self) -> str:
        return self.apiURL.text()

    def getLink(self) -> APILink:
        linkInx = self.apiLink.currentIndex()
        if len(self.dialog.listLink) + 1 > linkInx > 0:
            data = self.dialog.listLink[linkInx - 1]
            link = APILink()
            link.construct(data)
            return link
        else:
            defaultLink = APILink()
            defaultLink.setURL("")
            defaultLink.setName("..")
            return defaultLink

    # set
    def setConfig(self, config: APIConfig = None):
        if config is None:
            config = APIConfig()
            self.setURL(config.api())
            self.setAPILink(config.parseLink().url())
            self.apiType.setCurrentIndex(0)
        else:
            self.setURL(config.api())
            self.setAPIType(config.protocol())
            self.setAPILink(config.parseLink().url())
        self.setDescription(config.description())
        self.setBody(config.body(), config.bodyType())
        self.setParam(config.param())
        if config.param() is None or config.param() == {} or config.param(
        ) == []:
            if config.body() is not None and config.body(
            ) != {} and config.body() != [] and config.body() != "":
                self.tab.setCurrentIndex(2)
        else:
            self.tab.setCurrentIndex(1)

    def setURL(self, url):
        self.apiURL.setText(url)

    def setAPIType(self, tpe):
        if tpe == "GET":
            self.apiType.setCurrentIndex(0)
        elif tpe == "POST":
            self.apiType.setCurrentIndex(1)
        elif tpe == "PUT":
            self.apiType.setCurrentIndex(2)
        elif tpe == "HEAD":
            self.apiType.setCurrentIndex(3)
        elif tpe == "DELETE":
            self.apiType.setCurrentIndex(4)
        elif tpe == "PATCH":
            self.apiType.setCurrentIndex(5)
        elif tpe == "OPTIONS":
            self.apiType.setCurrentIndex(6)
        else:
            self.apiType.setCurrentIndex(0)

    def updateAPILink(self):
        self.apiLink.clear()
        self.apiLink.addItem("..")
        for item in self.dialog.listLink:
            i = APILink()
            i.construct(item)
            self.apiLink.addItem(i.name() + " (" + i.url() + ").")

    def setAPILink(self, link: str) -> bool:
        for i in range(len(self.dialog.listLink)):
            item = APILink()
            item.construct(self.dialog.listLink[i])
            if item.url() == link:
                self.apiLink.setCurrentIndex(i + 1)
                return True
        self.apiLink.setCurrentIndex(0)
        return False

    def setDescription(self, des):
        self.description.setText(des)

    def setParam(self, para):
        self.paramWidget.setData(para)
        self.paramWidget.refresh()

    def setBody(self, js, tpe):
        self.bodyWidget.setData(str(js), tpe)