<commit_before>#
# Menu class for pyglet
#
# Ideas borrowed from:
#    pygext: http://opioid-interactive.com/~shang/projects/pygext/
#    pyglet astraea: http://www.pyglet.org
#    Grossini's Hell: http://www.pyweek.org/e/Pywiii/ 
# 
#
"""A menu layer for los-cocos.

Menu
====

This module provides a Menu class, which is a layer you can use in cocos
apps. Menus can contain regular items (which trigger a function when selected)
or toggle items (which toggle a flag when selected).

When you need a menu, you can define a class inheriting `Menu`, and setting
some attributes which control the menu appearance. Then you add `MenuItem` s to
it, prepare it, and use it as you would use any layer.

There is a menu demo in the samples folder.

"""

__docformat__ = 'restructuredtext'

from pyglet import font
from pyglet import media
from pyglet import window
from pyglet.window import key
from pyglet.gl import *

from layer import *
from director import *

__all__ = [ 'Menu', 'MenuItem', 'ToggleMenuItem', 'CENTER', 'LEFT', 'RIGHT', 'TOP', 'BOTTOM' ]

#
# Class Menu
#

# Horizontal Align
CENTER = font.Text.CENTER
LEFT = font.Text.LEFT
RIGHT = font.Text.RIGHT

# Vertical Align
TOP = font.Text.TOP
BOTTOM = font.Text.BOTTOM

class Menu(Layer):
    """Abstract base class for menu layers.
    
    Normal usage is:

     - create a descendent from this class
     - override __init__ to set all style attributes, add items,
       and call build_items
     - add to a scene
    """

    def __init__( self, title = ''):
        super(Menu, self).__init__()

        #
        # Items and Title
        #
        self.items = []
        self.title = title
        self.title_text = None

        #
        # Menu default options
        # Menus can be customized changing these variables
        #

        # Title
        self.font_title = ''            # Full font name
        self.font_title_size = 72
        self.font_title_color = ( 0.6, 0.6, 0.6, 1.0 )

        # Items
        self.font_items = ''            # Full font name
        self.font_items_size = 48
        self.font_items_color = (0.6, 0.6, 0.6, 1.0 ) 
        self.font_items_selected_size = 64 
        self.font_items_selected_color = (1.0, 1.0, 1.0, 1.0 )

        # Sound
        self.sound_filename = 'menuchange.wav'

        # Alignment
        self.menu_halign = CENTER
        self.menu_valign = CENTER

     
    def _draw_title( self ):
        """ draws the title """
        width, height = director.get_window_size()

        ft = font.load( self.font_title, self.font_title_size )
        ft_height = ft.ascent - ft.descent
        text = font.Text(ft, self.title)

        text = font.Text(ft, self.title,
            x=width / 2,
            y=height - 40,
            halign=font.Text.CENTER,
            valign=font.Text.CENTER)
        text.color = self.font_title_color

        self.title_text = text

    def _draw_items( self ):
<commit_msg>added more docstrings to menu<commit_after>#
# Menu class for pyglet
#
# Ideas borrowed from:
#    pygext: http://opioid-interactive.com/~shang/projects/pygext/
#    pyglet astraea: http://www.pyglet.org
#    Grossini's Hell: http://www.pyweek.org/e/Pywiii/ 
# 
#
"""A menu layer for los-cocos.

Menu
====

This module provides a Menu class, which is a layer you can use in cocos
apps. Menus can contain regular items (which trigger a function when selected)
or toggle items (which toggle a flag when selected).

When you need a menu, you can define a class inheriting `Menu`, and setting
some attributes which control the menu appearance. Then you add `MenuItem` s to
it, prepare it, and use it as you would use any layer.

There is a menu demo in the samples folder.

"""

__docformat__ = 'restructuredtext'

from pyglet import font
from pyglet import media
from pyglet import window
from pyglet.window import key
from pyglet.gl import *

from layer import *
from director import *

__all__ = [ 'Menu', 'MenuItem', 'ToggleMenuItem', 'CENTER', 'LEFT', 'RIGHT', 'TOP', 'BOTTOM' ]

#
# Class Menu
#

# Horizontal Align
CENTER = font.Text.CENTER
LEFT = font.Text.LEFT
RIGHT = font.Text.RIGHT

# Vertical Align
TOP = font.Text.TOP
BOTTOM = font.Text.BOTTOM

class Menu(Layer):
    """Abstract base class for menu layers.
    
    Normal usage is:

     - create a descendent from this class
     - override __init__ to set all style attributes, add items,
       and call build_items
     - add to a scene
    """

    def __init__( self, title = ''):
        super(Menu, self).__init__()

        #
        # Items and Title
        #
        self.items = []
        self.title = title
        self.title_text = None

        #
        # Menu default options
        # Menus can be customized changing these variables
        #

        # Title
        self.font_title = ''
	"""Title's font name"""
        self.font_title_size = 72
	"""Title's font size. Default size is 72"""
        self.font_title_color = ( 0.6, 0.6, 0.6, 1.0 )
	"""Title's font color. Default color is (0.6, 0.6, 0.6, 1.0)"""

        # Items
        self.font_items = ''            # Full font name
	"""Items' font name"""
        self.font_items_size = 48
	"""Items' font size when unselected. Default size is 48"""
        self.font_items_color = (0.6, 0.6, 0.6, 1.0 ) 
	"""Items' font color when unselected. Default color is (0.6, 0.6, 0.6, 1.0)"""
        self.font_items_selected_size = 64 
	"""Items' font size when selected. Default size is 64"""
        self.font_items_selected_color = (1.0, 1.0, 1.0, 1.0 )
	"""Items' font color when selected. Default color is (1.0, 1.0, 1.0, 1.0)"""

        # Sound
        self.sound_filename = 'menuchange.wav'

        # Alignment
        self.menu_halign = CENTER
	"""Horizontal alignment. Possible options: CENTER, RIGHT or LEFT. Default is CENTER"""
        self.menu_valign = CENTER
	"""Vertical alignment. Possible options: CENTER, TOP or BOTTOM. Default is CENTER"""

     
    def _draw_title( self ):
        """ draws the title """
        width, height = director.get_window_size()

        ft = font.load( self.font_title, self.font_title_size )
        ft_height = ft.ascent - ft.descent
        text = font.Text(ft, self.title)

        text = font.Text(ft, self.title,
            x=width / 2,
            y=height - 40,
            halign=font.Text.CENTER,
            valign=font.Text.CENTER)
        text.color = self.font_title_color

        self.title_text = text

    def _draw_items( self ):

{'fraction_non_alphanumeric': 0.10601143563591407, 'fraction_numerical': 0.01483541956420955, 'mean_word_length': 2.393812270582066, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '7434443', 'n_tokens_mistral': 2152, 'n_tokens_neox': 2040, 'n_words': 666}