def mini_icon_button(ui_manager, parent, layout, icon=None, text='', action='', x=-1, y=-1, checkable=False, max_width=16): """ :param ui_manager: :param layout: :param parent: :param text: :param action: :param x: :param y: :param checkable: :param max_width: :return: """ button = PanelButton(pixmap=icon, tooltip=text, parent=parent, size=12) button.setMaximumWidth(max_width) button.setCheckable(checkable) ui_manager.connect_element_to_action(button, action) if x != -1: layout.addWidget(button, y, x) else: layout.addWidget(button) return button
def __init__(self, parent, host, text): UIWidget.__init__(self, host) QtWidgets.QWidget.__init__(self, parent) self._palette = None self.update_colors() self._drag_diff = None self.moved_by_hand = False self.top_row_layout = QtWidgets.QHBoxLayout() #close_button = QtWidgets.QPushButton("x") close_button = PanelButton(pixmap=qt_prefs.close_icon, tooltip='Close', parent=self, size=12, color_key='content1') close_button.setMaximumWidth(16) self.ui_manager.connect_element_to_action(close_button, 'close_embed') self.top_row_layout.addWidget(close_button) self.top_row_layout.setAlignment(QtCore.Qt.AlignLeft) self.top_row_layout.addSpacing(8) self.top_title = QtWidgets.QLabel(text) self.top_row_layout.addWidget(self.top_title) self.assumed_width = 300 self.assumed_height = 100 self._magnet = QtCore.QPoint(0, 0), 1 # Effect will be disabled if QTextEdit is used. self.setAutoFillBackground(True) self.setBackgroundRole(QtGui.QPalette.Window) self.hide()
def __init__(self, name, default_position='bottom', parent=None, folded=False): """ All of the panel constructors follow the same format so that the construction can be automated. :param name: Title of the panel and the key for accessing it :param default_position: 'bottom', 'right'... :param parent: self.main :param ui_manager: pass a dictionary where buttons from this panel will be added """ Panel.__init__(self, name, default_position, parent, folded) inner = QtWidgets.QWidget() inner.setMinimumHeight(40) inner.setMaximumHeight(50) inner.preferred_size = QtCore.QSize(220, 40) inner.sizeHint = self.sizeHint layout = QtWidgets.QVBoxLayout() hlayout = QtWidgets.QHBoxLayout() hlayout.setContentsMargins(0, 0, 0, 0) selector = SelectionBox(self) self.selector = selector for key, item in []: selector.addItem('%s (%s)' % (key, item.shortcut), key) self.ui_manager.connect_element_to_action(selector, 'set_visualization') hlayout.addWidget(selector) self.toggle_options = PanelButton(pixmap=qt_prefs.settings_pixmap, tooltip='Visualization settings', parent=self, size=20) self.toggle_options.setFixedSize(26, 26) self.toggle_options.setCheckable(True) ctrl.ui.connect_element_to_action(self.toggle_options, 'toggle_panel_%s' % g.VIS_OPTIONS) hlayout.addWidget(self.toggle_options, 1, QtCore.Qt.AlignRight) layout.addLayout(hlayout) inner.setLayout(layout) self.watchlist = ['forest_changed'] self.preferred_size = inner.preferred_size self.setWidget(inner) self.widget().setAutoFillBackground(True) self.finish_init()
def icon_button(ui_manager, parent, layout, icon=None, text='', action='', x=-1, y=-1, checkable=False, size=20, color_key='accent8', tooltip_suffix='', align=None): """ :param ui_manager: :param layout: :param parent: :param text: :param action: :param x :param y :param checkable :param size :param color_key :param tooltip_suffix :param align :return: """ button = PanelButton(pixmap=icon, tooltip=text, parent=parent, size=size, color_key=color_key) button.setCheckable(checkable) if action: ui_manager.connect_element_to_action(button, action, tooltip_suffix=tooltip_suffix) if x != -1: layout.addWidget(button, y, x) elif align is not None: layout.addWidget(button, 1, align) else: layout.addWidget(button) return button
def __init__(self, name, default_position='right', parent=None, folded=False): """ All of the panel constructors follow the same format so that the construction can be automated. :param name: Title of the panel and the key for accessing it :param default_position: 'bottom', 'right'... :param parent: self.main """ Panel.__init__(self, name, default_position, parent, folded) inner = QtWidgets.QWidget() inner.preferred_size = QtCore.QSize(200, 70) inner.setMaximumWidth(220) inner.setMaximumHeight(80) inner.sizeHint = self.sizeHint layout = QtWidgets.QVBoxLayout() hlayout = QtWidgets.QHBoxLayout() self.selector = SelectionBox(self) self.selector.add_items([('%s (%s)' % (key, item.shortcut), key) for key, item in VISUALIZATIONS.items()]) self.ui_manager.connect_element_to_action(self.selector, 'set_visualization') hlayout.addWidget(self.selector) self.toggle_options = PanelButton(pixmap=qt_prefs.settings_pixmap, parent=self, size=20) self.toggle_options.setFixedSize(26, 26) self.toggle_options.setCheckable(True) ctrl.ui.connect_element_to_action( self.toggle_options, 'toggle_panel_VisualizationOptionsPanel') hlayout.addWidget(self.toggle_options, 1, QtCore.Qt.AlignRight) layout.addLayout(hlayout) hlayout = QtWidgets.QHBoxLayout() w = 36 b1 = PanelButton(pixmap=qt_prefs.shape_icon_plain, parent=self, size=24) b1.setFixedWidth(w) b1.setCheckable(True) ctrl.ui.connect_element_to_action(b1, 'set_no_frame_node_shape') hlayout.addWidget(b1) b2 = PanelButton(pixmap=qt_prefs.shape_icon_scope, parent=self, size=24) b2.setFixedWidth(w) b2.setCheckable(True) ctrl.ui.connect_element_to_action(b2, 'set_scopebox_node_shape') hlayout.addWidget(b2) b3 = PanelButton(pixmap=qt_prefs.shape_icon_brackets, parent=self, size=24) b3.setFixedWidth(w) b3.setCheckable(True) ctrl.ui.connect_element_to_action(b3, 'set_bracketed_node_shape') hlayout.addWidget(b3) b4 = PanelButton(pixmap=qt_prefs.shape_icon_box, parent=self, size=24) b4.setFixedWidth(w) b4.setCheckable(True) ctrl.ui.connect_element_to_action(b4, 'set_box_node_shape') hlayout.addWidget(b4) b5 = PanelButton(pixmap=qt_prefs.shape_icon_card, parent=self, size=24) b5.setFixedWidth(w) b5.setCheckable(True) ctrl.ui.connect_element_to_action(b5, 'set_card_node_shape') hlayout.addWidget(b5) layout.addLayout(hlayout) #layout.setContentsMargins(0, 0, 0, 0) inner.setLayout(layout) self.watchlist = ['visualization'] self.preferred_size = inner.preferred_size self.setWidget(inner) inner.setAutoFillBackground(True) self.finish_init()