source: sasview/guiframe/utils.py @ 4e0806e8

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 4e0806e8 was 858fabed, checked in by Gervaise Alina <gervyh@…>, 16 years ago

add small function in utils

  • Property mode set to 100644
File size: 2.9 KB
Line 
1"""
2     Contains common classes and functions
3"""
4import wx,re
5
6def 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        output="0"
14        return output.lstrip().rstrip()
15   
16    if high:
17        output= "%-6.4g" % value
18       
19    else:
20        output= "%-5.3g" % value
21    return output.lstrip().rstrip()
22def 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   
43   
44class 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):
52        self.graph = graph
53       
54
55def 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
71def 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
86def 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
Note: See TracBrowser for help on using the repository browser.