By using this site, you agree to have cookies stored on your device, strictly for functional purposes, such as storing your session and preferences.

Dismiss

 __init__.py

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