<commit_before>import pygame
import os
from ..graphics import Surface, color_map

button_callback = None

left_margin = 25
bottom_margin = 12
top_margin = 12

bot_width = 470
bot_height = 353

wrapper = None


class Wrapper(Surface):
    def __init__(self):
        height = top_margin + bot_height + bottom_margin
        width = bot_width + left_margin
        self.surface = pygame.display.set_mode((width, height))
        background = pygame.image.load(os.path.join(os.path.dirname(__file__), 'bot.png'))
        self.surface.fill((50, 50, 50))
        self.surface.blit(background, (left_margin, top_margin))
        self.screen = self.surface.subsurface((86, 54, 320, 240))
        xPositions = (85, 125, 345, 385)
        self.buttons = []
        for x in range(4):
            self.buttons.append(Button(self.surface.subsurface(xPositions[x], top_margin, 22, 12), x))
        pygame.display.update()


class Button(Surface):
    def __init__(self, surface, number):
        from ..input import hit_areas, HitArea
        self.number = number
        self.color = color_map['grey']
        surface.fill(self.color)

        # register our button as something clickable
        self.surface = surface
        hit_areas.append(HitArea(pygame.Rect(surface.get_abs_offset(), surface.get_size()), self.click))

    def click(self, xy, action):
        if action == 'down':
            w, h = self.surface.get_size()
            self.surface.fill((0, 0, 0, 0), (0, 0, w, h*0.2))
            self.surface.fill(self.color, (0, h*0.2, w, h))
            if button_callback:
                button_callback(self.number, 'down')
        elif action == 'up':
            self.surface.fill(self.color)
            if button_callback:
                button_callback(self.number, 'up')
        pygame.display.update((self.surface.get_abs_offset(),self.surface.get_size()))

def initialise_if_needed():
    global wrapper
    if wrapper is None:
        pygame.init()
        wrapper = Wrapper()

def create_main_surface():
    initialise_if_needed()
    return wrapper.screen


def fixup_env():
    pass


def register_button_callback(callback):
    '''
    callback(button_index, action)
        button_index is a zero-based index that identifies which button has been pressed
        action is either 'down', or 'up'.

    The callback might not be called on the main thread.

    Currently only 'down' is implemented.
    '''
    initialise_if_needed()
    global button_callback
    button_callback = callback<commit_msg>Style edits to be more consistent with the rest of the project<commit_after>import pygame
import os

button_callback = None

left_margin = 25
bottom_margin = 12
top_margin = 12

bot_width = 470
bot_height = 353

background_color = (50, 50, 50)
button_color = (170, 170, 170)

simulator = None

class Simulator(object):
    def __init__(self):
        pygame.init()
        height = top_margin + bot_height + bottom_margin
        width = bot_width + left_margin
        self.surface = pygame.display.set_mode((width, height))

        self.screen = self.surface.subsurface((86, 54, 320, 240))
        button_positions = (85, 125, 345, 385)
        self.buttons = []

        for button_index, x_position in enumerate(button_positions):
            button_surface = self.surface.subsurface(x_position, top_margin, 22, 12)
            button = Button(button_surface, button_index)
            self.buttons.append(button)

        bot_image = pygame.image.load(os.path.join(os.path.dirname(__file__), 'bot.png'))
        self.surface.fill(background_color)
        self.surface.blit(bot_image, (left_margin, top_margin))
        pygame.display.update()


class Button(object):
    def __init__(self, surface, number):
        from ..input import hit_areas, HitArea
        self.number = number
        surface.fill(button_color)

        # register our button as something clickable
        self.surface = surface
        hit_areas.append(HitArea(pygame.Rect(surface.get_abs_offset(), surface.get_size()), self.click))

    def click(self, xy, action):
        if action == 'down':
            w, h = self.surface.get_size()
            self.surface.fill(background_color, (0, 0, w, h*0.2))
            self.surface.fill(button_color, (0, h*0.2, w, h))
            if button_callback:
                button_callback(self.number, 'down')
        elif action == 'up':
            self.surface.fill(button_color)
            if button_callback:
                button_callback(self.number, 'up')
        pygame.display.update((self.surface.get_abs_offset(), self.surface.get_size()))

def ensure_setup():
    if simulator is None:
        setup()

def setup():
    global simulator
    simulator = Simulator()

def create_main_surface():
    ensure_setup()
    return simulator.screen

def fixup_env():
    pass

def register_button_callback(callback):
    '''
    callback(button_index, action)
        button_index is a zero-based index that identifies which button has been pressed
        action is either 'down', or 'up'.

    The callback might not be called on the main thread.

    Currently only 'down' is implemented.
    '''
    ensure_setup()
    global button_callback
    button_callback = callback
{'fraction_non_alphanumeric': 0.10732733881767745, 'fraction_numerical': 0.021809833556533386, 'mean_word_length': 2.739628040057225, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2637100', 'n_tokens_mistral': 1662, 'n_tokens_neox': 1535, 'n_words': 397}