<commit_before>from collections import defaultdict
from color import *

import sys, pygame
from pygame.locals import *
from label import Label

__author__ = 'richard'


class Button(object):
    def __init__(self, screen):
        self.buttons = {}
        self.screen = screen
        self.attributes = defaultdict(dict)
        self.render_queue = None
        self.label = Label('Button_Label')

    def add_button(self,name,task_on_click,x1,y1,x2,y2):
        self.buttons[name] = (task_on_click,x1,x2,y1,y2)
        self.attributes[name]['x_left'] = x1
        self.attributes[name]['y_top'] = y1
        self.attributes[name]['width'] = x2 - x1
        self.attributes[name]['height'] = y2 - y1
        self.attributes[name]['color'] = red
        self.label.add_label(name,'',x1,y1,active=False)

    def add_attributes(self,name,type, value):
        self.attributes[name][type] = value
        if type == 'text':
            self.label.set_text(name,value)
            self.label.add_attribute(name,'active',True)
        #if we are chaing the position of the button, we need to update the position of the label as well
        if type=='x_left':
            self.label.add_attribute(name,'x',value)
        if type=='y_top':
            self.label.add_attribute(name,'y',value)

        self.render_queue.put(1)


    def set_render_queue(self, queue):
        self.render_queue = queue


    def on_click(self,x,y):
        for button in self.buttons:
            #pprint(button)
            value = self.buttons[button]
            #print "I have X: %s <= %s <= %s  Y: %s <= %s <= %s" % (value[1],str(x),value[2],value[3],str(y),value[4])
            if value[1] <= x <= value[2] and value[3] <= y <= value[4]:
                value[0]()<commit_msg>added the render queue to subclass label<commit_after>from collections import defaultdict
from color import *

import sys, pygame
from pygame.locals import *
from label import Label

__author__ = 'richard'


class Button(object):
    def __init__(self, screen):
        self.buttons = {}
        self.screen = screen
        self.attributes = defaultdict(dict)
        self.render_queue = None
        self.label = Label('Button_Label')

    def add_button(self,name,task_on_click,x1,y1,x2,y2):
        self.buttons[name] = (task_on_click,x1,x2,y1,y2)
        self.attributes[name]['x_left'] = x1
        self.attributes[name]['y_top'] = y1
        self.attributes[name]['width'] = x2 - x1
        self.attributes[name]['height'] = y2 - y1
        self.attributes[name]['color'] = red
        self.label.add_label(name,'',x1,y1,active=False)


    def add_attributes(self,name,type, value):
        self.attributes[name][type] = value
        if type == 'text':
            self.label.set_text(name,value)
            self.label.add_attribute(name,'active',True)
        #if we are chaing the position of the button, we need to update the position of the label as well
        if type=='x_left':
            self.label.add_attribute(name,'x',value)
        if type=='y_top':
            self.label.add_attribute(name,'y',value)

        self.render_queue.put(1)


    def set_render_queue(self, queue):
        self.render_queue = queue
        self.label.set_render_queue(self.render_queue)


    def on_click(self,x,y):
        for button in self.buttons:
            #pprint(button)
            value = self.buttons[button]
            #print "I have X: %s <= %s <= %s  Y: %s <= %s <= %s" % (value[1],str(x),value[2],value[3],str(y),value[4])
            if value[1] <= x <= value[2] and value[3] <= y <= value[4]:
                value[0]()
{'fraction_non_alphanumeric': 0.13952843273231622, 'fraction_numerical': 0.014424410540915394, 'mean_word_length': 2.6424242424242426, 'pattern_counts': {'":': 0, '<': 19, '<?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': '1710622', 'n_tokens_mistral': 1187, 'n_tokens_neox': 1161, 'n_words': 250}