Skip to content

Commit

Permalink
Gtk Application for auto-cpufreq (#486)
Browse files Browse the repository at this point in the history
* Squashed commit of the following:

commit ec7e087
Merge: 32b6e63 9912f9d
Author: shadeyg56 <31134255+shadeyg56@users.noreply.github.com>
Date:   Mon Feb 13 14:11:21 2023 -0600

    Merge branch 'AdnanHodzic:master' into gui

commit 32b6e63
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Mon Feb 13 14:10:34 2023 -0600

    increase MenuButton size

commit 12a2cda
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Sun Feb 12 23:35:33 2023 -0600

    set app icon

commit d170d07
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Sun Feb 12 23:35:15 2023 -0600

    remove unused pixbuf

commit 993333f
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Sun Feb 12 22:43:56 2023 -0600

    fix MenuButton icon

commit d1b8bd7
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Sun Feb 12 17:19:32 2023 -0600

    add icon

commit 13f43fa
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Sun Feb 12 17:19:10 2023 -0600

    add pkexec policy and change wrapper for gui

commit 4ddbb9c
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Sun Feb 12 14:09:35 2023 -0600

    add icon to destop entry and about dialog

commit 9912f9d
Author: Siddharth Kumar Jha <101443068+siddharthkumarjha@users.noreply.github.com>
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 <shadeyg56@gmail.com>
Date:   Tue Feb 7 19:06:59 2023 -0600

    add removal of gui and desktop entry

commit 4269370
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Mon Feb 6 23:28:44 2023 -0600

    CPU stats refresh and style stuff

commit 7149db7
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Mon Feb 6 23:10:29 2023 -0600

    daemon detection, daemon install/removal, and layout stuff

commit f7e03c9
Author: shadeyg56 <shadeyg56@gmail.com>
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 <shadeyg56@gmail.com>
Date:   Sun Feb 5 18:28:19 2023 -0600

    add dropdown menu and (not completed) about dialog

commit ade1fed
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Sun Feb 5 15:57:17 2023 -0600

    actually fix css

commit 67c8c97
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Sun Feb 5 15:54:47 2023 -0600

    fix css

commit c65eac3
Author: Adnan Hodzic <adnan@hodzic.org>
Date:   Sun Feb 5 09:29:19 2023 +0100

    Update readme, install psutil lib for power_helper

commit bd3feae
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Sun Feb 5 00:42:52 2023 -0600

    add desktop entry for gui

commit 5426a6a
Author: shadeyg56 <shadeyg56@gmail.com>
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 <shadeyg56@gmail.com>
Date:   Sat Feb 4 23:28:24 2023 -0600

    create system tray

commit 7b0d46d
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Sat Feb 4 23:28:01 2023 -0600

    small changes to layout

commit cd51ea3
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Sat Feb 4 00:44:08 2023 -0600

    css styling support

commit 136b449
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Sat Feb 4 00:14:52 2023 -0600

    several improvements

commit f9f7170
Merge: 242a8d0 8f343df
Author: shadeyg56 <31134255+shadeyg56@users.noreply.github.com>
Date:   Fri Feb 3 22:44:01 2023 -0600

    Merge branch 'AdnanHodzic:master' into gui

commit 8f343df
Merge: dadfae0 b38919f
Author: shadeyg56 <31134255+shadeyg56@users.noreply.github.com>
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 <shadeyg56@gmail.com>
Date:   Fri Feb 3 14:48:01 2023 -0600

    fix uncaught error in checking for snap

commit 242a8d0
Merge: f50b982 dadfae0
Author: shadeyg56 <31134255+shadeyg56@users.noreply.github.com>
Date:   Fri Feb 3 14:19:01 2023 -0600

    Merge branch 'AdnanHodzic:master' into gui

commit dadfae0
Author: Adnan Hodzic <adnan@hodzic.org>
Date:   Fri Feb 3 20:02:03 2023 +0100

    Update README with  new config options

commit 471611d
Author: Adnan Hodzic <adnan@hodzic.org>
Date:   Fri Feb 3 18:44:33 2023 +0100

    Remove GNOME Power Profiles Daemon performance install

commit f574257
Author: Adnan Hodzic <adnan@hodzic.org>
Date:   Fri Feb 3 18:32:04 2023 +0100

    Remove install_performance flag

commit 04b8783
Author: Adnan Hodzic <adnan@hodzic.org>
Date:   Fri Feb 3 17:52:20 2023 +0100

    Snap tag 2.0-beta + governor_override improvements

commit fe21ddf
Author: Adnan Hodzic <adnan@hodzic.org>
Date:   Fri Feb 3 17:28:12 2023 +0100

    Working governor override on Snap package

commit f50b982
Merge: a98225e 69ef913
Author: shadeyg56 <31134255+shadeyg56@users.noreply.github.com>
Date:   Thu Feb 2 18:19:10 2023 -0600

    Merge branch 'AdnanHodzic:master' into gui

commit a98225e
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Thu Feb 2 18:18:43 2023 -0600

    Revert "basic GUI"

    This reverts commit d2610c9.

commit 9606472
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Thu Feb 2 18:13:41 2023 -0600

    basic gui

commit d2610c9
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Thu Feb 2 17:47:55 2023 -0600

    basic GUI

commit bdbe120
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Thu Feb 2 15:21:42 2023 -0600

    rename folder

commit 31095c4
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Wed Jan 25 23:39:52 2023 -0600

    add tray

* Squashed commit of the following:

commit e2eaffc
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Mon Feb 20 23:08:57 2023 -0600

    move text to be inline with menu

commit e1dae9d
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Sun Feb 19 17:50:26 2023 -0600

    move distro info to top of system stats box

commit 959405b
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Sun Feb 19 17:49:15 2023 -0600

    fix app name on GNOME

commit 346093d
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Sun Feb 19 17:01:03 2023 -0600

    fix snap dependencies

commit ec7e087
Merge: 32b6e63 9912f9d
Author: shadeyg56 <31134255+shadeyg56@users.noreply.github.com>
Date:   Mon Feb 13 14:11:21 2023 -0600

    Merge branch 'AdnanHodzic:master' into gui

commit 32b6e63
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Mon Feb 13 14:10:34 2023 -0600

    increase MenuButton size

commit 12a2cda
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Sun Feb 12 23:35:33 2023 -0600

    set app icon

commit d170d07
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Sun Feb 12 23:35:15 2023 -0600

    remove unused pixbuf

commit 993333f
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Sun Feb 12 22:43:56 2023 -0600

    fix MenuButton icon

commit d1b8bd7
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Sun Feb 12 17:19:32 2023 -0600

    add icon

commit 13f43fa
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Sun Feb 12 17:19:10 2023 -0600

    add pkexec policy and change wrapper for gui

commit 4ddbb9c
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Sun Feb 12 14:09:35 2023 -0600

    add icon to destop entry and about dialog

commit 4379024
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Tue Feb 7 19:06:59 2023 -0600

    add removal of gui and desktop entry

commit 4269370
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Mon Feb 6 23:28:44 2023 -0600

    CPU stats refresh and style stuff

commit 7149db7
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Mon Feb 6 23:10:29 2023 -0600

    daemon detection, daemon install/removal, and layout stuff

commit f7e03c9
Author: shadeyg56 <shadeyg56@gmail.com>
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 <shadeyg56@gmail.com>
Date:   Sun Feb 5 18:28:19 2023 -0600

    add dropdown menu and (not completed) about dialog

commit ade1fed
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Sun Feb 5 15:57:17 2023 -0600

    actually fix css

commit 67c8c97
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Sun Feb 5 15:54:47 2023 -0600

    fix css

commit bd3feae
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Sun Feb 5 00:42:52 2023 -0600

    add desktop entry for gui

commit 5426a6a
Author: shadeyg56 <shadeyg56@gmail.com>
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 <shadeyg56@gmail.com>
Date:   Sat Feb 4 23:28:24 2023 -0600

    create system tray

commit 7b0d46d
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Sat Feb 4 23:28:01 2023 -0600

    small changes to layout

commit cd51ea3
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Sat Feb 4 00:44:08 2023 -0600

    css styling support

commit 136b449
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Sat Feb 4 00:14:52 2023 -0600

    several improvements

commit f9f7170
Merge: 242a8d0 8f343df
Author: shadeyg56 <31134255+shadeyg56@users.noreply.github.com>
Date:   Fri Feb 3 22:44:01 2023 -0600

    Merge branch 'AdnanHodzic:master' into gui

commit 242a8d0
Merge: f50b982 dadfae0
Author: shadeyg56 <31134255+shadeyg56@users.noreply.github.com>
Date:   Fri Feb 3 14:19:01 2023 -0600

    Merge branch 'AdnanHodzic:master' into gui

commit f50b982
Merge: a98225e 69ef913
Author: shadeyg56 <31134255+shadeyg56@users.noreply.github.com>
Date:   Thu Feb 2 18:19:10 2023 -0600

    Merge branch 'AdnanHodzic:master' into gui

commit a98225e
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Thu Feb 2 18:18:43 2023 -0600

    Revert "basic GUI"

    This reverts commit d2610c9.

commit 9606472
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Thu Feb 2 18:13:41 2023 -0600

    basic gui

commit d2610c9
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Thu Feb 2 17:47:55 2023 -0600

    basic GUI

commit bdbe120
Author: shadeyg56 <shadeyg56@gmail.com>
Date:   Thu Feb 2 15:21:42 2023 -0600

    rename folder

commit 31095c4
Author: shadeyg56 <shadeyg56@gmail.com>
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

* gui: fix pkexec on launch
  • Loading branch information
shadeyg56 authored Aug 15, 2023
1 parent b0f8472 commit 0925b5d
Show file tree
Hide file tree
Showing 15 changed files with 519 additions and 6 deletions.
23 changes: 19 additions & 4 deletions auto-cpufreq-installer
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,18 @@ function install {
python3 setup.py install --record files.txt
mkdir -p /usr/local/share/auto-cpufreq/
cp -r scripts/ /usr/local/share/auto-cpufreq/
cp -r images/ /usr/local/share/auto-cpufreq/
cp images/icon.png /usr/share/pixmaps/auto-cpufreq.png
cp scripts/org.auto-cpufreq.pkexec.policy /usr/share/polkit-1/actions

# this is necessary since we need this script before we can run auto-cpufreq itself
cp scripts/auto-cpufreq-venv-wrapper /usr/local/bin/auto-cpufreq
cp scripts/start_app /usr/local/bin/auto-cpufreq-gtk
chmod a+x /usr/local/bin/auto-cpufreq
chmod a+x /usr/local/bin/auto-cpufreq-gtk

desktop-file-install --dir=/usr/share/applications scripts/auto-cpufreq-gtk.desktop
update-desktop-database /usr/share/applications
}

# First argument is the distro
Expand Down Expand Up @@ -140,7 +148,7 @@ function tool_install {
separator
if [ -f /etc/debian_version ]; then
detected_distro "Debian based"
apt install python3-dev python3-pip python3-venv python3-setuptools dmidecode -y
apt install python3-dev python3-pip python3-venv python3-setuptools dmidecode libgirepository1.0-dev libcairo2-dev -y
completed
complete_msg
elif [ -f /etc/redhat-release ]; then
Expand Down Expand Up @@ -170,12 +178,12 @@ elif [ -f /etc/os-release ];then
opensuse)
detected_distro "OpenSUSE"
echo -e "\nDetected an OpenSUSE distribution\n\nSetting up Python environment\n"
zypper install -y python38 python3-pip python3-setuptools python3-devel gcc dmidecode
zypper install -y python38 python3-pip python3-setuptools python3-devel gcc dmidecode gobject-introspection-devel python3-cairo-devel
completed
;;
arch|manjaro|endeavouros|garuda|artix)
detected_distro "Arch Linux based"
pacman -S --noconfirm --needed python python-pip python-setuptools base-devel dmidecode
pacman -S --noconfirm --needed python python-pip python-setuptools base-devel dmidecode gobject-introspection
completed
;;
void)
Expand Down Expand Up @@ -208,12 +216,15 @@ function tool_remove {

tool_proc_rm="/usr/local/bin/auto-cpufreq --remove"
wrapper_script="/usr/local/bin/auto-cpufreq"
gui_wrapper_script="/usr/local/bin/auto-cpufreq-gtk"
unit_file="/etc/systemd/system/auto-cpufreq.service"
venv_path="/opt/auto-cpufreq"

cpufreqctl="/usr/local/bin/cpufreqctl.auto-cpufreq"
cpufreqctl_old="/usr/bin/cpufreqctl.auto-cpufreq"

desktop_file="/usr/share/applications/auto-cpufreq-gtk.desktop"

# stop any running auto-cpufreq argument (daemon/live/monitor)
tool_arg_pids=($(pgrep -f "auto-cpufreq --"))
for pid in "${tool_arg_pids[@]}"; do
Expand Down Expand Up @@ -246,10 +257,14 @@ function tool_remove {
[ -f $stats_file ] && rm $stats_file
[ -f $unit_file ] && rm $unit_file
[ -f $wrapper_script ] && rm $wrapper_script

[ -f $gui_wrapper_script ] && rm $gui_wrapper_script

[ -f $cpufreqctl ] && rm $cpufreqctl
[ -f $cpufreqctl_old ] && rm $cpufreqctl_old

[ -f $desktop_file ] && rm $desktop_file
update-desktop-database /usr/share/applications

# remove python virtual environment
rm -rf "${venv_path}"

Expand Down
3 changes: 3 additions & 0 deletions auto_cpufreq/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

warnings.filterwarnings("ignore")

# add path to auto-cpufreq executables for GUI
os.environ["PATH"] += ":/usr/local/bin"

# ToDo:
# - replace get system/CPU load from: psutil.getloadavg() | available in 5.6.2)

Expand Down
Empty file added auto_cpufreq/gui/__init__.py
Empty file.
81 changes: 81 additions & 0 deletions auto_cpufreq/gui/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import gi

gi.require_version("Gtk", "3.0")

from gi.repository import Gtk, GLib, Gdk, Gio, GdkPixbuf

import os
import sys

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"

HBOX_PADDING = 20

class ToolWindow(Gtk.Window):
def __init__(self):
super().__init__(title="auto-cpufreq")
self.set_default_size(600, 480)
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)
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)

self.systemstats = SystemStatsLabel()
self.hbox.pack_start(self.systemstats, False, False, 0)
self.add(self.hbox)

self.vbox_right = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=52)

self.menu = DropDownMenu(self)
self.hbox.pack_end(self.menu, False, False, 0)

self.currentgovernor = CurrentGovernorBox()
self.vbox_right.pack_start(self.currentgovernor, False, False, 0)
self.vbox_right.pack_start(RadioButtonView(), False, False, 0)

self.cpufreqstats = CPUFreqStatsLabel()
self.vbox_right.pack_start(self.cpufreqstats, False, False, 0)

self.hbox.pack_start(self.vbox_right, False, False, 0)


GLib.timeout_add_seconds(5, self.refresh)

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

def build(self):
if is_running("auto-cpufreq", "--daemon"):
self.main()
else:
self.daemon_not_running()

def load_css(self):
screen = Gdk.Screen.get_default()
self.gtk_provider = Gtk.CssProvider()
self.gtk_context = Gtk.StyleContext()
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):
self.systemstats.refresh()
self.currentgovernor.refresh()
self.cpufreqstats.refresh()
return True

Loading

0 comments on commit 0925b5d

Please sign in to comment.