Changeset 4e1c362 in sasview for invariantview/perspectives/invariant
- Timestamp:
- Jul 16, 2010 9:24:21 AM (14 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- b5a21aa
- Parents:
- 855546d
- Location:
- invariantview/perspectives/invariant
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
invariantview/perspectives/invariant/invariant.py
rd7a39e5 r4e1c362 11 11 #copyright 2009, University of Tennessee 12 12 ################################################################################ 13 13 import os 14 import sys 14 15 import wx 15 16 import copy 17 import logging, time 16 18 from sans.invariant import invariant 17 19 … … 21 23 from sans.guicomm.events import NewPlotEvent, StatusEvent 22 24 from sans.guicomm.events import ERR_DATA 25 from invariant_state import Reader as reader 26 from DataLoader.loader import Loader 27 from invariant_panel import InvariantPanel 23 28 24 29 class Plugin: 25 30 """ 26 31 This class defines the interface for invariant Plugin class 27 that can be used by the gui_manager. 28 32 that can be used by the gui_manager. 29 33 """ 30 34 … … 43 47 # for your plug-in. This defines your plug-in "perspective" 44 48 self.perspective = [] 49 50 self.state_reader = None 51 """ 52 # Create a CanSAS/Pr reader 53 self.state_reader = Reader(self.set_state) 54 l = Loader() 55 l.associate_file_reader('.inv', self.state_reader) 56 """ 57 # Log startup 58 logging.info("Invariant plug-in started") 45 59 46 60 def populate_menu(self, id, parent): … … 53 67 54 68 :return: plug-in menu 55 56 69 """ 57 70 return [] … … 60 73 """ 61 74 Show a general help dialog. 62 63 75 """ 64 76 from help_panel import HelpWindow … … 78 90 79 91 :return: list of panels 80 81 92 """ 82 93 ## Save a reference to the parent … … 84 95 #add error back to the data 85 96 self.parent.Bind(ERR_DATA, self._on_data_error) 86 from invariant_panel import InvariantPanel 97 98 87 99 self.invariant_panel = InvariantPanel(parent=self.parent) 88 100 self.invariant_panel.set_manager(manager=self) 89 self.perspective.append(self.invariant_panel.window_name) 101 self.perspective.append(self.invariant_panel.window_name) 102 #Create reader when fitting panel are created 103 self.state_reader = reader(self.set_state) 104 #append that reader to list of available reader 105 loader = Loader() 106 loader.associate_file_reader(".inv", self.state_reader) 90 107 # Return the list of panels 91 108 return [self.invariant_panel] … … 118 135 119 136 :return: a list of menu items with call-back function 120 121 137 """ 122 138 self.graph = graph … … 148 164 149 165 :param event: menu event 150 151 166 """ 152 167 self.parent.set_perspective(self.perspective) … … 171 186 receive a data 1D and the list of errors on dy 172 187 and create a new data1D data 173 174 188 """ 175 189 id = None … … 182 196 data.dy = dy 183 197 data.name = item.name 198 184 199 ## allow to highlight data when plotted 185 200 data.interactive = item.interactive … … 217 232 # Set the data set to be user for invariant calculation 218 233 self.invariant_panel.set_data(data=data) 234 235 def save_file(self, filepath, state=None): 236 """ 237 Save data in provided state object. 238 239 :param filepath: path of file to write to 240 :param state: invariant state 241 """ 242 243 # Write the state to file 244 # First, check that the data is of the right type 245 246 current_plottable = self.__data 247 248 if issubclass(current_plottable.__class__, LoaderData1D): 249 self.state_reader.write(filepath, current_plottable, state) 250 else: 251 raise RuntimeError, "invariant.save_file: the data being saved is not a DataLoader.data_info.Data1D object" 252 253 def set_state(self, state, datainfo=None): 254 """ 255 Call-back method for the state reader. 256 This method is called when a .inv file is loaded. 257 258 :param state: State object 259 """ 260 261 try: 262 if datainfo is None: 263 raise RuntimeError, "invariant.set_state: datainfo parameter cannot be None in standalone mode" 264 datainfo.meta_data['invstate'].file = datainfo.meta_data['invstate'].file+"_copy" 265 datainfo.name = datainfo.meta_data['invstate'].file 266 datainfo.filename = datainfo.meta_data['invstate'].file 267 self.__data = datainfo 268 self.__data.group_id = datainfo.filename 269 self.__data.id = datainfo.filename 270 271 temp_state = copy.deepcopy(state) 272 273 # Load the invariant states 274 # Make sure the user sees the invariant panel after loading 275 self.parent.set_perspective(self.perspective) 276 277 # set state 278 self.invariant_panel.set_state(state=temp_state,data=self.__data) 279 280 except: 281 logging.error("invariant.set_state: %s" % sys.exc_value) 282 283 219 284 220 285 def plot_theory(self, data=None, name=None): … … 224 289 :param data: extrapolated data to be plotted 225 290 :param name: Data's name to use for the legend 226 227 """291 """ 292 import copy 228 293 if data is None: 229 294 new_plot = Theory1D(x=[], y=[], dy=None) … … 245 310 new_plot.group_id = self.__data.group_id 246 311 new_plot.id = self.__data.id + name 312 # Save theory_data in a state 313 if data != None: 314 name_head = name.split('-') 315 if name_head[0]=='Low': 316 self.invariant_panel.state.theory_lowQ = copy.deepcopy(new_plot) 317 elif name_head[0]=='High': 318 self.invariant_panel.state.theory_highQ = copy.deepcopy(new_plot) 319 247 320 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=self.__data.name)) 248 321 … … 255 328 new_plot.group_id = self.__data.group_id 256 329 new_plot.id = self.__data.id 330 331 # Save data in a state: but seems to never happen 332 if new_plot != None: 333 self.invariant_panel.state.data = copy.deepcopy(new_plot) 257 334 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=new_plot.name)) 258 335 -
invariantview/perspectives/invariant/invariant_panel.py
r90b9a17 r4e1c362 6 6 import wx 7 7 8 import sys 8 import sys,os 9 9 from wx.lib.scrolledpanel import ScrolledPanel 10 10 from sans.invariant import invariant … … 13 13 from invariant_details import InvariantDetailsPanel, InvariantContainer 14 14 from invariant_widgets import OutputTextCtrl, InvTextCtrl 15 15 from invariant_state import InvariantState as IState 16 import copy,time 16 17 # The minimum q-value to be used when extrapolating 17 18 Q_MINIMUM = 1e-5 … … 32 33 #Invariant panel size 33 34 _BOX_WIDTH = 76 35 34 36 35 37 if sys.platform.count("win32")>0: … … 70 72 self._scale = SCALE 71 73 self._background = BACKGROUND 72 74 self._bmark = None 75 self.bookmark_num = 0 76 77 self._set_bookmark_menu() 78 #Init state 79 self.set_state() 80 # default flags for state 81 self.new_state = False 82 self.is_power_out = False 83 73 84 #container of invariant value 74 85 self.inv_container = None … … 76 87 self._do_layout() 77 88 self.reset_panel() 89 self._reset_state_list() 90 78 91 if self.parent is not None: 79 92 msg = "" 80 93 wx.PostEvent(self.parent,StatusEvent(status=msg, info="info")) 81 94 95 ## Default file location for save 96 self._default_save_location = os.getcwd() 97 82 98 def err_check_on_data(self): 83 99 """ … … 100 116 """ 101 117 Set the data 102 """ 118 119 : return: True/False; if False, it will not set_data 120 """ 121 # warn the users 122 if self._data != None and data != None: 123 if not self._show_message(): 124 return False 125 103 126 self._data = data 127 # reset popUpMenu 128 self._set_bookmark_menu() 104 129 #edit the panel 105 130 if self._data is not None: 131 106 132 self.err_check_on_data() 133 self.get_state_by_num(0) 107 134 data_name = self._data.name 108 135 data_qmin = min (self._data.x) 109 136 data_qmax = max (self._data.x) 110 self.data_name_tcl.SetValue(str(data_name)) 137 self.data_name_tcl.SetValue(str(data_name)) 111 138 self.data_min_tcl.SetLabel(str(data_qmin)) 112 139 self.data_max_tcl.SetLabel(str(data_qmax)) 140 self.button_save.Enable(True) 113 141 self.reset_panel() 114 142 self.compute_invariant(event=None) 115 143 #Reset the list of states 144 self.state.data = copy.deepcopy(data) 145 self._reset_state_list() 146 147 return True 148 116 149 def set_message(self): 117 150 """ … … 137 170 """ 138 171 self._manager = manager 139 172 173 def set_state(self,state=None,data=None): 174 """ 175 set state when loading it from a .inv file 176 """ 177 if state == None or data == None: 178 self.state = IState() 179 else: 180 if not self.set_data(data): 181 return 182 self.new_state = True 183 self.state = state 184 185 num = self.state.saved_state['state_num'] 186 self.get_state_by_num(state_num=num) 187 188 if num >0 : 189 self._undo_enable() 190 if num < len(state.state_list)-1: 191 self._redo_enable() 192 193 194 # get bookmarks 195 self.bookmark_num = len(self.state.bookmark_list) 196 total_bookmark_num = self.bookmark_num+1 197 for ind in range(1,total_bookmark_num): 198 #bookmark_num = ind 199 value = self.state.bookmark_list[ind] 200 name = "%d] bookmarked at %s on %s"% (ind,value[0], value[1]) 201 # append it to menu 202 id = wx.NewId() 203 self.popUpMenu.Append(id,name,str('')) 204 wx.EVT_MENU(self, id, self._back_to_bookmark) 205 self.new_state = False 206 207 140 208 def get_background(self): 141 209 """ … … 272 340 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 273 341 else: 274 self._manager.plot_theory(name="Low-Q extrapolation") 342 try: 343 self._manager.plot_theory(name="Low-Q extrapolation") 344 except: pass 275 345 276 346 def get_high_qstar(self, inv, high_q=False): … … 296 366 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 297 367 else: 298 self._manager.plot_theory(name="High-Q extrapolation") 299 368 try: 369 self._manager.plot_theory(name="High-Q extrapolation") 370 except: pass 371 300 372 def get_qstar(self, inv): 301 373 """ … … 341 413 function=function_low, power=power_low) 342 414 return inv, npts_low 343 415 416 344 417 def set_extrapolation_high(self, inv, high_q=False): 345 418 """ … … 387 460 compute invariant 388 461 """ 389 msg= "" 390 wx.PostEvent(self.parent, StatusEvent(status=msg)) 462 if self._data == None: 463 msg = "\n\nData must be loaded first in order to perform a compution..." 464 wx.PostEvent(self.parent, StatusEvent(status=msg)) 465 # set a state for this computation for saving 466 elif event != None: 467 self._set_compute_state(state='compute') 468 msg= "\n\nStarting a new invariant computation..." 469 wx.PostEvent(self.parent, StatusEvent(status=msg)) 470 391 471 if self._data is None or self.err_check_on_data(): 392 472 return 393 473 394 474 #clear outputs textctrl 395 475 self._reset_output() … … 442 522 porod_const = self.get_porod_const() 443 523 contrast = self.get_contrast() 524 444 525 try: 445 526 #Compute volume and set value to txtcrtl … … 453 534 self.get_surface(inv=inv, contrast=contrast, porod_const=porod_const, 454 535 extrapolation=extrapolation) 536 455 537 except: 456 538 msg = "Error occurred computing invariant: %s"%sys.exc_value … … 460 542 #compute percentage of each invariant 461 543 self.inv_container.compute_percentage() 544 462 545 #display a message 463 546 self.set_message() 547 548 # reset power_out to default to get ready for another '_on_text' 549 if self.is_power_out == True: 550 self.state.container = copy.deepcopy(self.inv_container) 551 self.state.timestamp= self._get_time_stamp() 552 msg = self.state.__str__() 553 self.is_power_out = False 554 wx.PostEvent(self.parent, StatusEvent(status = msg )) 555 464 556 #enable the button_ok for more details 465 557 self.button_details.Enable() 558 466 559 self.button_details.SetFocus() 467 560 if event != None: 561 wx.PostEvent(self.parent, StatusEvent(status = '\nFinished invariant computation...')) 562 563 def undo(self,event=None): 564 """ 565 Go back to the previous state 566 567 : param event: undo button event 568 569 """ 570 if event != None: event.Skip() 571 if self.state.state_num <0: return 572 self.is_power_out = True 573 # get the previous state_num 574 pre_state_num = int(self.state.saved_state['state_num']) - 1 575 self.get_state_by_num(state_num=str(pre_state_num)) 576 577 if float(pre_state_num) <=0: 578 self.button_undo.Disable() 579 elif not self.button_undo.Enabled: 580 self.button_undo.Enable(True) 581 582 self._redo_enable() 583 self.is_power_out = False 584 self._info_state_num() 585 586 587 588 def redo(self,event=None): 589 """ 590 Go forward to the previous state 591 592 : param event: redo button event 593 594 """ 595 if event != None: event.Skip() 596 self.is_power_out = True 597 next_state_num = int(self.state.saved_state['state_num']) + 1 598 599 self.get_state_by_num(state_num=str(next_state_num)) 600 601 if float(next_state_num)+2 > len(self.state.state_list): 602 self.button_redo.Disable() 603 elif not self.button_redo.Enabled: 604 self.button_redo.Enable(True) 605 606 self._undo_enable() 607 self.is_power_out = False 608 self._info_state_num() 609 610 def get_state_by_num(self,state_num=None): 611 """ 612 Get the state given by number 613 614 : param state_num: the given state number 615 616 """ 617 618 if state_num == None: 619 return 620 621 backup_state_list = copy.deepcopy(self.state.state_list) 622 623 # get the previous state 624 try: 625 current_state = copy.deepcopy(self.state.state_list[str(state_num)]) 626 # get the previously computed state number (computation before the state changes happened) 627 current_compute_num = str(current_state['compute_num']) 628 except : 629 raise ValueError, "No such state exists in history" 630 631 # get the state at pre_compute_num 632 comp_state = copy.deepcopy(self.state.state_list[current_compute_num]) 633 634 # set the parameters 635 for key in comp_state: 636 value = comp_state[key] 637 try: 638 exec "self.%s.SetValue(str(%s))" % (key, value) 639 except TypeError: 640 exec "self.%s.SetValue(%s)" % (key, value) 641 except: 642 pass 643 644 self.compute_invariant(event=None) 645 # set the input params at the state at pre_state_num 646 for key in current_state: 647 # Do not reset set some outputs 648 #key_split = key.split('_') 649 #if key_split[0] == 'surface' or key_split[0] == 'volume': 650 # continue 651 # set the inputs and boxes 652 value = current_state[key] 653 654 try: 655 exec 'self.%s.SetValue(str(%s))' % (key, value) 656 except TypeError: 657 exec 'self.%s.SetValue(%s)' % (key, value) 658 except: 659 pass 660 661 662 self._enable_high_q_section(event=None) 663 self._enable_low_q_section(event=None) 664 self.state.state_list = backup_state_list 665 self.state.saved_state = current_state 666 self.state.state_num = state_num 667 668 669 def get_bookmark_by_num(self, num=None): 670 """ 671 Get the bookmark state given by number 672 673 : param num: the given bookmark number 674 675 """ 676 current_state = {} 677 comp_state = {} 678 backup_state_list = copy.deepcopy(self.state.state_list) 679 680 # get the previous state 681 try: 682 time,date,current_state,comp_state = self.state.bookmark_list[int(num)] 683 except : 684 raise ValueError, "No such bookmark exists" 685 686 # set the parameters 687 for key in comp_state: 688 value = comp_state[key] 689 try: 690 exec "self.%s.SetValue(str(%s))" % (key, value) 691 except TypeError: 692 exec "self.%s.SetValue(%s)" % (key, value) 693 except: 694 pass 695 696 self.compute_invariant(event=None) 697 # set the input params at the state of pre_state_num 698 for key in current_state: 699 value = current_state[key] 700 try: 701 exec 'self.%s.SetValue(str(%s))' % (key, value) 702 except TypeError: 703 exec 'self.%s.SetValue(%s)' % (key, value) 704 except: 705 pass 706 self.state.saved_state = copy.deepcopy(current_state) 707 708 self._enable_high_q_section(event=None) 709 self._enable_low_q_section(event=None) 710 self.state.state_list = backup_state_list 711 #self.state.saved_state = current_state 712 #self.state.state_num = state_num 713 468 714 def reset_panel(self): 469 715 """ … … 490 736 self._enable_high_q_section() 491 737 self._reset_output() 738 self.button_undo.Disable() 739 self.button_redo.Disable() 492 740 self.button_calculate.SetFocus() 741 #self.SetupScrolling() 742 743 def _set_state(self, event): 744 """ 745 Set the state list 746 747 :param event: rb/cb event 748 749 """ 750 if event == None: 751 return 752 obj = event.GetEventObject() 753 name = str(obj.GetName()) 754 value = str(obj.GetValue()) 755 rb_list = [['power_law_low','guinier'],['fit_enable_low','fix_enable_low'],['fit_enable_high','fix_enable_high']] 756 757 try: 758 if value == None or value.lstrip().rstrip() =='': 759 value = 'None' 760 exec 'self.state.%s = %s' % (name, value) 761 exec "self.state.saved_state['%s'] = %s" % (name, value) 762 763 # set the count part of radio button clicked False for the saved_state 764 for title,content in rb_list: 765 if name == title: 766 name = content 767 value = False 768 elif name == content: 769 name = title 770 value = False 771 exec "self.state.saved_state['%s'] = %s" % (name, value) 772 773 # Instead of changing the future, create a new future. 774 max_state_num = len(self.state.state_list)-1 775 self.state.saved_state['state_num'] = max_state_num 776 777 self.state.saved_state['state_num'] +=1 778 self.state.state_num = self.state.saved_state['state_num'] 779 self.state.state_list[str(self.state.state_num)] = self.state.clone_state()#copy.deepcopy(self.state.saved_state) 780 781 except: 782 pass 783 784 event.Skip() 785 self._undo_enable() 786 self._redo_disable() 787 788 def _set_compute_state(self,state=None): 789 """ 790 Notify the compute_invariant state to self.state 791 792 : param state: set 'compute' when the computation is activated by the 'compute' button, else None 793 794 """ 795 # reset the default 796 if state != 'compute': 797 self.new_state = False 798 self.is_power_out = False 799 else: 800 self.is_power_out = True 801 # Instead of changing the future, create a new future. 802 max_state_num = len(self.state.state_list)-1 803 self.state.saved_state['state_num'] = max_state_num 804 # A new computation is also A state 805 temp_saved_states = self.state.clone_state()#copy.deepcopy(self.state.saved_state) 806 temp_saved_states['state_num'] +=1 807 self.state.state_num = temp_saved_states['state_num'] 808 809 810 # set the state number of the computation 811 if state == 'compute': 812 temp_saved_states['compute_num'] = self.state.state_num 813 self.state.saved_state= copy.deepcopy(temp_saved_states) 814 self.state.state_list[str(self.state.state_num)] = self.state.clone_state()#copy.deepcopy(self.state.saved_state) 815 816 # A computation is a new state, so delete the states with any higher state numbers 817 for i in range(self.state.state_num+1,len(self.state.state_list)): 818 try: 819 del (self.state.state_list[str(i)]) 820 except: 821 pass 822 # Enable the undo button if it was not 823 self._undo_enable() 824 self._redo_disable() 825 826 def _reset_state_list(self,data=None): 827 """ 828 Reset the state_list just before data was loading: Used in 'set_data()' 829 """ 830 #if data == None: return 831 #temp_state = self.state.clone_state()#copy.deepcopy(self.state.saved_state) 832 # Clear the list 833 self.state.state_list.clear() 834 self.state.bookmark_list.clear() 835 # Set defaults 836 self.state.saved_state['state_num'] = 0 837 self.state.saved_state['compute_num'] = 0 838 if self._data != None: 839 self.state.saved_state['file'] = str(self._data.name) 840 else: 841 self.state.saved_state['file'] = 'None' 842 self.state.file = self.state.saved_state['file'] 843 844 self.state.state_num = self.state.saved_state['state_num'] 845 # Put only the current state in the list 846 self.state.state_list[str(self.state.state_num)] = self.state.clone_state()#copy.deepcopy(self.state.saved_state) 847 self._undo_disable() 848 849 def _on_text(self, event): 850 """ 851 Catch text change event to add the state to the state_list 852 853 :param event: txtctr event ; assumes not None 854 855 """ 856 if self._data == None: 857 return 858 # check if this event is from do/undo button 859 if self.state.saved_state['is_time_machine'] or self.new_state: 860 event.Skip() 861 return 862 863 # get the object 864 obj = event.GetEventObject() 865 name = str(obj.GetName()) 866 value = str(obj.GetValue()) 867 state_num = self.state.saved_state['state_num'] 868 869 # text event is a new state, so delete the states with higher state_num 870 # i.e., change the future 871 for i in range(int(state_num)+1,len(self.state.state_list)): 872 try: 873 del (self.state.state_list[str(i)]) 874 except: 875 pass 876 877 # Instead of changing the future, create a new future. 878 #max_state_num = len(self.state.state_list)-1 879 #self.state.saved_state['state_num'] = max_state_num 880 881 # try to add new state of the text changes in the state_list 882 try: 883 if value.strip() == None: value = '' 884 exec "self.state.%s = '%s'" % (name, value) 885 exec "self.state.saved_state['%s'] = '%s'" % (name, value) 886 exec "self.state.input_list['%s'] = '%s'" % (name, value) 887 if not self.is_power_out: 888 if name != 'power_low_tcl' and name !='power_high_tcl': 889 self.state.saved_state['state_num'] += 1 890 self.state.state_num = self.state.saved_state['state_num'] 891 self.state.state_list[str(self.state.state_num)] = self.state.clone_state()#copy.deepcopy(self.state.saved_state) 892 except: 893 pass 894 895 event.Skip() 896 self._undo_enable() 897 self._redo_disable() 898 899 def _on_out_text(self, event): 900 """ 901 Catch ouput text change to add the state 902 903 :param event: txtctr event ; assumes not None 904 905 """ 906 # get the object 907 obj = event.GetEventObject() 908 name = str(obj.GetName()) 909 value = str(obj.GetValue()) 910 try: 911 exec "self.state.saved_state['%s'] = '%s'" % (name, value) 912 self.state.state_list[str(self.state.state_num)] = self.state.clone_state() 913 except: 914 pass 915 if event != None: event.Skip()\ 916 917 def _set_bookmark_menu(self): 918 """ 919 Setup 'bookmark' context menu 920 """ 921 ## Create context menu for page 922 self.popUpMenu = wx.Menu() 923 id = wx.NewId() 924 self._bmark = wx.MenuItem(self.popUpMenu,id,"BookMark"," Bookmark the panel to recall it later") 925 self.popUpMenu.AppendItem(self._bmark) 926 self._bmark.Enable(True) 927 wx.EVT_MENU(self, id, self._on_bookmark) 928 self.popUpMenu.AppendSeparator() 929 self.Bind(wx.EVT_CONTEXT_MENU, self._on_context_menu) 930 931 def _on_bookmark(self,event): 932 """ 933 Save the panel state in memory and add the list on the popup menu on bookmark context menu event 934 """ 935 if self._data == None: return 936 if event == None: return 937 self.bookmark_num += 1 938 # date and time of the event 939 #year, month, day,hour,minute,second,tda,ty,tm_isdst= time.localtime() 940 #my_time= str(hour)+" : "+str(minute)+" : "+str(second)+" " 941 #date= str( month)+"/"+str(day)+"/"+str(year) 942 my_time, date = self._get_time_stamp() 943 state_num = self.state.state_num 944 compute_num = self.state.saved_state['compute_num'] 945 # name and message of the bookmark list 946 msg= "State saved at %s on %s"%(my_time, date) 947 ## post help message for the selected model 948 msg +=" Saved! right click on this page to retrieve this model" 949 #wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) 950 name = "%d] bookmarked at %s on %s"%(self.bookmark_num,my_time, date) 951 952 # append it to menu 953 id = wx.NewId() 954 self.popUpMenu.Append(id,name,str(msg)) 955 wx.EVT_MENU(self, id, self._back_to_bookmark ) 956 state = self.state.clone_state() 957 comp_state = copy.deepcopy(self.state.state_list[str(compute_num)]) 958 self.state.bookmark_list[self.bookmark_num] = [my_time,date,state,comp_state] 959 self.state.toXML(self, doc=None, entry_node=None) 960 961 def _back_to_bookmark(self,event): 962 """ 963 Bring the panel back to the state of bookmarked requested by context menu event 964 and set it as a new state 965 """ 966 ## post help message for the selected model 967 msg = self.popUpMenu.GetHelpString(event.GetId()) 968 msg +=" reloaded" 969 wx.PostEvent(self.parent, StatusEvent(status = msg )) 970 971 name= self.popUpMenu.GetLabel(event.GetId()) 972 num,time = name.split(']') 973 current_state_num = self.state.state_num 974 self.get_bookmark_by_num(num) 975 state_num = int(current_state_num)+1 976 977 self.state.saved_state['state_num'] = state_num 978 self.state.state_list[str(state_num)] = self.state.clone_state()#copy.deepcopy(self.state.saved_state) 979 self.state.state_num = state_num 980 self._undo_enable() 981 self._info_bookmark_num(event) 982 983 def _info_bookmark_num(self,event=None): 984 """ 985 print the bookmark number in info 986 987 : event: popUpMenu event 988 """ 989 if event == None: return 990 # get the object 991 item = self.popUpMenu.FindItemById(event.GetId()) 992 text = item.GetText() 993 num = text.split(']')[0] 994 msg = "bookmark num = %s "% num 995 996 wx.PostEvent(self.parent, StatusEvent(status = msg )) 997 998 def _info_state_num(self): 999 """ 1000 print the current state number in info 1001 """ 1002 msg = "state num = " 1003 msg += self.state.state_num 1004 1005 wx.PostEvent(self.parent, StatusEvent(status = msg)) 1006 1007 def _get_time_stamp(self): 1008 """ 1009 return time and date stings 1010 """ 1011 # date and time 1012 year, month, day,hour,minute,second,tda,ty,tm_isdst= time.localtime() 1013 my_time= str(hour)+":"+str(minute)+":"+str(second) 1014 date= str( month)+"/"+str(day)+"/"+str(year) 1015 return my_time, date 1016 1017 def _undo_enable(self): 1018 """ 1019 Enable undo button 1020 """ 1021 if not self.button_undo.IsEnabled(): 1022 self.button_undo.Enable(True) 1023 1024 def _undo_disable(self): 1025 """ 1026 Disable undo button 1027 """ 1028 if self.button_undo.IsEnabled(): 1029 self.button_undo.Disable() 1030 1031 def _redo_enable(self): 1032 """ 1033 Enable redo button 1034 """ 1035 if not self.button_redo.IsEnabled(): 1036 self.button_redo.Enable(True) 1037 1038 def _redo_disable(self): 1039 """ 1040 Disable redo button 1041 """ 1042 if self.button_redo.IsEnabled(): 1043 self.button_redo.Disable() 1044 1045 def _on_save_button(self, evt=None): 1046 """ 1047 Save invariant state into a file 1048 """ 1049 # Ask the user the location of the file to write to. 1050 path = None 1051 dlg = wx.FileDialog(self, "Choose a file", self._default_save_location, "", "*.inv", wx.SAVE) 1052 if dlg.ShowModal() == wx.ID_OK: 1053 path = dlg.GetPath() 1054 self._default_save_location = os.path.dirname(path) 1055 else: 1056 return None 1057 1058 dlg.Destroy() 1059 1060 self._manager.save_file(filepath=path, state=self.state) 1061 1062 def _show_message(self, mssg='',msg='Warning'): 1063 """ 1064 Show warning message when resetting data 1065 """ 1066 1067 mssg += 'Loading a new data set will reset all the work done in this panel. \n\r' 1068 mssg += 'Please make sure to save it first... \n\r' 1069 answer = wx.MessageBox(mssg, msg, wx.CANCEL|wx.OK|wx.ICON_EXCLAMATION) 1070 1071 if answer == wx.OK: 1072 return True 1073 else: 1074 return False 493 1075 494 1076 def _reset_output(self): … … 504 1086 #prepare a new container to put result of invariant 505 1087 self.inv_container = InvariantContainer() 1088 1089 1090 def _on_context_menu(self,event): 1091 1092 pos = event.GetPosition() 1093 pos = self.ScreenToClient(pos) 506 1094 1095 self.PopupMenu(self.popUpMenu, pos) 1096 507 1097 def _define_structure(self): 508 1098 """ … … 550 1140 #Sizer related to button 551 1141 self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) 552 1142 #Sizer related to save button 1143 self.save_button_sizer = wx.BoxSizer(wx.HORIZONTAL) 1144 553 1145 def _layout_data_name(self): 554 1146 """ … … 557 1149 #Sizer hint 558 1150 hint_msg = "First open data file from 'File' menu. Then Highlight and right click on the data plot. \n" 559 hint_msg += "Finally, select 'Compute Invariant'. \n"1151 hint_msg += "Finally, select 'Compute Invariant'." 560 1152 self.hint_msg_txt = wx.StaticText(self, -1, hint_msg) 561 1153 self.hint_msg_txt.SetForegroundColour("red") … … 566 1158 data_name_txt = wx.StaticText(self, -1, 'Data : ') 567 1159 568 self.data_name_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH*5, 20), style=0 )1160 self.data_name_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH*5, 20), style=0, name='data_name_tcl') 569 1161 self.data_name_tcl.SetToolTipString("Data's name.") 570 1162 self.data_name_sizer.AddMany([(data_name_txt, 0, wx.LEFT|wx.RIGHT, 10), … … 573 1165 data_range_txt = wx.StaticText(self, -1, 'Total Q Range (1/A): ') 574 1166 data_min_txt = wx.StaticText(self, -1, 'Min : ') 575 self.data_min_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0 )1167 self.data_min_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0, name='data_min_tcl') 576 1168 self.data_min_tcl.SetToolTipString("The minimum value of q range.") 577 1169 data_max_txt = wx.StaticText(self, -1, 'Max : ') 578 self.data_max_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0 )1170 self.data_max_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0, name='data_max_tcl') 579 1171 self.data_max_tcl.SetToolTipString("The maximum value of q range.") 580 1172 self.data_range_sizer.AddMany([(data_range_txt, 0, wx.RIGHT, 10), … … 583 1175 (data_max_txt, 0, wx.RIGHT, 10), 584 1176 (self.data_max_tcl, 0, wx.RIGHT, 10)]) 585 self.data_name_boxsizer.AddMany([(self.hint_msg_sizer, 0 , wx.ALL, 10),1177 self.data_name_boxsizer.AddMany([(self.hint_msg_sizer, 0 , wx.ALL, 5), 586 1178 (self.data_name_sizer, 0 , wx.RIGHT, 10), 587 1179 (self.data_range_sizer, 0 , wx.ALL, 10)]) … … 592 1184 """ 593 1185 background_txt = wx.StaticText(self, -1, 'Background : ') 594 self.background_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 595 background_hint_txt = "background" 1186 self.background_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0, name='background_tcl') 1187 wx.EVT_TEXT(self, self.background_tcl.GetId(), self._on_text) 1188 background_hint_txt = "Background" 596 1189 self.background_tcl.SetToolTipString(background_hint_txt) 597 1190 background_unit_txt = wx.StaticText(self, -1, '[1/cm]') 598 1191 scale_txt = wx.StaticText(self, -1, 'Scale : ') 599 self.scale_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 1192 self.scale_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0, name='scale_tcl') 1193 wx.EVT_TEXT(self, self.scale_tcl.GetId(), self._on_text) 600 1194 scale_hint_txt = "Scale" 601 1195 self.scale_tcl.SetToolTipString(scale_hint_txt) … … 611 1205 """ 612 1206 contrast_txt = wx.StaticText(self, -1, 'Contrast : ') 613 self.contrast_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) 1207 self.contrast_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0,name='contrast_tcl') 1208 wx.EVT_TEXT(self, self.contrast_tcl.GetId(), self._on_text) 614 1209 contrast_hint_txt = "Contrast" 615 1210 self.contrast_tcl.SetToolTipString(contrast_hint_txt) … … 617 1212 porod_const_txt = wx.StaticText(self, -1, 'Porod Constant:') 618 1213 self.porod_constant_tcl = InvTextCtrl(self, -1, 619 size=(_BOX_WIDTH, 20), style=0) 1214 size=(_BOX_WIDTH, 20), style=0,name='porod_constant_tcl') 1215 wx.EVT_TEXT(self, self.porod_constant_tcl.GetId(), self._on_text) 620 1216 porod_const_hint_txt = "Porod Constant" 621 1217 self.porod_constant_tcl.SetToolTipString(porod_const_hint_txt) … … 632 1228 Enable and disable the power value editing 633 1229 """ 1230 if event != None: 1231 print "enable fit==>event!=None" 1232 634 1233 if self.fix_enable_low.IsEnabled(): 1234 635 1235 if self.fix_enable_low.GetValue(): 1236 self.fit_enable_low.SetValue(False) 636 1237 self.power_low_tcl.Enable() 637 1238 else: 1239 self.fit_enable_low.SetValue(True) 638 1240 self.power_low_tcl.Disable() 639 1241 self._set_state(event=event) 1242 640 1243 def _enable_low_q_section(self, event=None): 641 1244 """ 642 1245 Disable or enable some button if the user enable low q extrapolation 643 1246 """ 1247 #if event != None: self._set_compute_state() 644 1248 if self.enable_low_cbox.GetValue(): 645 1249 self.npts_low_tcl.Enable() … … 655 1259 self.guinier.Disable() 656 1260 self.power_law_low.Disable() 1261 657 1262 self._enable_power_law_low() 658 1263 self._enable_fit_power_law_low() 1264 self._set_state(event=event) 659 1265 self.button_calculate.SetFocus() 660 1266 661 1267 def _enable_power_law_low(self, event=None): 662 1268 """ 663 1269 Enable editing power law section at low q range 664 1270 """ 1271 #if event != None: self._set_compute_state() 665 1272 if self.guinier.GetValue(): 1273 self.power_law_low.SetValue(False) 666 1274 self.fix_enable_low.Disable() 667 1275 self.fit_enable_low.Disable() 668 1276 self.power_low_tcl.Disable() 669 1277 else: 1278 self.power_law_low.SetValue(True) 670 1279 self.fix_enable_low.Enable() 671 1280 self.fit_enable_low.Enable() 672 1281 self.power_low_tcl.Enable() 673 1282 self._enable_fit_power_law_low() 1283 self._set_state(event=event) 674 1284 675 1285 def _layout_extrapolation_low(self): … … 677 1287 Draw widgets related to extrapolation at low q range 678 1288 """ 679 self.enable_low_cbox = wx.CheckBox(self, -1, "Enable Extrapolate Low Q" )1289 self.enable_low_cbox = wx.CheckBox(self, -1, "Enable Extrapolate Low Q",name='enable_low_cbox') 680 1290 wx.EVT_CHECKBOX(self, self.enable_low_cbox.GetId(), 681 1291 self._enable_low_q_section) 682 1292 self.fix_enable_low = wx.RadioButton(self, -1, 'Fix', 683 (10, 10),style=wx.RB_GROUP) 684 self.fit_enable_low = wx.RadioButton(self, -1, 'Fit', (10, 10)) 1293 (10, 10),style=wx.RB_GROUP,name='fix_enable_low') 685 1294 self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_low, 686 1295 id=self.fix_enable_low.GetId()) 1296 self.fit_enable_low = wx.RadioButton(self, -1, 'Fit', (10, 10),name='fit_enable_low') 687 1297 self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_low, 688 1298 id=self.fit_enable_low.GetId()) 689 1299 self.guinier = wx.RadioButton(self, -1, 'Guinier', 690 (10, 10),style=wx.RB_GROUP) 691 self.power_law_low = wx.RadioButton(self, -1, 'Power Law', (10, 10)) 1300 (10, 10),style=wx.RB_GROUP, name='guinier') 692 1301 self.Bind(wx.EVT_RADIOBUTTON, self._enable_power_law_low, 693 id=self.guinier.GetId()) 1302 id=self.guinier.GetId()) 1303 self.power_law_low = wx.RadioButton(self, -1, 'Power Law', (10, 10),name='power_law_low') 694 1304 self.Bind(wx.EVT_RADIOBUTTON, self._enable_power_law_low, 695 1305 id=self.power_law_low.GetId()) 696 1306 697 1307 npts_low_txt = wx.StaticText(self, -1, 'Npts') 698 self.npts_low_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1)) 1308 self.npts_low_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1),name='npts_low_tcl') 1309 wx.EVT_TEXT(self, self.npts_low_tcl.GetId(), self._on_text) 699 1310 msg_hint = "Number of Q points to consider" 700 1311 msg_hint +="while extrapolating the low-Q region" 701 1312 self.npts_low_tcl.SetToolTipString(msg_hint) 702 1313 power_txt = wx.StaticText(self, -1, 'Power') 703 self.power_low_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1)) 1314 self.power_low_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1),name='power_low_tcl') 1315 wx.EVT_TEXT(self, self.power_low_tcl.GetId(), self._on_text) 704 1316 705 1317 power_hint_txt = "Exponent to apply to the Power_law function." … … 747 1359 Enable and disable the power value editing 748 1360 """ 1361 #if event != None: self._set_compute_state() 749 1362 if self.fix_enable_high.IsEnabled(): 750 1363 if self.fix_enable_high.GetValue(): 1364 self.fit_enable_high.SetValue(False) 751 1365 self.power_high_tcl.Enable() 752 1366 else: 1367 self.fit_enable_high.SetValue(True) 753 1368 self.power_high_tcl.Disable() 1369 self._set_state(event=event) 754 1370 755 1371 def _enable_high_q_section(self, event=None): … … 757 1373 Disable or enable some button if the user enable high q extrapolation 758 1374 """ 1375 #if event != None: self._set_compute_state() 759 1376 if self.enable_high_cbox.GetValue(): 760 1377 self.npts_high_tcl.Enable() … … 770 1387 self.fit_enable_high.Disable() 771 1388 self._enable_fit_power_law_high() 1389 self._set_state(event=event) 772 1390 self.button_calculate.SetFocus() 773 1391 … … 776 1394 Draw widgets related to extrapolation at high q range 777 1395 """ 778 self.enable_high_cbox = wx.CheckBox(self, -1, "Enable Extrapolate high-Q" )1396 self.enable_high_cbox = wx.CheckBox(self, -1, "Enable Extrapolate high-Q", name='enable_high_cbox') 779 1397 wx.EVT_CHECKBOX(self, self.enable_high_cbox.GetId(), 780 1398 self._enable_high_q_section) 781 782 1399 self.fix_enable_high = wx.RadioButton(self, -1, 'Fix', 783 (10, 10),style=wx.RB_GROUP) 784 self.fit_enable_high = wx.RadioButton(self, -1, 'Fit', (10, 10)) 1400 (10, 10),style=wx.RB_GROUP,name='fix_enable_high') 785 1401 self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_high, 786 1402 id=self.fix_enable_high.GetId()) 1403 self.fit_enable_high = wx.RadioButton(self, -1, 'Fit', (10, 10),name='fit_enable_high') 787 1404 self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_high, 788 1405 id=self.fit_enable_high.GetId()) … … 792 1409 self.power_law_high.SetToolTipString(msg_hint) 793 1410 npts_high_txt = wx.StaticText(self, -1, 'Npts') 794 self.npts_high_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1)) 1411 self.npts_high_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1),name='npts_high_tcl') 1412 wx.EVT_TEXT(self, self.npts_high_tcl.GetId(), self._on_text) 795 1413 msg_hint = "Number of Q points to consider" 796 1414 msg_hint += "while extrapolating the high-Q region" 797 1415 self.npts_high_tcl.SetToolTipString(msg_hint) 798 1416 power_txt = wx.StaticText(self, -1, 'Power') 799 self.power_high_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1)) 1417 self.power_high_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1),name='power_high_tcl') 1418 wx.EVT_TEXT(self, self.power_high_tcl.GetId(), self._on_text) 800 1419 power_hint_txt = "Exponent to apply to the Power_law function." 801 1420 self.power_high_tcl.SetToolTipString(power_hint_txt) … … 841 1460 extra_hint_txt = wx.StaticText(self, -1, extra_hint) 842 1461 #Extrapolation range [string] 843 extrapolation_min_txt = wx.StaticText(self, -1, 'Min : 1462 extrapolation_min_txt = wx.StaticText(self, -1, 'Min :') 844 1463 self.extrapolation_min_tcl = OutputTextCtrl(self, -1, 845 size=(_BOX_WIDTH, 20), style=0 )1464 size=(_BOX_WIDTH, 20), style=0,name='extrapolation_min_tcl') 846 1465 self.extrapolation_min_tcl.SetValue(str(Q_MINIMUM)) 847 1466 self.extrapolation_min_tcl.SetToolTipString("The minimum extrapolated q value.") 848 extrapolation_max_txt = wx.StaticText(self, -1, 'Max : 1467 extrapolation_max_txt = wx.StaticText(self, -1, 'Max :') 849 1468 self.extrapolation_max_tcl = OutputTextCtrl(self, -1, 850 size=(_BOX_WIDTH, 20), style=0 )1469 size=(_BOX_WIDTH, 20), style=0,name='extrapolation_max_tcl') 851 1470 self.extrapolation_max_tcl.SetValue(str(Q_MAXIMUM)) 852 1471 self.extrapolation_max_tcl.SetToolTipString("The maximum extrapolated q value.") … … 862 1481 self._layout_extrapolation_high() 863 1482 self.extrapolation_low_high_sizer.AddMany([(self.low_extrapolation_sizer, 864 0, wx.ALL, 10),1483 0, wx.ALL, 5), 865 1484 (self.high_extrapolation_sizer, 866 0, wx.ALL, 10)])1485 0, wx.ALL, 5)]) 867 1486 self.extrapolation_sizer.AddMany([(self.extrapolation_range_sizer, 0, 868 wx.RIGHT, 10),1487 wx.RIGHT, 5), 869 1488 (self.extrapolation_low_high_sizer, 0, 870 wx.ALL, 10)])1489 wx.ALL, 5)]) 871 1490 872 1491 def _layout_volume_surface_sizer(self): … … 878 1497 uncertainty = "+/-" 879 1498 volume_txt = wx.StaticText(self, -1, 'Volume Fraction ') 880 self.volume_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 1499 self.volume_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1),name='volume_tcl') 1500 wx.EVT_TEXT(self, self.volume_tcl.GetId(), self._on_out_text) 881 1501 self.volume_tcl.SetToolTipString("Volume fraction.") 882 self.volume_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 1502 self.volume_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1),name='volume_err_tcl') 1503 wx.EVT_TEXT(self, self.volume_err_tcl.GetId(), self._on_out_text) 883 1504 self.volume_err_tcl.SetToolTipString("Uncertainty on the volume fraction.") 884 1505 volume_units_txt = wx.StaticText(self, -1, unit_volume) 885 1506 886 1507 surface_txt = wx.StaticText(self, -1, 'Specific Surface') 887 self.surface_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 1508 self.surface_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1),name='surface_tcl') 1509 wx.EVT_TEXT(self, self.surface_tcl.GetId(), self._on_out_text) 888 1510 self.surface_tcl.SetToolTipString("Specific surface value.") 889 self.surface_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) 1511 self.surface_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1),name='surface_err_tcl') 1512 wx.EVT_TEXT(self, self.surface_err_tcl.GetId(), self._on_out_text) 890 1513 self.surface_err_tcl.SetToolTipString("Uncertainty on the specific surface.") 891 1514 surface_units_txt = wx.StaticText(self, -1, unit_surface) … … 930 1553 unit_invariant = '[1/(cm * A)]' 931 1554 invariant_total_txt = wx.StaticText(self, -1, 'Invariant Total [Q*]') 932 self.invariant_total_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1) )1555 self.invariant_total_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1),name='invariant_total_tcl') 933 1556 msg_hint = "Total invariant [Q*], including extrapolated regions." 934 1557 self.invariant_total_tcl.SetToolTipString(msg_hint) 935 self.invariant_total_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1) )1558 self.invariant_total_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1),name='invariant_total_err_tcl') 936 1559 self.invariant_total_err_tcl.SetToolTipString("Uncertainty on invariant.") 937 1560 invariant_total_units_txt = wx.StaticText(self, -1, unit_invariant) … … 980 1603 #compute button 981 1604 id = wx.NewId() 982 self.button_calculate = wx.Button(self, id, "Compute" )1605 self.button_calculate = wx.Button(self, id, "Compute", name ='compute_invariant' ) 983 1606 self.button_calculate.SetToolTipString("Compute invariant") 984 1607 self.Bind(wx.EVT_BUTTON, self.compute_invariant, id=id) … … 986 1609 id = wx.NewId() 987 1610 self.button_details = wx.Button(self, id, "Details?") 988 self.button_details.SetToolTipString(" Give Details on Computation")1611 self.button_details.SetToolTipString("Details about the results of the computation") 989 1612 self.Bind(wx.EVT_BUTTON, self.display_details, id=id) 990 1613 details = "Details on Invariant Total Calculations" 991 1614 details_txt = wx.StaticText(self, -1, details) 992 self.button_sizer.AddMany([(( 10,10), 0 , wx.LEFT,0),1615 self.button_sizer.AddMany([((50,10), 0 , wx.LEFT,0), 993 1616 (details_txt, 0 , 994 1617 wx.RIGHT|wx.BOTTOM|wx.TOP, 10), 995 1618 (self.button_details, 0 , wx.ALL, 10), 996 (self.button_calculate, 0 , wx.RIGHT|wx.TOP|wx.BOTTOM, 10)]) 997 1619 (self.button_calculate, 0 , wx.RIGHT|wx.TOP|wx.BOTTOM, 10)])#, 1620 #(self.button_undo, 0 , wx.ALL, 10), 1621 #(self.button_redo, 0 , wx.ALL, 10)]) 1622 def _layout_save_button(self): 1623 """ 1624 Do the layout for the save button widgets 1625 """ 1626 import sans.perspectives.invariant as invariant 1627 path = invariant.get_data_path(media='media') 1628 self.undo_png = os.path.join(path,"undo.png") 1629 self.redo_png = os.path.join(path,"redo.png") 1630 self.save_png = os.path.join(path,"save.png") 1631 #undo button 1632 id = wx.NewId() 1633 self.button_undo = wx.BitmapButton(self, id,wx.Bitmap(self.undo_png))#wx.Button(self, id, "Undo",size=(50,20)) 1634 self.button_undo.SetToolTipString("Undo") 1635 self.Bind(wx.EVT_BUTTON, self.undo, id=id) 1636 self.button_undo.Disable() 1637 #redo button 1638 id = wx.NewId() 1639 self.button_redo = wx.BitmapButton(self, id,wx.Bitmap(self.redo_png))#wx.Button(self, id, "Redo",size=(50,20)) 1640 self.button_redo.SetToolTipString("Redo") 1641 self.Bind(wx.EVT_BUTTON, self.redo, id=id) 1642 self.button_redo.Disable() 1643 #save button 1644 id = wx.NewId() 1645 self.button_save = wx.BitmapButton(self, id,wx.Bitmap(self.save_png), name ='Save_invariant')#wx.Button(self, id, "Save", name ='Save_invariant' ) 1646 self.button_save.SetToolTipString("Save as a file") 1647 self.Bind(wx.EVT_BUTTON, self._on_save_button, id=id) 1648 self.button_save.Disable() 1649 self.save_button_sizer.AddMany([((PANEL_WIDTH/1.5,20), 1 , wx.EXPAND|wx.ADJUST_MINSIZE,0), 1650 (self.button_undo, 0 ,wx.LEFT|wx.ADJUST_MINSIZE, 10), 1651 (self.button_redo, 0 ,wx.LEFT|wx.ADJUST_MINSIZE, 10), 1652 (self.button_save, 0 ,wx.LEFT|wx.ADJUST_MINSIZE, 10)]) 998 1653 def _do_layout(self): 999 1654 """ … … 1006 1661 self._layout_outputs_sizer() 1007 1662 self._layout_button() 1663 self._layout_save_button() 1008 1664 self.main_sizer.AddMany([(self.data_name_boxsizer,0, wx.ALL, 10), 1009 1665 (self.outputs_sizer, 0, … … 1014 1670 wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), 1015 1671 (self.extrapolation_sizer, 0, 1672 wx.LEFT|wx.RIGHT|wx.BOTTOM, 10),\ 1673 (self.save_button_sizer,0, 1016 1674 wx.LEFT|wx.RIGHT|wx.BOTTOM, 10)]) 1017 1675 self.SetSizer(self.main_sizer) … … 1037 1695 wx.Frame.__init__(self, parent, id, title, size=(PANEL_WIDTH +100, 1038 1696 PANEL_HEIGHT+100)) 1039 1697 from DataLoader.loader import Loader 1698 self.loader = Loader() 1699 import invariant 1700 1701 data= self.loader.load("C:/ECLPS/workspace/trunk/DataLoader/test/ascii_test_3.txt") 1040 1702 self.panel = InvariantPanel(self) 1703 1704 data.name = data.filename 1705 self.panel.set_data(data) 1041 1706 self.Centre() 1042 1707 self.Show(True) -
invariantview/perspectives/invariant/invariant_widgets.py
rd7a39e5 r4e1c362 15 15 import wx 16 16 import os 17 from invariant_state import InvariantState as IState 18 import copy 17 19 18 20 class InvTextCtrl(wx.TextCtrl): … … 22 24 """ 23 25 def __init__(self, *args, **kwds): 24 25 26 wx.TextCtrl.__init__(self, *args, **kwds) 26 27 27 ## Set to True when the mouse is clicked while the whole string is selected 28 full_selection = False28 self.full_selection = False 29 29 ## Call back for EVT_SET_FOCUS events 30 30 _on_set_focus_callback = None 31 31 32 # Bind appropriate events 32 33 self.Bind(wx.EVT_LEFT_UP, self._highlight_text) 33 34 self.Bind(wx.EVT_SET_FOCUS, self._on_set_focus) 34 35 35 36 def _on_set_focus(self, event): 36 37 """ … … 39 40 40 41 :param event: mouse event 41 42 42 """ 43 43 event.Skip() … … 49 49 50 50 :param event: mouse event 51 52 51 """ 53 52 # Make sure the mouse event is available to other listeners … … 63 62 if start==end: 64 63 control.SetSelection(-1,-1) 64 65 65 66 66 67 class OutputTextCtrl(wx.TextCtrl): 67 68 """ … … 78 79 # The event will be skipped once the call-back 79 80 # is called. 81 80 82 self.Bind(wx.EVT_MOUSE_EVENTS, self._click) 83 81 84 82 85 def _click(self, event): … … 86 89 """ 87 90 pass 91 92 93 88 94
Note: See TracChangeset
for help on using the changeset viewer.