source: sasview/guiframe/utils.py @ 8db3904

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 8db3904 was 32c0841, checked in by Gervaise Alina <gervyh@…>, 14 years ago

working on pylint

  • Property mode set to 100644
File size: 2.8 KB
Line 
1"""
2Contains common classes and functions
3"""
4import wx
5import re
6
7def format_number(value, high=False):
8    """
9    Return a float in a standardized, human-readable formatted string
10    """
11    try: 
12        value = float(value)
13    except:
14        output = "NaN"
15        return output.lstrip().rstrip()
16    if high:
17        output = "%-6.4g" % value
18    else:
19        output = "%-5.3g" % value
20    return output.lstrip().rstrip()
21
22def check_float(item):
23    """
24    :param item: txtcrtl containing a value
25    """
26    flag = True
27    try:
28        mini = float(item.GetValue())
29        item.SetBackgroundColour(wx.WHITE)
30        item.Refresh()
31    except:
32        flag = False
33        item.SetBackgroundColour("pink")
34        item.Refresh()
35    return flag
36
37   
38class PanelMenu(wx.Menu):
39    """
40    """
41    plots = None
42    graph = None
43   
44    def set_plots(self, plots):
45        """
46        """
47        self.plots = plots
48   
49    def set_graph(self, graph):
50        """
51        """
52        self.graph = graph
53       
54
55def split_list(separator, mylist, n=0):
56    """
57    returns a list of string without white space of separator
58   
59    :param separator: the string to remove
60   
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
73
74def split_text(separator, string1, n=0):
75    """
76    return a list of string without white space of separator
77   
78    :param separator: the string to remove
79   
80    """
81    list = []
82    if re.search(separator, string1) is not None:
83        if n > 0:
84            word = re.split(separator,string1,int(n))
85        else:
86            word = re.split(separator,string1)
87        for item in word: 
88            if item.lstrip().rstrip() != '':
89                list.append(item.lstrip().rstrip())
90    return list
91
92def look_for_tag(string1, begin, end=None):
93    """
94    this method  remove the begin and end tags given by the user
95    from the string .
96   
97    :param begin: the initial tag
98    :param end: the final tag
99    :param string: the string to check
100   
101    :return: begin_flag==True if begin was found,
102     end_flag==if end was found else return false, false
103     
104    """
105    begin_flag = False
106    end_flag = False
107    if  re.search(begin,string1) is not None:
108        begin_flag = True
109    if end  is not None:
110        if  re.search(end,string1) is not None:
111            end_flag = True
112    return begin_flag, end_flag
113
Note: See TracBrowser for help on using the repository browser.