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 ui(self): super(InterpolateItView, self).ui() central_layout = layouts.VerticalLayout(spacing=0, margins=(0, 0, 0, 0)) central_widget = QWidget() central_widget.setLayout(central_layout) central_widget.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)) scroll = QScrollArea() scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) scroll.setWidgetResizable(True) scroll.setFocusPolicy(Qt.NoFocus) self.main_layout.addWidget(scroll) scroll.setWidget(central_widget) self._interpolator_layout = layouts.VerticalLayout(spacing=0, margins=(0, 0, 0, 0)) self._interpolator_layout.setAlignment(Qt.AlignTop) button_layout = layouts.HorizontalLayout(spacing=2, margins=(0, 0, 0, 0)) self._load_btn = buttons.BaseButton('Load', parent=self) self._save_btn = buttons.BaseButton('Save', parent=self) self._add_btn = buttons.BaseButton('New', parent=self) button_layout.addWidget(self._save_btn) button_layout.addWidget(self._load_btn) button_layout.addStretch() button_layout.addWidget(self._add_btn) central_layout.addLayout(self._interpolator_layout) self.main_layout.addLayout(button_layout)
def ui(self): """ Function that sets up the ui of the widget Override it on new widgets (but always call super) """ self.main_layout = self.get_main_layout() if self._use_scrollbar: layout = layouts.VerticalLayout(spacing=0, margins=(0, 0, 0, 0)) self.setLayout(layout) central_widget = QWidget() central_widget.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)) scroll = QScrollArea() scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) scroll.setWidgetResizable(True) scroll.setFocusPolicy(Qt.NoFocus) layout.addWidget(scroll) scroll.setWidget(central_widget) central_widget.setLayout(self.main_layout) self.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)) else: self.setLayout(self.main_layout)
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 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 __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 ui(self): super(Changelog, self).ui() self.set_logo('changelog_logo') self.main_layout.setAlignment(Qt.AlignTop) self.main_layout.setContentsMargins(0, 0, 0, 0) self.setFixedWidth(600) self.setMaximumHeight(800) scroll_layout = layouts.VerticalLayout(spacing=2, margins=(2, 2, 2, 2)) scroll_layout.setAlignment(Qt.AlignTop) central_widget = QWidget() central_widget.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)) scroll = QScrollArea() scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) scroll.setWidgetResizable(True) scroll.setFocusPolicy(Qt.NoFocus) ok_btn = QPushButton('OK') ok_btn.clicked.connect(self.close) self.main_layout.addWidget(scroll) self.main_layout.setAlignment(Qt.AlignTop) self.main_layout.addWidget(ok_btn) scroll.setWidget(central_widget) central_widget.setLayout(scroll_layout) self.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)) self.main_layout = scroll_layout # =========================================================================================== self.version_accordion = accordion.AccordionWidget(parent=self) self.version_accordion.rollout_style = accordion.AccordionStyle.MAYA self.main_layout.addWidget(self.version_accordion) # =========================================================================================== changelog_json_file = os.path.join( os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'changelog.json') if not os.path.isfile(changelog_json_file): return with open(changelog_json_file, 'r') as f: changelog_data = json.load(f, object_pairs_hook=OrderedDict) if not changelog_data: return changelog_data = OrderedDict( sorted(changelog_data.items(), reverse=True)) for version, elements in changelog_data.items(): self._create_version(version, elements) last_version_item = self.version_accordion.item_at(0) last_version_item.set_collapsed(False)
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 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
class ExpandableFrame(base.BaseFrame, object): def __init__(self, title='', icon=None, parent=None): self._is_collapsed = True self._title_frame = None self._content = None self._title = title self._icon = icon self._content_layout = None super(ExpandableFrame, self).__init__(parent=parent) def ui(self): super(ExpandableFrame, self).ui() title_layout = layouts.HorizontalLayout(spacing=0, margins=(0, 0, 0, 0)) self._title_frame = TitleFrame(title=self._title, icon=self._icon, collapsed=self._is_collapsed) self._icon_button = label.BaseLabel(parent=self) if self._icon: self._icon_button.setPixmap(self._icon.pixmap(QSize(20, 20))) else: self._icon_button.setVisible(False) title_layout.addWidget(self._icon_button) title_layout.addWidget(self._title_frame) title_layout.addStretch() self._content = QWidget() self._content_layout = layouts.VerticalLayout() self._content.setLayout(self._content_layout) self._content.setVisible(not self._is_collapsed) self.main_layout.addLayout(title_layout) self.main_layout.addWidget(self._content) def setup_signals(self): self._title_frame.clicked.connect(self._on_toggle_collapsed) self._icon_button.clicked.connect(self._on_toggle_collapsed) def addWidget(self, widget): self._content_layout.addWidget(widget) def addLayout(self, layout): self._content_layout.addLayout(layout) def set_title(self, title): self._title_frame.set_title(title) def _on_toggle_collapsed(self): self._content.setVisible(self._is_collapsed) self._is_collapsed = not self._is_collapsed self._title_frame._arrow.setArrow(self._is_collapsed)
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(MenuTabWidget, self).ui() self.tool_btn_grp = MenuTabBlockButtonGroup() bar_widget = QWidget() bar_widget.setObjectName('bar_widget') self._bar_layout = layouts.HorizontalLayout(margins=(10, 0, 10, 0)) bar_widget.setLayout(self._bar_layout) self._bar_layout.addWidget(self.tool_btn_grp) self._bar_layout.addStretch() self.main_layout.addWidget(bar_widget) self.main_layout.addWidget(dividers.Divider()) self.main_layout.addSpacing(5)
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()
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 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 ui(self): super(AutoRenameWidget, self).ui() top_layout = layouts.HorizontalLayout(spacing=2, margins=(0, 0, 0, 0)) self._unique_id_cbx = checkbox.BaseCheckBox('Unique Id') self._last_joint_end_cbx = checkbox.BaseCheckBox('Make Last Joint End') top_layout.addStretch() top_layout.addWidget(self._unique_id_cbx) top_layout.addWidget(self._last_joint_end_cbx) self.main_layout.addLayout(top_layout) main_splitter = QSplitter(Qt.Horizontal) main_splitter.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding) self.main_layout.addWidget(main_splitter) auto_widget = QWidget() auto_layout = layouts.VerticalLayout(spacing=0, margins=(0, 0, 0, 0)) auto_widget.setLayout(auto_layout) main_splitter.addWidget(auto_widget) self._rules_list = QTreeWidget(self) self._rules_list.setHeaderHidden(True) self._rules_list.setSortingEnabled(True) self._rules_list.setRootIsDecorated(False) self._rules_list.setSelectionMode(QAbstractItemView.SingleSelection) self._rules_list.sortByColumn(0, Qt.AscendingOrder) self._rules_list.setUniformRowHeights(True) self._rules_list.setAlternatingRowColors(True) auto_layout.addWidget(self._rules_list) auto_w = QWidget() self.auto_l = layouts.VerticalLayout(spacing=0, margins=(0, 0, 0, 0)) auto_w.setLayout(self.auto_l) auto_w.setMinimumWidth(200) main_splitter.addWidget(auto_w) self.main_auto_layout = QFormLayout() self.auto_l.addLayout(self.main_auto_layout) self._rename_btn = buttons.BaseButton('Rename') self._rename_btn.setIcon(resources.icon('rename')) self.main_layout.addLayout(dividers.DividerLayout()) self.main_layout.addWidget(self._rename_btn)
class ScriptsEditorPlugin(plugin.DockPlugin, object): NAME = 'Scripts Editor' TOOLTIP = 'Allow to edit scripts easily' DEFAULT_DOCK_AREA = Qt.RightDockWidgetArea IS_SINGLETON = True 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) @staticmethod def icon(): return resources.icon('source_code') def show_plugin(self): super(ScriptsEditorPlugin, self).show_plugin() if not self._script_editor_widget: # Settings are used to colorize script editor text depending on current theme settings = self._app.settings() self._script_editor_widget = ScriptEditorWidget(settings=settings, parent=self) # self._script_editor_widget = scripteditor.ScriptEditorWidget(settings=settings, load_session=False) # self._script_editor_widget.scriptSaved.connect(self._on_script_saved) self._script_editor_widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self._content_layout.addWidget(self._script_editor_widget) self._script_editor_widget.editorClosed.connect(self.close) def load_script(self, script_file): if not self._script_editor_widget: return self._script_editor_widget.controller.load_script(script_file) def _on_script_saved(self, file_path): pass
class Widget(QTabWidget): def __init__(self): super(Widget, self).__init__() self.title = "Andrea <3" self.top = 100 self.left = 300 self.width = 200 self.height = 480 self.msg = "Nothing going on..." self.label = QLabel() self.label.setText(self.msg) self.build_button1() self.build_tab1() self.build_tab2() self.init_ui() def button1_clicked(self): self.msg = "Button 1 has been clicked." self.label.setText(self.msg) print(self.msg) def build_button1(self): self.button1 = QPushButton("Button1") self.button1.clicked.connect(self.button1_clicked) def build_tab1(self): self.tab1 = QWidget() self.tab1.layout = QVBoxLayout(self) self.tab1.layout.addWidget(self.button1) self.tab1.setLayout(self.tab1.layout) def build_tab2(self): self.tab2 = QWidget() self.tab2.layout = QVBoxLayout(self) self.tab2.layout.addWidget(self.label) self.tab2.setLayout(self.tab2.layout) def init_ui(self): self.setWindowTitle(self.title) self.addTab(self.tab1, "tab 1") self.addTab(self.tab2, "tab 2") self.setGeometry(self.left, self.top, self.width, self.height) self.show()
class RenamerPlugin(plugin.DockPlugin, object): NAME = 'Renamer' TOOLTIP = 'Allows to rename DCC nodes' DEFAULT_DOCK_AREA = Qt.LeftDockWidgetArea IS_SINGLETON = True 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) @staticmethod def icon(): return resources.icon('rename') def show_plugin(self): super(RenamerPlugin, self).show_plugin() # TODO: This should be defined dev = False names_config = configs.get_config( config_name='tpRigToolkit-names', environment='development' if dev else 'production') naming_config = configs.get_config( config_name='tpRigToolkit-naming', environment='development' if dev else 'production') self._renamer_widget = renamer.RenamerToolsetWidget( names_config=names_config, naming_config=naming_config, parent=self) self._renamer_widget.initialize() self._renamer_widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self._content_layout.addWidget(self._renamer_widget)
def ui(self): super(ScriptEditorView, self).ui() self._stack = stack.SlidingOpacityStackedWidget(parent=self) main_splitter = QSplitter(Qt.Vertical, parent=self) self._output_console = console.OutputConsole(parent=self) # NOTE: Scripts Tab MUST pass ScriptEditor as parent because internally some ScriptEditor functions # NOTE: are connected to some signals. If we don't do this Maya will crash when opening new Script Editors :) self._scripts_tab = script.ScriptsTab(controller=self._controller, parent=self) main_splitter.addWidget(self._output_console) main_splitter.addWidget(self._scripts_tab) self._menu_bar = self._setup_menubar() self._tool_bar = self._setup_toolbar() self._tool_bar_divider = dividers.Divider() # Empty widget empty_widget = QWidget(self) empty_layout = layouts.HorizontalLayout(spacing=5, margins=(5, 5, 5, 5)) empty_widget.setLayout(empty_layout) main_empty_layout = layouts.VerticalLayout(spacing=5, margins=(5, 5, 5, 5)) self._empty_label = label.BaseLabel('No Scripts Opened', parent=self).h4().strong() self._empty_label.setAlignment(Qt.AlignCenter) main_empty_layout.addStretch() main_empty_layout.addWidget(self._empty_label) main_empty_layout.addStretch() empty_layout.addStretch() empty_layout.addLayout(main_empty_layout) empty_layout.addStretch() self._stack.addWidget(empty_widget) self._stack.addWidget(main_splitter) self.main_layout.addWidget(self._menu_bar) self.main_layout.addWidget(self._tool_bar) self.main_layout.addWidget(self._tool_bar_divider) self.main_layout.addWidget(self._stack)
def get_vertical_separator_widget(max_height=30, parent=None): """ Returns horizontal separator widget :param max_height: int, maximum height for the separator :param parent: QWidget or None, parent widget :return: QWidget """ h_div_w = QWidget(parent=parent) h_div_l = layouts.VerticalLayout(spacing=0, margins=(5, 5, 5, 5)) h_div_l.setAlignment(Qt.AlignLeft) h_div_w.setLayout(h_div_l) h_div = QFrame(parent=h_div_w) h_div.setObjectName('dividerSeparator') # ID selector used by style h_div.setMaximumHeight(qtutils.dpi_scale(max_height)) h_div.setFrameShape(QFrame.VLine) h_div.setFrameShadow(QFrame.Sunken) h_div_l.addWidget(h_div) return h_div_w
def __init__(self, parent=None): super(ExpanderWidget, self).__init__(parent=parent) self._rolloutStyle = ExpanderStyles.Maya if dcc.client().is_maya() else ExpanderStyles.Square self._dragDropMode = ExpanderDragDropModes.NoDragDrop self._scrolling = False self._scrollInitY = 0 self._scrollInitVal = 0 self._itemClass = ExpanderItem self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.setFrameShape(QScrollArea.NoFrame) self.setAutoFillBackground(False) self.setWidgetResizable(True) self.setMouseTracking(True) widget = QWidget(self) layout = layouts.VerticalLayout(spacing=2, margins=(2, 2, 2, 2)) layout.setAlignment(Qt.AlignTop) widget.setLayout(layout) self.setWidget(widget)
def _create_version(self, version, elements): version_widget = QWidget() version_layout = layouts.VerticalLayout(spacing=0, margins=(0, 0, 0, 0)) version_layout.setContentsMargins(0, 0, 0, 0) version_layout.setSpacing(0) version_layout.setAlignment(Qt.AlignTop) version_widget.setLayout(version_layout) self.version_accordion.add_item(version, version_widget, collapsed=True) version_label = QLabel() version_layout.addWidget(version_label) version_text = '' for item in elements: version_text += '- {}\n'.format(item) version_label.setText(version_text) self.main_layout.addSpacing(5)
def _setup_colors_tab(self): scroll_area = QScrollArea() scroll_area.setWidgetResizable(True) colors_widget = QWidget() colors_layout = layouts.GridLayout(spacing=2, margins=(2, 2, 2, 2)) colors_layout.setAlignment(Qt.AlignTop) colors_widget.setLayout(colors_layout) scroll_area.setWidget(colors_widget) color_attribute_names = self._theme.get_color_attribute_names( ) or list() for i, color_attribute_name in enumerate(color_attribute_names): if not hasattr(self._theme, color_attribute_name): continue label, selector = self._add_color_widget( color_attribute_name, getattr(self._theme, color_attribute_name)) colors_layout.addWidget(label, i, 0, Qt.AlignRight) colors_layout.addWidget(selector, i, 1) return scroll_area
def ui(self): self.setLayout(layouts.VerticalLayout(spacing=0, margins=(3, 1, 3, 3))) self.main_layout = layouts.VerticalLayout(spacing=5, margins=(2, 2, 2, 2)) main_widget = QWidget() if self._item_height: main_widget.setFixedHeight(self._item_height - self._height_offset) if self._item_width: main_widget.setFixedWidth(self._item_width - self._width_offset) main_widget.setLayout(self.main_layout) self.layout().addWidget(main_widget) # ===================================================== # This layout is used to add custom widgets before the title of the node self.buttons_layout = layouts.VerticalLayout(spacing=2, margins=(2, 2, 2, 2)) title_layout = layouts.HorizontalLayout() title_layout.addLayout(self.buttons_layout) title_line = QLineEdit('Untitled') if not self._editable_title: title_line.setEnabled(False) if self._has_title: title_layout.addWidget(title_line) self._close_btn = QPushButton('X') self._close_btn.setFixedHeight(20) self._close_btn.setFixedWidth(20) self._close_btn.clicked.connect(self.close_widget) if self._is_closable: title_layout.addWidget(self._close_btn) self.main_layout.addLayout(title_layout)
def __init__(self, parent=None): super(AccordionWidget, self).__init__(parent=parent) self._rollout_style = AccordionStyle.SQUARE if dcc.is_maya(): self._rollout_style = AccordionStyle.MAYA self._drag_drop_mode = AccordionDragDrop.NO_DRAG_DROP self._scrolling = False self._scroll_init_y = 0 self._scroll_init_val = 0 self._item_class = AccordionItem self.setFrameShape(QScrollArea.NoFrame) self.setAutoFillBackground(False) self.setWidgetResizable(True) self.setMouseTracking(True) self.verticalScrollBar().setMaximumWidth(10) widget = QWidget(self) layout = layouts.VerticalLayout(spacing=2, margins=(2, 2, 2, 6)) layout.addStretch(1) widget.setLayout(layout) self.setWidget(widget)
def _setup_general_tab(self): general_widget = QWidget() general_layout = layouts.VerticalLayout(spacing=2, margins=(2, 2, 2, 2)) general_widget.setLayout(general_layout) self._themes_combobox = combobox.BaseComboBox(parent=self) all_themes = resources.get_all_resources_of_type( resources.ResourceTypes.THEME) for i, theme in enumerate(all_themes): accent_color_hex = theme.accent_color accent_color = color.Color.hex_to_qcolor( accent_color_hex[1:] if accent_color_hex. startswith('#') else accent_color_hex) background_color_hex = theme.background_color background_color = color.Color.hex_to_qcolor( background_color_hex[1:] if accent_color_hex. startswith('#') else background_color_hex) accent_color_pixmap = QPixmap(25, 25) background_color_pixmap = QPixmap(25, 25) accent_color_pixmap.fill(accent_color) background_color_pixmap.fill(background_color) color_pixmap = QPixmap(50, 25) painter = QPainter(color_pixmap) painter.drawPixmap(0, 0, 25, 25, accent_color_pixmap) painter.drawPixmap(25, 0, 25, 25, background_color_pixmap) painter.end() color_icon = QIcon(color_pixmap) self._themes_combobox.addItem(color_icon, theme.name()) general_layout.addWidget(self._themes_combobox) general_layout.addStretch() return general_widget
def _setup_fonts_tab(self): fonts_widget = QWidget() fonts_layout = layouts.VerticalLayout(spacing=2, margins=(2, 2, 2, 2)) fonts_widget.setLayout(fonts_layout) return fonts_widget
class ExpandablePanel(base.BaseWidget, object): def __init__(self, header_text, min_height=30, max_height=1000, show_header_text=True, is_opened=False, parent=None): self._header_text = header_text self._show_header_text = show_header_text self._min_height = min_height self._max_height = max_height if is_opened: self._panel_state = PanelState.OPEN else: self._panel_state = PanelState.CLOSED self._collapse_icon = QIcon() self._icon = QPushButton() self._icon.setMaximumSize(20, 20) self._icon.setIcon(self._collapse_icon) super(ExpandablePanel, self).__init__(parent=parent) self.setObjectName('ExpandablePanel') self.update_size() self.update_icon() def ui(self): super(ExpandablePanel, self).ui() widget_palette = QPalette() widget_palette.setColor(QPalette.Background, QColor.fromRgb(60, 60, 60)) self.setAutoFillBackground(True) self.setPalette(widget_palette) frame = QFrame() frame.setFrameShape(QFrame.StyledPanel) frame.setFrameShadow(QFrame.Sunken) self.main_layout.addWidget(frame) main_layout = layouts.VerticalLayout(spacing=0, margins=(2, 2, 2, 2), parent=frame) main_layout.setAlignment(Qt.AlignTop) self._header_area = QWidget() self._header_area.setMinimumHeight(20) self._widget_area = QWidget() self._widget_area.setAutoFillBackground(True) self._widget_area.setPalette(widget_palette) self._header_text_label = dividers.Divider(self._header_text) self._widget_layout = layouts.VerticalLayout(spacing=5) self._widget_layout.setMargin(5) self._widget_area.setLayout(self._widget_layout) header_layout = layouts.HorizontalLayout(margins=(0, 0, 0, 0)) header_layout.addWidget(self._icon) header_layout.addWidget(self._header_text_label) self._header_area.setLayout(header_layout) main_layout.addWidget(self._header_area) main_layout.addWidget(self._widget_area) self._icon.clicked.connect(self.change_state) def update_icon(self): if self._panel_state == PanelState.OPEN: self._icon.setStyleSheet( 'QLabel {image: url(:/icons/open_hover_collapsible_panel) no-repeat;} ' 'QLabel:hover {image:url(:/icons/open_hover_collapsible_panel) no-repeat;}') self._icon.setToolTip('Close') self._widget_area.show() else: self._icon.setStyleSheet( 'QLabel {image: url(:/icons/closed_collapsible_panel) no-repeat;} ' 'QLabel:hover {image:url(:/icons/closed_hover_collapsible_panel) no-repeat;}') self._icon.setToolTip('Open') self._widget_area.hide() def update_size(self): if self._panel_state == PanelState.OPEN: self.setMaximumHeight(self._max_height) self.setMinimumHeight(self._min_height) else: self.setMaximumHeight(self._min_height) self.setMinimumHeight(self._min_height) def change_state(self): if not self._show_header_text: self._header_text_label.setVisible(False) if self._panel_state == PanelState.OPEN: self._panel_state = PanelState.CLOSED # self._header_text_label.setText('Closed') self._widget_area.hide() else: self._panel_state = PanelState.OPEN # self._header_text_label.setText('Open') self._widget_area.show() self.update_icon() self.update_size() def add_widget(self, widget): self._widget_layout.addWidget(widget) def add_layout(self, layout): self._widget_layout.addLayout(layout)
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 ui(self): super(ManualJointOrientView, self).ui() manual_joint_ori_layout = layouts.HorizontalLayout() self._manual_joint_ori_x_spin = spinbox.DoubleSpinBoxAxis(axis='x', min=-360, max=360, parent=self) self._manual_joint_ori_y_spin = spinbox.DoubleSpinBoxAxis(axis='y', min=-360, max=360, parent=self) self._manual_joint_ori_z_spin = spinbox.DoubleSpinBoxAxis(axis='z', min=-360, max=360, parent=self) self._manual_joint_ori_x_spin.setDecimals(3) self._manual_joint_ori_y_spin.setDecimals(3) self._manual_joint_ori_z_spin.setDecimals(3) self._manual_joint_ori_reset_btn = buttons.BaseButton('Reset', parent=self) self._manual_joint_ori_reset_btn.setIcon(resources.icon('reset')) manual_joint_ori_layout.addWidget(self._manual_joint_ori_x_spin) manual_joint_ori_layout.addWidget(self._manual_joint_ori_y_spin) manual_joint_ori_layout.addWidget(self._manual_joint_ori_z_spin) manual_joint_ori_layout.addWidget(self._manual_joint_ori_reset_btn) manual_joint_splitter_layout = layouts.HorizontalLayout() manual_joint_splitter_layout.addStretch() self._degrees_checks = list() for degree in self._model.available_degrees: degree_radio = buttons.BaseRadioButton(str(degree), parent=self) manual_joint_splitter_layout.addWidget(degree_radio) self._degrees_checks.append(degree_radio) manual_joint_splitter_layout.addStretch() manual_joint_ori_buttons_layout = layouts.HorizontalLayout( spacing=5, margins=(2, 2, 2, 2)) self._manual_joint_ori_add_btn = buttons.BaseButton('Add', parent=self) self._manual_joint_ori_subtract_btn = buttons.BaseButton('Subract', parent=self) self._manual_joint_ori_set_btn = buttons.BaseButton('Set', parent=self) self._manual_joint_ori_set_cbx = checkbox.BaseCheckBox( 'Affect children', parent=self) self._manual_joint_ori_add_btn.setIcon(resources.icon('add')) self._manual_joint_ori_subtract_btn.setIcon(resources.icon('minus')) self._manual_joint_ori_set_btn.setIcon(resources.icon('equals')) manual_joint_ori_buttons_layout.addWidget( self._manual_joint_ori_add_btn) manual_joint_ori_buttons_layout.addWidget( self._manual_joint_ori_subtract_btn) manual_joint_ori_buttons_layout.addWidget( self._manual_joint_ori_set_btn) manual_joint_ori_buttons_layout.addWidget( self._manual_joint_ori_set_cbx) set_rot_axis_widget = QWidget() set_rot_axis_widget.setLayout(layouts.VerticalLayout()) set_rot_axis_widget.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) set_rot_axis_widget.layout().setContentsMargins(5, 5, 5, 5) set_rot_axis_widget.layout().setSpacing(10) self.main_layout.addLayout(manual_joint_splitter_layout) self.main_layout.addLayout(manual_joint_ori_layout) self.main_layout.addWidget(dividers.Divider()) self.main_layout.addLayout(manual_joint_ori_buttons_layout) self.main_layout.addWidget(set_rot_axis_widget)