Contents
This module provides a simple toolkit for adding GUIs to a SGE game as well as support for modal dialog boxes.
To use this module, you must call xsge.gui.init() sometime between the creation of the sge.Game object and the start of the game.
The colors used by this module. They can be safely changed, but be sure to call redraw() on all windows and widgets that would be affected; some changes might not become visible until you do.
The fonts used by this module. They can be safely changed, but be sure to call redraw() on all windows and widgets that would be affected; some changes might not become visible until you do.
The sprites used by this module. They can be safely changed, but be sure to call redraw() on all windows and widgets that would be affected; some changes might not become visible until you do.
An object of this class needs to exist in any room where windows are to be used. It feeds SGE events to the windows so they can react to user input. It also refreshes all windows every frame.
A list of all windows that are currently handled by this handler.
You don’t need to modify this list manually. Instead, use xsge.gui.Window.show() and xsge.gui.Window.hide() to add and remove windows from this list, respectively.
Window objects are used to contain widgets. They can be moved around the game window by the user.
A weak reference to this window’s parent handler object, which is used to display it when it is supposed to be visible.
If a strong reference is assigned to this attribute, it will automatically be changed to a weak reference.
The horizontal position of the window relative to the game window.
The vertical position of the window relative to the game window.
The width of the window.
The height of the window.
The text that shows up in the title bar of the window.
The color of this window’s background. If set to None, it becomes the same value as xsge.gui.window_background_color.
Whether or not the window has a border. If this is False, the window cannot be moved or resized by the user, and title will not be displayed.
A list of this window’s widgets.
The widget which currently has keyboard focus within this window, or None if no widget has keyboard focus within this window.
The sprite this window currently displays as itself.
An alias for xsge.gui.Window.hide().
Re-draw this window’s sprite.
Call this method if you change any variables that should affect this window’s appearance. For performance reasons, the changes won’t show up in an existing window until this method is called.
Called once every frame, before refreshing. See the documentation for sge.Game.event_step() for more information.
Called when a key is pressed while this window has keyboard focus. See the documentation for sge.input.KeyPress for more information.
Called when a key is released while this window has keyboard focus. See the documentation for sge.input.KeyRelease for more information.
Called when a mouse button is pressed while this window has mouse focus. See the documentation for sge.input.MouseButtonPress for more information.
Called when a mouse button is released while this window has mouse focus. See the documentation for sge.input.MouseButtonRelease for more information.
Called when a joystick axis is moved while this window has keyboard focus. See the documentation for sge.input.JoystickAxisMove for more information.
Called when a joystick hat is moved while this window has keyboard focus. See the documentation for sge.input.JoystickHatMove for more information.
Called when a joystick trackball is moved while this window has keyboard focus. See the documentation for sge.input.JoystickTrackballMove for more information.
Called when a joystick button is pressed while this window has keyboard focus. See the documentation for sge.input.JoystickButtonPress for more information.
Called when a joystick button is released while this window has keyboard focus. See the documentation for sge.input.JoystickButtonRelease for more information.
Called when a mouse button is pressed on top of this window’s title bar (top border). See the documentation for sge.input.MouseButtonPress for more information.
Called when a mouse button is released on top of this window’s title bar (top border). See the documentation for sge.input.MouseButtonRelease for more information.
Called when a key is pressed, regardless of which window has keyboard focus. See the documentation for sge.input.KeyPress for more information.
Called when a key is released, regardless of which window has keyboard focus. See the documentation for sge.input.KeyRelease for more information.
Called when a mouse button is pressed, regardless of which window has mouse focus. See the documentation for sge.input.MouseButtonPress for more information.
Called when a mouse button is released, regardless of which window has mouse focus. See the documentation for sge.input.MouseButtonRelease for more information.
Called when a joystick axis is moved, regardless of which window has keyboard focus. See the documentation for sge.input.JoystickAxisMove for more information.
Called when a joystick hat is moved, regardless of which window has keyboard focus. See the documentation for sge.input.JoystickHatMove for more information.
Called when a joystick trackball is moved, regardless of which window has keyboard focus. See the documentation for sge.input.JoystickTrackballMove for more information.
Called when a joystick button is pressed, regardless of which window has keyboard focus. See the documentation for sge.input.JoystickButtonPress for more information.
Called when a joystick button is released, regardless of which window has keyboard focus. See the documentation for sge.input.JoystickButtonRelease for more information.
Called when the “X” button in the top-right corner of the window is pressed.
By default, this calls xsge.gui.Window.destroy().
Dialog class.
Dialogs are windows with their own loops, also called modal windows. They are used for tasks that must be completed before the main program continues, such as pop-up messages.
See the documentation for xsge.gui.Window for more information.
In addition to methods inherited from xsge.gui.Window, the following methods are also available:
Show this dialog and start its loop.
Like xsge.gui.Window.show(), this method adds the dialog to its parent. It then starts this dialog’s loop. Call xsge.gui.Dialog.hide() on this dialog to end the loop.
Widget objects are things like controls and decorations that exist on windows.
A weak reference to this widget’s parent window.
If a strong reference is assigned to this attribute, it will automatically be changed to a weak reference.
The horizontal position of the widget relative to its parent window.
The vertical position of the widget relative to its parent window.
The Z-axis position of the widget. Widgets with a higher Z-axis value are in front of widgets with a lower Z-axis value. This value is not connected in any way to Z-axis values in the SGE.
The sprite this widget displays as itself.
Class attribute indicating whether or not the widget should be considered for focusing when the Tab key is pressed.
Called once every frame, before refreshing. See the documentation for sge.Game.event_step() for more information.
Called when a key is pressed while this widget has keyboard focus. See the documentation for sge.input.KeyPress for more information.
Called when a key is released while this widget has keyboard focus. See the documentation for sge.input.KeyRelease for more information.
Called when a mouse button is pressed while this widget has mouse focus. See the documentation for sge.input.MouseButtonPress for more information.
Called when a mouse button is released while this widget has mouse focus. See the documentation for sge.input.MouseButtonRelease for more information.
Called when a joystick axis is moved while this widget has keyboard focus. See the documentation for sge.input.JoystickAxisMove for more information.
Called when a joystick hat is moved while this widget has keyboard focus. See the documentation for sge.input.JoystickHatMove for more information.
Called when a joystick trackball is moved while this widget has keyboard focus. See the documentation for sge.input.JoystickTrackballMove for more information.
Called when a joystick button is pressed while this widget has keyboard focus. See the documentation for sge.input.JoystickButtonPress for more information.
Called when a joystick button is released while this widget has keyboard focus. See the documentation for sge.input.JoystickButtonRelease for more information.
Called when a key is pressed, regardless of which widget has keyboard focus. See the documentation for sge.input.KeyPress for more information.
Called when a key is released, regardless of which widget has keyboard focus. See the documentation for sge.input.KeyRelease for more information.
Called when a mouse button is pressed, regardless of which widget has mouse focus. See the documentation for sge.input.MouseButtonPress for more information.
Called when a mouse button is released, regardless of which widget has mouse focus. See the documentation for sge.input.MouseButtonRelease for more information.
Called when a joystick axis is moved, regardless of which widget has keyboard focus. See the documentation for sge.input.JoystickAxisMove for more information.
Called when a joystick hat is moved, regardless of which widget has keyboard focus. See the documentation for sge.input.JoystickHatMove for more information.
Called when a joystick trackball is moved, regardless of which widget has keyboard focus. See the documentation for sge.input.JoystickTrackballMove for more information.
Called when a joystick button is pressed, regardless of which widget has keyboard focus. See the documentation for sge.input.JoystickButtonPress for more information.
Called when a joystick button is released, regardless of which widget has keyboard focus. See the documentation for sge.input.JoystickButtonRelease for more information.
This widget simply displays some text.
The text this label should display.
The font this label’s text should be rendered with. If set to None, the value of xsge.gui.default_font is used.
The width of the imaginary rectangle the text is drawn in. See the documentation for sge.Sprite.draw_text() for more information.
The height of the imaginary rectangle the text is drawn in. See the documentation for sge.Sprite.draw_text() for more information.
The horizontal alignment of the text. See the documentation for sge.Sprite.draw_text() for more information.
The vertical alignment of the text. See the documentation for sge.Sprite.draw_text() for more information.
See the documentation for xsge.gui.Widget for more information.
This widget contains some text and can be clicked on by the user.
The text contained in the button.
The width of the button. If set to None, the width is chosen based on the width of the rendered text.
The horizontal alignment of the text. See the documentation for sge.Sprite.draw_text() for more information.
See the documentation for xsge.gui.Widget for more information.
In addition to the event methods inherited from xsge.gui.Widget, the following event methods are also available:
This widget can be toggled “on” or “off” by clicking on it.
Whether or not the checkbox is on.
See the documentation for xsge.gui.Widget for more information.
In addition to the event methods inherited from xsge.gui.Widget, the following event methods are also available:
This widget is mostly like xsge.gui.CheckBox, but clicking on it while it is on will not turn it off, and only one radio button can be on at any given time (i.e. enabling one radio button on a window will disable all others on the same window).
See the documentation for xsge.gui.CheckBox for more information.
In addition to the event methods inherited from xsge.gui.Widget, the following event methods are also available:
This widget displays a bar which can be used to show progress (e.g. of some task being done).
The width of the progress bar.
The progress indicated by the progress bar as a factor (i.e. 0 is no completion, 1 is full completion, and 0.5 is half completion).
This widget provides a place for the user to enter text.
The width of the text box.
The text in the text box.
The maximum number of characters allowed in the text box.
See the documentation for xsge.gui.Widget for more information.
In addition to the event methods inherited from xsge.gui.Widget, the following event methods are also available:
This dialog shows a message box and accepts button input. All buttons cause the dialog to close and set choice to the button pressed.
The button clicked. If a button hasn’t been clicked (i.e. the dialog hasn’t yet been closed or was closed by clicking on the close button), it is set to None.
See the documentation for xsge.gui.Dialog for more information.
This dialog shows a message and has the user enter some text. Two buttons are shown: a “Cancel” button that closes the dialog, and an “Ok” button that sets text to the text entered and then closes the dialog.
The text entered after the “Ok” button is clicked. If the “Ok” button hasn’t been clicked, this is None.
See the documentation for xsge.gui.Dialog for more information.
Prepare this module for use. This function in particular creates the sprites and fonts it uses for windows and widgets. Because of this, it must not be called until after a sge.Game object has been created.
Show a message and return the button pressed.
Arguments:
Value returned is the index of the button pressed, where 0 is the leftmost button, or None if no button was pressed (i.e. the close button on the window frame was pressed instead).
See the documentation for xsge.gui.MessageDialog for more information.
Return text entered by the user.
Arguments:
Value returned is the text entered if the “Ok” button is pressed, or None otherwise.
See the documentation for xsge.gui.TextEntryDialog for more information.
Show a menu and return the index of the menu item selected.
Arguments:
See the documentation for xsge.gui.MenuDialog.from_text for more information.