source: sasview/guiframe/utils.py @ f118fe2f

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

working on documentation

  • Property mode set to 100644
File size: 2.7 KB
RevLine 
[0d9dae8]1"""
[d955bf19]2Contains common classes and functions
[0d9dae8]3"""
[2bd9927]4import wx,re
[0d9dae8]5
6def format_number(value, high=False):
7    """
[d955bf19]8    Return a float in a standardized, human-readable formatted string
[0d9dae8]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    """
[d955bf19]25    :param item: txtcrtl containing a value
[74ad4b1]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
[a208464]37
[0d9dae8]38   
39class PanelMenu(wx.Menu):
[d955bf19]40    """
41    """
[0d9dae8]42    plots = None
43    graph = None
44   
45    def set_plots(self, plots):
[d955bf19]46        """
47        """
[0d9dae8]48        self.plots = plots
49   
50    def set_graph(self, graph):
[d955bf19]51        """
52        """
[2bd9927]53        self.graph = graph
54       
55
56def split_list(separator, mylist, n=0):
57    """
[d955bf19]58    returns a list of string without white space of separator
59   
60    :param separator: the string to remove
61   
[2bd9927]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
[d955bf19]74
[2bd9927]75def split_text(separator, string1, n=0):
76    """
[d955bf19]77    return a list of string without white space of separator
78   
79    :param separator: the string to remove
80   
[2bd9927]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
[d955bf19]92
93def look_for_tag(string1, begin, end=None):
[2bd9927]94    """
[d955bf19]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     
[2bd9927]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.