<commit_before># Keyboard Gui Class
# -------------------
import functools
import math
import random
import time

from PyQt5 import QtGui, QtWidgets, QtCore
from PyQt5.QtCore import QTimer


class Keyboard:
    # constructor
    def __init__(self, main_panel, character_display_panel, interval):
        # Style sheets
        self.DEFAULT_STYLESHEET = "QPushButton {background-color: #444444; " \
                                  "color: white; font-size: 65px;}"
        self.PREDICT_STYLESHEET = "QPushButton {background-color: #444444; " \
                                  "color: white; font-size: 50px;}"
        self.DARKEN_STYLESHEET = "QPushButton {background-color: #444444; " \
                                 "color: blue; font-size: 65px;}"

        self.main_panel = main_panel
        self.character_display_panel = character_display_panel

        self.predict_buttons = []
        self.character_buttons = []

        # creating a button grid
        self.key_grid = self.make_keyboard_widget(character_display_panel)

        self.num_grid = None

        # Top 3 Word Predictions
        self.predict_grid = QtWidgets.QGridLayout()
        self.predict_grid.setSpacing(0)

        self.make_predictions_widget()

        # variables used for pausing
        self.flashing_interval = interval

        # attaching grid to main panel
        self.main_panel.addLayout(self.predict_grid)
        self.main_panel.addLayout(self.key_grid)

        # variables used for flashing
        self.flash_timer_queue = []
        self.row_col_flash_order = []
        self.time_start = 0
        self.time_elapsed = 0

    def make_keyboard_widget(self, character_display_panel):
        ret_key_grid = QtWidgets.QGridLayout()
        ret_key_grid.setSpacing(0)

        for row in range(6):
            for col in range(6):
                # button_name = ""
                character_number = (row * 6) + col
                # a-z buttons
                if character_number < 26:
                    button_name = chr(ord('a') + character_number)
                    self.add_key_to_keyboard(ret_key_grid,
                                             button_name,
                                             character_display_panel,
                                             row, col)

                elif character_number is 26:
                    button_name = "0"

                    button = QtWidgets.QPushButton(button_name)
                    button.setStyleSheet(self.DEFAULT_STYLESHEET)
                    # adding button listener
                    button.clicked.connect(
                        functools.partial(self.start_number_context,
                                          character_display_panel))
                    ret_key_grid.addWidget(button, row, col, alignment=QtCore.Qt.AlignTop)
                    self.character_buttons.append(button)

                else:
                    pass

        return ret_key_grid

    def make_numbers_widget(self, character_display_panel):
        ret_num_grid = QtWidgets.QGridLayout()
        ret_num_grid.setSpacing(0)

        self.character_buttons = []

        for i in range(6):
            for j in range(6):
                num = i * 6 + j
                if num < 10:
                    self.add_key_to_keyboard(ret_num_grid, str(num), character_display_panel,
                                             i, j)

        return ret_num_grid

    def make_predictions_widget(self):
        for pred in range(3):
            button_name = "pred" + str(pred)
            button = QtWidgets.QPushButton(button_name)
            button.setStyleSheet(self.PREDICT_STYLESHEET)

            self.predict_grid.addWidget(button, 0, pred)
            self.predict_buttons.append(button)

    def add_key_to_keyboard(self, key_grid,
                            button_name,
                            character_display_panel,
                            row, col):
        button = QtWidgets.QPushButton(button_name)
        button.setStyleSheet(self.DEFAULT_STYLESHEET)
        # adding button listener
        button.clicked.connect(functools.partial(self.print_char, button_name,
                                                 character_display_panel))
        key_grid.addWidget(button, row, col, alignment=QtCore.Qt.AlignTop)
        self.character_buttons.append(button)

    def print_char(self, name, character_display_panel):
        # printing characters on same line
        print(name),
        if character_display_panel.text() == "Enter Text!":
            character_display_panel.setText(name)
        else:
            character_display_panel.setText(character_display_panel.text() + name)

    def start_number_context(self, character_display_panel):

        for btn in self.character_buttons:
            btn.deleteLater()<commit_msg>added spacebar<commit_after># Keyboard Gui Class
# -------------------
import functools
import math
import random
import string
import time

from PyQt5 import QtGui, QtWidgets, QtCore
from PyQt5.QtCore import QTimer


class Keyboard:
    # constructor
    def __init__(self, main_panel, character_display_panel, interval):
        # Style sheets
        self.DEFAULT_STYLESHEET = "QPushButton {background-color: #444444; " \
                                  "color: white; font-size: 65px;}"
        self.PREDICT_STYLESHEET = "QPushButton {background-color: #444444; " \
                                  "color: white; font-size: 50px;}"
        self.DARKEN_STYLESHEET = "QPushButton {background-color: #444444; " \
                                 "color: blue; font-size: 65px;}"

        self.main_panel = main_panel
        self.character_display_panel = character_display_panel

        self.predict_buttons = []
        self.character_buttons = []

        # creating a button grid
        self.key_grid = self.make_keyboard_widget(character_display_panel)

        self.num_grid = None

        # Top 3 Word Predictions
        self.predict_grid = QtWidgets.QGridLayout()
        self.predict_grid.setSpacing(0)

        self.make_predictions_widget()

        # variables used for pausing
        self.flashing_interval = interval

        # attaching grid to main panel
        self.main_panel.addLayout(self.predict_grid)
        self.main_panel.addLayout(self.key_grid)

        # variables used for flashing
        self.flash_timer_queue = []
        self.row_col_flash_order = []
        self.time_start = 0
        self.time_elapsed = 0

        self.current_text = ""

    def make_keyboard_widget(self, character_display_panel):
        ret_key_grid = QtWidgets.QGridLayout()
        ret_key_grid.setSpacing(0)

        for row in range(6):
            for col in range(6):
                # button_name = ""
                character_number = (row * 6) + col
                # a-z buttons
                if character_number < 26:
                    button_name = chr(ord('a') + character_number)
                    self.add_key_to_keyboard(ret_key_grid,
                                             button_name,
                                             character_display_panel,
                                             row, col)

                elif character_number is 26:
                    button_name = "0"

                    button = QtWidgets.QPushButton(button_name)
                    button.setStyleSheet(self.DEFAULT_STYLESHEET)
                    # adding button listener
                    button.clicked.connect(
                        functools.partial(self.start_number_context,
                                          character_display_panel))
                    ret_key_grid.addWidget(button, row, col, alignment=QtCore.Qt.AlignTop)
                    self.character_buttons.append(button)

                elif character_number is 27:
                    button_name = "space"
                    button = QtWidgets.QPushButton(button_name)
                    button.setStyleSheet(self.DEFAULT_STYLESHEET)
                    button.clicked.connect(functools.partial(self.print_char, " ",
                                                             character_display_panel))
                    ret_key_grid.addWidget(button, row, col, alignment=QtCore.Qt.AlignTop)
                    self.character_buttons.append(button)

                else:
                    pass

        return ret_key_grid

    def make_numbers_widget(self, character_display_panel):
        ret_num_grid = QtWidgets.QGridLayout()
        ret_num_grid.setSpacing(0)

        self.character_buttons = []

        for i in range(6):
            for j in range(6):
                num = i * 6 + j
                if num < 10:
                    self.add_key_to_keyboard(ret_num_grid, str(num), character_display_panel,
                                             i, j)

        return ret_num_grid

    def make_predictions_widget(self):
        for pred in range(3):
            button_name = "pred" + str(pred)
            button = QtWidgets.QPushButton(button_name)
            button.setStyleSheet(self.PREDICT_STYLESHEET)

            self.predict_grid.addWidget(button, 0, pred)
            self.predict_buttons.append(button)

    def add_key_to_keyboard(self, key_grid,
                            button_name,
                            character_display_panel,
                            row, col):
        button = QtWidgets.QPushButton(button_name)
        button.setStyleSheet(self.DEFAULT_STYLESHEET)
        # adding button listener
        button.clicked.connect(functools.partial(self.print_char, button_name,
                                                 character_display_panel))
        key_grid.addWidget(button, row, col, alignment=QtCore.Qt.AlignTop)
        self.character_buttons.append(button)

    def print_char(self, char, character_display_panel):
        # printing characters on same line
        print(char)
        self.current_text += char

        # Punctuation indicates new word
        if char is " ":
            self.current_text = char
        # else:
        #     pred_1, pred_2, pred_3 = autocomplete(self.current_text)

        character_display_panel.setText(self.current_text)

        # if character_display_panel.text() == "Enter Text!":
        #     character_display_panel.setText(char)
        # else:
        #     character_display_panel.setText(character_display_panel.text() + char)


    def start_number_context(self, character_display_panel):

        for btn in self.character_buttons:
            btn.deleteLater()
{'fraction_non_alphanumeric': 0.07703227027538563, 'fraction_numerical': 0.009368789628087442, 'mean_word_length': 1.6938567422890645, 'pattern_counts': {'":': 3, '<': 7, '<?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': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3201447', 'n_tokens_mistral': 2942, 'n_tokens_neox': 2767, 'n_words': 534}