<commit_before># coding=gbk

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *

import settings
import main


def get_path_head(api_name):
    api_item_list = api_name.split('|')[0].split('/')
    return api_item_list[0]


def get_method(api_name):
    api_item_list = api_name.split('| ')
    return api_item_list[-1]


class RotatedHeaderView(QHeaderView):
    def __init__(self, parent=None):
        super(RotatedHeaderView, self).__init__(Qt.Horizontal, parent)
        self.setMinimumSectionSize(20)

    def paintSection(self, painter, rect, logicalIndex ):
        painter.save()
        # translate the painter such that rotate will rotate around the correct point
        # painter.translate(rect.x()+rect.width(), rect.y())
        # painter.rotate(90)
        # painter.translate(rect.x(), rect.y()+rect.height())
        # painter.rotate(-90)
        # and have parent code paint at this location
        newrect = QRect(0, 0, rect.height(), rect.width())
        super(RotatedHeaderView, self).paintSection(painter, newrect, logicalIndex)
        painter.restore()

    def minimumSizeHint(self):
        size = super(RotatedHeaderView, self).minimumSizeHint()
        size.transpose()
        return size

    def sectionSizeFromContents(self, logicalIndex):
        size = super(RotatedHeaderView, self).sectionSizeFromContents(logicalIndex)
        size.transpose()
        return size


class HeaderViewFilter(QObject):
    def __init__(self, parent, header, *args):
        super(HeaderViewFilter, self).__init__(parent, *args)
        self.header = header
        self.prev_logical_index = -1

    def eventFilter(self, object, event):
        if event.type() == QEvent.HoverMove:
            logical_index = self.header.logicalIndexAt(event.pos())
            if self.prev_logical_index != logical_index:
                # print "haha " + str(logical_index)
                QToolTip.hideText()
                QToolTip.showText(QCursor.pos(), settings.api_list[logical_index])
            self.prev_logical_index = logical_index
        elif event.type() == QEvent.HoverLeave:
            QToolTip.hideText()
            self.prev_logical_index = -1
        return False
            # you could emit a signal here if you wanted


class LPTable(QTableWidget):
    def __init__(self, matrix, header_table):
        QTableWidget.__init__(self, settings.case_count, settings.api_count)
        self.matrix = matrix
        self.header_table = header_table
        self.set_data()
        self.resizeColumnsToContents()
        self.resizeRowsToContents()

        # headerView = RotatedHeaderView()
        # self.setHorizontalHeader(headerView)
        for i in range(settings.api_count):
            self.setColumnWidth(i, 20)

        # self.setMouseTracking(True)
        #
        # self.current_hover = [0, 0]
        # self.itemEntered.connect(self.header_hover)
        # self.horizontalHeader().enterEvent.connect(self.header_hover)

        self.filter = HeaderViewFilter(self, self.horizontalHeader())
        self.horizontalHeader().setMouseTracking(True)
        self.horizontalHeader().installEventFilter(self.filter)

        self.connect(self.horizontalScrollBar(), SIGNAL("valueChanged(int)"), self.sync_scroll)

    def sync_scroll(self):
        slide_value = self.horizontalScrollBar().value()
        # print slide_value
        self.header_table.horizontalScrollBar().setValue(slide_value)
        # self.sliderBar2.setValue(slide_value)

    # def header_hover(self, row):
    #     print str(row)
    #
    #     QToolTip.hideText()
    #     QToolTip.showText(QCursor.pos(), "aaa")
    #
    # def cell_hover(self, row, column):
    #     item = self.item(row, column)
    #     print str(row) + ", " + str(column)
    #     old_item = self.item(self.current_hover[0], self.current_hover[1])
    #     if self.current_hover != [row, column]:
    #         old_item.setBackground(QBrush(QColor('white')))
    #         item.setBackground(QBrush(QColor('yellow')))
    #     self.current_hover = [row, column]
    #
    #     QToolTip.hideText()
    #     QToolTip.showText(QCursor.pos(), "aaa")

    def set_data(self):
        # Column header
        hlist = []
        # self.setHorizontalHeaderLabels(settings.api_list)
        for i in range(settings.api_count):
            hlist.append(str(i))
            # hlist.append(str(i) + ":" + settings.api_list[i])
        self.setHorizontalHeaderLabels(hlist)

        for i in range(settings.api_count):
            header_item = self.horizontalHeaderItem(i)
            self.horizontalHeader()
            header_item.setBackground(QColor(255, 0, 0))

        # Row header
        vlist = []
        for i in range(settings.case_count):
            vlist.append(str(i) + ":" + settings.case_list[i])
        self.setVerticalHeaderLabels(vlist)
<commit_msg>Set header colors for different API methods.<commit_after># coding=gbk

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *

import settings
import main


def get_path_head(api_name):
    api_item_list = api_name.split('|')[0].split('/')
    return api_item_list[0]


def get_method(api_name):
    api_item_list = api_name.split('| ')
    return api_item_list[-1]


class RotatedHeaderView(QHeaderView):
    def __init__(self, parent=None):
        super(RotatedHeaderView, self).__init__(Qt.Horizontal, parent)
        self.setMinimumSectionSize(20)

    def paintSection(self, painter, rect, logicalIndex ):
        painter.save()
        # translate the painter such that rotate will rotate around the correct point
        # painter.translate(rect.x()+rect.width(), rect.y())
        # painter.rotate(90)
        # painter.translate(rect.x(), rect.y()+rect.height())
        # painter.rotate(-90)
        # and have parent code paint at this location
        newrect = QRect(0, 0, rect.height(), rect.width())
        super(RotatedHeaderView, self).paintSection(painter, newrect, logicalIndex)
        painter.restore()

    def minimumSizeHint(self):
        size = super(RotatedHeaderView, self).minimumSizeHint()
        size.transpose()
        return size

    def sectionSizeFromContents(self, logicalIndex):
        size = super(RotatedHeaderView, self).sectionSizeFromContents(logicalIndex)
        size.transpose()
        return size


class HeaderViewFilter(QObject):
    def __init__(self, parent, header, *args):
        super(HeaderViewFilter, self).__init__(parent, *args)
        self.header = header
        self.prev_logical_index = -1

    def eventFilter(self, object, event):
        if event.type() == QEvent.HoverMove:
            logical_index = self.header.logicalIndexAt(event.pos())
            if self.prev_logical_index != logical_index:
                # print "haha " + str(logical_index)
                QToolTip.hideText()
                QToolTip.showText(QCursor.pos(), settings.api_list[logical_index])
            self.prev_logical_index = logical_index
        elif event.type() == QEvent.HoverLeave:
            QToolTip.hideText()
            self.prev_logical_index = -1
        return False
            # you could emit a signal here if you wanted


class LPTable(QTableWidget):
    def __init__(self, matrix, header_table):
        QTableWidget.__init__(self, settings.case_count, settings.api_count)
        self.matrix = matrix
        self.header_table = header_table
        self.set_data()
        self.resizeColumnsToContents()
        self.resizeRowsToContents()

        # headerView = RotatedHeaderView()
        # self.setHorizontalHeader(headerView)
        for i in range(settings.api_count):
            self.setColumnWidth(i, 20)

        # self.setMouseTracking(True)
        #
        # self.current_hover = [0, 0]
        # self.itemEntered.connect(self.header_hover)
        # self.horizontalHeader().enterEvent.connect(self.header_hover)

        self.filter = HeaderViewFilter(self, self.horizontalHeader())
        self.horizontalHeader().setMouseTracking(True)
        self.horizontalHeader().installEventFilter(self.filter)

        self.connect(self.horizontalScrollBar(), SIGNAL("valueChanged(int)"), self.sync_scroll)

    def sync_scroll(self):
        slide_value = self.horizontalScrollBar().value()
        # print slide_value
        self.header_table.horizontalScrollBar().setValue(slide_value)
        # self.sliderBar2.setValue(slide_value)

    # def header_hover(self, row):
    #     print str(row)
    #
    #     QToolTip.hideText()
    #     QToolTip.showText(QCursor.pos(), "aaa")
    #
    # def cell_hover(self, row, column):
    #     item = self.item(row, column)
    #     print str(row) + ", " + str(column)
    #     old_item = self.item(self.current_hover[0], self.current_hover[1])
    #     if self.current_hover != [row, column]:
    #         old_item.setBackground(QBrush(QColor('white')))
    #         item.setBackground(QBrush(QColor('yellow')))
    #     self.current_hover = [row, column]
    #
    #     QToolTip.hideText()
    #     QToolTip.showText(QCursor.pos(), "aaa")

    def set_data(self):
        # Column header
        hlist = []
        # self.setHorizontalHeaderLabels(settings.api_list)
        for i in range(settings.api_count):
            hlist.append(str(i))
            # hlist.append(str(i) + ":" + settings.api_list[i])
        self.setHorizontalHeaderLabels(hlist)

        for i in range(settings.api_count):
            header_item = self.horizontalHeaderItem(i)
            self.horizontalHeader()
            if get_method(settings.api_list[i]) == 'GET':
                # Red
                header_item.setBackground(QColor(255, 0, 0))
            elif get_method(settings.api_list[i]) == 'POST':
                # Green
                header_item.setBackground(QColor(0, 255, 0))
            elif get_method(settings.api_list[i]) == 'PUT':
                # Blue
                header_item.setBackground(QColor(0, 0, 255))
            elif get_method(settings.api_list[i]) == 'DELETE':
                # Yellow
                header_item.setBackground(QColor(255, 255, 0))
            elif get_method(settings.api_list[i]) == 'HEAD':
                # Purple
                header_item.setBackground(QColor(255, 0, 255))
            else:
                # Black
                header_item.setBackground(QColor(0, 0, 0))

        # Row header
        vlist = []
        for i in range(settings.case_count):
            vlist.append(str(i) + ":" + settings.case_list[i])
        self.setVerticalHeaderLabels(vlist)

{'fraction_non_alphanumeric': 0.11498290922901633, 'fraction_numerical': 0.007690846942650969, 'mean_word_length': 2.585091899251191, 'pattern_counts': {'":': 4, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1898040', 'n_tokens_mistral': 3225, 'n_tokens_neox': 3113, 'n_words': 561}