Skip to content

Commit 59713c5

Browse files
committed
2 parents fb90e90 + e23f869 commit 59713c5

6 files changed

Lines changed: 85 additions & 55 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Linux Undervolt Tool
22

3-
A fairly simple tool built to mimic the basic functionality of ThrottleStop on Windows. Acts as a GUI so users are able to tell what they are doing without fiddling with the terminal.
3+
A fairly simple GTK tool built to mimic the basic functionality of ThrottleStop on Windows. Acts as a GUI so users are able to tell what they are doing without fiddling with the terminal.
44

55
Uses <a href="https://github.com/kitsunyan/intel-undervolt">intel-undervolt</a> to perform the undervolting, therefore it must be installed on the user's system. <a href="https://github.com/kitsunyan/intel-undervolt/blob/master/README.md">The guide to installing it can be found here</a>
66

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ python3 setup.py --command-packages=stdeb.command bdist_deb
66
cp ./deb_dist/*.deb ./builds
77

88
# Delete files created by stdeb for the build
9-
sudo rm -f -r ./deb_dist ./dist ./linux_undervolt_tool.egg-info ./*.tar.gz
9+
rm -f -r ./deb_dist ./dist ./linux_undervolt_tool.egg-info ./*.tar.gz

linux_undervolt/GUI.glade

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
<property name="can-focus">False</property>
9797
<property name="label" translatable="yes">Import Settings</property>
9898
<property name="use-underline">True</property>
99+
<signal name="activate" handler="importConfig" swapped="no"/>
99100
</object>
100101
</child>
101102
<child>
@@ -104,6 +105,7 @@
104105
<property name="can-focus">False</property>
105106
<property name="label" translatable="yes">Export Settings</property>
106107
<property name="use-underline">True</property>
108+
<signal name="activate" handler="exportConfig" swapped="no"/>
107109
</object>
108110
</child>
109111
<child>
@@ -115,6 +117,7 @@
115117
<child>
116118
<object class="GtkCheckMenuItem">
117119
<property name="visible">True</property>
120+
<property name="sensitive">False</property>
118121
<property name="can-focus">False</property>
119122
<property name="tooltip-text" translatable="yes">Currently WIP</property>
120123
<property name="label" translatable="yes">Advanced Options</property>
@@ -146,7 +149,9 @@
146149
<child>
147150
<object class="GtkMenuItem">
148151
<property name="visible">True</property>
152+
<property name="sensitive">False</property>
149153
<property name="can-focus">False</property>
154+
<property name="tooltip-text" translatable="yes">Currently WIP</property>
150155
<property name="label" translatable="yes">CPU Info</property>
151156
<property name="use-underline">True</property>
152157
</object>

linux_undervolt/backend.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def createUdevRule(options: dict) -> None:
4949

5050
# Add environment variables since the service will be run as root
5151
env_dir = os.path.join(tmp_dir, "temp.env")
52+
5253
with open(env_dir, 'w') as env_file:
5354
env_file.write(f'HOME={HOME}\n')
5455

linux_undervolt/config.py

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class Config:
1111

12-
def __init__(self, created=False, options={}):
12+
def __init__(self, configFile=CONFIG_DIRECTORY):
1313
"""
1414
docstring
1515
"""
@@ -19,38 +19,34 @@ def __init__(self, created=False, options={}):
1919
self.undervolt_file = None
2020
self.active_profile = None
2121

22-
if created:
23-
self.parser.read(CONFIG_DIRECTORY)
22+
if os.path.isfile(configFile):
23+
self.parser.read(configFile)
2424
else:
25-
self.createConfig(general_options=options)
25+
self.createConfig()
2626
self.saveChanges()
2727

2828
self.undervolt_file = self.parser['SETTINGS']['undervolt_path']
2929
self.active_profile = self.parser['SETTINGS']['profile']
3030

31-
def createConfig(self, general_options=None) -> None:
31+
def createConfig(self) -> None:
3232
"""
3333
Creates the configuration file for the application. Stores the general settings as well as profile-specific
3434
information.
3535
"""
3636

37-
undervolt_path = general_options.get("undervolt_path", "/etc/intel-undervolt.conf")
38-
battery_switch = general_options.get("bat_switch", 'false')
39-
battery_profile = general_options.get("bat_profile", "")
40-
ac_profile = general_options.get("ac_profile", "")
41-
4237
self.parser['SETTINGS'] = {
4338
'profile': 0,
44-
'undervolt_path': undervolt_path,
45-
'battery_switch': battery_switch,
46-
'battery_profile': battery_profile,
47-
'ac_profile': ac_profile
39+
'undervolt_path': "/etc/intel-undervolt.conf",
40+
'battery_switch': 'false',
41+
'battery_profile': "",
42+
'ac_profile': ""
4843
}
4944

5045
profile_options = ['cpu', 'gpu', 'cpu_cache', 'sys_agent', 'analog_io']
5146

5247
profiles = [{i: 0 for i in profile_options} for j in range(4)]
5348

49+
# Create default undervolt values for each profile in config file
5450
for index, profile in enumerate(profiles):
5551
self.parser[str(index)] = profile
5652

@@ -123,6 +119,11 @@ def changeProfileSettings(self, settings: dict, profile=None) -> None:
123119
# Save & Apply changes #
124120
########################
125121

122+
def exportConfig(self, output):
123+
124+
with open(output, 'w') as export_file:
125+
self.parser.write(export_file)
126+
126127
def saveChanges(self) -> None:
127128
"""
128129
Save the profile settings to the config file.
@@ -209,11 +210,7 @@ def main():
209210
"""
210211

211212
import argparse
212-
import gi
213-
gi.require_version('Notify', '0.7')
214-
from gi.repository import Notify
215213

216-
Notify.init('Linux Undervolt Tool')
217214
parser = argparse.ArgumentParser()
218215
parser.add_argument("-set-profile")
219216

@@ -224,11 +221,6 @@ def main():
224221
temp_config = Config(created=True)
225222
temp_config.changeSettings('profile', new_profile)
226223
temp_config.applyChanges()
227-
228-
Notify.Notification.new(
229-
summary='Profile Changed',
230-
body=f'Profile {new_profile} active'
231-
).show()
232224

233225

234226

linux_undervolt/main.py

Lines changed: 62 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from gi.repository import Notify
77

88
from time import sleep
9+
from datetime import date
10+
911
import os
1012

1113
from . import config
@@ -35,7 +37,7 @@ def __init__(self):
3537
if return_code != gtk.ResponseType.OK:
3638
return
3739
else:
38-
self.config = config.Config(created=True)
40+
self.config = config.Config()
3941

4042
# Create template and add general signals
4143
current_directory = os.path.dirname(os.path.abspath(__file__))
@@ -61,7 +63,7 @@ def __init__(self):
6163
window.connect("delete-event", gtk.main_quit)
6264
window.show()
6365

64-
def firstTimeSetup(self):
66+
def firstTimeSetup(self) -> gtk.ResponseType:
6567
"""
6668
Creates the initial files required for the application to run. This is only called the first time
6769
the application is run.
@@ -70,33 +72,11 @@ def firstTimeSetup(self):
7072
# Check whether intel-undervolt has been installed.
7173

7274
prereqs = config.checkPrerequisites()
73-
if prereqs:
74-
default_undervolt_path = '/etc/intel-undervolt.conf'
75-
76-
if os.path.isfile(default_undervolt_path):
77-
self.config = config.Config()
78-
return gtk.ResponseType.OK
7975

80-
else:
81-
folder_dialog = gtk.FileChooserDialog("Select intel-undervolt Config File", None, gtk.FileChooserAction.OPEN,
82-
(gtk.STOCK_CLOSE, gtk.ResponseType.CLOSE, gtk.STOCK_OPEN, gtk.ResponseType.OK))
83-
84-
filter_conf = gtk.FileFilter()
85-
filter_conf.set_name("Configuration files")
86-
filter_conf.add_pattern("*.conf")
87-
folder_dialog.add_filter(filter_conf)
88-
89-
response = folder_dialog.run()
90-
91-
if response == gtk.ResponseType.OK:
92-
response = folder_dialog.get_filename()
93-
options = {'undervolt_path': response}
94-
self.config = config.Config(options=options)
95-
else:
96-
folder_dialog.destroy()
76+
if prereqs:
77+
self.config = config.Config(configFile=None)
78+
response = gtk.ResponseType.OK
9779

98-
return response
99-
10080
else:
10181
dialog = gtk.MessageDialog(
10282
message_type=gtk.MessageType.ERROR,
@@ -105,10 +85,10 @@ def firstTimeSetup(self):
10585
required programs (intel-undervolt) properly installed."""
10686
)
10787

108-
dialog.run()
88+
response = dialog.run()
10989
dialog.destroy()
11090

111-
return dialog
91+
return response
11292

11393
##############
11494
# UI Changes #
@@ -272,9 +252,61 @@ def setPowerProfile(self, _):
272252
text="An error occurred."
273253
)
274254

275-
dialog.run()
255+
dialog.run()
256+
dialog.destroy()
257+
258+
def importConfig(self, _):
259+
260+
dialog = gtk.FileChooserDialog(
261+
title="Choose import file",
262+
action=gtk.FileChooserAction.OPEN
263+
)
264+
265+
dialog.add_buttons(
266+
gtk.STOCK_CANCEL, gtk.ResponseType.CANCEL,
267+
gtk.STOCK_OPEN, gtk.ResponseType.OK
268+
)
269+
270+
file_filter = gtk.FileFilter()
271+
file_filter.set_name("Config File")
272+
file_filter.add_pattern("*.conf")
273+
274+
dialog.add_filter(file_filter)
275+
276+
response = dialog.run()
277+
278+
if response == gtk.ResponseType.OK:
279+
filename = dialog.get_filename()
280+
self.config = config.Config(filename)
281+
self.config.saveChanges()
282+
283+
dialog.destroy()
284+
285+
def exportConfig(self, _):
286+
287+
dialog = gtk.FileChooserDialog(
288+
title="Select export file",
289+
action=gtk.FileChooserAction.SAVE
290+
)
291+
292+
# Set default export file name
293+
file_name = date.today().isoformat()
294+
file_name = f"{file_name}_linux-undervolt.conf"
295+
dialog.set_current_name(file_name)
296+
297+
dialog.add_buttons(
298+
gtk.STOCK_SAVE, gtk.ResponseType.OK,
299+
gtk.STOCK_CANCEL, gtk.ResponseType.CANCEL
300+
)
301+
302+
response = dialog.run()
303+
304+
if response == gtk.ResponseType.OK:
305+
self.config.exportConfig(dialog.get_filename())
306+
276307
dialog.destroy()
277308

309+
278310
def saveProfile(self, _):
279311
"""
280312
Save scale values to the profile in the config

0 commit comments

Comments
 (0)