Skip to content

Commit

Permalink
GUI: finishing touches and bug fixes (#554)
Browse files Browse the repository at this point in the history
* Squashed commit of the following:

commit ec7e087
Merge: 32b6e63 9912f9d
Author: shadeyg56 <[email protected]>
Date:   Mon Feb 13 14:11:21 2023 -0600

    Merge branch 'AdnanHodzic:master' into gui

commit 32b6e63
Author: shadeyg56 <[email protected]>
Date:   Mon Feb 13 14:10:34 2023 -0600

    increase MenuButton size

commit 12a2cda
Author: shadeyg56 <[email protected]>
Date:   Sun Feb 12 23:35:33 2023 -0600

    set app icon

commit d170d07
Author: shadeyg56 <[email protected]>
Date:   Sun Feb 12 23:35:15 2023 -0600

    remove unused pixbuf

commit 993333f
Author: shadeyg56 <[email protected]>
Date:   Sun Feb 12 22:43:56 2023 -0600

    fix MenuButton icon

commit d1b8bd7
Author: shadeyg56 <[email protected]>
Date:   Sun Feb 12 17:19:32 2023 -0600

    add icon

commit 13f43fa
Author: shadeyg56 <[email protected]>
Date:   Sun Feb 12 17:19:10 2023 -0600

    add pkexec policy and change wrapper for gui

commit 4ddbb9c
Author: shadeyg56 <[email protected]>
Date:   Sun Feb 12 14:09:35 2023 -0600

    add icon to destop entry and about dialog

commit 9912f9d
Author: Siddharth Kumar Jha <[email protected]>
Date:   Sun Feb 12 12:55:14 2023 +0530

    Update Readme for issue of auto-cpufreq not autostarting on AUR  (#485)

    * Updated Readme for issue auto-cpufreq not autostarting

    Added solution to issue #463

    * Fixed minor errors

    * Fixed auto-cpufreq.serivce Typo

    * Reprashed text as per suggestion

commit 4379024
Author: shadeyg56 <[email protected]>
Date:   Tue Feb 7 19:06:59 2023 -0600

    add removal of gui and desktop entry

commit 4269370
Author: shadeyg56 <[email protected]>
Date:   Mon Feb 6 23:28:44 2023 -0600

    CPU stats refresh and style stuff

commit 7149db7
Author: shadeyg56 <[email protected]>
Date:   Mon Feb 6 23:10:29 2023 -0600

    daemon detection, daemon install/removal, and layout stuff

commit f7e03c9
Author: shadeyg56 <[email protected]>
Date:   Sun Feb 5 19:26:42 2023 -0600

    improve AboutDialog

    Please enter the commit message for your changes. Lines starting

commit cb8cfe7
Author: shadeyg56 <[email protected]>
Date:   Sun Feb 5 18:28:19 2023 -0600

    add dropdown menu and (not completed) about dialog

commit ade1fed
Author: shadeyg56 <[email protected]>
Date:   Sun Feb 5 15:57:17 2023 -0600

    actually fix css

commit 67c8c97
Author: shadeyg56 <[email protected]>
Date:   Sun Feb 5 15:54:47 2023 -0600

    fix css

commit c65eac3
Author: Adnan Hodzic <[email protected]>
Date:   Sun Feb 5 09:29:19 2023 +0100

    Update readme, install psutil lib for power_helper

commit bd3feae
Author: shadeyg56 <[email protected]>
Date:   Sun Feb 5 00:42:52 2023 -0600

    add desktop entry for gui

commit 5426a6a
Author: shadeyg56 <[email protected]>
Date:   Sun Feb 5 00:33:08 2023 -0600

    add gui to install file, update required packages, and create wrapper script

commit 84124df
Author: shadeyg56 <[email protected]>
Date:   Sat Feb 4 23:28:24 2023 -0600

    create system tray

commit 7b0d46d
Author: shadeyg56 <[email protected]>
Date:   Sat Feb 4 23:28:01 2023 -0600

    small changes to layout

commit cd51ea3
Author: shadeyg56 <[email protected]>
Date:   Sat Feb 4 00:44:08 2023 -0600

    css styling support

commit 136b449
Author: shadeyg56 <[email protected]>
Date:   Sat Feb 4 00:14:52 2023 -0600

    several improvements

commit f9f7170
Merge: 242a8d0 8f343df
Author: shadeyg56 <[email protected]>
Date:   Fri Feb 3 22:44:01 2023 -0600

    Merge branch 'AdnanHodzic:master' into gui

commit 8f343df
Merge: dadfae0 b38919f
Author: shadeyg56 <[email protected]>
Date:   Fri Feb 3 14:54:11 2023 -0600

    Merge pull request #481 from shadeyg56/master

    Fix uncaught error in checking for snap

commit b38919f
Author: shadeyg56 <[email protected]>
Date:   Fri Feb 3 14:48:01 2023 -0600

    fix uncaught error in checking for snap

commit 242a8d0
Merge: f50b982 dadfae0
Author: shadeyg56 <[email protected]>
Date:   Fri Feb 3 14:19:01 2023 -0600

    Merge branch 'AdnanHodzic:master' into gui

commit dadfae0
Author: Adnan Hodzic <[email protected]>
Date:   Fri Feb 3 20:02:03 2023 +0100

    Update README with  new config options

commit 471611d
Author: Adnan Hodzic <[email protected]>
Date:   Fri Feb 3 18:44:33 2023 +0100

    Remove GNOME Power Profiles Daemon performance install

commit f574257
Author: Adnan Hodzic <[email protected]>
Date:   Fri Feb 3 18:32:04 2023 +0100

    Remove install_performance flag

commit 04b8783
Author: Adnan Hodzic <[email protected]>
Date:   Fri Feb 3 17:52:20 2023 +0100

    Snap tag 2.0-beta + governor_override improvements

commit fe21ddf
Author: Adnan Hodzic <[email protected]>
Date:   Fri Feb 3 17:28:12 2023 +0100

    Working governor override on Snap package

commit f50b982
Merge: a98225e 69ef913
Author: shadeyg56 <[email protected]>
Date:   Thu Feb 2 18:19:10 2023 -0600

    Merge branch 'AdnanHodzic:master' into gui

commit a98225e
Author: shadeyg56 <[email protected]>
Date:   Thu Feb 2 18:18:43 2023 -0600

    Revert "basic GUI"

    This reverts commit d2610c9.

commit 9606472
Author: shadeyg56 <[email protected]>
Date:   Thu Feb 2 18:13:41 2023 -0600

    basic gui

commit d2610c9
Author: shadeyg56 <[email protected]>
Date:   Thu Feb 2 17:47:55 2023 -0600

    basic GUI

commit bdbe120
Author: shadeyg56 <[email protected]>
Date:   Thu Feb 2 15:21:42 2023 -0600

    rename folder

commit 31095c4
Author: shadeyg56 <[email protected]>
Date:   Wed Jan 25 23:39:52 2023 -0600

    add tray

* Squashed commit of the following:

commit e2eaffc
Author: shadeyg56 <[email protected]>
Date:   Mon Feb 20 23:08:57 2023 -0600

    move text to be inline with menu

commit e1dae9d
Author: shadeyg56 <[email protected]>
Date:   Sun Feb 19 17:50:26 2023 -0600

    move distro info to top of system stats box

commit 959405b
Author: shadeyg56 <[email protected]>
Date:   Sun Feb 19 17:49:15 2023 -0600

    fix app name on GNOME

commit 346093d
Author: shadeyg56 <[email protected]>
Date:   Sun Feb 19 17:01:03 2023 -0600

    fix snap dependencies

commit ec7e087
Merge: 32b6e63 9912f9d
Author: shadeyg56 <[email protected]>
Date:   Mon Feb 13 14:11:21 2023 -0600

    Merge branch 'AdnanHodzic:master' into gui

commit 32b6e63
Author: shadeyg56 <[email protected]>
Date:   Mon Feb 13 14:10:34 2023 -0600

    increase MenuButton size

commit 12a2cda
Author: shadeyg56 <[email protected]>
Date:   Sun Feb 12 23:35:33 2023 -0600

    set app icon

commit d170d07
Author: shadeyg56 <[email protected]>
Date:   Sun Feb 12 23:35:15 2023 -0600

    remove unused pixbuf

commit 993333f
Author: shadeyg56 <[email protected]>
Date:   Sun Feb 12 22:43:56 2023 -0600

    fix MenuButton icon

commit d1b8bd7
Author: shadeyg56 <[email protected]>
Date:   Sun Feb 12 17:19:32 2023 -0600

    add icon

commit 13f43fa
Author: shadeyg56 <[email protected]>
Date:   Sun Feb 12 17:19:10 2023 -0600

    add pkexec policy and change wrapper for gui

commit 4ddbb9c
Author: shadeyg56 <[email protected]>
Date:   Sun Feb 12 14:09:35 2023 -0600

    add icon to destop entry and about dialog

commit 4379024
Author: shadeyg56 <[email protected]>
Date:   Tue Feb 7 19:06:59 2023 -0600

    add removal of gui and desktop entry

commit 4269370
Author: shadeyg56 <[email protected]>
Date:   Mon Feb 6 23:28:44 2023 -0600

    CPU stats refresh and style stuff

commit 7149db7
Author: shadeyg56 <[email protected]>
Date:   Mon Feb 6 23:10:29 2023 -0600

    daemon detection, daemon install/removal, and layout stuff

commit f7e03c9
Author: shadeyg56 <[email protected]>
Date:   Sun Feb 5 19:26:42 2023 -0600

    improve AboutDialog

    Please enter the commit message for your changes. Lines starting

commit cb8cfe7
Author: shadeyg56 <[email protected]>
Date:   Sun Feb 5 18:28:19 2023 -0600

    add dropdown menu and (not completed) about dialog

commit ade1fed
Author: shadeyg56 <[email protected]>
Date:   Sun Feb 5 15:57:17 2023 -0600

    actually fix css

commit 67c8c97
Author: shadeyg56 <[email protected]>
Date:   Sun Feb 5 15:54:47 2023 -0600

    fix css

commit bd3feae
Author: shadeyg56 <[email protected]>
Date:   Sun Feb 5 00:42:52 2023 -0600

    add desktop entry for gui

commit 5426a6a
Author: shadeyg56 <[email protected]>
Date:   Sun Feb 5 00:33:08 2023 -0600

    add gui to install file, update required packages, and create wrapper script

commit 84124df
Author: shadeyg56 <[email protected]>
Date:   Sat Feb 4 23:28:24 2023 -0600

    create system tray

commit 7b0d46d
Author: shadeyg56 <[email protected]>
Date:   Sat Feb 4 23:28:01 2023 -0600

    small changes to layout

commit cd51ea3
Author: shadeyg56 <[email protected]>
Date:   Sat Feb 4 00:44:08 2023 -0600

    css styling support

commit 136b449
Author: shadeyg56 <[email protected]>
Date:   Sat Feb 4 00:14:52 2023 -0600

    several improvements

commit f9f7170
Merge: 242a8d0 8f343df
Author: shadeyg56 <[email protected]>
Date:   Fri Feb 3 22:44:01 2023 -0600

    Merge branch 'AdnanHodzic:master' into gui

commit 242a8d0
Merge: f50b982 dadfae0
Author: shadeyg56 <[email protected]>
Date:   Fri Feb 3 14:19:01 2023 -0600

    Merge branch 'AdnanHodzic:master' into gui

commit f50b982
Merge: a98225e 69ef913
Author: shadeyg56 <[email protected]>
Date:   Thu Feb 2 18:19:10 2023 -0600

    Merge branch 'AdnanHodzic:master' into gui

commit a98225e
Author: shadeyg56 <[email protected]>
Date:   Thu Feb 2 18:18:43 2023 -0600

    Revert "basic GUI"

    This reverts commit d2610c9.

commit 9606472
Author: shadeyg56 <[email protected]>
Date:   Thu Feb 2 18:13:41 2023 -0600

    basic gui

commit d2610c9
Author: shadeyg56 <[email protected]>
Date:   Thu Feb 2 17:47:55 2023 -0600

    basic GUI

commit bdbe120
Author: shadeyg56 <[email protected]>
Date:   Thu Feb 2 15:21:42 2023 -0600

    rename folder

commit 31095c4
Author: shadeyg56 <[email protected]>
Date:   Wed Jan 25 23:39:52 2023 -0600

    add tray

* fix undefined var

* app no longer needs root to start, only asks when needed

* fix wmclass

* create file in /bin for gui

* fix bug with radio buttons and pkexec

* snap: update snap to package GTK gui

* update setup.py

* requirements.txt: fix conflict

* Merge master into dev

* Add Snap package icon

* gui: fix pkexec on launch

* Deploy auto-cpufreq-gtk as binary using dump

* auto-cpufreq + gtk as part of parts

* snap: fix packaging for gtk app

* add additional error catching to GUI

* GUI: add threading

* GUI: switch to ThreadPool for daemon stuff

* disable debug catch

* remove useless comments

* GUI: add message for Snap users

---------

Co-authored-by: Adnan Hodzic <[email protected]>
  • Loading branch information
shadeyg56 and AdnanHodzic authored Sep 16, 2023
1 parent 3e2b779 commit 257d6e9
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 18 deletions.
41 changes: 31 additions & 10 deletions auto_cpufreq/gui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@

import os
import sys
from threading import Thread

sys.path.append("../")
from auto_cpufreq.core import is_running
from auto_cpufreq.gui.objects import RadioButtonView, SystemStatsLabel, CPUFreqStatsLabel, CurrentGovernorBox, DropDownMenu, DaemonNotRunningView

CSS_FILE = "/usr/local/share/auto-cpufreq/scripts/style.css"
if os.getenv("PKG_MARKER") == "SNAP":
ICON_FILE = "/snap/auto-cpufreq/current/icon.png"
CSS_FILE = "/snap/auto-cpufreq/current/style.css"
else:
ICON_FILE = "/usr/local/share/auto-cpufreq/images/icon.png"
CSS_FILE = "/usr/local/share/auto-cpufreq/scripts/style.css"

HBOX_PADDING = 20

Expand All @@ -22,15 +28,11 @@ def __init__(self):
self.set_border_width(10)
self.set_resizable(False)
self.load_css()
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(filename="/usr/local/share/auto-cpufreq/images/icon.png", width=500, height=500, preserve_aspect_ratio=True)
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(filename=ICON_FILE, width=500, height=500, preserve_aspect_ratio=True)
self.set_icon(pixbuf)
self.build()

def main(self):
# self.vbox_top = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
# self.vbox_top.set_valign(Gtk.Align.CENTER)
# self.vbox_top.set_halign(Gtk.Align.CENTER)
#self.add(self.vbox_top)

# Main HBOX
self.hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=HBOX_PADDING)
Expand All @@ -54,14 +56,30 @@ def main(self):
self.hbox.pack_start(self.vbox_right, False, False, 0)


GLib.timeout_add_seconds(5, self.refresh)
GLib.timeout_add_seconds(5, self.refresh_in_thread)

def snap(self):
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, halign=Gtk.Align.CENTER, valign=Gtk.Align.CENTER)

label = Gtk.Label(label="GUI not available due to Snap package confinement limitations.\nPlease install auto-cpufreq using auto-cpufreq-installer\nVisit the GitHub repo for more info")
label.set_justify(Gtk.Justification.CENTER)
button = Gtk.LinkButton.new_with_label(
uri="https://github.com/AdnanHodzic/auto-cpufreq",
label="GitHub Repo"
)

box.pack_start(label, False, False, 0)
box.pack_start(button, False, False, 0)
self.add(box)

def daemon_not_running(self):
self.box = DaemonNotRunningView(self)
self.add(self.box)

def build(self):
if is_running("auto-cpufreq", "--daemon"):
if os.getenv("PKG_MARKER") == "SNAP":
self.snap()
elif is_running("auto-cpufreq", "--daemon"):
self.main()
else:
self.daemon_not_running()
Expand All @@ -73,9 +91,12 @@ def load_css(self):
self.gtk_context.add_provider_for_screen(screen, self.gtk_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
self.gtk_provider.load_from_file(Gio.File.new_for_path(CSS_FILE))

def refresh(self):
def refresh_in_thread(self):
Thread(target=self._refresh).start()
return True

def _refresh(self):
self.systemstats.refresh()
self.currentgovernor.refresh()
self.cpufreqstats.refresh()
return True

20 changes: 14 additions & 6 deletions auto_cpufreq/gui/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys
import os
import platform as pl
from concurrent.futures import ThreadPoolExecutor

sys.path.append("../../")
from subprocess import getoutput, run, PIPE
Expand Down Expand Up @@ -77,9 +78,6 @@ def __init__(self):
self.pack_start(self.powersave, True, True, 0)
self.pack_start(self.performance, True, True, 0)

#self.pack_start(self.label, False, False, 0)
#self.pack_start(self.hbox, False, False, 0)

def on_button_toggled(self, button, override):
if button.get_active():
if not self.set_by_app:
Expand Down Expand Up @@ -185,7 +183,11 @@ def _remove_daemon(self, MenuItem, parent):
confirm.destroy()
if response == Gtk.ResponseType.YES:
try:
result = run("pkexec auto-cpufreq --remove", shell=True, stdout=PIPE, stderr=PIPE)
# run in thread to prevent GUI from hanging
with ThreadPoolExecutor() as executor:
kwargs = {"shell": True, "stdout": PIPE, "stderr": PIPE}
future = executor.submit(run, "pkexec auto-cpufreq --remove", **kwargs)
result = future.result()
if result.stderr.decode() == PKEXEC_ERROR:
raise Exception("Authorization was cancelled")
dialog = Gtk.MessageDialog(
Expand Down Expand Up @@ -215,7 +217,6 @@ def __init__(self, parent):
super().__init__(title="About", transient_for=parent)
app_version = get_version()
self.box = self.get_content_area()
# self.box.set_homogeneous(True)
self.box.set_spacing(10)
self.add_button("Close", Gtk.ResponseType.CLOSE)
self.set_default_size(400, 350)
Expand Down Expand Up @@ -267,9 +268,16 @@ def __init__(self, parent):

def install_daemon(self, button, parent):
try:
result = run("pkexec auto-cpufreq --install", shell=True, stdout=PIPE, stderr=PIPE)
# run in thread to prevent GUI from hanging
with ThreadPoolExecutor() as executor:
kwargs = {"shell": True, "stdout": PIPE, "stderr": PIPE}
future = executor.submit(run, "pkexec auto-cpufreq --install", **kwargs)
result = future.result()
if result.stderr.decode() == PKEXEC_ERROR:
raise Exception("Authorization was cancelled")
# enable for debug. causes issues if kept
# elif result.stderr is not None:
# raise Exception(result.stderr.decode())
dialog = Gtk.MessageDialog(
transient_for=parent,
message_type=Gtk.MessageType.INFO,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def read(name):
return f.read()

# Used for the tar.gz/snap releases
VERSION = "1.9.9"
VERSION = "2.0"

setup(
name="auto-cpufreq",
Expand Down
Binary file added snap/gui/auto-cpufreq.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions snap/gui/auto-cpufreq_auto-cpufreq.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=auto-cpufreq
Comment=Automatic CPU speed & power optimizer for Linux
Exec=auto-cpufreq.auto-cpufreq-gtk
StartupWMClass=app.py
Terminal=false
Icon=${SNAP}/meta/gui/auto-cpufreq.png
Categories=System;
5 changes: 4 additions & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ parts:
cpufreqctl.sh: usr/bin/cpufreqctl.auto-cpufreq
snapdaemon.sh: usr/bin/snapdaemon

copy-image:
plugin: dump
source: images

plugs:
etc-auto-cpufreq-conf:
interface: system-files
Expand Down Expand Up @@ -78,7 +82,6 @@ apps:
- cpu-control
- system-observe
- hardware-observe
- etc-auto-cpufreq-conf
environment:
LC_ALL: C.UTF-8
LANG: C.UTF-8
Expand Down

0 comments on commit 257d6e9

Please sign in to comment.