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