def __init__(self, url: QUrl) -> None: super().__init__() self.setupUi(self) self.m_cookies = [] self.m_urlLineEdit.setText(url.toString()) self.m_layout = QVBoxLayout() self.m_layout.addItem( QSpacerItem(0, 0, QSizePolicy.Minimum, QSizePolicy.Expanding)) self.m_layout.setContentsMargins(0, 0, 0, 0) self.m_layout.setSpacing(0) w = QWidget() p = w.palette() p.setColor(self.widget.backgroundRole(), Qt.white) w.setPalette(p) w.setLayout(self.m_layout) self.m_scrollArea.setWidget(w) self.m_scrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.m_scrollArea.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) self.m_urlButton.clicked.connect(self.handleUrlClicked) self.m_deleteAllButton.clicked.connect(self.handleDeleteAllClicked) self.m_newButton.clicked.connect(self.handleNewClicked) self.m_store: QWebEngineCookieStore = self.m_webview.page().profile( ).cookieStore() self.m_store.cookieAdded.connect(self.handleCookieAdded) self.m_store.loadAllCookies() self.m_webview.load(url)
def __init__(self, value, data, attr, particleNum, numColumns, parent=None): QWidget.__init__(self, parent) self.value = value self.data = data self.attr = attr self.particleNum = particleNum self.setFrameShape(QFrame.NoFrame) self.name = 'AttrWidget{}'.format(AttrWidget.widgetNumber) self.setObjectName(self.name) AttrWidget.widgetNumber += 1 self.withBorderStyle = '#%s {border: 1px solid dodgerblue;}' % self.name self.noBorderStyle = '#%s {border: 0px;}' % self.name self.setStyleSheet(self.noBorderStyle) layout = QVBoxLayout() layout.setContentsMargins(0,0,0,0) self.setLayout(layout) idx = 0 self.items = [] self.textValues = [] numRows = int(math.ceil(len(value) / float(numColumns))) for _ in range(numRows): row = QHBoxLayout() layout.addLayout(row) for _ in range(numColumns): item = NumericalEdit(value[idx]) self.textValues.append(str(value[idx])) item.editingFinished.connect(self.applyEdit) row.addWidget(item, Qt.AlignHCenter|Qt.AlignTop) self.items.append(item) idx += 1 if idx == len(self.value): break
def main(): import sys app = QApplication(sys.argv) layout = QVBoxLayout() infos = QSerialPortInfo.availablePorts() for info in infos: s = ( f"Port: {info.portName()}", f"Location: {info.systemLocation()}", f"Description: {info.description()}", f"Manufacturer: {info.manufacturer()}", f"Serial number: {info.serialNumber()}", "Vendor Identifier: " + f"{info.vendorIdentifier():x}" if info.hasVendorIdentifier() else "", "Product Identifier: " + f"{info.productIdentifier():x}" if info.hasProductIdentifier() else "", ) label = QLabel("\n".join(s)) layout.addWidget(label) workPage = QWidget() workPage.setLayout(layout) area = QScrollArea() area.setWindowTitle("Info about all available serial ports.") area.setWidget(workPage) area.show() sys.exit(app.exec_())
def __init__(self): super(VariablesTool, self).__init__() self.setMinimumSize(QtCore.QSize(200, 50)) self.content = QWidget() self.content.setObjectName("VariablesToolContent") self.verticalLayout = QVBoxLayout(self.content) self.verticalLayout.setSpacing(0) self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.verticalLayout.setObjectName("verticalLayout") self.setWidget(self.content)
def _build_ui(self): layout = QVBoxLayout() self.results = QTextBrowser() font = QFontDatabase.systemFont(QFontDatabase.FixedFont) self.results.setFont(font) layout.insertWidget(0, self.results, 1) self.ui_area.setLayout(layout) self.manage(None)
def showSystemSettings(system): from brigks.gui.systemSettingsWidget import SystemSettingsWidget widget = SystemSettingsWidget(system) dialog = QDialog() layout = QVBoxLayout() layout.addWidget(widget) dialog.setLayout(layout) if not dialog.exec_(): return
def DDTree(): tree = TreeWidget() dialog = QDialog() layout = QVBoxLayout() layout.addWidget(tree) dialog.setLayout(layout) if not dialog.exec_(): return
def __init__(self): super(HistoryTool, self).__init__() self.setMinimumSize(QtCore.QSize(200, 50)) self.content = QWidget() self.content.setObjectName("historyToolContent") self.verticalLayout = QVBoxLayout(self.content) self.verticalLayout.setSpacing(0) self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.verticalLayout.setObjectName("verticalLayout") self.undoStackView = QUndoView(self) self.undoStackView.setObjectName("undoStackView") self.verticalLayout.addWidget(self.undoStackView) self.setWidget(self.content)
def get_horizontal_separator(): v_div_w = QWidget() v_div_l = QVBoxLayout() v_div_l.setAlignment(Qt.AlignLeft) v_div_l.setContentsMargins(0, 0, 0, 0) v_div_l.setSpacing(0) v_div_w.setLayout(v_div_l) v_div = QFrame() v_div.setMinimumHeight(30) v_div.setFrameShape(QFrame.VLine) v_div.setFrameShadow(QFrame.Sunken) v_div_l.addWidget(v_div) return v_div_w
def __init__(self, parent): self.figure = Figure() self.canvas = FigureCanvas(self.figure) self.canvas.setParent(parent) self.mpl_toolbar = NavigationToolbar(self.canvas, parent) self.axes = self.figure.add_subplot(111) self.grid_layout = QVBoxLayout() self.grid_layout.addWidget(self.canvas) self.grid_layout.addWidget(self.mpl_toolbar) parent.setLayout(self.grid_layout) self.clear()
class HistoryTool(DockTool): """docstring for History tool.""" def __init__(self): super(HistoryTool, self).__init__() self.setMinimumSize(QtCore.QSize(200, 50)) self.content = QWidget() self.content.setObjectName("historyToolContent") self.verticalLayout = QVBoxLayout(self.content) self.verticalLayout.setSpacing(0) self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.verticalLayout.setObjectName("verticalLayout") self.undoStackView = QUndoView(self) self.undoStackView.setObjectName("undoStackView") self.verticalLayout.addWidget(self.undoStackView) self.setWidget(self.content) @staticmethod def getIcon(): return QtGui.QIcon(RESOURCES_DIR + "/history.png") def onShow(self): super(HistoryTool, self).onShow() self.undoStackView.setStack(self.canvas.undoStack) @staticmethod def defaultDockArea(): return QtCore.Qt.LeftDockWidgetArea @staticmethod def toolTip(): return "Undo stack" @staticmethod def name(): return str("History")
class VariablesTool(DockTool): """docstring for Variables tool.""" def __init__(self): super(VariablesTool, self).__init__() self.setMinimumSize(QtCore.QSize(200, 50)) self.content = QWidget() self.content.setObjectName("VariablesToolContent") self.verticalLayout = QVBoxLayout(self.content) self.verticalLayout.setSpacing(0) self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.verticalLayout.setObjectName("verticalLayout") self.setWidget(self.content) @staticmethod def getIcon(): return QtGui.QIcon(RESOURCES_DIR + "/variable.png") @staticmethod def isSingleton(): return True def onShow(self): super(VariablesTool, self).onShow() self.verticalLayout.addWidget(VariablesWidget(self.canvas)) @staticmethod def toolTip(): return "Variables editing/creation" @staticmethod def name(): return str("Variables")
class VariablesTool(DockTool): """docstring for Variables tool.""" def __init__(self): super(VariablesTool, self).__init__() self.setMinimumSize(QtCore.QSize(200, 50)) self.content = QWidget() self.content.setObjectName("VariablesToolContent") self.verticalLayout = QVBoxLayout(self.content) self.verticalLayout.setSpacing(0) self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.verticalLayout.setObjectName("verticalLayout") self.setWidget(self.content) @staticmethod def getIcon(): return QtGui.QIcon(":variable.png") @staticmethod def isSingleton(): return True def onShow(self): super(VariablesTool, self).onShow() varsWidget = VariablesWidget(self.pyFlowInstance) self.pyFlowInstance.fileBeenLoaded.connect(varsWidget.actualize) self.verticalLayout.addWidget(varsWidget) @staticmethod def toolTip(): return "Variables editing/creation" @staticmethod def name(): return str("Variables")
def __init__(self, data, parent=None): QWidget.__init__(self, parent) self.data = data vbox = QVBoxLayout() self.setLayout(vbox) title = QLabel('Indexed Strings') vbox.addWidget(title) self.frame = QFrame() vbox.addWidget(self.frame) self.vbox = QVBoxLayout() self.frame.setLayout(self.vbox) self.frame.setFrameShape(QFrame.Panel) self.frame.setFrameShadow(QFrame.Sunken) self.table = QTableWidget() self.table.horizontalHeader().hide() self.vbox.addWidget(self.table) self.table.hide() self.noStringsLabel = QLabel('<i>No indexed strings</i>') self.vbox.addWidget(self.noStringsLabel) self.widgets = [] self.populate() self.data.attributeAdded.connect(self.attributeAddedSlot) self.data.dataReset.connect(self.dataResetSlot) self.data.dirtied.connect(self.dataDirtiedSlot)
class TextInput(QWidget): # used when input text inputChanged = Signal() okPressed = Signal() cancelPressed = Signal() def __init__(self, parent=None): super(TextInput, self).__init__(parent) self.setWindowFlags(Qt.Dialog | Qt.FramelessWindowHint) self.mainLayout = QVBoxLayout() self.textArea = QTextEdit(self) self.buttonArea = QWidget(self) self.buttonLayout = QHBoxLayout() self.cancelButton = QPushButton('Cancel', self) self.okButton = QPushButton('Ok', self) self.buttonLayout.addWidget(self.cancelButton) self.buttonLayout.addWidget(self.okButton) self.buttonArea.setLayout(self.buttonLayout) self.mainLayout.addWidget(self.textArea) self.mainLayout.addWidget(self.buttonArea) self.setLayout(self.mainLayout) self.textArea.textChanged.connect(self.textChanged_) self.okButton.clicked.connect(self.okButtonClicked) self.cancelButton.clicked.connect(self.cancelPressed) def getText(self): return self.textArea.toPlainText() def getFocus(self): self.setFocus() self.textArea.setFocus() def clearText(self): self.textArea.clear() # slots def textChanged_(self): self.inputChanged.emit() def cancelButtonClicked(self): self.cancelPressed.emit() def okButtonClicked(self): self.okPressed.emit()
class NodesBox(QWidget): """doc string for NodesBox""" def __init__(self, parent, canvas=None): super(NodesBox, self).__init__(parent) self.canvasRef = weakref.ref(canvas) self.verticalLayout = QVBoxLayout(self) self.verticalLayout.setObjectName("verticalLayout") self.verticalLayout.setContentsMargins(4, 4, 4, 4) self.lineEdit = NodeBoxLineEdit(self) self.lineEdit.setObjectName("lineEdit") self.verticalLayout.addWidget(self.lineEdit) self.treeWidget = NodeBoxTreeWidget(self) self.treeWidget.setObjectName("treeWidget") self.treeWidget.headerItem().setText(0, "1") self.verticalLayout.addWidget(self.treeWidget) self.lineEdit.textChanged.connect(self.leTextChanged) self.treeWidget.refresh() def sizeHint(self): return QtCore.QSize(400, 250) def expandCategory(self): for i in self.treeWidget.categoryPaths: self.treeWidget.setItemExpanded(self.treeWidget.categoryPaths[i], True) def leTextChanged(self): if self.lineEdit.text() == '': self.lineEdit.setPlaceholderText("enter node name..") self.treeWidget.refresh() return self.treeWidget.refresh(None, self.lineEdit.text()) self.expandCategory()
def __init__(self, parent, canvas=None): super(NodesBox, self).__init__(parent) self.canvasRef = weakref.ref(canvas) self.verticalLayout = QVBoxLayout(self) self.verticalLayout.setObjectName("verticalLayout") self.verticalLayout.setContentsMargins(4, 4, 4, 4) self.lineEdit = NodeBoxLineEdit(self) self.lineEdit.setObjectName("lineEdit") self.verticalLayout.addWidget(self.lineEdit) self.treeWidget = NodeBoxTreeWidget(self) self.treeWidget.setObjectName("treeWidget") self.treeWidget.headerItem().setText(0, "1") self.verticalLayout.addWidget(self.treeWidget) self.lineEdit.textChanged.connect(self.leTextChanged) self.treeWidget.refresh()
def setupUi(self, widget): """ Creates and lays out the widgets defined in the ui file. :Parameters: widget : `QtGui.QWidget` Base widget """ #super(PreferencesDialog, self).setupUi(widget) # TODO: Switch back to this if we get loadUiType working. self.baseInstance = loadUiWidget("preferences_dialog.ui", self) self.setWindowIcon(QIcon.fromTheme("preferences-system")) self.buttonFont.setIcon(QIcon.fromTheme("preferences-desktop-font")) self.buttonNewProg.setIcon(QIcon.fromTheme("list-add")) # ----- General tab ----- # Set initial preferences. parent = self.parent() self.checkBox_parseLinks.setChecked(parent.preferences['parseLinks']) self.checkBox_newTab.setChecked(parent.preferences['newTab']) self.checkBox_syntaxHighlighting.setChecked( parent.preferences['syntaxHighlighting']) self.checkBox_teletypeConversion.setChecked( parent.preferences['teletype']) self.checkBox_lineNumbers.setChecked(parent.preferences['lineNumbers']) self.checkBox_showAllMessages.setChecked( parent.preferences['showAllMessages']) self.checkBox_showHiddenFiles.setChecked( parent.preferences['showHiddenFiles']) self.checkBox_autoCompleteAddressBar.setChecked( parent.preferences['autoCompleteAddressBar']) self.useSpacesCheckBox.setChecked(parent.preferences['useSpaces']) self.useSpacesSpinBox.setValue(parent.preferences['tabSpaces']) self.lineEditTextEditor.setText(parent.preferences['textEditor']) self.lineEditDiffTool.setText(parent.preferences['diffTool']) self.updateFontLabel() # ----- Programs tab ----- self.progLayout = QVBoxLayout() self.extLayout = QVBoxLayout() # Extensions can only be: <optional .><alphanumeric><optional comma><optional space> #self.progValidator = QRegExpValidator(QRegExp("[\w,. ]+"), self) self.extValidator = QRegExpValidator(QRegExp(r"(?:\.?\w*,?\s*)+"), self) self.lineEdit.setValidator(self.extValidator) # Create the fields for programs and extensions. self.populateProgsAndExts(parent.programs)
def __init__(self, parent=None): QScrollArea.__init__(self, parent) self.setWidgetResizable(True) self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) self._layout = QVBoxLayout() self._layout.setContentsMargins(0, 0, 0, 0) self._layout.setSpacing(Counters.SPACING) widget = QWidget() widget.setLayout(self._layout) self.setWidget(widget) self.setFixedWidth(200) self.checked_buttons = dict()
def _build_ui(self): self._lyt_grid.setContentsMargins(0, 0, 0, 0) self._lyt_grid.setSpacing(10) self._lyt_grid.setAlignment(Qt.AlignTop | Qt.AlignLeft) scroll_area = QScrollArea() scroll_area.setFrameStyle(0) scroll_area.setWidget(QWidget()) scroll_area.widget().setLayout(self._lyt_grid) scroll_area.setWidgetResizable(True) lyt_main = QVBoxLayout() lyt_main.setContentsMargins(0, 0, 0, 0) lyt_main.setSpacing(0) lyt_main.addWidget(scroll_area) lyt_main.addWidget(self._toolbar) self.setLayout(lyt_main)
def __init__(self, font, textColor, parent=None): super(TextEditDialog, self).__init__(parent) self.setWindowFlags(QtCore.Qt.Window | QtCore.Qt.FramelessWindowHint) self.resize(QtCore.QSize(400, 300)) self.layout = QVBoxLayout(self) self.layout.setContentsMargins(2, 2, 2, 2) self.te = TextEditingField() self.te.accepted.connect(self.onAccept) self._font = QtGui.QFont(font) self.te.setTextColor(textColor) self.layout.addWidget(self.te) self.buttons = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel, self) self.buttons.accepted.connect(self.onAccept) self.buttons.rejected.connect(self.onReject) self.layout.addWidget(self.buttons) self._result = None
def __init__(self): super().__init__() if separate_colorbars: if rescale_colorbars: self.vmins = tuple(np.min(u[0]) for u in U) self.vmaxs = tuple(np.max(u[0]) for u in U) else: self.vmins = tuple(np.min(u) for u in U) self.vmaxs = tuple(np.max(u) for u in U) else: if rescale_colorbars: self.vmins = (min(np.min(u[0]) for u in U),) * len(U) self.vmaxs = (max(np.max(u[0]) for u in U),) * len(U) else: self.vmins = (min(np.min(u) for u in U),) * len(U) self.vmaxs = (max(np.max(u) for u in U),) * len(U) layout = QHBoxLayout() plot_layout = QGridLayout() self.colorbarwidgets = [cbar_widget(self, vmin=vmin, vmax=vmax) if cbar_widget else None for vmin, vmax in zip(self.vmins, self.vmaxs)] plots = [widget(self, grid, vmin=vmin, vmax=vmax, bounding_box=bounding_box, codim=codim) for vmin, vmax in zip(self.vmins, self.vmaxs)] if legend: for i, plot, colorbar, l in zip(range(len(plots)), plots, self.colorbarwidgets, legend): subplot_layout = QVBoxLayout() caption = QLabel(l) caption.setAlignment(Qt.AlignHCenter) subplot_layout.addWidget(caption) if not separate_colorbars or backend == 'matplotlib': subplot_layout.addWidget(plot) else: hlayout = QHBoxLayout() hlayout.addWidget(plot) if colorbar: hlayout.addWidget(colorbar) subplot_layout.addLayout(hlayout) plot_layout.addLayout(subplot_layout, int(i/columns), (i % columns), 1, 1) else: for i, plot, colorbar in zip(range(len(plots)), plots, self.colorbarwidgets): if not separate_colorbars or backend == 'matplotlib': plot_layout.addWidget(plot, int(i/columns), (i % columns), 1, 1) else: hlayout = QHBoxLayout() hlayout.addWidget(plot) if colorbar: hlayout.addWidget(colorbar) plot_layout.addLayout(hlayout, int(i/columns), (i % columns), 1, 1) layout.addLayout(plot_layout) if not separate_colorbars: layout.addWidget(self.colorbarwidgets[0]) for w in self.colorbarwidgets[1:]: w.setVisible(False) self.setLayout(layout) self.plots = plots
def __init__(self, parent=None): super(QLineNumberArea, self).__init__(parent) self.fixWidth = 10 self.paintLineNum = -1 self.current_line = -1 self.editor = parent layout = QVBoxLayout() self.setLayout(layout)
class MatplotlibWidget: def __init__(self, parent): self.figure = Figure() self.canvas = FigureCanvas(self.figure) self.canvas.setParent(parent) self.mpl_toolbar = NavigationToolbar(self.canvas, parent) self.axes = self.figure.add_subplot(111) self.grid_layout = QVBoxLayout() self.grid_layout.addWidget(self.canvas) self.grid_layout.addWidget(self.mpl_toolbar) parent.setLayout(self.grid_layout) self.clear() def clear(self, *, keep_limits=False): """ Make sure the figure is in a nice state """ if keep_limits: # slightly hacky way to clear axes, but prevents axis limits being reset when # we redraw for artist in self.axes.lines + self.axes.collections: artist.remove() self.axes.set_prop_cycle(None) return self.axes.clear() self.figure.clear() self.axes = self.figure.add_subplot(111) self.axes.grid(True) # Reset to some hardcoded default values self.figure.subplots_adjust(left=0.125, right=0.9, top=0.9, bottom=0.1, wspace=0.2, hspace=0.2) self.axes.set_xlabel("R", fontsize=16) self.axes.set_ylabel("Z", rotation="horizontal", fontsize=16) self.canvas.draw()
def __init__(self, device_info: QAudioDeviceInfo, parent: QWidget = None) -> None: super().__init__(parent) self.m_chart = QChart() self.m_series = QLineSeries() chart_view = QChartView(self.m_chart) chart_view.setMinimumSize(800, 600) self.m_chart.addSeries(self.m_series) axisX = QValueAxis() axisX.setRange(0, XYSeriesIODevice.sampleCount) axisX.setLabelFormat("%g") axisX.setTitleText("Samples") axisY = QValueAxis() axisY.setRange(-1, 1) axisY.setTitleText("Audio level") self.m_chart.addAxis(axisX, Qt.AlignBottom) self.m_series.attachAxis(axisX) self.m_chart.addAxis(axisY, Qt.AlignLeft) self.m_series.attachAxis(axisY) self.m_chart.legend().hide() self.m_chart.setTitle( f"Data from the microphone ({device_info.deviceName()})") mainLayout = QVBoxLayout(self) mainLayout.addWidget(chart_view) formatAudio = QAudioFormat() formatAudio.setSampleRate(8000) formatAudio.setChannelCount(1) formatAudio.setSampleSize(8) formatAudio.setCodec("audio/pcm") formatAudio.setByteOrder(QAudioFormat.LittleEndian) formatAudio.setSampleType(QAudioFormat.UnSignedInt) self.m_audioInput = QAudioInput(device_info, formatAudio, self) self.m_device = XYSeriesIODevice(self.m_series, self) self.m_device.open(QIODevice.WriteOnly) self.m_audioInput.start(self.m_device)
def _build_ui(self): fields = self._entity.fields() fields = [ x for x in fields if x.name not in ('id', 'timestamp', 'username') ] lyt_buttons = QHBoxLayout() lyt_buttons.addWidget(self._btn_create) lyt_buttons.addWidget(self._btn_cancel) r = 0 lyt_grid = QGridLayout() for field in fields: editor = QLineEdit() if field.type == int: editor = QSpinBox() editor.setRange(-1000000, 1000000) self._wdg_map[field] = editor lyt_grid.addWidget(QLabel(field.name), r, 0) lyt_grid.addWidget(editor, r, 1) r += 1 lyt_main = QVBoxLayout() lyt_main.addLayout(lyt_grid) lyt_main.addLayout(lyt_buttons) self.setLayout(lyt_main)
def __init__(self, parent=None): super().__init__(parent) self.m_icon = QLabel() self.m_title = QLabel() self.m_message = QLabel() self.notification = None self.setWindowFlags(Qt.ToolTip) rootLayout = QHBoxLayout(self) rootLayout.addWidget(self.m_icon) bodyLayout = QVBoxLayout() rootLayout.addLayout(bodyLayout) titleLayout = QHBoxLayout() bodyLayout.addLayout(titleLayout) titleLayout.addWidget(self.m_title) titleLayout.addItem(QSpacerItem(0, 0, QSizePolicy.Expanding)) close = QPushButton(self.tr("Close")) titleLayout.addWidget(close) close.clicked.connect(self.onClosed) bodyLayout.addWidget(self.m_message) self.adjustSize()
def __init__(self, page, parent=None): super(HelpForm, self).__init__(parent) self.setAttribute(Qt.WA_DeleteOnClose) self.setAttribute(Qt.WA_GroupLeader) backAction = QAction(QIcon(":/back.png"), "&Back", self) backAction.setShortcut(QKeySequence.Back) homeAction = QAction(QIcon(":/home.png"), "&Home", self) homeAction.setShortcut("Home") self.pageLabel = QLabel() toolBar = QToolBar() toolBar.addAction(backAction) toolBar.addAction(homeAction) toolBar.addWidget(self.pageLabel) self.textBrowser = QTextBrowser() layout = QVBoxLayout() layout.addWidget(toolBar) layout.addWidget(self.textBrowser, 1) self.setLayout(layout) backAction.triggered.connect(self.tbackward) homeAction.triggered.connect(self.thome) self.textBrowser.sourceChanged.connect(self.updatePageTitle) self.textBrowser.setSearchPaths([":/help"]) self.textBrowser.setSource(QUrl(page)) self.resize(400, 600) self.setWindowTitle("{0} Help".format(QApplication.applicationName()))
def __init__(self, name='modelPanelWidget', **kwargs): super(ModelPanelWidget, self).__init__(**kwargs) unique_name = name + str(id(self)) self.setObjectName(unique_name + 'Widget') main_layout = QVBoxLayout(self) main_layout.setContentsMargins(0, 0, 0, 0) main_layout.setObjectName(unique_name + 'Layout') self.setLayout(main_layout) maya.cmds.setParent(main_layout.objectName()) pane_layout_name = maya.cmds.paneLayout() self._model_panel = maya.cmds.modelPanel(unique_name, label="ModelPanel", menuBarVisible=False) pane_layout_widget = gui.to_qt_object(pane_layout_name) main_layout.addWidget(pane_layout_widget) self.set_model_panel_options() self.hide_bar_layout() self.hide_menu_bar()
def setupUI(self): self.setWindowTitle("浏览窗口") self.ui = loadUi(file_path + "\\res\\UI\\CenterWidget.ui") self.ui.setParent(self) self.setLayout(QVBoxLayout()) self.layout().addWidget(self.ui) self.layout().setContentsMargins(0,0,0,0) self.child_widget = self.ui.findChild(QWidget, "widget") # 设置选择窗口 self.widget = SelWidget() layout = QVBoxLayout() self.child_widget.setLayout(layout) self.child_widget.layout().addWidget(self.widget) self.flowLayout = layouitflow.FlowLayout() self.widget.setLayout(self.flowLayout) #瀑布流布局 self.widget.layout().setSpacing(0) #设置间距
def setUI(self): """设置界面""" #加载ui #self.ui = loadUi(btnWin_ui) self.ui = loadUi(btnWin_ui) self.ui.setParent(self) #设置布局 self.setLayout(QVBoxLayout()) self.layout().setContentsMargins(1.5, 1.5, 1.5, 1.5) self.layout().addWidget(self.ui)
def __init__(self, U, plot, length=1, title=None): super().__init__() layout = QVBoxLayout() if title: title = QLabel('<b>' + title + '</b>') title.setAlignment(Qt.AlignHCenter) layout.addWidget(title) layout.addWidget(plot) plot.set(U, 0) if length > 1: hlayout = QHBoxLayout() self.slider = QSlider(Qt.Horizontal) self.slider.setMinimum(0) self.slider.setMaximum(length - 1) self.slider.setTickPosition(QSlider.TicksBelow) hlayout.addWidget(self.slider) lcd = QLCDNumber(m.ceil(m.log10(length))) lcd.setDecMode() lcd.setSegmentStyle(QLCDNumber.Flat) hlayout.addWidget(lcd) layout.addLayout(hlayout) hlayout = QHBoxLayout() toolbar = QToolBar() self.a_play = QAction(self.style().standardIcon(QStyle.SP_MediaPlay), 'Play', self) self.a_play.setCheckable(True) self.a_rewind = QAction(self.style().standardIcon(QStyle.SP_MediaSeekBackward), 'Rewind', self) self.a_toend = QAction(self.style().standardIcon(QStyle.SP_MediaSeekForward), 'End', self) self.a_step_backward = QAction(self.style().standardIcon(QStyle.SP_MediaSkipBackward), 'Step Back', self) self.a_step_forward = QAction(self.style().standardIcon(QStyle.SP_MediaSkipForward), 'Step', self) self.a_loop = QAction(self.style().standardIcon(QStyle.SP_BrowserReload), 'Loop', self) self.a_loop.setCheckable(True) toolbar.addAction(self.a_play) toolbar.addAction(self.a_rewind) toolbar.addAction(self.a_toend) toolbar.addAction(self.a_step_backward) toolbar.addAction(self.a_step_forward) toolbar.addAction(self.a_loop) if hasattr(self, 'save'): self.a_save = QAction(self.style().standardIcon(QStyle.SP_DialogSaveButton), 'Save', self) toolbar.addAction(self.a_save) self.a_save.triggered.connect(self.save) hlayout.addWidget(toolbar) self.speed = QSlider(Qt.Horizontal) self.speed.setMinimum(0) self.speed.setMaximum(100) hlayout.addWidget(QLabel('Speed:')) hlayout.addWidget(self.speed) layout.addLayout(hlayout) self.timer = QTimer() self.timer.timeout.connect(self.update_solution) self.slider.valueChanged.connect(self.slider_changed) self.slider.valueChanged.connect(lcd.display) self.speed.valueChanged.connect(self.speed_changed) self.a_play.toggled.connect(self.toggle_play) self.a_rewind.triggered.connect(self.rewind) self.a_toend.triggered.connect(self.to_end) self.a_step_forward.triggered.connect(self.step_forward) self.a_step_backward.triggered.connect(self.step_backward) self.speed.setValue(50) elif hasattr(self, 'save'): hlayout = QHBoxLayout() toolbar = QToolBar() self.a_save = QAction(self.style().standardIcon(QStyle.SP_DialogSaveButton), 'Save', self) toolbar.addAction(self.a_save) hlayout.addWidget(toolbar) layout.addLayout(hlayout) self.a_save.triggered.connect(self.save) self.setLayout(layout) self.plot = plot self.U = U self.length = length
class FixedAttributesWidget(QWidget): """ A widget for viewing/editing fixed attributes (non-varying) """ def __init__(self, data, parent=None): QWidget.__init__(self, parent) self.data = data vbox = QVBoxLayout() self.setLayout(vbox) title = QLabel('Fixed Attributes') vbox.addWidget(title) self.frame = QFrame() vbox.addWidget(self.frame) self.vbox = QVBoxLayout() self.frame.setLayout(self.vbox) self.frame.setFrameShape(QFrame.Panel) self.frame.setFrameShadow(QFrame.Sunken) self.table = QTableWidget() self.table.horizontalHeader().hide() self.vbox.addWidget(self.table) self.table.hide() self.noAttrLabel = QLabel('<i>No fixed attributes</i>') self.vbox.addWidget(self.noAttrLabel) self.widgets = [] self.populate() self.data.fixedAttributeAdded.connect(self.fixedAttributeAddedSlot) self.data.dataReset.connect(self.dataResetSlot) self.data.dirtied.connect(self.dataDirtiedSlot) def dataDirtiedSlot(self, dirty): """ SLOT when the particle data is dirtied or cleaned.""" if not dirty: for widget in self.widgets: widget.drawBorder(False) def dataResetSlot(self): """ SLOT when particle data is reconstructed """ self.populate() def fixedAttributeAddedSlot(self, name): #pylint:disable=W0613 """ SLOT when a fixed attribute is added to the particle set """ self.populate() def populate(self): """ Populates the table of fixed attributes """ self.widgets = [] # If no widgets, just drop that in numAttrs = self.data.numFixedAttributes() if not numAttrs: self.table.hide() self.noAttrLabel.show() return self.table.show() self.noAttrLabel.hide() self.table.setColumnCount(1) self.table.setRowCount(numAttrs) self.attrs = getAttrs(self.data.numFixedAttributes, self.data.fixedAttributeInfo, True) for row, (_, attr) in enumerate(self.attrs): item = QTableWidgetItem(attr.name) tooltip = '<p><tt> Name: {}<br> Type: {}<br>Count: {}</tt></p>'.\ format(attr.name, partio.TypeName(attr.type), attr.count) item.setToolTip(tooltip) self.table.setVerticalHeaderItem(row, item) value = self.data.getFixed(attr) widget = getWidget(value, self.data, attr) self.table.setCellWidget(row, 0, widget) self.widgets.append(widget) self.table.horizontalHeader().setStretchLastSection(False) self.table.setTabKeyNavigation(True) self.table.horizontalHeader().setSectionsMovable(False) self.table.horizontalHeader().resizeSections(QHeaderView.ResizeToContents) self.table.verticalHeader().resizeSections(QHeaderView.ResizeToContents)
class IndexedStringsWidget(QWidget): """ Holds the list of indexed string attributes """ def __init__(self, data, parent=None): QWidget.__init__(self, parent) self.data = data vbox = QVBoxLayout() self.setLayout(vbox) title = QLabel('Indexed Strings') vbox.addWidget(title) self.frame = QFrame() vbox.addWidget(self.frame) self.vbox = QVBoxLayout() self.frame.setLayout(self.vbox) self.frame.setFrameShape(QFrame.Panel) self.frame.setFrameShadow(QFrame.Sunken) self.table = QTableWidget() self.table.horizontalHeader().hide() self.vbox.addWidget(self.table) self.table.hide() self.noStringsLabel = QLabel('<i>No indexed strings</i>') self.vbox.addWidget(self.noStringsLabel) self.widgets = [] self.populate() self.data.attributeAdded.connect(self.attributeAddedSlot) self.data.dataReset.connect(self.dataResetSlot) self.data.dirtied.connect(self.dataDirtiedSlot) def dataDirtiedSlot(self, dirty): """ SLOT when the particle data is dirtied or cleaned.""" if not dirty: for widget in self.widgets: widget.drawBorder(False) def dataResetSlot(self): """ SLOT when particle data is reconstructed """ self.populate() def attributeAddedSlot(self, name): #pylint:disable=W0613 """ SLOT when an attribute is added to the particle set """ attr = self.data.attributeInfo(name) if attr.type == partio.INDEXEDSTR: self.populate() def populate(self): """ Populates the table of indexed strings """ self.widgets = [] # If no widgets, just drop that in attrs = [] for anum in range(self.data.numAttributes()): attr = self.data.attributeInfo(anum) if attr.type == partio.INDEXEDSTR: attrs.append(attr) if not attrs: self.table.hide() self.noStringsLabel.show() return self.table.show() self.noStringsLabel.hide() self.table.setColumnCount(1) self.table.setRowCount(len(attrs)) for row, attr in enumerate(attrs): item = QTableWidgetItem(attr.name) self.table.setVerticalHeaderItem(row, item) strings = self.data.indexedStrs(attr) table = QTableWidget() table.setColumnCount(1) table.setRowCount(len(strings)) table.horizontalHeader().hide() table.setVerticalHeaderLabels([str(i) for i in range(len(strings))]) for i, string in enumerate(strings): widget = QLabel(string) table.setCellWidget(i, 0, widget) self.widgets.append(widget) self.table.setCellWidget(row, 0, table) self.table.horizontalHeader().setStretchLastSection(False) self.table.setTabKeyNavigation(True) self.table.horizontalHeader().setSectionsMovable(False) self.table.horizontalHeader().resizeSections(QHeaderView.ResizeToContents) self.table.verticalHeader().resizeSections(QHeaderView.ResizeToContents)
def __init__(self, parent=None): QMainWindow.__init__(self, parent) self.data = ParticleData() toolbar = self.addToolBar("Test") openButton = QPushButton("") openButton.setFlat(True) openButton.setIconSize( QSize(32, 32) ) openButton.setIcon(QIcon("/jobs2/soft/icons/dlight/open.png")) openButton.setToolTip( "Open File" ) toolbar.addWidget(openButton) openButton.clicked.connect(self.openSlot) QShortcut( QKeySequence(Qt.CTRL + Qt.Key_O), self, self.openSlot ) saveButton = QPushButton("") saveButton.setFlat(True) saveButton.setIconSize( QSize(32, 32) ) saveButton.setIcon(QIcon("/jobs2/soft/icons/dlight/file_save.png")) saveButton.setToolTip( "Save File" ) toolbar.addWidget(saveButton) saveButton.clicked.connect(self.saveSlot) QShortcut( QKeySequence(Qt.CTRL + Qt.Key_S), self, self.saveSlot ) saveDeltaButton = QPushButton("") saveDeltaButton.setFlat(True) saveDeltaButton.setIconSize( QSize(32, 32) ) saveDeltaButton.setIcon(QIcon("/jobs2/soft/icons/dlight/file_save_as.png")) saveDeltaButton.setToolTip( "Save File As Delta" ) toolbar.addWidget(saveDeltaButton) saveDeltaButton.clicked.connect(self.saveDeltaSlot) QShortcut( QKeySequence(Qt.CTRL + Qt.SHIFT + Qt.Key_S), self, self.saveDeltaSlot ) addParticleButton = QPushButton("Particle") addParticleButton.setFlat(True) addParticleButton.setIconSize( QSize(32, 32) ) addParticleButton.setIcon(QIcon("/jobs2/soft/icons/shared/plus.png")) addParticleButton.setToolTip( "Add Particle" ) toolbar.addWidget(addParticleButton) addParticleButton.clicked.connect(self.addParticleSlot) addAttributeButton = QPushButton("Attribute") addAttributeButton.setFlat(True) addAttributeButton.setIconSize( QSize(32, 32) ) addAttributeButton.setIcon(QIcon("/jobs2/soft/icons/shared/plus.png")) addAttributeButton.setToolTip( "Add Attribute" ) toolbar.addWidget(addAttributeButton) addAttributeButton.clicked.connect(self.addAttributeSlot) splitter = QSplitter(self) self.setCentralWidget(splitter) particleTable = ParticleTableWidget(self.data, self) splitter.addWidget(particleTable) right = QWidget(self) splitter.addWidget(right) vbox = QVBoxLayout(right) right.setLayout(vbox) fixedAttrWidget = FixedAttributesWidget(self.data, self) vbox.addWidget(fixedAttrWidget) indexedStrings = IndexedStringsWidget(self.data, self) vbox.addWidget(indexedStrings) vbox.addStretch() # TODD: SCROLLABLE AREAS FOR EVERYTHING self.data.dirtied.connect(self.dataDirtiedSlot) # Configure ctrl-w to close the window QShortcut( QKeySequence(Qt.CTRL + Qt.Key_W), self, self.close )
def addAttributeSlot(self): """ Adds a new attribute (column) to the table """ dialog = QDialog(self) dialog.setModal(True) dialog.setWindowTitle('Add Attribute') layout = QVBoxLayout() dialog.setLayout(layout) form = QFormLayout() nameBox = QLineEdit() typeCombo = QComboBox() for attrType in _attrTypes: typeName = partio.TypeName(attrType) typeCombo.addItem(typeName) typeCombo.setCurrentIndex(partio.FLOAT) countBox = QLineEdit() countBox.setValidator(QIntValidator()) countBox.setText('1') fixedCheckbox = QCheckBox() valueBox = QLineEdit() valueBox.setText('0') form.addRow('Name:', nameBox) form.addRow('Type:', typeCombo) form.addRow('Count:', countBox) form.addRow('Fixed:', fixedCheckbox) form.addRow('Default Value:', valueBox) layout.addLayout(form) buttons = QHBoxLayout() layout.addLayout(buttons) add = QPushButton('Add') add.clicked.connect(dialog.accept) buttons.addWidget(add) cancel = QPushButton('Cancel') cancel.clicked.connect(dialog.reject) buttons.addWidget(cancel) if not dialog.exec_(): return name = str(nameBox.text()) if not name: print 'Please supply a name for the new attribute' # TODO: prompt return attrType = typeCombo.currentIndex() count = int(countBox.text()) fixed = fixedCheckbox.isChecked() values = list(str(valueBox.text()).strip().split()) for i in range(count): if i < len(values): value = values[i] else: value = values[-1] if attrType == partio.INT or attrType == partio.INDEXEDSTR: values[i] = int(value) elif attrType == partio.FLOAT or attrType == partio.VECTOR: values[i] = float(value) # pylint:disable=R0204 else: values[i] = 0.0 # pylint:disable=R0204 value = tuple(values) self.data.addAttribute(name, attrType, count, fixed, value)