Ejemplo n.º 1
0
 def webViewFormTest(self):
     """Just as a demo, load a google search in a web view
 and use the qt api to fill in a search term"""
     self.webView = qt.QWebView()
     self.webView.settings().setAttribute(
         qt.QWebSettings.DeveloperExtrasEnabled, True)
     self.webView.connect('loadFinished(bool)',
                          self.webViewFormLoadedCallback)
     self.webView.show()
     u = qt.QUrl('http://www.google.com')
     self.webView.setUrl(u)
Ejemplo n.º 2
0
    def __init__(self, remoteURI, localURI):
        """ 
        """

        #----------------------
        # Replace all double slashes for local files.
        #----------------------
        localURI = localURI.replace("//", "/").replace("\\\\",
                                                       "/").replace("\\", "/")

        #----------------------
        # Define the remote filesnames. (path included) Ex. for "http://foo/file.exe" returns "http://foo/file.exe"
        #----------------------
        self.fileInfo = {}
        self.fileInfo["remoteURI"] = remoteURI
        self.fileInfo["remoteURINoHost"] = qt.QUrl(remoteURI).path()
        self.fileInfo["remoteHost"] = qt.QUrl(remoteURI).host()

        #----------------------
        # Derived remove URIs.
        #----------------------
        self.fileInfo["remoteDirName"] = os.path.dirname(remoteURI)
        self.fileInfo["remoteBasename"] = os.path.basename(remoteURI)

        #----------------------
        # Local and related derived URIs.
        #----------------------
        self.fileInfo["localURI"] = localURI
        self.fileInfo["localDirName"] = os.path.dirname(localURI)
        self.fileInfo["localBasename"] = os.path.basename(localURI)

        #----------------------
        # Other.
        #----------------------
        if self.fileInfo["remoteBasename"] == self.fileInfo["localBasename"]:
            self.fileInfo["basename"] = os.path.basename(localURI)
            self.fileInfo["basenameNoExtension"] = self.fileInfo[
                "basename"].split(".")[0]
            self.fileInfo["extension"] = "." + self.fileInfo["basename"].split(
                ".")[1]
Ejemplo n.º 3
0
    def getAncestorUri(self, remotePath, ancestorName = None):
        """ Returns an ancestor path based on the provided level.
        """ 
        
        #---------------------
        # Convert the path to a URL to avoid slash errors.
        #---------------------
        remotePath = os.path.dirname(qt.QUrl(remotePath).path())



        #---------------------
        # Split the path by the forward slashes.
        #---------------------
        pathLayers = remotePath.rsplit("/")        
        parentPath = ""
        for pathLayer in pathLayers:
            if pathLayer == ancestorName:
                break
            parentPath += pathLayer + "/"
        return parentPath
Ejemplo n.º 4
0
    def onPresetChanged(self, presetIndex=-1):
        slicer.presetSelector = self.presetSelector
        presetId = self.presetSelector.itemData(
            self.presetSelector.currentIndex)
        heartValveMeasurementNode = self.getHeartValveMeasurementNode()
        if heartValveMeasurementNode:
            heartValveMeasurementNode.SetAttribute(
                'MeasurementPreset', presetId if presetId else "")
        self.measurementPreset = self.logic.getMeasurementPresetById(presetId)

        # Hide all valve node selectors and field selectors
        for widget in self.inputValveNodeLabels + self.inputValveNodeSelectors + \
            self.inputReferenceRequiredCheckBoxes + self.inputReferenceNameLabels + \
            self.inputReferencePointPlaceWidgets + self.inputReferenceResetButtons + \
            self.inputReferenceValueSliders + [self.inputFieldsCommentLabel]:
            widget.hide()

        if not self.measurementPreset:
            self.setDefinitionUrl(qt.QUrl())
            return

        if self.definitionsWidget.url != self.measurementPreset.definitionsUrl:
            self.setDefinitionUrl(
                qt.QUrl(self.measurementPreset.definitionsUrl))

        if self.measurementPreset.inputFieldsComment:
            self.inputFieldsCommentLabel.text = self.measurementPreset.inputFieldsComment
            self.inputFieldsCommentLabel.show()

        # Add new valve selectors (reuse/hide cached selectors and labels,
        # as removing widgets from the layout is very tricky)
        inputValveIds = self.measurementPreset.inputValveIds
        for inputValveIndex in range(len(inputValveIds)):
            if inputValveIndex >= len(self.inputValveNodeSelectors):
                valveLabel = qt.QLabel()
                valveSelector = slicer.qMRMLNodeComboBox()
                valveSelector.nodeTypes = ["vtkMRMLScriptedModuleNode"]
                valveSelector.setNodeTypeLabel("HeartValve",
                                               "vtkMRMLScriptedModuleNode")
                valveSelector.addAttribute("vtkMRMLScriptedModuleNode",
                                           "ModuleName", "HeartValve")
                valveSelector.addEnabled = False
                valveSelector.removeEnabled = True
                valveSelector.noneEnabled = True
                valveSelector.showHidden = True  # scripted module nodes are hidden by default
                valveSelector.renameEnabled = True
                valveSelector.setMRMLScene(slicer.mrmlScene)
                valveSelector.setToolTip("Select heart valve")
                self.valveSelectorsFormLayout.addRow(valveLabel, valveSelector)
                self.inputValveNodeLabels.append(valveLabel)
                self.inputValveNodeSelectors.append(valveSelector)
                self.annulusLabelsMarkupNodes.append(None)
                self.annulusLabelsMarkupNodeObservers.append([])
                valveSelector.connect(
                    "currentNodeChanged(vtkMRMLNode*)",
                    lambda valveNode, inputValveIndex=inputValveIndex: self.
                    onValveNodeSelect(inputValveIndex, valveNode))
            else:
                valveLabel = self.inputValveNodeLabels[inputValveIndex]
                valveSelector = self.inputValveNodeSelectors[inputValveIndex]
            valveLabel.text = self.measurementPreset.inputValveNames[
                inputValveIds[inputValveIndex]]
            valveLabel.show()
            heartValveMeasurementNode = self.getHeartValveMeasurementNode()
            valveNode = heartValveMeasurementNode.GetNodeReference(
                'Valve' + inputValveIds[inputValveIndex])
            valveSelector.setCurrentNode(valveNode)
            self.onValveNodeSelect(inputValveIndex, valveNode)
            valveSelector.show()

        # Add field selectors (reuse/hide cached widgets, as removing widgets from the layout is very tricky)
        inputFields = self.measurementPreset.inputFields
        self.inputFieldValues = {}

        self.fieldsCollapsibleButton.enabled = len(inputFields) != 0

        for inputFieldIndex in range(len(inputFields)):

            # Get widgets
            if inputFieldIndex >= len(self.inputReferenceRequiredCheckBoxes):
                # need to add a new field
                requiredCheckBox = qt.QCheckBox()
                nameLabel = qt.QLabel()
                pointPlaceWidget = slicer.qSlicerMarkupsPlaceWidget()
                pointPlaceWidget.setButtonsVisible(False)
                pointPlaceWidget.placeButton().show()
                pointPlaceWidget.setMRMLScene(slicer.mrmlScene)
                pointPlaceWidget.placeMultipleMarkups = slicer.qSlicerMarkupsPlaceWidget.ForcePlaceSingleMarkup
                pointPlaceWidget.connect(
                    'activeMarkupsFiducialPlaceModeChanged(bool)',
                    lambda enable, inputFieldIndex=inputFieldIndex: self.
                    onReferencePointMarkupPlace(inputFieldIndex, enable))
                resetButton = qt.QPushButton("Reset")
                resetButton.connect('clicked()',
                                    lambda inputFieldIndex=inputFieldIndex:
                                    self.onFieldValueReset(inputFieldIndex))
                valueSlider = ctk.ctkSliderWidget()
                valueSlider.connect(
                    'valueChanged(double)',
                    lambda value, inputFieldIndex=inputFieldIndex: self.
                    onInputFieldValueChanged(inputFieldIndex, value))
                self.fieldsWidgetsGridLayout.addWidget(requiredCheckBox,
                                                       inputFieldIndex, 0)
                self.fieldsWidgetsGridLayout.addWidget(nameLabel,
                                                       inputFieldIndex, 1)
                # Put the pointPlaceWidget and resetButton in the same grid cell, as either one or the other is shown
                hFrame = qt.QFrame()
                hBoxLayout = qt.QHBoxLayout()
                hFrame.setLayout(hBoxLayout)
                pointPlaceWidget.hide()  # only one of widgets will be shown
                resetButton.hide()  # only one of widgets will be shown
                hBoxLayout.addWidget(pointPlaceWidget)
                hBoxLayout.addWidget(resetButton)
                resetButton.checked = True  # to be in sync with enabled status of other widgets
                requiredCheckBox.connect('toggled(bool)', resetButton,
                                         'setEnabled(bool)')
                requiredCheckBox.connect('toggled(bool)', valueSlider,
                                         'setEnabled(bool)')
                requiredCheckBox.connect(
                    'toggled(bool)',
                    lambda enable, inputFieldIndex=inputFieldIndex: self.
                    onFieldValueEnabled(inputFieldIndex, enable))
                self.fieldsWidgetsGridLayout.addWidget(hFrame, inputFieldIndex,
                                                       2)
                self.fieldsWidgetsGridLayout.addWidget(valueSlider,
                                                       inputFieldIndex, 3)
                self.inputReferenceRequiredCheckBoxes.append(requiredCheckBox)
                self.inputReferenceNameLabels.append(nameLabel)
                self.inputReferencePointPlaceWidgets.append(pointPlaceWidget)
                self.inputReferenceResetButtons.append(resetButton)
                self.inputReferenceValueSliders.append(valueSlider)
            else:
                requiredCheckBox = self.inputReferenceRequiredCheckBoxes[
                    inputFieldIndex]
                nameLabel = self.inputReferenceNameLabels[inputFieldIndex]
                pointPlaceWidget = self.inputReferencePointPlaceWidgets[
                    inputFieldIndex]
                resetButton = self.inputReferenceResetButtons[inputFieldIndex]
                valueSlider = self.inputReferenceValueSliders[inputFieldIndex]

            sliderWasBlocked = valueSlider.blockSignals(True)
            checkBoxWasBlocked = requiredCheckBox.blockSignals(True)

            field = inputFields[inputFieldIndex]
            fieldType = field[FIELD_TYPE]
            required = FIELD_REQUIRED in field.keys() and field[FIELD_REQUIRED]
            requiredCheckBox.show()
            if fieldType == FIELD_TYPE_POINT:
                # Reference point
                valveId = field[FIELD_VALVE_ID]
                valveModel = self.inputValveModels[
                    valveId] if valveId in self.inputValveModels.keys(
                    ) else None
                pointPositionAnnulus = valveModel.getAnnulusMarkupPositionByLabel(
                    field[FIELD_NAME]) if valveModel else None

                requiredCheckBox.checked = pointPositionAnnulus is not None
                requiredCheckBox.enabled = True

                nameLabel.text = field[FIELD_NAME] + ' point'
                nameLabel.show()

                pointPlaceWidget.setCurrentNode(
                    self.pointFieldMarkupsNode[inputFieldIndex])
                pointPlaceWidget.enabled = True
                pointPlaceWidget.show()

                if valveId:
                    # point is constrained to the annulus contour, show slider to allow adjustment
                    if pointPositionAnnulus is not None:
                        [_, closestPointIdOnAnnulusCurve
                         ] = valveModel.annulusContourCurve.getClosestPoint(
                             pointPositionAnnulus)
                        pointDistanceAlongCurve = valveModel.annulusContourCurve.getCurveLength(
                            closestPointIdOnAnnulusCurve)
                        valueSlider.minimum = pointDistanceAlongCurve - 20
                        valueSlider.maximum = pointDistanceAlongCurve + 20
                        valueSlider.value = pointDistanceAlongCurve
                    else:
                        valueSlider.minimum = 0
                        valueSlider.maximum = 0
                        valueSlider.value = 0
                    valueSlider.singleStep = 0.1
                    valueSlider.pageStep = 1.0
                    valueSlider.suffix = 'mm'
                    valueSlider.enabled = requiredCheckBox.checked
                    valueSlider.show()
            elif fieldType == FIELD_TYPE_SCALAR:
                requiredCheckBox.checked = required
                requiredCheckBox.enabled = not required
                # Reference value
                nameLabel.text = field[FIELD_NAME]
                nameLabel.show()
                resetButton.show()
                resetButton.enabled = required
                valueSlider.minimum = field[FIELD_MIN_VALUE]
                valueSlider.maximum = field[FIELD_MAX_VALUE]
                valueSlider.value = field[FIELD_DEFAULT_VALUE]
                if required:
                    self.inputFieldValues[field[FIELD_ID]] = valueSlider.value
                valueSlider.singleStep = field[FIELD_STEP_SIZE]
                valueSlider.pageStep = valueSlider.singleStep * 5
                valueSlider.suffix = field[KEY_UNIT]
                valueSlider.enabled = required
                valueSlider.show()

            valueSlider.blockSignals(sliderWasBlocked)
            requiredCheckBox.blockSignals(checkBoxWasBlocked)
Ejemplo n.º 5
0
 def doneGenerating(self):
     self.reset()
     qt.QDesktopServices().openUrl(
         qt.QUrl(qt.QUrl.fromLocalFile(
             self.targetDirectoryButton.directory)))
     print "done generating!!!"
Ejemplo n.º 6
0
 def openLocalConnection(self):
     qt.QDesktopServices.openUrl(qt.QUrl('http://localhost:8080'))