~ubuntu-branches/ubuntu/wily/spyder/wily

« back to all changes in this revision

Viewing changes to spyderlib/widgets/arrayeditor.py

  • Committer: Package Import Robot
  • Author(s): Benjamin Drung
  • Date: 2015-01-15 12:20:11 UTC
  • mfrom: (18.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20150115122011-cc7j5dhy2h9uo13m
Tags: 2.3.2+dfsg-1ubuntu1
Backport patch to support pylint3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
76
76
                     'bool': '%r',
77
77
                     }
78
78
 
 
79
LARGE_NROWS = 1e5
 
80
 
 
81
 
79
82
def is_float(dtype):
80
83
    """Return True if datatype dtype is a float kind"""
81
84
    return ('float' in dtype.name) or dtype.name in ['single', 'double']
93
96
 
94
97
class ArrayModel(QAbstractTableModel):
95
98
    """Array Editor Table Model"""
 
99
    
 
100
    ROWS_TO_LOAD = 500
 
101
    
96
102
    def __init__(self, data, format="%.3f", xlabels=None, ylabels=None,
97
103
                 readonly=False, parent=None):
98
104
        QAbstractTableModel.__init__(self)
135
141
            self.dhue = None
136
142
            self.bgcolor_enabled = False
137
143
        
 
144
        # To define paging when the number of rows is large
 
145
        self.total_rows = self._data.shape[0]
 
146
        if self.total_rows > LARGE_NROWS:
 
147
            self.rows_loaded = self.ROWS_TO_LOAD
 
148
        else:
 
149
            self.rows_loaded = self.total_rows
 
150
        
138
151
        
139
152
    def get_format(self):
140
153
        """Return current format"""
156
169
 
157
170
    def rowCount(self, qindex=QModelIndex()):
158
171
        """Array row number"""
159
 
        return self._data.shape[0]
 
172
        if self.total_rows <= self.rows_loaded:
 
173
            return self.total_rows
 
174
        else:
 
175
            return self.rows_loaded
 
176
    
 
177
    def canFetchMore(self, qindex=QModelIndex()):
 
178
        if self.total_rows > self.rows_loaded:
 
179
            return True
 
180
        else:
 
181
            return False
 
182
 
 
183
    def fetchMore(self, qindex=QModelIndex()):
 
184
        reminder = self.total_rows - self.rows_loaded
 
185
        items_to_fetch = min(reminder, self.ROWS_TO_LOAD)
 
186
        self.beginInsertRows(QModelIndex(), self.rows_loaded,
 
187
                             self.rows_loaded + items_to_fetch - 1)
 
188
        self.rows_loaded += items_to_fetch
 
189
        self.endInsertRows()
160
190
 
161
191
    def bgcolor(self, state):
162
192
        """Toggle backgroundcolor"""
308
338
  
309
339
    def resize_to_contents(self):
310
340
        """Resize cells to contents"""
311
 
        size = 1
312
 
        for dim in self.shape:
313
 
            size *= dim
314
 
        if size > 1e5:
315
 
            answer = QMessageBox.warning(self, _("Array editor"),
316
 
                                         _("Resizing cells of a table of such "
317
 
                                           "size could take a long time.\n"
318
 
                                           "Do you want to continue anyway?"),
319
 
                                         QMessageBox.Yes | QMessageBox.No)
320
 
            if answer == QMessageBox.No:
321
 
                return
322
341
        self.resizeColumnsToContents()
323
342
        self.resizeRowsToContents()
324
343