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