software: turn into generic ChoicesPage
This commit is contained in:
@@ -4,6 +4,7 @@ blueprints = custom_target('blueprints',
|
||||
input: files(
|
||||
'ui/confirm_quit_popup.blp',
|
||||
'ui/main_window.blp',
|
||||
'ui/pages/choices.blp',
|
||||
'ui/pages/confirm.blp',
|
||||
'ui/pages/disk.blp',
|
||||
'ui/pages/done.blp',
|
||||
@@ -17,7 +18,6 @@ blueprints = custom_target('blueprints',
|
||||
'ui/pages/language.blp',
|
||||
'ui/pages/locale.blp',
|
||||
'ui/pages/restart.blp',
|
||||
'ui/pages/software.blp',
|
||||
'ui/pages/summary.blp',
|
||||
'ui/pages/timezone.blp',
|
||||
'ui/pages/user.blp',
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
<file preprocess="xml-stripblanks">ui/confirm_quit_popup.ui</file>
|
||||
<file preprocess="xml-stripblanks">ui/main_window.ui</file>
|
||||
|
||||
<file preprocess="xml-stripblanks">ui/pages/choices.ui</file>
|
||||
<file preprocess="xml-stripblanks">ui/pages/confirm.ui</file>
|
||||
<file preprocess="xml-stripblanks">ui/pages/disk.ui</file>
|
||||
<file preprocess="xml-stripblanks">ui/pages/done.ui</file>
|
||||
@@ -36,7 +37,6 @@
|
||||
<file preprocess="xml-stripblanks">ui/pages/language.ui</file>
|
||||
<file preprocess="xml-stripblanks">ui/pages/locale.ui</file>
|
||||
<file preprocess="xml-stripblanks">ui/pages/restart.ui</file>
|
||||
<file preprocess="xml-stripblanks">ui/pages/software.ui</file>
|
||||
<file preprocess="xml-stripblanks">ui/pages/summary.ui</file>
|
||||
<file preprocess="xml-stripblanks">ui/pages/timezone.ui</file>
|
||||
<file preprocess="xml-stripblanks">ui/pages/user.ui</file>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Gtk 4.0;
|
||||
using Gio 2.0;
|
||||
|
||||
template $SoftwarePage : Box {
|
||||
template $ChoicesPage : Box {
|
||||
orientation: vertical;
|
||||
spacing: 12;
|
||||
|
||||
@@ -15,10 +16,10 @@ template $SoftwarePage : Box {
|
||||
ScrolledWindow {
|
||||
propagate-natural-height: true;
|
||||
styles ["embedded", "separate-bottom"]
|
||||
child: ListBox software_list {
|
||||
child: ListBox choices_list {
|
||||
hexpand: true;
|
||||
selection-mode: none;
|
||||
row-activated => $software_row_activated();
|
||||
row-activated => $row_activated();
|
||||
styles ["boxed-list"]
|
||||
};
|
||||
}
|
||||
@@ -33,3 +34,5 @@ template $SoftwarePage : Box {
|
||||
styles ["suggested-action", "pill", "bottom-button"]
|
||||
}
|
||||
}
|
||||
|
||||
Gio.ListStore model {}
|
||||
@@ -31,6 +31,7 @@ os_installer_sources = [
|
||||
'provider/timezone_provider.py',
|
||||
'ui/confirm_quit_popup.py',
|
||||
'ui/page.py',
|
||||
'ui/pages/choices.py',
|
||||
'ui/pages/confirm.py',
|
||||
'ui/pages/disk.py',
|
||||
'ui/pages/done.py',
|
||||
@@ -44,7 +45,6 @@ os_installer_sources = [
|
||||
'ui/pages/language.py',
|
||||
'ui/pages/locale.py',
|
||||
'ui/pages/restart.py',
|
||||
'ui/pages/software.py',
|
||||
'ui/pages/summary.py',
|
||||
'ui/pages/timezone.py',
|
||||
'ui/pages/user.py',
|
||||
|
||||
@@ -84,13 +84,14 @@ def handle_choices(config_entries):
|
||||
|
||||
### public methods ###
|
||||
|
||||
@staticmethod
|
||||
def get_software_suggestions():
|
||||
if software := global_state.get_config('additional_software'):
|
||||
return handle_choices(software)
|
||||
else:
|
||||
return []
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_feature_suggestions():
|
||||
if features := global_state.get_config('additional_features'):
|
||||
return handle_choices(features)
|
||||
|
||||
86
src/ui/pages/choices.py
Normal file
86
src/ui/pages/choices.py
Normal file
@@ -0,0 +1,86 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from enum import Enum
|
||||
from gi.repository import Gio, Gtk
|
||||
|
||||
from .choices_provider import get_software_suggestions
|
||||
from .global_state import global_state
|
||||
from .page import Page
|
||||
from .util import SummaryEntry
|
||||
from .widgets import MultiSelectionRow, reset_model, SelectionRow
|
||||
|
||||
|
||||
class ChoiceType(Enum):
|
||||
feature = 0
|
||||
software = 1
|
||||
|
||||
|
||||
@Gtk.Template(resource_path='/com/github/p3732/os-installer/ui/pages/choices.ui')
|
||||
class ChoicesPage(Gtk.Box, Page):
|
||||
__gtype_name__ = __qualname__
|
||||
|
||||
choices_list = Gtk.Template.Child()
|
||||
model = Gio.ListStore()
|
||||
|
||||
def __init__(self, choice_type, **kwargs):
|
||||
Gtk.Box.__init__(self, **kwargs)
|
||||
|
||||
self.type = choice_type
|
||||
match self.type:
|
||||
case ChoiceType.software:
|
||||
self.image = 'system-software-install-symbolic'
|
||||
self.software_header.set_visible(True)
|
||||
self.list_provider = get_software_suggestions
|
||||
case _:
|
||||
print("Unknown choice type!")
|
||||
exit(0)
|
||||
|
||||
self.choices_list.bind_model(
|
||||
self.model,
|
||||
self._create_row)
|
||||
|
||||
def _create_row(self, choice):
|
||||
if choice.options:
|
||||
return MultiSelectionRow(choice.name, choice.description, choice.icon_path,
|
||||
'application-x-executable-symbolic',
|
||||
choice.options)
|
||||
else:
|
||||
return SelectionRow(choice.name, choice.description, choice.icon_path,
|
||||
'application-x-executable-symbolic',
|
||||
choice.suggested, choice.keyword)
|
||||
|
||||
### callbacks ###
|
||||
|
||||
@Gtk.Template.Callback('continue')
|
||||
def _continue(self, button):
|
||||
global_state.advance(self)
|
||||
|
||||
@Gtk.Template.Callback('row_activated')
|
||||
def _row_activated(self, list_box, row):
|
||||
if type(row) == SelectionRow:
|
||||
row.flip_switch()
|
||||
|
||||
### public methods ###
|
||||
|
||||
def load_once(self):
|
||||
reset_model(self.model, self.list_provider())
|
||||
|
||||
def unload(self):
|
||||
summary = []
|
||||
keywords = []
|
||||
for row in self.choices_list:
|
||||
if type(row) == MultiSelectionRow:
|
||||
option = row.get_chosen_option()
|
||||
keywords.append(option.keyword)
|
||||
summary.append(SummaryEntry(option.display, row.icon_path))
|
||||
elif type(row) == SelectionRow and row.is_activated():
|
||||
keywords.append(row.info)
|
||||
summary.append(SummaryEntry(row.get_title(), row.icon_path))
|
||||
keywords = ' '.join(keywords)
|
||||
match self.type:
|
||||
case ChoiceType.software:
|
||||
global_state.set_config('chosen_software_packages', keywords)
|
||||
global_state.set_config('chosen_software', summary)
|
||||
|
||||
|
||||
SoftwarePage = lambda **args: ChoicesPage(ChoiceType.software, **args)
|
||||
@@ -1,67 +0,0 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from gi.repository import Gio, Gtk
|
||||
|
||||
from .choices_provider import get_software_suggestions
|
||||
from .global_state import global_state
|
||||
from .page import Page
|
||||
from .util import SummaryEntry
|
||||
from .widgets import MultiSelectionRow, reset_model, SelectionRow
|
||||
|
||||
|
||||
@Gtk.Template(resource_path='/com/github/p3732/os-installer/ui/pages/software.ui')
|
||||
class SoftwarePage(Gtk.Box, Page):
|
||||
__gtype_name__ = __qualname__
|
||||
image = 'system-software-install-symbolic'
|
||||
|
||||
software_list = Gtk.Template.Child()
|
||||
software_model = Gio.ListStore()
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
Gtk.Box.__init__(self, **kwargs)
|
||||
self.software_list.bind_model(
|
||||
self.software_model,
|
||||
self._create_row)
|
||||
|
||||
def _create_row(self, pkg):
|
||||
if pkg.options:
|
||||
return MultiSelectionRow(pkg.name, pkg.description, pkg.icon_path,
|
||||
'application-x-executable-symbolic', pkg.options)
|
||||
else:
|
||||
return SelectionRow(pkg.name, pkg.description, pkg.icon_path,
|
||||
'application-x-executable-symbolic', pkg.suggested, pkg.keyword)
|
||||
|
||||
def _setup_software(self):
|
||||
suggestions = get_software_suggestions()
|
||||
reset_model(self.software_model, suggestions)
|
||||
|
||||
### callbacks ###
|
||||
|
||||
@Gtk.Template.Callback('continue')
|
||||
def _continue(self, button):
|
||||
global_state.advance(self)
|
||||
|
||||
@Gtk.Template.Callback('software_row_activated')
|
||||
def _software_row_activated(self, list_box, row):
|
||||
if type(row) == SelectionRow:
|
||||
row.flip_switch()
|
||||
|
||||
### public methods ###
|
||||
|
||||
def load_once(self):
|
||||
self._setup_software()
|
||||
|
||||
def unload(self):
|
||||
summary = []
|
||||
packages = []
|
||||
for row in self.software_list:
|
||||
if type(row) == MultiSelectionRow:
|
||||
option = row.get_chosen_option()
|
||||
packages.append(option.keyword)
|
||||
summary.append(SummaryEntry(option.display, row.icon_path))
|
||||
elif type(row) == SelectionRow and row.is_activated():
|
||||
packages.append(row.info)
|
||||
summary.append(SummaryEntry(row.get_title(), row.icon_path))
|
||||
packages = ' '.join(packages)
|
||||
global_state.set_config('chosen_software_packages', packages)
|
||||
global_state.set_config('chosen_software', summary)
|
||||
@@ -8,6 +8,7 @@ from gi.repository import Gtk, Adw
|
||||
|
||||
from .global_state import global_state
|
||||
|
||||
from .choices import SoftwarePage
|
||||
from .confirm import ConfirmPage
|
||||
from .disk import DiskPage
|
||||
from .done import DonePage
|
||||
@@ -21,7 +22,6 @@ from .keyboard_layout import KeyboardLayoutPage
|
||||
from .language import LanguagePage
|
||||
from .locale import LocalePage
|
||||
from .restart import RestartPage
|
||||
from .software import SoftwarePage
|
||||
from .summary import SummaryPage
|
||||
from .timezone import TimezonePage
|
||||
from .user import UserPage
|
||||
|
||||
Reference in New Issue
Block a user