[0d9dae8] | 1 | """ |
---|
[12aa9b5] | 2 | Contains common classes and functions |
---|
[0d9dae8] | 3 | """ |
---|
[2bd9927] | 4 | import wx,re |
---|
[0d9dae8] | 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: |
---|
[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 | """ |
---|
[a208464] | 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 | |
---|
| 38 | |
---|
| 39 | def check_value(item1, item2): |
---|
[858fabed] | 40 | """ |
---|
[a208464] | 41 | Check 2 txtcrtl item values if they are in order |
---|
| 42 | @param item1: txtcrtl containing value1 |
---|
| 43 | @param item2: txtcrtl containing value2 |
---|
| 44 | @return flag=True when value1<value2 |
---|
| 45 | Note: item1 backgroundcolour="white" when value1<value2 otherwise "pink" |
---|
[858fabed] | 46 | """ |
---|
[a208464] | 47 | flag= True |
---|
| 48 | flag_item1 = check_float(item1) |
---|
| 49 | flag_item2 = check_float(item2) |
---|
| 50 | if flag_item1 == False or flag_item2 == False: |
---|
[ac166e9c] | 51 | flag = False |
---|
[858fabed] | 52 | else: |
---|
[a208464] | 53 | value_item1 = float(item1.GetValue()) |
---|
| 54 | value_item2 = float(item2.GetValue()) |
---|
| 55 | if value_item1 < value_item2: |
---|
| 56 | #Make sure to set both colours white. |
---|
| 57 | item1.SetBackgroundColour(wx.WHITE) |
---|
| 58 | item1.Refresh() |
---|
| 59 | item2.SetBackgroundColour(wx.WHITE) |
---|
| 60 | item2.Refresh() |
---|
| 61 | else: |
---|
| 62 | flag = False |
---|
| 63 | item1.SetBackgroundColour("pink") |
---|
| 64 | item1.Refresh() |
---|
[858fabed] | 65 | return flag |
---|
| 66 | |
---|
[0d9dae8] | 67 | |
---|
| 68 | class PanelMenu(wx.Menu): |
---|
| 69 | plots = None |
---|
| 70 | graph = None |
---|
| 71 | |
---|
| 72 | def set_plots(self, plots): |
---|
| 73 | self.plots = plots |
---|
| 74 | |
---|
| 75 | def set_graph(self, graph): |
---|
[2bd9927] | 76 | self.graph = graph |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | def split_list(separator, mylist, n=0): |
---|
| 80 | """ |
---|
| 81 | @return a list of string without white space of separator |
---|
| 82 | @param separator: the string to remove |
---|
| 83 | """ |
---|
| 84 | list=[] |
---|
| 85 | for item in mylist: |
---|
| 86 | if re.search( separator,item)!=None: |
---|
| 87 | if n >0: |
---|
| 88 | word =re.split(separator,item,int(n)) |
---|
| 89 | else: |
---|
| 90 | word =re.split( separator,item) |
---|
| 91 | for new_item in word: |
---|
| 92 | if new_item.lstrip().rstrip() !='': |
---|
| 93 | list.append(new_item.lstrip().rstrip()) |
---|
| 94 | return list |
---|
| 95 | def split_text(separator, string1, n=0): |
---|
| 96 | """ |
---|
| 97 | @return a list of string without white space of separator |
---|
| 98 | @param separator: the string to remove |
---|
| 99 | """ |
---|
| 100 | list=[] |
---|
| 101 | if re.search( separator,string1)!=None: |
---|
| 102 | if n >0: |
---|
| 103 | word =re.split(separator,string1,int(n)) |
---|
| 104 | else: |
---|
| 105 | word =re.split(separator,string1) |
---|
| 106 | for item in word: |
---|
| 107 | if item.lstrip().rstrip() !='': |
---|
| 108 | list.append(item.lstrip().rstrip()) |
---|
| 109 | return list |
---|
| 110 | def look_for_tag( string1,begin, end=None ): |
---|
| 111 | """ |
---|
| 112 | @note: this method remove the begin and end tags given by the user |
---|
| 113 | from the string . |
---|
| 114 | @param begin: the initial tag |
---|
| 115 | @param end: the final tag |
---|
| 116 | @param string: the string to check |
---|
| 117 | @return: begin_flag==True if begin was found, |
---|
| 118 | end_flag==if end was found else return false, false |
---|
| 119 | |
---|
| 120 | """ |
---|
| 121 | begin_flag= False |
---|
| 122 | end_flag= False |
---|
| 123 | if re.search( begin,string1)!=None: |
---|
| 124 | begin_flag= True |
---|
| 125 | if end !=None: |
---|
| 126 | if re.search(end,string1)!=None: |
---|
| 127 | end_flag= True |
---|
| 128 | return begin_flag, end_flag |
---|
| 129 | |
---|
| 130 | |
---|