import gi gi.require_version("Gtk", "4.0") gi.require_version("Adw", "1") from gi.repository import Adw, Gdk, Gtk class PartitioningPage(Adw.Bin): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Main Layout clamp = Adw.Clamp() clamp.set_maximum_size(800) self.set_child(clamp) box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) box.set_spacing(24) box.set_margin_top(24) box.set_margin_bottom(24) clamp.set_child(box) # Title title = Gtk.Label(label="Disk Configuration") title.add_css_class("title-1") box.append(title) descr = Gtk.Label( label="Review and modify the partition layout for your installation." ) descr.set_wrap(True) box.append(descr) # Selected Disk Info (Mock) disk_info_group = Adw.PreferencesGroup() disk_info_group.set_title("Selected Drive") box.append(disk_info_group) row = Adw.ActionRow() row.set_title("NVMe Samsung 970 EVO") row.set_subtitle("500 GB - /dev/nvme0n1") row.set_icon_name("drive-harddisk-solidstate-symbolic") disk_info_group.add(row) # Partition Bar (The "Horizontal Bar") bar_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) bar_box.set_spacing(12) box.append(bar_box) bar_label = Gtk.Label(label="Partition Layout", xalign=0) bar_label.add_css_class("heading") bar_box.append(bar_label) # The Visual Bar # We use a horizontal box with homogeneous=False visual_bar = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) visual_bar.add_css_class("card") # Gives it a border/background visual_bar.set_overflow(Gtk.Overflow.HIDDEN) visual_bar.set_size_request(-1, 60) # Height of the bar bar_box.append(visual_bar) # Segment 1: EFI seg1 = Gtk.Box() seg1.set_hexpand(False) seg1.set_size_request(50, -1) # Mock width for small partition seg1.add_css_class("accent") # Blue-ish usually # Add a tooltip or label inside? seg1.set_tooltip_text("/dev/nvme0n1p1 (EFI) - 512 MB") visual_bar.append(seg1) # Separator (optional, or just rely on boxes) # Segment 2: Root seg2 = Gtk.Box() seg2.set_hexpand(True) # Takes remaining space seg2.add_css_class("success") # Green-ish usually seg2.set_tooltip_text("/dev/nvme0n1p2 (Root) - 499.5 GB") visual_bar.append(seg2) # Legend legend_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) legend_box.set_spacing(12) legend_box.set_halign(Gtk.Align.CENTER) bar_box.append(legend_box) self.add_legend_item(legend_box, "accent", "EFI System") self.add_legend_item(legend_box, "success", "Root Filesystem") # Partition Table (Detailed List) part_list_group = Adw.PreferencesGroup() part_list_group.set_title("Partitions") box.append(part_list_group) p1 = Adw.ActionRow() p1.set_title("/dev/nvme0n1p1") p1.set_subtitle("EFI System Partition - FAT32") p1.add_suffix(Gtk.Label(label="512 MB")) part_list_group.add(p1) p2 = Adw.ActionRow() p2.set_title("/dev/nvme0n1p2") p2.set_subtitle("Root - Ext4") p2.add_suffix(Gtk.Label(label="499.5 GB")) part_list_group.add(p2) # Controls actions_group = Adw.PreferencesGroup() box.append(actions_group) btn_row = Adw.ActionRow() btn_row.set_title("Manual Partitioning") btn_row.set_subtitle("Open external partition editor (GParted)") edit_btn = Gtk.Button(label="Open Editor") edit_btn.set_valign(Gtk.Align.CENTER) btn_row.add_suffix(edit_btn) actions_group.add(btn_row) def add_legend_item(self, box, style_class, label_text): item = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) item.set_spacing(6) swatch = Gtk.Box() swatch.set_size_request(16, 16) swatch.add_css_class(style_class) swatch.add_css_class("circular") # Make it round if supported, or just a box label = Gtk.Label(label=label_text) item.append(swatch) item.append(label) box.append(item)