<commit_before>from time import sleep

import logging

def to_be_foreground(func): #A safety check wrapper so that certain checks don't get called if menu is not the one active
    def wrapper(self, *args, **kwargs):
        if self.in_foreground:
            return func(self, *args, **kwargs)
        else:
            return False
    return wrapper

class Menu():
    contents = []
    pointer = 0
    display_callback = None
    in_background = True
    in_foreground = False
    exit_flag = False
    name = ""
    first_displayed_entry = 0
    last_displayed_entry = None

    def __init__(self, contents, o, i, name="Menu", entry_height=1):
        self.i = i
        self.o = o
        self.entry_height = entry_height
        self.name = name
        self.generate_keymap()
        self.set_contents(contents)
        self.set_display_callback(o.display_data)

    def to_foreground(self):
        logging.info("menu {0} enabled".format(self.name))    
        self.in_background = True
        self.in_foreground = True
        self.refresh()
        self.set_keymap()

    @to_be_foreground
    def to_background(self):
        self.in_foreground = False
        logging.info("menu {0} disabled".format(self.name))    

    def activate(self):
        logging.info("menu {0} activated".format(self.name))    
        self.to_foreground() 
        while self.in_background: #All the work is done in input callbacks
            sleep(1)
        logging.debug(self.name+" exited")
        return True

    def deactivate(self):
        self.in_foreground = False
        self.in_background = False
        logging.info("menu {0} deactivated".format(self.name))    

    def print_contents(self):
        logging.info(self.contents)

    def print_name(self):
        logging.info("Active menu is {0}".format(self.name))    

    @to_be_foreground
    def move_down(self):
        if self.pointer < (len(self.contents)-1):
            logging.debug("moved down")
            self.pointer += 1  
            self.refresh()    
            return True<commit_msg>Increased polling rate in Menu UI element so that it's more responsive<commit_after>from time import sleep

import logging

def to_be_foreground(func): #A safety check wrapper so that certain checks don't get called if menu is not the one active
    def wrapper(self, *args, **kwargs):
        if self.in_foreground:
            return func(self, *args, **kwargs)
        else:
            return False
    return wrapper

class Menu():
    contents = []
    pointer = 0
    display_callback = None
    in_background = True
    in_foreground = False
    exit_flag = False
    name = ""
    first_displayed_entry = 0
    last_displayed_entry = None

    def __init__(self, contents, o, i, name="Menu", entry_height=1):
        self.i = i
        self.o = o
        self.entry_height = entry_height
        self.name = name
        self.generate_keymap()
        self.set_contents(contents)
        self.set_display_callback(o.display_data)

    def to_foreground(self):
        logging.info("menu {0} enabled".format(self.name))    
        self.in_background = True
        self.in_foreground = True
        self.refresh()
        self.set_keymap()

    @to_be_foreground
    def to_background(self):
        self.in_foreground = False
        logging.info("menu {0} disabled".format(self.name))    

    def activate(self):
        logging.info("menu {0} activated".format(self.name))    
        self.to_foreground() 
        while self.in_background: #All the work is done in input callbacks
            sleep(0.1)
        logging.debug(self.name+" exited")
        return True

    def deactivate(self):
        self.in_foreground = False
        self.in_background = False
        logging.info("menu {0} deactivated".format(self.name))    

    def print_contents(self):
        logging.info(self.contents)

    def print_name(self):
        logging.info("Active menu is {0}".format(self.name))    

    @to_be_foreground
    def move_down(self):
        if self.pointer < (len(self.contents)-1):
            logging.debug("moved down")
            self.pointer += 1  
            self.refresh()    
            return True
{'fraction_non_alphanumeric': 0.0981653562068144, 'fraction_numerical': 0.005480104836788182, 'mean_word_length': 2.277127244340359, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2422897', 'n_tokens_mistral': 1254, 'n_tokens_neox': 1219, 'n_words': 306}