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