__init__.py
Python script, ASCII text executable
1""" 2Launcher applets for the Panorama panel. 3Copyright 2025, roundabout-host.com <vlad@roundabout-host.com> 4 5This program is free software: you can redistribute it and/or modify 6it under the terms of the GNU General Public Licence as published by 7the Free Software Foundation, either version 3 of the Licence, or 8(at your option) any later version. 9 10This program is distributed in the hope that it will be useful, 11but WITHOUT ANY WARRANTY; without even the implied warranty of 12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13GNU General Public Licence for more details. 14 15You should have received a copy of the GNU General Public Licence 16along with this program. If not, see <https://www.gnu.org/licenses/>. 17""" 18 19import os 20import subprocess 21from pathlib import Path 22import panorama_panel 23 24import gi 25gi.require_version("Gtk", "4.0") 26 27from gi.repository import Gtk, GLib, Gio, Gdk 28 29 30class CommandButton(panorama_panel.Applet): 31name = "Command button" 32description = "Run a command when clicked" 33 34def __init__(self, orientation=Gtk.Orientation.HORIZONTAL, config=None): 35super().__init__(orientation=orientation, config=config) 36if config is None: 37config = {} 38self.button = Gtk.Button() 39self.button.set_has_frame(False) # flat look 40self.inner_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) 41self.button.set_child(self.inner_box) 42self.icon_name = config.get("icon_name") 43self.icon_size = config.get("icon_size", 24) 44self.label = config.get("label") 45self.command = config.get("command") 46self.button.connect("clicked", self.execute) 47if config.get("icon_name"): 48self.inner_box.append(Gtk.Image(icon_name=config["icon_name"], pixel_size=config.get("icon_size", 24))) 49if config.get("label"): 50self.inner_box.append(Gtk.Label.new(config["label"])) 51 52self.append(self.button) 53 54def execute(self, button, *args): 55subprocess.Popen(self.command, shell=True, start_new_session=True) 56 57def get_config(self): 58return {"label": self.label, "icon_name": self.icon_name, "icon_size": self.icon_size, "command": self.command} 59 60 61class DesktopFileButton(panorama_panel.Applet): 62name = "Desktop file button" 63description = "Launch a desktop file when clicked" 64 65def __init__(self, orientation=Gtk.Orientation.HORIZONTAL, config=None): 66super().__init__(orientation=orientation, config=config) 67if config is None: 68config = {} 69self.button = Gtk.Button() 70self.button.set_has_frame(False) # flat look 71self.inner_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) 72self.button.set_child(self.inner_box) 73self.desktop_file = config.get("desktop_file") 74self.app_id = config.get("app_id") 75if self.desktop_file: 76self.app_info = Gio.DesktopAppInfo.new_from_filename(self.desktop_file) 77elif self.app_id: 78self.app_info = Gio.DesktopAppInfo.new(self.app_id) 79self.button.connect("clicked", self.execute) 80self.icon_size = config.get("icon_size", 24) 81self.inner_box.append(Gtk.Image(gicon=self.app_info.get_icon(), pixel_size=self.icon_size)) 82 83self.append(self.button) 84 85def execute(self, button, *args): 86self.app_info.launch() 87 88def get_config(self): 89return {"desktop_file": self.desktop_file, "app_id": self.app_id, "icon_size": self.icon_size} 90