smartdict-gtk 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/bin/smartdict-gtk CHANGED
@@ -4,8 +4,8 @@ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
4
  require 'rubygems'
5
5
 
6
6
  # For development
7
- # require 'bundler'
8
- # Bundler.setup(:default, :development)
7
+ require 'bundler'
8
+ Bundler.setup(:default, :development)
9
9
 
10
10
  require 'smartdict-core'
11
11
  require 'smartdict-icons'
data/lib/smartdict/gui.rb CHANGED
@@ -15,6 +15,7 @@ module Smartdict::Gui
15
15
  autoload :LangComboBox
16
16
  autoload :InterchangeButton
17
17
  autoload :ExportDialog
18
+ autoload :WordList
18
19
 
19
20
 
20
21
  LEFT_BOX_BUTTON_HEIGHT = 36
@@ -6,7 +6,7 @@ module Smartdict::Gui
6
6
  autoload :Config
7
7
 
8
8
  attr_reader :main_window, :word_entry, :translate_button, :menu_bar, :text_view, :status_icon,
9
- :from_lang_combo_box, :to_lang_combo_box, :interchange_button
9
+ :from_lang_combo_box, :to_lang_combo_box, :interchange_button, :word_list
10
10
 
11
11
  def initialize
12
12
  @main_window = MainWindow.new(self)
@@ -18,6 +18,7 @@ module Smartdict::Gui
18
18
  @from_lang_combo_box = LangComboBox.new(self, config.from_lang) {|lang| Smartdict::Translator.from_lang_code = lang }
19
19
  @to_lang_combo_box = LangComboBox.new(self, config.to_lang) {|lang| Smartdict::Translator.to_lang_code = lang }
20
20
  @interchange_button = InterchangeButton.new(self)
21
+ @word_list = WordList.new(self)
21
22
 
22
23
  #open_export_dialog
23
24
  #exit
@@ -37,10 +38,19 @@ module Smartdict::Gui
37
38
  word = @word_entry.text.strip.downcase
38
39
  translation = Smartdict::Translator.translate(word)
39
40
  @text_view.show_translation(translation)
41
+ @word_list.prepend_word(translation)
40
42
  rescue Smartdict::TranslationNotFound => err
41
43
  @text_view.buffer.text = err.message
42
44
  end
43
45
 
46
+ # @param [String] word
47
+ # @param [String] from_lang language code
48
+ # @param [String] to_lang language code
49
+ def translate_selected_word(word, from_lang, to_lang)
50
+ translation = Smartdict::Translator.translate(word)
51
+ @text_view.show_translation(translation)
52
+ end
53
+
44
54
  def toggle_main_window
45
55
  if @main_window.visible? and @main_window.active?
46
56
  @main_window.hide_all
@@ -2,7 +2,8 @@ class Smartdict::Gui::MainWindow < ::Gtk::Window
2
2
  extend Forwardable
3
3
 
4
4
  def_delegators :@controller, :menu_bar, :word_entry, :translate_button, :text_view,
5
- :from_lang_combo_box, :to_lang_combo_box, :interchange_button
5
+ :from_lang_combo_box, :to_lang_combo_box, :interchange_button,
6
+ :word_list
6
7
 
7
8
  def initialize(controller)
8
9
  super("Smartdict")
@@ -27,6 +28,7 @@ class Smartdict::Gui::MainWindow < ::Gtk::Window
27
28
  main_hpaned = Gtk::HPaned.new
28
29
 
29
30
  left_scrolled_win = Gtk::ScrolledWindow.new.
31
+ add(word_list).
30
32
  set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
31
33
 
32
34
  left_side_box = Gtk::VBox.new.
@@ -0,0 +1,47 @@
1
+ class Smartdict::Gui::WordList < ::Gtk::TreeView
2
+
3
+ class ListColumn < Gtk::TreeViewColumn
4
+ class << self
5
+ attr_accessor :column_counter
6
+ end
7
+ self.column_counter = 0
8
+
9
+ def initialize(title)
10
+ column_id = self.class.column_counter
11
+ self.class.column_counter += 1
12
+
13
+ super(title, Gtk::CellRendererText.new, :text => column_id) # call to base class
14
+
15
+ # set options of column
16
+ self.resizable = true
17
+ self.clickable = true
18
+ self.sort_indicator = false
19
+ self.sort_column_id = column_id
20
+ end
21
+ end
22
+
23
+
24
+
25
+ def initialize(controller)
26
+ @controller = controller
27
+
28
+ @list_model = Gtk::ListStore.new(String, String, String)
29
+ super(@list_model)
30
+
31
+ self.append_column(ListColumn.new("History"))
32
+
33
+ self.selection.signal_connect("changed"){
34
+ item = self.selection.selected
35
+ word, from_lang, to_lang = item[0], item[1], item[2]
36
+ @controller.translate_selected_word(word, from_lang, to_lang)
37
+ }
38
+ end
39
+
40
+ def prepend_word(translation)
41
+ item = @list_model.prepend
42
+ item[0] = translation.word
43
+ item[1] = translation.from_lang
44
+ item[2] = translation.to_lang
45
+ end
46
+
47
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartdict-gtk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-09 00:00:00.000000000 Z
12
+ date: 2012-04-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: smartdict-core
@@ -165,6 +165,7 @@ files:
165
165
  - ./lib/smartdict/gui/text_view/buffer.rb
166
166
  - ./lib/smartdict/gui/translate_button.rb
167
167
  - ./lib/smartdict/gui/word_entry.rb
168
+ - ./lib/smartdict/gui/word_list.rb
168
169
  - GPL-LICENSE.txt
169
170
  - README.markdown
170
171
  - !binary |-