Class: Kita::Application
- Inherits:
-
Gtk::Application
- Object
- Gtk::Application
- Kita::Application
- Includes:
- Menu
- Defined in:
- lib/kita.rb
Overview
LocaleSettings.new Main application class
Instance Method Summary collapse
- #build_main_window ⇒ Object
- #correct_button(buttons, question) ⇒ Object
- #ee ⇒ Object
-
#initialize ⇒ Application
constructor
A new instance of Application.
- #new_question ⇒ Object
- #repeat_button_click ⇒ Object
- #reset_buttons ⇒ Object
- #setup_about_box ⇒ Object
- #toggle_hiragana ⇒ Object
- #toggle_katakana ⇒ Object
- #toggle_sound ⇒ Object
- #wrong_button_click(button) ⇒ Object
- #wrong_buttons(buttons, question) ⇒ Object
Methods included from Menu
Constructor Details
#initialize ⇒ Application
Returns a new instance of Application.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/kita.rb', line 19 def initialize super 'uk.danbishop.kita', :handles_open # Construct a Gtk::Builder instance @builder = Gtk::Builder.new(file: "#{File.(File.dirname(__dir__))}/ui/builder.ui") # Set menu toggles to match settings # Now connect signals @builder.connect_signals { |handler| method(handler) } # Initiate Question class @question = Question.new @button_signals = {} @sound = Audio.new new_question setup_about_box build_main_window end |
Instance Method Details
#build_main_window ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/kita.rb', line 72 def build_main_window signal_connect :activate do # Connect signal handlers to the constructed widgets window = @builder['window'] window.signal_connect('destroy') { Gtk.main_quit } window.present end end |
#correct_button(buttons, question) ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/kita.rb', line 91 def (, question) # Choose random letter and remove it from array correct = .delete(.sample) = @builder["answer_#{correct}"] .set_label(question[:answer]) correct_signal = .signal_connect('clicked') do new_question end @button_signals[correct] = correct_signal end |
#ee ⇒ Object
67 68 69 70 |
# File 'lib/kita.rb', line 67 def ee @ee += 1 @sound.play('これは北です') if @ee == 3 end |
#new_question ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/kita.rb', line 81 def new_question question = @question.new_question @builder['question'].set_markup("<span font='72'>#{question[:question]}</span>") = %w[a b c d] (, question) (, question) @sound.play("#{question[:question].hiragana}#{[1, 2].sample}") if Settings.sound end |
#repeat_button_click ⇒ Object
46 47 48 |
# File 'lib/kita.rb', line 46 def @sound.repeat end |
#reset_buttons ⇒ Object
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/kita.rb', line 120 def return nil if @button_signals.empty? @button_signals.each do |letter, signal| = @builder["answer_#{letter}"] .signal_handler_disconnect(signal) .set_sensitive(true) end @button_signals = {} end |
#setup_about_box ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/kita.rb', line 36 def setup_about_box @ee = 0 about_box = @builder['about_box'] about_box.version = VERSION @builder['menu_about'].signal_connect('clicked') do about_box.run about_box.hide end end |
#toggle_hiragana ⇒ Object
56 57 58 59 60 |
# File 'lib/kita.rb', line 56 def toggle_hiragana Settings.hiragana = !Settings.hiragana (@builder['katakana_switch'].set_active(true) && Settings.katakana = true) if !Settings.katakana && !Settings.hiragana save_settings end |
#toggle_katakana ⇒ Object
50 51 52 53 54 |
# File 'lib/kita.rb', line 50 def toggle_katakana Settings.katakana = !Settings.katakana (@builder['hiragana_switch'].set_active(true) && Settings.hiragana = true) if !Settings.katakana && !Settings.hiragana save_settings end |
#toggle_sound ⇒ Object
62 63 64 65 |
# File 'lib/kita.rb', line 62 def toggle_sound Settings.sound = !Settings.sound save_settings end |
#wrong_button_click(button) ⇒ Object
111 112 113 114 115 116 117 118 |
# File 'lib/kita.rb', line 111 def () .set_sensitive(false) label = .child correction = @question.type == 'hiragana' ? .label.hiragana : .label.katakana label.set_markup( "<span color='#d40000'>#{.label} #{correction}</span>" ) end |
#wrong_buttons(buttons, question) ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'lib/kita.rb', line 102 def (, question) .each_with_index do |letter, i| = @builder.get_object("answer_#{letter}") .set_label(question[:choices][i]) signal = .signal_connect('clicked') { () } @button_signals[letter] = signal end end |