|
| 1 | +# turing-smart-screen-python - a Python system monitor and library for USB-C displays like Turing Smart Screen or XuanFang |
| 2 | +# https://github.com/mathoudebine/turing-smart-screen-python/ |
| 3 | + |
| 4 | +# Copyright (C) 2021-2023 Matthieu Houdebine (mathoudebine) |
| 5 | +# |
| 6 | +# This program is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU General Public License as published by |
| 8 | +# the Free Software Foundation, either version 3 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# This program is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU General Public License |
| 17 | +# along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +# This file allows to add custom data source as sensors and display them in System Monitor themes |
| 20 | +# There is no limitation on how much custom data source classes can be added to this file |
| 21 | +# See CustomDataExample theme for the theme implementation part |
| 22 | + |
| 23 | +import platform |
| 24 | +from abc import ABC, abstractmethod |
| 25 | + |
| 26 | + |
| 27 | +# Custom data classes must be implemented in this file, inherit the CustomDataSource and implement its 2 methods |
| 28 | +class CustomDataSource(ABC): |
| 29 | + @abstractmethod |
| 30 | + def as_numeric(self) -> float: |
| 31 | + # Numeric value will be used for graph and radial progress bars |
| 32 | + # If there is no numeric value, keep this function empty |
| 33 | + pass |
| 34 | + |
| 35 | + @abstractmethod |
| 36 | + def as_string(self) -> str: |
| 37 | + # Text value will be used for text display and radial progress bar inner text |
| 38 | + # Numeric value can be formatted here to be displayed as expected |
| 39 | + # It is also possible to return a text unrelated to the numeric value |
| 40 | + # If this function is empty, the numeric value will be used as string without formatting |
| 41 | + pass |
| 42 | + |
| 43 | + |
| 44 | +# Example for a custom data class that has numeric and text values |
| 45 | +class ExampleCustomNumericData(CustomDataSource): |
| 46 | + def as_numeric(self) -> float: |
| 47 | + # Numeric value will be used for graph and radial progress bars |
| 48 | + # Here a Python function from another module can be called to get data |
| 49 | + # Example: return my_module.get_rgb_led_brightness() / return audio.system_volume() ... |
| 50 | + return 75.845 |
| 51 | + |
| 52 | + def as_string(self) -> str: |
| 53 | + # Text value will be used for text display and radial progress bar inner text. |
| 54 | + # Numeric value can be formatted here to be displayed as expected |
| 55 | + # It is also possible to return a text unrelated to the numeric value |
| 56 | + # If this function is empty, the numeric value will be used as string without formatting |
| 57 | + # Example here: format numeric value: add unit as a suffix, and keep 1 digit decimal precision |
| 58 | + return f'{self.as_numeric(): .1f}%' |
| 59 | + |
| 60 | + |
| 61 | +# Example for a custom data class that only has text values |
| 62 | +class ExampleCustomTextOnlyData(CustomDataSource): |
| 63 | + def as_numeric(self) -> float: |
| 64 | + # If there is no numeric value, keep this function empty |
| 65 | + pass |
| 66 | + |
| 67 | + def as_string(self) -> str: |
| 68 | + # If a custom data class only has text values, it won't be possible to display graph or radial bars |
| 69 | + return "Python version: " + platform.python_version() |
0 commit comments