Class: RosettAi::Ui::Gtk4

Inherits:
Base
  • Object
show all
Defined in:
lib/rosett_ai/ui/gtk4.rb

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 =
'GTK4 adapter requires the gtk4 gem. Install: gem install gtk4'

Constants inherited from Base

Base::RTL_LOCALES

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#accessible?, #text_direction

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
# File 'lib/rosett_ai/ui/gtk4.rb', line 20

def self.available?
  require 'gtk4'
  true
rescue LoadError
  false
end

Instance Method Details

#announce(message, priority: :polite) ⇒ Object



61
62
63
# File 'lib/rosett_ai/ui/gtk4.rb', line 61

def announce(message, priority: :polite)
  warn("[GTK4:#{priority}] #{message}")
end

#display_table(headers, rows) ⇒ Object



35
36
37
38
39
40
# File 'lib/rosett_ai/ui/gtk4.rb', line 35

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



42
43
44
45
46
47
48
49
50
# File 'lib/rosett_ai/ui/gtk4.rb', line 42

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) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/rosett_ai/ui/gtk4.rb', line 27

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) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/rosett_ai/ui/gtk4.rb', line 52

def show_spinner(_message)
  require_gtk4!
  spinner = ::Gtk::Spinner.new
  spinner.start
  result = yield
  spinner.stop
  result
end