Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions PYME/DSView/modules/blobFinding.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def OnFindObjects(self, event):
self.objPosRA = numpy.rec.fromrecords(self.dsviewer.view.points, names='x,y,z')

if self.vObjPos is None:
self.vObjPos = recArrayView.recArrayPanel(self.dsviewer, self.objPosRA)
self.vObjPos = recArrayView.ArrayPanel(self.dsviewer, self.objPosRA)
self.dsviewer.AddPage(self.vObjPos, caption='Object Positions')
else:
self.vObjPos.grid.SetData(self.objPosRA)
Expand Down Expand Up @@ -244,7 +244,7 @@ def OnFitObjects(self, event):
#if self.nObjFit == None:


vObjFit = recArrayView.recArrayPanel(self.dsviewer, self.objFitRes[chnum]['fitResults'])
vObjFit = recArrayView.ArrayPanel(self.dsviewer, self.objFitRes[chnum]['fitResults'])

Copy link
Copy Markdown

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)

self.dsviewer.AddPage(vObjFit, caption = 'Fitted Positions %d - %d' % (chnum, self.nObjFit))
self.nObjFit += 1
#else:
Expand Down
20 changes: 20 additions & 0 deletions PYME/IO/tabular.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,26 @@ def to_hdf(self, filename, tablename='Data', keys=None, metadata=None,

#wait until data is written
f.flush()

def to_csv(self, outFile, keys=None):
if outFile.endswith('.csv'):
delim = ', '
else:
delim = '\t'

if keys is None:
keys = self.keys()

#nRecords = len(ds[keys[0]])

of = open(outFile, 'w')

of.write('#' + delim.join(['%s' % k for k in keys]) + '\n')

for row in zip(*[self[k] for k in keys]):
of.write(delim.join(['%e' % c for c in row]) + '\n')

of.close()


def keys(self):
Expand Down
2 changes: 1 addition & 1 deletion PYME/LMVis/triBlobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def OnObjMeasure(self, event):
om = self.pipeline.measureObjects()

if self.visgui.rav is None:
self.visgui.rav = recArrayView.recArrayPanel(self.visgui, om)
self.visgui.rav = recArrayView.ArrayPanel(self.visgui, om)
self.visgui.AddPage(self.visgui.rav, 'Measurements')
else:
self.visgui.rav.grid.SetData(om)
Expand Down
8 changes: 7 additions & 1 deletion PYME/recipes/recipeGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -544,6 +545,11 @@ def OnPick(self, event):
mode = 'lite'

dv = ViewIm3D(outp, mode=mode, glCanvas=self.recipes.dsviewer.glCanvas)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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):
Expand Down
113 changes: 72 additions & 41 deletions PYME/ui/recArrayView.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,15 @@
##################

import wx
import wx.grid as gridlib
import wx.grid as gridlib
import numpy as np

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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)

Expand All @@ -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] )

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E231: missing whitespace after ','

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E251: unexpected spaces around keyword / parameter equals

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E251: unexpected spaces around keyword / parameter equals


Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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)