<commit_before>##    generic - Part of the pymedia package. Menu drawing utilities.
##        Main drawing classes, supporting other modules in representing
##        information on the screen
##    
##    Copyright (C) 2002-2003  <NAME>
##
##    This library is free software; you can redistribute it and/or
##    modify it under the terms of the GNU Library General Public
##    License as published by the Free Software Foundation; either
##    version 2 of the License, or (at your option) any later version.
##
##    This library is distributed in the hope that it will be useful,
##    but WITHOUT ANY WARRANTY; without even the implied warranty of
##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
##    Library General Public License for more details.
##
##    You should have received a copy of the GNU Library General Public
##    License along with this library; if not, write to the Free
##    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
##
##    <NAME>

import os, Queue, threading, string, traceback, time
import pygame
from __main__ import *

DEFAULT_FONT= 'arialn'
DEFAULT_FONT_SIZE= 20
DEFAULT_FONT_COLOR= ( 255, 255, 255 )
LEFT_C= (0,0)
EMPTY= 0
NAV_ICONS= ( 'up_0.gif', 'down_0.gif' )

# ****************************************************************************************************
# Generic class to support menu items rendering
# Provides basic set of functions such as:
#   getItemSize() -> ( width, height )
#     etc
class MenuHelper:
  # -----------------------------------------------------------------
  # Constructor
  def __init__( self, rect, params ):
    self.attributes= params
    self.params= params[ 'params' ]
    self.parentParams= params
    self.changed= 1
  
  # -----------------------------------------------------------------
  # Return item size 
  def getItemSize( self ):
    return self.itemSize
  
  # -----------------------------------------------------------------
  def getRect( self ):
    return self.rect
  
  # -----------------------------------------------------------------
  def getPos( self ):
    return self.rect[ :2 ]
  
  # -----------------------------------------------------------------
  def getParam( self, name, default ):
    try:
      return self.params[ name ]
    except:
      return default
    
  # -----------------------------------------------------------------
  def getParamList( self, name, default ):
    try:
      return eval( '('+ self.params[ name ]+ ')' )
    except:
      return default
  
  # -----------------------------------------------------------------
  def setFocus( self, item, isFocused ):
    # Only icon item will change for the focused item
    self.drawItem( item, isFocused )
    
  # -----------------------------------------------------------------
  def adjustPos( self, items, offsetPos ):
    # Filter out only existing items
    items= filter( lambda x: x, items )
    # Adjust pos for all of the items in a list
    return map( lambda x: ( x[ 0 ], ( x[ 1 ][ 0 ]+ offsetPos[ 0 ], x[ 1 ][ 1 ]+ offsetPos[ 1 ] )), items )
  
  # -----------------------------------------------------------------
  def hasChanged( self ):
    return self.changed
  
  # -----------------------------------------------------------------
  def setChanged( self, changed ):
    self.changed= changed
  
  # -----------------------------------------------------------------
  def loadFont( self, paramName ):
    fontName= self.getParam( paramName, DEFAULT_FONT )
    fontSize= self.getParam( paramName+ 'Size', DEFAULT_FONT_SIZE )
    #font= pygame.font.SysFont( fontName, int( fontSize ) )
    font= pygame.font.Font( 'icons/'+ fontName+ '.ttf', int( fontSize ) )
    if self.getParam( paramName+ 'Bold', 'no' )== 'yes':
      font.set_bold( 1 )
    
    fontColor= self.getParamList( paramName+ 'Color', DEFAULT_FONT_COLOR )
    
    return font, fontColor
  
  # -----------------------------------------------------------------
  def loadIcon( self, paramName, default ):
    icons= self.getParam( paramName, default )
    icons1= None
    
    if type( icons )== str:
      icons1= pygame.image.load( 'icons/'+ icons )
    elif type( icons )== list or type( icons )== tuple:
      icons1= map( lambda x: pygame.image.load( 'icons/'+ x ), icons )
    
    return icons1

  # -----------------------------------------------------------------<commit_msg>Nav icons fixed, alpha parameter can be specified for the icon<commit_after>##    generic - Part of the pymedia package. Menu drawing utilities.
##        Main drawing classes, supporting other modules in representing
##        information on the screen
##    
##    Copyright (C) 2002-2003  <NAME>
##
##    This library is free software; you can redistribute it and/or
##    modify it under the terms of the GNU Library General Public
##    License as published by the Free Software Foundation; either
##    version 2 of the License, or (at your option) any later version.
##
##    This library is distributed in the hope that it will be useful,
##    but WITHOUT ANY WARRANTY; without even the implied warranty of
##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
##    Library General Public License for more details.
##
##    You should have received a copy of the GNU Library General Public
##    License along with this library; if not, write to the Free
##    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
##
##    <NAME>

import os, Queue, threading, string, traceback, time
import pygame
from __main__ import *

DEFAULT_FONT= 'arialn'
DEFAULT_FONT_SIZE= 20
DEFAULT_FONT_COLOR= ( 255, 255, 255 )
LEFT_C= (0,0)
EMPTY= 0
NAV_ICONS= ( 'down_0.gif', 'up_0.gif' )

# ****************************************************************************************************
# Generic class to support menu items rendering
# Provides basic set of functions such as:
#   getItemSize() -> ( width, height )
#     etc
class MenuHelper:
  # -----------------------------------------------------------------
  # Constructor
  def __init__( self, rect, params ):
    self.attributes= params
    self.params= params[ 'params' ]
    self.parentParams= params
    self.changed= 1
  
  # -----------------------------------------------------------------
  # Return item size 
  def getItemSize( self ):
    return self.itemSize
  
  # -----------------------------------------------------------------
  def getRect( self ):
    return self.rect
  
  # -----------------------------------------------------------------
  def getPos( self ):
    return self.rect[ :2 ]
  
  # -----------------------------------------------------------------
  def getParam( self, name, default ):
    try:
      return self.params[ name ]
    except:
      return default
    
  # -----------------------------------------------------------------
  def getParamList( self, name, default ):
    try:
      return eval( '('+ self.params[ name ]+ ')' )
    except:
      return default
  
  # -----------------------------------------------------------------
  def setFocus( self, item, isFocused ):
    # Only icon item will change for the focused item
    self.drawItem( item, isFocused )
    
  # -----------------------------------------------------------------
  def adjustPos( self, items, offsetPos ):
    # Filter out only existing items
    items= filter( lambda x: x, items )
    # Adjust pos for all of the items in a list
    return map( lambda x: ( x[ 0 ], ( x[ 1 ][ 0 ]+ offsetPos[ 0 ], x[ 1 ][ 1 ]+ offsetPos[ 1 ] )), items )
  
  # -----------------------------------------------------------------
  def hasChanged( self ):
    return self.changed
  
  # -----------------------------------------------------------------
  def setChanged( self, changed ):
    self.changed= changed
  
  # -----------------------------------------------------------------
  def loadFont( self, paramName ):
    fontName= self.getParam( paramName, DEFAULT_FONT )
    fontSize= self.getParam( paramName+ 'Size', DEFAULT_FONT_SIZE )
    #font= pygame.font.SysFont( fontName, int( fontSize ) )
    font= pygame.font.Font( 'icons/'+ fontName+ '.ttf', int( fontSize ) )
    if self.getParam( paramName+ 'Bold', 'no' )== 'yes':
      font.set_bold( 1 )
    
    fontColor= self.getParamList( paramName+ 'Color', DEFAULT_FONT_COLOR )
    
    return font, fontColor
  
  # -----------------------------------------------------------------
  def loadIcon( self, paramName, default, alpha= -1 ):
    icons= self.getParam( paramName, default )
    icons1= None
    
    if type( icons )== str:
      icons1= pygame.image.load( 'icons/'+ icons )
      if alpha!= -1:
        icons1.set_alpha( alpha )
    elif type( icons )== list or type( icons )== tuple:
      icons1= map( lambda x: pygame.image.load( 'icons/'+ x ), icons )
      if alpha!= -1:
        map( lambda x: x.set_alpha( alpha ), icons1 )
    
    return icons1

  # -----------------------------------------------------------------
{'fraction_non_alphanumeric': 0.29447035309793473, 'fraction_numerical': 0.012325116588940706, 'mean_word_length': 1.5279259051361211, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '3342359', 'n_tokens_mistral': 2364, 'n_tokens_neox': 2245, 'n_words': 820}