source: sasview/guiframe/utils.py @ 383eeaa

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 383eeaa was 7ab35154, checked in by Jae Cho <jhjcho@…>, 15 years ago

correction of wrong color for setbackground in check_value

  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[0d9dae8]1"""
[12aa9b5]2     Contains common classes and functions
[0d9dae8]3"""
[2bd9927]4import wx,re
[0d9dae8]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:
[31f3f661]13        output="NaN"
[4ba846b]14        return output.lstrip().rstrip()
[0d9dae8]15   
16    if high:
[4ba846b]17        output= "%-6.4g" % value
18       
[0d9dae8]19    else:
[4ba846b]20        output= "%-5.3g" % value
21    return output.lstrip().rstrip()
[31f3f661]22
[74ad4b1]23def check_float(item):
24    """
25       @param item2: txtcrtl containing the maximum 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
[858fabed]37def check_value( item1, item2):
38    """
39        Check 2 txtcrtl value
40        @param item1: txtcrtl containing the minimum value
41        @param item2: txtcrtl containing the maximum value
42    """
[ac166e9c]43    flag= False
44    try:
45        mini = float(format_number(item1.GetValue()))
46        item1.SetBackgroundColour(wx.WHITE)
47        item1.Refresh()
48    except:
49        flag = False
50        item1.SetBackgroundColour("pink")
51        item1.Refresh()
52        return flag
53    try:   
54        maxi = float(format_number(item2.GetValue()))
[7ab35154]55        item2.SetBackgroundColour(wx.WHITE)
[ac166e9c]56        item2.Refresh()
57    except:
58        flag = False
59        item2.SetBackgroundColour("pink")
60        item2.Refresh()
61        return flag
62   
[858fabed]63    if mini <  maxi: 
64      item1.SetBackgroundColour(wx.WHITE)
65      item1.Refresh()
[ac166e9c]66      item2.SetBackgroundColour(wx.WHITE)
67      item2.Refresh()
68      flag = True
[858fabed]69    else:
70        flag = False
71        item1.SetBackgroundColour("pink")
72        item1.Refresh()
73     
74    return flag
75   
76   
77   
[0d9dae8]78   
79class PanelMenu(wx.Menu):
80    plots = None
81    graph = None
82   
83    def set_plots(self, plots):
84        self.plots = plots
85   
86    def set_graph(self, graph):
[2bd9927]87        self.graph = graph
88       
89
90def split_list(separator, mylist, n=0):
91    """
92        @return a list of string without white space of separator
93        @param separator: the string to remove
94    """
95    list=[]
96    for item in mylist:
97        if re.search( separator,item)!=None:
98            if n >0:
99                word =re.split(separator,item,int(n))
100            else:
101                word =re.split( separator,item)
102            for new_item in word: 
103                if new_item.lstrip().rstrip() !='':
104                    list.append(new_item.lstrip().rstrip())
105    return list
106def split_text(separator, string1, n=0):
107    """
108        @return a list of string without white space of separator
109        @param separator: the string to remove
110    """
111    list=[]
112    if re.search( separator,string1)!=None:
113        if n >0:
114            word =re.split(separator,string1,int(n))
115        else:
116            word =re.split(separator,string1)
117        for item in word: 
118            if item.lstrip().rstrip() !='':
119                list.append(item.lstrip().rstrip())
120    return list
121def look_for_tag( string1,begin, end=None ):
122    """
123        @note: this method  remove the begin and end tags given by the user
124        from the string .
125        @param begin: the initial tag
126        @param end: the final tag
127        @param string: the string to check
128        @return: begin_flag==True if begin was found,
129         end_flag==if end was found else return false, false
130         
131    """
132    begin_flag= False
133    end_flag= False
134    if  re.search( begin,string1)!=None:
135        begin_flag= True
136    if end !=None:
137        if  re.search(end,string1)!=None:
138            end_flag= True
139    return begin_flag, end_flag
140
141
Note: See TracBrowser for help on using the repository browser.