Class: RosettAi::Ui::Gtk4
Overview
GTK4 adapter using ruby-gnome gtk4 gem.
Implements all Base methods using native GTK4 widgets. Installed as part of the rosett-ai-gtk4 Debian package. Requires libgtk-4-dev and the gtk4 gem on the host system.
Methods raise RosettAi::Error with install instructions if the gem is not available at runtime.
Constant Summary collapse
- UNAVAILABLE_MESSAGE =
Returns Error message when the UI backend is not available.
'GTK4 adapter requires the gtk4 gem. Install: gem install gtk4'
Constants inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
-
#announce(message, priority: :polite) ⇒ void
Announce a message to the user via the UI backend.
-
#display_table(headers, rows) ⇒ void
Render a table in the UI backend.
-
#prompt_user(question, choices: nil) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument -- keyword name is part of public API.
-
#render(content) ⇒ void
Render content in the UI backend.
-
#show_spinner(_message) ⇒ void
Display a spinner during a long-running operation.
Methods inherited from Base
Class Method Details
.available? ⇒ Boolean
21 22 23 24 25 26 |
# File 'lib/rosett_ai/ui/gtk4.rb', line 21 def self.available? require 'gtk4' true rescue LoadError false end |
Instance Method Details
#announce(message, priority: :polite) ⇒ void
This method returns an undefined value.
Announce a message to the user via the UI backend.
80 81 82 |
# File 'lib/rosett_ai/ui/gtk4.rb', line 80 def announce(, priority: :polite) warn("[GTK4:#{priority}] #{}") end |
#display_table(headers, rows) ⇒ void
This method returns an undefined value.
Render a table in the UI backend.
45 46 47 48 49 50 |
# File 'lib/rosett_ai/ui/gtk4.rb', line 45 def display_table(headers, rows) require_gtk4! store = build_list_store(headers.length) populate_store(store, rows) build_tree_view(store, headers) end |
#prompt_user(question, choices: nil) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument -- keyword name is part of public API
52 53 54 55 56 57 58 59 60 |
# File 'lib/rosett_ai/ui/gtk4.rb', line 52 def prompt_user(question, choices: nil) # rubocop:disable Lint/UnusedMethodArgument -- keyword name is part of public API require_gtk4! dialog = ::Gtk::MessageDialog.new( message: question, buttons: :ok_cancel ) dialog.accessible_role = :dialog if dialog.respond_to?(:accessible_role=) dialog end |
#render(content) ⇒ void
This method returns an undefined value.
Render content in the UI backend.
32 33 34 35 36 37 38 |
# File 'lib/rosett_ai/ui/gtk4.rb', line 32 def render(content) require_gtk4! text_view = ::Gtk::TextView.new text_view.buffer.text = String(content) text_view.editable = false text_view end |
#show_spinner(_message) ⇒ void
This method returns an undefined value.
Display a spinner during a long-running operation.
66 67 68 69 70 71 72 73 |
# File 'lib/rosett_ai/ui/gtk4.rb', line 66 def show_spinner() require_gtk4! spinner = ::Gtk::Spinner.new spinner.start result = yield spinner.stop result end |