1+ """Pygame module to provide additional context about the system.
2+
3+ .. versionadded:: 2.2.0
4+ """
5+
16from typing import Optional , TypedDict
27
38from pygame ._data_classes import PowerState
@@ -22,8 +27,180 @@ class _Locale(TypedDict):
2227 language : str
2328 country : Optional [str ]
2429
25- def get_cpu_instruction_sets () -> _InstructionSets : ...
26- def get_total_ram () -> int : ...
27- def get_pref_path (org : str , app : str ) -> str : ...
28- def get_pref_locales () -> list [_Locale ]: ...
29- def get_power_state () -> Optional [PowerState ]: ...
30+ def get_cpu_instruction_sets () -> _InstructionSets :
31+ """Get the information of CPU instruction sets.
32+
33+ Returns a dict of the information of CPU instruction sets. The keys of
34+ the dict are the names of instruction sets and the values determine
35+ whether the instruction set is available.
36+
37+ Some of functions like ``Surface.blit`` can be accelerated by SIMD
38+ instruction sets like SSE2 or AVX2. By checking the availability of
39+ instruction sets, you can check if these accelerations are available.
40+
41+ Here is an example of the returned dict
42+ ::
43+
44+ {
45+ 'ALTIVEC': False,
46+ 'MMX': True,
47+ 'SSE': True,
48+ 'SSE2': True,
49+ 'SSE3': True,
50+ 'SSE41': True,
51+ 'SSE42': True,
52+ 'AVX': True,
53+ 'AVX2': True,
54+ 'AVX512F': False,
55+ 'NEON': False,
56+ 'ARMSIMD': False,
57+ 'LSX': False,
58+ 'LASX': False
59+ }
60+
61+ .. note:: The values of ``LSX`` and ``LASX`` will be always False if
62+ SDL version < 2.24.0.
63+
64+ .. versionadded:: 2.3.1
65+
66+ .. versionchanged:: 2.4.0 removed ``RDTSC`` key,
67+ as it has been removed in pre-release SDL3
68+ """
69+
70+ def get_total_ram () -> int :
71+ """Get the amount of RAM configured in the system.
72+
73+ Returns the amount of RAM configured in the system in MiB.
74+
75+ .. versionadded:: 2.3.1
76+ """
77+
78+ def get_pref_path (org : str , app : str ) -> str :
79+ """Get a writeable folder for your app.
80+
81+ When distributing apps, it's helpful to have a way to get a writeable path,
82+ because it's what apps are expected to do, and because sometimes the local
83+ space around the app isn't writeable to the app.
84+
85+ This function returns a platform specific path for your app to store
86+ savegames, settings, and the like. This path is unique per user and
87+ per app name.
88+
89+ It takes two strings, ``org`` and ``app``, referring to the "organization"
90+ and "application name." For example, the organization could be "Valve,"
91+ and the application name could be "Half Life 2." It then will figure out the
92+ preferred path, **creating the folders referenced by the path if necessary**,
93+ and return a string containing the absolute path.
94+
95+ For example::
96+
97+ On Windows, it would resemble
98+ C:\\ Users\\ bob\\ AppData\\ Roaming\\ My Company\\ My Program Name\\
99+
100+ On macOS, it would resemble
101+ /Users/bob/Library/Application Support/My Company/My Program Name/
102+
103+ And on Linux it would resemble
104+ /home/bob/.local/share/My Company/My Program Name/
105+
106+ .. note::
107+ Since the organization and app names can potentially be used as
108+ a folder name, it is highly encouraged to avoid punctuation.
109+ Instead stick to letters, numbers, and spaces.
110+
111+ .. note::
112+ The ``appdirs`` library has similar functionality for this use case,
113+ but has more "folder types" to choose from.
114+
115+ .. versionadded:: 2.2.0
116+ """
117+
118+ def get_pref_locales () -> list [_Locale ]:
119+ """Get preferred locales set on the system.
120+
121+ Returns a list of "locale" dicts, sorted in descending order of preference
122+ set on the host OS (the most preferred locale is the first element). May
123+ also be an empty list if pygame could not find this information.
124+
125+ Each "locale" dict contains the language code which can be accessed by the
126+ key ``"language"``. This language code is an ISO-639 language specifier
127+ (such as "en" for English, "de" for German, etc).
128+ A "locale" dict may also optionally contain a ``"country"`` field, whose
129+ value is an ISO-3166 country code (such as "US" for the United States,
130+ "CA" for Canada, etc). If this field is not set or undetermined, it is
131+ ``None``.
132+ A "locale" dict which looks like ``{'language': 'en', 'country': 'US'}``
133+ indicates the user prefers American English, while
134+ ``{'language': 'en', 'country': None}`` indicates that the user prefers
135+ English, generically.
136+
137+ This might be a bit of an expensive call because it has to query the OS. So
138+ this function must not be called in a game loop, instead it's best to ask
139+ for this once and save the results. However, this list can change when the
140+ user changes a system preference outside of your program. pygame will send
141+ a ``LOCALECHANGED`` event in this case, if possible, and you can call this
142+ function again to get an updated copy of preferred locales.
143+
144+ .. versionadded:: 2.2.0
145+ """
146+
147+ def get_power_state () -> Optional [PowerState ]:
148+ """Get the current power supply state.
149+
150+ **Experimental:** feature available for testing and feedback.
151+ We don't anticipate it changing, but it might if something important
152+ is brought up. `Please leave get_power_state feedback with
153+ authors <https://github.com/pygame-community/pygame-ce/pull/2257>`_
154+
155+ Returns a ``PowerState`` object representing the power supply state.
156+
157+ Returns ``None`` if the power state is unknown.
158+
159+ The PowerState object has several attributes:
160+
161+ .. code-block:: text
162+
163+ battery_percent:
164+ An integer between 0 and 100, representing the percentage of
165+ battery life left.
166+
167+ battery_seconds:
168+ An integer, representing the seconds of battery life left.
169+ Could be None if the value is unknown.
170+
171+ on_battery:
172+ True if the device is running on the battery (not plugged in).
173+
174+ no_battery:
175+ True if the device has no battery available (plugged in).
176+
177+ charging:
178+ True if the device is charging battery (plugged in).
179+
180+ charged:
181+ True if the battery of the device is fully charged (plugged in).
182+
183+ plugged_in:
184+ True if the device is plugged in.
185+ Equivalent to `not on_battery`.
186+
187+ has_battery:
188+ True if the device has battery.
189+ Equivalent to `on_battery or not no_battery`.
190+
191+
192+ You should never take a battery status as absolute truth. Batteries
193+ (especially failing batteries) are delicate hardware, and the values
194+ reported here are best estimates based on what that hardware reports. It's
195+ not uncommon for older batteries to lose stored power much faster than it
196+ reports, or completely drain when reporting it has 20 percent left, etc.
197+
198+ Battery status can change at any time; if you are concerned with power
199+ state, you should call this function frequently, and perhaps ignore changes
200+ until they seem to be stable for a few seconds.
201+
202+ It's possible a platform can only report battery percentage or time left
203+ but not both.
204+
205+ .. versionadded:: 2.4.0
206+ """
0 commit comments