module RBT::GUI::Gtk

Constants

DATASET
#

DATASET

#
DEBUG
#

DEBUG

#
TITLE
#

TITLE

#
WIDTH
#

WIDTH

#

Public Class Methods

run() click to toggle source
#

RBT::Cookbooks::Gui::Gtk.run

#
# File lib/rbt/gui/gtk/box.rb, line 74
def self.run
  r = ::Gtk.runner
  available_programs = RBT.available_programs?
  main_box = ::Gtk.hbox
  @text_view_widget = ::Gtk.text_view_widget
  @text_view_widget.cursor_visible = true # cursor is nit mehr zu sehen.
  scrolled_windows = ::Gtk.scrolled_window(@text_view_widget)
  # ======================================================================= #
  # The combobox shall show all available programs. Whenever it is changed,
  # we will update the buffer of the text-view widget.
  # ======================================================================= #
  combobox = ::Gtk.combo_box
  combobox.fill(available_programs)
  combobox.active = 0
  # ======================================================================= #
  # Here is the signal that the combobox issues when it is changed.
  # ======================================================================= #
  combobox.signal_connect(:changed) {
    if combobox.active_iter
      text = combobox.active_text
      set_buffer_for_this_program(text)
    end
  } 
  main_box.pack_start(combobox, false, false, 2)
  main_box.pack_start(scrolled_windows, true, true, 2)
  main_box.show_all
  # ======================================================================= #
  # Adding the entry next.
  # ======================================================================= #
  entry = ::Gtk.entry 
  entry.set_activates_default(true)
  entry.signal_connect(:key_press_event) { |widget, event|
    if Gdk::Keyval.to_name(event.keyval) == 'Return'
      text = entry.text
      set_buffer_for_this_program(text)
    end
  }
  huge_box = ::Gtk.vbox
  huge_box << main_box
  huge_box.pack_start(entry, false, true, 2)
  r << huge_box
  r.width  = WIDTH
  r.height =  900
  r.title  = TITLE
  r.top_left.show_all.run
end
set_buffer_for_this_program(text) click to toggle source
#

Cookbooks::Gui::Gtk.set_buffer_for_this_program

#
# File lib/rbt/gui/gtk/box.rb, line 45
def self.set_buffer_for_this_program(text)
  e 'Now setting to the entry '+sfancy(text)+'.' if DEBUG
  text = text.to_sym
  if RBT.does_include? text
    # If the file ALL_PROGRAMS exists, we will use this.
    if File.exist? ALL_PROGRAMS
      dataset = DATASET[text.to_s]
    else
      # =================================================================== #
      # Next, ask the Cookbooks module directly for this dataset.
      # =================================================================== #
      dataset = RBT::Cookbooks::Cookbook.return_array(text) # This will return a Hash.
    end
    _ = ''.dup
    dataset.each_pair {|key, value|
      value = value.join if value.is_a? Array
      _ << key+': '+value.to_s+"\n"
    }
    @text_view_widget.buffer.set_buffer(_)
  else
    if DEBUG
      e 'RBT::Cookbooks::Cookbook does not include '+sfancy(text.to_s)+'.'
    end
  end
end