-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from ankostis/encapse_buffer
WIP refact(table): decouple buffer from table-view by moving paging up to model
- Loading branch information
Showing
8 changed files
with
283 additions
and
378 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,7 +146,7 @@ def helpAbout(self, parent): | |
'folder': os.path.join(os.path.dirname(__file__)), | ||
'author': 'Vicent Mas <[email protected]>', | ||
'comment': translate('ArrayColsOrganizer', | ||
""" | ||
""" | ||
<qt><p>Plugin that provides an alternative view for | ||
arrays with the same number of rows. <p> | ||
The user has to open all the arrays she whishes to see in | ||
|
@@ -158,7 +158,7 @@ def helpAbout(self, parent): | |
<p>Note that all ticked arrays must have the same | ||
dimensions for the `Group` menu item to enable.</qt> | ||
""", | ||
'Text of an About plugin message box')} | ||
'Text of an About plugin message box')} | ||
about_page = AboutPage(desc, parent) | ||
return about_page | ||
|
||
|
@@ -198,10 +198,10 @@ def addEntry(self): | |
triggered=self.groupArrays, | ||
icon=object_group_icon, | ||
statusTip=translate('MenuUpdater', | ||
""" | ||
""" | ||
Use a unique widget to display Arrays as if | ||
they where columns of a Table""", | ||
"Status bar text for the Node -> Group Arrays action")) | ||
"Status bar text for the Node -> Group Arrays action")) | ||
|
||
object_ungroup_icon = QtGui.QIcon() | ||
pixmap = QtGui.QPixmap(os.path.join(_PLUGIN_FOLDER, | ||
|
@@ -219,8 +219,8 @@ def addEntry(self): | |
triggered=self.ungroupArrays, | ||
icon=object_ungroup_icon, | ||
statusTip=translate('MenuUpdater', | ||
"""Ungroup previously grouped arrays.""", | ||
"Status bar text for the Node -> Ungroup Arrays action")) | ||
"""Ungroup previously grouped arrays.""", | ||
"Status bar text for the Node -> Ungroup Arrays action")) | ||
|
||
# Add the actions to the Node menu | ||
vitables.utils.addToMenu(self.vtgui.node_menu, (self.group_action, | ||
|
@@ -468,12 +468,12 @@ def customizeGroupedViews(self): | |
|
||
nd = len(datasheets) | ||
for i in range(nd): | ||
datasheets[nd-1].widget().verticalScrollBar().valueChanged.connect( | ||
datasheets[nd - 1].widget().verticalScrollBar().valueChanged.connect( | ||
datasheets[i].widget().verticalScrollBar().setValue) | ||
if i < (nd - 1): | ||
datasheets[i].widget().verticalScrollBar().hide() | ||
datasheets[i].widget().setCornerWidget(None) | ||
datasheets[i+1].widget().verticalHeader().hide() | ||
datasheets[i + 1].widget().verticalHeader().hide() | ||
|
||
def closeEvent(self, event): | ||
""" Propagate the close event. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,6 @@ | |
pd = None | ||
|
||
from qtpy import QtCore | ||
from qtpy import QtGui | ||
from qtpy import QtWidgets | ||
|
||
import vitables.utils | ||
|
@@ -152,7 +151,7 @@ def tsFrequency(ts_kind, leaf): | |
if ts_kind == 'scikits_ts': | ||
# The frequency of the time serie. Default is 6000 (daily) | ||
special_attrs = getattr(leaf._v_attrs, 'special_attrs', | ||
{'freq': 6000}) | ||
{'freq': 6000}) | ||
ts_freq = special_attrs['freq'] | ||
return ts_freq | ||
|
||
|
@@ -225,14 +224,14 @@ def customiseModel(self, datasheet): | |
'ts_cols': time_cols, | ||
'ts_freq': tsFrequency(ts_kind, leaf), | ||
'ts_format': datetimeFormat(), | ||
} | ||
} | ||
if isinstance(leaf, tables.Table): | ||
leaf_kind = 'table' | ||
else: | ||
leaf_kind = 'array' | ||
model_info = { | ||
'leaf_kind': leaf_kind, | ||
'rbuffer': model.rbuffer, | ||
'model': model, | ||
'numrows': model.rowCount(), | ||
'formatContent': model.formatContent, | ||
} | ||
|
@@ -246,7 +245,6 @@ def customiseModel(self, datasheet): | |
model.tsFormatter = ts_model.tsFormatter | ||
model.data = ts_model.data | ||
|
||
|
||
def helpAbout(self, parent): | ||
"""Full description of the plugin. | ||
|
@@ -260,17 +258,17 @@ def helpAbout(self, parent): | |
|
||
# Plugin full description | ||
desc = {'version': __version__, | ||
'module_name': os.path.join(os.path.basename(__file__)), | ||
'folder': os.path.join(os.path.dirname(__file__)), | ||
'author': 'Vicent Mas <[email protected]>', | ||
'about_text': translate('TimeFormatterPage', | ||
"""<qt> | ||
'module_name': os.path.join(os.path.basename(__file__)), | ||
'folder': os.path.join(os.path.dirname(__file__)), | ||
'author': 'Vicent Mas <[email protected]>', | ||
'about_text': translate('TimeFormatterPage', | ||
"""<qt> | ||
<p>Plugin that provides nice string formatting for time fields. | ||
<p>It supports not only native PyTables time datatypes but | ||
also time series generated (and stored in PyTables tables) via | ||
Pandas and scikits.timeseries packages. | ||
</qt>""", | ||
'Text of an About plugin message box')} | ||
'Text of an About plugin message box')} | ||
self.about_page = AboutPage(desc, parent) | ||
|
||
# We need to install the event filter because the Preferences dialog | ||
|
@@ -300,7 +298,7 @@ def __init__(self, model_info, ts_info, parent=None): | |
self.ts_freq = ts_info['ts_freq'] | ||
self.ts_format = ts_info['ts_format'] | ||
# Attributes required by the data() method | ||
self.rbuffer = model_info['rbuffer'] | ||
self.model = model_info['model'] | ||
self.numrows = model_info['numrows'] | ||
self.ts_cols = ts_info['ts_cols'] | ||
self.formatContent = model_info['formatContent'] | ||
|
@@ -313,7 +311,6 @@ def __init__(self, model_info, ts_info, parent=None): | |
else: | ||
self.data = self.array_data | ||
|
||
|
||
def table_data(self, index, role=QtCore.Qt.DisplayRole): | ||
"""Returns the data stored under the given role for the item | ||
referred to by the index. | ||
|
@@ -325,21 +322,21 @@ def table_data(self, index, role=QtCore.Qt.DisplayRole): | |
- `index`: the index of a data item | ||
- `role`: the role being returned | ||
""" | ||
row, col = index.row(), index.column() | ||
|
||
if not index.isValid() or \ | ||
not (0 <= index.row() < self.numrows): | ||
if not index.isValid() or not (0 <= row < self.nrows): | ||
return None | ||
cell = self.rbuffer.getCell(self.rbuffer.start + index.row(), | ||
index.column()) | ||
|
||
if role == QtCore.Qt.DisplayRole: | ||
cell = self.model.cell(row, col) | ||
if index.column() in self.ts_cols: | ||
return self.tsFormatter(cell) | ||
return self.formatContent(cell) | ||
elif role == QtCore.Qt.TextAlignmentRole: | ||
return int(QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop) | ||
else: | ||
return None | ||
|
||
if role == QtCore.Qt.TextAlignmentRole: | ||
return QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop | ||
|
||
return None | ||
|
||
def array_data(self, index, role=QtCore.Qt.DisplayRole): | ||
"""Returns the data stored under the given role for the item | ||
|
@@ -352,19 +349,19 @@ def array_data(self, index, role=QtCore.Qt.DisplayRole): | |
- `index`: the index of a data item | ||
- `role`: the role being returned | ||
""" | ||
row, col = index.row(), index.column() | ||
|
||
if not index.isValid() or \ | ||
not (0 <= index.row() < self.numrows): | ||
if not index.isValid() or not (0 <= row < self.nrows): | ||
return None | ||
cell = self.rbuffer.getCell(self.rbuffer.start + index.row(), | ||
index.column()) | ||
|
||
if role == QtCore.Qt.DisplayRole: | ||
cell = self.model.cell(row, col) | ||
return self.tsFormatter(cell) | ||
elif role == QtCore.Qt.TextAlignmentRole: | ||
return int(QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop) | ||
else: | ||
return None | ||
|
||
if role == QtCore.Qt.TextAlignmentRole: | ||
return QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop | ||
|
||
return None | ||
|
||
def timeFormatter(self): | ||
"""Return the function to be used for formatting time series. | ||
|
@@ -380,7 +377,6 @@ def timeFormatter(self): | |
time_formatter = self.formatPyTablesTS | ||
return time_formatter | ||
|
||
|
||
def formatPyTablesTS(self, content): | ||
""" | ||
Format a given date in a user friendly way. | ||
|
@@ -396,7 +392,6 @@ def formatPyTablesTS(self, content): | |
except ValueError: | ||
return content | ||
|
||
|
||
def formatPandasTS(self, content): | ||
"""Format a given date in a user friendly way. | ||
|
@@ -405,14 +400,13 @@ def formatPandasTS(self, content): | |
:Parameter content: the content of the table cell being formatted | ||
""" | ||
|
||
# ImportError if pandas not installed! | ||
date = pd.Timestamp(int(content)) | ||
try: | ||
return date.strftime(self.ts_format) | ||
except ValueError: | ||
return content | ||
|
||
|
||
def formatScikitsTS(self, content): | ||
"""Format a given date in a user friendly way. | ||
|
Oops, something went wrong.