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
RevLine 
[0d9dae8]1"""
[d955bf19]2Contains common classes and functions
[0d9dae8]3"""
[32c0841]4import wx
5import re
[0d9dae8]6
7def format_number(value, high=False):
8    """
[d955bf19]9    Return a float in a standardized, human-readable formatted string
[0d9dae8]10    """
11    try: 
12        value = float(value)
13    except:
[32c0841]14        output = "NaN"
[4ba846b]15        return output.lstrip().rstrip()
[0d9dae8]16    if high:
[32c0841]17        output = "%-6.4g" % value
[0d9dae8]18    else:
[32c0841]19        output = "%-5.3g" % value
[4ba846b]20    return output.lstrip().rstrip()
[31f3f661]21
[74ad4b1]22def check_float(item):
23    """
[d955bf19]24    :param item: txtcrtl containing a value
[74ad4b1]25    """
[32c0841]26    flag = True
[74ad4b1]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
[a208464]36
[0d9dae8]37   
38class PanelMenu(wx.Menu):
[d955bf19]39    """
40    """
[0d9dae8]41    plots = None
42    graph = None
43   
44    def set_plots(self, plots):
[d955bf19]45        """
46        """
[0d9dae8]47        self.plots = plots
48   
49    def set_graph(self, graph):
[d955bf19]50        """
51        """
[2bd9927]52        self.graph = graph
53       
54
55def split_list(separator, mylist, n=0):
56    """
[d955bf19]57    returns a list of string without white space of separator
58   
59    :param separator: the string to remove
60   
[2bd9927]61    """
[32c0841]62    list = []
[2bd9927]63    for item in mylist:
[32c0841]64        if re.search(separator,item)!= None:
65            if n > 0:
66                word = re.split(separator, item, int(n))
[2bd9927]67            else:
[32c0841]68                word = re.split(separator, item)
[2bd9927]69            for new_item in word: 
[32c0841]70                if new_item.lstrip().rstrip() != '':
[2bd9927]71                    list.append(new_item.lstrip().rstrip())
72    return list
[d955bf19]73
[2bd9927]74def split_text(separator, string1, n=0):
75    """
[d955bf19]76    return a list of string without white space of separator
77   
78    :param separator: the string to remove
79   
[2bd9927]80    """
[32c0841]81    list = []
82    if re.search(separator, string1) is not None:
83        if n > 0:
84            word = re.split(separator,string1,int(n))
[2bd9927]85        else:
[32c0841]86            word = re.split(separator,string1)
[2bd9927]87        for item in word: 
[32c0841]88            if item.lstrip().rstrip() != '':
[2bd9927]89                list.append(item.lstrip().rstrip())
90    return list
[d955bf19]91
92def look_for_tag(string1, begin, end=None):
[2bd9927]93    """
[d955bf19]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     
[2bd9927]104    """
[32c0841]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
[2bd9927]112    return begin_flag, end_flag
[32c0841]113
Note: See TracBrowser for help on using the repository browser.