[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 | """ |
---|
[6db811e] | 27 | def __init__(self, parent,*args, **kwds): |
---|
[3feed3e] | 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 | CT.CustomTreeCtrl.__init__(self, parent, *args, **kwds) |
---|
| 31 | self.root = self.AddRoot("Available Data") |
---|
[3c44c66] | 32 | |
---|
| 33 | class DataPanel(ScrolledPanel): |
---|
| 34 | """ |
---|
| 35 | This panel displays data available in the application and widgets to |
---|
| 36 | interact with data. |
---|
| 37 | """ |
---|
[3feed3e] | 38 | ## Internal name for the AUI manager |
---|
| 39 | window_name = "Data Panel" |
---|
| 40 | ## Title to appear on top of the window |
---|
| 41 | window_caption = "Data Panel" |
---|
| 42 | #type of window |
---|
| 43 | window_type = "Data Panel" |
---|
| 44 | ## Flag to tell the GUI manager that this panel is not |
---|
| 45 | # tied to any perspective |
---|
| 46 | #ALWAYS_ON = True |
---|
| 47 | def __init__(self, parent, list=[],list_of_perspective=[], |
---|
| 48 | size=(PANEL_WIDTH,560), manager=None, *args, **kwds): |
---|
| 49 | kwds['size']= size |
---|
[3c44c66] | 50 | ScrolledPanel.__init__(self, parent=parent, *args, **kwds) |
---|
| 51 | self.SetupScrolling() |
---|
[3feed3e] | 52 | |
---|
[3c44c66] | 53 | self.parent = parent |
---|
[3feed3e] | 54 | self.manager = manager |
---|
[3c44c66] | 55 | self.list_of_data = list |
---|
[3feed3e] | 56 | self.list_of_perspective = list_of_perspective |
---|
| 57 | self.list_rb_perspectives= [] |
---|
| 58 | self.list_cb_data =[] |
---|
| 59 | self.list_cb_theory =[] |
---|
| 60 | self.owner = None |
---|
| 61 | self.do_layout() |
---|
[6db811e] | 62 | |
---|
[3feed3e] | 63 | def do_layout(self): |
---|
[6db811e] | 64 | """ |
---|
| 65 | """ |
---|
[3c44c66] | 66 | self.define_panel_structure() |
---|
| 67 | self.layout_selection() |
---|
[3feed3e] | 68 | self.layout_list() |
---|
[3c44c66] | 69 | self.layout_button() |
---|
[3feed3e] | 70 | self.layout_batch() |
---|
| 71 | |
---|
[3c44c66] | 72 | def define_panel_structure(self): |
---|
| 73 | """ |
---|
| 74 | Define the skeleton of the panel |
---|
| 75 | """ |
---|
[3feed3e] | 76 | w, h = self.parent.GetSize() |
---|
[3c44c66] | 77 | self.vbox = wx.BoxSizer(wx.VERTICAL) |
---|
| 78 | self.sizer1 = wx.BoxSizer(wx.VERTICAL) |
---|
[6db811e] | 79 | self.sizer1.SetMinSize((w/12, h/2)) |
---|
[3feed3e] | 80 | self.sizer2 = wx.BoxSizer(wx.VERTICAL) |
---|
| 81 | self.sizer3 = wx.GridBagSizer(5,5) |
---|
[3c44c66] | 82 | self.sizer4 = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 83 | self.sizer5 = wx.BoxSizer(wx.HORIZONTAL) |
---|
[6db811e] | 84 | #self.sizer3.SetMinSize((w-60, -1)) |
---|
[3feed3e] | 85 | |
---|
| 86 | self.vbox.Add(self.sizer5, 0,wx.EXPAND|wx.ALL,10) |
---|
| 87 | self.vbox.Add(self.sizer1, 0,wx.EXPAND|wx.ALL,0) |
---|
| 88 | self.vbox.Add(self.sizer2, 0,wx.EXPAND|wx.ALL,10) |
---|
| 89 | self.vbox.Add(self.sizer3, 0,wx.EXPAND|wx.ALL,10) |
---|
| 90 | self.vbox.Add(self.sizer4, 0,wx.EXPAND|wx.ALL,10) |
---|
| 91 | |
---|
[3c44c66] | 92 | self.SetSizer(self.vbox) |
---|
| 93 | |
---|
[3feed3e] | 94 | def layout_selection(self): |
---|
[3c44c66] | 95 | """ |
---|
| 96 | """ |
---|
[3feed3e] | 97 | select_txt = wx.StaticText(self, -1, 'Selection Options') |
---|
| 98 | self.selection_cbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) |
---|
| 99 | list_of_options = ['Select all Data', |
---|
| 100 | 'Unselect all Data', |
---|
| 101 | 'Select all Data 1D', |
---|
| 102 | 'Unselect all Data 1D', |
---|
| 103 | 'Select all Data 2D', |
---|
| 104 | 'Unselect all Data 2D' ] |
---|
| 105 | for option in list_of_options: |
---|
| 106 | self.selection_cbox.Append(str(option)) |
---|
| 107 | self.selection_cbox.SetValue('None') |
---|
| 108 | wx.EVT_COMBOBOX(self.selection_cbox,-1, self._on_selection_type) |
---|
| 109 | self.sizer5.AddMany([(select_txt,0, wx.ALL,5), |
---|
| 110 | (self.selection_cbox,0, wx.ALL,5)]) |
---|
| 111 | def layout_perspective(self, list_of_perspective=[]): |
---|
[3c44c66] | 112 | """ |
---|
| 113 | Layout widgets related to the list of plug-ins of the gui_manager |
---|
| 114 | """ |
---|
[3feed3e] | 115 | if len(list_of_perspective)==0: |
---|
| 116 | return |
---|
| 117 | w, h = self.parent.GetSize() |
---|
| 118 | box_description_2= wx.StaticBox(self, -1, "Set Active Perspective") |
---|
| 119 | self.boxsizer_2 = wx.StaticBoxSizer(box_description_2, wx.HORIZONTAL) |
---|
| 120 | self.sizer_perspective = wx.GridBagSizer(5,5) |
---|
| 121 | self.boxsizer_2.Add(self.sizer_perspective) |
---|
| 122 | self.sizer2.Add(self.boxsizer_2,1, wx.ALL, 10) |
---|
| 123 | self.list_of_perspective = list_of_perspective |
---|
| 124 | self.sizer_perspective.Clear(True) |
---|
| 125 | self.list_rb_perspectives = [] |
---|
| 126 | |
---|
| 127 | nb_active_perspective = 0 |
---|
[3c44c66] | 128 | if list_of_perspective: |
---|
| 129 | ix = 0 |
---|
| 130 | iy = 0 |
---|
[3feed3e] | 131 | for perspective_name, is_active in list_of_perspective: |
---|
| 132 | |
---|
| 133 | if is_active: |
---|
| 134 | nb_active_perspective += 1 |
---|
| 135 | if nb_active_perspective == 1: |
---|
| 136 | rb = wx.RadioButton(self, -1, perspective_name, style=wx.RB_GROUP) |
---|
| 137 | rb.SetToolTipString("Data will be applied to this perspective") |
---|
| 138 | rb.SetValue(is_active) |
---|
| 139 | else: |
---|
| 140 | rb = wx.RadioButton(self, -1, perspective_name) |
---|
| 141 | rb.SetToolTipString("Data will be applied to this perspective") |
---|
| 142 | #only one perpesctive can be active |
---|
| 143 | rb.SetValue(False) |
---|
| 144 | |
---|
| 145 | self.Bind(wx.EVT_RADIOBUTTON, self.on_set_active_perspective, |
---|
| 146 | id=rb.GetId()) |
---|
| 147 | self.list_rb_perspectives.append(rb) |
---|
| 148 | self.sizer_perspective.Add(rb,(iy, ix),(1,1), |
---|
| 149 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
[3c44c66] | 150 | iy += 1 |
---|
| 151 | else: |
---|
| 152 | rb = wx.RadioButton(self, -1, 'No Perspective', |
---|
| 153 | style=wx.RB_GROUP) |
---|
| 154 | rb.SetValue(True) |
---|
| 155 | rb.Disable() |
---|
| 156 | ix = 0 |
---|
| 157 | iy = 0 |
---|
[3feed3e] | 158 | self.sizer_perspective.Add(rb,(iy, ix),(1,1), |
---|
[3c44c66] | 159 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
[3feed3e] | 160 | |
---|
| 161 | def _on_selection_type(self, event): |
---|
[3c44c66] | 162 | """ |
---|
[3feed3e] | 163 | Select data according to patterns |
---|
[3c44c66] | 164 | """ |
---|
[3feed3e] | 165 | option = self.selection_cbox.GetValue() |
---|
| 166 | if option == 'Select all Data': |
---|
[6db811e] | 167 | print "on select" |
---|
| 168 | |
---|
[3feed3e] | 169 | def on_set_active_perspective(self, event): |
---|
[3c44c66] | 170 | """ |
---|
[3feed3e] | 171 | Select the active perspective |
---|
| 172 | """ |
---|
| 173 | ctrl = event.GetEventObject() |
---|
[3c44c66] | 174 | |
---|
| 175 | def layout_button(self): |
---|
| 176 | """ |
---|
| 177 | Layout widgets related to buttons |
---|
| 178 | """ |
---|
[3feed3e] | 179 | self.bt_import = wx.Button(self, wx.NewId(), "Send To") |
---|
| 180 | self.bt_import.SetToolTipString("Send set of Data to active perspective") |
---|
[3c44c66] | 181 | wx.EVT_BUTTON(self, self.bt_import.GetId(), self.on_import) |
---|
| 182 | |
---|
[3feed3e] | 183 | self.bt_append_plot = wx.Button(self, wx.NewId(), "Append Plot To") |
---|
[213892bc] | 184 | self.bt_append_plot.SetToolTipString("Plot the selected data in the active panel") |
---|
| 185 | wx.EVT_BUTTON(self, self.bt_append_plot.GetId(), self.on_append_plot) |
---|
[3feed3e] | 186 | |
---|
| 187 | self.bt_plot = wx.Button(self, wx.NewId(), "New Plot") |
---|
[3c44c66] | 188 | self.bt_plot.SetToolTipString("To trigger plotting") |
---|
| 189 | wx.EVT_BUTTON(self, self.bt_plot.GetId(), self.on_plot) |
---|
| 190 | |
---|
[3feed3e] | 191 | self.bt_remove = wx.Button(self, wx.NewId(), "Delete Data") |
---|
| 192 | self.bt_remove.SetToolTipString("Delete data from the application") |
---|
| 193 | wx.EVT_BUTTON(self, self.bt_remove.GetId(), self.on_remove) |
---|
| 194 | |
---|
[c5e84fb] | 195 | self.tctrl_perspective = wx.StaticText(self, -1, 'No Active Application') |
---|
[3feed3e] | 196 | self.tctrl_perspective.SetToolTipString("Active Application") |
---|
[213892bc] | 197 | self.tctrl_plotpanel = wx.StaticText(self, -1, 'No Plot panel on focus') |
---|
| 198 | self.tctrl_plotpanel.SetToolTipString("Active Plot Panel") |
---|
[3feed3e] | 199 | #self.sizer3.AddMany([(self.bt_import,0, wx.ALL,5), |
---|
| 200 | # (self.bt_append_plot,0, wx.ALL,5), |
---|
| 201 | # (self.bt_plot, 0, wx.ALL,5), |
---|
| 202 | # (self.bt_remove,0, wx.ALL,5)]) |
---|
| 203 | ix = 0 |
---|
| 204 | iy = 0 |
---|
| 205 | self.sizer3.Add(self.bt_import,( iy, ix),(1,1), |
---|
| 206 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 207 | ix += 1 |
---|
| 208 | self.sizer3.Add(self.tctrl_perspective,(iy, ix),(1,1), |
---|
| 209 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 210 | ix = 0 |
---|
| 211 | iy += 1 |
---|
| 212 | self.sizer3.Add(self.bt_append_plot,( iy, ix),(1,1), |
---|
| 213 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 214 | ix += 1 |
---|
| 215 | self.sizer3.Add(self.tctrl_plotpanel,(iy, ix),(1,1), |
---|
| 216 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 217 | ix = 0 |
---|
| 218 | iy += 1 |
---|
| 219 | self.sizer3.Add(self.bt_plot,( iy, ix),(1,1), |
---|
| 220 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 221 | ix = 0 |
---|
| 222 | iy += 1 |
---|
| 223 | self.sizer3.Add(self.bt_remove,( iy, ix),(1,1), |
---|
| 224 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 225 | |
---|
| 226 | |
---|
| 227 | def layout_batch(self): |
---|
[3c44c66] | 228 | """ |
---|
| 229 | """ |
---|
[3feed3e] | 230 | |
---|
| 231 | self.rb_single_mode = wx.RadioButton(self, -1, 'Single Mode', |
---|
| 232 | style=wx.RB_GROUP) |
---|
| 233 | self.rb_batch_mode = wx.RadioButton(self, -1, 'Batch Mode') |
---|
| 234 | |
---|
| 235 | self.rb_single_mode.SetValue(True) |
---|
| 236 | self.rb_batch_mode.SetValue(False) |
---|
| 237 | self.sizer4.AddMany([(self.rb_single_mode,0, wx.ALL,5), |
---|
| 238 | (self.rb_batch_mode,0, wx.ALL,5)]) |
---|
| 239 | |
---|
| 240 | def layout_list(self): |
---|
[3c44c66] | 241 | """ |
---|
[3feed3e] | 242 | Add a listcrtl in the panel |
---|
[3c44c66] | 243 | """ |
---|
[6db811e] | 244 | self.tree_ctrl = DataTreeCtrl(parent=self) |
---|
[3feed3e] | 245 | self.tree_ctrl.Bind(CT.EVT_TREE_ITEM_CHECKED, self.on_check_item) |
---|
| 246 | self.tree_ctrl.Bind(CT.EVT_TREE_ITEM_RIGHT_CLICK, self.on_right_click) |
---|
[6db811e] | 247 | self.sizer1.Add(self.tree_ctrl,1, wx.EXPAND|wx.ALL, 20) |
---|
[3feed3e] | 248 | |
---|
| 249 | def on_right_click(self, event): |
---|
[3c44c66] | 250 | """ |
---|
| 251 | """ |
---|
[3feed3e] | 252 | ## Create context menu for data |
---|
| 253 | self.popUpMenu = wx.Menu() |
---|
| 254 | msg = "Edit %s"%str(self.tree_ctrl.GetItemText(event.GetItem())) |
---|
| 255 | id = wx.NewId() |
---|
| 256 | self.edit_data_mitem = wx.MenuItem(self.popUpMenu,id,msg, |
---|
| 257 | "Edit meta data") |
---|
| 258 | wx.EVT_MENU(self, id, self.on_edit_data) |
---|
| 259 | self.popUpMenu.AppendItem(self.edit_data_mitem) |
---|
| 260 | self.Bind(wx.EVT_CONTEXT_MENU, self.onContextMenu) |
---|
[3c44c66] | 261 | |
---|
[3feed3e] | 262 | def on_edit_data(self, event): |
---|
[3c44c66] | 263 | """ |
---|
| 264 | """ |
---|
[3feed3e] | 265 | print "editing data" |
---|
[c5e84fb] | 266 | |
---|
[3feed3e] | 267 | def onContextMenu(self, event): |
---|
[3c44c66] | 268 | """ |
---|
[3feed3e] | 269 | Retrieve the state selected state |
---|
[3c44c66] | 270 | """ |
---|
[3feed3e] | 271 | # Skipping the save state functionality for release 0.9.0 |
---|
| 272 | #return |
---|
| 273 | pos = event.GetPosition() |
---|
| 274 | pos = self.ScreenToClient(pos) |
---|
| 275 | self.PopupMenu(self.popUpMenu, pos) |
---|
| 276 | |
---|
| 277 | def on_check_item(self, event): |
---|
[3c44c66] | 278 | """ |
---|
| 279 | """ |
---|
[3feed3e] | 280 | item = event.GetItem() |
---|
[c5e84fb] | 281 | name = self.tree_ctrl.GetItemText(item) |
---|
[3feed3e] | 282 | |
---|
| 283 | def load_data_list(self, list): |
---|
[3c44c66] | 284 | """ |
---|
| 285 | |
---|
| 286 | """ |
---|
[3feed3e] | 287 | if not list: |
---|
| 288 | return |
---|
[3c44c66] | 289 | |
---|
[3feed3e] | 290 | for dstate in list.values(): |
---|
| 291 | data = dstate.get_data() |
---|
| 292 | if data is None: |
---|
| 293 | data_name = str(data) |
---|
| 294 | data_class = "unkonwn" |
---|
| 295 | else: |
---|
| 296 | data_name = data.name |
---|
| 297 | data_class = data.__class__.__name__ |
---|
| 298 | path = dstate.get_path() |
---|
| 299 | theory_list = dstate.get_theory() |
---|
| 300 | theory = None |
---|
| 301 | if theory_list: |
---|
| 302 | theory = theory_list[len(theory_list)-1] |
---|
| 303 | data_child = None |
---|
| 304 | for item in self.list_cb_data: |
---|
| 305 | if self.tree_ctrl.GetItemText(item) == data_name: |
---|
| 306 | data_child = item |
---|
| 307 | for process in data.process: |
---|
| 308 | theory_child = self.tree_ctrl.FindItem(data_child, |
---|
| 309 | "Available Theories")#, |
---|
| 310 | if theory is not None: |
---|
| 311 | av_theory_child =self.tree_ctrl.AppendItem(theory_child, |
---|
[584c4c4] | 312 | theory.name,ct_type=1, data=theory.id) |
---|
[3feed3e] | 313 | self.list_cb_theory.append(av_theory_child) |
---|
| 314 | av_theory_child_info =self.tree_ctrl.AppendItem(av_theory_child, |
---|
| 315 | 'info') |
---|
| 316 | for process in theory.process: |
---|
| 317 | info_time_child =self.tree_ctrl.AppendItem(av_theory_child_info, |
---|
| 318 | process.__str__()) |
---|
| 319 | |
---|
| 320 | break |
---|
| 321 | if data_child is None: |
---|
| 322 | data_child =self.tree_ctrl.InsertItem(self.tree_ctrl.root,0, |
---|
[584c4c4] | 323 | data_name,ct_type=1, data=data.id) |
---|
[3feed3e] | 324 | cb_data = self.tree_ctrl.GetFirstChild(self.tree_ctrl.root) |
---|
| 325 | item, id = cb_data |
---|
| 326 | item.Check(True) |
---|
| 327 | self.list_cb_data.append(item) |
---|
| 328 | data_info_child =self.tree_ctrl.AppendItem(data_child, 'info')#, |
---|
| 329 | #wnd=data_info_txt) |
---|
| 330 | info_class_child =self.tree_ctrl.AppendItem(data_info_child, |
---|
| 331 | 'Type: %s'%data_class) |
---|
| 332 | path_class_child =self.tree_ctrl.AppendItem(data_info_child, |
---|
| 333 | 'Path: %s'%str(path)) |
---|
| 334 | for process in data.process: |
---|
| 335 | info_time_child =self.tree_ctrl.AppendItem(data_info_child,process.__str__()) |
---|
| 336 | theory_child =self.tree_ctrl.AppendItem(data_child, "Available Theories") |
---|
| 337 | |
---|
| 338 | if theory_list: |
---|
| 339 | theory = theory_list[len(theory_list)-1] |
---|
| 340 | if theory is not None: |
---|
| 341 | av_theory_child =self.tree_ctrl.AppendItem(theory_child, |
---|
| 342 | theory.name,ct_type=1) |
---|
| 343 | self.list_cb_theory.append(av_theory_child) |
---|
| 344 | av_theory_child_info =self.tree_ctrl.AppendItem(av_theory_child, |
---|
| 345 | 'info') |
---|
| 346 | for process in theory.process: |
---|
| 347 | info_time_child =self.tree_ctrl.AppendItem(av_theory_child_info, |
---|
| 348 | process.__str__()) |
---|
| 349 | |
---|
| 350 | def set_data_helper(self): |
---|
[3c44c66] | 351 | """ |
---|
| 352 | """ |
---|
[3feed3e] | 353 | data_to_plot = [] |
---|
| 354 | for item in self.list_cb_data: |
---|
| 355 | if item.IsChecked(): |
---|
[213892bc] | 356 | |
---|
[584c4c4] | 357 | data_to_plot.append(self.tree_ctrl.GetItemPyData(item)) |
---|
| 358 | theory_to_plot = [] |
---|
[3feed3e] | 359 | for item in self.list_cb_theory: |
---|
| 360 | if item.IsChecked(): |
---|
[213892bc] | 361 | theory_to_plot.append(self.tree_ctrl.GetItemPyData(item)) |
---|
[3feed3e] | 362 | return data_to_plot, theory_to_plot |
---|
| 363 | |
---|
| 364 | def on_remove(self, event): |
---|
| 365 | data_to_remove, theory_to_remove = self.set_data_helper() |
---|
| 366 | for item in self.list_cb_data: |
---|
| 367 | if item.IsChecked()and \ |
---|
| 368 | self.tree_ctrl.GetItemText(item) in data_to_remove: |
---|
| 369 | self.tree_ctrl.Delete(item) |
---|
[213892bc] | 370 | for item in self.list_cb_theory: |
---|
[3feed3e] | 371 | if item.IsChecked()and \ |
---|
| 372 | self.tree_ctrl.GetItemText(item) in theory_to_remove: |
---|
| 373 | self.tree_ctrl.Delete(item) |
---|
[213892bc] | 374 | delete_all = False |
---|
| 375 | if data_to_remove: |
---|
| 376 | delete_all = True |
---|
| 377 | self.parent.delete_data(data_id=data_to_remove, |
---|
| 378 | theory_id=theory_to_remove, |
---|
| 379 | delete_all=delete_all) |
---|
[3c44c66] | 380 | |
---|
[3feed3e] | 381 | def on_import(self, event=None): |
---|
[3c44c66] | 382 | """ |
---|
[3feed3e] | 383 | Get all select data and set them to the current active perspetive |
---|
[3c44c66] | 384 | """ |
---|
[3feed3e] | 385 | self.post_helper(plot=False) |
---|
[213892bc] | 386 | |
---|
| 387 | def on_append_plot(self, event=None): |
---|
| 388 | """ |
---|
| 389 | append plot to plot panel on focus |
---|
| 390 | """ |
---|
| 391 | self.post_helper(plot=True, append=True) |
---|
| 392 | |
---|
[3feed3e] | 393 | def on_plot(self, event=None): |
---|
[3c44c66] | 394 | """ |
---|
[3feed3e] | 395 | Send a list of data names to plot |
---|
[3c44c66] | 396 | """ |
---|
[3feed3e] | 397 | self.post_helper(plot=True) |
---|
| 398 | |
---|
| 399 | def set_active_perspective(self, name): |
---|
[3c44c66] | 400 | """ |
---|
[3feed3e] | 401 | set the active perspective |
---|
[3c44c66] | 402 | """ |
---|
[3feed3e] | 403 | self.tctrl_perspective.SetLabel(str(name)) |
---|
[c5e84fb] | 404 | |
---|
[3feed3e] | 405 | def set_panel_on_focus(self, name): |
---|
[3c44c66] | 406 | """ |
---|
[3feed3e] | 407 | set the plot panel on focus |
---|
[3c44c66] | 408 | """ |
---|
[3feed3e] | 409 | self.tctrl_plotpanel.SetLabel(str(name)) |
---|
[3c44c66] | 410 | |
---|
[213892bc] | 411 | def post_helper(self, plot=False, append=False): |
---|
[3c44c66] | 412 | """ |
---|
| 413 | """ |
---|
[3feed3e] | 414 | data_to_plot, theory_to_plot = self.set_data_helper() |
---|
[584c4c4] | 415 | |
---|
| 416 | if self.parent is not None: |
---|
[213892bc] | 417 | self.parent.get_data_from_panel(data_id=data_to_plot, plot=plot, |
---|
| 418 | append=append) |
---|
[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 | |
---|