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 initPenSizeButtons(self): self.penSize = QWidget(self) self.penSizeLayout = QHBoxLayout() self.penSize.setLayout(self.penSizeLayout) # adjust pen size self.penSize1 = QPushButton(self.penSize) self.penSize1.setIcon(QIcon(":/resource/icon/pensize1.png")) self.penSize1.setObjectName('1') self.penSize1.setFixedSize(self.iconWidth, self.iconHeight) self.penSize1.setCheckable(True) self.penSize2 = QPushButton(self.penSize) self.penSize2.setIcon(QIcon(":/resource/icon/pensize2.png")) self.penSize2.setObjectName('2') self.penSize2.setFixedSize(self.iconWidth, self.iconHeight) self.penSize2.setCheckable(True) self.penSize3 = QPushButton(self.penSize) self.penSize3.setIcon(QIcon(":/resource/icon/pensize3.png")) self.penSize3.setObjectName('3') self.penSize3.setFixedSize(self.iconWidth, self.iconHeight) self.penSize3.setCheckable(True) self.sizeButtonGroup = QButtonGroup(self.penSize) self.sizeButtonGroup.addButton(self.penSize1) self.sizeButtonGroup.addButton(self.penSize2) self.sizeButtonGroup.addButton(self.penSize3) self.sizeButtonGroup.buttonClicked.connect(self.sizeButtonToggled) self.penSizeLayout.addWidget(self.penSize1) self.penSizeLayout.addWidget(self.penSize2) self.penSizeLayout.addWidget(self.penSize3) self.penSizeLayout.setSpacing(5) self.penSizeLayout.setContentsMargins(0, 0, 0, 0)
def __init__(self, parent=None): QWidget.__init__(self, parent) self.hue = QSlider() self.hue.setMaximum(100) self.hue.setOrientation(Qt.Horizontal) self.hue.valueChanged.connect(self._changed) self.saturation = QSlider() self.saturation.setMaximum(100) self.saturation.setOrientation(Qt.Horizontal) self.saturation.valueChanged.connect(self._changed) self.value = QSlider() self.value.setMaximum(100) self.value.setOrientation(Qt.Horizontal) self.value.valueChanged.connect(self._changed) layout = QGridLayout(self) layout.addWidget(QLabel("H")) layout.addWidget(QLabel("S")) layout.addWidget(QLabel("V")) layout.addWidget(self.hue, 0, 1) layout.addWidget(self.saturation, 1, 1) layout.addWidget(self.value, 2, 1)
def __init__(self, parent=None): QWidget.__init__(self, parent) self.setMinimumWidth(500) self.table = QTableWidget() self.table.setSelectionMode(QTableWidget.SingleSelection) self.table.itemChanged.connect(self._item_changed) self.table.currentItemChanged.connect(self._current_item_changed) self.table.horizontalHeader().hide() self.table.verticalHeader().hide() self.table.setColumnCount(3) self.table.horizontalHeader().resizeSection(0, 200) self.table.horizontalHeader().resizeSection(1, 200) self.table.horizontalHeader().resizeSection(2, 20) self.new = QPushButton('New variable') self.new.clicked.connect(self._new) self.color = Color() self.color.changed.connect(self._color_changed) layout = QGridLayout(self) layout.addWidget(self.table) layout.addWidget(self.color) layout.addWidget(self.new)
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")
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 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")
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 __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 _toolbar_example(self): def _collapse(): tool_bar.collapse() def _set_icon_color(): tool_bar.set_icon_color(QColor(255, 255, 0)) toolbar_widget = QWidget(parent=self) toolbar_layout = layouts.VerticalLayout() toolbar_widget.setLayout(toolbar_layout) tool_bar = toolbar.ToolBar(parent=self) tool_bar.set_children_height(50) toolbar_layout.addWidget(tool_bar) line_edit = lineedit.BaseLineEdit(parent=self) line_edit.setObjectName('hello') collapse_action = tool_bar.addAction('Collapse') tool_bar.addWidget(line_edit) tool_bar.addAction(resources.icon('add'), 'Plus') color_action = QAction('Yellow', None) tool_bar.insertAction('Plus', color_action) collapse_action.triggered.connect(_collapse) color_action.triggered.connect(_set_icon_color) self.main_layout.addWidget(buttons.BaseButton('Hello')) self.main_layout.addStretch() return toolbar_widget
def __init__(self): super(RenamerPlugin, self).__init__() self._renamer_widget = None self._content = QWidget() self._content_layout = layouts.VerticalLayout(spacing=0, margins=(0, 0, 0, 0)) self._content.setLayout(self._content_layout) self.setWidget(self._content)
def __init__(self): super(ScriptsEditorPlugin, self).__init__() self._script_editor_widget = None self._content = QWidget() self._content_layout = layouts.VerticalLayout(spacing=0, margins=(0, 0, 0, 0)) self._content.setLayout(self._content_layout) self.setWidget(self._content)
def __init__(self): QWidget.__init__(self) self.setWindowTitle('Simple') self.verticalLayout = QtWidgets.QVBoxLayout(self) self.verticalLayout.setObjectName("verticalLayout") self.label = QLabel("Hello World.\nUsing Qt binding %s" % Qt.Qt.__binding__) self.verticalLayout.addWidget(self.label) self.pushButton = QPushButton('Button', self) self.verticalLayout.addWidget(self.pushButton)
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 ui(self): super(SkinningWidget, self).ui() self._average_falloff_widget = QWidget() average_falloff_layout = layouts.VerticalLayout(spacing=2, margins=(5, 5, 5, 5)) self._average_falloff_widget.setLayout(average_falloff_layout) self._average_falloff_curve = fallofcurve.FallofCurveWidget( parent=self) average_falloff_layout.addWidget(self._average_falloff_curve) self._mirror_auto_assign_joints_labels_cbx = checkbox.BaseCheckBox( 'Auto Assign Labels', self) self._copy_skin_weights_auto_assign_joints_labels_cbx = checkbox.BaseCheckBox( 'Auto Assign Labels', self) self._transfer_skin_uvs_auto_assign_joints_labels_cbx = checkbox.BaseCheckBox( 'Auto Assign Labels', self) self._clean_skin_mesh_auto_assign_joints_labels_cbx = checkbox.BaseCheckBox( 'Auto Assign Labels', self) self._extract_skin_faces_auto_assign_joints_labels_cbx = checkbox.BaseCheckBox( 'Auto Assign Labels', self) self._distance_widget = QWidget() distance_layout = layouts.VerticalLayout(spacing=2, margins=(5, 5, 5, 5)) self._distance_widget.setLayout(distance_layout) self._distance_average_cbx = checkbox.BaseCheckBox('On Distance', self) self._average_falloff_curve = fallofcurve.FallofCurveWidget( parent=self) distance_layout.addWidget(self._distance_average_cbx) distance_layout.addWidget(self._average_falloff_curve) self._fast_delete_cbx = checkbox.BaseCheckBox('Fast Delete', self) self._average_falloff_widget.setVisible(False) self._mirror_auto_assign_joints_labels_cbx.setVisible(False) self._copy_skin_weights_auto_assign_joints_labels_cbx.setVisible(False) self._transfer_skin_uvs_auto_assign_joints_labels_cbx.setVisible(False) self._clean_skin_mesh_auto_assign_joints_labels_cbx.setVisible(False) self._extract_skin_faces_auto_assign_joints_labels_cbx.setVisible( False) self._distance_widget.setVisible(False) self._fast_delete_cbx.setVisible(False) self.main_layout.addWidget(self._average_falloff_widget) self.main_layout.addWidget(self._mirror_auto_assign_joints_labels_cbx) self.main_layout.addWidget( self._copy_skin_weights_auto_assign_joints_labels_cbx) self.main_layout.addWidget( self._transfer_skin_uvs_auto_assign_joints_labels_cbx) self.main_layout.addWidget( self._clean_skin_mesh_auto_assign_joints_labels_cbx) self.main_layout.addWidget( self._extract_skin_faces_auto_assign_joints_labels_cbx) self.main_layout.addWidget(self._distance_widget) self.main_layout.addWidget(self._fast_delete_cbx)
def _add_category(self, category_name): if not self._controller: return False commands_to_add = list() for command_name, command_data in self._commands_data.items(): command_function = self._controller_functions_mapping.get( command_name, None) if not command_data or command_name not in self._controller_functions_mapping: continue command_categories = command_data.get('categories', list()) if category_name not in command_categories: continue options = list() command_actions = command_data.get('options', dict()) for command_option_name, command_option_data in command_actions.items( ): command_option_function = self._controller_functions_mapping.get( command_option_name, None) if not command_option_function: continue option_data = command_option_data.copy() option_data['fn'] = command_option_function options.append(option_data) new_command_data = command_data.copy() new_command_data.pop( 'categories') # categories is not part of the command creation new_command_data.pop('options', None) new_command = self._create_button(fn=command_function, settings=options, **new_command_data) is_available = self._check_command_availability(command_name) if not is_available: new_command.setToolTip( 'Command "{}" is not available!'.format(command_name)) new_command.setEnabled(False) commands_to_add.append(new_command) if not commands_to_add: return False category_widget = QWidget() category_layout = layouts.FlowLayout() category_layout.setAlignment(Qt.AlignLeft) category_widget.setLayout(category_layout) for command in commands_to_add: category_layout.addWidget(command) return category_widget
def add_spacing(self, spacing): """ Adds new spacing into the widget :param spacing: int """ # TODO: Check if we should use spacer items instead of standard widgets space_widget = QWidget() space_widget.setFixedSize(QSize(spacing, spacing)) self.addWidget(space_widget)
def ui(self): super(CollapsableGroup, self).ui() self._base_widget = QWidget() if self._layout_orientation == Qt.Vertical: manager_layout = layouts.VerticalLayout(spacing=2, margins=(4, 4, 4, 4)) else: manager_layout = layouts.HorizontalLayout(spacing=2, margins=(4, 4, 4, 4)) manager_layout.setAlignment(Qt.AlignCenter) self._base_widget.setLayout(manager_layout) self.main_layout.addWidget(self._base_widget) self.main_layout = manager_layout
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 add_ligand(tool): rows = tool.ligand_table.rowCount() if rows != 0: rows -= 1 ligand_name = QTableWidgetItem() name = "<click to choose>" is_c2 = Qt.Unchecked enabled = True if rows > 0: name = tool.ligand_table.item(rows - 1, 0).text() is_c2 = tool.ligand_table.cellWidget(rows - 1, 1).layout().itemAt(0).widget().checkState() enabled = tool.ligand_table.cellWidget(rows - 1, 1).layout().itemAt(0).widget().isEnabled() ligand_name.setData(Qt.DisplayRole, name) tool.ligand_table.setItem(rows, 0, ligand_name) widget_that_lets_me_horizontally_align_a_checkbox = QWidget() widget_layout = QHBoxLayout(widget_that_lets_me_horizontally_align_a_checkbox) c2 = QCheckBox() c2.setEnabled(enabled) c2.setCheckState(is_c2) widget_layout.addWidget(c2, 0, Qt.AlignHCenter) widget_layout.setContentsMargins(0, 0, 0, 0) tool.ligand_table.setCellWidget( rows, 1, widget_that_lets_me_horizontally_align_a_checkbox ) widget_that_lets_me_horizontally_align_an_icon = QWidget() widget_layout = QHBoxLayout(widget_that_lets_me_horizontally_align_an_icon) section_remove = QLabel() dim = int(1.5 * section_remove.fontMetrics().boundingRect("Q").height()) section_remove.setPixmap( QIcon(section_remove.style().standardIcon( QStyle.SP_DialogDiscardButton) ).pixmap(dim, dim) ) widget_layout.addWidget(section_remove, 0, Qt.AlignHCenter) widget_layout.setContentsMargins(0, 0, 0, 0) tool.ligand_table.setCellWidget( rows, 2, widget_that_lets_me_horizontally_align_an_icon ) rows += 1 tool.ligand_table.insertRow(rows) widget_that_lets_me_horizontally_align_an_icon = QWidget() widget_layout = QHBoxLayout(widget_that_lets_me_horizontally_align_an_icon) ligand_add = QLabel("add ligand") widget_layout.addWidget(ligand_add, 0, Qt.AlignHCenter) widget_layout.setContentsMargins(0, 0, 0, 0) tool.ligand_table.setCellWidget(rows, 1, widget_that_lets_me_horizontally_align_an_icon)
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()
def ui(self): super(RenamerView, self).ui() renamer_widget = QWidget() renamer_widget.setLayout( layouts.VerticalLayout(spacing=0, margins=(0, 0, 0, 0))) renamer_widget.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) self.main_layout.addWidget(renamer_widget) rename_layout = layouts.HorizontalLayout(spacing=2, margins=(0, 0, 0, 0)) rename_layout.setAlignment(Qt.AlignLeft) renamer_widget.layout().addLayout(rename_layout) self._base_name_cbx = checkbox.BaseCheckBox(parent=self) rename_layout.addWidget(self._base_name_cbx) self._renamer_line = lineedit.BaseLineEdit(parent=self) self._renamer_line.setPlaceholderText('New Name') rename_layout.addWidget(self._renamer_line) reg_ex = QRegExp("^(?!^_)[a-zA-Z_]+") text_validator = QRegExpValidator(reg_ex, self._renamer_line) self._renamer_line.setValidator(text_validator) self._renamer_btn = buttons.BaseButton(parent=self) self._renamer_btn.setIcon(resources.icon('rename')) rename_layout.addWidget(self._renamer_btn)
def ui(self): super(OptionsViewer, self).ui() edit_mode_icon = resources.icon('edit') move_up_icon = resources.icon('sort_up') move_down_icon = resources.icon('sort_down') remove_icon = resources.icon('delete') self._edit_widget = QWidget() top_layout = layouts.HorizontalLayout() top_layout.setContentsMargins(0, 0, 0, 0) top_layout.setSpacing(2) self._edit_widget.setLayout(top_layout) self.main_layout.addWidget(self._edit_widget) self._edit_mode_btn = buttons.BaseButton(parent=self) self._edit_mode_btn.setIcon(edit_mode_icon) self._edit_mode_btn.setCheckable(True) top_layout.addWidget(self._edit_mode_btn) horizontal_separator = QFrame() horizontal_separator.setFrameShape(QFrame.VLine) horizontal_separator.setFrameShadow(QFrame.Sunken) top_layout.addWidget(horizontal_separator) self._move_up_btn = buttons.BaseButton(parent=self) self.move_down_btn = buttons.BaseButton(parent=self) self.remove_btn = buttons.BaseButton(parent=self) self._move_up_btn.setIcon(move_up_icon) self.move_down_btn.setIcon(move_down_icon) self.remove_btn.setIcon(remove_icon) self._move_up_btn.setVisible(False) self.move_down_btn.setVisible(False) self.remove_btn.setVisible(False) top_layout.addWidget(self._move_up_btn) top_layout.addWidget(self.move_down_btn) top_layout.addWidget(self.remove_btn) top_layout.addStretch() self.main_layout.addWidget(dividers.Divider()) self._scroll = QScrollArea() self._scroll.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self._scroll.setFocusPolicy(Qt.NoFocus) self._scroll.setWidgetResizable(True) self.setFocusPolicy(Qt.NoFocus) self._options_list = self.OPTION_LIST_CLASS(parent=self) self._scroll.setWidget(self._options_list) self.main_layout.addWidget(self._scroll)
def __init__(self, project_name): self.project_name = project_name self._app = QApplication.instance() self._css_filepath = None self.main_window = QWidget() self.main_window.setWindowFlags(Qt.Tool) self.main_window.setWindowTitle("CSS Editor - " + self.project_name) self.variables = Variables() self.variables.changed.connect(self._variables_changed) self.variables.changed.connect(self._render_and_apply) self.template = CSSTextEdit() self.template.changed.connect(self._template_changed) self.template.changed.connect(self._render_and_apply) self.save = QPushButton('Save stylesheet to') self.save.clicked.connect(self._save_stylesheet) self.save_destination = QLineEdit() self.save_destination.textChanged.connect(self._destination_changed) self.splitter = QSplitter() self.splitter.setOrientation(Qt.Vertical) self.splitter.addWidget(self.variables) self.splitter.addWidget(self.template) layout = QGridLayout(self.main_window) layout.addWidget(self.splitter, 0, 0, 1, 2) layout.addWidget(self.save, 1, 0) layout.addWidget(self.save_destination, 1, 1) self.main_window.resize(800, 600) self._project_dir = self._ensure_project_dir() self._top_level_widgets = [ widget for widget in QApplication.topLevelWidgets() if widget.windowTitle() != self.main_window.windowTitle() ] self._variables = dict() self._template = None self._stylesheet = "" self._app.aboutToQuit.connect(self._save_editor_state) self._open() self.save_destination.setText(self.css_filepath) self.main_window.show()
def add_files(self, filenames): """add filenames (list(str)) to the table""" for f in filenames: row = self.table.rowCount() self.table.insertRow(row) file_item = QTableWidgetItem() file_item.setData(Qt.DisplayRole, f) self.table.setItem(row, 0, file_item) widget_that_lets_me_horizontally_align_an_icon = QWidget() widget_layout = QHBoxLayout( widget_that_lets_me_horizontally_align_an_icon) section_remove = QLabel() dim = int(1.5 * section_remove.fontMetrics().boundingRect("Z").height()) section_remove.setPixmap( QIcon(section_remove.style().standardIcon( QStyle.SP_DialogDiscardButton)).pixmap(dim, dim)) widget_layout.addWidget(section_remove, 0, Qt.AlignHCenter) widget_layout.setContentsMargins(0, 0, 0, 0) self.table.setCellWidget( row, 1, widget_that_lets_me_horizontally_align_an_icon) self.add_last_row()
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 addCircle(self): try: self.win = QWidget() self.win.setMinimumSize(self.child_widget.width()/1.05,self.child_widget.height()/1.1) self.loading_wrapper = MLoading.huge() self.win.setLayout(QHBoxLayout()) self.win.layout().addWidget(self.loading_wrapper) self.widget.layout().addWidget(self.win) except: pass
class RGBA8PaletteOption(Option): ''' Widget with a variable number of color choosers useful for defining custom palettes. Supported keyword arguments: * num colors: The number of individual color pickers * labels: a list of length num_colors or None * initial_colors: a list of RGBA8 values of length num_colors or None ''' default_color = [200, 200, 200, 255] def __init__(self, *args, num_colors=1, **kw): self.num_colors = num_colors super().__init__(*args, **kw) def get_value(self): colors = [self._color_button[i].color for i in self.num_colors] def set_value(self, value): for i, val in enumerate(value): self._color_button[i].color = val value = property(get_value, set_value) def _make_widget(self, **kw): nc = self.num_colors from chimerax.ui.widgets import MultiColorButton from Qt.QtWidgets import QWidget, QHBoxLayout, QLabel labels = kw.pop('labels', None) if labels is None: labels = [None] + [" "] * (nc - 1) self.widget = QWidget() layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) self._color_button = [] initial_colors = kw.get('initial_colors', [default_color] * nc) for i in range(nc): label = labels[i] if label: layout.addWidget(QLabel(label)) mcb = MultiColorButton(max_size=(16, 16), has_alpha_channel=True) self._color_button.append(mcb) mcb.color = initial_colors[i] mcb.color_changed.connect(lambda c, s=self: s.make_callback()) layout.addWidget(mcb) self.widget.setLayout(layout)
def initPenColorButtons(self): self.colorSet = QWidget(self) self.colorLayout = QHBoxLayout() self.colorLayout.setSpacing(5) self.colorLayout.setContentsMargins(5, 0, 5, 0) self.colorSet.setLayout(self.colorLayout) self.presentColor = QPushButton(self.colorSet) self.presentColor.setFixedSize(self.iconWidth, self.iconHeight) self.presentColor.setEnabled(False) # adjust pen color self.colorPick = QWidget(self.colorSet) self.colorGrid = QGridLayout() self.colorGrid.setSpacing(0) self.colorGrid.setContentsMargins(5, 0, 5, 0) self.colorPick.setLayout(self.colorGrid) self.colorList = [('white', '#ffffff'), ('red', '#ff0000'), ('green', '#00ff00'), ('blue', '#0000ff'), ('cyan', '#00ffff'), ('magenta', '#ff00ff'), ('yellow', '#ffff00'), ('gray', '#a0a0a4'), ('black', '#000000'), ('darkRed', '#800000'), ('darkGreen', '#008000'), ('darkBlue', '#000080'), ('darkCyan', '#008080'), ('darkMagenta', '#800080'), ('darkYellow', '#808000'), ('darkGray', '#808080')] self.generateButtons() self.colorButtonGroup = QButtonGroup(self) for button in self.colorButtons: self.colorButtonGroup.addButton(button) self.colorButtonGroup.buttonClicked.connect(self.colorButtonToggled) # set the layout tmp = 0 for x in range(0, 2): for y in range(0, int(len(self.colorList) / 2)): self.colorGrid.addWidget(self.colorButtons[tmp], x, y) tmp += 1 self.colorGrid.setSpacing(0) self.colorGrid.setContentsMargins(0, 0, 0, 0) self.colorLayout.addWidget(self.presentColor) self.colorLayout.addWidget(self.colorPick)
def ui(self): super(ProjectSettingsWidget, self).ui() image_layout = layouts.HorizontalLayout(spacing=2, margins=(2, 2, 2, 2)) image_layout.setContentsMargins(2, 2, 2, 2) image_layout.setSpacing(2) self.main_layout.addLayout(image_layout) self._project_image = QLabel() self._project_image.setAlignment(Qt.AlignCenter) image_layout.addStretch() image_layout.addWidget(self._project_image) image_layout.addStretch() self._settings_tab = tabs.BaseTabWidget(parent=self) self.main_layout.addWidget(self._settings_tab) self._naming_widget = NamingWidget(project=self._project) self._project_options_widget = rigoptionsviewer.RigOptionsViewer( option_object=self._project, parent=self) self._external_code_widget = ExternalCodeDirectoryWidget(parent=self) version_control_widget = QWidget(parent=self) version_control_layout = layouts.VerticalLayout(spacing=0, margins=(2, 2, 2, 2)) version_control_widget.setLayout(version_control_layout) self._version_type_combo = combobox.BaseComboBox(parent=self) version_control_layout.addWidget(self._version_type_combo) version_control_layout.addStretch() self._settings_tab.addTab(self._project_options_widget, 'Settings') self._settings_tab.addTab(self._naming_widget, 'Nomenclature') self._settings_tab.addTab(version_control_widget, 'Version Control') self._settings_tab.addTab(self._external_code_widget, 'External Code') bottom_layout = layouts.VerticalLayout(spacing=2, margins=(2, 2, 2, 2)) bottom_layout.setAlignment(Qt.AlignBottom) self.main_layout.addLayout(bottom_layout) bottom_layout.addLayout(dividers.DividerLayout()) buttons_layout = layouts.HorizontalLayout(spacing=2, margins=(2, 2, 2, 2)) bottom_layout.addLayout(buttons_layout) ok_icon = resources.icon('ok') self._ok_btn = buttons.BaseButton(parent=self) self._ok_btn.setIcon(ok_icon) buttons_layout.addWidget(self._ok_btn)
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 )