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="0" |
---|
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 | class PanelMenu(wx.Menu): |
---|
24 | plots = None |
---|
25 | graph = None |
---|
26 | |
---|
27 | def set_plots(self, plots): |
---|
28 | self.plots = plots |
---|
29 | |
---|
30 | def set_graph(self, graph): |
---|
31 | self.graph = graph |
---|
32 | |
---|
33 | |
---|
34 | def split_list(separator, mylist, n=0): |
---|
35 | """ |
---|
36 | @return a list of string without white space of separator |
---|
37 | @param separator: the string to remove |
---|
38 | """ |
---|
39 | list=[] |
---|
40 | for item in mylist: |
---|
41 | if re.search( separator,item)!=None: |
---|
42 | if n >0: |
---|
43 | word =re.split(separator,item,int(n)) |
---|
44 | else: |
---|
45 | word =re.split( separator,item) |
---|
46 | for new_item in word: |
---|
47 | if new_item.lstrip().rstrip() !='': |
---|
48 | list.append(new_item.lstrip().rstrip()) |
---|
49 | return list |
---|
50 | def split_text(separator, string1, n=0): |
---|
51 | """ |
---|
52 | @return a list of string without white space of separator |
---|
53 | @param separator: the string to remove |
---|
54 | """ |
---|
55 | list=[] |
---|
56 | if re.search( separator,string1)!=None: |
---|
57 | if n >0: |
---|
58 | word =re.split(separator,string1,int(n)) |
---|
59 | else: |
---|
60 | word =re.split(separator,string1) |
---|
61 | for item in word: |
---|
62 | if item.lstrip().rstrip() !='': |
---|
63 | list.append(item.lstrip().rstrip()) |
---|
64 | return list |
---|
65 | def look_for_tag( string1,begin, end=None ): |
---|
66 | """ |
---|
67 | @note: this method remove the begin and end tags given by the user |
---|
68 | from the string . |
---|
69 | @param begin: the initial tag |
---|
70 | @param end: the final tag |
---|
71 | @param string: the string to check |
---|
72 | @return: begin_flag==True if begin was found, |
---|
73 | end_flag==if end was found else return false, false |
---|
74 | |
---|
75 | """ |
---|
76 | begin_flag= False |
---|
77 | end_flag= False |
---|
78 | if re.search( begin,string1)!=None: |
---|
79 | begin_flag= True |
---|
80 | if end !=None: |
---|
81 | if re.search(end,string1)!=None: |
---|
82 | end_flag= True |
---|
83 | return begin_flag, end_flag |
---|
84 | |
---|
85 | |
---|