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