"""
     Contains common classes and functions
"""
import wx,re

def format_number(value, high=False):
    """
        Return a float in a standardized, human-readable formatted string 
    """
    try: 
        value = float(value)
    except:
        output="NaN"
        return output.lstrip().rstrip()
    
    if high:
        output= "%-6.4g" % value
        
    else:
        output= "%-5.3g" % value
    return output.lstrip().rstrip()

def check_float(item):
    """
       @param item: txtcrtl containing a value
    """
    flag= True
    try:
        mini = float(item.GetValue())
        item.SetBackgroundColour(wx.WHITE)
        item.Refresh()
    except:
        flag = False
        item.SetBackgroundColour("pink")
        item.Refresh()
    return flag


def check_value(item1, item2):
    """
        Check 2 txtcrtl item values if they are in order
        @param item1: txtcrtl containing value1
        @param item2: txtcrtl containing value2
        @return flag=True when value1<value2 
        Note: item1 backgroundcolour="white" when value1<value2 otherwise "pink"
    """
    flag= True
    flag_item1 = check_float(item1)
    flag_item2 = check_float(item2)
    if flag_item1 == False or flag_item2 == False:
        flag = False
    else:
        value_item1 = float(item1.GetValue())
        value_item2 = float(item2.GetValue())
        if value_item1 <  value_item2: 
          #Make sure to set both colours white.  
          item1.SetBackgroundColour(wx.WHITE)
          item1.Refresh()
          item2.SetBackgroundColour(wx.WHITE)
          item2.Refresh()
        else:
            flag = False
            item1.SetBackgroundColour("pink")
            item1.Refresh()      
    return flag
    
    
class PanelMenu(wx.Menu):
    plots = None
    graph = None
    
    def set_plots(self, plots):
        self.plots = plots
    
    def set_graph(self, graph):
        self.graph = graph
        

def split_list(separator, mylist, n=0):
    """
        @return a list of string without white space of separator
        @param separator: the string to remove
    """
    list=[]
    for item in mylist:
        if re.search( separator,item)!=None:
            if n >0:
                word =re.split(separator,item,int(n))
            else:
                word =re.split( separator,item)
            for new_item in word: 
                if new_item.lstrip().rstrip() !='':
                    list.append(new_item.lstrip().rstrip())
    return list
def split_text(separator, string1, n=0):
    """
        @return a list of string without white space of separator
        @param separator: the string to remove
    """
    list=[]
    if re.search( separator,string1)!=None:
        if n >0:
            word =re.split(separator,string1,int(n))
        else:
            word =re.split(separator,string1)
        for item in word: 
            if item.lstrip().rstrip() !='':
                list.append(item.lstrip().rstrip())
    return list
def look_for_tag( string1,begin, end=None ):
    """
        @note: this method  remove the begin and end tags given by the user
        from the string .
        @param begin: the initial tag
        @param end: the final tag
        @param string: the string to check
        @return: begin_flag==True if begin was found,
         end_flag==if end was found else return false, false
         
    """
    begin_flag= False
    end_flag= False
    if  re.search( begin,string1)!=None:
        begin_flag= True
    if end !=None:
        if  re.search(end,string1)!=None:
            end_flag= True
    return begin_flag, end_flag



@@ -808,1000 +808,8 @@
 %0D%0A%0D%0A
-%0D%0Adef check_value(item1, item2):%0D%0A    %22%22%22%0D%0A        Check 2 txtcrtl item values if they are in order%0D%0A        @param item1: txtcrtl containing value1%0D%0A        @param item2: txtcrtl containing value2%0D%0A        @return flag=True when value1%3Cvalue2 %0D%0A        Note: item1 backgroundcolour=%22white%22 when value1%3Cvalue2 otherwise %22pink%22%0D%0A    %22%22%22%0D%0A    flag= True%0D%0A    flag_item1 = check_float(item1)%0D%0A    flag_item2 = check_float(item2)%0D%0A    if flag_item1 == False or flag_item2 == False:%0D%0A        flag = False%0D%0A    else:%0D%0A        value_item1 = float(item1.GetValue())%0D%0A        value_item2 = float(item2.GetValue())%0D%0A        if value_item1 %3C  value_item2: %0D%0A          #Make sure to set both colours white.  %0D%0A          item1.SetBackgroundColour(wx.WHITE)%0D%0A          item1.Refresh()%0D%0A          item2.SetBackgroundColour(wx.WHITE)%0D%0A          item2.Refresh()%0D%0A        else:%0D%0A            flag = False%0D%0A            item1.SetBackgroundColour(%22pink%22)%0D%0A            item1.Refresh()      %0D%0A    return flag%0D%0A    %0D%0A
     

remove badly design util method