1
+ import gi
2
+
3
+ gi .require_version ("Gtk" , "3.0" )
4
+
5
+ from gi .repository import Gtk
6
+ from gi .repository import GLib
7
+
8
+ import sys
9
+ import os
10
+
11
+ sys .path .append ("../../" )
12
+ from auto_cpufreq .core import sysinfo , distro_info , getoutput , set_override
13
+
14
+ from io import StringIO
15
+
16
+ HBOX_PADDING = 20
17
+
18
+ class RadioButtonView (Gtk .Box ):
19
+ def __init__ (self ):
20
+ super ().__init__ ()
21
+ self .set_valign (Gtk .Align .START )
22
+
23
+ default = Gtk .RadioButton .new_with_label_from_widget (None , "Default" )
24
+ default .connect ("toggled" , self .on_button_toggled , "reset" )
25
+ powersave = Gtk .RadioButton .new_with_label_from_widget (default , "Powersave" )
26
+ powersave .connect ("toggled" , self .on_button_toggled , "powersave" )
27
+ performance = Gtk .RadioButton .new_with_label_from_widget (default , "Performance" )
28
+ performance .connect ("toggled" , self .on_button_toggled , "performance" )
29
+
30
+ self .pack_start (default , False , False , 0 )
31
+ self .pack_start (powersave , False , False , 0 )
32
+ self .pack_start (performance , False , False , 0 )
33
+
34
+ def on_button_toggled (self , button , override ):
35
+ if button .get_active ():
36
+ set_override (override )
37
+
38
+
39
+ class CurrentGovernorBox (Gtk .Box ):
40
+ def __init__ (self ):
41
+ super ().__init__ (spacing = 60 )
42
+
43
+ self .static = Gtk .Label (label = "Current Governor" )
44
+ self .governor = Gtk .Label (label = getoutput ("cpufreqctl.auto-cpufreq --governor" ).strip ().split (" " )[0 ])
45
+
46
+ self .pack_start (self .static , False , False , 0 )
47
+ self .pack_start (self .governor , False , False , 0 )
48
+
49
+ def refresh (self ):
50
+ self .governor .set_label (getoutput ("cpufreqctl.auto-cpufreq --governor" ).strip ().split (" " )[0 ])
51
+
52
+ class SystemStatsLabel (Gtk .Label ):
53
+ def __init__ (self ):
54
+ super ().__init__ ()
55
+
56
+ self .update ()
57
+
58
+ def update (self ):
59
+ # change stdout and store label text to file-like object
60
+ old_stdout = sys .stdout
61
+ text = StringIO ()
62
+ sys .stdout = text
63
+ sysinfo ()
64
+ distro_info ()
65
+ self .set_label (text .getvalue ())
66
+ sys .stdout = old_stdout
67
+
68
+ def refresh (self ):
69
+ self .update ()
70
+
71
+ class MyWindow (Gtk .Window ):
72
+ def __init__ (self ):
73
+ super ().__init__ (title = "auto-cpufreq" )
74
+ self .set_default_size (640 , 480 )
75
+ self .set_border_width (10 )
76
+
77
+ settings = Gtk .Settings .get_default ()
78
+ # Theme
79
+ theme = os .environ .get ("GTK_THEME" )
80
+ if theme is not None :
81
+ settings .set_property ("gtk-theme-name" , theme )
82
+
83
+ # main HBOX
84
+ self .hbox = Gtk .Box (orientation = Gtk .Orientation .HORIZONTAL , spacing = HBOX_PADDING )
85
+ self .add (self .hbox )
86
+
87
+ self .systemstats = SystemStatsLabel ()
88
+ self .hbox .pack_start (self .systemstats , False , False , 0 )
89
+
90
+ self .vbox = Gtk .Box (orientation = Gtk .Orientation .VERTICAL , spacing = 20 )
91
+ self .currentgovernor = CurrentGovernorBox ()
92
+ self .vbox .pack_start (self .currentgovernor , False , False , 0 )
93
+ self .vbox .pack_start (RadioButtonView (), False , False , 0 )
94
+
95
+ self .hbox .pack_start (self .vbox , False , False , 0 )
96
+
97
+ GLib .timeout_add_seconds (2 , self .refresh )
98
+
99
+ def refresh (self ):
100
+ self .systemstats .refresh ()
101
+ self .currentgovernor .refresh ()
102
+
103
+ return True
104
+
105
+
106
+
107
+ win = MyWindow ()
108
+ win .connect ("destroy" , Gtk .main_quit )
109
+ win .show_all ()
110
+ Gtk .main ()
0 commit comments