source: sasview/guiframe/utils.py @ 2389bd4

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 2389bd4 was e051c8d, checked in by Mathieu Doucet <doucetm@…>, 15 years ago

guiframe: remove badly design util method

  • Property mode set to 100644
File size: 2.7 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="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    plots = None
41    graph = None
42   
43    def set_plots(self, plots):
44        self.plots = plots
45   
46    def set_graph(self, graph):
47        self.graph = graph
48       
49
50def 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
66def 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
81def 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
Note: See TracBrowser for help on using the repository browser.