[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 | """ |
---|
| 25 | @param item2: txtcrtl containing the maximum value |
---|
| 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 |
---|
[858fabed] | 37 | def check_value( item1, item2): |
---|
| 38 | """ |
---|
| 39 | Check 2 txtcrtl value |
---|
| 40 | @param item1: txtcrtl containing the minimum value |
---|
| 41 | @param item2: txtcrtl containing the maximum value |
---|
| 42 | """ |
---|
[ac166e9c] | 43 | flag= False |
---|
| 44 | try: |
---|
| 45 | mini = float(format_number(item1.GetValue())) |
---|
| 46 | item1.SetBackgroundColour(wx.WHITE) |
---|
| 47 | item1.Refresh() |
---|
| 48 | except: |
---|
| 49 | flag = False |
---|
| 50 | item1.SetBackgroundColour("pink") |
---|
| 51 | item1.Refresh() |
---|
| 52 | return flag |
---|
| 53 | try: |
---|
| 54 | maxi = float(format_number(item2.GetValue())) |
---|
| 55 | item2.SetBackgroundColour("pink") |
---|
| 56 | item2.Refresh() |
---|
| 57 | except: |
---|
| 58 | flag = False |
---|
| 59 | item2.SetBackgroundColour("pink") |
---|
| 60 | item2.Refresh() |
---|
| 61 | return flag |
---|
| 62 | |
---|
[858fabed] | 63 | if mini < maxi: |
---|
| 64 | item1.SetBackgroundColour(wx.WHITE) |
---|
| 65 | item1.Refresh() |
---|
[ac166e9c] | 66 | item2.SetBackgroundColour(wx.WHITE) |
---|
| 67 | item2.Refresh() |
---|
| 68 | flag = True |
---|
[858fabed] | 69 | else: |
---|
| 70 | flag = False |
---|
| 71 | item1.SetBackgroundColour("pink") |
---|
| 72 | item1.Refresh() |
---|
| 73 | |
---|
| 74 | return flag |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | |
---|
[0d9dae8] | 78 | |
---|
| 79 | class PanelMenu(wx.Menu): |
---|
| 80 | plots = None |
---|
| 81 | graph = None |
---|
| 82 | |
---|
| 83 | def set_plots(self, plots): |
---|
| 84 | self.plots = plots |
---|
| 85 | |
---|
| 86 | def set_graph(self, graph): |
---|
[2bd9927] | 87 | self.graph = graph |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | def split_list(separator, mylist, n=0): |
---|
| 91 | """ |
---|
| 92 | @return a list of string without white space of separator |
---|
| 93 | @param separator: the string to remove |
---|
| 94 | """ |
---|
| 95 | list=[] |
---|
| 96 | for item in mylist: |
---|
| 97 | if re.search( separator,item)!=None: |
---|
| 98 | if n >0: |
---|
| 99 | word =re.split(separator,item,int(n)) |
---|
| 100 | else: |
---|
| 101 | word =re.split( separator,item) |
---|
| 102 | for new_item in word: |
---|
| 103 | if new_item.lstrip().rstrip() !='': |
---|
| 104 | list.append(new_item.lstrip().rstrip()) |
---|
| 105 | return list |
---|
| 106 | def split_text(separator, string1, n=0): |
---|
| 107 | """ |
---|
| 108 | @return a list of string without white space of separator |
---|
| 109 | @param separator: the string to remove |
---|
| 110 | """ |
---|
| 111 | list=[] |
---|
| 112 | if re.search( separator,string1)!=None: |
---|
| 113 | if n >0: |
---|
| 114 | word =re.split(separator,string1,int(n)) |
---|
| 115 | else: |
---|
| 116 | word =re.split(separator,string1) |
---|
| 117 | for item in word: |
---|
| 118 | if item.lstrip().rstrip() !='': |
---|
| 119 | list.append(item.lstrip().rstrip()) |
---|
| 120 | return list |
---|
| 121 | def look_for_tag( string1,begin, end=None ): |
---|
| 122 | """ |
---|
| 123 | @note: this method remove the begin and end tags given by the user |
---|
| 124 | from the string . |
---|
| 125 | @param begin: the initial tag |
---|
| 126 | @param end: the final tag |
---|
| 127 | @param string: the string to check |
---|
| 128 | @return: begin_flag==True if begin was found, |
---|
| 129 | end_flag==if end was found else return false, false |
---|
| 130 | |
---|
| 131 | """ |
---|
| 132 | begin_flag= False |
---|
| 133 | end_flag= False |
---|
| 134 | if re.search( begin,string1)!=None: |
---|
| 135 | begin_flag= True |
---|
| 136 | if end !=None: |
---|
| 137 | if re.search(end,string1)!=None: |
---|
| 138 | end_flag= True |
---|
| 139 | return begin_flag, end_flag |
---|
| 140 | |
---|
| 141 | |
---|