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