2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-28 12:58:07 +00:00

aa-notify: make ttkthemes conditional - partial backport of MR1324

ttkthemees may not be installed on some systems, and if not present
will cause aa-notify to fail. Instead of making ttkthemes a required
dependency, make its use conditional on it being present.

Backport by: Christian Boltz <apparmor@cboltz.de>
Signed-off-by: John Johansen <john.johansen@canonical.com>
This commit is contained in:
John Johansen 2025-02-13 00:50:24 -08:00
parent 0587826fb4
commit 47096faadd

View File

@ -2,7 +2,12 @@ import os
import tkinter as tk import tkinter as tk
import tkinter.ttk as ttk import tkinter.ttk as ttk
import subprocess import subprocess
import ttkthemes
try: # We use tk without themes as a fallback which makes the GUI uglier but functional.
import ttkthemes
except ImportError:
ttkthemes = None
import apparmor.aa as aa import apparmor.aa as aa
@ -26,12 +31,12 @@ class GUI:
os._exit(1) os._exit(1)
self.result = None self.result = None
style = ttkthemes.ThemedStyle(self.master) if ttkthemes:
style.theme_use(interface_theme) style = ttkthemes.ThemedStyle(self.master)
self.bg_color = style.lookup('TLabel', 'background') style.theme_use(interface_theme)
self.fg_color = style.lookup('TLabel', 'foreground') self.bg_color = style.lookup('TLabel', 'background')
self.master.configure(background=self.bg_color) self.fg_color = style.lookup('TLabel', 'foreground')
self.master.configure(background=self.bg_color)
self.label_frame = ttk.Frame(self.master, padding=(20, 10)) self.label_frame = ttk.Frame(self.master, padding=(20, 10))
self.label_frame.pack() self.label_frame.pack()
@ -59,8 +64,9 @@ class ShowMoreGUI(GUI):
self.master.title(_('AppArmor - More info')) self.master.title(_('AppArmor - More info'))
self.label = tk.Label(self.label_frame, background=self.bg_color, foreground=self.fg_color, self.label = tk.Label(self.label_frame, text=self.msg, anchor='w', justify=tk.LEFT, wraplength=460)
text=self.msg, anchor='w', justify=tk.LEFT, wraplength=460) if ttkthemes:
self.label.configure(background=self.bg_color, foreground=self.fg_color)
self.label.pack(pady=(0, 10) if not self.profile_found else (0, 0)) self.label.pack(pady=(0, 10) if not self.profile_found else (0, 0))
if self.profile_found: if self.profile_found:
@ -143,11 +149,11 @@ class ErrorGUI(GUI):
self.master.title('AppArmor Error') self.master.title('AppArmor Error')
# Create label to display the error message self.label = ttk.Label(self.label_frame, text=self.msg, wraplength=460)
self.label = ttk.Label(self.label_frame, background=self.bg_color, text=self.msg, wraplength=460) if ttkthemes:
self.label.configure(background=self.bg_color)
self.label.pack() self.label.pack()
# Create a button to close the dialog
self.button = ttk.Button(self.button_frame, text='OK', command=self.destroy) self.button = ttk.Button(self.button_frame, text='OK', command=self.destroy)
self.button.pack() self.button.pack()