<commit_before>'''
Created on 07.06.2011

@author: michi
'''
from PyQt4.QtCore import Qt, QSize, QRect
from PyQt4.QtGui import QHeaderView, QAction, QTableView

class ParamAction(QAction):
    def triggerWithParams(self, model, row):
        self.trigger()
        
class ActionVHeaderView(QHeaderView):
    
    def __init__(self, iconSize=16, parent=None):
        if not isinstance(parent, QTableView):
            raise TypeError("Parent has to be QTableView")
        super(ActionVHeaderView, self).__init__(Qt.Vertical, parent)
        self._actions = []
        self.margin = 4
        if isinstance(iconSize, QSize):
            self.setIconSize(iconSize)
        else:
            self.setIconSize(QSize(iconSize,iconSize))
        
    def mousePressEvent(self, event):
        action = self.actionAt(event.pos())
        
        if action is not None:
            if isinstance(action, ParamAction):
                action.triggerWithParams(self.parent().model(),
                                         self.parent().rowAt(event.y()))
            else:
                action.trigger()
    
    def mouseMoveEvent(self, event):
        action = self.actionAt(event.pos())
        if action is not None:
            self.setToolTip(action.text())
    
    def actionAt(self, point):
        for action in self._actions:
            for rect in action.localRects:
                if rect.contains(point):
                    return action
    
    def sizeHint(self):
        width = (len(self._actions)* (self.iconSize().width() + self.margin)) +\
            self.margin
         
        return QSize(width,24)
    
    def addAction(self, action):
        action.localRects = []
        self._actions.append(action)

    def paintSection(self, painter, rect, index):
        
        xOffset = rect.x()
        for action in self._actions:
            iconRect = QRect(xOffset+self.margin,
                             rect.y() + ((rect.height()/2) - (self.iconSize().height()/2)),
                             self.iconSize().width(),
                             self.iconSize().height())
            
            action.localRects.append(iconRect)
            painter.drawImage(iconRect,action.icon().pixmap(self.iconSize()).toImage())
            xOffset += (self.iconSize().width() + self.margin)
    <commit_msg>* Solar und Energierechner sauber in Suche eingehangen * Ursprüngliches Widget in vertikalem Header trotzdem untendrunter gezeichnet<commit_after>'''
Created on 07.06.2011

@author: michi
'''
from PyQt4.QtCore import Qt, QSize, QRect
from PyQt4.QtGui import QHeaderView, QAction, QTableView

class ParamAction(QAction):
    def triggerWithParams(self, model, row):
        self.trigger()
        
class ActionVHeaderView(QHeaderView):
    
    def __init__(self, iconSize=16, parent=None):
        if not isinstance(parent, QTableView):
            raise TypeError("Parent has to be QTableView")
        super(ActionVHeaderView, self).__init__(Qt.Vertical, parent)
        self._actions = []
        self.margin = 4
        if isinstance(iconSize, QSize):
            self.setIconSize(iconSize)
        else:
            self.setIconSize(QSize(iconSize,iconSize))
        
    def mousePressEvent(self, event):
        action = self.actionAt(event.pos())
        
        if action is not None:
            if isinstance(action, ParamAction):
                action.triggerWithParams(self.parent().model(),
                                         self.parent().rowAt(event.y()))
            else:
                action.trigger()
    
    def mouseMoveEvent(self, event):
        action = self.actionAt(event.pos())
        if action is not None:
            self.setToolTip(action.text())
    
    def actionAt(self, point):
        for action in self._actions:
            for rect in action.localRects:
                if rect.contains(point):
                    return action
    
    def sizeHint(self):
        width = (len(self._actions)* (self.iconSize().width() + self.margin)) +\
            self.margin + super(ActionVHeaderView, self).sizeHint().width()
         
        return QSize(width,24)
    
    def addAction(self, action):
        action.localRects = []
        self._actions.append(action)

    def paintSection(self, painter, rect, index):
        super(ActionVHeaderView, self).paintSection(painter, rect, index)
        xOffset = rect.x()
        for action in self._actions:
            iconRect = QRect(xOffset+self.margin,
                             rect.y() + ((rect.height()/2) - (self.iconSize().height()/2)),
                             self.iconSize().width(),
                             self.iconSize().height())
            
            action.localRects.append(iconRect)
            painter.drawImage(iconRect,action.icon().pixmap(self.iconSize()).toImage())
            xOffset += (self.iconSize().width() + self.margin)
    
{'fraction_non_alphanumeric': 0.1137846655791191, 'fraction_numerical': 0.006933115823817292, 'mean_word_length': 1.9548192771084338, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4320446', 'n_tokens_mistral': 1377, 'n_tokens_neox': 1359, 'n_words': 287}