bauiv1 package¶
Ballistica user interface api version 1
- class bauiv1.App[source]¶
Bases:
object
High level Ballistica app functionality and state.
Access the single shared instance of this class via the
app
attr available on various high level modules such asbabase
,bauiv1
, andbascenev1
.- SHUTDOWN_TASK_TIMEOUT_SECONDS = 12¶
How long we allow shutdown tasks to run before killing them. Currently the entire app hard-exits if shutdown takes 15 seconds, so we need to keep it under that. Staying above 10 should allow 10 second network timeouts to happen though.
- property active: bool¶
Whether the app is currently front and center.
This will be False when the app is hidden, other activities are covering it, etc. (depending on the platform).
- add_shutdown_task(coro: Coroutine[None, None, None]) None [source]¶
Add a task to be run on app shutdown.
Note that shutdown tasks will be canceled after
SHUTDOWN_TASK_TIMEOUT_SECONDS
if they are still running.
- property asyncio_loop: AbstractEventLoop¶
The logic thread’s
asyncio
event-loop.This allows
asyncio
tasks to be run in the logic thread.Generally you should call
create_async_task()
to schedule async code to run instead of using this directly. That will handle retaining the task and logging errors automatically. Only schedule tasks ontoasyncio_loop
yourself when you intend to hold on to the returned task and await its results. Releasing the task reference can lead to subtle bugs such as unreported errors and garbage-collected tasks disappearing before their work is done.Note that, at this time, the asyncio loop is encapsulated and explicitly stepped by the engine’s logic thread loop and thus things like
asyncio.get_running_loop()
will unintuitively not return this loop from most places in the logic thread; only from within a task explicitly created in this loop. Hopefully this situation will be improved in the future with a unified event loop.
- property classic: ClassicAppSubsystem | None¶
Our classic subsystem (if available).
- components: AppComponentSubsystem¶
- create_async_task(coro: Coroutine[Any, Any, T], *, name: str | None = None) None [source]¶
Create a fully managed
asyncio
task.This will automatically retain and release a reference to the task and log any exceptions that occur in it. If you need to await a task or otherwise need more control, schedule a task directly using
asyncio_loop
.
- devconsole: DevConsoleSubsystem¶
Subsystem for wrangling the dev-console UI.
- env: babase.Env¶
Static environment values for the app.
- fg_state: int¶
Incremented each time the app leaves the
SUSPENDED
state. This can be a simple way to determine if network data should be refreshed/etc.
- health: AppHealthSubsystem¶
Subsystem for keeping tabs on app health.
- lang: LanguageSubsystem¶
Language subsystem.
- meta: MetadataSubsystem¶
Subsystem for wrangling metadata.
- property mode_selector: babase.AppModeSelector¶
Controls which app-modes are used for handling given intents.
Plugins can override this to change high level app behavior and spinoff projects can change the default implementation for the same effect.
- net: NetworkSubsystem¶
Subsystem for network functionality.
- plugins: PluginSubsystem¶
Subsystem for wrangling plugins.
- property plus: PlusAppSubsystem | None¶
Our plus subsystem (if available).
- postinit() None [source]¶
Called after we’ve been inited and assigned to
babase.app
.Anything that accesses
babase.app
as part of its init process must go here instead of __init__.
- run() None [source]¶
Run the app to completion.
Note that this only works on builds/runs where Ballistica is managing its own event loop.
- set_intent(intent: AppIntent) None [source]¶
Set the intent for the app.
Intent defines what the app is trying to do at a given time. This call is asynchronous; the intent switch will happen in the logic thread in the near future. If this is called repeatedly before the change takes place, the final intent to be set will be used.
- stringedit: StringEditSubsystem¶
Subsystem for wrangling text input from various sources.
- threadpool: ThreadPoolExecutorEx¶
Default executor which can be used for misc background processing. It should also be passed to any additional asyncio loops we create so that everything shares the same single set of worker threads.
- property ui_v1: UIV1AppSubsystem¶
Our ui_v1 subsystem (always available).
- workspaces: WorkspaceSubsystem¶
Subsystem for wrangling workspaces.
- class bauiv1.AppIntent[source]¶
Bases:
object
Base class for high level directives given to the app.
- class bauiv1.AppIntentDefault[source]¶
Bases:
AppIntent
Tells the app to simply run in its default mode.
- class bauiv1.AppIntentExec(code: str)[source]¶
Bases:
AppIntent
Tells the app to exec some Python code.
- class bauiv1.AppMode[source]¶
Bases:
object
A low level mode the app can be in.
App-modes fundamentally change app behavior related to input handling, networking, graphics, and more. In a way, different app-modes can almost be considered different apps.
- classmethod can_handle_intent(intent: AppIntent) bool [source]¶
Return whether this mode can handle the provided intent.
For this to return True, the app-mode must claim to support the provided intent (via its
can_handle_intent_impl()
method) AND theAppExperience
associated with the app-mode must be supported by the current app and runtime environment.
- classmethod can_handle_intent_impl(intent: AppIntent) bool [source]¶
Override this to define indent handling for an app-mode.
Note that
AppExperience
does not have to be considered here; that is handled automatically by thecan_handle_intent()
call.
- classmethod get_app_experience() AppExperience [source]¶
Return the overall experience provided by this mode.
- on_app_active_changed() None [source]¶
Called when the app’s active state changes while in this app-mode.
This corresponds to the app’s
active
attr. App-active state becomes false when the app is hidden, minimized, backgrounded, etc. The app-mode may want to take action such as pausing a running game or saving state when this occurs.On platforms such as mobile where apps get suspended and later silently terminated by the OS, this is likely to be the last reliable place to save state/etc.
To best cover both mobile and desktop style platforms, actions such as saving state should generally happen in response to both
on_deactivate()
andon_app_active_changed()
(when active is False).
- on_deactivate() None [source]¶
Called when the mode stops being the active one for the app.
On platforms where the app is explicitly exited (such as desktop PC) this will also be called at app shutdown.
To best cover both mobile and desktop style platforms, actions such as saving state should generally happen in response to both
on_deactivate()
andon_app_active_changed()
(when active is False).
- class bauiv1.AppState(*values)[source]¶
Bases:
Enum
High level state the app can be in.
- INITING = 2¶
Python app subsystems are being inited but should not yet interact or do any work.
- LOADING = 3¶
Python app subsystems are inited and interacting, but the app has not yet embarked on a high level course of action. It is doing initial account logins, workspace & asset downloads, etc.
- NATIVE_BOOTSTRAPPING = 1¶
The native layer is spinning up its machinery (screens, renderers, etc.). Nothing should happen in the Python layer until this completes.
- NOT_STARTED = 0¶
The app has not yet begun starting and should not be used in any way.
- RUNNING = 4¶
All pieces are in place and the app is now doing its thing.
- SHUTDOWN_COMPLETE = 7¶
The app has completed shutdown. Any code running here should be basically immediate.
- SHUTTING_DOWN = 6¶
The app is shutting down. This process may involve sending network messages or other things that can take up to a few seconds, so ideally graphics and audio should remain functional (with fades or spinners or whatever to show something is happening).
- SUSPENDED = 5¶
Used on platforms such as mobile where the app basically needs to shut down while backgrounded. In this state, all event loops are suspended and all graphics and audio must cease completely. Be aware that the suspended state can be entered from any other state including
NATIVE_BOOTSTRAPPING
andSHUTTING_DOWN
.
- class bauiv1.AppTimer(time: float, call: Callable[[], Any], repeat: bool = False)[source]¶
Bases:
object
Timers are used to run code at later points in time.
This class encapsulates a timer based on app-time. The underlying timer will be destroyed when this object is no longer referenced. If you do not want to worry about keeping a reference to your timer around, use the
apptimer()
function instead to get a one-off timer.- Parameters:
time – Length of time in seconds that the timer will wait before firing.
call – A callable Python object. Remember that the timer will retain a strong reference to the callable for as long as it exists, so you may want to look into concepts such as
WeakCall
if that is not desired.repeat – If True, the timer will fire repeatedly, with each successive firing having the same delay as the first.
Example: Use a timer object to print repeatedly for a few seconds:
def say_it(): babase.screenmessage('BADGER!') def stop_saying_it(): global g_timer g_timer = None babase.screenmessage('MUSHROOM MUSHROOM!') # Create our timer; it will run as long as we keep its ref alive. g_timer = babase.AppTimer(0.3, say_it, repeat=True) # Now fire off a one-shot timer to kill the ref. babase.apptimer(3.89, stop_saying_it)
- class bauiv1.BasicMainWindowState(create_call: Callable[[Literal['in_right', 'in_left', 'in_scale'] | None, bauiv1.Widget | None], bauiv1.MainWindow])[source]¶
Bases:
MainWindowState
A basic MainWindowState holding a lambda to recreate a MainWindow.
- create_window(transition: Literal['in_right', 'in_left', 'in_scale'] | None = None, origin_widget: bauiv1.Widget | None = None) bauiv1.MainWindow [source]¶
Create a window based on this state.
WindowState child classes should override this to recreate their particular type of window.
- class bauiv1.Call(*args: Any, **keywds: Any)¶
Bases:
object
Wraps a callable and arguments into a single callable object.
The callable is strong-referenced so it won’t die until this object does.
Note that a bound method (ex:
myobj.dosomething
) contains a reference toself
(myobj
in that case), so you will be keeping that object alive too. Use babase.WeakCall if you want to pass a method to a callback without keeping its object alive.Example: Wrap a method call with 1 positional and 1 keyword arg:
mycall = babase.Call(myobj.dostuff, argval, namedarg=argval2) # Now we have a single callable to run that whole mess. # ..the same as calling myobj.dostuff(argval, namedarg=argval2) mycall()
- class bauiv1.ContextRef[source]¶
Bases:
object
Store or use a Ballistica context.
Many operations such as
bascenev1.newnode()
orbascenev1.gettexture()
operate implicitly on a current ‘context’. A context is some sort of state that functionality can implicitly use. Context determines, for example, which scene new nodes or textures get added to without having to specify that explicitly in the newnode()/gettexture() call. Contexts can also affect object lifecycles; for example aContextCall
will instantly become a no-op and release any references it is holding when the context it belongs to is destroyed.In general, if you are a modder, you should not need to worry about contexts; mod code should mostly be getting run in the correct context and timers and other callbacks will take care of saving and restoring contexts automatically. There may be rare cases, however, where you need to deal directly with contexts, and that is where this class comes in.
Creating a context-ref will capture a reference to the current context. Other modules may provide ways to access their contexts; for example a
bascenev1.Activity
instance has acontext
attribute. You can also use theempty()
classmethod to create a reference to no context. Some code such as UI calls may expect to be run with no context set and may complain if you try to use them within a context.Usage¶
Context-refs are generally used with the Python
with
statement, which sets the context they point to as current on entry and resets it to the previous value on exit.Example: Explicitly clear context while working with UI code from gameplay (UI stuff may complain if called within a context):
import bauiv1 as bui def _callback_called_from_gameplay(): # We are probably called with a game context as current, but # this makes UI stuff unhappy. So we clear the context while # doing our thing. with bui.ContextRef.empty(): my_container = bui.containerwidget()
- classmethod empty() ContextRef [source]¶
Return a context-ref pointing to no context.
This is useful when code should be run free of a context. For example, UI code generally insists on being run this way. Otherwise, callbacks set on the UI could inadvertently stop working due to a game activity ending, which would be unintuitive behavior.
- class bauiv1.DisplayTimer(time: float, call: Callable[[], Any], repeat: bool = False)[source]¶
Bases:
object
Timers are used to run code at later points in time.
This class encapsulates a timer based on display-time. The underlying timer will be destroyed when this object is no longer referenced. If you do not want to worry about keeping a reference to your timer around, use the
displaytimer()
function instead to get a one-off timer.Display-time is a time value intended to be used for animation and other visual purposes. It will generally increment by a consistent amount each frame. It will pass at an overall similar rate to AppTime, but trades accuracy for smoothness.
- Parameters:
time – Length of time in seconds that the timer will wait before firing.
call – A callable Python object. Remember that the timer will retain a strong reference to the callable for as long as it exists, so you may want to look into concepts such as
WeakCall
if that is not desired.repeat – If True, the timer will fire repeatedly, with each successive firing having the same delay as the first.
Example: Use a Timer object to print repeatedly for a few seconds:
def say_it(): babase.screenmessage('BADGER!') def stop_saying_it(): global g_timer g_timer = None babase.screenmessage('MUSHROOM MUSHROOM!') # Create our timer; it will run as long as we keep its ref alive. g_timer = babase.DisplayTimer(0.3, say_it, repeat=True) # Now fire off a one-shot timer to kill the ref. babase.displaytimer(3.89, stop_saying_it)
- class bauiv1.Keyboard[source]¶
Bases:
object
Chars definitions for on-screen keyboard.
Keyboards are discoverable by the meta-tag system and the user can select which one they want to use. On-screen keyboard uses chars from active babase.Keyboard.
- class bauiv1.LoginAdapter(login_type: LoginType)[source]¶
Bases:
object
Allows using implicit login types in an explicit way.
Some login types such as Google Play Game Services or Game Center are basically always present and often do not provide a way to log out from within a running app, so this adapter exists to use them in a flexible manner by ‘attaching’ and ‘detaching’ from an always-present login, allowing for its use alongside other login types. It also provides common functionality for server-side account verification and other handy bits.
- class ImplicitLoginState(login_id: str, display_name: str)[source]¶
Bases:
object
Describes the current state of an implicit login.
- class SignInResult(credentials: str)[source]¶
Bases:
object
Describes the final result of a sign-in attempt.
- get_sign_in_token(completion_cb: Callable[[str | None], None]) None [source]¶
Get a sign-in token from the adapter back end.
This token is then passed to the cloud to complete the sign-in process. The adapter can use this opportunity to bring up account creation UI, call its internal sign-in function, etc. as needed. The provided
completion_cb
should then be called with either a token or withNone
if sign in failed or was cancelled.
- on_back_end_active_change(active: bool) None [source]¶
Called when active state for the back-end is (possibly) changing.
Meant to be overridden by subclasses. Being active means that the implicit login provided by the back-end is actually being used by the app. It should therefore register unlocked achievements, leaderboard scores, allow viewing native UIs, etc. When not active it should ignore everything and behave as if signed out, even if it technically is still signed in.
- set_implicit_login_state(state: ImplicitLoginState | None) None [source]¶
Keep the adapter informed of implicit login states.
This should be called by the adapter back-end when an account of their associated type gets logged in or out.
- sign_in(result_cb: Callable[[LoginAdapter, SignInResult | Exception], None], description: str) None [source]¶
Attempt to sign in via this adapter.
This can be called even if the back-end is not implicitly signed in; the adapter will attempt to sign in if possible. An exception will be passed to the callback if the sign-in attempt fails.
- class bauiv1.LoginInfo(name: str)[source]¶
Bases:
object
Info for a login used by
AccountV2Handle
.
- class bauiv1.Lstr(*, resource: str, fallback_resource: str = '', fallback_value: str = '', subs: Sequence[tuple[str, str | Lstr]] | None = None)[source]¶
- class bauiv1.Lstr(*, translate: tuple[str, str], subs: Sequence[tuple[str, str | Lstr]] | None = None)
- class bauiv1.Lstr(*, value: str, subs: Sequence[tuple[str, str | Lstr]] | None = None)
Bases:
object
Used to define strings in a language-independent way.
These should be used whenever possible in place of hard-coded strings so that in-game or UI elements show up correctly on all clients in their currently active language.
To see available resource keys, look at any of the
ba_data/data/languages/*.json
files in the game or the translations pages at legacy.ballistica.net/translate.- Parameters:
resource – Pass a string to look up a translation by resource key.
translate – Pass a tuple consisting of a translation category and untranslated value. Any matching translation found in that category will be used. Otherwise the untranslated value will be.
value – Pass a regular string value to be used as-is.
subs – A sequence of 2-member tuples consisting of values and replacements. Replacements can be regular strings or other
Lstr
values.fallback_resource – A resource key that will be used if the main one is not present for the current language instead of falling back to the english value (‘resource’ mode only).
fallback_value – A regular string that will be used if neither the resource nor the fallback resource is found (‘resource’ mode only).
Example 1: Resource path
mynode.text = babase.Lstr(resource='audioSettingsWindow.titleText')
Example 2: Translation
If a translated value is available, it will be used; otherwise the English value will be. To see available translation categories, look under the
translations
resource section.mynode.text = babase.Lstr(translate=('gameDescriptions', 'Defeat all enemies'))
Example 3: Substitutions
Substitutions can be used with
resource
andtranslate
modes as well as thevalue
shown here.mynode.text = babase.Lstr(value='${A} / ${B}', subs=[('${A}', str(score)), ('${B}', str(total))])
Example 4: Nesting
Lstr
instances can be nested. This example would display the translated resource at'res_a'
but replace any instances of'${NAME}'
it contains with the translated resource at'res_b'
.mytextnode.text = babase.Lstr( resource='res_a', subs=[('${NAME}', babase.Lstr(resource='res_b'))])
- args¶
Basically just stores the exact args passed. However if Lstr values were passed for subs, they are replaced with that Lstr’s dict.
- evaluate() str [source]¶
Evaluate to a flat string in the current language.
You should avoid doing this as much as possible and instead pass and store
Lstr
values.
- static from_json(json_string: str) babase.Lstr [source]¶
Given a json string, returns a
Lstr
.Does no validation.
- is_flat_value() bool [source]¶
Return whether this instance represents a ‘flat’ value.
This is defined as a simple string value incorporating no translations, resources, or substitutions. In this case it may be reasonable to replace it with a raw string value, perform string manipulation on it, etc.
- class bauiv1.MainWindow(root_widget: bauiv1.Widget, *, transition: str | None, origin_widget: bauiv1.Widget | None, cleanupcheck: bool = True, refresh_on_screen_size_changes: bool = False)[source]¶
Bases:
Window
A special type of window that can be set as ‘main’.
The UI system has at most one main window at any given time. MainWindows support high level functionality such as saving and restoring states, allowing them to be automatically recreated when navigating back from other locations or when something like ui-scale changes.
- get_main_window_state() MainWindowState [source]¶
Return a WindowState to recreate this window, if supported.
- main_window_back() None [source]¶
Move back in the main window stack.
Is a no-op if the main window does not have control; no need to check main_window_has_control() first.
- main_window_close(transition: str | None = None) None [source]¶
Get window transitioning out if still alive.
- main_window_has_control() bool [source]¶
Is this MainWindow allowed to change the global main window?
It is a good idea to make sure this is True before calling main_window_replace(). This prevents fluke UI breakage such as multiple simultaneous events causing a MainWindow to spawn multiple replacements for itself.
- main_window_replace(new_window: MainWindow, back_state: MainWindowState | None = None, is_auxiliary: bool = False) None [source]¶
Replace ourself with a new MainWindow.
- class bauiv1.MainWindowState[source]¶
Bases:
object
Persistent state for a specific MainWindow.
This allows MainWindows to be automatically recreated for back-button purposes, when switching app-modes, etc.
- create_window(transition: Literal['in_right', 'in_left', 'in_scale'] | None = None, origin_widget: bauiv1.Widget | None = None) MainWindow [source]¶
Create a window based on this state.
WindowState child classes should override this to recreate their particular type of window.
- exception bauiv1.NotFoundError[source]¶
Bases:
Exception
Raised when a referenced object does not exist.
- class bauiv1.Permission(*values)[source]¶
Bases:
Enum
Permissions that can be requested from the OS.
- STORAGE = 0¶
- class bauiv1.Plugin[source]¶
Bases:
object
A plugin to alter app behavior in some way.
Plugins are discoverable by the
MetadataSubsystem
system and the user can select which ones they want to enable. Enabled plugins are then called at specific times as the app is running in order to modify its behavior in some way.
- class bauiv1.PluginSpec(class_path: str, loadable: bool)[source]¶
Bases:
object
Represents a plugin the engine knows about.
- attempted_load¶
Whether the engine has attempted to load the plugin. If this is True but the value of
plugin
is None, it means there was an error loading the plugin. If a plugin’s api-version does not match the running app, if a new plugin is detected with auto-enable-plugins disabled, or if the user has explicitly disabled a plugin, the engine will not even attempt to load it.
- class_path¶
Fully qualified class path for the plugin.
- property enabled: bool¶
Whether this plugin is set to load.
Getting or setting this attr affects the corresponding app-config key. Remember to commit the app-config after making any changes.
- loadable¶
Can we attempt to load the plugin?
- class bauiv1.QuitType(*values)[source]¶
Bases:
Enum
Types of quit behavior that can be requested from the app.
- ‘soft’ may hide/reset the app but keep the process running, depending
on the platform (generally a thing on mobile).
- ‘back’ is a variant of ‘soft’ which may give ‘back-button-pressed’
behavior depending on the platform. (returning to some previous activity instead of dumping to the home screen, etc.)
- ‘hard’ leads to the process exiting. This generally should be avoided
on platforms such as mobile where apps are expected to keep running until killed by the OS.
- BACK = 1¶
- HARD = 2¶
- SOFT = 0¶
- class bauiv1.RootUIUpdatePause[source]¶
Bases:
object
Pauses updates to the root-ui while in existence.
- class bauiv1.SpecialChar(*values)[source]¶
Bases:
Enum
Special characters the game can print.
- BACK = 10¶
- BOTTOM_BUTTON = 7¶
- CROWN = 64¶
- DELETE = 8¶
- DICE_BUTTON1 = 31¶
- DICE_BUTTON2 = 32¶
- DICE_BUTTON3 = 33¶
- DICE_BUTTON4 = 34¶
- DOWN_ARROW = 0¶
- DPAD_CENTER_BUTTON = 15¶
- DRAGON = 69¶
- EXPLODINARY_LOGO = 46¶
- EYE_BALL = 66¶
- FAST_FORWARD_BUTTON = 14¶
- FEDORA = 62¶
- FIREBALL = 76¶
- FLAG_ALGERIA = 81¶
- FLAG_ARGENTINA = 92¶
- FLAG_AUSTRALIA = 85¶
- FLAG_BRAZIL = 50¶
- FLAG_CANADA = 54¶
- FLAG_CHILE = 94¶
- FLAG_CHINA = 52¶
- FLAG_CZECH_REPUBLIC = 84¶
- FLAG_EGYPT = 79¶
- FLAG_FRANCE = 57¶
- FLAG_GERMANY = 49¶
- FLAG_INDIA = 55¶
- FLAG_INDONESIA = 58¶
- FLAG_IRAN = 90¶
- FLAG_ITALY = 59¶
- FLAG_JAPAN = 56¶
- FLAG_KUWAIT = 80¶
- FLAG_MALAYSIA = 83¶
- FLAG_MEXICO = 48¶
- FLAG_NETHERLANDS = 61¶
- FLAG_PHILIPPINES = 93¶
- FLAG_POLAND = 91¶
- FLAG_QATAR = 78¶
- FLAG_RUSSIA = 51¶
- FLAG_SAUDI_ARABIA = 82¶
- FLAG_SINGAPORE = 86¶
- FLAG_SOUTH_KOREA = 60¶
- FLAG_UNITED_ARAB_EMIRATES = 77¶
- FLAG_UNITED_KINGDOM = 53¶
- FLAG_UNITED_STATES = 47¶
- GAME_CENTER_LOGO = 30¶
- GAME_CIRCLE_LOGO = 35¶
- GOOGLE_PLAY_GAMES_LOGO = 29¶
- HAL = 63¶
- HEART = 68¶
- HELMET = 70¶
- LEFT_ARROW = 2¶
- LEFT_BUTTON = 5¶
- LOCAL_ACCOUNT = 45¶
- LOGO = 27¶
- LOGO_FLAT = 11¶
- MIKIROG = 95¶
- MOON = 74¶
- MUSHROOM = 71¶
- NINJA_STAR = 72¶
- NVIDIA_LOGO = 89¶
- OCULUS_LOGO = 87¶
- OUYA_BUTTON_A = 25¶
- OUYA_BUTTON_O = 22¶
- OUYA_BUTTON_U = 23¶
- OUYA_BUTTON_Y = 24¶
- PARTY_ICON = 36¶
- PAUSE_BUTTON = 21¶
- PLAY_BUTTON = 20¶
- PLAY_PAUSE_BUTTON = 13¶
- PLAY_STATION_CIRCLE_BUTTON = 17¶
- PLAY_STATION_CROSS_BUTTON = 16¶
- PLAY_STATION_SQUARE_BUTTON = 19¶
- PLAY_STATION_TRIANGLE_BUTTON = 18¶
- REWIND_BUTTON = 12¶
- RIGHT_ARROW = 3¶
- RIGHT_BUTTON = 6¶
- SHIFT = 9¶
- SKULL = 67¶
- SPIDER = 75¶
- STEAM_LOGO = 88¶
- TEST_ACCOUNT = 37¶
- TICKET = 28¶
- TICKET_BACKING = 38¶
- TOKEN = 26¶
- TOP_BUTTON = 4¶
- TROPHY0A = 42¶
- TROPHY0B = 43¶
- TROPHY1 = 39¶
- TROPHY2 = 40¶
- TROPHY3 = 41¶
- TROPHY4 = 44¶
- UP_ARROW = 1¶
- V2_LOGO = 96¶
- VIKING_HELMET = 73¶
- YIN_YANG = 65¶
- class bauiv1.UIScale(*values)[source]¶
Bases:
Enum
The overall scale the UI is being rendered for. Note that this is independent of pixel resolution. For example, a phone and a desktop PC might render the game at similar pixel resolutions but the size they display content at will vary significantly.
- ‘large’ is used for devices such as desktop PCs where fine details can
be clearly seen. UI elements are generally smaller on the screen and more content can be seen at once.
- ‘medium’ is used for devices such as tablets, TVs, or VR headsets.
This mode strikes a balance between clean readability and amount of content visible.
- ‘small’ is used primarily for phones or other small devices where
content needs to be presented as large and clear in order to remain readable from an average distance.
- LARGE = 2¶
- MEDIUM = 1¶
- SMALL = 0¶
- class bauiv1.UIV1AppSubsystem[source]¶
Bases:
AppSubsystem
Consolidated UI functionality for the app.
To use this class, access the single instance of it at ‘ba.app.ui’.
- class RootUIElement(*values)[source]¶
Bases:
Enum
Stuff provided by the root ui.
- ACCOUNT_BUTTON = 'account_button'¶
- ACHIEVEMENTS_BUTTON = 'achievements_button'¶
- CHEST_SLOT_0 = 'chest_slot_0'¶
- CHEST_SLOT_1 = 'chest_slot_1'¶
- CHEST_SLOT_2 = 'chest_slot_2'¶
- CHEST_SLOT_3 = 'chest_slot_3'¶
- GET_TOKENS_BUTTON = 'get_tokens_button'¶
- INBOX_BUTTON = 'inbox_button'¶
- INVENTORY_BUTTON = 'inventory_button'¶
- LEVEL_METER = 'level_meter'¶
- MENU_BUTTON = 'menu_button'¶
- SETTINGS_BUTTON = 'settings_button'¶
- SQUAD_BUTTON = 'squad_button'¶
- STORE_BUTTON = 'store_button'¶
- TICKETS_METER = 'tickets_meter'¶
- TOKENS_METER = 'tokens_meter'¶
- TROPHY_METER = 'trophy_meter'¶
- property available: bool¶
Can uiv1 currently be used?
Code that may run in headless mode, before the UI has been spun up, while other ui systems are active, etc. can check this to avoid likely erroring.
- get_main_window() bauiv1.MainWindow | None [source]¶
Return main window, if any.
- on_app_loading() None [source]¶
Called when the app reaches the loading state.
Note that subsystems created after the app switches to the loading state will not receive this callback. Subsystems created by plugins are an example of this.
- on_screen_size_change() None [source]¶
Called when the screen size changes.
Will not be called for the initial screen size.
- on_ui_scale_change() None [source]¶
Called when screen ui-scale changes.
Will not be called for the initial ui scale.
- reset() None [source]¶
Reset the subsystem to a default state.
This is called when switching app modes, but may be called at other times too.
- restore_main_window_state(state: MainWindowState) None [source]¶
Restore UI to a saved state.
- save_main_window_state(window: MainWindow) MainWindowState [source]¶
Fully initialize a window-state from a window.
Use this to get a complete state for later restoration purposes. Calling the window’s get_main_window_state() directly is insufficient.
- set_main_window(window: bauiv1.MainWindow, *, from_window: bauiv1.MainWindow | None | bool = True, is_back: bool = False, is_top_level: bool = False, is_auxiliary: bool = False, back_state: MainWindowState | None = None, suppress_warning: bool = False) None [source]¶
Set the current ‘main’ window.
Generally this should not be called directly; The high level MainWindow methods main_window_replace() and main_window_back() should be used whenever possible to implement navigation.
The caller is responsible for cleaning up any previous main window.
- class bauiv1.WeakCall(*args: Any, **keywds: Any)¶
Bases:
object
Wrap a callable and arguments into a single callable object.
When passed a bound method as the callable, the instance portion of it is weak-referenced, meaning the underlying instance is free to die if all other references to it go away. Should this occur, calling the weak-call is simply a no-op.
Think of this as a handy way to tell an object to do something at some point in the future if it happens to still exist.
EXAMPLE A: This code will create a
FooClass
instance and call itsbar()
method 5 seconds later; it will be kept alive even though we overwrite its variable with None because the bound method we pass as a timer callback (foo.bar
) strong-references it:foo = FooClass() babase.apptimer(5.0, foo.bar) foo = None
EXAMPLE B: This code will not keep our object alive; it will die when we overwrite it with
None
and the timer will be a no-op when it fires:foo = FooClass() babase.apptimer(5.0, ba.WeakCall(foo.bar)) foo = None
EXAMPLE C: Wrap a method call with some positional and keyword args:
myweakcall = babase.WeakCall(self.dostuff, argval1, namedarg=argval2) # Now we have a single callable to run that whole mess. # The same as calling myobj.dostuff(argval1, namedarg=argval2) # (provided my_obj still exists; this will do nothing otherwise). myweakcall()
Note: additional args and keywords you provide to the weak-call constructor are stored as regular strong-references; you’ll need to wrap them in weakrefs manually if desired.
- class bauiv1.Widget[source]¶
Bases:
object
Internal type for low level UI elements; buttons, windows, etc.
This class represents a weak reference to a widget object in the internal C++ layer. Currently, functions such as bauiv1.buttonwidget() must be used to instantiate or edit these.
- add_delete_callback(call: Callable) None [source]¶
Add a call to be run immediately after this widget is destroyed.
- delete(ignore_missing: bool = True) None [source]¶
Delete the Widget. Ignores already-deleted Widgets if ignore_missing is True; otherwise an Exception is thrown.
- exists() bool [source]¶
Returns whether the Widget still exists. Most functionality will fail on a nonexistent widget.
Note that you can also use the boolean operator for this same functionality, so a statement such as “if mywidget” will do the right thing both for Widget objects and values of None.
- get_children() list[bauiv1.Widget] [source]¶
Returns any child Widgets of this Widget.
- get_screen_space_center() tuple[float, float] [source]¶
Returns the coords of the bauiv1.Widget center relative to the center of the screen. This can be useful for placing pop-up windows and other special cases.
- get_selected_child() bauiv1.Widget | None [source]¶
Returns the selected child Widget or None if nothing is selected.
- class bauiv1.Window(root_widget: bauiv1.Widget, cleanupcheck: bool = True, prevent_main_window_auto_recreate: bool = True)[source]¶
Bases:
object
A basic window.
Essentially wraps a ContainerWidget with some higher level functionality.
- get_root_widget() bauiv1.Widget [source]¶
Return the root widget.
- bauiv1.apptime() babase.AppTime [source]¶
Return the current app-time in seconds.
App-time is a monotonic time value; it starts at 0.0 when the app launches and will never jump by large amounts or go backwards, even if the system time changes. Its progression will pause when the app is in a suspended state.
Note that the AppTime returned here is simply float; it just has a unique type in the type-checker’s eyes to help prevent it from being accidentally used with time functionality expecting other time types.
- bauiv1.apptimer(time: float, call: Callable[[], Any]) None [source]¶
Schedule a callable object to run based on app-time.
This function creates a one-off timer which cannot be canceled or modified once created. If you require the ability to do so, or need a repeating timer, use the babase.AppTimer class instead.
- Parameters:
time – Length of time in seconds that the timer will wait before firing.
call – A callable Python object. Note that the timer will retain a strong reference to the callable for as long as the timer exists, so you may want to look into concepts such as
WeakCall
if that is not desired.
Example: Print some stuff through time:
import babase babase.screenmessage('hello from now!') babase.apptimer(1.0, babase.Call(babase.screenmessage, 'hello from the future!')) babase.apptimer(2.0, babase.Call(babase.screenmessage, 'hello from the future 2!'))
- bauiv1.buttonwidget(*, edit: bauiv1.Widget | None = None, parent: bauiv1.Widget | None = None, id: str | None = None, size: Sequence[float] | None = None, position: Sequence[float] | None = None, on_activate_call: Callable | None = None, label: str | bauiv1.Lstr | None = None, color: Sequence[float] | None = None, down_widget: bauiv1.Widget | None = None, up_widget: bauiv1.Widget | None = None, left_widget: bauiv1.Widget | None = None, right_widget: bauiv1.Widget | None = None, texture: bauiv1.Texture | None = None, text_scale: float | None = None, textcolor: Sequence[float] | None = None, enable_sound: bool | None = None, mesh_transparent: bauiv1.Mesh | None = None, mesh_opaque: bauiv1.Mesh | None = None, repeat: bool | None = None, scale: float | None = None, transition_delay: float | None = None, on_select_call: Callable | None = None, button_type: str | None = None, extra_touch_border_scale: float | None = None, selectable: bool | None = None, show_buffer_top: float | None = None, icon: bauiv1.Texture | None = None, iconscale: float | None = None, icon_tint: float | None = None, icon_color: Sequence[float] | None = None, autoselect: bool | None = None, mask_texture: bauiv1.Texture | None = None, tint_texture: bauiv1.Texture | None = None, tint_color: Sequence[float] | None = None, tint2_color: Sequence[float] | None = None, text_flatness: float | None = None, text_res_scale: float | None = None, enabled: bool | None = None) bauiv1.Widget [source]¶
Create or edit a button widget.
Pass a valid existing bauiv1.Widget as ‘edit’ to modify it; otherwise a new one is created and returned. Arguments that are not set to None are applied to the Widget.
- bauiv1.charstr(char_id: babase.SpecialChar) str [source]¶
Return a unicode string representing a special character.
Note that these utilize the private-use block of unicode characters (U+E000-U+F8FF) and are specific to the game; exporting or rendering them elsewhere will be meaningless.
See
SpecialChar
for the list of available characters.
- bauiv1.checkboxwidget(*, edit: bauiv1.Widget | None = None, parent: bauiv1.Widget | None = None, size: Sequence[float] | None = None, position: Sequence[float] | None = None, text: str | bauiv1.Lstr | None = None, value: bool | None = None, on_value_change_call: Callable[[bool], None] | None = None, on_select_call: Callable[[], None] | None = None, text_scale: float | None = None, textcolor: Sequence[float] | None = None, scale: float | None = None, is_radio_button: bool | None = None, maxwidth: float | None = None, autoselect: bool | None = None, color: Sequence[float] | None = None) bauiv1.Widget [source]¶
Create or edit a check-box widget.
Pass a valid existing bauiv1.Widget as ‘edit’ to modify it; otherwise a new one is created and returned. Arguments that are not set to None are applied to the Widget.
- bauiv1.clipboard_is_supported() bool [source]¶
Return whether this platform supports clipboard operations at all.
If this returns False, UIs should not show ‘copy to clipboard’ buttons, etc.
- bauiv1.clipboard_set_text(value: str) None [source]¶
Copy a string to the system clipboard.
Ensure that
clipboard_is_supported()
returns True before adding buttons/etc. that make use of this functionality.
- bauiv1.columnwidget(*, edit: bauiv1.Widget | None = None, parent: bauiv1.Widget | None = None, size: Sequence[float] | None = None, position: Sequence[float] | None = None, background: bool | None = None, selected_child: bauiv1.Widget | None = None, visible_child: bauiv1.Widget | None = None, single_depth: bool | None = None, print_list_exit_instructions: bool | None = None, left_border: float | None = None, top_border: float | None = None, bottom_border: float | None = None, selection_loops_to_parent: bool | None = None, border: float | None = None, margin: float | None = None, claims_left_right: bool | None = None) bauiv1.Widget [source]¶
Create or edit a column widget.
Pass a valid existing bauiv1.Widget as ‘edit’ to modify it; otherwise a new one is created and returned. Arguments that are not set to None are applied to the Widget.
- bauiv1.containerwidget(*, edit: bauiv1.Widget | None = None, parent: bauiv1.Widget | None = None, id: str | None = None, size: Sequence[float] | None = None, position: Sequence[float] | None = None, background: bool | None = None, selected_child: bauiv1.Widget | None = None, transition: str | None = None, cancel_button: bauiv1.Widget | None = None, start_button: bauiv1.Widget | None = None, root_selectable: bool | None = None, on_activate_call: Callable[[], None] | None = None, claims_left_right: bool | None = None, selection_loops: bool | None = None, selection_loops_to_parent: bool | None = None, scale: float | None = None, on_outside_click_call: Callable[[], None] | None = None, single_depth: bool | None = None, visible_child: bauiv1.Widget | None = None, stack_offset: Sequence[float] | None = None, color: Sequence[float] | None = None, on_cancel_call: Callable[[], None] | None = None, print_list_exit_instructions: bool | None = None, click_activate: bool | None = None, always_highlight: bool | None = None, selectable: bool | None = None, scale_origin_stack_offset: Sequence[float] | None = None, toolbar_visibility: Literal['menu_minimal', 'menu_minimal_no_back', 'menu_full', 'menu_full_no_back', 'menu_store', 'menu_store_no_back', 'menu_in_game', 'menu_tokens', 'get_tokens', 'no_menu_minimal', 'inherit'] | None = None, on_select_call: Callable[[], None] | None = None, claim_outside_clicks: bool | None = None, claims_up_down: bool | None = None) bauiv1.Widget [source]¶
Create or edit a container widget.
Pass a valid existing bauiv1.Widget as ‘edit’ to modify it; otherwise a new one is created and returned. Arguments that are not set to None are applied to the Widget.
- bauiv1.displaytime() babase.DisplayTime [source]¶
Return the current display-time in seconds.
Display-time is a time value intended to be used for animation and other visual purposes. It will generally increment by a consistent amount each frame. It will pass at an overall similar rate to app-time, but trades accuracy for smoothness.
Note that the value returned here is simply a float; it just has a unique type in the type-checker’s eyes to help prevent it from being accidentally used with time functionality expecting other time types.
- bauiv1.displaytimer(time: float, call: Callable[[], Any]) None [source]¶
Schedule a callable object to run based on display-time.
This function creates a one-off timer which cannot be canceled or modified once created. If you require the ability to do so, or need a repeating timer, use the
DisplayTimer
class instead.Display-time is a time value intended to be used for animation and other visual purposes. It will generally increment by a consistent amount each frame. It will pass at an overall similar rate to app-time, but trades accuracy for smoothness.
- Parameters:
time – Length of time in seconds that the timer will wait before firing.
call – A callable Python object. Note that the timer will retain a strong reference to the callable for as long as the timer exists, so you may want to look into concepts such as
WeakCall
if that is not desired.
Example: Print some stuff through time:
babase.screenmessage('hello from now!') babase.displaytimer(1.0, babase.Call(babase.screenmessage, 'hello from the future!')) babase.displaytimer(2.0, babase.Call(babase.screenmessage, 'hello from the future 2!'))
- bauiv1.do_once() bool [source]¶
Return whether this is the first time running a line of code.
This is used by
print_once()
type calls to keep from overflowing logs. The call functions by registering the filename and line where The call is made from. Returns True if this location has not been registered already, and False if it has.Example: This print will only fire for the first loop iteration:
for i in range(10): if babase.do_once(): print('HelloWorld once from loop!')
- bauiv1.existing(obj: ExistableT | None) ExistableT | None [source]¶
Convert invalid references to None for any babase.Existable object.
To best support type checking, it is important that invalid references not be passed around and instead get converted to values of None. That way the type checker can properly flag attempts to pass possibly-dead objects (
FooType | None
) into functions expecting only live ones (FooType
), etc. This call can be used on any ‘existable’ object (one with anexists()
method) and will convert it to aNone
value if it does not exist.For more info, see notes on ‘existables’ here: https://ballistica.net/wiki/Coding-Style-Guide
- bauiv1.get_ip_address_type(addr: str) AddressFamily [source]¶
Return an address-type given an address.
Can be
socket.AF_INET
orsocket.AF_INET6
.
- bauiv1.get_qrcode_texture(url: str) bauiv1.Texture [source]¶
Return a QR code texture.
The provided url must be 64 bytes or less.
- bauiv1.get_special_widget(name: Literal['squad_button', 'back_button', 'account_button', 'achievements_button', 'settings_button', 'inbox_button', 'store_button', 'get_tokens_button', 'inventory_button', 'tickets_meter', 'tokens_meter', 'trophy_meter', 'level_meter', 'overlay_stack', 'chest_0_button', 'chest_1_button', 'chest_2_button', 'chest_3_button']) bauiv1.Widget [source]¶
(internal)
- bauiv1.get_virtual_safe_area_size() tuple[float, float] [source]¶
Return the size of the area on screen that will always be visible.
- bauiv1.get_virtual_screen_size() tuple[float, float] [source]¶
Return the current virtual size of the display.
- bauiv1.getclass(name: str, subclassof: type[T], check_sdlib_modulename_clash: bool = False) type[T] [source]¶
Given a full class name such as
foo.bar.MyClass
, return the class.The class will be checked to make sure it is a subclass of the provided ‘subclassof’ class, and a
TypeError
will be raised if not.
- bauiv1.getmesh(name: str) bauiv1.Mesh [source]¶
Load a mesh for use solely in the local user interface.
- bauiv1.getsound(name: str) bauiv1.Sound [source]¶
Load a sound for use in the ui.
- bauiv1.gettexture(name: str) bauiv1.Texture [source]¶
Load a texture for use in the ui.
- bauiv1.hscrollwidget(*, edit: bauiv1.Widget | None = None, parent: bauiv1.Widget | None = None, size: Sequence[float] | None = None, position: Sequence[float] | None = None, background: bool | None = None, selected_child: bauiv1.Widget | None = None, capture_arrows: bool | None = None, on_select_call: Callable[[], None] | None = None, center_small_content: bool | None = None, color: Sequence[float] | None = None, highlight: bool | None = None, border_opacity: float | None = None, simple_culling_h: float | None = None, claims_left_right: bool | None = None, claims_up_down: bool | None = None) bauiv1.Widget [source]¶
Create or edit a horizontal scroll widget.
Pass a valid existing bauiv1.Widget as ‘edit’ to modify it; otherwise a new one is created and returned. Arguments that are not set to None are applied to the Widget.
- bauiv1.imagewidget(*, edit: bauiv1.Widget | None = None, parent: bauiv1.Widget | None = None, size: Sequence[float] | None = None, position: Sequence[float] | None = None, color: Sequence[float] | None = None, texture: bauiv1.Texture | None = None, opacity: float | None = None, mesh_transparent: bauiv1.Mesh | None = None, mesh_opaque: bauiv1.Mesh | None = None, has_alpha_channel: bool = True, tint_texture: bauiv1.Texture | None = None, tint_color: Sequence[float] | None = None, transition_delay: float | None = None, draw_controller: bauiv1.Widget | None = None, tint2_color: Sequence[float] | None = None, tilt_scale: float | None = None, mask_texture: bauiv1.Texture | None = None, radial_amount: float | None = None, draw_controller_mult: float | None = None) bauiv1.Widget [source]¶
Create or edit an image widget.
Pass a valid existing bauiv1.Widget as ‘edit’ to modify it; otherwise a new one is created and returned. Arguments that are not set to None are applied to the Widget.
- bauiv1.in_logic_thread() bool [source]¶
Return whether the current thread is the logic thread.
The logic thread is where a large amount of app code runs, and various functionality expects to only be used from there.
- bauiv1.is_browser_likely_available() bool [source]¶
Return whether a browser likely exists on the current device.
If this returns False, you may want to avoid calling
open_url()
with any lengthy addresses. (open_url()
will display an address as a string/qr-code in a window if unable to bring up a browser, but that is only reasonable for small-ish URLs.)
- bauiv1.open_url(address: str, force_fallback: bool = False) None [source]¶
Open the provided URL.
Attempts to open the provided url in a web-browser. If that is not possible (or
force_fallback
is True), instead displays the url as a string and/or qrcode.
- bauiv1.pushcall(call: Callable, from_other_thread: bool = False, suppress_other_thread_warning: bool = False, other_thread_use_fg_context: bool = False, raw: bool = False) None [source]¶
Push a call to the logic-thread’s event loop.
This function expects to be called from the logic thread, and will automatically save and restore the context to behave seamlessly.
To push a call from outside of the logic thread, pass
from_other_thread=True
. In that case the call will run with no context set. To instead run in whichever context is currently active on the logic thread, passother_thread_use_fg_context=True
. Passingraw=True
will skip thread checks and context saves/restores altogether.
- bauiv1.quit(confirm: bool = False, quit_type: babase.QuitType | None = None) None [source]¶
Quit the app.
If
confirm
is True, a confirm dialog will be presented if conditions allow; otherwise the quit will still be immediate. See docs forQuitType
for explanations of the optionalquit_type
arg.
- bauiv1.root_ui_pause_updates() None [source]¶
Temporarily pause updates to the root ui for animation purposes. Make sure that each call to this is matched by a call to root_ui_resume_updates().
- bauiv1.root_ui_resume_updates() None [source]¶
Resume paused updates to the root ui for animation purposes.
- bauiv1.rowwidget(edit: bauiv1.Widget | None = None, parent: bauiv1.Widget | None = None, size: Sequence[float] | None = None, position: Sequence[float] | None = None, background: bool | None = None, selected_child: bauiv1.Widget | None = None, visible_child: bauiv1.Widget | None = None, claims_left_right: bool | None = None, selection_loops_to_parent: bool | None = None) bauiv1.Widget [source]¶
Create or edit a row widget.
Pass a valid existing bauiv1.Widget as ‘edit’ to modify it; otherwise a new one is created and returned. Arguments that are not set to None are applied to the Widget.
- bauiv1.safecolor(color: Sequence[float], target_intensity: float = 0.6) tuple[float, ...] [source]¶
Given a color tuple, return a color safe to display as text.
Accepts tuples of length 3 or 4. This will slightly brighten very dark colors, etc.
- bauiv1.screenmessage(message: str | babase.Lstr, color: Sequence[float] | None = None, log: bool = False) None [source]¶
Print a message to the local client’s screen in a given color.
Note that this function is purely for local display. To broadcast screen-messages during gameplay, look for methods such as
bascenev1.broadcastmessage()
.
- bauiv1.scrollwidget(*, edit: bauiv1.Widget | None = None, parent: bauiv1.Widget | None = None, size: Sequence[float] | None = None, position: Sequence[float] | None = None, background: bool | None = None, selected_child: bauiv1.Widget | None = None, capture_arrows: bool = False, on_select_call: Callable | None = None, center_small_content: bool | None = None, center_small_content_horizontally: bool | None = None, color: Sequence[float] | None = None, highlight: bool | None = None, border_opacity: float | None = None, simple_culling_v: float | None = None, selection_loops_to_parent: bool | None = None, claims_left_right: bool | None = None, claims_up_down: bool | None = None, autoselect: bool | None = None) bauiv1.Widget [source]¶
Create or edit a scroll widget.
Pass a valid existing bauiv1.Widget as ‘edit’ to modify it; otherwise a new one is created and returned. Arguments that are not set to None are applied to the Widget.
- bauiv1.spinnerwidget(*, edit: bauiv1.Widget | None = None, parent: bauiv1.Widget | None = None, size: float | None = None, position: Sequence[float] | None = None, style: Literal['bomb', 'simple'] | None = None, visible: bool | None = None) bauiv1.Widget [source]¶
Create or edit a spinner widget.
Pass a valid existing bauiv1.Widget as ‘edit’ to modify it; otherwise a new one is created and returned. Arguments that are not set to None are applied to the Widget.
- bauiv1.supports_unicode_display() bool [source]¶
Return whether we can display all unicode characters in the gui.
- bauiv1.textwidget(*, edit: bauiv1.Widget | None = None, parent: bauiv1.Widget | None = None, size: Sequence[float] | None = None, position: Sequence[float] | None = None, text: str | bauiv1.Lstr | None = None, v_align: str | None = None, h_align: str | None = None, editable: bool | None = None, padding: float | None = None, on_return_press_call: Callable[[], None] | None = None, on_activate_call: Callable[[], None] | None = None, selectable: bool | None = None, query: bauiv1.Widget | None = None, max_chars: int | None = None, color: Sequence[float] | None = None, click_activate: bool | None = None, on_select_call: Callable[[], None] | None = None, always_highlight: bool | None = None, draw_controller: bauiv1.Widget | None = None, scale: float | None = None, corner_scale: float | None = None, description: str | bauiv1.Lstr | None = None, transition_delay: float | None = None, maxwidth: float | None = None, max_height: float | None = None, flatness: float | None = None, shadow: float | None = None, autoselect: bool | None = None, rotate: float | None = None, enabled: bool | None = None, force_internal_editing: bool | None = None, always_show_carat: bool | None = None, big: bool | None = None, extra_touch_border_scale: float | None = None, res_scale: float | None = None, query_max_chars: bauiv1.Widget | None = None, query_description: bauiv1.Widget | None = None, adapter_finished: bool | None = None, glow_type: str | None = None, allow_clear_button: bool | None = None) bauiv1.Widget [source]¶
Create or edit a text widget.
Pass a valid existing bauiv1.Widget as ‘edit’ to modify it; otherwise a new one is created and returned. Arguments that are not set to None are applied to the Widget.
- bauiv1.timestring(timeval: float | int, centi: bool = True) babase.Lstr [source]¶
Generate a localized string for displaying a time value.
Given a time value, returns a localized string with: (hours if > 0 ) : minutes : seconds : (centiseconds if centi=True).
Warning
the underlying localized-string value is somewhat large, so don’t use this to rapidly update text values for an in-game timer or you may consume significant network bandwidth. For that sort of thing you should use things like ‘timedisplay’ nodes and attribute connections.
- bauiv1.uibounds() tuple[float, float, float, float] [source]¶
(internal)
Returns a tuple of 4 values: (x-min, x-max, y-min, y-max) representing the range of values that can be plugged into a root level bauiv1.ContainerWidget’s stack_offset value while guaranteeing that its center remains onscreen.
- bauiv1.uicleanupcheck(obj: Any, widget: bauiv1.Widget) None [source]¶
Checks to ensure a widget-owning object gets cleaned up properly.
This adds a check which will print an error message if the provided object still exists ~5 seconds after the provided bauiv1.Widget dies.
This is a good sanity check for any sort of object that wraps or controls a bauiv1.Widget. For instance, a ‘Window’ class instance has no reason to still exist once its root container bauiv1.Widget has fully transitioned out and been destroyed. Circular references or careless strong referencing can lead to such objects never getting destroyed, however, and this helps detect such cases to avoid memory leaks.
- bauiv1.utc_now_cloud() datetime.datetime [source]¶
Returns estimated utc time regardless of local clock settings.
Applies offsets pulled from server communication/etc.
- bauiv1.widget(*, edit: bauiv1.Widget, up_widget: bauiv1.Widget | None = None, down_widget: bauiv1.Widget | None = None, left_widget: bauiv1.Widget | None = None, right_widget: bauiv1.Widget | None = None, show_buffer_top: float | None = None, show_buffer_bottom: float | None = None, show_buffer_left: float | None = None, show_buffer_right: float | None = None, depth_range: tuple[float, float] | None = None, autoselect: bool | None = None) None [source]¶
Edit common attributes of any widget.
Unlike other UI calls, this can only be used to edit, not to create.
Submodules¶
bauiv1.onscreenkeyboard module¶
Provides the built-in on screen keyboard UI.
- class bauiv1.onscreenkeyboard.OnScreenKeyboardWindow(adapter: StringEditAdapter)[source]¶
Bases:
Window
Simple built-in on-screen keyboard.