forked from d4nj1/TLPUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatui.py
83 lines (61 loc) · 2.55 KB
/
statui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import sys
from gi.repository import Gtk
from shutil import which
from subprocess import check_output
from . import language
def get_graphical_sudo():
sudo = which("pkexec")
if sudo == None:
sudo = which("gksu")
if sudo == None:
sudo = which("gksudo")
if sudo == None:
sudo = which("kdesu")
if sudo == None:
sudo = which("kdesudo")
return sudo
def fetch_simple_stats(self, textbuffer):
tlpstat_cmd = which("tlp-stat")
if tlpstat_cmd == None:
textbuffer.set_text(language.ST_('tlp-stat executable not found.'))
return
tlpstat = check_output(["tlp-stat", "-g", "-r", "-t", "-c", "-s", "-u"]).decode(sys.stdout.encoding)
textbuffer.set_text(tlpstat)
def fetch_complete_stats(self, textbuffer):
sudo_cmd = get_graphical_sudo()
tlpstat_cmd = which("tlp-stat")
if sudo_cmd == None:
textbuffer.set_text(language.ST_('Install pkexec, gksu, gksudo, kdesu or kdesudo first.'))
return
if tlpstat_cmd == None:
textbuffer.set_text(language.ST_('tlp-stat executable not found.'))
return
tlpstat = check_output([sudo_cmd, "tlp-stat"]).decode(sys.stdout.encoding)
textbuffer.set_text(tlpstat)
def create_stat_box() -> Gtk.Box:
scrolledwindow = Gtk.ScrolledWindow()
scrolledwindow.set_hexpand(True)
scrolledwindow.set_vexpand(True)
textbuffer = Gtk.TextBuffer()
textbuffer.set_text(language.ST_('Click fetch button to receive results'))
textview = Gtk.TextView()
textview.set_buffer(textbuffer)
textview.set_editable(False)
scrolledwindow.add(textview)
emptylabel = Gtk.Label()
fetchsimplebutton = Gtk.Button(label=language.ST_(' Simple'), image=Gtk.Image(stock=Gtk.STOCK_INFO))
fetchsimplebutton.connect('clicked', fetch_simple_stats, textbuffer)
fetchcompletebutton = Gtk.Button(label=language.ST_(' Complete'), image=Gtk.Image(stock=Gtk.STOCK_INDEX))
fetchcompletebutton.connect('clicked', fetch_complete_stats, textbuffer)
buttonbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=12)
buttonbox.pack_start(emptylabel, True, True, 0)
buttonbox.pack_start(fetchsimplebutton, False, False, 0)
buttonbox.pack_start(fetchcompletebutton, False, False, 0)
statbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=12)
statbox.set_margin_top(18)
statbox.set_margin_bottom(18)
statbox.set_margin_left(18)
statbox.set_margin_right(18)
statbox.pack_start(buttonbox, False, False, 0)
statbox.pack_start(scrolledwindow, True, True, 0)
return statbox