forked from d4nj1/TLPUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatui.py
63 lines (46 loc) · 1.76 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
import sys
from gi.repository import Gtk
from shutil import which
from subprocess import check_output
def get_graphical_sudo():
sudo = which("gksudo")
if sudo == None:
sudo = which("kdesudo")
if sudo == None:
sudo = which("gksu")
return sudo
def fetch_tlp_stat(self, textbuffer):
sudo_cmd = get_graphical_sudo()
tlpstat_cmd = which("tlp-stat")
if sudo_cmd == None:
textbuffer.set_text('Install gksudo, kdesudo or gksu first.')
return
if tlpstat_cmd == None:
textbuffer.set_text('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('Click fetch button to receive results')
textview = Gtk.TextView()
textview.set_buffer(textbuffer)
textview.set_editable(False)
scrolledwindow.add(textview)
emptylabel = Gtk.Label()
fetchbutton = Gtk.Button(label=' Fetch stats', image=Gtk.Image(stock=Gtk.STOCK_CONVERT))
fetchbutton.connect('clicked', fetch_tlp_stat, textbuffer)
buttonbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
buttonbox.pack_start(emptylabel, True, True, 0)
buttonbox.pack_start(fetchbutton, 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