2022-09-16 10:07:57 -06:00
|
|
|
'''
|
|
|
|
Module of Windows API helper for plyer.battery.
|
|
|
|
'''
|
|
|
|
|
|
|
|
__all__ = ('battery_status')
|
|
|
|
|
|
|
|
|
|
|
|
import ctypes
|
2024-06-02 10:31:58 -06:00
|
|
|
from sbapp.plyer.platforms.win.libs import win_api_defs
|
2022-09-16 10:07:57 -06:00
|
|
|
|
|
|
|
|
|
|
|
def battery_status():
|
|
|
|
'''
|
|
|
|
Implementation of Windows system power status API for plyer.battery.
|
|
|
|
'''
|
|
|
|
|
|
|
|
status = win_api_defs.SYSTEM_POWER_STATUS()
|
|
|
|
if not win_api_defs.GetSystemPowerStatus(ctypes.pointer(status)):
|
|
|
|
raise Exception('Could not get system power status.')
|
|
|
|
|
|
|
|
return dict(
|
|
|
|
(field, getattr(status, field))
|
|
|
|
for field, _ in status._fields_
|
|
|
|
)
|