Skip to content

Commit

Permalink
add dropdown menu and (not completed) about dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
shadeyg56 committed Feb 6, 2023
1 parent ade1fed commit cb8cfe7
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
1 change: 1 addition & 0 deletions auto-cpufreq-installer
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ 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/

# 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
Expand Down
8 changes: 6 additions & 2 deletions auto_cpufreq/gui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import sys

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

CSS_FILE = "/usr/local/share/auto-cpufreq/scripts/style.css"

Expand Down Expand Up @@ -38,6 +38,10 @@ def __init__(self):
self.hbox.pack_start(self.systemstats, False, False, 0)

self.vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=20)

self.menu = DropDownMenu(self)
self.vbox.pack_start(self.menu, False, False, 0)

self.currentgovernor = CurrentGovernorBox()
self.vbox.pack_start(self.currentgovernor, False, False, 0)
self.vbox.pack_start(RadioButtonView(), False, False, 0)
Expand All @@ -47,7 +51,7 @@ def __init__(self):

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

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

def load_css(self):
screen = Gdk.Screen.get_default()
Expand Down
47 changes: 45 additions & 2 deletions auto_cpufreq/gui/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

from gi.repository import Gtk
from gi.repository import Gtk, GdkPixbuf

import sys
import os
Expand Down Expand Up @@ -114,4 +114,47 @@ def update(self):
del stats[:i]
del stats[-4:]
self.set_label("\n".join(stats))


class DropDownMenu(Gtk.MenuButton):
def __init__(self, parent):
super().__init__()
self.set_halign(Gtk.Align.END)
img_buffer = GdkPixbuf.Pixbuf.new_from_file_at_scale(
filename="/usr/local/share/auto-cpufreq/images/menu.png",
width=25,
height=25,
preserve_aspect_ratio=True)
self.image = Gtk.Image.new_from_pixbuf(img_buffer)
self.add(self.image)
self.menu = self.build_menu(parent)
self.set_popup(self.menu)

def build_menu(self, parent):
menu = Gtk.Menu()

daemon = Gtk.MenuItem(label="Remove Daemon")
menu.append(daemon)

about = Gtk.MenuItem(label="About")
about.connect("activate", self.about_dialog, parent)
menu.append(about)

menu.show_all()
return menu

def about_dialog(self, MenuItem, parent):
dialog = AboutDialog(parent)
response = dialog.run()
dialog.destroy()


class AboutDialog(Gtk.Dialog):
def __init__(self, parent):
super().__init__(title="About", transient_for=parent)
self.box = self.get_content_area()
self.add_button("Close", Gtk.ResponseType.CLOSE)
self.set_default_size(150, 100)

label = Gtk.Label("Hello World")
self.box.pack_start(label, False, False, 0)
self.show_all()
Binary file added images/menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions scripts/style.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
label{
font-family: Noto Sans;
font-size: 15px;
}

button.popup{
background-image: none;
background-color: white;
}

0 comments on commit cb8cfe7

Please sign in to comment.