saving reports, plot ench

This commit is contained in:
anwinged 2012-05-05 08:36:45 +00:00
parent 5d02391096
commit 989b333244
3 changed files with 58 additions and 6 deletions

View File

@ -278,6 +278,7 @@ class ResultFrame(wx.Frame):
self.table = wx.grid.Grid(self) self.table = wx.grid.Grid(self)
self.table.SetDefaultCellAlignment(wx.ALIGN_CENTER, wx.ALIGN_CENTER) self.table.SetDefaultCellAlignment(wx.ALIGN_CENTER, wx.ALIGN_CENTER)
self.table.DisableCellEditControl()
sizer.Add(self.scalar, 0, wx.EXPAND | wx.ALL, 1) sizer.Add(self.scalar, 0, wx.EXPAND | wx.ALL, 1)
sizer.Add(self.table, 1, wx.EXPAND | wx.ALL, 1) sizer.Add(self.table, 1, wx.EXPAND | wx.ALL, 1)
@ -366,8 +367,7 @@ class PlotFrame(wx.Frame):
self.plot.canvas.SetCursor(wx.STANDARD_CURSOR) self.plot.canvas.SetCursor(wx.STANDARD_CURSOR)
self.plot.HandCursor = wx.CursorFromImage(HandCursorImage) self.plot.HandCursor = wx.CursorFromImage(HandCursorImage)
self.plot.GrabHandCursor = wx.CursorFromImage(GrabHandCursorImage) self.plot.GrabHandCursor = wx.CursorFromImage(GrabHandCursorImage)
# все равно не используется self.plot.MagCursor = wx.StockCursor(wx.CURSOR_MAGNIFIER)
# self.plot.MagCursor = wx.StockCursor(wx.CURSOR_MAGNIFIER)
self.plot.SetGridColour(wx.Color(200, 200, 200)) self.plot.SetGridColour(wx.Color(200, 200, 200))
self.plot.SetEnableGrid(True) self.plot.SetEnableGrid(True)
@ -384,7 +384,10 @@ class PlotFrame(wx.Frame):
menubar.Append(menu, 'Plot') menubar.Append(menu, 'Plot')
self.SetMenuBar(menubar) self.SetMenuBar(menubar)
self.plot.Bind(wx.EVT_MOUSEWHEEL, self.OnZoom) self.plot.canvas.Bind(wx.EVT_MOUSEWHEEL, self.OnZoom)
self.plot.canvas.Bind(wx.EVT_MIDDLE_DOWN, self.OnZoomReset)
self.plot.canvas.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
self.plot.canvas.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
def OnZoom(self, event): def OnZoom(self, event):
x = event.GetX() x = event.GetX()
@ -394,6 +397,19 @@ class PlotFrame(wx.Frame):
delta = 0.8/1.0 if r > 0 else 1.0/0.8 delta = 0.8/1.0 if r > 0 else 1.0/0.8
self.plot.Zoom((x, y), (delta, delta)) self.plot.Zoom((x, y), (delta, delta))
def OnZoomReset(self, event):
self.plot.Reset()
def OnKeyDown(self, event):
if event.GetKeyCode() == wx.WXK_SHIFT:
self.plot.SetEnableDrag(False)
self.plot.SetEnableZoom(True)
def OnKeyUp(self, event):
if event.GetKeyCode() == wx.WXK_SHIFT:
self.plot.SetEnableZoom(False)
self.plot.SetEnableDrag(True)
class AboutDialog(wx.Dialog): class AboutDialog(wx.Dialog):
def __init__(self, parent): def __init__(self, parent):
wx.Dialog.__init__(self, parent, title = 'About Opal', size = (300, 330)) wx.Dialog.__init__(self, parent, title = 'About Opal', size = (300, 330))

39
opal.py
View File

@ -625,6 +625,7 @@ class MainFrame(forms.MainFrame):
return lines return lines
@item_protector
def AddLines(self, line_type): def AddLines(self, line_type):
item, data = self.GetSelectedItemData(self.m_plots) item, data = self.GetSelectedItemData(self.m_plots)
if data != 'plot': if data != 'plot':
@ -649,7 +650,6 @@ class MainFrame(forms.MainFrame):
else: else:
self.m_plots.SetItemImage(child, self.icons.pline) self.m_plots.SetItemImage(child, self.icons.pline)
@item_protector
def OnAddCurves(self, event): def OnAddCurves(self, event):
self.AddLines(LINE_CURVE) self.AddLines(LINE_CURVE)
@ -738,6 +738,9 @@ class ResultFrame(forms.ResultFrame):
self.result = result self.result = result
self.UpdateResults() self.UpdateResults()
self.Bind(wx.EVT_MENU, self.OnExportToCSV,
id = forms.ID_EXPORT_CSV)
def UpdateResults(self): def UpdateResults(self):
self.scalar.Clear() self.scalar.Clear()
self.table.ClearGrid() self.table.ClearGrid()
@ -768,7 +771,38 @@ class ResultFrame(forms.ResultFrame):
value = str(param.GetValue()))) value = str(param.GetValue())))
def OnExportToCSV(self, event): def OnExportToCSV(self, event):
pass
if not self.result or not self.result.table:
return
text_file = wx.FileSelector('Save table to CSV',
default_filename = 'table.csv',
wildcard = 'PNG files (*.csv)|*.csv|Text files (*.txt)|*.txt',
flags = wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
if not text_file:
return
tl = self.table.GetSelectionBlockTopLeft() # [(t, l)]
br = self.table.GetSelectionBlockBottomRight() # [(b, r)]
if not tl:
tl = (0, 0)
else:
tl = tl[0]
if not br:
br = (len(self.result.rows), len(self.result.columns))
else:
x, y = br[0]
br = x + 1, y + 1
with open(text_file, 'w') as f:
for i in xrange(tl[0], br[0]):
s = []
for j in xrange(tl[1], br[1]):
s.append(repr(self.result.GetCell(i, j)))
f.write('; '.join(s) + '\n')
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# Форма с выбором наборов значений для построения графика # Форма с выбором наборов значений для построения графика
@ -856,7 +890,6 @@ class PlotFrame(forms.PlotFrame):
self.plot.SetSize(old_size) self.plot.SetSize(old_size)
self.plot.Thaw() self.plot.Thaw()
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# Приложение # Приложение
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------

View File

@ -179,6 +179,9 @@ class ResultData:
rows = property(GetRows) rows = property(GetRows)
def GetCell(self, row, col):
return self.table[row][col]
def GetColumn(self, index): def GetColumn(self, index):
return [ row[index] for row in self.rows ] return [ row[index] for row in self.rows ]