source: sasview/guiframe/utils.py @ ac166e9c

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

checking min and max value

  • Property mode set to 100644
File size: 3.4 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
23
24def check_value( item1, item2):
25    """
26        Check 2 txtcrtl value
27        @param item1: txtcrtl containing the minimum value
28        @param item2: txtcrtl containing the maximum value
29    """
30    flag= False
31    try:
32        mini = float(format_number(item1.GetValue()))
33        item1.SetBackgroundColour(wx.WHITE)
34        item1.Refresh()
35    except:
36        flag = False
37        item1.SetBackgroundColour("pink")
38        item1.Refresh()
39        return flag
40    try:   
41        maxi = float(format_number(item2.GetValue()))
42        item2.SetBackgroundColour("pink")
43        item2.Refresh()
44    except:
45        flag = False
46        item2.SetBackgroundColour("pink")
47        item2.Refresh()
48        return flag
49   
50    if mini <  maxi: 
51      item1.SetBackgroundColour(wx.WHITE)
52      item1.Refresh()
53      item2.SetBackgroundColour(wx.WHITE)
54      item2.Refresh()
55      flag = True
56    else:
57        flag = False
58        item1.SetBackgroundColour("pink")
59        item1.Refresh()
60     
61    return flag
62   
63   
64   
65   
66class PanelMenu(wx.Menu):
67    plots = None
68    graph = None
69   
70    def set_plots(self, plots):
71        self.plots = plots
72   
73    def set_graph(self, graph):
74        self.graph = graph
75       
76
77def split_list(separator, mylist, n=0):
78    """
79        @return a list of string without white space of separator
80        @param separator: the string to remove
81    """
82    list=[]
83    for item in mylist:
84        if re.search( separator,item)!=None:
85            if n >0:
86                word =re.split(separator,item,int(n))
87            else:
88                word =re.split( separator,item)
89            for new_item in word: 
90                if new_item.lstrip().rstrip() !='':
91                    list.append(new_item.lstrip().rstrip())
92    return list
93def split_text(separator, string1, n=0):
94    """
95        @return a list of string without white space of separator
96        @param separator: the string to remove
97    """
98    list=[]
99    if re.search( separator,string1)!=None:
100        if n >0:
101            word =re.split(separator,string1,int(n))
102        else:
103            word =re.split(separator,string1)
104        for item in word: 
105            if item.lstrip().rstrip() !='':
106                list.append(item.lstrip().rstrip())
107    return list
108def look_for_tag( string1,begin, end=None ):
109    """
110        @note: this method  remove the begin and end tags given by the user
111        from the string .
112        @param begin: the initial tag
113        @param end: the final tag
114        @param string: the string to check
115        @return: begin_flag==True if begin was found,
116         end_flag==if end was found else return false, false
117         
118    """
119    begin_flag= False
120    end_flag= False
121    if  re.search( begin,string1)!=None:
122        begin_flag= True
123    if end !=None:
124        if  re.search(end,string1)!=None:
125            end_flag= True
126    return begin_flag, end_flag
127
128
Note: See TracBrowser for help on using the repository browser.