1 | """ |
---|
2 | Contains common classes and functions |
---|
3 | """ |
---|
4 | import wx,re |
---|
5 | |
---|
6 | def format_number(value, high=False): |
---|
7 | """ |
---|
8 | Return a float in a standardized, human-readable formatted string |
---|
9 | """ |
---|
10 | try: |
---|
11 | value = float(value) |
---|
12 | except: |
---|
13 | output="NaN" |
---|
14 | return output.lstrip().rstrip() |
---|
15 | |
---|
16 | if high: |
---|
17 | output= "%-6.4g" % value |
---|
18 | |
---|
19 | else: |
---|
20 | output= "%-5.3g" % value |
---|
21 | return output.lstrip().rstrip() |
---|
22 | |
---|
23 | |
---|
24 | def check_value( item1, item2): |
---|
25 | """ |
---|
26 | Check 2 txtcrtl value |
---|
27 | @param item1: txtcrtl containing the minimum value |
---|
28 | @param item2: txtcrtl containing the maximum value |
---|
29 | """ |
---|
30 | mini = float(format_number(item1.GetValue())) |
---|
31 | maxi = float(format_number(item2.GetValue())) |
---|
32 | flag= True |
---|
33 | if mini < maxi: |
---|
34 | item1.SetBackgroundColour(wx.WHITE) |
---|
35 | item1.Refresh() |
---|
36 | else: |
---|
37 | flag = False |
---|
38 | item1.SetBackgroundColour("pink") |
---|
39 | item1.Refresh() |
---|
40 | |
---|
41 | return flag |
---|
42 | |
---|
43 | |
---|
44 | |
---|
45 | |
---|
46 | class PanelMenu(wx.Menu): |
---|
47 | plots = None |
---|
48 | graph = None |
---|
49 | |
---|
50 | def set_plots(self, plots): |
---|
51 | self.plots = plots |
---|
52 | |
---|
53 | def set_graph(self, graph): |
---|
54 | self.graph = graph |
---|
55 | |
---|
56 | |
---|
57 | def split_list(separator, mylist, n=0): |
---|
58 | """ |
---|
59 | @return a list of string without white space of separator |
---|
60 | @param separator: the string to remove |
---|
61 | """ |
---|
62 | list=[] |
---|
63 | for item in mylist: |
---|
64 | if re.search( separator,item)!=None: |
---|
65 | if n >0: |
---|
66 | word =re.split(separator,item,int(n)) |
---|
67 | else: |
---|
68 | word =re.split( separator,item) |
---|
69 | for new_item in word: |
---|
70 | if new_item.lstrip().rstrip() !='': |
---|
71 | list.append(new_item.lstrip().rstrip()) |
---|
72 | return list |
---|
73 | def split_text(separator, string1, n=0): |
---|
74 | """ |
---|
75 | @return a list of string without white space of separator |
---|
76 | @param separator: the string to remove |
---|
77 | """ |
---|
78 | list=[] |
---|
79 | if re.search( separator,string1)!=None: |
---|
80 | if n >0: |
---|
81 | word =re.split(separator,string1,int(n)) |
---|
82 | else: |
---|
83 | word =re.split(separator,string1) |
---|
84 | for item in word: |
---|
85 | if item.lstrip().rstrip() !='': |
---|
86 | list.append(item.lstrip().rstrip()) |
---|
87 | return list |
---|
88 | def look_for_tag( string1,begin, end=None ): |
---|
89 | """ |
---|
90 | @note: this method remove the begin and end tags given by the user |
---|
91 | from the string . |
---|
92 | @param begin: the initial tag |
---|
93 | @param end: the final tag |
---|
94 | @param string: the string to check |
---|
95 | @return: begin_flag==True if begin was found, |
---|
96 | end_flag==if end was found else return false, false |
---|
97 | |
---|
98 | """ |
---|
99 | begin_flag= False |
---|
100 | end_flag= False |
---|
101 | if re.search( begin,string1)!=None: |
---|
102 | begin_flag= True |
---|
103 | if end !=None: |
---|
104 | if re.search(end,string1)!=None: |
---|
105 | end_flag= True |
---|
106 | return begin_flag, end_flag |
---|
107 | |
---|
108 | |
---|