Changeset 9130227 in sasview
- Timestamp:
- Apr 19, 2012 5:26:54 PM (13 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:
- 11857f7
- Parents:
- b716dd8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansguiframe/src/sans/guiframe/data_processor.py
ra5e749f r9130227 779 779 self.x = [] 780 780 self.y = [] 781 self.dy = [] 781 782 self.x_axis_label = None 782 783 self.y_axis_label = None 784 self.dy_axis_label = None 783 785 self.x_axis_title = None 784 786 self.y_axis_title = None … … 811 813 self.y_axis_title.SetValue(str(label)) 812 814 815 def set_dyaxis(self, label="", dy=None): 816 """ 817 """ 818 if dy is None: 819 dy = [] 820 self.dy = dy 821 self.dy_axis_label.SetValue("%s[:]" % str(label)) 822 813 823 def get_plot_axis(self, col, list): 814 824 """ … … 959 969 960 970 dict = parse_string(sentence, column_names.keys()) 961 for tok, (col_name, list) in dict.iteritems():962 col = column_names[col_name]963 x axis = self.get_plot_axis(col, list)964 sentence = sentence.replace(tok,965 "numpy.array(%s)" % str(xaxis))966 for key, value in FUNC_DICT.iteritems():967 sentence = sentence.replace(key.lower(), value)968 x = eval(sentence)971 sentence = self.get_sentence(dict, sentence, column_names) 972 try: 973 x = eval(sentence) 974 except: 975 msg = "Need a proper x-range." 976 wx.PostEvent(self.parent.parent, 977 StatusEvent(status=msg, info="error")) 978 return 969 979 #evaluate y 970 980 sentence = self.y_axis_label.GetValue() … … 973 983 raise ValueError, msg 974 984 dict = parse_string(sentence, column_names.keys()) 975 for tok, (col_name, list) in dict.iteritems(): 976 col = column_names[col_name] 977 yaxis = self.get_plot_axis(col, list) 978 sentence = sentence.replace(tok, 979 "numpy.array(%s)" % str(yaxis)) 980 for key, value in FUNC_DICT.iteritems(): 981 sentence = sentence.replace(key, value) 982 y = eval(sentence) 983 if len(x) != len(y) and (len(x) == 0 or len(y) == 0): 985 sentence = self.get_sentence(dict, sentence, column_names) 986 try: 987 y = eval(sentence) 988 except: 989 msg = "Need a proper y-range." 990 wx.PostEvent(self.parent.parent, 991 StatusEvent(status=msg, info="error")) 992 return 993 #evaluate y 994 sentence = self.dy_axis_label.GetValue() 995 dy = None 996 if sentence.strip() != "": 997 dict = parse_string(sentence, column_names.keys()) 998 sentence = self.get_sentence(dict, sentence, column_names) 999 try: 1000 dy = eval(sentence) 1001 except: 1002 msg = "Need a proper dy-range." 1003 wx.PostEvent(self.parent.parent, 1004 StatusEvent(status=msg, info="error")) 1005 return 1006 if len(x) != len(y) or (len(x) == 0 or len(y) == 0): 984 1007 msg = "Need same length for X and Y axis and both greater than 0" 985 1008 msg += " to plot.\n" … … 989 1012 StatusEvent(status=msg, info="error")) 990 1013 return 991 1014 if dy != None and (len(y) != len(dy)): 1015 msg = "Need same length for Y and dY axis and both greater than 0" 1016 msg += " to plot.\n" 1017 msg += "Got Y length = %s, dY length = %s" % (str(len(y)), 1018 str(len(dy))) 1019 wx.PostEvent(self.parent.parent, 1020 StatusEvent(status=msg, info="error")) 1021 return 992 1022 #plotting 993 new_plot = Data1D(x=x, y=y )1023 new_plot = Data1D(x=x, y=y, dy=dy) 994 1024 new_plot.id = wx.NewId() 995 1025 new_plot.group_id = wx.NewId() … … 1014 1044 wx.PostEvent(self.parent.parent, 1015 1045 StatusEvent(status=msg, info="error")) 1016 1046 1047 def get_sentence(self, dict, sentence, column_names): 1048 """ 1049 Get sentence from dict 1050 """ 1051 for tok, (col_name, list) in dict.iteritems(): 1052 col = column_names[col_name] 1053 axis = self.get_plot_axis(col, list) 1054 sentence = sentence.replace(tok, 1055 "numpy.array(%s)" % str(axis)) 1056 for key, value in FUNC_DICT.iteritems(): 1057 sentence = sentence.replace(key.lower(), value) 1058 return sentence 1059 1017 1060 def layout_grid(self): 1018 1061 """ … … 1032 1075 self.x_axis_label = wx.TextCtrl(self, -1, size=(200, -1)) 1033 1076 self.y_axis_label = wx.TextCtrl(self, -1, size=(200, -1)) 1077 self.dy_axis_label = wx.TextCtrl(self, -1, size=(200, -1)) 1034 1078 self.x_axis_add = wx.Button(self, -1, "Add") 1035 1079 self.x_axis_add.Bind(event=wx.EVT_BUTTON, handler=self.on_edit_axis, … … 1038 1082 self.y_axis_add.Bind(event=wx.EVT_BUTTON, handler=self.on_edit_axis, 1039 1083 id=self.y_axis_add.GetId()) 1084 self.dy_axis_add = wx.Button(self, -1, "Add") 1085 self.dy_axis_add.Bind(event=wx.EVT_BUTTON, handler=self.on_edit_axis, 1086 id=self.dy_axis_add.GetId()) 1040 1087 self.x_axis_unit = wx.TextCtrl(self, -1) 1041 1088 self.y_axis_unit = wx.TextCtrl(self, -1) … … 1075 1122 (wx.StaticText(self, -1 , "Y-axis Unit"), 1, wx.BOTTOM, 10), 1076 1123 (self.y_axis_unit, 1, wx.BOTTOM, 10), 1124 (wx.StaticText(self, -1, 1125 "dY Label (Optional)\nSelection Range"), 1, 1126 wx.BOTTOM|wx.LEFT, 10), 1127 (self.dy_axis_label, wx.BOTTOM, 10), 1128 (self.dy_axis_add, 1, wx.BOTTOM|wx.RIGHT, 10), 1077 1129 (-1, -1), 1078 1130 (-1, -1), … … 1102 1154 self.edit_axis_helper(self.y_axis_label, self.y_axis_title, 1103 1155 label, title) 1156 elif tcrtl == self.dy_axis_add: 1157 self.edit_axis_helper(self.dy_axis_label, None, 1158 label, None) 1104 1159 1105 1160 def create_axis_label(self, cell_list): … … 1117 1172 get controls to modify 1118 1173 """ 1119 tcrtl_label.SetValue(str(label)) 1120 tcrtl_title.SetValue(str(title)) 1174 if label != None: 1175 tcrtl_label.SetValue(str(label)) 1176 if title != None: 1177 tcrtl_title.SetValue(str(title)) 1121 1178 1122 1179 def add_column(self):
Note: See TracChangeset
for help on using the changeset viewer.