[3c44c66] | 1 | ################################################################################ |
---|
| 2 | #This software was developed by the University of Tennessee as part of the |
---|
| 3 | #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
| 4 | #project funded by the US National Science Foundation. |
---|
| 5 | # |
---|
| 6 | #See the license text in license.txt |
---|
| 7 | # |
---|
| 8 | #copyright 2010, University of Tennessee |
---|
| 9 | ################################################################################ |
---|
| 10 | """ |
---|
| 11 | This module provides Graphic interface for the data_manager module. |
---|
| 12 | """ |
---|
| 13 | import wx |
---|
| 14 | import sys |
---|
[3feed3e] | 15 | import warnings |
---|
[3c44c66] | 16 | from wx.lib.scrolledpanel import ScrolledPanel |
---|
[3feed3e] | 17 | import wx.lib.agw.customtreectrl as CT |
---|
| 18 | from sans.guiframe.dataFitting import Data1D |
---|
| 19 | from sans.guiframe.dataFitting import Data2D |
---|
[52725d6] | 20 | from sans.guiframe.panel_base import PanelBase |
---|
[3feed3e] | 21 | |
---|
| 22 | PANEL_WIDTH = 200 |
---|
[3c44c66] | 23 | |
---|
[3feed3e] | 24 | class DataTreeCtrl(CT.CustomTreeCtrl): |
---|
[3c44c66] | 25 | """ |
---|
| 26 | Check list control to be used for Data Panel |
---|
| 27 | """ |
---|
[6db811e] | 28 | def __init__(self, parent,*args, **kwds): |
---|
[3feed3e] | 29 | kwds['style']= wx.SUNKEN_BORDER|CT.TR_HAS_BUTTONS| CT.TR_HIDE_ROOT| \ |
---|
| 30 | CT.TR_HAS_VARIABLE_ROW_HEIGHT|wx.WANTS_CHARS |
---|
| 31 | CT.CustomTreeCtrl.__init__(self, parent, *args, **kwds) |
---|
| 32 | self.root = self.AddRoot("Available Data") |
---|
[3c44c66] | 33 | |
---|
[52725d6] | 34 | class DataPanel(ScrolledPanel, PanelBase): |
---|
[3c44c66] | 35 | """ |
---|
| 36 | This panel displays data available in the application and widgets to |
---|
| 37 | interact with data. |
---|
| 38 | """ |
---|
[3feed3e] | 39 | ## Internal name for the AUI manager |
---|
| 40 | window_name = "Data Panel" |
---|
| 41 | ## Title to appear on top of the window |
---|
| 42 | window_caption = "Data Panel" |
---|
| 43 | #type of window |
---|
| 44 | window_type = "Data Panel" |
---|
| 45 | ## Flag to tell the GUI manager that this panel is not |
---|
| 46 | # tied to any perspective |
---|
| 47 | #ALWAYS_ON = True |
---|
| 48 | def __init__(self, parent, list=[],list_of_perspective=[], |
---|
| 49 | size=(PANEL_WIDTH,560), manager=None, *args, **kwds): |
---|
| 50 | kwds['size']= size |
---|
[3c44c66] | 51 | ScrolledPanel.__init__(self, parent=parent, *args, **kwds) |
---|
[52725d6] | 52 | PanelBase.__init__(self) |
---|
[3c44c66] | 53 | self.SetupScrolling() |
---|
[3feed3e] | 54 | |
---|
[3c44c66] | 55 | self.parent = parent |
---|
[3feed3e] | 56 | self.manager = manager |
---|
[3c44c66] | 57 | self.list_of_data = list |
---|
[3feed3e] | 58 | self.list_of_perspective = list_of_perspective |
---|
| 59 | self.list_rb_perspectives= [] |
---|
| 60 | self.list_cb_data =[] |
---|
| 61 | self.list_cb_theory =[] |
---|
| 62 | self.owner = None |
---|
| 63 | self.do_layout() |
---|
[6db811e] | 64 | |
---|
[3feed3e] | 65 | def do_layout(self): |
---|
[6db811e] | 66 | """ |
---|
| 67 | """ |
---|
[3c44c66] | 68 | self.define_panel_structure() |
---|
| 69 | self.layout_selection() |
---|
[3feed3e] | 70 | self.layout_list() |
---|
[3c44c66] | 71 | self.layout_button() |
---|
[3feed3e] | 72 | self.layout_batch() |
---|
| 73 | |
---|
[3c44c66] | 74 | def define_panel_structure(self): |
---|
| 75 | """ |
---|
| 76 | Define the skeleton of the panel |
---|
| 77 | """ |
---|
[3feed3e] | 78 | w, h = self.parent.GetSize() |
---|
[3c44c66] | 79 | self.vbox = wx.BoxSizer(wx.VERTICAL) |
---|
| 80 | self.sizer1 = wx.BoxSizer(wx.VERTICAL) |
---|
[6db811e] | 81 | self.sizer1.SetMinSize((w/12, h/2)) |
---|
[3feed3e] | 82 | self.sizer2 = wx.BoxSizer(wx.VERTICAL) |
---|
| 83 | self.sizer3 = wx.GridBagSizer(5,5) |
---|
[3c44c66] | 84 | self.sizer4 = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 85 | self.sizer5 = wx.BoxSizer(wx.HORIZONTAL) |
---|
[6db811e] | 86 | #self.sizer3.SetMinSize((w-60, -1)) |
---|
[3feed3e] | 87 | |
---|
| 88 | self.vbox.Add(self.sizer5, 0,wx.EXPAND|wx.ALL,10) |
---|
| 89 | self.vbox.Add(self.sizer1, 0,wx.EXPAND|wx.ALL,0) |
---|
| 90 | self.vbox.Add(self.sizer2, 0,wx.EXPAND|wx.ALL,10) |
---|
| 91 | self.vbox.Add(self.sizer3, 0,wx.EXPAND|wx.ALL,10) |
---|
| 92 | self.vbox.Add(self.sizer4, 0,wx.EXPAND|wx.ALL,10) |
---|
| 93 | |
---|
[3c44c66] | 94 | self.SetSizer(self.vbox) |
---|
| 95 | |
---|
[3feed3e] | 96 | def layout_selection(self): |
---|
[3c44c66] | 97 | """ |
---|
| 98 | """ |
---|
[3feed3e] | 99 | select_txt = wx.StaticText(self, -1, 'Selection Options') |
---|
| 100 | self.selection_cbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) |
---|
| 101 | list_of_options = ['Select all Data', |
---|
| 102 | 'Unselect all Data', |
---|
| 103 | 'Select all Data 1D', |
---|
| 104 | 'Unselect all Data 1D', |
---|
| 105 | 'Select all Data 2D', |
---|
| 106 | 'Unselect all Data 2D' ] |
---|
| 107 | for option in list_of_options: |
---|
| 108 | self.selection_cbox.Append(str(option)) |
---|
| 109 | self.selection_cbox.SetValue('None') |
---|
| 110 | wx.EVT_COMBOBOX(self.selection_cbox,-1, self._on_selection_type) |
---|
| 111 | self.sizer5.AddMany([(select_txt,0, wx.ALL,5), |
---|
| 112 | (self.selection_cbox,0, wx.ALL,5)]) |
---|
| 113 | def layout_perspective(self, list_of_perspective=[]): |
---|
[3c44c66] | 114 | """ |
---|
| 115 | Layout widgets related to the list of plug-ins of the gui_manager |
---|
| 116 | """ |
---|
[3feed3e] | 117 | if len(list_of_perspective)==0: |
---|
| 118 | return |
---|
| 119 | w, h = self.parent.GetSize() |
---|
| 120 | box_description_2= wx.StaticBox(self, -1, "Set Active Perspective") |
---|
| 121 | self.boxsizer_2 = wx.StaticBoxSizer(box_description_2, wx.HORIZONTAL) |
---|
| 122 | self.sizer_perspective = wx.GridBagSizer(5,5) |
---|
| 123 | self.boxsizer_2.Add(self.sizer_perspective) |
---|
| 124 | self.sizer2.Add(self.boxsizer_2,1, wx.ALL, 10) |
---|
| 125 | self.list_of_perspective = list_of_perspective |
---|
| 126 | self.sizer_perspective.Clear(True) |
---|
| 127 | self.list_rb_perspectives = [] |
---|
| 128 | |
---|
| 129 | nb_active_perspective = 0 |
---|
[3c44c66] | 130 | if list_of_perspective: |
---|
| 131 | ix = 0 |
---|
| 132 | iy = 0 |
---|
[3feed3e] | 133 | for perspective_name, is_active in list_of_perspective: |
---|
| 134 | |
---|
| 135 | if is_active: |
---|
| 136 | nb_active_perspective += 1 |
---|
| 137 | if nb_active_perspective == 1: |
---|
| 138 | rb = wx.RadioButton(self, -1, perspective_name, style=wx.RB_GROUP) |
---|
| 139 | rb.SetToolTipString("Data will be applied to this perspective") |
---|
| 140 | rb.SetValue(is_active) |
---|
| 141 | else: |
---|
| 142 | rb = wx.RadioButton(self, -1, perspective_name) |
---|
| 143 | rb.SetToolTipString("Data will be applied to this perspective") |
---|
| 144 | #only one perpesctive can be active |
---|
| 145 | rb.SetValue(False) |
---|
| 146 | |
---|
| 147 | self.Bind(wx.EVT_RADIOBUTTON, self.on_set_active_perspective, |
---|
| 148 | id=rb.GetId()) |
---|
| 149 | self.list_rb_perspectives.append(rb) |
---|
| 150 | self.sizer_perspective.Add(rb,(iy, ix),(1,1), |
---|
| 151 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
[3c44c66] | 152 | iy += 1 |
---|
| 153 | else: |
---|
| 154 | rb = wx.RadioButton(self, -1, 'No Perspective', |
---|
| 155 | style=wx.RB_GROUP) |
---|
| 156 | rb.SetValue(True) |
---|
| 157 | rb.Disable() |
---|
| 158 | ix = 0 |
---|
| 159 | iy = 0 |
---|
[3feed3e] | 160 | self.sizer_perspective.Add(rb,(iy, ix),(1,1), |
---|
[3c44c66] | 161 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
[3feed3e] | 162 | |
---|
| 163 | def _on_selection_type(self, event): |
---|
[3c44c66] | 164 | """ |
---|
[3feed3e] | 165 | Select data according to patterns |
---|
[3c44c66] | 166 | """ |
---|
[3feed3e] | 167 | option = self.selection_cbox.GetValue() |
---|
| 168 | if option == 'Select all Data': |
---|
[6db811e] | 169 | print "on select" |
---|
| 170 | |
---|
[3feed3e] | 171 | def on_set_active_perspective(self, event): |
---|
[3c44c66] | 172 | """ |
---|
[3feed3e] | 173 | Select the active perspective |
---|
| 174 | """ |
---|
| 175 | ctrl = event.GetEventObject() |
---|
[3c44c66] | 176 | |
---|
| 177 | def layout_button(self): |
---|
| 178 | """ |
---|
| 179 | Layout widgets related to buttons |
---|
| 180 | """ |
---|
[3feed3e] | 181 | self.bt_import = wx.Button(self, wx.NewId(), "Send To") |
---|
| 182 | self.bt_import.SetToolTipString("Send set of Data to active perspective") |
---|
[3c44c66] | 183 | wx.EVT_BUTTON(self, self.bt_import.GetId(), self.on_import) |
---|
| 184 | |
---|
[3feed3e] | 185 | self.bt_append_plot = wx.Button(self, wx.NewId(), "Append Plot To") |
---|
[213892bc] | 186 | self.bt_append_plot.SetToolTipString("Plot the selected data in the active panel") |
---|
| 187 | wx.EVT_BUTTON(self, self.bt_append_plot.GetId(), self.on_append_plot) |
---|
[3feed3e] | 188 | |
---|
| 189 | self.bt_plot = wx.Button(self, wx.NewId(), "New Plot") |
---|
[3c44c66] | 190 | self.bt_plot.SetToolTipString("To trigger plotting") |
---|
| 191 | wx.EVT_BUTTON(self, self.bt_plot.GetId(), self.on_plot) |
---|
| 192 | |
---|
[d828481] | 193 | self.bt_remove = wx.Button(self, wx.NewId(), "Remove Data") |
---|
| 194 | self.bt_remove.SetToolTipString("Remove data from the application") |
---|
[3feed3e] | 195 | wx.EVT_BUTTON(self, self.bt_remove.GetId(), self.on_remove) |
---|
| 196 | |
---|
[c5e84fb] | 197 | self.tctrl_perspective = wx.StaticText(self, -1, 'No Active Application') |
---|
[3feed3e] | 198 | self.tctrl_perspective.SetToolTipString("Active Application") |
---|
[213892bc] | 199 | self.tctrl_plotpanel = wx.StaticText(self, -1, 'No Plot panel on focus') |
---|
| 200 | self.tctrl_plotpanel.SetToolTipString("Active Plot Panel") |
---|
[3feed3e] | 201 | #self.sizer3.AddMany([(self.bt_import,0, wx.ALL,5), |
---|
| 202 | # (self.bt_append_plot,0, wx.ALL,5), |
---|
| 203 | # (self.bt_plot, 0, wx.ALL,5), |
---|
| 204 | # (self.bt_remove,0, wx.ALL,5)]) |
---|
| 205 | ix = 0 |
---|
| 206 | iy = 0 |
---|
| 207 | self.sizer3.Add(self.bt_import,( iy, ix),(1,1), |
---|
| 208 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 209 | ix += 1 |
---|
| 210 | self.sizer3.Add(self.tctrl_perspective,(iy, ix),(1,1), |
---|
| 211 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 212 | ix = 0 |
---|
| 213 | iy += 1 |
---|
| 214 | self.sizer3.Add(self.bt_append_plot,( iy, ix),(1,1), |
---|
| 215 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 216 | ix += 1 |
---|
| 217 | self.sizer3.Add(self.tctrl_plotpanel,(iy, ix),(1,1), |
---|
| 218 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 219 | ix = 0 |
---|
| 220 | iy += 1 |
---|
| 221 | self.sizer3.Add(self.bt_plot,( iy, ix),(1,1), |
---|
| 222 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 223 | ix = 0 |
---|
| 224 | iy += 1 |
---|
| 225 | self.sizer3.Add(self.bt_remove,( iy, ix),(1,1), |
---|
| 226 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 227 | |
---|
| 228 | |
---|
| 229 | def layout_batch(self): |
---|
[3c44c66] | 230 | """ |
---|
| 231 | """ |
---|
[3feed3e] | 232 | |
---|
| 233 | self.rb_single_mode = wx.RadioButton(self, -1, 'Single Mode', |
---|
| 234 | style=wx.RB_GROUP) |
---|
| 235 | self.rb_batch_mode = wx.RadioButton(self, -1, 'Batch Mode') |
---|
| 236 | |
---|
| 237 | self.rb_single_mode.SetValue(True) |
---|
| 238 | self.rb_batch_mode.SetValue(False) |
---|
| 239 | self.sizer4.AddMany([(self.rb_single_mode,0, wx.ALL,5), |
---|
| 240 | (self.rb_batch_mode,0, wx.ALL,5)]) |
---|
| 241 | |
---|
| 242 | def layout_list(self): |
---|
[3c44c66] | 243 | """ |
---|
[3feed3e] | 244 | Add a listcrtl in the panel |
---|
[3c44c66] | 245 | """ |
---|
[6db811e] | 246 | self.tree_ctrl = DataTreeCtrl(parent=self) |
---|
[3feed3e] | 247 | self.tree_ctrl.Bind(CT.EVT_TREE_ITEM_CHECKED, self.on_check_item) |
---|
| 248 | self.tree_ctrl.Bind(CT.EVT_TREE_ITEM_RIGHT_CLICK, self.on_right_click) |
---|
[6db811e] | 249 | self.sizer1.Add(self.tree_ctrl,1, wx.EXPAND|wx.ALL, 20) |
---|
[3feed3e] | 250 | |
---|
| 251 | def on_right_click(self, event): |
---|
[3c44c66] | 252 | """ |
---|
| 253 | """ |
---|
[3feed3e] | 254 | ## Create context menu for data |
---|
| 255 | self.popUpMenu = wx.Menu() |
---|
| 256 | msg = "Edit %s"%str(self.tree_ctrl.GetItemText(event.GetItem())) |
---|
| 257 | id = wx.NewId() |
---|
| 258 | self.edit_data_mitem = wx.MenuItem(self.popUpMenu,id,msg, |
---|
| 259 | "Edit meta data") |
---|
| 260 | wx.EVT_MENU(self, id, self.on_edit_data) |
---|
| 261 | self.popUpMenu.AppendItem(self.edit_data_mitem) |
---|
| 262 | self.Bind(wx.EVT_CONTEXT_MENU, self.onContextMenu) |
---|
[3c44c66] | 263 | |
---|
[3feed3e] | 264 | def on_edit_data(self, event): |
---|
[3c44c66] | 265 | """ |
---|
| 266 | """ |
---|
[3feed3e] | 267 | print "editing data" |
---|
[c5e84fb] | 268 | |
---|
[3feed3e] | 269 | def onContextMenu(self, event): |
---|
[3c44c66] | 270 | """ |
---|
[3feed3e] | 271 | Retrieve the state selected state |
---|
[3c44c66] | 272 | """ |
---|
[3feed3e] | 273 | # Skipping the save state functionality for release 0.9.0 |
---|
| 274 | #return |
---|
| 275 | pos = event.GetPosition() |
---|
| 276 | pos = self.ScreenToClient(pos) |
---|
| 277 | self.PopupMenu(self.popUpMenu, pos) |
---|
| 278 | |
---|
| 279 | def on_check_item(self, event): |
---|
[3c44c66] | 280 | """ |
---|
| 281 | """ |
---|
[3feed3e] | 282 | item = event.GetItem() |
---|
[c5e84fb] | 283 | name = self.tree_ctrl.GetItemText(item) |
---|
[3feed3e] | 284 | |
---|
| 285 | def load_data_list(self, list): |
---|
[3c44c66] | 286 | """ |
---|
| 287 | |
---|
| 288 | """ |
---|
[3feed3e] | 289 | if not list: |
---|
| 290 | return |
---|
[3c44c66] | 291 | |
---|
[3feed3e] | 292 | for dstate in list.values(): |
---|
| 293 | data = dstate.get_data() |
---|
| 294 | if data is None: |
---|
| 295 | data_name = str(data) |
---|
| 296 | data_class = "unkonwn" |
---|
| 297 | else: |
---|
| 298 | data_name = data.name |
---|
| 299 | data_class = data.__class__.__name__ |
---|
| 300 | path = dstate.get_path() |
---|
| 301 | theory_list = dstate.get_theory() |
---|
| 302 | theory = None |
---|
| 303 | if theory_list: |
---|
| 304 | theory = theory_list[len(theory_list)-1] |
---|
| 305 | data_child = None |
---|
| 306 | for item in self.list_cb_data: |
---|
| 307 | if self.tree_ctrl.GetItemText(item) == data_name: |
---|
| 308 | data_child = item |
---|
| 309 | for process in data.process: |
---|
| 310 | theory_child = self.tree_ctrl.FindItem(data_child, |
---|
| 311 | "Available Theories")#, |
---|
| 312 | if theory is not None: |
---|
| 313 | av_theory_child =self.tree_ctrl.AppendItem(theory_child, |
---|
[584c4c4] | 314 | theory.name,ct_type=1, data=theory.id) |
---|
[3feed3e] | 315 | self.list_cb_theory.append(av_theory_child) |
---|
| 316 | av_theory_child_info =self.tree_ctrl.AppendItem(av_theory_child, |
---|
| 317 | 'info') |
---|
| 318 | for process in theory.process: |
---|
| 319 | info_time_child =self.tree_ctrl.AppendItem(av_theory_child_info, |
---|
| 320 | process.__str__()) |
---|
| 321 | |
---|
| 322 | break |
---|
| 323 | if data_child is None: |
---|
| 324 | data_child =self.tree_ctrl.InsertItem(self.tree_ctrl.root,0, |
---|
[584c4c4] | 325 | data_name,ct_type=1, data=data.id) |
---|
[3feed3e] | 326 | cb_data = self.tree_ctrl.GetFirstChild(self.tree_ctrl.root) |
---|
| 327 | item, id = cb_data |
---|
| 328 | item.Check(True) |
---|
| 329 | self.list_cb_data.append(item) |
---|
| 330 | data_info_child =self.tree_ctrl.AppendItem(data_child, 'info')#, |
---|
| 331 | #wnd=data_info_txt) |
---|
| 332 | info_class_child =self.tree_ctrl.AppendItem(data_info_child, |
---|
| 333 | 'Type: %s'%data_class) |
---|
| 334 | path_class_child =self.tree_ctrl.AppendItem(data_info_child, |
---|
| 335 | 'Path: %s'%str(path)) |
---|
| 336 | for process in data.process: |
---|
| 337 | info_time_child =self.tree_ctrl.AppendItem(data_info_child,process.__str__()) |
---|
| 338 | theory_child =self.tree_ctrl.AppendItem(data_child, "Available Theories") |
---|
| 339 | |
---|
| 340 | if theory_list: |
---|
| 341 | theory = theory_list[len(theory_list)-1] |
---|
| 342 | if theory is not None: |
---|
| 343 | av_theory_child =self.tree_ctrl.AppendItem(theory_child, |
---|
| 344 | theory.name,ct_type=1) |
---|
| 345 | self.list_cb_theory.append(av_theory_child) |
---|
| 346 | av_theory_child_info =self.tree_ctrl.AppendItem(av_theory_child, |
---|
| 347 | 'info') |
---|
| 348 | for process in theory.process: |
---|
| 349 | info_time_child =self.tree_ctrl.AppendItem(av_theory_child_info, |
---|
| 350 | process.__str__()) |
---|
| 351 | |
---|
| 352 | def set_data_helper(self): |
---|
[3c44c66] | 353 | """ |
---|
| 354 | """ |
---|
[3feed3e] | 355 | data_to_plot = [] |
---|
| 356 | for item in self.list_cb_data: |
---|
| 357 | if item.IsChecked(): |
---|
[213892bc] | 358 | |
---|
[584c4c4] | 359 | data_to_plot.append(self.tree_ctrl.GetItemPyData(item)) |
---|
| 360 | theory_to_plot = [] |
---|
[3feed3e] | 361 | for item in self.list_cb_theory: |
---|
| 362 | if item.IsChecked(): |
---|
[213892bc] | 363 | theory_to_plot.append(self.tree_ctrl.GetItemPyData(item)) |
---|
[3feed3e] | 364 | return data_to_plot, theory_to_plot |
---|
| 365 | |
---|
| 366 | def on_remove(self, event): |
---|
| 367 | data_to_remove, theory_to_remove = self.set_data_helper() |
---|
| 368 | for item in self.list_cb_data: |
---|
| 369 | if item.IsChecked()and \ |
---|
| 370 | self.tree_ctrl.GetItemText(item) in data_to_remove: |
---|
| 371 | self.tree_ctrl.Delete(item) |
---|
[213892bc] | 372 | for item in self.list_cb_theory: |
---|
[3feed3e] | 373 | if item.IsChecked()and \ |
---|
| 374 | self.tree_ctrl.GetItemText(item) in theory_to_remove: |
---|
| 375 | self.tree_ctrl.Delete(item) |
---|
[213892bc] | 376 | delete_all = False |
---|
| 377 | if data_to_remove: |
---|
| 378 | delete_all = True |
---|
| 379 | self.parent.delete_data(data_id=data_to_remove, |
---|
| 380 | theory_id=theory_to_remove, |
---|
| 381 | delete_all=delete_all) |
---|
[3c44c66] | 382 | |
---|
[3feed3e] | 383 | def on_import(self, event=None): |
---|
[3c44c66] | 384 | """ |
---|
[3feed3e] | 385 | Get all select data and set them to the current active perspetive |
---|
[3c44c66] | 386 | """ |
---|
[3feed3e] | 387 | self.post_helper(plot=False) |
---|
[213892bc] | 388 | |
---|
| 389 | def on_append_plot(self, event=None): |
---|
| 390 | """ |
---|
| 391 | append plot to plot panel on focus |
---|
| 392 | """ |
---|
| 393 | self.post_helper(plot=True, append=True) |
---|
| 394 | |
---|
[3feed3e] | 395 | def on_plot(self, event=None): |
---|
[3c44c66] | 396 | """ |
---|
[3feed3e] | 397 | Send a list of data names to plot |
---|
[3c44c66] | 398 | """ |
---|
[3feed3e] | 399 | self.post_helper(plot=True) |
---|
| 400 | |
---|
| 401 | def set_active_perspective(self, name): |
---|
[3c44c66] | 402 | """ |
---|
[3feed3e] | 403 | set the active perspective |
---|
[3c44c66] | 404 | """ |
---|
[3feed3e] | 405 | self.tctrl_perspective.SetLabel(str(name)) |
---|
[c5e84fb] | 406 | |
---|
[3feed3e] | 407 | def set_panel_on_focus(self, name): |
---|
[3c44c66] | 408 | """ |
---|
[3feed3e] | 409 | set the plot panel on focus |
---|
[3c44c66] | 410 | """ |
---|
[3feed3e] | 411 | self.tctrl_plotpanel.SetLabel(str(name)) |
---|
[3c44c66] | 412 | |
---|
[213892bc] | 413 | def post_helper(self, plot=False, append=False): |
---|
[3c44c66] | 414 | """ |
---|
| 415 | """ |
---|
[3feed3e] | 416 | data_to_plot, theory_to_plot = self.set_data_helper() |
---|
[584c4c4] | 417 | |
---|
| 418 | if self.parent is not None: |
---|
[213892bc] | 419 | self.parent.get_data_from_panel(data_id=data_to_plot, plot=plot, |
---|
| 420 | append=append) |
---|
[3feed3e] | 421 | |
---|
[3c44c66] | 422 | |
---|
| 423 | class DataFrame(wx.Frame): |
---|
[3feed3e] | 424 | ## Internal name for the AUI manager |
---|
| 425 | window_name = "Data Panel" |
---|
| 426 | ## Title to appear on top of the window |
---|
| 427 | window_caption = "Data Panel" |
---|
| 428 | ## Flag to tell the GUI manager that this panel is not |
---|
| 429 | # tied to any perspective |
---|
| 430 | ALWAYS_ON = True |
---|
| 431 | |
---|
| 432 | def __init__(self, parent=None, owner=None, manager=None,size=(600, 600), |
---|
| 433 | list_of_perspective=[],list=[], *args, **kwds): |
---|
| 434 | #kwds['size'] = size |
---|
[3c44c66] | 435 | kwds['id'] = -1 |
---|
[3feed3e] | 436 | kwds['title']= "Loaded Data" |
---|
[3c44c66] | 437 | wx.Frame.__init__(self, parent=parent, *args, **kwds) |
---|
| 438 | self.parent = parent |
---|
| 439 | self.owner = owner |
---|
| 440 | self.manager = manager |
---|
[32c0841] | 441 | self.panel = DataPanel(parent=self, |
---|
[3feed3e] | 442 | size=size, |
---|
[32c0841] | 443 | list_of_perspective=list_of_perspective) |
---|
[3feed3e] | 444 | |
---|
| 445 | def load_data_list(self, list=[]): |
---|
[3c44c66] | 446 | """ |
---|
| 447 | Fill the list inside its panel |
---|
| 448 | """ |
---|
[3feed3e] | 449 | self.panel.load_data_list(list=list) |
---|
[3c44c66] | 450 | |
---|
[3feed3e] | 451 | def layout_perspective(self, list_of_perspective=[]): |
---|
[3c44c66] | 452 | """ |
---|
| 453 | """ |
---|
| 454 | self.panel.layout_perspective(list_of_perspective=list_of_perspective) |
---|
[32c0841] | 455 | |
---|
[3feed3e] | 456 | |
---|
| 457 | from dataFitting import Data1D |
---|
| 458 | from dataFitting import Data2D, Theory1D |
---|
| 459 | from data_state import DataState |
---|
| 460 | import sys |
---|
| 461 | class State(): |
---|
| 462 | def __init__(self): |
---|
| 463 | self.msg = "" |
---|
| 464 | def __str__(self): |
---|
| 465 | self.msg = "model mane : model1\n" |
---|
| 466 | self.msg += "params : \n" |
---|
| 467 | self.msg += "name value\n" |
---|
| 468 | return msg |
---|
| 469 | def set_data_state(data, path, theory, state): |
---|
| 470 | dstate = DataState(data=data) |
---|
| 471 | dstate.set_path(path=path) |
---|
| 472 | dstate.set_theory(theory) |
---|
| 473 | dstate.set_state(state) |
---|
| 474 | return dstate |
---|
| 475 | """' |
---|
| 476 | data_list = [1:('Data1', 'Data1D', '07/01/2010', "theory1d", "state1"), |
---|
| 477 | ('Data2', 'Data2D', '07/03/2011', "theory2d", "state1"), |
---|
| 478 | ('Data3', 'Theory1D', '06/01/2010', "theory1d", "state1"), |
---|
| 479 | ('Data4', 'Theory2D', '07/01/2010', "theory2d", "state1"), |
---|
| 480 | ('Data5', 'Theory2D', '07/02/2010', "theory2d", "state1")] |
---|
| 481 | """ |
---|
[3c44c66] | 482 | if __name__ == "__main__": |
---|
[3feed3e] | 483 | |
---|
[3c44c66] | 484 | app = wx.App() |
---|
[3feed3e] | 485 | try: |
---|
| 486 | list_of_perspective = [('perspective2', False), ('perspective1', True)] |
---|
| 487 | data_list = {} |
---|
| 488 | data = Data1D() |
---|
| 489 | data.name = "data1" |
---|
[584c4c4] | 490 | data.id = 1 |
---|
[3feed3e] | 491 | #data.append_process() |
---|
| 492 | #process = data.process[len(data.process)-1] |
---|
| 493 | #process.data = "07/01/2010" |
---|
| 494 | theory = Theory1D() |
---|
[584c4c4] | 495 | theory.id = 34 |
---|
[3feed3e] | 496 | theory.pseudo_name = "theory1" |
---|
| 497 | path = "path1" |
---|
| 498 | state = State() |
---|
| 499 | data_list['1']=set_data_state(data, path,theory, state) |
---|
| 500 | |
---|
| 501 | data = Data1D() |
---|
| 502 | data.name = "data2" |
---|
[584c4c4] | 503 | data.id = 76 |
---|
[3feed3e] | 504 | theory = Theory1D() |
---|
[584c4c4] | 505 | theory.id = 78 |
---|
[3feed3e] | 506 | theory.name = "CoreShell 07/24/25" |
---|
| 507 | theory.pseudo_name = "CoreShell" |
---|
| 508 | path = "path2" |
---|
| 509 | state = State() |
---|
| 510 | data_list['2']=set_data_state(data, path,theory, state) |
---|
| 511 | data = Data1D() |
---|
[584c4c4] | 512 | data.id = 3 |
---|
[3feed3e] | 513 | data.name = "data2" |
---|
| 514 | theory = Theory1D() |
---|
| 515 | theory.name = "CoreShell" |
---|
| 516 | theory.pseudo_name = "CoreShell" |
---|
[584c4c4] | 517 | theory.id = 4 |
---|
[3feed3e] | 518 | #theory.append_process() |
---|
| 519 | #process = theory.process[len(theory.process)-1] |
---|
| 520 | #process.description = "this is my description" |
---|
| 521 | path = "path3" |
---|
| 522 | #data.append_process() |
---|
| 523 | #process = data.process[len(data.process)-1] |
---|
| 524 | #process.data = "07/22/2010" |
---|
| 525 | data_list['4']=set_data_state(data, path,theory, state) |
---|
| 526 | |
---|
| 527 | data = Data2D() |
---|
| 528 | data.name = "data3" |
---|
[584c4c4] | 529 | data.id = 5 |
---|
[3feed3e] | 530 | #data.append_process() |
---|
| 531 | #process = data.process[len(data.process)-1] |
---|
| 532 | #process.data = "07/01/2010" |
---|
| 533 | theory = Theory1D() |
---|
| 534 | theory.pseudo_name = "Cylinder" |
---|
| 535 | path = "path2" |
---|
| 536 | state = State() |
---|
| 537 | dstate= set_data_state(data, path,theory, state) |
---|
| 538 | theory = Theory1D() |
---|
[584c4c4] | 539 | theory.id = 6 |
---|
[3feed3e] | 540 | theory.pseudo_name = "Sphere" |
---|
| 541 | dstate.set_theory(theory) |
---|
| 542 | data_list['3']=dstate |
---|
| 543 | |
---|
| 544 | window = DataFrame(list=data_list) |
---|
| 545 | window.load_data_list(list=data_list) |
---|
| 546 | window.layout_perspective(list_of_perspective=list_of_perspective) |
---|
| 547 | window.Show(True) |
---|
| 548 | except: |
---|
| 549 | #raise |
---|
| 550 | print "error",sys.exc_value |
---|
[3c44c66] | 551 | app.MainLoop() |
---|
| 552 | |
---|
| 553 | |
---|