From 228dc546308f952fa64d848c72466854c233fe3e Mon Sep 17 00:00:00 2001 From: anwinged Date: Sat, 5 May 2012 08:36:45 +0000 Subject: [PATCH] saving reports, plot ench --- trunk/forms.py | 22 +++++++++++++++++++--- trunk/opal.py | 39 ++++++++++++++++++++++++++++++++++++--- trunk/task.py | 3 +++ 3 files changed, 58 insertions(+), 6 deletions(-) diff --git a/trunk/forms.py b/trunk/forms.py index 02a70a7..dcb61fa 100644 --- a/trunk/forms.py +++ b/trunk/forms.py @@ -278,6 +278,7 @@ class ResultFrame(wx.Frame): self.table = wx.grid.Grid(self) 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.table, 1, wx.EXPAND | wx.ALL, 1) @@ -366,8 +367,7 @@ class PlotFrame(wx.Frame): self.plot.canvas.SetCursor(wx.STANDARD_CURSOR) self.plot.HandCursor = wx.CursorFromImage(HandCursorImage) 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.SetEnableGrid(True) @@ -384,7 +384,10 @@ class PlotFrame(wx.Frame): menubar.Append(menu, 'Plot') 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): x = event.GetX() @@ -394,6 +397,19 @@ class PlotFrame(wx.Frame): delta = 0.8/1.0 if r > 0 else 1.0/0.8 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): def __init__(self, parent): wx.Dialog.__init__(self, parent, title = 'About Opal', size = (300, 330)) diff --git a/trunk/opal.py b/trunk/opal.py index 73522e2..0d909f9 100644 --- a/trunk/opal.py +++ b/trunk/opal.py @@ -625,6 +625,7 @@ class MainFrame(forms.MainFrame): return lines + @item_protector def AddLines(self, line_type): item, data = self.GetSelectedItemData(self.m_plots) if data != 'plot': @@ -649,7 +650,6 @@ class MainFrame(forms.MainFrame): else: self.m_plots.SetItemImage(child, self.icons.pline) - @item_protector def OnAddCurves(self, event): self.AddLines(LINE_CURVE) @@ -738,6 +738,9 @@ class ResultFrame(forms.ResultFrame): self.result = result self.UpdateResults() + self.Bind(wx.EVT_MENU, self.OnExportToCSV, + id = forms.ID_EXPORT_CSV) + def UpdateResults(self): self.scalar.Clear() self.table.ClearGrid() @@ -768,7 +771,38 @@ class ResultFrame(forms.ResultFrame): value = str(param.GetValue()))) 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.Thaw() - #----------------------------------------------------------------------------- # Приложение #----------------------------------------------------------------------------- diff --git a/trunk/task.py b/trunk/task.py index f2efe32..109fa03 100644 --- a/trunk/task.py +++ b/trunk/task.py @@ -179,6 +179,9 @@ class ResultData: rows = property(GetRows) + def GetCell(self, row, col): + return self.table[row][col] + def GetColumn(self, index): return [ row[index] for row in self.rows ]