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