Class: Smartdict::Gui::Controller
- Inherits:
-
Object
- Object
- Smartdict::Gui::Controller
- Extended by:
- ActiveSupport::Autoload, Forwardable
- Defined in:
- lib/smartdict/gui/controller.rb
Defined Under Namespace
Classes: Config
Constant Summary collapse
- HISTORY_SIZE_ON_START =
50
Instance Attribute Summary collapse
-
#from_lang_combo_box ⇒ Object
readonly
Returns the value of attribute from_lang_combo_box.
-
#interchange_button ⇒ Object
readonly
Returns the value of attribute interchange_button.
-
#main_window ⇒ Object
readonly
Returns the value of attribute main_window.
-
#menu_bar ⇒ Object
readonly
Returns the value of attribute menu_bar.
-
#status_bar ⇒ Object
readonly
Returns the value of attribute status_bar.
-
#status_icon ⇒ Object
readonly
Returns the value of attribute status_icon.
-
#text_view ⇒ Object
readonly
Returns the value of attribute text_view.
-
#to_lang_combo_box ⇒ Object
readonly
Returns the value of attribute to_lang_combo_box.
-
#translate_button ⇒ Object
readonly
Returns the value of attribute translate_button.
-
#word_entry ⇒ Object
readonly
Returns the value of attribute word_entry.
-
#word_list ⇒ Object
readonly
Returns the value of attribute word_list.
Instance Method Summary collapse
- #export_translations(format_name, file_path, options = {}) ⇒ Object
- #focus_word_entry ⇒ Object
-
#initialize ⇒ Controller
constructor
A new instance of Controller.
- #interchange_langs ⇒ Object
- #open_about_window ⇒ Object
- #open_export_dialog ⇒ Object
- #quit ⇒ Object
- #run ⇒ Object
- #translate ⇒ Object
- #translate_selected_word(word, from_lang, to_lang) ⇒ Object
Constructor Details
#initialize ⇒ Controller
Returns a new instance of Controller.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/smartdict/gui/controller.rb', line 15 def initialize @translator = Smartdict::Translator.new( :from_lang => config.from_lang, :to_lang => config.to_lang, :log => true ) @main_window = MainWindow.new(self) @word_entry = WordEntry.new(self) @translate_button = TranslateButton.new(self) @menu_bar = MenuBar.new(self) @text_view = TextView.new(self) @status_icon = StatusIcon.new(self) @status_bar = StatusBar.new(self) @from_lang_combo_box = LangComboBox.new(self, config.from_lang) do |lang| @translator.default_opts[:from_lang] = lang end @to_lang_combo_box = LangComboBox.new(self, config.to_lang) do |lang| @translator.default_opts[:to_lang] = lang end @interchange_button = InterchangeButton.new(self) @word_list = WordList.new(self) @db_mutex = Mutex.new load_history end |
Instance Attribute Details
#from_lang_combo_box ⇒ Object (readonly)
Returns the value of attribute from_lang_combo_box.
10 11 12 |
# File 'lib/smartdict/gui/controller.rb', line 10 def from_lang_combo_box @from_lang_combo_box end |
#interchange_button ⇒ Object (readonly)
Returns the value of attribute interchange_button.
10 11 12 |
# File 'lib/smartdict/gui/controller.rb', line 10 def @interchange_button end |
#main_window ⇒ Object (readonly)
Returns the value of attribute main_window.
10 11 12 |
# File 'lib/smartdict/gui/controller.rb', line 10 def main_window @main_window end |
#menu_bar ⇒ Object (readonly)
Returns the value of attribute menu_bar.
10 11 12 |
# File 'lib/smartdict/gui/controller.rb', line 10 def @menu_bar end |
#status_bar ⇒ Object (readonly)
Returns the value of attribute status_bar.
10 11 12 |
# File 'lib/smartdict/gui/controller.rb', line 10 def @status_bar end |
#status_icon ⇒ Object (readonly)
Returns the value of attribute status_icon.
10 11 12 |
# File 'lib/smartdict/gui/controller.rb', line 10 def status_icon @status_icon end |
#text_view ⇒ Object (readonly)
Returns the value of attribute text_view.
10 11 12 |
# File 'lib/smartdict/gui/controller.rb', line 10 def text_view @text_view end |
#to_lang_combo_box ⇒ Object (readonly)
Returns the value of attribute to_lang_combo_box.
10 11 12 |
# File 'lib/smartdict/gui/controller.rb', line 10 def to_lang_combo_box @to_lang_combo_box end |
#translate_button ⇒ Object (readonly)
Returns the value of attribute translate_button.
10 11 12 |
# File 'lib/smartdict/gui/controller.rb', line 10 def @translate_button end |
#word_entry ⇒ Object (readonly)
Returns the value of attribute word_entry.
10 11 12 |
# File 'lib/smartdict/gui/controller.rb', line 10 def word_entry @word_entry end |
#word_list ⇒ Object (readonly)
Returns the value of attribute word_list.
10 11 12 |
# File 'lib/smartdict/gui/controller.rb', line 10 def word_list @word_list end |
Instance Method Details
#export_translations(format_name, file_path, options = {}) ⇒ Object
91 92 93 94 95 96 |
# File 'lib/smartdict/gui/controller.rb', line 91 def export_translations(format_name, file_path, = {}) format = Smartdict::Core::FormatManager.find(format_name) translations = Smartdict::Log.fetch() content = format.format_list(translations) File.open(file_path, 'w') { |file| file.write content } end |
#focus_word_entry ⇒ Object
102 103 104 |
# File 'lib/smartdict/gui/controller.rb', line 102 def focus_word_entry @word_entry.grab_focus end |
#interchange_langs ⇒ Object
98 99 100 |
# File 'lib/smartdict/gui/controller.rb', line 98 def interchange_langs @to_lang_combo_box.active, @from_lang_combo_box.active = @from_lang_combo_box.active, @to_lang_combo_box.active end |
#open_about_window ⇒ Object
83 84 85 |
# File 'lib/smartdict/gui/controller.rb', line 83 def open_about_window AboutWindow.new end |
#open_export_dialog ⇒ Object
87 88 89 |
# File 'lib/smartdict/gui/controller.rb', line 87 def open_export_dialog ExportDialog.new(self) end |
#quit ⇒ Object
49 50 51 |
# File 'lib/smartdict/gui/controller.rb', line 49 def quit ::Gtk.main_quit end |
#run ⇒ Object
43 44 45 46 47 |
# File 'lib/smartdict/gui/controller.rb', line 43 def run @main_window.draw_window @main_window.show_all Gtk.main end |
#translate ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/smartdict/gui/controller.rb', line 53 def translate word = @word_entry.text.strip.downcase from_lang = @translator.default_opts[:from_lang] to_lang = @translator.default_opts[:to_lang] = "Looking for \"#{word}\" ..." safe_concurrent_run do do_with_status() do with_reported_exception do if add_to_history?(word, from_lang, to_lang) translation = @translator.translate(word) add_to_history(translation) else translation = @translator.translate(word, :log => false) end @text_view.show_translation(translation) @word_list.scroll_up end end end end |
#translate_selected_word(word, from_lang, to_lang) ⇒ Object
78 79 80 81 |
# File 'lib/smartdict/gui/controller.rb', line 78 def translate_selected_word(word, from_lang, to_lang) translation = @translator.translate(word, :log => false) @text_view.show_translation(translation) end |