Package diffpy :: Package pdfgui :: Package gui :: Module phasenotebookpanel
[hide private]
[frames] | no frames]

Source Code for Module diffpy.pdfgui.gui.phasenotebookpanel

  1  ############################################################################## 
  2  # 
  3  # PDFgui            by DANSE Diffraction group 
  4  #                   Simon J. L. Billinge 
  5  #                   (c) 2006 trustees of the Michigan State University. 
  6  #                   All rights reserved. 
  7  # 
  8  # File coded by:    Dmitriy Bryndin 
  9  # 
 10  # See AUTHORS.txt for a list of people who contributed. 
 11  # See LICENSE.txt for license information. 
 12  # 
 13  ############################################################################## 
 14   
 15  # 
 16  # Phase notebook panel 
 17  #  
 18  # Just a notebook, holds three panels:  "Configure", "Constraints", "Results" 
 19  # 
 20  # Dmitriy Bryndin 
 21  # 
 22  # version 
 23  __id__ = "$Id: phasenotebookpanel.py 2980 2009-04-02 00:14:33Z juhas $" 
 24   
 25  import wx 
 26   
 27  from diffpy.pdfgui.gui.pdfpanel import PDFPanel 
 28   
 29  from diffpy.pdfgui.gui.phaseconfigurepanel import PhaseConfigurePanel 
 30  from diffpy.pdfgui.gui.phaseconstraintspanel import PhaseConstraintsPanel 
 31  from diffpy.pdfgui.gui.phaseresultspanel import PhaseResultsPanel 
 32   
 33   
 34   
35 -class PhaseNotebookPanel(wx.Panel, PDFPanel):
36 - def __init__(self, *args, **kwds):
37 PDFPanel.__init__(self) 38 kwds["style"] = wx.TAB_TRAVERSAL 39 wx.Panel.__init__(self, *args, **kwds) 40 self.notebook_phase = wx.Notebook(self, -1, style=0) 41 self.notebook_phase_pane_Configure = PhaseConfigurePanel(self.notebook_phase, -1) 42 self.notebook_phase_pane_Constraints = PhaseConstraintsPanel(self.notebook_phase, -1) 43 self.notebook_phase_pane_Results = PhaseResultsPanel(self.notebook_phase, -1) 44 45 self.__set_properties() 46 self.__do_layout() 47 48 self.notebook_phase.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.onNotebookPageChanged ) 49 self.notebook_phase.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGING, self.onNotebookPageChanging ) 50 51 self.configuration = None 52 self.constraints = {} 53 self.results = None 54 self.mainFrame = None 55 self.focusedId = 0
56 57
58 - def __set_properties(self):
59 pass
60 61
62 - def __do_layout(self):
63 sizer_1 = wx.BoxSizer(wx.HORIZONTAL) 64 self.notebook_phase.AddPage(self.notebook_phase_pane_Configure, "Configure") 65 self.notebook_phase.AddPage(self.notebook_phase_pane_Constraints, "Constraints") 66 self.notebook_phase.AddPage(self.notebook_phase_pane_Results, "Results") 67 sizer_1.Add(self.notebook_phase, 1, wx.EXPAND, 0) 68 self.SetAutoLayout(True) 69 self.SetSizer(sizer_1) 70 sizer_1.Fit(self) 71 sizer_1.SetSizeHints(self)
72 73
74 - def refresh(self):
75 """Refreshes the currently shown panel.""" 76 if self.mainFrame.quitting: return 77 if self.focusedId is -1: return 78 79 panel = self.notebook_phase.GetPage(self.focusedId) 80 81 panel.structure = self.configuration 82 panel.constraints = self.constraints 83 panel.results = self.results 84 85 # This has to be done here, because this panel does not know who it 86 # belongs to until after it is instantiated. 87 panel.mainFrame = self.mainFrame 88 panel.refresh() 89 return
90
91 - def onNotebookPageChanging(self, event):
92 """Called during the page selection change.""" 93 focusedId = event.GetOldSelection() 94 panel = self.notebook_phase.GetPage(self.focusedId) 95 panel._cache() 96 return
97
98 - def onNotebookPageChanged(self, event):
99 """Called after the page selection is changed.""" 100 self.focusedId = event.GetSelection() 101 self.refresh() 102 event.Skip() 103 return
104 105 # Overloaded from Panel.
106 - def Enable(self, enable = True):
107 """Keep the notebook enabled, just not the panels.""" 108 self.notebook_phase_pane_Configure.Enable(enable) 109 self.notebook_phase_pane_Constraints.Enable(enable) 110 self.notebook_phase_pane_Results.Enable(enable) 111 return
112 113 114 # end of class PhaseNotebookPanel 115 116 ##### testing code ############################################################ 117 if __name__ == "__main__":
118 - class MyFrame(wx.Frame):
119 - def __init__(self, *args, **kwds):
120 kwds["style"] = wx.DEFAULT_FRAME_STYLE 121 wx.Frame.__init__(self, *args, **kwds) 122 self.window = PhaseNotebookPanel(self, -1) 123 self.SetTitle("testing") 124 # choke, mainframe.needsSave() emulation 125 self.window.mainFrame = self.window 126 self.window.mainFrame.needsSave = self.dummy 127 128 # choke, treeCtrlMain.GetSelections() emulation 129 self.window.treeCtrlMain = self.window 130 self.window.treeCtrlMain.GetSelections = self.dummy_dict 131 #self.window.treeCtrlMain.GetBranchType = self.dummy_true 132 self.test()
133 134
135 - def dummy(self, *args, **kwds):
136 pass
137
138 - def dummy_dict(self, *args, **kwds):
139 return [True]
140
141 - def dummy_true(self, *args, **kwds):
142 return True
143 144
145 - def test(self):
146 '''Testing code goes here''' 147 from diffpy.Structure.PDFFitStructure import PDFFitStructure 148 from diffpy.pdfgui.control.constraint import Constraint 149 150 self.window.configuration = PDFFitStructure() 151 self.window.configuration.read('../../tests/testdata/LaMnO3.pdb') 152 self.window.results = PDFFitStructure() 153 self.window.results.read('../../tests/testdata/LaMnO3.pdb') 154 155 formulas =['@1','@45','23+@3','@5 / 2',' @6 ', 'sin(@5)', '12+2*sqrt(@4)',' cos( @9 ) ','(@9*@9)','@10*2', '@6+@1'] 156 self.window.constraints = {} 157 # fill textcontrols 158 for i in xrange( len(self.window.notebook_phase_pane_Constraints.lConstraints) ): 159 self.window.constraints[self.window.notebook_phase_pane_Constraints.lConstraints[i]] = Constraint(formulas[i]) 160 # fill some cells (on diagonal) 161 for i in xrange(len(self.window.notebook_phase_pane_Constraints.lAtomConstraints)): 162 key = self.window.notebook_phase_pane_Constraints.lAtomConstraints[i] + '('+`i+1`+')' 163 self.window.constraints[key] = Constraint(formulas[i]) 164 165 self.window.refresh()
166 167 168
169 - class MyApp(wx.App):
170 - def OnInit(self):
171 wx.InitAllImageHandlers() 172 frame_1 = MyFrame(None, -1, "") 173 self.SetTopWindow(frame_1) 174 frame_1.Show() 175 return 1
176 177 app = MyApp(0) 178 app.MainLoop() 179 ##### end of testing code ##################################################### 180