__init__.py
Python script, ASCII text executable
1""" 2The MIT License (MIT) 3 4Copyright (c) 2025 Scott Moreau <oreaus@gmail.com>, modified by <root@roundabout-host.com> 5 6Permission is hereby granted, free of charge, to any person obtaining a copy 7of this software and associated documentation files (the "Software"), to deal 8in the Software without restriction, including without limitation the rights 9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10copies of the Software, and to permit persons to whom the Software is 11furnished to do so, subject to the following conditions: 12 13The above copyright notice and this permission notice shall be included in 14all copies or substantial portions of the Software. 15 16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22SOFTWARE. 23""" 24 25import os 26from pathlib import Path 27import locale 28import panorama_panel 29 30import gi 31gi.require_version("Gtk", "4.0") 32 33from gi.repository import Gtk, GLib, Gio, Gdk, Pango 34import subprocess 35 36class SoreausMenu(panorama_panel.Applet): 37name = "Soreau's menu" 38description = "Flowbox app menu" 39 40def __init__(self, orientation=Gtk.Orientation.HORIZONTAL, config=None): 41super().__init__() 42 43self.button = Gtk.MenuButton() 44 45image = Gtk.Image.new_from_icon_name("wayfire") 46image.set_icon_size(Gtk.IconSize.LARGE) 47self.append(self.button) 48self.button.set_child(image) 49self.popover = Gtk.Popover() 50self.popover.set_parent(self) 51self.flowbox = Gtk.FlowBox() 52self.populate_menu_entries() 53self.scrolled_window = Gtk.ScrolledWindow() 54self.scrolled_window.set_child(self.flowbox) 55self.popover.set_child(self.scrolled_window) 56self.popover.set_size_request(300, 400) 57self.button.set_popover(self.popover) 58 59def popover_popup(self, parent): 60self.popover.popup() 61 62def app_button_clicked(self, app_button): 63print(f"Launching: {app_button.command}") 64if os.getenv("LD_PRELOAD") is not None: 65del os.environ["LD_PRELOAD"] 66subprocess.Popen(app_button.command, start_new_session=True) 67self.popover.popdown() 68 69def populate_menu_entries(self): 70app_infos = Gio.AppInfo.get_all() # Get all registered applications 71 72for app_info in app_infos: 73app_name = app_info.get_display_name() 74app_button = Gtk.Button() 75app_button.command = app_info.get_executable() 76app_button.set_tooltip_text(app_name) 77app_label = Gtk.Label(label=app_name) 78app_label.set_ellipsize(Pango.EllipsizeMode.END) 79app_label.set_max_width_chars(7) 80app_button_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) 81app_button_box.append(app_label) 82app_button.set_child(app_button_box) 83self.flowbox.append(app_button) 84 85app_button.connect("clicked", lambda *_, app_button=app_button: self.app_button_clicked(app_button)) 86 87image = Gtk.Image.new_from_icon_name("foobarbaz") 88image.set_icon_size(Gtk.IconSize.LARGE) 89icon = app_info.get_icon() 90if icon: 91icon_name = icon.to_string() 92if icon_name[0] == '/': 93image.set_from_file(icon_name) 94else: 95image.set_from_icon_name(icon_name) 96else: 97print(f"No icon found: {app_name}") 98image.set_from_icon_name(app_name.lower()) 99app_button_box.prepend(image)