applicationrow.py 1.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
from gi.repository import Adw, Gtk


class ApplicationRow(Adw.ActionRow):
    def __init__(self, app, is_installed, on_toggle):
        super().__init__(title=app['name'], subtitle=app['dscr'])
        self.app = app
        self.is_installed = is_installed
        self.checkbox = Gtk.CheckButton()
        self.checkbox.add_css_class("selection-mode")
11 12
        self.checkbox.set_valign(Gtk.Align.CENTER)
        self.checkbox.set_halign(Gtk.Align.CENTER)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
        self.checkbox.set_active(is_installed)
        self.checkbox.connect("toggled", self.on_checkbox_toggled)
        self.add_suffix(self.checkbox)
        self.on_toggle = on_toggle  # Callback for when the checkbox is toggled

    def on_checkbox_toggled(self, checkbox):
        self.on_toggle(self.app['name'], checkbox.get_active())
        self.update_row_css()  # Update the row's style when toggled

    def is_changed(self):
        """Determine if the checkbox state has changed compared to the installed state."""
        return self.checkbox.get_active() != self.is_installed

    def update_row_css(self):
        """Update the CSS classes for the row based on the checkbox state."""
        for css in ["marked-for-install", "marked-for-removal", "unchanged"]:
            self.remove_css_class(css)

        # Add the appropriate class based on the current checkbox state
        if self.is_changed():
            if self.checkbox.get_active():
                self.add_css_class("marked-for-install")
                print("marked-for-install")
            else:
                self.add_css_class("marked-for-removal")
                print("marked-for-removal")
        else:
            # self.add_css_class("unchanged")
            print("marked-unchanged")