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 =

Returns Error message when the UI backend is not available.

Returns:

  • (String)

    Error message when the UI backend is not available.

'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)


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.

Parameters:

  • message (Object)

    the message

  • priority (Object) (defaults to: :polite)

    the priority



80
81
82
# File 'lib/rosett_ai/ui/gtk4.rb', line 80

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

#display_table(headers, rows) ⇒ void

This method returns an undefined value.

Render a table in the UI backend.

Parameters:

  • headers (Object)

    the headers

  • rows (Object)

    the rows



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.

Parameters:

  • content (Object)

    the content



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.

Parameters:

  • _message (Object)

    the message



66
67
68
69
70
71
72
73
# File 'lib/rosett_ai/ui/gtk4.rb', line 66

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