class Dictionaries::GUI::Gtk::Dictionary

Constants

HEIGHT
#

HEIGHT

#
NAMESPACE
#

NAMESPACE

#
SMALLER_FONT
#

SMALLER_FONT

This one should be relative to the font used above.

#
TITLE
#

TITLE

#
USE_THIS_FONT
#

USE_THIS_FONT

#
WIDTH
#

WIDTH

#

Public Class Methods

new( commandline_arguments = ARGV, run_already = true ) click to toggle source
#

initialize

#
Calls superclass method
# File lib/dictionaries/gui/gtk3/dictionary/dictionary.rb, line 62
def initialize(
    commandline_arguments = ARGV,
    run_already           = true
  )
  super(:vertical)
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  run if run_already
end
run( i = ARGV ) click to toggle source
#

Dictionaries::GUI::Gtk::Dictionary.run

Use this method if you wish to start a new gtk-application window.

#
# File lib/dictionaries/gui/gtk3/dictionary/dictionary.rb, line 427
def self.run(
    i = ARGV
  )
  require 'gtk_paradise/app/app.rb'
  _ = ::Dictionaries::GUI::Gtk::Dictionary.new(i)
  r = ::Gtk.run
  r << _
  r.automatic_size_then_automatic_title
  r.enable_quick_exit
  r.border_width = 12
  r.top_left_then_run
end

Public Instance Methods

add_ask_the_question_button() click to toggle source
#

add_ask_the_question_button

#
# File lib/dictionaries/gui/gtk3/dictionary/dictionary.rb, line 132
def add_ask_the_question_button
  button = bold_button('_Translate into german')
  button.clear_background
  button.bblack2
  button.hint =
    'Click this button in order to <b>translate the english '\
    'word into the german equivalent word</b>.'
  button.on_clicked {
    button_pressed_so_try_to_convert_the_input
  }
  @array_style_these_buttons << button
  hbox1 = gtk_hbox
  hbox1.minimal(button, 1)
  hbox1.halign_center
  minimal(hbox1, 5)
end
add_the_answer_field() click to toggle source
#

add_the_answer_field

#
# File lib/dictionaries/gui/gtk3/dictionary/dictionary.rb, line 396
def add_the_answer_field
  minimal(@answer_field) # ← Translation appears here.
end
add_the_header_bar() click to toggle source
#

add_the_header_bar

#
# File lib/dictionaries/gui/gtk3/dictionary/dictionary.rb, line 382
def add_the_header_bar
  minimal(@header_bar, 1)
end
add_the_statistics_frame() click to toggle source
#

add_the_statistics_frame

#
# File lib/dictionaries/gui/gtk3/dictionary/dictionary.rb, line 389
def add_the_statistics_frame
  maximal(@frame_statistics, 2)
end
add_the_widget_for_remote_query_of_the_dictionary_at_leo() click to toggle source
#

add_the_widget_for_remote_query_of_the_dictionary_at_leo (bottom tag)

This is the bottom widget.

#
# File lib/dictionaries/gui/gtk3/dictionary/dictionary.rb, line 184
def add_the_widget_for_remote_query_of_the_dictionary_at_leo
  bottom_vbox = gtk_vbox
  bold_label = gtk_bold_label(
    'Query from a remote website instead (more entries available)'
  ) 
  bottom_vbox.minimal(bold_label, 15)
  # This is the user-input entry at the bottom.
  @entry_for_the_remote_query = gtk_entry
  @entry_for_the_remote_query.center
  @entry_for_the_remote_query.on_key_press_event { |widget, event|
    case Gdk::Keyval.to_name(event.keyval) 
    when 'Return', 'KP_Enter'
      do_perform_a_remote_query_to_the_leo_dictionary
    end
  }
  bottom_vbox.minimal(@entry_for_the_remote_query)
  # ======================================================================= #
  # === button_for_the_remote_query
  # ======================================================================= #
  button_for_the_remote_query = button(
    '_Query from a remote dictionary'
  )
  button_for_the_remote_query.clear_background
  button_for_the_remote_query.bblack2
  button_for_the_remote_query.make_bold
  button_for_the_remote_query.hint = 
    'This will <b>query the remote dictionary</b> at leo instead. '\
    'The <b>advantage</b> here is that the dataset at leo will '\
    'contain many more entries than does the knowledgebase '\
    'distributed with the <b>dictionaries gem</b>.'
  button_for_the_remote_query.on_clicked {
    do_perform_a_remote_query_to_the_leo_dictionary
  }
  bottom_vbox.minimal(
    @entry_at_the_bottom_showing_the_result_from_online_leo, 2
  )
  @array_style_these_buttons << button_for_the_remote_query
  small_hbox = gtk_hbox
  small_hbox.minimal(button_for_the_remote_query, 1)
  small_hbox.halign_center
  bottom_vbox.minimal(
    small_hbox, 2
  )
  maximal(bottom_vbox, 2)
end
border_size?() click to toggle source
#

border_size?

#
# File lib/dictionaries/gui/gtk3/dictionary/dictionary.rb, line 118
def border_size?
  2
end
button_pressed_so_try_to_convert_the_input() click to toggle source
#

button_pressed_so_try_to_convert_the_input (click tag)

This action is called when the user clicks on the button.

#
# File lib/dictionaries/gui/gtk3/dictionary/dictionary.rb, line 169
def button_pressed_so_try_to_convert_the_input
  user_input = @input_field.return_input
  unless user_input.empty? # We check whether the user did input something.
    translated_word = @dictionaries.translate(user_input)
    e "#{::Colours.sfancy(user_input)} → "\
      "#{::Colours.simp(translated_word)}"
    @answer_field.set_text(translated_word)
  end
end
connect_skeleton() click to toggle source
#

connect_skeleton (connect tag)

#
# File lib/dictionaries/gui/gtk3/dictionary/dictionary.rb, line 403
def connect_skeleton
  abort_on_exception
  add_the_answer_field
  add_ask_the_question_button
  add_the_widget_for_remote_query_of_the_dictionary_at_leo
  add_the_statistics_frame
end
create_answer_field() click to toggle source
#

create_answer_field

This method builds up the “answer-widget”.

#
# File lib/dictionaries/gui/gtk3/dictionary/dictionary.rb, line 154
def create_answer_field
  # ======================================================================= #
  # === @answer_field
  # ======================================================================= #
  @answer_field = gtk_input_field
  @answer_field.center
  @answer_field.hint = 'The translated string may appear here.'
  @answer_field.very_light_yellow_background
end
create_input_field_on_top() click to toggle source
#

create_input_field_on_top

This is the main widget for user input. The user types in some words, and then hits the main button on the bottom, in order to translate the (english) word to german.

#
# File lib/dictionaries/gui/gtk3/dictionary/dictionary.rb, line 286
def create_input_field_on_top
  text_for_the_label = 'Input an english word in the field below'
  text = gtk_label(text_for_the_label)
  text.slateblue
  text.set_markup(
    '<span size="x-large" weight="bold">'+text_for_the_label+'</span>',
    use_underline: true
  )
  # ======================================================================= #
  # Add the "input field" next for the english word that is to
  # be translated.
  # ======================================================================= #
  @input_field = gtk_input_field
  @input_field.hint = 'Input the word that should be translated '\
    'here. Then, press the "enter" key or the button '\
    '"Translate into german" below.'
  @input_field.very_light_yellow_background
  completion = gtk_entry_completion
  @input_field.completion = completion # Assign the completion.
  completion_model = gtk_list_store(String)
  @dictionaries.array.each { |word|
    iter = completion_model.append
    iter[0] = word
  }
  completion.model = completion_model
  # ======================================================================= #
  # Use model column 0 as the text column
  # ======================================================================= #
  completion.text_column = 0
  @input_field.center
  @input_field.on_key_press_event { |widget, event|
    case Gdk::Keyval.to_name(event.keyval) 
    when 'Return', 'KP_Enter'
      button_pressed_so_try_to_convert_the_input
    end
  }
  hbox_holding_label_and_input_field = gtk_vbox(
    text, @input_field
  )
  minimal(hbox_holding_label_and_input_field, 2)
end
create_skeleton() click to toggle source
#

create_skeleton (create tag, skeleton tag)

#
# File lib/dictionaries/gui/gtk3/dictionary/dictionary.rb, line 359
def create_skeleton
  create_the_entries
  create_the_header_bar
  add_the_header_bar
  create_input_field_on_top
  create_answer_field
  create_the_statistics_frame
end
create_the_entries() click to toggle source
#

create_the_entries (entries tag, entry tag)

#
# File lib/dictionaries/gui/gtk3/dictionary/dictionary.rb, line 371
def create_the_entries
  # ======================================================================= #
  # === @entry_at_the_bottom_showing_the_result_from_online_leo
  # ======================================================================= #
  @entry_at_the_bottom_showing_the_result_from_online_leo = gtk_entry
  @entry_at_the_bottom_showing_the_result_from_online_leo.center
end
create_the_header_bar() click to toggle source
#

create_the_header_bar

#
# File lib/dictionaries/gui/gtk3/dictionary/dictionary.rb, line 348
def create_the_header_bar
  # ======================================================================= #
  # === @header_bar
  # ======================================================================= #
  @header_bar = default_header_bar
  @header_bar.title = 'Dictionary'
end
create_the_statistics_frame() click to toggle source
#

create_the_statistics_frame

#
# File lib/dictionaries/gui/gtk3/dictionary/dictionary.rb, line 254
def create_the_statistics_frame
  # ======================================================================= #
  # === @frame_statistics
  # ======================================================================= #
  @frame_statistics = gtk_frame(' Statistics ')
  @frame_statistics.make_bold
  @frame_statistics.use_this_font = smaller_font?
  vbox = gtk_vbox
  @label_currently_selected_file = gtk_label(return_currently_selected_file)
  vbox.minimal(
    @label_currently_selected_file, 0
  )
  @frame_statistics.add(vbox)
end
do_perform_a_remote_query_to_the_leo_dictionary( i = @entry_for_the_remote_query.text.to_s ) click to toggle source
#

do_perform_a_remote_query_to_the_leo_dictionary

#
# File lib/dictionaries/gui/gtk3/dictionary/dictionary.rb, line 241
def do_perform_a_remote_query_to_the_leo_dictionary(
    i = @entry_for_the_remote_query.text.to_s
  )
  if i and !i.empty?
    array = ::Dictionaries.return_array_of_translated_words_from_online_leo(i)
    result = array.first
    @entry_at_the_bottom_showing_the_result_from_online_leo.set_text(result)
  end
end
do_style_the_important_buttons() click to toggle source
#

do_style_the_important_buttons

#
# File lib/dictionaries/gui/gtk3/dictionary/dictionary.rb, line 414
def do_style_the_important_buttons
  @array_style_these_buttons.each {|this_button|
    this_button.modify_background(:normal,   :khaki)         # ← default colour
    this_button.modify_background(:prelight, :paleturquoise) # ← mouse-on-over events
    this_button.modify_background(:active,   :slategray)     # ← colour on mouse-press-event
  }
end
e(i = '') click to toggle source
#

e

#
# File lib/dictionaries/gui/gtk3/dictionary/dictionary.rb, line 125
def e(i = '')
  ::Dictionaries.e(i)
end
handle_CSS() click to toggle source
#

handle_CSS

#
# File lib/dictionaries/gui/gtk3/dictionary/dictionary.rb, line 104
def handle_CSS
  use_gtk_paradise_project_css_file
end
padding?() click to toggle source
#

padding?

#
# File lib/dictionaries/gui/gtk3/dictionary/dictionary.rb, line 111
def padding?
  2
end
reset() click to toggle source
#

reset (reset tag)

#
# File lib/dictionaries/gui/gtk3/dictionary/dictionary.rb, line 77
def reset
  reset_the_internal_variables
  # ======================================================================= #
  # === @configuration
  # ======================================================================= #
  @configuration = [true, __dir__, NAMESPACE]
  # ======================================================================= #
  # === Set the title, width, height and the font in use.
  # ======================================================================= #
  title_width_height_font(TITLE, WIDTH, HEIGHT, USE_THIS_FONT)
  infer_the_size_automatically
  # ======================================================================= #
  # === @dictionaries
  # ======================================================================= #
  @dictionaries = Dictionaries.new(:do_not_run_yet)
  Dictionaries.set_main_file(:default)
  @dictionaries.load_the_english_file
  # ======================================================================= #
  # === @array_style_these_buttons
  # ======================================================================= #
  @array_style_these_buttons = []
  handle_CSS
end
return_currently_selected_file() click to toggle source
#

return_currently_selected_file

#
# File lib/dictionaries/gui/gtk3/dictionary/dictionary.rb, line 272
def return_currently_selected_file
  'Currently selected file: <b>'+
  File.basename(
    @dictionaries.currently_selected_file?.to_s
  )+'</b>'
end
run() click to toggle source
#

run (run tag)

#
Calls superclass method
# File lib/dictionaries/gui/gtk3/dictionary/dictionary.rb, line 331
def run
  super()
  update_the_statistics_frame
  do_style_the_important_buttons
  show_all
end
smaller_font?() click to toggle source
#

smaller_font?

#
# File lib/dictionaries/gui/gtk3/dictionary/dictionary.rb, line 341
def smaller_font?
  SMALLER_FONT
end
update_the_statistics_frame(i = return_currently_selected_file) click to toggle source
#

update_the_statistics_frame (update tag)

#
# File lib/dictionaries/gui/gtk3/dictionary/dictionary.rb, line 233
def update_the_statistics_frame(i = return_currently_selected_file)
  @label_currently_selected_file.set_text(i)
  @label_currently_selected_file.do_markify
end