[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 | |
---|
[0d9dae8] | 38 | |
---|
| 39 | class PanelMenu(wx.Menu): |
---|
| 40 | plots = None |
---|
| 41 | graph = None |
---|
| 42 | |
---|
| 43 | def set_plots(self, plots): |
---|
| 44 | self.plots = plots |
---|
| 45 | |
---|
| 46 | def set_graph(self, graph): |
---|
[2bd9927] | 47 | self.graph = graph |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | def split_list(separator, mylist, n=0): |
---|
| 51 | """ |
---|
| 52 | @return a list of string without white space of separator |
---|
| 53 | @param separator: the string to remove |
---|
| 54 | """ |
---|
| 55 | list=[] |
---|
| 56 | for item in mylist: |
---|
| 57 | if re.search( separator,item)!=None: |
---|
| 58 | if n >0: |
---|
| 59 | word =re.split(separator,item,int(n)) |
---|
| 60 | else: |
---|
| 61 | word =re.split( separator,item) |
---|
| 62 | for new_item in word: |
---|
| 63 | if new_item.lstrip().rstrip() !='': |
---|
| 64 | list.append(new_item.lstrip().rstrip()) |
---|
| 65 | return list |
---|
| 66 | def split_text(separator, string1, n=0): |
---|
| 67 | """ |
---|
| 68 | @return a list of string without white space of separator |
---|
| 69 | @param separator: the string to remove |
---|
| 70 | """ |
---|
| 71 | list=[] |
---|
| 72 | if re.search( separator,string1)!=None: |
---|
| 73 | if n >0: |
---|
| 74 | word =re.split(separator,string1,int(n)) |
---|
| 75 | else: |
---|
| 76 | word =re.split(separator,string1) |
---|
| 77 | for item in word: |
---|
| 78 | if item.lstrip().rstrip() !='': |
---|
| 79 | list.append(item.lstrip().rstrip()) |
---|
| 80 | return list |
---|
| 81 | def look_for_tag( string1,begin, end=None ): |
---|
| 82 | """ |
---|
| 83 | @note: this method remove the begin and end tags given by the user |
---|
| 84 | from the string . |
---|
| 85 | @param begin: the initial tag |
---|
| 86 | @param end: the final tag |
---|
| 87 | @param string: the string to check |
---|
| 88 | @return: begin_flag==True if begin was found, |
---|
| 89 | end_flag==if end was found else return false, false |
---|
| 90 | |
---|
| 91 | """ |
---|
| 92 | begin_flag= False |
---|
| 93 | end_flag= False |
---|
| 94 | if re.search( begin,string1)!=None: |
---|
| 95 | begin_flag= True |
---|
| 96 | if end !=None: |
---|
| 97 | if re.search(end,string1)!=None: |
---|
| 98 | end_flag= True |
---|
| 99 | return begin_flag, end_flag |
---|
| 100 | |
---|
| 101 | |
---|