Commit fa30b375 authored by Roman Alifanov's avatar Roman Alifanov

The dialog is now a class

parent 0acb99f7
...@@ -8,6 +8,35 @@ gi.require_version('Adw', '1') ...@@ -8,6 +8,35 @@ gi.require_version('Adw', '1')
from gi.repository import Gtk, Gio, Adw from gi.repository import Gtk, Gio, Adw
from .window import XimperUnifiedThemeSwitcherGuiGtk4Window from .window import XimperUnifiedThemeSwitcherGuiGtk4Window
class ServiceNeededDialog(Adw.AlertDialog):
def __init__(self, parent_window):
super().__init__()
self.parent_window = parent_window
self.set_heading(_("The user service is disabled.")),
self.set_body(_("Do you want to enable it?"))
self.add_response("yes", _("Yes"))
self.add_response("no", _("No"))
self.connect("response", self.on_response)
def present(self):
"""Present the dialog to the user."""
super().present(self.parent_window)
def on_response(self, dialog, response):
print(f"response: {response}")
if response == "yes":
service_enable("ximper-unified-theme-switcher.service")
dialog.close()
elif response in ("no", "close"):
dialog.close()
self.parent_window.close()
class XimperUnifiedThemeSwitcherGuiGtk4Application(Adw.Application): class XimperUnifiedThemeSwitcherGuiGtk4Application(Adw.Application):
"""The main application singleton class.""" """The main application singleton class."""
...@@ -32,33 +61,8 @@ class XimperUnifiedThemeSwitcherGuiGtk4Application(Adw.Application): ...@@ -32,33 +61,8 @@ class XimperUnifiedThemeSwitcherGuiGtk4Application(Adw.Application):
if service_status("ximper-unified-theme-switcher.service") == False: if service_status("ximper-unified-theme-switcher.service") == False:
print("service not found") print("service not found")
dialog = ServiceNeededDialog(win)
# Create the dialog dialog.present()
dialog = Adw.AlertDialog(
heading=_("The user service is disabled."),
body=_("Do you want to enable it?")
)
# Add buttons for the user to respond
dialog.add_response("yes", _("Yes"))
dialog.add_response("no", _("No"))
# Connect the response handler
dialog.connect("response", self.srvs_d_on_response)
# Present the dialog
dialog.present(win)
def srvs_d_on_response(self, dialog, response):
print(f"response: {response}")
if response == "yes":
service_enable("ximper-unified-theme-switcher.service")
dialog.close()
elif response in ("no", "close"):
dialog.close()
self.props.active_window.close()
def on_about_action(self, widget, _): def on_about_action(self, widget, _):
"""Callback for the app.about action.""" """Callback for the app.about action."""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment