pygamelib
v1.3.x

Contents (API reference):

  • actuators
    • Actuator
    • Behavioral
    • PathActuator
    • PatrolActuator
    • PathFinder
    • RandomActuator
    • UnidirectionalActuator
  • assets
    • graphics
      • Blocks
      • BoxDrawings
      • GeometricShapes
      • MiscTechnicals
      • Models
    • Fonts
      • 8bits
        • How to use?
        • What does it look like?
      • figlet-caligraphy
        • How to use?
        • What does it look like?
        • More
      • figlet-doom
        • How to use?
        • What does it look like?
        • More
      • figlet-graffiti
        • How to use?
        • What does it look like?
        • More
      • figlet-mirror
        • How to use?
        • What does it look like?
        • More
      • figlet-pepper
        • How to use?
        • What does it look like?
        • More
      • figlet-poison
        • How to use?
        • What does it look like?
        • More
      • figlet-puffy
        • How to use?
        • What does it look like?
        • More
      • figlet-rounded
        • How to use?
        • What does it look like?
        • More
      • figlet-stampatello
        • How to use?
        • What does it look like?
        • More
      • figlet-univers
        • How to use?
        • What does it look like?
        • More
      • figlet-wavy
        • How to use?
        • What does it look like?
        • More
  • base
    • Console
    • Math
    • PglBaseObject
    • PglException
    • PglInvalidLevelException
    • PglInvalidTypeException
    • PglInventoryException
    • PglObjectIsNotMovableException
    • PglOutOfBoardBoundException
    • Text
    • Vector2D
    • Deprecated objects
      • HacException
      • HacInvalidLevelException
      • HacInvalidTypeException
      • HacObjectIsNotMovableException
      • HacOutOfBoardBoundException
  • board_items
    • Actionable
    • ActionableTile
    • BoardComplexItem
    • BoardItemComplexComponent
    • BoardItem
    • BoardItemVoid
    • Camera
    • Character
    • ComplexDoor
    • ComplexNPC
    • ComplexPlayer
    • ComplexTreasure
    • ComplexWall
    • Door
    • GenericActionableStructure
    • GenericStructureComplexComponent
    • GenericStructure
    • Immovable
    • Movable
    • NPC
    • Player
    • Projectile
    • TextItem
    • Tile
    • Treasure
    • Wall
  • constants
  • engine
    • Board
    • Game
    • Inventory
    • Screen
  • gfx
    • core
      • Animation
      • Font
      • SpriteCollection
      • Sprite
      • Sprixel
      • Color
    • ui
      • Box
      • ColorPickerDialog
      • ColorPicker
      • Dialog
      • FileDialog
      • GridSelectorDialog
      • GridSelector
      • LineInputDialog
      • Menu
      • MenuAction
      • MenuBar
      • MessageDialog
      • MultiLineInputDialog
      • ProgressBar
      • ProgressDialog
      • UiConfig
    • particles
      • CircleEmitter
      • ColorParticle
      • ColorPartitionParticle
      • EmitterProperties
      • ParticleEmitter
      • ParticlePool
      • Particle
      • ParticleSprixel
      • PartitionParticle
      • RandomColorParticle
      • RandomColorPartitionParticle
  • Credits
    • Development Lead
    • Contributors
  • Release notes
    • 1.3.0 (2022-10-07)
      • ⬆️ Main updates
      • ⚠️ Breaking changes
      • 🔧 Other changes
    • 1.2.3 (2020-09-01)
    • 1.2.2 (2020-09-01)
    • 1.2.0 (2020-08-29)
    • 1.1.1 (2020-07-18)
    • 1.1.0 (2020-06-12)
    • 1.0.1 (2020-05-17)
    • 1.0.0 (2020-03-20)
    • 2019.5
    • pre-2019.5
pygamelib
  • Docs »
  • gfx »
  • ui »
  • MenuAction
  • Edit on GitHub

MenuAction¶

class pygamelib.gfx.ui.MenuAction(title: pygamelib.base.Text = None, action=None, parameter=None, padding: int = 1, config: pygamelib.gfx.ui.UiConfig = None)¶

Bases: object

A menu action is a menu entry that executes a callback when activated. Usually a Menuaction represents an action from the user interface like open file, save, quit, etc.

Therefor a MenuAction is fairly simple, at its simplest it has a title and a callable reference to a function.

An action cannot be used by itself but can be added to a MenuBar or a Menu.

Like everything in the UI module, MenuAction are styled through a UiConfig object. Unlike the other classes of that module however, the configuration object is not mandatory when instanciating this class. The reason is that the MenuBar object impose the configuration to its managed MenuAction and Menu.

__init__(title: pygamelib.base.Text = None, action=None, parameter=None, padding: int = 1, config: pygamelib.gfx.ui.UiConfig = None) → None¶

The constructor takes the following parameters.

Parameters:
  • title (str | Text) – The title of the action (i.e: its label)
  • action (callable) – A reference to a callable function that is going to be executed when the action is activated. If set to None, nothing will happen when the action is activated.
  • parameter (Any) – A parameter that is passed to the callback action if not None.
  • padding (int) – The horizontal padding, i.e the number of space characters added to the left and right of the action.
  • config (UiConfig) – The configuration object.

Example

menubar = MenuBar(config=UiConfig.instance())
file_menu = Menu(
    "File",
    [
        MenuAction("Open", open_file),
        MenuAction("Save", save_file),
        MenuAction("Save as", save_file_as),
        MenuAction("Quit", exit_application),
    ]
)
menubar.add_entry( file_menu )
menubar.add_entry( MenuAction("Help", display_help) )
screen.place(menubar, 0, 0)
screen.update()

Methods

__init__(title[, action, parameter]) The constructor takes the following parameters.
activate() Execute and return the result of the callback.
render_to_buffer(buffer, row, column, …) Render the object from the display buffer to the frame buffer.
title_width() Return the actual width of the action’s title.

Attributes

action Get / set the action’s callback, it needs to be a callable.
config Get / set the config of the MenuAction, it needs to be a UiConfig.
padding Get / set the padding before and after the menu action, it needs to be an int.
selected Get / set the selected of the MenuAction, it needs to be a boolean.
title Get / set the title of the action, it needs to be a str or a Text object.
action¶

Get / set the action’s callback, it needs to be a callable.

activate()¶

Execute and return the result of the callback.

Example:

file_save_action.activate()
config¶

Get / set the config of the MenuAction, it needs to be a UiConfig.

padding¶

Get / set the padding before and after the menu action, it needs to be an int.

render_to_buffer(buffer, row: int, column: int, buffer_height: int, buffer_width: int) → None¶

Render the object from the display buffer to the frame buffer.

This method is automatically called by pygamelib.engine.Screen.render().

Parameters:
  • buffer (numpy.array) – A screen buffer to render the item into.
  • row (int) – The row to render in.
  • column (int) – The column to render in.
  • height (int) – The total height of the display buffer.
  • width (int) – The total width of the display buffer.
selected¶

Get / set the selected of the MenuAction, it needs to be a boolean.

This changes the representation (way it’s drawn) of the menu entry.

title¶

Get / set the title of the action, it needs to be a str or a Text object.

The title is used in the Menu. In the following image, the title of the first action in the expanded menu is “Open”, followed by “Save”.

menu
title_width()¶

Return the actual width of the action’s title. This takes into account the padding.

Example:

menu_action.title_width()
Next Previous

© Copyright 2019-2022, Arnaud Dupuis Revision 683af6b9.

Built with Sphinx using a theme provided by Read the Docs.