<commit_before>'''
Created on Oct 21, 2011

@author: bluec0re
'''
from __future__ import absolute_import


import os.path
import sys
import zipfile
import functools
import wx
from wx import xrc

from cvsscalc import cvsscalc
from wx.lib.masked import TimeCtrl

try:
    import wx.lib.agw.pygauge as PG
    
    class ColorGauge(PG.PyGauge):
        def __init__(self, *args, **kwargs):
            """Constructor
            
            Keyword arguments:
            *args -- 
            **kwargs -- 
            
            """
            super(ColorGauge, self).__init__(*args, **kwargs)
            self.SetBackgroundStyle(wx.BG_STYLE_SYSTEM)
            col = wx.Color()
            col.SetFromString('grey')
            self.SetBorderColor(col)
            self.SetBorderPadding(2)
            self._keys = {}
            
        def add_color_key(self, pos, color):
            """Adds a new color keypoint
            
            Keyword arguments:
            pos -- Position where the color starts
            color -- which color
            
            """
            if isinstance(color, int):
                color = '#%06x' % color
            col = wx.Color()
            col.SetFromString(color)
            self._keys[pos] = col
        
        def SetValue(self, pos):
            """Sets the new gauge value
            
            Keyword arguments:
            pos -- gauge value
            
            """
            color = self.GetBarColor()
    
            for key,col in self._keys.items():
                if pos == key:
                    color = col
                    break
                elif pos > key:
                    color = col
                elif pos < key:
                    break
            
            self.SetBarColour(color)
            super(ColorGauge, self).SetValue(pos)
            self.Refresh()


except ImportError:
    class ColorGauge(wx.Gauge):            
        def add_color_key(self, pos, color):
            """Dummy function. Does nothing
            """
            pass

def find_file(path):
    """Find the file named path in the sys.path.
    Returns the full path name if found, None if not found"""
    for dirname in sys.path:
        if os.path.isfile(dirname):
            zf = zipfile.ZipFile(dirname)
            if path in zf.namelist():
                data = zf.read(path)
                zf.close()
                return data

            continue

        possible = os.path.join(dirname, path)
        if os.path.isfile(possible):
            with open(possible, 'r') as fp:
                return fp.read()
    return None


class ScoreGauge(ColorGauge):
    def __init__(self, *args, **kwargs):
        """Constructor
        
        Keyword arguments:
        *args -- 
        **kwargs -- 
        
        """
        super(ScoreGauge, self).__init__(*args, **kwargs)
        
        self.add_color_key(0, 'green')
        self.add_color_key(40, 'yellow')
        self.add_color_key(70, 'red')
        
    def set_score(self, score):
        """Wrapper around SetValue.
        
        Keyword arguments:
        score -- 
        
        """
        self.SetValue(score*10)
     

class TimeCtrlHandler(xrc.XmlResourceHandler):
    def __init__(self):
        """Constructor
        
        
        """
        xrc.XmlResourceHandler.__init__(self)
        # Standard styles
        self.AddWindowStyles()
        # Custom styles
        
    def CanHandle(self,node):
        """returns True if this Handler can handle the given node
        
        Keyword arguments:
        node -- 
        
        """
        return self.IsOfClass(node, 'TimeCtrl')
    
    def DoCreateResource(self):
        """Creates a new Resource
        
        
        """
        assert self.GetInstance() is None
        w = TimeCtrl(parent=self.GetParentAsWindow(),
                     id=self.GetID(),
                     pos=self.GetPosition(),
                     size=self.GetSize(),
                     style=self.GetStyle())
        if self.GetText('value'):
            w.SetValue(self.GetText('value'))
        self.SetupWindow(w)
        return w
    
        
class ScoreGaugeHandler(xrc.XmlResourceHandler):
    def __init__(self):
        """Constructor
        
        
        """
        xrc.XmlResourceHandler.__init__(self)
        # Standard styles
        self.AddWindowStyles()
        # Custom styles
        self.AddStyle('wxGA_HORIZONTAL', wx.GA_HORIZONTAL)
        
        
    def CanHandle(self,node):
        """
        
        Keyword arguments:
        node -- 
        
        """
        return self.IsOfClass(node, 'ScoreGauge')
    
    def DoCreateResource(self):
        """
        <commit_msg>Zeitfeld mit initial now<commit_after>'''
Created on Oct 21, 2011

@author: bluec0re
'''
from __future__ import absolute_import


import os.path
import sys
import zipfile
import functools
import wx
from wx import xrc

from cvsscalc import cvsscalc
from wx.lib.masked import TimeCtrl

try:
    import wx.lib.agw.pygauge as PG
    
    class ColorGauge(PG.PyGauge):
        def __init__(self, *args, **kwargs):
            """Constructor
            
            Keyword arguments:
            *args -- 
            **kwargs -- 
            
            """
            super(ColorGauge, self).__init__(*args, **kwargs)
            self.SetBackgroundStyle(wx.BG_STYLE_SYSTEM)
            col = wx.Color()
            col.SetFromString('grey')
            self.SetBorderColor(col)
            self.SetBorderPadding(2)
            self._keys = {}
            
        def add_color_key(self, pos, color):
            """Adds a new color keypoint
            
            Keyword arguments:
            pos -- Position where the color starts
            color -- which color
            
            """
            if isinstance(color, int):
                color = '#%06x' % color
            col = wx.Color()
            col.SetFromString(color)
            self._keys[pos] = col
        
        def SetValue(self, pos):
            """Sets the new gauge value
            
            Keyword arguments:
            pos -- gauge value
            
            """
            color = self.GetBarColor()
    
            for key,col in self._keys.items():
                if pos == key:
                    color = col
                    break
                elif pos > key:
                    color = col
                elif pos < key:
                    break
            
            self.SetBarColour(color)
            super(ColorGauge, self).SetValue(pos)
            self.Refresh()


except ImportError:
    class ColorGauge(wx.Gauge):            
        def add_color_key(self, pos, color):
            """Dummy function. Does nothing
            """
            pass

def find_file(path):
    """Find the file named path in the sys.path.
    Returns the full path name if found, None if not found"""
    for dirname in sys.path:
        if os.path.isfile(dirname):
            zf = zipfile.ZipFile(dirname)
            if path in zf.namelist():
                data = zf.read(path)
                zf.close()
                return data

            continue

        possible = os.path.join(dirname, path)
        if os.path.isfile(possible):
            with open(possible, 'r') as fp:
                return fp.read()
    return None


class ScoreGauge(ColorGauge):
    def __init__(self, *args, **kwargs):
        """Constructor
        
        Keyword arguments:
        *args -- 
        **kwargs -- 
        
        """
        super(ScoreGauge, self).__init__(*args, **kwargs)
        
        self.add_color_key(0, 'green')
        self.add_color_key(40, 'yellow')
        self.add_color_key(70, 'red')
        
    def set_score(self, score):
        """Wrapper around SetValue.
        
        Keyword arguments:
        score -- 
        
        """
        self.SetValue(score*10)
     

class TimeCtrlHandler(xrc.XmlResourceHandler):
    def __init__(self):
        """Constructor
        
        
        """
        xrc.XmlResourceHandler.__init__(self)
        # Standard styles
        self.AddWindowStyles()
        # Custom styles
        
    def CanHandle(self,node):
        """returns True if this Handler can handle the given node
        
        Keyword arguments:
        node -- 
        
        """
        return self.IsOfClass(node, 'TimeCtrl')
    
    def DoCreateResource(self):
        """Creates a new Resource
        
        
        """
        assert self.GetInstance() is None
        w = TimeCtrl(parent=self.GetParentAsWindow(),
                     id=self.GetID(),
                     pos=self.GetPosition(),
                     size=self.GetSize(),
                     style=self.GetStyle())
        if self.GetText('value'):
            w.SetValue(self.GetText('value'))
        else:
            w.SetValue(wx.DateTime.Now())
        self.SetupWindow(w)
        return w
    
        
class ScoreGaugeHandler(xrc.XmlResourceHandler):
    def __init__(self):
        """Constructor
        
        
        """
        xrc.XmlResourceHandler.__init__(self)
        # Standard styles
        self.AddWindowStyles()
        # Custom styles
        self.AddStyle('wxGA_HORIZONTAL', wx.GA_HORIZONTAL)
        
        
    def CanHandle(self,node):
        """
        
        Keyword arguments:
        node -- 
        
        """
        return self.IsOfClass(node, 'ScoreGauge')
    
    def DoCreateResource(self):
        """
        
{'fraction_non_alphanumeric': 0.09544740973312402, 'fraction_numerical': 0.0035583464154892728, 'mean_word_length': 1.3484885721307447, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '574422', 'n_tokens_mistral': 2636, 'n_tokens_neox': 2542, 'n_words': 603}