source: sasview/guiframe/utils.py @ bffc2ad

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 bffc2ad was 31f3f661, checked in by Gervaise Alina <gervyh@…>, 16 years ago

Nan in format_number

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