| 1 |
# Copyright 2017 Tom Rothamel <[email protected]> |
| 2 |
# |
| 3 |
# This software is provided 'as-is', without any express or implied |
| 4 |
# warranty. In no event will the authors be held liable for any damages |
| 5 |
# arising from the use of this software. |
| 6 |
# |
| 7 |
# Permission is granted to anyone to use this software for any purpose, |
| 8 |
# including commercial applications, and to alter it and redistribute it |
| 9 |
# freely, subject to the following restrictions: |
| 10 |
# |
| 11 |
# 1. The origin of this software must not be misrepresented; you must not |
| 12 |
# claim that you wrote the original software. If you use this software |
| 13 |
# in a product, an acknowledgment in the product documentation would be |
| 14 |
# appreciated but is not required. |
| 15 |
# 2. Altered source versions must be plainly marked as such, and must not be |
| 16 |
# misrepresented as being the original software. |
| 17 |
# 3. This notice may not be removed or altered from any source distribution. |
| 18 |
|
| 19 |
from pygame_sdl2.locals import POWERSTATE_UNKNOWN, POWERSTATE_ON_BATTERY, POWERSTATE_NO_BATTERY, POWERSTATE_CHARGING, POWERSTATE_CHARGED |
| 20 |
|
| 21 |
from sdl2 cimport * |
| 22 |
|
| 23 |
powerstate_to_name = { |
| 24 |
POWERSTATE_UNKNOWN : "POWERSTATE_UNKNOWN", |
| 25 |
POWERSTATE_ON_BATTERY : "POWERSTATE_ON_BATTERY", |
| 26 |
POWERSTATE_NO_BATTERY : "POWERSTATE_NO_BATTERY", |
| 27 |
POWERSTATE_CHARGING : "POWERSTATE_CHARGING", |
| 28 |
POWERSTATE_CHARGED : "POWERSTATE_CHARGED", |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
class PowerInfo(object): |
| 33 |
def __repr__(self): |
| 34 |
return "<PowerInfo state={} seconds={} percent={}>".format( |
| 35 |
powerstate_to_name.get(self.state, "INVALID"), |
| 36 |
self.seconds, |
| 37 |
self.percent) |
| 38 |
|
| 39 |
def get_power_info(): |
| 40 |
|
| 41 |
cdef int seconds |
| 42 |
cdef int percent |
| 43 |
|
| 44 |
state = SDL_GetPowerInfo(&seconds, &percent) |
| 45 |
|
| 46 |
rv = PowerInfo() |
| 47 |
rv.state = state |
| 48 |
rv.seconds = seconds |
| 49 |
rv.percent = percent |
| 50 |
|
| 51 |
return rv |
| 52 |
|
| 53 |
|