From c24a76d476fc814ed61cdb7fd22f07e955505a54 Mon Sep 17 00:00:00 2001 From: anwinged Date: Thu, 3 May 2012 09:11:57 +0000 Subject: [PATCH] now main window is managed by aui --- forms.py | 95 ++++++++++++++++++++++++++++++++++++++----------------- opal.py | 43 +++++++++++++++++-------- server.py | 1 - 3 files changed, 96 insertions(+), 43 deletions(-) diff --git a/forms.py b/forms.py index dc3bade..bfcae84 100644 --- a/forms.py +++ b/forms.py @@ -5,6 +5,8 @@ import wx.gizmos import wx.grid import wx.propgrid as wxpg import wx.lib.plot as wxplot +import wx.lib.agw.aui as aui +# import wx.aui as aui ID_NEW = wx.NewId() ID_SAVE = wx.NewId() @@ -55,27 +57,40 @@ class Icons: """ pass -class MainFrame (wx.Frame): +class PropertyCtrl(wxpg.PropertyGrid): + + def GetPosition(self): + return self.GetPanel().GetPosition() + + def Clear(self): + wxpg.PropertyGrid.Clear(self) + +class MainFrame(wx.Frame): def __init__(self, parent): wx.Frame.__init__ (self, parent, title = 'Opal', size = wx.Size(873,594)) + self.auimgr = aui.AuiManager() + self.auimgr.SetManagedWindow(self) + self.auimgr.GetArtProvider().SetMetric(aui.AUI_DOCKART_SASH_SIZE, 3) + self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize) self.ilist, self.icons = self.LoadIcons() - bSizer3 = wx.BoxSizer(wx.HORIZONTAL) + # Спецификации - self.m_specs = wx.TreeCtrl(self, style = wx.TR_DEFAULT_STYLE) - self.m_specs.SetMinSize(wx.Size(200,-1)) + self.m_specs = wx.TreeCtrl(self, size = (200, -1), style = wx.TR_DEFAULT_STYLE) + # self.m_specs.SetMinSize(wx.Size(200,-1)) - bSizer3.Add(self.m_specs, 0, wx.ALL|wx.EXPAND, 1) + self.auimgr.AddPane(self.m_specs, + aui.AuiPaneInfo().Name("m_specs").Caption("Templates"). + Left().Layer(1).CloseButton(False)) - bSizer4 = wx.BoxSizer(wx.VERTICAL) + # Пользовательские модели - self.m_user_models = TreeListCtrl(self, + self.m_user_models = TreeListCtrl(self, size = (200, -1), style = wx.TR_DEFAULT_STYLE | wx.TR_HIDE_ROOT | wx.TR_FULL_ROW_HIGHLIGHT | wx.TR_ROW_LINES | wx.TR_MULTIPLE) - self.m_user_models.SetMinSize(wx.Size(-1, 300)) self.m_user_models.AddColumn("Model name") self.m_user_models.AddColumn("Status") self.m_user_models.AddColumn("Progress") @@ -83,42 +98,49 @@ class MainFrame (wx.Frame): self.m_user_models.SetMainColumn(0) self.m_user_models.SetImageList(self.ilist) - bSizer4.Add(self.m_user_models, 0, wx.ALL | wx.EXPAND, 1) + self.auimgr.AddPane(self.m_user_models, + aui.AuiPaneInfo().Name("m_user_models").Caption("Models"). + CenterPane().Position(1)) - # WARNING: wxPython code generation isn't supported for this widget yet. - self.m_params = wxpg.PropertyGridManager(self) - self.m_params.AddPage('fp') - bSizer4.Add(self.m_params, 1, wx.EXPAND | wx.ALL, 1) + # Параметры модели - bSizer3.Add(bSizer4, 1, wx.EXPAND, 5) + self.m_params = PropertyCtrl(self, size = (-1, 300)) - bSizer5 = wx.BoxSizer(wx.VERTICAL) + self.auimgr.AddPane(self.m_params, + aui.AuiPaneInfo().Name("m_params").Caption("Parameters").CloseButton(False). + CenterPane().Bottom().Position(2)) - self.m_quick_result = wxpg.PropertyGridManager(self) - self.m_quick_result.AddPage('fp') - self.m_quick_result.SetMinSize(wx.Size(200, -1)) - bSizer5.Add(self.m_quick_result, 1, wx.EXPAND | wx.ALL, 1) + # Быстрые результаты - self.m_plots = wx.TreeCtrl(self, + self.m_quick_result = PropertyCtrl(self, size = (200, -1)) + + self.auimgr.AddPane(self.m_quick_result, + aui.AuiPaneInfo().Name("m_quick_result").Caption("Quick results").CloseButton(False). + Right().Position(1).Layer(1)) + + # Графики + + self.m_plots = wx.TreeCtrl(self, size = (200, -1), style = wx.TR_DEFAULT_STYLE | wx.TR_HIDE_ROOT | wx.TR_EDIT_LABELS) - bSizer5.Add(self.m_plots, 1, wx.EXPAND | wx.ALL, 1) self.m_plots.SetImageList(self.ilist) - bSizer3.Add(bSizer5, 0, wx.ALL | wx.EXPAND, 1) + self.auimgr.AddPane(self.m_plots, + aui.AuiPaneInfo().Name("m_plots").Caption("Plots").CloseButton(False). + Right().Position(2).Layer(1)) + + # Меню, панель инструментов и панель статуса sbar = wx.StatusBar(self) self.SetStatusBar(sbar) - mbar = self.BuildMenu() - self.SetMenuBar(mbar) + self.SetMenuBar(self.BuildMenu()) + self.BuildContextMenu() # tbar = self.BuildToolBar() # self.SetToolBar(tbar) - self.SetSizer(bSizer3) - self.Layout() - self.Centre(wx.BOTH) + self.auimgr.Update() def LoadIcons(self): icons = Icons() @@ -217,8 +239,8 @@ class ResultFrame(wx.Frame): sizer = wx.BoxSizer(wx.VERTICAL) - self.scalar = wxpg.PropertyGridManager(self) - self.scalar.AddPage('fp') + self.scalar = PropertyCtrl(self) + self.scalar.SetMinSize((-1, 200)) self.table = wx.grid.Grid(self) self.table.SetDefaultCellAlignment(wx.ALIGN_CENTER, wx.ALIGN_CENTER) @@ -226,10 +248,23 @@ class ResultFrame(wx.Frame): sizer.Add(self.scalar, 0, wx.EXPAND | wx.ALL, 1) sizer.Add(self.table, 1, wx.EXPAND | wx.ALL, 1) + self.SetMenuBar(self.BuildMenu()) + self.SetSizer(sizer) self.Layout() self.Centre(wx.BOTH) + def BuildMenu(self): + + menubar = wx.MenuBar() + + menu = wx.Menu() + menu.Append(wx.NewId(), 'CSV\tCtrl+E') + menu.Append(wx.NewId(), 'TeX') + menubar.Append(menu, 'Export to') + + return menubar + class LineSelectDialog(wx.Dialog): def __init__(self, parent, title): wx.Dialog.__init__ (self, parent, -1, title, size = wx.Size(400, 300)) @@ -262,3 +297,5 @@ class PlotFrame(wx.Frame): self.plot.SetEnableAntiAliasing(True) self.plot.SetEnableHiRes(True) self.plot.SetEnableLegend(True) + + self.Centre(wx.BOTH) diff --git a/opal.py b/opal.py index 69b9cab..4533a9a 100644 --- a/opal.py +++ b/opal.py @@ -40,7 +40,6 @@ class ModelData: self.res = None - LINE_CURVE = 1 LINE_MARKER = 2 LINE_HISTOGRAM = 3 @@ -87,6 +86,8 @@ class MainFrame(forms.MainFrame): self.m_user_models.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnModelActivated) + self.m_user_models.Bind(wx.EVT_TREE_DELETE_ITEM, + self.OnDeleteModelsItem) self.m_params.Bind(wxpg.EVT_PG_CHANGING, self.OnParamChanging) self.m_params.Bind(wxpg.EVT_PG_CHANGED, @@ -97,7 +98,8 @@ class MainFrame(forms.MainFrame): self.OnModelProcess) self.m_plots.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnPlotProcess) - + self.m_plots.Bind(wx.EVT_CHAR, + self.OnPlotsKeyPressed) # События меню @@ -253,8 +255,8 @@ class MainFrame(forms.MainFrame): """ self.m_specs.DeleteAllItems() self.m_user_models.DeleteAllItems() - self.m_params.ClearPage(0) - self.m_quick_result.ClearPage(0) + self.m_params.Clear() + self.m_quick_result.Clear() self.m_plots.DeleteAllItems() # Строим спецификации self.BuildSpecs(model) @@ -392,7 +394,7 @@ class MainFrame(forms.MainFrame): raise KeyError() pg = self.m_params - pg.ClearPage(0) + pg.Clear() for label, value in model_def.params.iteritems(): param = model_def.DD[label] title = param.GetTitle() @@ -405,7 +407,7 @@ class MainFrame(forms.MainFrame): if not result: return pg = self.m_quick_result - pg.ClearPage(0) + pg.Clear() for label, param in result.data.iteritems(): pg.Append(wxpg.StringProperty(label, value = str(param.GetValue()))) pg.SetSplitterLeft() @@ -486,9 +488,14 @@ class MainFrame(forms.MainFrame): # Удаление модели + def OnDeleteModelsItem(self, event): + item = event.GetItem() + data = self.m_user_models.GetPyData(item) + if data: + self.server.DeleteJob(data.jid) + def OnDeleteModel(self, event): - item, data = self.GetSelectedItemData(self.m_user_models) - self.server.DeleteJob(data.jid) + item = self.GetSelectedItem(self.m_user_models) self.m_user_models.Delete(item) # Функции запуска модели на выполнение и управления очередью @@ -528,7 +535,7 @@ class MainFrame(forms.MainFrame): item, data = self.GetSelectedItemData(um) title = um.GetItemText(item) if not data.res: - self.SetStatusText("There is no results in model") + wx.MessageBox('There is no any result data', 'Warning', wx.OK | wx.ICON_EXCLAMATION) return [] f = LineSelectDialog(self, 'Select lines for "{}"'.format(title)) for index, col in enumerate(data.res.columns): @@ -579,8 +586,9 @@ class MainFrame(forms.MainFrame): self.AddLines(LINE_MARKER) def ShowPlot(self, lines, plot_title = ''): - p = PlotFrame(self, 'Plot', lines) - p.Show() + if lines: + p = PlotFrame(self, 'Plot', lines) + p.Show() def OnQuickShowPlot(self, event): lines = self.GetLines(LINE_CURVE) @@ -613,6 +621,13 @@ class MainFrame(forms.MainFrame): self.ShowPlot(lines) + def OnPlotsKeyPressed(self, event): + keycode = event.GetKeyCode() + item = self.GetSelectedItem(self.m_plots) + if keycode == wx.WXK_DELETE: + self.m_plots.Delete(item) + event.Skip() + #----------------------------------------------------------------------------- # Форма с выбором модели из представленного списка #----------------------------------------------------------------------------- @@ -653,7 +668,7 @@ class ResultFrame(forms.ResultFrame): self.UpdateResults() def UpdateResults(self): - self.scalar.ClearPage(0) + self.scalar.Clear() self.table.ClearGrid() if not self.result: return @@ -681,6 +696,9 @@ class ResultFrame(forms.ResultFrame): pg.Append(wxpg.StringProperty(label, value = str(param.GetValue()))) + def OnExportToCSV(self, event): + pass + #----------------------------------------------------------------------------- # Форма с выбором наборов значений для построения графика #----------------------------------------------------------------------------- @@ -723,7 +741,6 @@ class LineSelectDialog(forms.LineSelectDialog): return [ (x, y) for y in ys ] - #----------------------------------------------------------------------------- # Форма с изображением графика #----------------------------------------------------------------------------- diff --git a/server.py b/server.py index c4ce5d1..21da102 100644 --- a/server.py +++ b/server.py @@ -232,7 +232,6 @@ class Worker(threading.Thread): else: job.Finish(JOB_COMPLETED, 1.0) - def ProcessMessage(self, job, msg): try: # разбираем полученный ответ