def __init__(self, item, parent_layout): super(TabGroupWidget, self).__init__(item, parent_layout) self.tabs = QTabWidget() items = item.item.group self.widgets = [] for item in items: if item.get_prop_value("display", parent_layout.instance, "hide", False): continue item.set_prop("display", embedded=True) widget = parent_layout.build_widget(item) frame = QFrame() label = widget.item.get_prop_value("display", "label") icon = widget.item.get_prop_value("display", "icon", None) if icon is not None: self.tabs.addTab(frame, get_icon(icon), label) else: self.tabs.addTab(frame, label) layout = QGridLayout() layout.setAlignment(Qt.AlignTop) frame.setLayout(layout) widget.place_on_grid(layout, 0, 0, 1) try: widget.get() except Exception: print("Error building item :", item.item._name) raise self.widgets.append(widget)
def setup_instance(self, instance): """Construct main layout""" grid = QGridLayout() grid.setAlignment(Qt.AlignTop) self.layout.addLayout(grid) self.edit_layout.append( self.layout_factory( instance, grid) )
class FloatArrayWidget(AbstractDataSetWidget): """ FloatArrayItem widget """ def __init__(self, item, parent_layout): super(FloatArrayWidget, self).__init__(item, parent_layout) _label = item.get_prop_value("display", "label") self.groupbox = self.group = QGroupBox(_label) self.layout = QGridLayout() self.layout.setAlignment(Qt.AlignLeft) self.groupbox.setLayout(self.layout) self.first_line, self.dim_label = get_image_layout("shape.png", _("Number of rows x Number of columns")) edit_button = QPushButton(get_icon("arredit.png"), "") edit_button.setToolTip(_("Edit array contents")) edit_button.setMaximumWidth(32) self.first_line.addWidget(edit_button) self.layout.addLayout(self.first_line, 0, 0) self.min_line, self.min_label = get_image_layout("min.png", _("Smallest element in array")) self.layout.addLayout(self.min_line, 1, 0) self.max_line, self.max_label = get_image_layout("max.png", _("Largest element in array")) self.layout.addLayout(self.max_line, 2, 0) edit_button.clicked.connect(self.edit_array) self.arr = None # le tableau si il a été modifié self.instance = None def edit_array(self): """Open an array editor dialog""" parent = self.parent_layout.parent label = self.item.get_prop_value("display", "label") try: # Spyder 3 from spyderlib.widgets.variableexplorer import arrayeditor except ImportError: # Spyder 2 from spyderlib.widgets import arrayeditor editor = arrayeditor.ArrayEditor(parent) if editor.setup_and_check(self.arr, title=label): if editor.exec_(): self.update(self.arr) def get(self): """Override AbstractDataSetWidget method""" self.arr = numpy.array(self.item.get(), copy=False) if self.item.get_prop_value("display", "transpose"): self.arr = self.arr.T self.update(self.arr) def update(self, arr): """Override AbstractDataSetWidget method""" shape = arr.shape if len(shape) == 1: shape = (1,) + shape dim = " x ".join( [ str(d) for d in shape ]) self.dim_label.setText(dim) format = self.item.get_prop_value("display", "format") minmax = self.item.get_prop_value("display", "minmax") try: if minmax == "all": mint = format % arr.min() maxt = format % arr.max() elif minmax == "columns": mint = ", ".join([format % arr[r,:].min() for r in range(arr.shape[0])]) maxt = ", ".join([format % arr[r,:].max() for r in range(arr.shape[0])]) else: mint = ", ".join([format % arr[:, r].min() for r in range(arr.shape[1])]) maxt = ", ".join([format % arr[:, r].max() for r in range(arr.shape[1])]) except (TypeError, IndexError): mint, maxt = "-", "-" self.min_label.setText(mint) self.max_label.setText(maxt) def set(self): """Override AbstractDataSetWidget method""" if self.item.get_prop_value("display", "transpose"): value = self.value().T else: value = self.value() self.item.set(value) def value(self): return self.arr def place_on_grid(self, layout, row, label_column, widget_column, row_span=1, column_span=1): """Override AbstractDataSetWidget method""" layout.addWidget(self.group, row, label_column, row_span, column_span+1)