[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: |
---|
| 13 | print "returning 0" |
---|
| 14 | return "0" |
---|
| 15 | |
---|
| 16 | if high: |
---|
| 17 | return "%-6.4g" % value |
---|
| 18 | else: |
---|
| 19 | return "%-5.3g" % value |
---|
| 20 | |
---|
| 21 | class PanelMenu(wx.Menu): |
---|
| 22 | plots = None |
---|
| 23 | graph = None |
---|
| 24 | |
---|
| 25 | def set_plots(self, plots): |
---|
| 26 | self.plots = plots |
---|
| 27 | |
---|
| 28 | def set_graph(self, graph): |
---|
[2bd9927] | 29 | self.graph = graph |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | def split_list(separator, mylist, n=0): |
---|
| 33 | """ |
---|
| 34 | @return a list of string without white space of separator |
---|
| 35 | @param separator: the string to remove |
---|
| 36 | """ |
---|
| 37 | list=[] |
---|
| 38 | for item in mylist: |
---|
| 39 | if re.search( separator,item)!=None: |
---|
| 40 | if n >0: |
---|
| 41 | word =re.split(separator,item,int(n)) |
---|
| 42 | else: |
---|
| 43 | word =re.split( separator,item) |
---|
| 44 | for new_item in word: |
---|
| 45 | if new_item.lstrip().rstrip() !='': |
---|
| 46 | list.append(new_item.lstrip().rstrip()) |
---|
| 47 | return list |
---|
| 48 | def split_text(separator, string1, n=0): |
---|
| 49 | """ |
---|
| 50 | @return a list of string without white space of separator |
---|
| 51 | @param separator: the string to remove |
---|
| 52 | """ |
---|
| 53 | list=[] |
---|
| 54 | if re.search( separator,string1)!=None: |
---|
| 55 | if n >0: |
---|
| 56 | word =re.split(separator,string1,int(n)) |
---|
| 57 | else: |
---|
| 58 | word =re.split(separator,string1) |
---|
| 59 | for item in word: |
---|
| 60 | if item.lstrip().rstrip() !='': |
---|
| 61 | list.append(item.lstrip().rstrip()) |
---|
| 62 | return list |
---|
| 63 | def look_for_tag( string1,begin, end=None ): |
---|
| 64 | """ |
---|
| 65 | @note: this method remove the begin and end tags given by the user |
---|
| 66 | from the string . |
---|
| 67 | @param begin: the initial tag |
---|
| 68 | @param end: the final tag |
---|
| 69 | @param string: the string to check |
---|
| 70 | @return: begin_flag==True if begin was found, |
---|
| 71 | end_flag==if end was found else return false, false |
---|
| 72 | |
---|
| 73 | """ |
---|
| 74 | begin_flag= False |
---|
| 75 | end_flag= False |
---|
| 76 | if re.search( begin,string1)!=None: |
---|
| 77 | begin_flag= True |
---|
| 78 | if end !=None: |
---|
| 79 | if re.search(end,string1)!=None: |
---|
| 80 | end_flag= True |
---|
| 81 | return begin_flag, end_flag |
---|
| 82 | |
---|
| 83 | |
---|