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