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