<commit_before>import pygame, sys
import pygame.font
#from pygame.locals import *
import pygame.locals
import timeit

class Menu:
    items = []
    currentItems = None
    currentIndex = 0
    menuPosition = []
    displaySurface = None
    
    # optimization
    clearIndex = None
    
    # Display
    font = None
    color = None # TODO
    
    # Colors
    colorBlack = (0, 0, 0)
    colorWhite = (255, 255, 255)
    colorRed = (255, 0, 0)
    colorGreen = (0, 255, 0)
    colorBlue = (0, 0, 255)
    
    def __init__(self, displaySurface, menuStructure, menuOptions = None):
        self.displaySurface = displaySurface

        if menuOptions == None:
            menuOptions = MenuOptions() # with default values

        self.font = menuOptions.getItemFont()

        # populate with MenuItem objects
        self.items = MenuItem.itemsListFromDict(menuStructure, menuOptions)
        self.currentItems = self.items
        
        
    def show(self):
        pass
        
    def hide(self):
        pass
        
    def getParentMenu(self):
        print self.currentItems[0].getParentMenu()
        return self.currentItems[0].getParentMenu()
        
    def registerKeypress(self, key):
        print "registered key " + str(key)
        
        if key == pygame.locals.K_ESCAPE: # ESC
            if self.getParentMenu() != None:
                self.currentItems = self.getSiblingsOfItem(self.getParentMenu())
                self.currentIndex = 0
                self.clear()
                self.render()
            else:
                pygame.quit()
                sys.exit()
        elif key == pygame.locals.K_q:
            pygame.quit()
            sys.exit()
        elif key == pygame.locals.K_UP:
            print "UP"
            self.clearIndex = self.currentIndex
            self.moveUp()
            self.render()
        elif key == pygame.locals.K_DOWN:
            print "DOWN"
            self.clearIndex = self.currentIndex
            self.moveDown()
            self.render()
        elif key == pygame.locals.K_RETURN:
            print "selected item"
            
            selectedItem = self.currentItems[self.currentIndex]
            
            print selectedItem
            
            if selectedItem.hasSubmenu():
                self.currentItems = selectedItem.getSubmenu()
                self.currentIndex = 0
                self.clear()
                self.render()
            else:
                selectedItem.execute()

    def render(self):
        start_time = timeit.default_timer()
        
        if self.clearIndex == None:
            self.renderFull()
        else:<commit_msg>clear before populating menu with new menu items<commit_after>import pygame, sys
import pygame.font
#from pygame.locals import *
import pygame.locals
import timeit

class Menu:
    items = []
    currentItems = None
    currentIndex = 0
    menuPosition = []
    displaySurface = None
    
    # optimization
    clearIndex = None
    
    # Display
    font = None
    color = None # TODO
    
    # Colors
    colorBlack = (0, 0, 0)
    colorWhite = (255, 255, 255)
    colorRed = (255, 0, 0)
    colorGreen = (0, 255, 0)
    colorBlue = (0, 0, 255)
    
    def __init__(self, displaySurface, menuStructure, menuOptions = None):
        self.displaySurface = displaySurface

        if menuOptions == None:
            menuOptions = MenuOptions() # with default values

        self.font = menuOptions.getItemFont()

        # populate with MenuItem objects
        self.items = MenuItem.itemsListFromDict(menuStructure, menuOptions)
        self.currentItems = self.items
        
        
    def show(self):
        pass
        
    def hide(self):
        pass
        
    def getParentMenu(self):
        print self.currentItems[0].getParentMenu()
        return self.currentItems[0].getParentMenu()
        
    def registerKeypress(self, key):
        print "registered key " + str(key)
        
        if key == pygame.locals.K_ESCAPE: # ESC
            if self.getParentMenu() != None:
                self.clear()
                self.currentItems = self.getSiblingsOfItem(self.getParentMenu())
                self.currentIndex = 0
                self.render()
            else:
                pygame.quit()
                sys.exit()
        elif key == pygame.locals.K_q:
            pygame.quit()
            sys.exit()
        elif key == pygame.locals.K_UP:
            print "UP"
            self.clearIndex = self.currentIndex
            self.moveUp()
            self.render()
        elif key == pygame.locals.K_DOWN:
            print "DOWN"
            self.clearIndex = self.currentIndex
            self.moveDown()
            self.render()
        elif key == pygame.locals.K_RETURN:
            print "selected item"
            
            selectedItem = self.currentItems[self.currentIndex]
            
            print selectedItem
            
            if selectedItem.hasSubmenu():
                self.clear()
                self.currentItems = selectedItem.getSubmenu()
                self.currentIndex = 0
                self.render()
            else:
                selectedItem.execute()

    def render(self):
        start_time = timeit.default_timer()
        
        if self.clearIndex == None:
            self.renderFull()
        else:
{'fraction_non_alphanumeric': 0.08875629311952266, 'fraction_numerical': 0.01193361924296103, 'mean_word_length': 1.5738963531669865, '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': '199630', 'n_tokens_mistral': 1533, 'n_tokens_neox': 1444, 'n_words': 338}