def minimumSize(self): size = QtCore.QSize() for item in self._items: size = size.expandedTo(item.minimumSize()) size += QtCore.QSize(2 * self.margin(), 2 * self.margin()) return size
def updateCapabilities(self, masteruri, cfg_name, description): ''' Updates the capabilities view. @param masteruri: the ROS master URI of updated ROS master. @type masteruri: C{str} @param cfg_name: The name of the node provided the capabilities description. @type cfg_name: C{str} @param description: The capabilities description object. @type description: L{default_cfg_fkie.Description} ''' # if it is a new masteruri add a new column robot_index = self._robotHeader.index(masteruri) robot_name = description.robot_name if description.robot_name else nm.nameres().mastername(masteruri) if robot_index == -1: # append a new robot robot_index = self._robotHeader.insertSortedItem(masteruri, robot_name) self.insertColumn(robot_index) # robot_index = self.columnCount()-1 # self._robotHeader.insertItem(robot_index) self._robotHeader.setDescription(robot_index, cfg_name, masteruri, robot_name, description.robot_type, description.robot_descr.replace("\\n ", "\n").decode(sys.getfilesystemencoding()), description.robot_images) item = QtGui.QTableWidgetItem() item.setSizeHint(QtCore.QSize(96,96)) self.setHorizontalHeaderItem(robot_index, item) self.horizontalHeaderItem(robot_index).setText(robot_name) else: #update self._robotHeader.setDescription(robot_index, cfg_name, masteruri, robot_name, description.robot_type, description.robot_descr.replace("\\n ", "\n").decode(sys.getfilesystemencoding()), description.robot_images) #set the capabilities for c in description.capabilities: cap_index = self._capabilityHeader.index(c.name.decode(sys.getfilesystemencoding())) if cap_index == -1: # append a new capability cap_index = self._capabilityHeader.insertSortedItem(c.name.decode(sys.getfilesystemencoding()), c.name.decode(sys.getfilesystemencoding())) self.insertRow(cap_index) self.setRowHeight(cap_index, 96) self._capabilityHeader.setDescription(cap_index, cfg_name, c.name.decode(sys.getfilesystemencoding()), c.name.decode(sys.getfilesystemencoding()), c.type, c.description.replace("\\n ", "\n").decode(sys.getfilesystemencoding()), c.images) item = QtGui.QTableWidgetItem() item.setSizeHint(QtCore.QSize(96,96)) self.setVerticalHeaderItem(cap_index, item) self.verticalHeaderItem(cap_index).setText(c.name.decode(sys.getfilesystemencoding())) # add the capability control widget controlWidget = CapabilityControlWidget(masteruri, cfg_name, c.namespace, c.nodes) controlWidget.start_nodes_signal.connect(self._start_nodes) controlWidget.stop_nodes_signal.connect(self._stop_nodes) self.setCellWidget(cap_index, robot_index, controlWidget) self._capabilityHeader.controlWidget.insert(cap_index, controlWidget) else: self._capabilityHeader.updateDescription(cap_index, cfg_name, c.name.decode(sys.getfilesystemencoding()), c.name.decode(sys.getfilesystemencoding()), c.type, c.description.replace("\\n ", "\n").decode(sys.getfilesystemencoding()), c.images) self._capabilityHeader.controlWidget[cap_index].updateNodes(cfg_name, c.namespace, c.nodes)
def sizeHint(self, option, index): ''' Determines and returns the size of the text after the format. @see: U{http://www.pyside.org/docs/pyside/PySide/QtGui/QAbstractItemDelegate.html#PySide.QtGui.QAbstractItemDelegate} ''' options = QtGui.QStyleOptionViewItemV4(option) self.initStyleOption(options, index) return QtCore.QSize(options.rect.width(), 25)
def minimumSizeHint(self): s = QtCore.QSize() shfr = self.sizeHintForRow(0) if shfr < 0: shfr = 12 h = shfr * self.count() + 2 * self.frameWidth() s.setHeight(h) s.setWidth(super(AxesListWidget, self).minimumSizeHint().width()) return s
def __init__(self, type, parent=None): super(AxesListWidget, self).__init__(parent) self.setIconSize(QtCore.QSize(124, 124)) self.setDragDropMode(QtGui.QAbstractItemView.DragDrop) self.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection) self.setAcceptDrops(True) m = self.model() m.rowsInserted.connect(self._on_rows_inserted) m.rowsMoved.connect(self._on_rows_moved)
def readSettings(self): if nm.settings().store_geometry: settings = nm.settings().qsettings(nm.settings().CFG_GUI_FILE) settings.beginGroup("editor") maximized = settings.value("maximized", 'false') == 'true' if maximized: self.showMaximized() else: self.resize(settings.value("size", QtCore.QSize(800,640))) self.move(settings.value("pos", QtCore.QPoint(0, 0))) settings.endGroup()
def sizeHint(self, option, index): ''' Determines and returns the size of the text after the format. @see: U{http://www.pyside.org/docs/pyside/PySide/QtGui/QAbstractItemDelegate.html#PySide.QtGui.QAbstractItemDelegate} ''' options = QtGui.QStyleOptionViewItemV4(option) self.initStyleOption(options, index) doc = QtGui.QTextDocument() doc.setHtml(options.text) doc.setTextWidth(options.rect.width()) metric = QtGui.QFontMetrics(doc.defaultFont()) return QtCore.QSize(doc.idealWidth(), metric.height() + 4)
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, path, parent=None): QtGui.QWidget.__init__(self, parent) self.path = path self._layout = QtGui.QHBoxLayout(self) self._layout.setContentsMargins(0, 0, 0, 0) self._layout.setSpacing(0) self._button = QtGui.QPushButton('...') self._button.setMaximumSize(QtCore.QSize(24, 20)) self._button.clicked.connect(self._on_path_select_clicked) self._layout.addWidget(self._button) self._lineedit = QtGui.QLineEdit(path) self._lineedit.returnPressed.connect(self._on_editing_finished) self._layout.addWidget(self._lineedit) self.setLayout(self._layout) self.setFocusProxy(self._button) self.setAutoFillBackground(True)
def __init__(self, name, value, parent=None): ''' Initialize the item object. @param name: the name of the parameter @type name: C{str} @param value: the value of the parameter @type value: C{str} ''' QtGui.QStandardItem.__init__( self, unicode(value) if not isinstance(value, Binary) else str(value)) self._name = name '''@ivar: the name of parameter ''' self._value = value '''@ivar: the value of the parameter ''' if isinstance(value, (str, unicode)) and value.find('\n') > -1: self.setSizeHint(QtCore.QSize(-1, 45))
def __init__(self, plugin): super(ControllerManagerWidget, self).__init__() self._plugin = plugin self.setWindowTitle('Controller Manager') # create layouts vlayout_outer = QtGui.QVBoxLayout(self) vlayout_outer.setObjectName('vert_layout_outer') hlayout_top = QtGui.QHBoxLayout(self) hlayout_top.setObjectName('hori_layout_top') vlayout_outer.addLayout(hlayout_top) # create top bar # controller manager namespace combo box & label cm_ns_label = QtGui.QLabel(self) cm_ns_label.setObjectName('cm_ns_label') cm_ns_label.setText('CM Namespace:') fixed_policy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed) cm_ns_label.setSizePolicy(fixed_policy) hlayout_top.addWidget(cm_ns_label) cm_namespace_combo = QtGui.QComboBox(self) cm_namespace_combo.setObjectName('cm_namespace_combo') hlayout_top.addWidget(cm_namespace_combo) self.cm_namespace_combo = cm_namespace_combo # load controller combo box & label load_ctrl_label = QtGui.QLabel(self) load_ctrl_label.setObjectName('load_ctrl_label') load_ctrl_label.setText('Load Controller:') fixed_policy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed) load_ctrl_label.setSizePolicy(fixed_policy) hlayout_top.addWidget(load_ctrl_label) load_ctrl_combo = QtGui.QComboBox(self) load_ctrl_combo.setObjectName('load_ctrl_combo') load_ctrl_size_policy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed) load_ctrl_combo.setSizePolicy(load_ctrl_size_policy) hlayout_top.addWidget(load_ctrl_combo) self.load_ctrl_combo = load_ctrl_combo # load control button load_ctrl_button = QtGui.QPushButton(self) load_ctrl_button.setObjectName('load_ctrl_button') button_size_policy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) button_size_policy.setHorizontalStretch(0) button_size_policy.setVerticalStretch(0) button_size_policy.setHeightForWidth( load_ctrl_button.sizePolicy().hasHeightForWidth()) load_ctrl_button.setSizePolicy(button_size_policy) load_ctrl_button.setBaseSize(QtCore.QSize(30, 30)) load_ctrl_button.setIcon(QIcon.fromTheme('list-add')) load_ctrl_button.setIconSize(QtCore.QSize(20, 20)) load_ctrl_button.clicked.connect(self.load_cur_ctrl) hlayout_top.addWidget(load_ctrl_button) # start control button start_ctrl_button = QtGui.QPushButton(self) start_ctrl_button.setObjectName('start_ctrl_button') button_size_policy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) button_size_policy.setHorizontalStretch(0) button_size_policy.setVerticalStretch(0) button_size_policy.setHeightForWidth( start_ctrl_button.sizePolicy().hasHeightForWidth()) start_ctrl_button.setSizePolicy(button_size_policy) start_ctrl_button.setBaseSize(QtCore.QSize(30, 30)) start_ctrl_button.setIcon(QIcon.fromTheme('media-playback-start')) start_ctrl_button.setIconSize(QtCore.QSize(20, 20)) start_ctrl_button.clicked.connect(self.start_cur_ctrl) hlayout_top.addWidget(start_ctrl_button) # create tree/list widget ctrl_list_tree_widget = QtGui.QTreeWidget(self) ctrl_list_tree_widget.setObjectName('ctrl_list_tree_widget') self.ctrl_list_tree_widget = ctrl_list_tree_widget ctrl_list_tree_widget.setColumnCount(len(self._column_names)) ctrl_list_tree_widget.setHeaderLabels(self._column_names_pretty) ctrl_list_tree_widget.sortByColumn(0, Qt.AscendingOrder) ctrl_list_tree_widget.setContextMenuPolicy(Qt.CustomContextMenu) ctrl_list_tree_widget.customContextMenuRequested.connect( self.on_ctrl_list_tree_widget_customContextMenuRequested) vlayout_outer.addWidget(ctrl_list_tree_widget) header = self.ctrl_list_tree_widget.header() header.setResizeMode(QHeaderView.ResizeToContents) header.customContextMenuRequested.connect( self.handle_header_view_customContextMenuRequested) header.setContextMenuPolicy(Qt.CustomContextMenu) self._ctrlers = {} self._column_index = {} for column_name in self._column_names: self._column_index[column_name] = len(self._column_index) # controller manager services self.list_types = {} self.list_ctrlers = {} self.load_ctrler = {} self.unload_ctrler = {} self.switch_ctrlers = {} self.ctrlman_ns_cur = '' self.loadable_params = {} # init and start update timer self._timer_refresh_ctrlers = QTimer(self) self._timer_refresh_ctrlers.timeout.connect(self._refresh_ctrlers_cb)
def value(self, value): self._value = value self.setText( unicode(value) if not isinstance(value, Binary) else str(value)) if isinstance(value, (str, unicode)) and value.find('\n') > -1: self.setSizeHint(QtCore.QSize(-1, 45))