def __init__(self, masteruri, cfg, ns, nodes, parent=None): QtGui.QFrame.__init__(self, parent) self._masteruri = masteruri self._nodes = {cfg: {ns: nodes}} frame_layout = QtGui.QVBoxLayout(self) frame_layout.setContentsMargins(0, 0, 0, 0) # create frame for warning label self.warning_frame = warning_frame = QtGui.QFrame() warning_layout = QtGui.QHBoxLayout(warning_frame) warning_layout.setContentsMargins(0, 0, 0, 0) warning_layout.addItem( QtGui.QSpacerItem(0, 0, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)) self.warning_label = QtGui.QLabel() icon = QtGui.QIcon(':/icons/crystal_clear_warning.png') self.warning_label.setPixmap(icon.pixmap(QtCore.QSize(40, 40))) self.warning_label.setToolTip( 'Multiple configuration for same node found!\nA first one will be selected for the start a node!' ) warning_layout.addWidget(self.warning_label) warning_layout.addItem( QtGui.QSpacerItem(0, 0, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)) frame_layout.addItem( QtGui.QSpacerItem(0, 0, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)) frame_layout.addWidget(warning_frame) # create frame for start/stop buttons buttons_frame = QtGui.QFrame() buttons_layout = QtGui.QHBoxLayout(buttons_frame) buttons_layout.setContentsMargins(0, 0, 0, 0) buttons_layout.addItem(QtGui.QSpacerItem(20, 20)) self.on_button = QtGui.QPushButton() self.on_button.setFlat(False) self.on_button.setText("On") self.on_button.clicked.connect(self.on_on_clicked) buttons_layout.addWidget(self.on_button) self.off_button = QtGui.QPushButton() self.off_button.setFlat(True) self.off_button.setText("Off") self.off_button.clicked.connect(self.on_off_clicked) buttons_layout.addWidget(self.off_button) buttons_layout.addItem(QtGui.QSpacerItem(20, 20)) frame_layout.addWidget(buttons_frame) frame_layout.addItem( QtGui.QSpacerItem(0, 0, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)) self.warning_frame.setVisible(False)
def __init__(self, name, param_type, collapsible=True, parent=None): QtGui.QWidget.__init__(self, parent) self.setObjectName(name) self.name = name self.type = param_type self.params = [] self.collapsed = False self.parameter_description = None vLayout = QtGui.QVBoxLayout() vLayout.setSpacing(0) self.options_layout = QtGui.QHBoxLayout() self.param_widget = QtGui.QFrame() self.name_label = QtGui.QLabel(name) font = self.name_label.font() font.setBold(True) self.name_label.setFont(font) self.type_label = QtGui.QLabel(''.join([' (', param_type, ')'])) if collapsible: self.hide_button = QtGui.QPushButton('-') self.hide_button.setFlat(True) self.hide_button.setMaximumSize(20,20) self.hide_button.clicked.connect(self._on_hide_clicked) self.options_layout.addWidget(self.hide_button) self.options_layout.addWidget(self.name_label) self.options_layout.addWidget(self.type_label) self.options_layout.addStretch() vLayout.addLayout(self.options_layout) self.param_widget.setFrameShape(QtGui.QFrame.Box) self.param_widget.setFrameShadow(QtGui.QFrame.Raised) boxLayout = QtGui.QFormLayout() boxLayout.setVerticalSpacing(0) self.param_widget.setLayout(boxLayout) vLayout.addWidget(self.param_widget) self.setLayout(vLayout) if param_type in ['std_msgs/Header']: self.setCollapsed(True)
def __createDistanceSlider(self, label, distance, callback): """Create a slider widget to control the distance from the selected node. * label -- the label for the slider * distance -- the default distance value * callback -- the function to call when the slider is changed """ frame = QtGui.QFrame() layout = QtGui.QHBoxLayout() frame.setLayout(layout) # Create a main label for the slider label = QtGui.QLabel("%s:" % label) layout.addWidget(label) # Create the slider slider = QtGui.QSlider(QtCore.Qt.Horizontal) slider.setMinimum(0) slider.setMaximum(self.__maxDistance) slider.setValue(distance) slider.setTickPosition(QtGui.QSlider.TicksBelow) slider.setTickInterval(1) # Every 1 level slider.valueChanged.connect(callback) layout.addWidget(slider) # Create a label to display the value label = QtGui.QLabel("%s" % distance) layout.addWidget(label) # Add a button to reset the slider to its original value resetButton = QtGui.QPushButton("Reset") resetButton.clicked.connect(self.__getClickWrapper(slider, distance)) layout.addWidget(resetButton) self.__layout.addWidget(frame) return slider, label
def __createNodeListWidget(self): """Create a list widget to display all possible nodes.""" frame = QtGui.QFrame() layout = QtGui.QVBoxLayout() frame.setLayout(layout) # Add a label label = QtGui.QLabel("Nodes:") layout.addWidget(label) # Add the list of known nodes self.__nodeListWidget = QtGui.QListWidget() layout.addWidget(self.__nodeListWidget) # Display nodes in alphabetical order sortedNodes = sorted(self.__graph.getNodes()) for node in sortedNodes: self.__nodeListWidget.addItem(node) # Update the graph with the currently selected widget self.__nodeListWidget.currentItemChanged.connect(self.__onNodeClicked) self.__layout.addWidget(frame)
def __init__(self, items=list(), buttons=QtGui.QDialogButtonBox.Cancel | QtGui.QDialogButtonBox.Ok, exclusive=False, preselect_all=False, title='', description='', icon='', parent=None, select_if_single=True): ''' Creates an input dialog. @param items: a list with strings @type items: C{list()} ''' QtGui.QDialog.__init__(self, parent=parent) self.setObjectName(' - '.join(['SelectDialog', str(items)])) self.verticalLayout = QtGui.QVBoxLayout(self) self.verticalLayout.setObjectName("verticalLayout") self.verticalLayout.setContentsMargins(1, 1, 1, 1) # add filter row self.filter_frame = QtGui.QFrame(self) filterLayout = QtGui.QHBoxLayout(self.filter_frame) filterLayout.setContentsMargins(1, 1, 1, 1) label = QtGui.QLabel("Filter:", self.filter_frame) self.filter_field = QtGui.QLineEdit(self.filter_frame) filterLayout.addWidget(label) filterLayout.addWidget(self.filter_field) self.filter_field.textChanged.connect(self._on_filter_changed) self.verticalLayout.addWidget(self.filter_frame) if description: self.description_frame = QtGui.QFrame(self) descriptionLayout = QtGui.QHBoxLayout(self.description_frame) # descriptionLayout.setContentsMargins(1, 1, 1, 1) if icon: self.icon_label = QtGui.QLabel(self.description_frame) self.icon_label.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) self.icon_label.setPixmap( QtGui.QPixmap(icon).scaled(30, 30, QtCore.Qt.KeepAspectRatio)) descriptionLayout.addWidget(self.icon_label) self.description_label = QtGui.QLabel(self.description_frame) self.description_label.setWordWrap(True) self.description_label.setText(description) descriptionLayout.addWidget(self.description_label) self.verticalLayout.addWidget(self.description_frame) # create area for the parameter self.scrollArea = scrollArea = QtGui.QScrollArea(self) self.scrollArea.setFocusPolicy(QtCore.Qt.NoFocus) scrollArea.setObjectName("scrollArea") scrollArea.setWidgetResizable(True) self.content = MainBox(self) scrollArea.setWidget(self.content) self.verticalLayout.addWidget(scrollArea) # add select all option if not exclusive: self._ignore_next_toggle = False options = QtGui.QWidget(self) hLayout = QtGui.QHBoxLayout(options) hLayout.setContentsMargins(1, 1, 1, 1) self.select_all_checkbox = QtGui.QCheckBox('all') self.select_all_checkbox.setTristate(True) self.select_all_checkbox.stateChanged.connect( self._on_select_all_checkbox_stateChanged) hLayout.addWidget(self.select_all_checkbox) self.content.toggled.connect(self._on_main_toggle) # add spacer spacerItem = QtGui.QSpacerItem(515, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) hLayout.addItem(spacerItem) self.verticalLayout.addWidget(options) # create buttons self.buttonBox = QtGui.QDialogButtonBox(self) self.buttonBox.setObjectName("buttonBox") self.buttonBox.setOrientation(QtCore.Qt.Horizontal) self.buttonBox.setStandardButtons(buttons) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) self.verticalLayout.addWidget(self.buttonBox) # set the input fields if items: self.content.createFieldsFromValues(items, exclusive) if (select_if_single and len(items) == 1) or preselect_all: self.select_all_checkbox.setCheckState(QtCore.Qt.Checked) if not items or len(items) < 11: self.filter_frame.setVisible(False)
def __init__(self, params=dict(), buttons=QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok, sidebar_var='', parent=None): ''' Creates an input dialog. @param params: a dictionary with parameter names and (type, values). The C{value}, can be a primitive value, a list with values or parameter dictionary to create groups. In this case the type is the name of the group. @type params: C{dict(str:(str, {value, [..], dict()}))} ''' QtGui.QDialog.__init__(self, parent=parent) self.setObjectName('ParameterDialog - %s'%str(params)) self.__current_path = nm.settings().current_dialog_path self.horizontalLayout = QtGui.QHBoxLayout(self) self.horizontalLayout.setObjectName("horizontalLayout") self.horizontalLayout.setContentsMargins(1, 1, 1, 1) self.verticalLayout = QtGui.QVBoxLayout() self.verticalLayout.setObjectName("verticalLayout") self.verticalLayout.setContentsMargins(1, 1, 1, 1) # add filter row self.filter_frame = QtGui.QFrame(self) filterLayout = QtGui.QHBoxLayout(self.filter_frame) filterLayout.setContentsMargins(1, 1, 1, 1) label = QtGui.QLabel("Filter:", self.filter_frame) self.filter_field = QtGui.QLineEdit(self.filter_frame) filterLayout.addWidget(label) filterLayout.addWidget(self.filter_field) self.filter_field.textChanged.connect(self._on_filter_changed) self.filter_visible = True self.verticalLayout.addWidget(self.filter_frame) # create area for the parameter self.scrollArea = scrollArea = ScrollArea(self); scrollArea.setObjectName("scrollArea") scrollArea.setWidgetResizable(True) self.content = MainBox('/', 'str', False, self) scrollArea.setWidget(self.content) self.verticalLayout.addWidget(scrollArea) # add info text field self.info_field = QtGui.QTextEdit(self) self.info_field.setVisible(False) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(255, 254, 242)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush) brush = QtGui.QBrush(QtGui.QColor(255, 254, 242)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush) brush = QtGui.QBrush(QtGui.QColor(244, 244, 244)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush) self.info_field.setPalette(palette) self.info_field.setFrameShadow(QtGui.QFrame.Plain) self.info_field.setReadOnly(True) self.info_field.setTextInteractionFlags(QtCore.Qt.LinksAccessibleByKeyboard|QtCore.Qt.LinksAccessibleByMouse|QtCore.Qt.TextBrowserInteraction|QtCore.Qt.TextSelectableByKeyboard|QtCore.Qt.TextSelectableByMouse) self.info_field.setObjectName("dialog_info_field") self.verticalLayout.addWidget(self.info_field) # create buttons self.buttonBox = QtGui.QDialogButtonBox(self) self.buttonBox.setObjectName("buttonBox") self.buttonBox.setOrientation(QtCore.Qt.Horizontal) self.buttonBox.setStandardButtons(buttons) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) self.verticalLayout.addWidget(self.buttonBox) self.horizontalLayout.addLayout(self.verticalLayout) # add side bar for checklist values = nm.history().cachedParamValues('/%s'%sidebar_var) self.sidebar_frame = QtGui.QFrame() self.sidebar_frame.setObjectName(sidebar_var) sidebarframe_verticalLayout = QtGui.QVBoxLayout(self.sidebar_frame) sidebarframe_verticalLayout.setObjectName("sidebarframe_verticalLayout") sidebarframe_verticalLayout.setContentsMargins(1, 1, 1, 1) self._sidebar_selected = 0 if len(values) > 1 and sidebar_var in params: self.horizontalLayout.addWidget(self.sidebar_frame) try: self.sidebar_default_val = params[sidebar_var][1] except: self.sidebar_default_val = '' values.sort() for v in values: checkbox = QtGui.QCheckBox(v) checkbox.stateChanged.connect(self._on_sidebar_stateChanged) self.sidebar_frame.layout().addWidget(checkbox) self.sidebar_frame.layout().addItem(QtGui.QSpacerItem(100, 20, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)) # set the input fields if params: self.content.createFieldFromValue(params) self.setInfoActive(False) if self.filter_frame.isVisible(): self.filter_field.setFocus() self.setMinimumSize(350,200)