-
Notifications
You must be signed in to change notification settings - Fork 26
make the recarray viewer also handle tabular data (and add save) #624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -342,7 +342,7 @@ def __init__(self, parent, recipes): | |
| vsizer.Add(self.tRecipeText, 1, wx.ALL, 2) | ||
|
|
||
| self.bApply = wx.Button(self, -1, 'Apply Text Changes') | ||
| vsizer.Add(self.bApply, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 2) | ||
| vsizer.Add(self.bApply, 0, wx.ALL, 2) | ||
| self.bApply.Bind(wx.EVT_BUTTON, self.OnApplyText) | ||
|
|
||
| hsizer1.Add(vsizer, 0, wx.EXPAND|wx.ALL, 2) | ||
|
|
@@ -529,6 +529,7 @@ def OnAddModule(self, event): | |
|
|
||
|
|
||
| def OnPick(self, event): | ||
| from PYME.IO import tabular | ||
| k = event.artist._data | ||
| if not (isinstance(k, six.string_types)): | ||
| self.configureModule(k) | ||
|
|
@@ -544,6 +545,11 @@ def OnPick(self, event): | |
| mode = 'lite' | ||
|
|
||
| dv = ViewIm3D(outp, mode=mode, glCanvas=self.recipes.dsviewer.glCanvas) | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. W293: blank line contains whitespace |
||
| elif isinstance(outp, tabular.TabularBase): | ||
| from PYME.ui import recArrayView | ||
| f = recArrayView.ArrayFrame(outp, parent=self, title='Data table - %s' % k) | ||
| f.Show() | ||
|
|
||
|
|
||
| def configureModule(self, k): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,31 +22,15 @@ | |
| ################## | ||
|
|
||
| import wx | ||
| import wx.grid as gridlib | ||
| import wx.grid as gridlib | ||
| import numpy as np | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. F401: 'numpy as np' imported but unused |
||
| from PYME.IO import tabular | ||
|
|
||
| class RecArrayTable(gridlib.PyGridTableBase): | ||
|
|
||
| def __init__(self, recarray): | ||
| gridlib.PyGridTableBase.__init__(self) | ||
| self.recarray = recarray | ||
|
|
||
| # self.odd=gridlib.GridCellAttr() | ||
| # self.odd.SetBackgroundColour("sky blue") | ||
| # self.even=gridlib.GridCellAttr() | ||
| # self.even.SetBackgroundColour("sea green") | ||
| # | ||
| # def GetAttr(self, row, col, kind): | ||
| # attr = [self.even, self.odd][row % 2] | ||
| # attr.IncRef() | ||
| # return attr | ||
|
|
||
|
|
||
|
|
||
| # This is all it takes to make a custom data table to plug into a | ||
| # wxGrid. There are many more methods that can be overridden, but | ||
| # the ones shown below are the required ones. This table simply | ||
| # provides strings containing the row and column values. | ||
|
|
||
| def GetNumberRows(self): | ||
| return len(self.recarray) | ||
|
|
||
|
|
@@ -57,58 +41,105 @@ def IsEmptyCell(self, row, col): | |
| return False | ||
|
|
||
| def GetValue(self, row, col): | ||
| return str( self.recarray[row][col] ) | ||
| return str(self.recarray[row][col] ) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. E202: whitespace before ')' |
||
|
|
||
| def SetValue(self, row, col, value): | ||
| pass | ||
| #self.log.write('SetValue(%d, %d, "%s") ignored.\n' % (row, col, value)) | ||
|
|
||
| def GetColLabelValue(self, col): | ||
| return self.recarray.dtype.names[col] | ||
|
|
||
|
|
||
| class TabularTable(gridlib.PyGridTableBase): | ||
| def __init__(self, tabular): | ||
| gridlib.PyGridTableBase.__init__(self) | ||
| self._tabular = tabular | ||
|
|
||
| def GetNumberRows(self): | ||
| return len(self._tabular) | ||
|
|
||
| class RecarrayTableGrid(gridlib.Grid): | ||
| def __init__(self, parent, recarray): | ||
| gridlib.Grid.__init__(self, parent, -1, size = (-1,-1)) | ||
| def GetNumberCols(self): | ||
| return len(self._tabular.keys()) | ||
|
|
||
| table = RecArrayTable(recarray) | ||
| def IsEmptyCell(self, row, col): | ||
| return False | ||
|
|
||
| # The second parameter means that the grid is to take ownership of the | ||
| # table and will destroy it when done. Otherwise you would need to keep | ||
| # a reference to it and call it's Destroy method later. | ||
| self.SetTable(table, True) | ||
| def GetValue(self, row, col): | ||
| return str(self._tabular[self._tabular.keys()[col]][row]) | ||
|
|
||
| def SetValue(self, row, col, value): | ||
| pass | ||
|
|
||
| def GetColLabelValue(self, col): | ||
| return self._tabular.keys()[col] | ||
|
|
||
| def SetData(self, recarray): | ||
| table = RecArrayTable(recarray) | ||
|
|
||
| class ArrayTableGrid(gridlib.Grid): | ||
| def __init__(self, parent, data): | ||
| gridlib.Grid.__init__(self, parent, -1, size = (-1,-1)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. E231: missing whitespace after ',' There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. E251: unexpected spaces around keyword / parameter equals There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. E251: unexpected spaces around keyword / parameter equals |
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. W293: blank line contains whitespace |
||
| self.SetData(data) | ||
|
|
||
| def SetData(self, data): | ||
| if isinstance(data, tabular.TabularBase): | ||
| table = TabularTable(tabular.CachingResultsFilter(data)) | ||
| else: | ||
| table = RecArrayTable(data) | ||
|
|
||
| # The second parameter means that the grid is to take ownership of the | ||
| # table and will destroy it when done. Otherwise you would need to keep | ||
| # a reference to it and call it's Destroy method later. | ||
| self.SetTable(table, True) | ||
|
|
||
|
|
||
| class recArrayPanel(wx.Panel): | ||
|
|
||
| class ArrayPanel(wx.Panel): | ||
| def __init__(self, parent, recarray): | ||
| wx.Panel.__init__(self, parent) | ||
|
|
||
| self.recarray = recarray | ||
|
|
||
| #sizer = wx.BoxSizer(wx.VERTICAL) | ||
| self.data = recarray | ||
|
|
||
| self.grid = RecarrayTableGrid(self, recarray) | ||
| sizer = wx.BoxSizer(wx.VERTICAL) | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. W293: blank line contains whitespace |
||
| tool_sizer = wx.BoxSizer(wx.HORIZONTAL) | ||
| bSave = wx.BitmapButton(self, -1, wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE), style=wx.NO_BORDER | wx.BU_AUTODRAW, name='Save') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. E501: line too long (135 > 130 characters) |
||
| bSave.Bind(wx.EVT_BUTTON, self.OnSave) | ||
| tool_sizer.Add(bSave) | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. W293: blank line contains whitespace |
||
| sizer.Add(tool_sizer) | ||
|
|
||
| self.grid = ArrayTableGrid(self, recarray) | ||
| self.grid.SetSize((10,10)) | ||
|
|
||
| #sizer.Add(self.grid, 1, wx.EXPAND, 0) | ||
|
|
||
| #self.SetSizerAndFit(sizer) | ||
| sizer.Add(self.grid, 1, wx.EXPAND, 0) | ||
| self.SetSizerAndFit(sizer) | ||
| #self.SetAutoLayout(True) | ||
|
|
||
| wx.EVT_SIZE(self, self.OnSize) | ||
|
|
||
| def OnSize(self, event): | ||
| self.grid.SetSize(self.GetClientSize()) | ||
| #self.Refresh() | ||
| event.Skip() | ||
| event.Skip() | ||
|
|
||
| def OnSave(self, event): | ||
| filename = wx.SaveFileSelector("Save data as ...", 'HDF (*.hdf)|*.hdf|Comma separated text (*.csv)|*.csv') | ||
| if not filename == '': | ||
| if isinstance(self.data, tabular.TabularBase): | ||
| data = self.data | ||
| else: | ||
| data = tabular.RecArraySource(self.data) | ||
|
|
||
| if filename.endswith('.hdf'): | ||
| data.to_hdf(filename) | ||
| else: | ||
| data.to_csv(filename) | ||
|
|
||
|
|
||
| class ArrayFrame(wx.Frame): | ||
| def __init__(self, data, title='Data table', parent=-1): | ||
| wx.Frame.__init__(self, parent, title=title, size=(800,600)) | ||
|
|
||
| sizer = wx.BoxSizer(wx.VERTICAL) | ||
| self._array_pan = ArrayPanel(self, data) | ||
| sizer.Add(self._array_pan, 1, wx.EXPAND, 0) | ||
| self.SetSizer(sizer) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E303: too many blank lines (2)