def createEditor(self, parent, option, index): ''' Creates a editor in the TreeView depending on type of the settings data. ''' item = self._itemFromIndex(index) if item.edit_type() == SettingsValueItem.EDIT_TYPE_AUTODETECT: if isinstance(item.value(), bool): box = QtGui.QCheckBox(parent) box.setFocusPolicy(QtCore.Qt.StrongFocus) box.setAutoFillBackground(True) box.stateChanged.connect(self.edit_finished) return box elif isinstance(item.value(), int): box = QtGui.QSpinBox(parent) box.setValue(item.value()) if not item.value_min() is None: box.setMinimum(item.value_min()) if not item.value_max() is None: box.setMaximum(item.value_max()) return box elif item.edit_type() == SettingsValueItem.EDIT_TYPE_FOLDER: editor = PathEditor(item.value(), parent) editor.editing_finished_signal.connect(self.edit_finished) return editor return QtGui.QStyledItemDelegate.createEditor(self, parent, option, index)
def createFieldsFromValues(self, values, exclusive=False): self.setUpdatesEnabled(False) try: if isinstance(values, list): for v in values: checkbox = QtGui.QCheckBox(v) checkbox.toggled.connect(self._on_checkbox_toggled) checkbox.setObjectName(v) checkbox.setAutoExclusive(exclusive) self.layout().addRow(checkbox) finally: self.setUpdatesEnabled(True)
def __init__(self, topic_name, attributes, array_index, publisher, parent, label_text=None): super(ValueWidget, self).__init__(topic_name, publisher, parent=parent) self._parent = parent self._attributes = attributes self._array_index = array_index self._text = ez_model.make_text(topic_name, attributes, array_index) self._horizontal_layout = QtGui.QHBoxLayout() if label_text is None: self._topic_label = QtGui.QLabel(self._text) else: self._topic_label = QtGui.QLabel(label_text) self.close_button = QtGui.QPushButton() self.close_button.setMaximumWidth(30) self.close_button.setIcon(self.style().standardIcon( QtGui.QStyle.SP_TitleBarCloseButton)) self.up_button = QtGui.QPushButton() self.up_button.setIcon(self.style().standardIcon( QtGui.QStyle.SP_ArrowUp)) self.up_button.setMaximumWidth(30) self.down_button = QtGui.QPushButton() self.down_button.setMaximumWidth(30) self.down_button.setIcon(self.style().standardIcon( QtGui.QStyle.SP_ArrowDown)) repeat_label = QtGui.QLabel('repeat') self._repeat_box = QtGui.QCheckBox() self._repeat_box.stateChanged.connect(self.repeat_changed) self._repeat_box.setChecked(publisher.is_repeating()) self._horizontal_layout.addWidget(self._topic_label) self._horizontal_layout.addWidget(self.close_button) self._horizontal_layout.addWidget(self.up_button) self._horizontal_layout.addWidget(self.down_button) self._horizontal_layout.addWidget(repeat_label) self._horizontal_layout.addWidget(self._repeat_box) if self._array_index is not None: self.add_button = QtGui.QPushButton('+') self.add_button.setMaximumWidth(30) self._horizontal_layout.addWidget(self.add_button) else: self.add_button = None self.close_button.clicked.connect( lambda x: self._parent.close_slider(self)) self.up_button.clicked.connect( lambda x: self._parent.move_up_widget(self)) self.down_button.clicked.connect( lambda x: self._parent.move_down_widget(self)) self.setup_ui(self._text)
def __init__(self, parent=None): QtGui.QDialog.__init__(self, parent) self.setObjectName('FindDialog') self.setWindowTitle('Search') self.verticalLayout = QtGui.QVBoxLayout(self) self.verticalLayout.setObjectName("verticalLayout") self.content = QtGui.QWidget(self) self.contentLayout = QtGui.QFormLayout(self.content) # self.contentLayout.setFieldGrowthPolicy(QtGui.QFormLayout.AllNonFixedFieldsGrow) # self.contentLayout.setVerticalSpacing(0) self.contentLayout.setContentsMargins(0, 0, 0, 0) self.verticalLayout.addWidget(self.content) label = QtGui.QLabel("Find:", self.content) self.search_field = QtGui.QLineEdit(self.content) self.contentLayout.addRow(label, self.search_field) replace_label = QtGui.QLabel("Replace:", self.content) self.replace_field = QtGui.QLineEdit(self.content) self.contentLayout.addRow(replace_label, self.replace_field) self.recursive = QtGui.QCheckBox("recursive search") self.contentLayout.addRow(self.recursive) self.result_label = QtGui.QLabel("") self.verticalLayout.addWidget(self.result_label) self.found_files = QtGui.QListWidget() self.found_files.setVisible(False) self.found_files.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) self.verticalLayout.addWidget(self.found_files) self.buttonBox = QtGui.QDialogButtonBox(self) self.find_button = QtGui.QPushButton(self.tr("&Find")) self.find_button.setDefault(True) self.buttonBox.addButton(self.find_button, QtGui.QDialogButtonBox.ActionRole) self.replace_button = QtGui.QPushButton(self.tr("&Replace/Find")) self.buttonBox.addButton(self.replace_button, QtGui.QDialogButtonBox.ActionRole) self.buttonBox.addButton(QtGui.QDialogButtonBox.Close) self.buttonBox.setOrientation(QtCore.Qt.Horizontal) self.buttonBox.setObjectName("buttonBox") self.verticalLayout.addWidget(self.buttonBox) # QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), self.accept) QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.reject) QtCore.QMetaObject.connectSlotsByName(self) self.search_text = '' self.search_pos = QtGui.QTextCursor()
def create_controls(self): """ Create UI controls. """ vbox = QtGui.QVBoxLayout() form = QtGui.QFormLayout() self.num_sigma = QtGui.QDoubleSpinBox() self.num_sigma.setValue(1.0) self.num_sigma.setMinimum(0.0) self.num_sigma.setSingleStep(0.1) self.num_sigma.setMaximum(1e3) self.num_sigma.setDecimals(2) form.addRow(tr("Sigma:"), self.num_sigma) vbox.addLayout(form) self.chk_preview = QtGui.QCheckBox(tr("Preview")) self.chk_preview.setCheckable(True) self.chk_preview.setChecked(False) vbox.addWidget(self.chk_preview) self.chk_preview.toggled[bool].connect(self.set_preview) self.gbo_output = QtGui.QGroupBox(tr("Output")) self.opt_new = QtGui.QRadioButton(tr("New signal")) self.opt_replace = QtGui.QRadioButton(tr("In place")) self.opt_new.setChecked(True) gbo_vbox2 = QtGui.QVBoxLayout() gbo_vbox2.addWidget(self.opt_new) gbo_vbox2.addWidget(self.opt_replace) self.gbo_output.setLayout(gbo_vbox2) vbox.addWidget(self.gbo_output) self.btn_ok = QtGui.QPushButton(tr("&OK")) self.btn_ok.setDefault(True) self.btn_ok.clicked.connect(self.accept) self.btn_cancel = QtGui.QPushButton(tr("&Cancel")) self.btn_cancel.clicked.connect(self.reject) hbox = QtGui.QHBoxLayout() hbox.addWidget(self.btn_ok) hbox.addWidget(self.btn_cancel) vbox.addLayout(hbox) vbox.addStretch(1) self.setLayout(vbox)
def createTypedWidget(self, parent): result = None if self.isPrimitiveType(): value = self._value if 'bool' in self.baseType(): result = QtGui.QCheckBox(parent=parent) result.setObjectName(self.name()) if not isinstance(value, bool): value = str2bool(value[0] if isinstance(value, list) else value) self._value_org = value result.setChecked(value) else: result = MyComboBox(parent=parent) result.setObjectName(self.name()) result.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)) result.setEditable(True) result.remove_item_signal.connect(self.removeCachedValue) items = [] if isinstance(value, list): if self.isArrayType(): items.append(','.join([str(val) for val in value])) else: items[len(items):] = value else: if not value is None and value: items.append(unicode(value) if not isinstance(value, Binary) else '{binary data!!! updates will be ignored!!!}') elif self.isTimeType(): items.append('now') self._value_org = items[0] if items else '' result.addItems(items) else: if self.isArrayType(): result = ArrayBox(self.name(), self._type, parent=parent) else: result = GroupBox(self.name(), self._type, parent=parent) return result
def __init__(self, topic, msg_type, show_only_rate=False, masteruri=None, use_ssh=False, parent=None): ''' Creates an input dialog. @param topic: the name of the topic @type topic: C{str} @param msg_type: the type of the topic @type msg_type: C{str} @raise Exception: if no topic class was found for the given type ''' QtGui.QDialog.__init__(self, parent=parent) self._masteruri = masteruri masteruri_str = '' if masteruri is None else '[%s]' % masteruri self.setObjectName(' - '.join(['EchoDialog', topic, masteruri_str])) self.setAttribute(QtCore.Qt.WA_DeleteOnClose, True) self.setWindowFlags(QtCore.Qt.Window) self.setWindowTitle('%s %s %s' % ('Echo --- ' if not show_only_rate else 'Hz --- ', topic, masteruri_str)) self.resize(728, 512) self.verticalLayout = QtGui.QVBoxLayout(self) self.verticalLayout.setObjectName("verticalLayout") self.verticalLayout.setContentsMargins(1, 1, 1, 1) self.mIcon = QtGui.QIcon(":/icons/crystal_clear_prop_run_echo.png") self.setWindowIcon(self.mIcon) self.topic = topic self.show_only_rate = show_only_rate self.lock = threading.RLock() self.last_printed_count = 0 self.msg_t0 = -1. self.msg_tn = 0 self.times = [] self.message_count = 0 self._rate_message = '' self._scrapped_msgs = 0 self._scrapped_msgs_sl = 0 self._last_received_ts = 0 self.receiving_hz = self.MESSAGE_HZ_LIMIT self.line_limit = self.MESSAGE_LINE_LIMIT self.field_filter_fn = None options = QtGui.QWidget(self) if not show_only_rate: hLayout = QtGui.QHBoxLayout(options) hLayout.setContentsMargins(1, 1, 1, 1) self.no_str_checkbox = no_str_checkbox = QtGui.QCheckBox( 'Hide strings') no_str_checkbox.toggled.connect(self.on_no_str_checkbox_toggled) hLayout.addWidget(no_str_checkbox) self.no_arr_checkbox = no_arr_checkbox = QtGui.QCheckBox( 'Hide arrays') no_arr_checkbox.toggled.connect(self.on_no_arr_checkbox_toggled) hLayout.addWidget(no_arr_checkbox) self.combobox_reduce_ch = QtGui.QComboBox(self) self.combobox_reduce_ch.addItems( [str(self.MESSAGE_LINE_LIMIT), '0', '80', '256', '1024']) self.combobox_reduce_ch.activated[str].connect( self.combobox_reduce_ch_activated) self.combobox_reduce_ch.setEditable(True) self.combobox_reduce_ch.setToolTip( "Set maximum line width. 0 disables the limit.") hLayout.addWidget(self.combobox_reduce_ch) # reduce_ch_label = QtGui.QLabel('ch', self) # hLayout.addWidget(reduce_ch_label) # add spacer spacerItem = QtGui.QSpacerItem(515, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) hLayout.addItem(spacerItem) # add combobox for displaying frequency of messages self.combobox_displ_hz = QtGui.QComboBox(self) self.combobox_displ_hz.addItems([ str(self.MESSAGE_HZ_LIMIT), '0', '0.1', '1', '50', '100', '1000' ]) self.combobox_displ_hz.activated[str].connect( self.on_combobox_hz_activated) self.combobox_displ_hz.setEditable(True) hLayout.addWidget(self.combobox_displ_hz) displ_hz_label = QtGui.QLabel('Hz', self) hLayout.addWidget(displ_hz_label) # add combobox for count of displayed messages self.combobox_msgs_count = QtGui.QComboBox(self) self.combobox_msgs_count.addItems( [str(self.MAX_DISPLAY_MSGS), '0', '50', '100']) self.combobox_msgs_count.activated[str].connect( self.on_combobox_count_activated) self.combobox_msgs_count.setEditable(True) self.combobox_msgs_count.setToolTip( "Set maximum displayed message count. 0 disables the limit.") hLayout.addWidget(self.combobox_msgs_count) displ_count_label = QtGui.QLabel('#', self) hLayout.addWidget(displ_count_label) # add topic control button for unsubscribe and subscribe self.topic_control_button = QtGui.QToolButton(self) self.topic_control_button.setText('stop') self.topic_control_button.setIcon( QtGui.QIcon(':/icons/deleket_deviantart_stop.png')) self.topic_control_button.clicked.connect( self.on_topic_control_btn_clicked) hLayout.addWidget(self.topic_control_button) # add clear button clearButton = QtGui.QToolButton(self) clearButton.setText('clear') clearButton.clicked.connect(self.on_clear_btn_clicked) hLayout.addWidget(clearButton) self.verticalLayout.addWidget(options) self.display = QtGui.QTextBrowser(self) self.display.setReadOnly(True) self.verticalLayout.addWidget(self.display) self.display.document().setMaximumBlockCount(500) self.max_displayed_msgs = self.MAX_DISPLAY_MSGS self._blocks_in_msg = None self.display.setOpenLinks(False) self.display.anchorClicked.connect(self._on_display_anchorClicked) self.status_label = QtGui.QLabel('0 messages', self) self.verticalLayout.addWidget(self.status_label) # subscribe to the topic errmsg = '' try: self.__msg_class = message.get_message_class(msg_type) if not self.__msg_class: errmsg = "Cannot load message class for [%s]. Did you build messages?" % msg_type # raise Exception("Cannot load message class for [%s]. Did you build messages?"%msg_type) except Exception as e: self.__msg_class = None errmsg = "Cannot load message class for [%s]. Did you build messagest?\nError: %s" % ( msg_type, e) # raise Exception("Cannot load message class for [%s]. Did you build messagest?\nError: %s"%(msg_type, e)) # variables for Subscriber self.msg_signal.connect(self._append_message) self.sub = None # vairables for SSH connection self.ssh_output_file = None self.ssh_error_file = None self.ssh_input_file = None self.text_signal.connect(self._append_text) self.text_hz_signal.connect(self._append_text_hz) self._current_msg = '' self._current_errmsg = '' self.text_error_signal.connect(self._append_error_text) # decide, which connection to open if use_ssh: self.__msg_class = None self._on_display_anchorClicked(QtCore.QUrl(self._masteruri)) elif self.__msg_class is None: errtxt = '<pre style="color:red; font-family:Fixedsys,Courier,monospace; padding:10px;">\n%s</pre>' % ( errmsg) self.display.setText('<a href="%s">open using SSH</a>' % (masteruri)) self.display.append(errtxt) else: self.sub = rospy.Subscriber(self.topic, self.__msg_class, self._msg_handle) self.print_hz_timer = QtCore.QTimer() self.print_hz_timer.timeout.connect(self._on_calc_hz) self.print_hz_timer.start(1000)
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)