Beispiel #1
0
class WebFileWidget(QtWidgets.QWidget):
    sgnValidURI = QtCore.pyqtSignal()
    sgnNotValidURI = QtCore.pyqtSignal()

    def __init__(self, session, parent=None):
        """
        Initialize the base information box.
        :type session: Session
        :type parent: QtWidgets.QWidget
        """
        super().__init__(parent)
        self.session = session
        self.isValidUri = False
        uriLabel = QtWidgets.QLabel(self, objectName='uri_label')
        uriLabel.setText('URI')
        self.uriField = StringField(self, objectName='uri_field')
        connect(self.uriField.textChanged, self.onUriFieldChanged)
        formlayout = QtWidgets.QFormLayout()
        formlayout.addRow(uriLabel, self.uriField)
        groupbox = QtWidgets.QGroupBox('Import from remote document', self)
        groupbox.setLayout(formlayout)
        outerFormLayout = QtWidgets.QFormLayout()
        outerFormLayout.addRow(groupbox)
        self.setLayout(outerFormLayout)


    #############################################
    #   SLOTS
    #################################
    @QtCore.pyqtSlot(str)
    def onUriFieldChanged(self, uri):
        if urlparse(uri):
            self.isValidUri = True
            self.sgnValidURI.emit()
            self.uriField.setStyleSheet("color: black;")
        else:
            self.isValidUri = False
            self.sgnNotValidURI.emit()
            self.uriField.setStyleSheet("color: red;")
Beispiel #2
0
class LocalFileWidget(QtWidgets.QWidget):
    sgnValidPath = QtCore.pyqtSignal()
    sgnNotValidPath = QtCore.pyqtSignal()

    def __init__(self, session, parent=None):
        """
        Initialize the base information box.
        :type session: Session
        :type parent: QtWidgets.QWidget
        """
        super().__init__(parent)
        self.session = session
        self.isValidPath = False
        pathLabel = QtWidgets.QLabel(self, objectName='path_label')
        pathLabel.setText('Path')
        self.pathField = StringField(self, objectName='path_field')
        connect(self.pathField.textChanged, self.onPathFieldChanged)
        self.browseBtn = QtWidgets.QPushButton('Browse')
        self.browseBtn.setEnabled(True)
        connect(self.browseBtn.clicked, self.onBrowseClicked)
        formlayout = QtWidgets.QFormLayout()
        formlayout.addRow(pathLabel, self.pathField)
        boxlayout = QtWidgets.QHBoxLayout()
        boxlayout.setAlignment(QtCore.Qt.AlignCenter)
        boxlayout.addWidget(self.browseBtn)
        outerFormLayout = QtWidgets.QFormLayout()
        outerFormLayout.addRow(formlayout)
        outerFormLayout.addRow(boxlayout)
        groupbox = QtWidgets.QGroupBox('Import from local document', self)
        groupbox.setLayout(outerFormLayout)
        outerFormLayout = QtWidgets.QFormLayout()
        outerFormLayout.addRow(groupbox)
        self.setLayout(outerFormLayout)

    #############################################
    #   SLOTS
    #################################
    @QtCore.pyqtSlot(str)
    def onPathFieldChanged(self, path):
        if os.path.isfile(path):
            self.isValidPath = True
            self.sgnValidPath.emit()
            self.pathField.setStyleSheet("color: black;")
        else:
            self.isValidPath = False
            self.sgnNotValidPath.emit()
            self.pathField.setStyleSheet("color: red;")

    @QtCore.pyqtSlot(bool)
    def onBrowseClicked(self,  _):
        """
        Back button pressed
        :type _: bool
        """
        self.browseBtn.setDown(False)
        dialog = QtWidgets.QFileDialog(self)
        dialog.setAcceptMode(QtWidgets.QFileDialog.AcceptOpen)
        dialog.setFileMode(QtWidgets.QFileDialog.ExistingFile)
        dialog.setViewMode(QtWidgets.QFileDialog.Detail)
        dialog.setNameFilter("OWL files (*.owl)")
        if dialog.exec_() == QtWidgets.QFileDialog.Accepted:
            path = first(dialog.selectedFiles())
            if path:
                self.pathField.setText(path)