Add shortcut cheatsheet

This commit is contained in:
Jeena 2025-08-30 10:33:19 +09:00
parent 5dfae0e5eb
commit 3f7d6c9821
5 changed files with 113 additions and 1 deletions

81
hypr/scripts/cheatsheet.py Executable file
View file

@ -0,0 +1,81 @@
#!/usr/bin/env python3
import gi, sys
gi.require_version("Gtk", "4.0")
gi.require_version("Adw", "1")
from gi.repository import Gtk, Adw, Gdk, Pango, Gio
class Cheatsheet(Adw.Application):
def __init__(self, path):
super().__init__(application_id="net.jeena.Cheatsheet")
self.path = path
def do_activate(self):
win = self.create_window()
container, label = self.create_cheatsheet_label(self.path)
self.apply_css(container, label)
win.set_content(container)
win.present()
def create_window(self):
win = Adw.ApplicationWindow(application=self)
win.set_title("Hyprland Cheatsheet")
win.set_default_size(980, 400)
win.set_resizable(True)
win.set_decorated(False)
win.set_opacity(0.7)
win.add_css_class("cheatsheet")
key_controller = Gtk.EventControllerKey()
key_controller.connect("key-pressed", self.on_key)
win.add_controller(key_controller)
return win
def create_cheatsheet_label(self, filepath):
container = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
container.set_margin_top(10)
container.set_margin_bottom(10)
container.set_margin_start(10)
container.set_margin_end(10)
label = Gtk.Label()
label.set_xalign(0)
label.set_yalign(0)
label.set_wrap(True)
label.set_justify(Gtk.Justification.LEFT)
label.set_text(open(filepath).read().rstrip('\n'))
label.set_selectable(False)
container.append(label)
return container, label
def apply_css(self, container, label):
css_provider = Gtk.CssProvider()
css_provider.load_from_data(b"""
window.cheatsheet {
background-color: rgba(0,0,0,0.7);
border-radius: 10px;
}
window.cheatsheet label {
font-family: "JetBrains Mono Nerd Font";
font-size: 12pt;
font-weight: bold;
color: #ffffff;
}
""")
Gtk.StyleContext.add_provider_for_display(
Gdk.Display.get_default(),
css_provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
)
def on_key(self, controller, keyval, keycode, state):
key_name = Gdk.keyval_name(keyval)
if key_name == "Escape":
self.get_active_window().close()
return True
if __name__ == "__main__":
app = Cheatsheet(sys.argv[1])
app.run()