refactor: make psutil optional
This commit is contained in:
1 parent
7ea3122908
commit
ecc32647ed
1 file changed
+9
-1
@@ -1,6 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import logging
|
||||
import psutil
|
||||
import gi
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
@@ -10,6 +9,13 @@ from datetime import datetime
|
||||
from math import log
|
||||
from ks_includes.screen_panel import ScreenPanel
|
||||
|
||||
try:
|
||||
import psutil
|
||||
psutil_available = True
|
||||
except ImportError:
|
||||
psutil_available = False
|
||||
logging.debug("psutil is not installed. Unable to do battery check.")
|
||||
|
||||
|
||||
class BasePanel(ScreenPanel):
|
||||
def __init__(self, screen, title=None):
|
||||
@@ -396,6 +402,8 @@ class BasePanel(ScreenPanel):
|
||||
return self.battery_icons['unknown']
|
||||
|
||||
def battery_percentage(self):
|
||||
if not psutil_available:
|
||||
return False
|
||||
battery = psutil.sensors_battery()
|
||||
if battery and battery.percent:
|
||||
self.labels['battery_icon'].set_from_pixbuf(
|
||||
|
||||
Reference in new issue
Block a user