Exemplo n.º 1
0
class TwoStepLandmarkWidget(QWidget):
    """
	TwoStepLandmarkWidget
	"""

    pickedPosition = Signal()

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

        self.textFrame = QTextEdit(
            "<p>Place your mouse over the desired "
            "landmark point. Press 'Space' to shoot a ray through the volume. "
            "Move the volume around and move the mouse to move the locator. "
            "Press 'Space' again to define the final place of the landmark.</p>"
            "<p>You can also use the ray profile to define the landmark's location.</p>"
        )
        self.textFrame.setReadOnly(True)
        self.textFrame.setFrameShape(QFrame.NoFrame)
        self.textFrame.setAutoFillBackground(False)
        self.textFrame.setAttribute(Qt.WA_TranslucentBackground)
        self.textFrame.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.textFrame.setStyleSheet("background: #aaa")

        self.histogramWidget = TrackingHistogramWidget()
        self.histogramWidget.setMinimumHeight(100)
        self.histogramWidget.setVisible(False)

        self.button = QPushButton("Pick current landmark position")
        self.button.clicked.connect(self.applyButtonClicked)
        self.button.setVisible(False)

        layout = QGridLayout()
        layout.setAlignment(Qt.AlignTop)
        layout.setSpacing(0)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self.textFrame)
        layout.addWidget(self.histogramWidget)
        layout.addWidget(self.button)
        self.setLayout(layout)

    def setSamples(self, samples, scope=None):
        self.textFrame.setVisible(False)
        self.histogramWidget.setVisible(True)

        self.histogram = Histogram()
        self.histogram.bins = samples

        if scope:
            self.histogram.minY = scope[0]
            self.histogram.maxY = scope[1]
            self.histogram.enabled = True

        self.histogramWidget.setHistogram(self.histogram)
        self.histogramWidget.setAxeMode(left=HistogramWidget.AxeNormal)
        self.histogramWidget.nodeItem.tracking = True
        self.button.setVisible(True)

    @Slot()
    def applyButtonClicked(self):
        self.pickedPosition.emit()

    @Slot()
    def pickedLocation(self, location):
        self.histogramWidget.nodeItem.tracking = False
        self.button.setVisible(False)
Exemplo n.º 2
0
class FoamDictWidget(QWidget):
    "QWidget to view and edit simple Foam Dictionary"
    def __init__(self, variable_setting, parent=None):
        super(FoamDictWidget, self).__init__(parent)

        self.buttonLayout = QHBoxLayout()
        self.pushButtonInsert = QPushButton("Insert")
        #self.pushButtonLoad = QPushButton("Load default")
        self.pushButtonRestore = QPushButton("Restore")
        self.pushButtonClear = QPushButton("Clear")
        self.buttonLayout.addWidget(self.pushButtonInsert)
        #self.buttonLayout.addWidget(self.pushButtonLoad)
        self.buttonLayout.addWidget(self.pushButtonRestore)
        self.buttonLayout.addWidget(self.pushButtonClear)

        self.buttonPreview = QPushButton('Preview FoamFile write-out')
        self.textPreview = QTextEdit('')
        self.textPreview.setVisible(False)
        self.textPreview.setEnabled(False)

        self.tableWidget = QTableWidget()
        #header, should not sort, has vertical scrollbar
        # set column count, fixed to 2, size of TableItem
        self.tableWidget.setColumnCount(2)
        #5self.tableWidget.setHorizontalHeaderItem(0, )
        self.tableWidget.setHorizontalHeaderLabels(['key', 'value text'])
        # set a default row count, insert as needed
        self.tableWidget.setRowCount(0)

        #PySide has different name other than @QtCore.pyqtSlot, but PySide.QtCore.SLOT
        QtCore.QObject.connect(self.pushButtonInsert, QtCore.SIGNAL("clicked()"), self.insertRow)
        QtCore.QObject.connect(self.pushButtonRestore, QtCore.SIGNAL("clicked()"), self.restoreDict)
        QtCore.QObject.connect(self.pushButtonClear, QtCore.SIGNAL("clicked()"), self.clearDict)
        #
        QtCore.QObject.connect(self.tableWidget, QtCore.SIGNAL("doubleClicked()"), self.showPreview)  # does not work for PySide
        QtCore.QObject.connect(self.buttonPreview, QtCore.SIGNAL("clicked()"), self.showPreview)
        self._previewing = False

        self.settings = variable_setting
        self.restoreDict()

        self.myLayout = QVBoxLayout()
        self.myLayout.addLayout(self.buttonLayout)
        self.myLayout.addWidget(self.tableWidget)
        self.myLayout.addWidget(self.buttonPreview)
        self.myLayout.addWidget(self.textPreview)
        self.setLayout(self.myLayout)

    def dict(self):
        _settings = OrderedDict()
        for i in range(self.tableWidget.rowCount()):
            k = self.tableWidget.item(i, 0).text()
            v = self.tableWidget.item(i, 1).text()  # data() will return QVariant type-> python type
            # validated by non-empty string
            if k and v:
                _settings[k] = v
        return _settings

    def setDict(self, settings):
        self.settings = settings
        self.updateDictView(self.settings)

    def restoreDict(self):
        self.updateDictView(self.settings)

    def updateDictView(self, varible_settings):
        i = 0
        self.clearDict()  # will clear contents, but leave row text empty
        N = self.tableWidget.rowCount()
        for k,v in varible_settings.items():
            # translate seq into unicode
            if i>=N:
                self.tableWidget.insertRow(i)
            kitem = QTableWidgetItem(k)  # also set flags and state, type
            vitem = QTableWidgetItem(v)  # automaticall convert str to unicode to feed QWidget?
            self.tableWidget.setItem(i, 0, kitem)
            self.tableWidget.setItem(i, 1, vitem)  # currently only works for string value !
            i += 1

    #@pyqtSlot()  # PySide use another name "QtCore.Slot()"
    def insertRow(self):
        nRows = self.tableWidget.rowCount()
        self.tableWidget.insertRow(nRows)  # inset one row at the end
        kitem = QTableWidgetItem("")  # also set flags and state, type
        vitem = QTableWidgetItem("")
        self.tableWidget.setItem(nRows, 0, kitem)
        self.tableWidget.setItem(nRows, 1, vitem)

    def clearDict(self):
        self.tableWidget.clearContents()  # keep the header, clear all items

    def showPreview(self):
        if self._previewing:
            self._previewing = False
            self.textPreview.setVisible(False)
            self.buttonPreview.setText('click to preview write out')
        else:
            self._previewing = True
            self.buttonPreview.setText('click on text to hide preview')
            # enable scrollbar ?
            self.textPreview.setText(self.printDict())
            self.textPreview.setVisible(True)

    def loadDefault(self):
        pass

    def printDict(self):
        dictText = "{\n"
        for k,v in self.dict().items():
            dictText += "   {}  {};\n".format(str(k), str(v))
        dictText += "}"
        return dictText
class TwoStepLandmarkWidget(QWidget):
	"""
	TwoStepLandmarkWidget
	"""

	pickedPosition = Signal()

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

		self.textFrame = QTextEdit("<p>Place your mouse over the desired "
			"landmark point. Press 'Space' to shoot a ray through the volume. "
			"Move the volume around and move the mouse to move the locator. "
			"Press 'Space' again to define the final place of the landmark.</p>"
			"<p>You can also use the ray profile to define the landmark's location.</p>")
		self.textFrame.setReadOnly(True)
		self.textFrame.setFrameShape(QFrame.NoFrame)
		self.textFrame.setAutoFillBackground(False)
		self.textFrame.setAttribute(Qt.WA_TranslucentBackground)
		self.textFrame.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
		self.textFrame.setStyleSheet("background: #aaa")

		self.histogramWidget = TrackingHistogramWidget()
		self.histogramWidget.setMinimumHeight(100)
		self.histogramWidget.setVisible(False)

		self.button = QPushButton("Pick current landmark position")
		self.button.clicked.connect(self.applyButtonClicked)
		self.button.setVisible(False)

		layout = QGridLayout()
		layout.setAlignment(Qt.AlignTop)
		layout.setSpacing(0)
		layout.setContentsMargins(0, 0, 0, 0)
		layout.addWidget(self.textFrame)
		layout.addWidget(self.histogramWidget)
		layout.addWidget(self.button)
		self.setLayout(layout)

	def setSamples(self, samples, scope=None):
		self.textFrame.setVisible(False)
		self.histogramWidget.setVisible(True)

		self.histogram = Histogram()
		self.histogram.bins = samples
		
		if scope:
			self.histogram.minY = scope[0]
			self.histogram.maxY = scope[1]
			self.histogram.enabled = True

		self.histogramWidget.setHistogram(self.histogram)
		self.histogramWidget.setAxeMode(left=HistogramWidget.AxeNormal)
		self.histogramWidget.nodeItem.tracking = True
		self.button.setVisible(True)

	@Slot()
	def applyButtonClicked(self):
		self.pickedPosition.emit()

	@Slot()
	def pickedLocation(self, location):
		self.histogramWidget.nodeItem.tracking = False
		self.button.setVisible(False)
Exemplo n.º 4
0
class MainWindow(QMainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)

        #widnow setup
        resolution = QDesktopWidget().screenGeometry()
        self.screen_w = resolution.width()
        self.screen_h = resolution.height()
        self.setGeometry(0, 0, 650, 200)
        self.setWindowTitle('MARS change version' + mof.get_version_suffix())
        self.setWindowIcon(QIcon('icons/rename.jpeg'))

        #center window
        qr = self.frameGeometry()
        cp = QtGui.QDesktopWidget().availableGeometry().center()
        qr.moveCenter(cp)
        self.move(qr.topLeft())
        #adjust size
        self.resize(self.screen_w / 2, self.screen_h / 10)
        self.Menu()
        self.Layout()

        central_widget = QtGui.QWidget()
        central_widget.setLayout(self.main_layout)
        self.setCentralWidget(central_widget)

    def Menu(self):
        #this creates an action exit, a shortcut and status tip
        exitAction = QAction(QIcon('icons/exit.png'), '&Exit', self)
        exitAction.setShortcut('Ctrl+Q')
        exitAction.setStatusTip('Exit application')
        exitAction.triggered.connect(self.close)

        openFile = QAction(QIcon('icons/open.png'), '&Open', self)
        openFile.setShortcut('Ctrl+O')
        openFile.setStatusTip('Open new File')
        openFile.triggered.connect(self.browse)

        runAction = QAction(QIcon('icons/run.png'), '&Run', self)
        runAction.setShortcut('Ctrl+R')
        runAction.setStatusTip('Run Mars')
        runAction.triggered.connect(self.run_event)

    def Layout(self):
        #LAYOUT
        self.directory_prompt = QLabel(self)
        self.directory_prompt.setText("Directory Selected:")
        self.directory_prompt.move(25, 50)
        self.directory_prompt.resize(150, 30)
        self.directory_prompt.setVisible(False)

        self.browse_btn = QPushButton("Browse", self)
        self.browse_btn.move(130, 50)
        self.browse_btn.resize(50, 30)

        self.browse_btn.setStatusTip(" Browse Folder")
        # self.browse_btn.setStyleSheet("background-color: rgb(186, 186, 186); border-radius: 15px;border-style: solid;border-width: 2px;border-color: black;");
        self.browse_btn.clicked.connect(self.browse)

        self.dir_shower = QLabel(self)
        self.dir_shower.setText("")
        self.dir_shower.setVisible(False)

        self.label_version = QLabel(self)
        self.label_version.setText("Version to rename")
        self.label_version.setVisible(False)

        self.version = QTextEdit()
        self.version.setStatusTip("Version to rename example: 1_6")
        self.version.setFixedHeight(30)
        self.version.setFixedWidth(40)
        self.version.setVisible(False)

        self.run_mars = QPushButton("RENAME", self)
        self.run_mars.setVisible(False)
        self.run_mars.move(50, 200)
        self.run_mars.resize(self.screen_w / 2 - 150, 50)
        self.run_mars.setStatusTip('')
        self.run_mars.setStyleSheet(
            "background-color: rgb(142, 229, 171); border-radius: 15px;")
        self.run_mars.clicked.connect(self.run_event)

        self.menu_layout = QtGui.QHBoxLayout()
        self.menu_layout.addWidget(self.browse_btn)
        self.menu_layout.addWidget(self.directory_prompt)
        self.menu_layout.addWidget(self.dir_shower)
        self.menu_layout.addStretch()

        self.version_layout = QtGui.QHBoxLayout()
        self.version_layout.addWidget(self.label_version)
        self.version_layout.addWidget(self.version)
        self.version_layout.addStretch()

        self.run_layout = QtGui.QHBoxLayout()
        self.run_layout.addWidget(self.run_mars)

        self.main_layout = QtGui.QVBoxLayout()
        self.main_layout.addLayout(self.menu_layout)
        self.main_layout.addLayout(self.version_layout)
        self.main_layout.addLayout(self.run_layout)
        self.main_layout.addStretch()

    def browse(self):
        # sender = self.sender()
        dialog = QtGui.QFileDialog()
        dialog.setFileMode(QtGui.QFileDialog.Directory)
        dialog.setOption(QtGui.QFileDialog.ShowDirsOnly)
        self.dirname = dialog.getExistingDirectory(self, 'Choose Directory',
                                                   os.path.curdir)
        if os.path.exists(self.dirname) and os.path.isdir(self.dirname):
            self.dir_shower.setText(self.dirname)
            self.dir_shower.setVisible(True)
            self.directory_prompt.setVisible(True)
            self.version.setVisible(True)
            self.label_version.setVisible(True)
            self.run_mars.setVisible(True)
            return
        else:
            QMessageBox.information(self, " Wrong file selected",
                                    "Select a folder containing .seq files!")

    def run_event(self):
        self.genericThread = GenericThread(self.dirname,
                                           self.version.toPlainText())
        self.genericThread.start()