def setup_and_check(self, data, title=''):
        """
        Setup DataFrameEditor:
        return False if data is not supported, True otherwise.
        Supported types for data are DataFrame, Series and Index.
        """
        self._selection_rec = False
        self._model = None

        self.layout = QGridLayout()
        self.layout.setSpacing(0)
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(self.layout)
        self.setWindowIcon(ima.icon('arredit'))
        if title:
            title = to_text_string(title) + " - %s" % data.__class__.__name__
        else:
            title = _("%s editor") % data.__class__.__name__
        if isinstance(data, Series):
            self.is_series = True
            data = data.to_frame()
        elif isinstance(data, Index):
            data = DataFrame(data)

        self.setWindowTitle(title)
        self.resize(600, 500)

        self.hscroll = QScrollBar(Qt.Horizontal)
        self.vscroll = QScrollBar(Qt.Vertical)

        # Create the view for the level
        self.create_table_level()

        # Create the view for the horizontal header
        self.create_table_header()

        # Create the view for the vertical index
        self.create_table_index()

        # Create the model and view of the data
        self.dataModel = DataFrameModel(data, parent=self)
        self.dataModel.dataChanged.connect(self.save_and_close_enable)
        self.create_data_table()

        self.layout.addWidget(self.hscroll, 2, 0, 1, 2)
        self.layout.addWidget(self.vscroll, 0, 2, 2, 1)

        # autosize columns on-demand
        self._autosized_cols = set()
        self._max_autosize_ms = None
        self.dataTable.installEventFilter(self)

        avg_width = self.fontMetrics().averageCharWidth()
        self.min_trunc = avg_width * 12  # Minimum size for columns
        self.max_width = avg_width * 64  # Maximum size for columns

        self.setLayout(self.layout)
        self.setMinimumSize(400, 300)
        # Make the dialog act as a window
        self.setWindowFlags(Qt.Window)
        btn_layout = QHBoxLayout()

        btn = QPushButton(_("Format"))
        # disable format button for int type
        btn_layout.addWidget(btn)
        btn.clicked.connect(self.change_format)
        btn = QPushButton(_('Resize'))
        btn_layout.addWidget(btn)
        btn.clicked.connect(self.resize_to_contents)

        bgcolor = QCheckBox(_('Background color'))
        bgcolor.setChecked(self.dataModel.bgcolor_enabled)
        bgcolor.setEnabled(self.dataModel.bgcolor_enabled)
        bgcolor.stateChanged.connect(self.change_bgcolor_enable)
        btn_layout.addWidget(bgcolor)

        self.bgcolor_global = QCheckBox(_('Column min/max'))
        self.bgcolor_global.setChecked(self.dataModel.colum_avg_enabled)
        self.bgcolor_global.setEnabled(not self.is_series and
                                       self.dataModel.bgcolor_enabled)
        self.bgcolor_global.stateChanged.connect(self.dataModel.colum_avg)
        btn_layout.addWidget(self.bgcolor_global)

        btn_layout.addStretch()

        self.btn_save_and_close = QPushButton(_('Save and Close'))
        self.btn_save_and_close.setDisabled(True)
        self.btn_save_and_close.clicked.connect(self.accept)
        btn_layout.addWidget(self.btn_save_and_close)

        self.btn_close = QPushButton(_('Close'))
        self.btn_close.setAutoDefault(True)
        self.btn_close.setDefault(True)
        self.btn_close.clicked.connect(self.reject)
        btn_layout.addWidget(self.btn_close)

        btn_layout.setContentsMargins(4, 4, 4, 4)
        self.layout.addLayout(btn_layout, 4, 0, 1, 2)
        self.setModel(self.dataModel)
        self.resizeColumnsToContents()

        return True
def setup_and_check ( self , data , title = '' ) : self . _selection_rec = False self . _model = None self . layout = QGridLayout ( ) self . layout . setSpacing ( 0 ) self . layout . setContentsMargins ( 0 , 0 , 0 , 0 ) self . setLayout ( self . layout ) self . setWindowIcon ( ima . icon ( 'arredit' ) ) if title : title = to_text_string ( title ) + " - %s" % data . __class__ . __name__ else : title = _ ( "%s editor" ) % data . __class__ . __name__ if isinstance ( data , Series ) : self . is_series = True data = data . to_frame ( ) elif isinstance ( data , Index ) : data = DataFrame ( data ) self . setWindowTitle ( title ) self . resize ( 600 , 500 ) self . hscroll = QScrollBar ( Qt . Horizontal ) self . vscroll = QScrollBar ( Qt . Vertical ) self . create_table_level ( ) self . create_table_header ( ) self . create_table_index ( ) self . dataModel = DataFrameModel ( data , parent = self ) self . dataModel . dataChanged . connect ( self . save_and_close_enable ) self . create_data_table ( ) self . layout . addWidget ( self . hscroll , 2 , 0 , 1 , 2 ) self . layout . addWidget ( self . vscroll , 0 , 2 , 2 , 1 ) self . _autosized_cols = set ( ) self . _max_autosize_ms = None self . dataTable . installEventFilter ( self ) avg_width = self . fontMetrics ( ) . averageCharWidth ( ) self . min_trunc = avg_width * 12 self . max_width = avg_width * 64 self . setLayout ( self . layout ) self . setMinimumSize ( 400 , 300 ) self . setWindowFlags ( Qt . Window ) btn_layout = QHBoxLayout ( ) btn = QPushButton ( _ ( "Format" ) ) btn_layout . addWidget ( btn ) btn . clicked . connect ( self . change_format ) btn = QPushButton ( _ ( 'Resize' ) ) btn_layout . addWidget ( btn ) btn . clicked . connect ( self . resize_to_contents ) bgcolor = QCheckBox ( _ ( 'Background color' ) ) bgcolor . setChecked ( self . dataModel . bgcolor_enabled ) bgcolor . setEnabled ( self . dataModel . bgcolor_enabled ) bgcolor . stateChanged . connect ( self . change_bgcolor_enable ) btn_layout . addWidget ( bgcolor ) self . bgcolor_global = QCheckBox ( _ ( 'Column min/max' ) ) self . bgcolor_global . setChecked ( self . dataModel . colum_avg_enabled ) self . bgcolor_global . setEnabled ( not self . is_series and self . dataModel . bgcolor_enabled ) self . bgcolor_global . stateChanged . connect ( self . dataModel . colum_avg ) btn_layout . addWidget ( self . bgcolor_global ) btn_layout . addStretch ( ) self . btn_save_and_close = QPushButton ( _ ( 'Save and Close' ) ) self . btn_save_and_close . setDisabled ( True ) self . btn_save_and_close . clicked . connect ( self . accept ) btn_layout . addWidget ( self . btn_save_and_close ) self . btn_close = QPushButton ( _ ( 'Close' ) ) self . btn_close . setAutoDefault ( True ) self . btn_close . setDefault ( True ) self . btn_close . clicked . connect ( self . reject ) btn_layout . addWidget ( self . btn_close ) btn_layout . setContentsMargins ( 4 , 4 , 4 , 4 ) self . layout . addLayout ( btn_layout , 4 , 0 , 1 , 2 ) self . setModel ( self . dataModel ) self . resizeColumnsToContents ( ) return True
Setup DataFrameEditor:
        return False if data is not supported, True otherwise.
        Supported types for data are DataFrame, Series and Index.