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