def __init__(self, parent=None): super(ui, self).__init__(parent) self.setWindowTitle("Facial Rigger") self.setWindowFlags(QtCore.Qt.Window) self.setAttribute(QtCore.Qt.WA_DeleteOnClose, 1) tab_widget = QtWidgets.QTabWidget() dialogs = [eye_rigger.ui(), lips_rigger.ui()] for dialog in dialogs: tab_widget.addTab(dialog, dialog.windowTitle()) mainLayout = QtWidgets.QHBoxLayout() mainLayout.addWidget(tab_widget) self.setLayout(mainLayout)
def remove_all(self): self.jointNamesList.clearContents() self.jointNamesList.setRowCount(0) self.jointNamesList.insertRow(0) self.jointNamesList.setItem(0, 0, QtWidgets.QTableWidgetItem("")) self.jointNamesList.setCurrentCell(0, 0) self.apply_names()
def create_layout(self): self.gmc_layout = QtWidgets.QVBoxLayout() self.gmc_layout.addWidget(self.gmcUIInst) self.gmc_layout.setContentsMargins(3, 3, 3, 3) self.setLayout(self.gmc_layout)
def _layer_menu(self, QPos): """Create the layers rightclick menu Args: QPos (QPos): Position Returns: None: None """ lyr_widget = self.crankUIWInst.layers_listView currentSelection = lyr_widget.selectedIndexes() if currentSelection is None: return self.lyr_menu = QtWidgets.QMenu() parentPosition = lyr_widget.mapToGlobal(QtCore.QPoint(0, 0)) menu_item_01 = self.lyr_menu.addAction("Select Members") self.lyr_menu.addSeparator() menu_item_02 = self.lyr_menu.addAction("Selected Layer Edit OFF") menu_item_03 = self.lyr_menu.addAction("All Layers Edit OFF") self.lyr_menu.addSeparator() menu_item_04 = self.lyr_menu.addAction("Random Color + Isolate") menu_item_05 = self.lyr_menu.addAction("Clear Random Color") self.lyr_menu.addSeparator() menu_item_01.triggered.connect(self.select_members) menu_item_02.triggered.connect(self.edit_layer_off) menu_item_03.triggered.connect(self.edit_all_off) menu_item_04.triggered.connect(self.random_color) menu_item_05.triggered.connect(self.clear_random_color) self.lyr_menu.move(parentPosition + QPos) self.lyr_menu.show()
def dropOn(self, event): if event.isAccepted(): return False, None, None, None index = QtWidgets.QModelIndex() row = -1 col = -1 if self.viewport().rect().contains(event.pos()): index = self.indexAt(event.pos()) if (not index.isValid() or not self.visualRect(index).contains(event.pos())): index = self.rootIndex() if self.model().supportedDropActions() & event.dropAction(): if index != self.rootIndex(): dropIndicatorPosition = self.position(event.pos(), self.visualRect(index), index) qabw = QtWidgets.QAbstractItemView if dropIndicatorPosition == qabw.AboveItem: row = index.row() col = index.column() elif dropIndicatorPosition == qabw.BelowItem: row = index.row() + 1 col = index.column() else: row = index.row() col = index.column() if not self.droppingOnItself(event, index): return True, row, col, index return False, None, None, None
def add(self): row = max(0, self.jointNamesList.currentRow() or 0) self.jointNamesList.insertRow(row) item = QtWidgets.QTableWidgetItem("") self.jointNamesList.setItem(row, 0, item) self.jointNamesList.setCurrentCell(row, 0) self.apply_names()
def dropEvent(self, event): if not event.isAccepted() and event.source() == self: drop_row = self.drop_on(event) rows = sorted(set(item.row() for item in self.selectedItems())) rows_to_move = [[ QtWidgets.QTableWidgetItem(self.item(row_index, column_index)) for column_index in range(self.columnCount()) ] for row_index in rows] for row_index in reversed(rows): self.removeRow(row_index) if row_index < drop_row: drop_row -= 1 for row_index, data in enumerate(rows_to_move): row_index += drop_row self.insertRow(row_index) for column_index, column_data in enumerate(data): self.setItem(row_index, column_index, column_data) event.accept() for row_index in range(len(rows_to_move)): for column_index in range(self.columnCount()): self.item(drop_row + row_index, column_index).setSelected(True)
def add_node_save_options(self): '''Save data to node option ''' self.node_option_cb = QtWidgets.QCheckBox() self.node_option_cb.setText("Save data to node") self.option_layout.addWidget(self.node_option_cb)
def create_componentLayout(self): self.settings_layout = QtWidgets.QVBoxLayout() self.settings_layout.addWidget(self.tabs) self.settings_layout.addWidget(self.close_button) self.setLayout(self.settings_layout)
def _addNewRow(self, channel=None, source=None, target=None): """Add new row to the table Args: channel (str, optional): The channel to add to the table. source (str, optional): The source node that has the channel to move. target (str, optional): The destionation node for the channel. Returns: int: The row position index """ rowPosition = self.table.rowCount() self.table.insertRow(rowPosition) if channel and source: self._setRowChannel(rowPosition, channel, source) if target: self._setRowTarget(rowPosition, target) # adding the operation combo box operation_comboBox = QtWidgets.QComboBox() operation_comboBox.setObjectName("operation") operation_comboBox.addItem("Move Channel") operation_comboBox.addItem("Proxy Channel") operation_comboBox.SizeAdjustPolicy( QtWidgets.QComboBox.AdjustToContentsOnFirstShow) self.table.setCellWidget(rowPosition, 4, operation_comboBox) return rowPosition
def dropEvent(self, event): if not event.isAccepted() and event.source() == self: drop_row = self.drop_on(event) rows = sorted(set(item.row() for item in self.selectedItems())) rows_to_move = [[QtWidgets.QTableWidgetItem( self.item(row_index, column_index)) for column_index in range(self.columnCount())] for row_index in rows] rows_widgets_to_move = [self.cellWidget(row_index, 4) for row_index in rows] for row_index in reversed(rows): self.removeRow(row_index) if row_index < drop_row: drop_row -= 1 for row_index, data in enumerate(rows_to_move): inRow = row_index + drop_row self.insertRow(inRow) for column_index, column_data in enumerate(data): if column_index != 4: self.setItem(inRow, column_index, column_data) # self.setCellWidget(inRow, 4, rows_widgets_to_move[row_index]) # moving the combo box crash core. Current workaround is # create a new one and destroy the old # someone knows better way? Thanks :) operation_comboBox = QtWidgets.QComboBox() operation_comboBox.setObjectName("operation") operation_comboBox.addItem("Move Channel") operation_comboBox.addItem("Proxy Channel") size_polizy = QtWidgets.QComboBox.AdjustToContentsOnFirstShow operation_comboBox.SizeAdjustPolicy(size_polizy) oComboOld = rows_widgets_to_move[row_index] self.setCellWidget(inRow, 4, operation_comboBox) operation_comboBox.setCurrentIndex(oComboOld.currentIndex()) oComboOld.deleteLater() event.accept() for row_index in range(len(rows_to_move)): self.item(drop_row + row_index, 0).setSelected(True) self.item(drop_row + row_index, 1).setSelected(True) self.item(drop_row + row_index, 2).setSelected(True) self.item(drop_row + row_index, 3).setSelected(True)
def mousePressEvent(self, event): self.prevValue = self.value() self.startDragpos = event.pos() emodif = event.modifiers() modif = [ QtCore.Qt.ControlModifier, QtCore.Qt.ShiftModifier, QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier ] if event.button() == QtCore.Qt.MidButton: if self.draggers is None: self.draggers = draggers(self, self.isFloat, draggerSteps=self.draggerSteps) self.draggers.increment.connect(self.valueIncremented.emit) self.draggers.show() if self.isFloat: self.draggers.move( self.mapToGlobal( QtCore.QPoint( event.pos().x() - 1, event.pos().y() - self.draggers.height() / 2))) else: self.draggers.move( self.mapToGlobal( QtCore.QPoint( event.pos().x() - 1, event.pos().y() - (self.draggers.height() - self.draggers.height() / 6)))) elif event.button() == self.LeftButton and emodif not in modif: butts = QtCore.Qt.MouseButtons(self.MidButton) nevent = QtGui.QMouseEvent(event.type(), event.pos(), self.MidButton, butts, event.modifiers()) super(slider, self).mousePressEvent(nevent) elif emodif in modif: st_slider = QtWidgets.QStyleOptionSlider() st_slider.initFrom(self) st_slider.orientation = self.orientation() available = self.style().pixelMetric( QtWidgets.QStyle.PM_SliderSpaceAvailable, st_slider, self) xloc = QtWidgets.QStyle.sliderPositionFromValue( self.minimum(), self.maximum(), super(slider, self).value(), available) butts = QtCore.Qt.MouseButtons(self.MidButton) newPos = QtCore.QPointF() newPos.setX(xloc) nevent = QtGui.QMouseEvent(event.type(), newPos, self.MidButton, butts, event.modifiers()) self.startDragpos = newPos self.realStartDragpos = event.pos() super(slider, self).mousePressEvent(nevent) self.deltaValue = self.value() - self.prevValue self.setValue(self.prevValue) else: super(slider, self).mousePressEvent(event)
def create_layout(self): wdg_layout = QtWidgets.QHBoxLayout() wdg_layout.addWidget(QtWidgets.QLabel( "Duplicate symmetry: {}".format(self.guide_name))) btn_layout = QtWidgets.QHBoxLayout() btn_layout.addStretch() btn_layout.addWidget(self.skip_btn) btn_layout.addWidget(self.skip_all_btn) btn_layout.addWidget(self.re_sym_btn) btn_layout.addWidget(self.re_sym_all_btn) btn_layout.addWidget(self.cancel_btn) main_layout = QtWidgets.QVBoxLayout(self) main_layout.addLayout(wdg_layout) main_layout.addLayout(btn_layout)
def init_gui(self): """initialize the gui """ self.listWidget = QtWidgets.QListWidget(self) action = QtWidgets.QWidgetAction(self) action.setDefaultWidget(self.listWidget) self.addAction(action) self.listWidget.setFocus() self.key_list = anim_utils.getComboKeys( self.namespace, self.ui_host, self.combo_attr) self.listWidget.addItems(self.key_list) current_idx = anim_utils.getComboIndex( self.namespace, self.ui_host, self.combo_attr) self.listWidget.setCurrentRow(current_idx) self.listWidget.currentRowChanged.connect(self.accept)
def create_layout(self): """Create the layout """ self.crank_layout = QtWidgets.QVBoxLayout() self.crank_layout.addWidget(self.crankUIWInst) self.crank_layout.setContentsMargins(3, 3, 3, 3) self.setLayout(self.crank_layout)
def update_name(self, row, column): item = self.jointNamesList.item(row, column) if row == self.jointNamesList.rowCount() - 1 and item.text(): self.jointNamesList.insertRow(row + 1) self.jointNamesList.setItem( row + 1, 0, QtWidgets.QTableWidgetItem("")) self.apply_names() self.jointNamesList.setCurrentCell(row + 1, 0) self.jointNamesList.editItem(self.jointNamesList.currentItem())
def add_file_save_options(self): '''Add save to file options ''' self.file_option_cb = QtWidgets.QCheckBox() self.file_option_cb.setText("Save data to file") self.option_layout.addWidget(self.file_option_cb) file_layout = QtWidgets.QHBoxLayout() self.file_path_le = QtWidgets.QLineEdit() file_layout.addWidget(self.file_path_le) file_btn = basic.CallbackButton(callback=self.select_file_event) file_btn.setText("Select File") file_layout.addWidget(file_btn) self.option_layout.addLayout(file_layout)
def _search_menu(self, QPos): search_widget = self.gmcUIInst.search_lineEdit self.search_menu = QtWidgets.QMenu() parentPosition = search_widget.mapToGlobal(QtCore.QPoint(0, 0)) menu_item_01 = self.search_menu.addAction("Clear") menu_item_01.triggered.connect(search_widget.clear) self.search_menu.move(parentPosition + QPos) self.search_menu.show()
def gui(self): """set the widget layout and content """ self.mainLayout = QtWidgets.QVBoxLayout() self.setLayout(self.mainLayout) # ------------------------------------------------------------------- self.searchLineEdit = QtWidgets.QLineEdit() self.searchLineEdit.setPlaceholderText("Filter via ',' seperated...") self.selectAllButton = QtWidgets.QPushButton('Select All') self.mainLayout.addWidget(self.searchLineEdit) self.mainLayout.addWidget(self.selectAllButton) # ------------------------------------------------------------------- self.resultWidget = QtWidgets.QListWidget() self.resultWidget.setSpacing(4) self.resultWidget.setAlternatingRowColors(True) selMode = QtWidgets.QAbstractItemView.ExtendedSelection self.resultWidget.setSelectionMode(selMode) self.mainLayout.addWidget(self.resultWidget)
def setup(self): OverlayWidget.setup(self) # Add options group box group_box = QtWidgets.QGroupBox() group_box.setMaximumHeight(150) group_box.setTitle("Load options") self.option_layout = QtWidgets.QVBoxLayout(group_box) self.add_load_options() self.layout.addWidget(group_box) self.layout.addLayout(self.option_layout) self.layout.setAlignment(QtCore.Qt.AlignTop) self.load_namespace_options() # -------------------------------------------------------------------- close_btn = basic.CallbackButton(callback=self.hide) close_btn.setText("Cancel") self.layout.addWidget(close_btn) # -------------------------------------------------------------------- self.update_namespaces()
def create_menu(self): self.menu = QtWidgets.QMenu(self) reset_value_action = QtWidgets.QAction('Reset Value to Default', self) reset_value_action.setIcon(pyqt.get_icon("rewind")) reset_value_action.triggered.connect(self.reset_value_slot) self.menu.addAction(reset_value_action) self.menu.addSeparator() sync_graph_editor_action = QtWidgets.QAction( 'Sync Selected with Graph Editor', self) sync_graph_editor_action.setIcon(pyqt.get_icon("activity")) sync_graph_editor_action.triggered.connect(self.sync_graph_editor) self.menu.addAction(sync_graph_editor_action) self.menu.addSeparator() select_attr_host_action = QtWidgets.QAction('Select Host', self) select_attr_host_action.setIcon(pyqt.get_icon("arrow-up")) select_attr_host_action.triggered.connect(self.select_host) self.menu.addAction(select_attr_host_action) self.menu.addSeparator() set_range_action = QtWidgets.QAction('Set Range', self) set_range_action.setIcon(pyqt.get_icon("sliders")) set_range_action.triggered.connect(self.set_range_slot) self.menu.addAction(set_range_action) self.menu.addSeparator() self.menu.addSeparator() set_color_action = QtWidgets.QAction('Set Color', self) set_color_action.setIcon(pyqt.get_icon("edit-2")) set_color_action.triggered.connect(self.set_color_slot) self.menu.addAction(set_color_action) auto_color_host_action = QtWidgets.QAction('Auto Color by Host', self) auto_color_host_action.setIcon(pyqt.get_icon("edit-3")) auto_color_host_action.triggered.connect(self.auto_color_host_slot) self.menu.addAction(auto_color_host_action) auto_color_axis_action = QtWidgets.QAction('Auto Color by Axis', self) auto_color_axis_action.setIcon(pyqt.get_icon("edit-3")) auto_color_axis_action.triggered.connect(self.auto_color_axis_slot) self.menu.addAction(auto_color_axis_action) clear_color_action = QtWidgets.QAction('Clear Color', self) clear_color_action.setIcon(pyqt.get_icon("x-octagon")) clear_color_action.triggered.connect(self.clear_color_slot) self.menu.addAction(clear_color_action)
def create_layout(self): line_edit_style = """ QLineEdit { border: 0 solid transparent; margin-right: 2px; margin-left: 2px; } """ # main Layout main_layout = QtWidgets.QVBoxLayout(self) main_layout.setContentsMargins(2, 2, 2, 2) main_layout.setSpacing(0) main_layout.setMenuBar(self.menu_bar) # keyframe buttons Layout key_buttons_layout = QtWidgets.QHBoxLayout() key_buttons_layout.addWidget(self.key_all_button) key_buttons_layout.addWidget(self.key_copy_button) key_buttons_layout.addWidget(self.key_paste_button) # channel listing buttons Layout channel_buttons_layout = QtWidgets.QVBoxLayout() channel_buttons_layout.addWidget(self.lock_button) channel_buttons_layout.addWidget(self.refresh_button) channel_add_remove_buttons_layout = QtWidgets.QHBoxLayout() channel_add_remove_buttons_layout.addWidget(self.add_channel_button) channel_add_remove_buttons_layout.addWidget(self.remove_channel_button) channel_add_remove_buttons_layout.addWidget(self.lock_button) # node list layout node_list_layout = QtWidgets.QHBoxLayout() node_list_layout.addWidget(self.node_list_combobox) node_list_layout.addWidget(self.refresh_node_list_button) node_list_layout.addWidget(self.new_node_button) # search line layout search_line_layout = QtWidgets.QHBoxLayout() self.search_lineEdit.setStyleSheet(line_edit_style) search_line_layout.addWidget(self.search_label) search_line_layout.addWidget(self.search_lineEdit) search_line_layout.addWidget(self.search_clear_button) # Buttons layout buttons_layout = QtWidgets.QHBoxLayout() buttons_layout.addLayout(key_buttons_layout) buttons_layout.addStretch() buttons_layout.addLayout(channel_add_remove_buttons_layout) main_layout.addLayout(node_list_layout) main_layout.addLayout(search_line_layout) main_layout.addLayout(buttons_layout) main_layout.addWidget(self.tab_widget) # main_table self.tab_widget.addTab(self.main_table, "Main")
def __init__(self, *args, **kwargs): # type: () -> None super(SynopticTabWrapper, self).__init__(*args, **kwargs) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.rubberband = QtWidgets.QRubberBand( QtWidgets.QRubberBand.Rectangle, self) self.offset = QtCore.QPoint()
def create_layouts(self): for d in self.descriptors_layout: self.main_layout.addLayout(d) spacerItem = QtWidgets.QSpacerItem( 20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) self.main_layout.addItem(spacerItem)
def create_button(size=17, text=None, icon=None, toggle_icon=None, icon_size=None, toolTip=None): """Create and configure a QPsuhButton Args: size (int, optional): Size of the button text (str, optional): Text of the button icon (str, optional): Icon name toggle_icon (str, optional): Toggle icon name. If exist will make the button checkable icon_size (int, optional): Icon size toolTip (str, optional): Buttom tool tip Returns: QPushButton: The reated button """ button = QtWidgets.QPushButton() button.setMaximumHeight(size) button.setMinimumHeight(size) button.setMaximumWidth(size) button.setMinimumWidth(size) if toolTip: button.setToolTip(toolTip) if text: button.setText(text) if icon: if not icon_size: icon_size = size - 3 button.setIcon(pyqt.get_icon(icon, icon_size)) if toggle_icon: button.setCheckable(True) def changeIcon(button=button, icon=icon, toggle_icon=toggle_icon, size=icon_size): if button.isChecked(): button.setIcon(pyqt.get_icon(toggle_icon, size)) else: button.setIcon(pyqt.get_icon(icon, size)) button.clicked.connect(changeIcon) return button
def populate_controls(self): jointNames = self.root.attr("joint_names").get().split(",") if jointNames[-1]: jointNames.append("") self.jointNamesList.clearContents() self.jointNamesList.setRowCount(0) for i, name in enumerate(jointNames): self.jointNamesList.insertRow(i) item = QtWidgets.QTableWidgetItem(name.strip()) self.jointNamesList.setItem(i, 0, item)
def add_confirmation_buttons(self): '''Add save confirmation buttons to overlay ''' btn_layout = QtWidgets.QHBoxLayout() spacer = QtWidgets.QSpacerItem(0, 0, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) btn_layout.addItem(spacer) close_btn = basic.CallbackButton(callback=self.cancel_event) close_btn.setText("Cancel") btn_layout.addWidget(close_btn) save_btn = basic.CallbackButton(callback=self.save_event) save_btn.setText("Save") btn_layout.addWidget(save_btn) spacer = QtWidgets.QSpacerItem(0, 0, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) btn_layout.addItem(spacer) self.layout.addLayout(btn_layout)
def setup(self): OverlayWidget.setup(self) # Add options group box group_box = QtWidgets.QGroupBox() group_box.setTitle("Save options") self.option_layout = QtWidgets.QVBoxLayout(group_box) self.layout.addWidget(group_box) # Add options self.add_node_save_options() self.add_file_save_options() # Add action buttons self.add_confirmation_buttons() # Add vertical spacer spacer = QtWidgets.QSpacerItem(0, 0, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) self.layout.addItem(spacer) self.data_node = None
def _setRowItem(self, rowPosition, itemIndex, itemContent): """Set the row item Args: rowPosition (Int): Row Index itemIndex (Int): Item Index itemContent (Str): Item content Returns: QTableWidgetItem: Item """ item = QtWidgets.QTableWidgetItem(itemContent) self.table.setItem(rowPosition, itemIndex, item) return item
def contextMenuEvent(self, event): '''Right click menu options ''' # Abort in non edit mode if not __EDIT_MODE__.get(): return # Init context menu menu = QtWidgets.QMenu(self) # Add choose action choose_action = QtWidgets.QAction("Select Picture", None) choose_action.triggered.connect(self.select_image) menu.addAction(choose_action) # Add reset action reset_action = QtWidgets.QAction("Reset", None) reset_action.triggered.connect(self.reset_image) menu.addAction(reset_action) # Open context menu under mouse if not menu.isEmpty(): menu.exec_(self.mapToGlobal(event.pos()))