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