source: sasview/guiframe/utils.py @ 16f60cb

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 16f60cb was d955bf19, checked in by Gervaise Alina <gervyh@…>, 15 years ago

working on documentation

  • Property mode set to 100644
File size: 2.7 KB
Line 
1"""
2Contains 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="NaN"
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()
22
23def check_float(item):
24    """
25    :param item: txtcrtl containing a value
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
37
38   
39class PanelMenu(wx.Menu):
40    """
41    """
42    plots = None
43    graph = None
44   
45    def set_plots(self, plots):
46        """
47        """
48        self.plots = plots
49   
50    def set_graph(self, graph):
51        """
52        """
53        self.graph = graph
54       
55
56def split_list(separator, mylist, n=0):
57    """
58    returns a list of string without white space of separator
59   
60    :param separator: the string to remove
61   
62    """
63    list=[]
64    for item in mylist:
65        if re.search( separator,item)!=None:
66            if n >0:
67                word =re.split(separator,item,int(n))
68            else:
69                word =re.split( separator,item)
70            for new_item in word: 
71                if new_item.lstrip().rstrip() !='':
72                    list.append(new_item.lstrip().rstrip())
73    return list
74
75def split_text(separator, string1, n=0):
76    """
77    return a list of string without white space of separator
78   
79    :param separator: the string to remove
80   
81    """
82    list=[]
83    if re.search( separator,string1)!=None:
84        if n >0:
85            word =re.split(separator,string1,int(n))
86        else:
87            word =re.split(separator,string1)
88        for item in word: 
89            if item.lstrip().rstrip() !='':
90                list.append(item.lstrip().rstrip())
91    return list
92
93def look_for_tag(string1, begin, end=None):
94    """
95    this method  remove the begin and end tags given by the user
96    from the string .
97   
98    :param begin: the initial tag
99    :param end: the final tag
100    :param string: the string to check
101   
102    :return: begin_flag==True if begin was found,
103     end_flag==if end was found else return false, false
104     
105    """
106    begin_flag= False
107    end_flag= False
108    if  re.search( begin,string1)!=None:
109        begin_flag= True
110    if end !=None:
111        if  re.search(end,string1)!=None:
112            end_flag= True
113    return begin_flag, end_flag
Note: See TracBrowser for help on using the repository browser.