Skip to content

Port To Gtk4#24

Draft
Dakshsharma1108 wants to merge 2 commits intosugarlabs:masterfrom
Dakshsharma1108:gtk4
Draft

Port To Gtk4#24
Dakshsharma1108 wants to merge 2 commits intosugarlabs:masterfrom
Dakshsharma1108:gtk4

Conversation

@Dakshsharma1108
Copy link
Copy Markdown

@Dakshsharma1108 Dakshsharma1108 commented Mar 16, 2026

WIP: Migrate log activity to GTK4

Incrementally modernize the log activity by replacing deprecated GTK3
APIs with GTK4 equivalents. This is a work-in-progress refactoring being
applied in stages.

  • LogTreeNode class (GObject.Object) added for structured tree representation
    with node_id, display_name, logfile, and children (Gio.ListStore)

REMOVED (GTK3 only, not available in GTK4):

  • Gtk.TreeStore → replaced by Gio.ListStore (self._root_store)
  • Gtk.TreeView → replaced by Gtk.ListView (self._listview)
  • Gtk.TreeModelSort → replaced by manual _sort_node_list() helper
  • Gtk.TreeViewColumn → replaced by Gtk.SignalListItemFactory
  • GObject.GObject.init() → replaced by super().init()
  • _format_col() → replaced by _setup_tree_row_cb / _bind_tree_row_cb
  • _cursor_changed_cb() → replaced by _selection_changed_cb()
  • Gtk.Clipboard → replaced by Gdk.Display.get_default().get_clipboard()
  • toolbar.insert() → replaced by toolbar.append() (modern API)
  • Gtk.SearchEntry → replaced by custom iconentry.IconEntry
  • Gtk.VBox → replaced by Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
  • show_all() → replaced by show()

ADDED (new GTK4 / GIO APIs):

  • Gtk.TreeListModel → wraps the nested Gio.ListStore tree
  • Gtk.TreeExpander → renders expand/collapse arrows per row
  • Gtk.SingleSelection → selection model wired to Gtk.ListView
  • LogTreeNode (GObject) → new data-model node that holds children
  • _log_index dict → metadata cache (top_key, group_name, …)
  • Gio.FileMonitor → replaces deprecated gnomevfs / Sugar file
    watchers; stored in self._gio_monitors

Improved error handling:

  • Profile logs path creation with os.makedirs(exist_ok=True)
  • OSError exception handling with logging

Visual Changes:

After porting testing without sugar:
image

Replace deprecated GTK3 tree widgets and models with modern GTK4
equivalents. This migration modernizes the log file tree interface
while maintaining the same functionality.

REMOVED (GTK3 only, not available in GTK4):
  - Gtk.TreeStore           → replaced by Gio.ListStore (self._root_store)
  - Gtk.TreeView            → replaced by Gtk.ListView (self._listview)
  - Gtk.TreeModelSort       → replaced by manual _sort_node_list() helper
  - Gtk.TreeViewColumn      → replaced by Gtk.SignalListItemFactory
  - _format_col()           → replaced by _setup_tree_row_cb / _bind_tree_row_cb
  - _cursor_changed_cb()    → replaced by _selection_changed_cb()

ADDED (new GTK4 / GIO APIs):
  - Gtk.TreeListModel       → wraps the nested Gio.ListStore tree
  - Gtk.TreeExpander        → renders expand/collapse arrows per row
  - Gtk.SingleSelection     → selection model wired to Gtk.ListView
  - LogTreeNode (GObject)   → new data-model node that holds children
  - _log_index dict         → metadata cache (top_key, group_name, …)
  - Gio.FileMonitor         → replaces deprecated gnomevfs / Sugar file
                              watchers; stored in self._gio_monitors
@Dakshsharma1108 Dakshsharma1108 marked this pull request as draft March 16, 2026 18:07
@Dakshsharma1108
Copy link
Copy Markdown
Author

Have a look at this pr @MostlyKIGuess @chimosky

- Replace deprecated GTK3 APIs with GTK4 equivalents (Gtk.SearchEntry, Box, etc.)
- Use modern Python initialization patterns (super() instead of explicit __init__)
- Replace toolbar.insert() with toolbar.append() for better API consistency
- Replace VBox/HBox with modern Box and orientation API
- Update clipboard API from Gtk.Clipboard to Gdk.Display.get_default().get_clipboard()
- Add LogTreeNode class for structured log tree representation
- Remove deprecated screen configuration callbacks and responsive layout logic
- Improve error handling for profile logs directory creation
- Simplify UI construction with modern GTK patterns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant