当前位置: 首页>>代码示例>>Python>>正文


Python QGridLayout.addLayout方法代码示例

本文整理汇总了Python中guidata.qt.QtGui.QGridLayout.addLayout方法的典型用法代码示例。如果您正苦于以下问题:Python QGridLayout.addLayout方法的具体用法?Python QGridLayout.addLayout怎么用?Python QGridLayout.addLayout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在guidata.qt.QtGui.QGridLayout的用法示例。


在下文中一共展示了QGridLayout.addLayout方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: FloatArrayWidget

# 需要导入模块: from guidata.qt.QtGui import QGridLayout [as 别名]
# 或者: from guidata.qt.QtGui.QGridLayout import addLayout [as 别名]
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)
开发者ID:artillan,项目名称:guidata,代码行数:99,代码来源:qtitemwidgets.py


注:本文中的guidata.qt.QtGui.QGridLayout.addLayout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。