__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.flowbox_item_focus_signal = self.flowbox.connect("selected-children-changed", self.on_flowbox_item_focus) 53self.populate_menu_entries() 54self.scrolled_window = Gtk.ScrolledWindow() 55self.scrolled_window.set_child(self.flowbox) 56self.popover.set_child(self.scrolled_window) 57self.popover.set_size_request(300, 400) 58self.popover.connect("show", self.on_popover_popup) 59self.button.set_popover(self.popover) 60 61def on_flowbox_item_focus(self, flowbox): 62selected_children = flowbox.get_selected_children() 63if len(selected_children) >= 1: 64selected_children[0].get_child().grab_focus() 65 66def on_popover_popup(self, parent): 67for child in self.flowbox.get_selected_children(): 68self.flowbox.unselect_child(child) 69self.popover.popup() 70 71def app_button_clicked(self, app_button): 72subprocess.Popen(app_button.command, start_new_session=True) 73self.popover.popdown() 74 75def populate_menu_entries(self): 76app_infos = Gio.AppInfo.get_all() # Get all registered applications 77 78for app_info in app_infos: 79app_categories = app_info.get_categories() 80if app_categories == None: 81continue 82app_name = app_info.get_display_name() 83app_button = Gtk.Button() 84app_button.command = app_info.get_executable() 85app_button.set_tooltip_text(app_name) 86app_label = Gtk.Label(label=app_name) 87app_label.set_ellipsize(Pango.EllipsizeMode.END) 88app_label.set_max_width_chars(7) 89app_button_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) 90app_button_box.append(app_label) 91app_button.set_child(app_button_box) 92 93image = Gtk.Image() 94image.set_icon_size(Gtk.IconSize.LARGE) 95icon = app_info.get_icon() 96if icon: 97icon_name = icon.to_string() 98if not Gtk.IconTheme.get_for_display(Gdk.Display.get_default()).has_icon(icon_name): 99continue 100if icon_name[0] == '/': 101image.set_from_file(icon_name) 102else: 103image.set_from_icon_name(icon_name) 104else: 105if not Gtk.IconTheme.get_for_display(Gdk.Display.get_default()).has_icon(app_name.lower()): 106continue 107image.set_from_icon_name(app_name.lower()) 108 109self.flowbox.append(app_button) 110app_button.connect("clicked", self.app_button_clicked) 111app_button_box.prepend(image) 112