smartdict-gtk 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/smartdict/gui.rb +1 -0
- data/lib/smartdict/gui/controller.rb +36 -17
- data/lib/smartdict/gui/main_window.rb +2 -2
- data/lib/smartdict/gui/status_bar.rb +16 -0
- metadata +6 -8
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/lib/smartdict/gui.rb
CHANGED
@@ -8,7 +8,7 @@ module Smartdict::Gui
|
|
8
8
|
HISTORY_SIZE_ON_START = 50
|
9
9
|
|
10
10
|
attr_reader :main_window, :word_entry, :translate_button, :menu_bar, :text_view, :status_icon,
|
11
|
-
:from_lang_combo_box, :to_lang_combo_box, :interchange_button, :word_list
|
11
|
+
:from_lang_combo_box, :to_lang_combo_box, :interchange_button, :word_list, :status_bar
|
12
12
|
|
13
13
|
def_delegators :@main_window, :toggle_visibility, :hide_visibility, :show_visibility
|
14
14
|
|
@@ -25,6 +25,7 @@ module Smartdict::Gui
|
|
25
25
|
@menu_bar = MenuBar.new(self)
|
26
26
|
@text_view = TextView.new(self)
|
27
27
|
@status_icon = StatusIcon.new(self)
|
28
|
+
@status_bar = StatusBar.new(self)
|
28
29
|
@from_lang_combo_box = LangComboBox.new(self, config.from_lang) do |lang|
|
29
30
|
@translator.default_opts[:from_lang] = lang
|
30
31
|
end
|
@@ -34,7 +35,7 @@ module Smartdict::Gui
|
|
34
35
|
@interchange_button = InterchangeButton.new(self)
|
35
36
|
@word_list = WordList.new(self)
|
36
37
|
|
37
|
-
@
|
38
|
+
@db_mutex = Mutex.new
|
38
39
|
|
39
40
|
load_history
|
40
41
|
end
|
@@ -50,9 +51,23 @@ module Smartdict::Gui
|
|
50
51
|
end
|
51
52
|
|
52
53
|
def translate
|
53
|
-
|
54
|
-
|
55
|
-
|
54
|
+
word = @word_entry.text.strip.downcase
|
55
|
+
from_lang = @translator.default_opts[:from_lang]
|
56
|
+
to_lang = @translator.default_opts[:to_lang]
|
57
|
+
status_message = "Looking for \"#{word}\" ..."
|
58
|
+
|
59
|
+
safe_concurrent_run do
|
60
|
+
do_with_status(status_message) do
|
61
|
+
with_reported_exception do
|
62
|
+
if add_to_history?(word, from_lang, to_lang)
|
63
|
+
translation = @translator.translate(word)
|
64
|
+
add_to_history(translation)
|
65
|
+
else
|
66
|
+
translation = @translator.translate(word, :log => false)
|
67
|
+
end
|
68
|
+
@text_view.show_translation(translation)
|
69
|
+
@word_list.scroll_up
|
70
|
+
end
|
56
71
|
end
|
57
72
|
end
|
58
73
|
end
|
@@ -110,20 +125,24 @@ module Smartdict::Gui
|
|
110
125
|
end
|
111
126
|
end
|
112
127
|
|
113
|
-
def
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
if add_to_history?(word, from_lang, to_lang)
|
119
|
-
translation = @translator.translate(word)
|
120
|
-
add_to_history(translation)
|
121
|
-
else
|
122
|
-
translation = @translator.translate(word, :log => false)
|
128
|
+
def safe_concurrent_run
|
129
|
+
Thread.new do
|
130
|
+
@db_mutex.synchronize do
|
131
|
+
yield
|
132
|
+
end
|
123
133
|
end
|
134
|
+
end
|
124
135
|
|
125
|
-
|
126
|
-
@
|
136
|
+
def do_with_status(status_message)
|
137
|
+
context_id = @status_bar.get_context_id(status_message)
|
138
|
+
@status_bar.push(context_id, status_message)
|
139
|
+
yield
|
140
|
+
ensure
|
141
|
+
@status_bar.pop(context_id)
|
142
|
+
end
|
143
|
+
|
144
|
+
def with_reported_exception
|
145
|
+
yield
|
127
146
|
rescue Smartdict::TranslationNotFound => error
|
128
147
|
@text_view.buffer.text = error.message
|
129
148
|
rescue Exception => error
|
@@ -3,7 +3,7 @@ class Smartdict::Gui::MainWindow < ::Gtk::Window
|
|
3
3
|
|
4
4
|
def_delegators :@controller, :menu_bar, :word_entry, :translate_button, :text_view,
|
5
5
|
:from_lang_combo_box, :to_lang_combo_box, :interchange_button,
|
6
|
-
:word_list
|
6
|
+
:word_list, :status_bar
|
7
7
|
|
8
8
|
def initialize(controller)
|
9
9
|
super("Smartdict")
|
@@ -58,7 +58,7 @@ class Smartdict::Gui::MainWindow < ::Gtk::Window
|
|
58
58
|
add_child(Gtk::Builder.new, right_scrolled_win)
|
59
59
|
|
60
60
|
main_box.add(main_hpaned)
|
61
|
-
|
61
|
+
main_box.pack_start(status_bar, false, false)
|
62
62
|
|
63
63
|
add(main_box)
|
64
64
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Smartdict::Gui::StatusBar < ::Gtk::Statusbar
|
2
|
+
DEFAULT_MESSAGE = "Enter a word to look for a translation"
|
3
|
+
|
4
|
+
def initialize(controller)
|
5
|
+
super()
|
6
|
+
@controller = controller
|
7
|
+
push_default_message
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def push_default_message
|
13
|
+
context_id = get_context_id("default")
|
14
|
+
push(context_id, DEFAULT_MESSAGE)
|
15
|
+
end
|
16
|
+
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.1.
|
4
|
+
version: 0.1.4
|
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-08-
|
12
|
+
date: 2012-08-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: smartdict-core
|
@@ -192,6 +192,7 @@ files:
|
|
192
192
|
- ./lib/smartdict/gui/lang_combo_box.rb
|
193
193
|
- ./lib/smartdict/gui/main_window.rb
|
194
194
|
- ./lib/smartdict/gui/menu_bar.rb
|
195
|
+
- ./lib/smartdict/gui/status_bar.rb
|
195
196
|
- ./lib/smartdict/gui/status_icon.rb
|
196
197
|
- ./lib/smartdict/gui/text_view.rb
|
197
198
|
- ./lib/smartdict/gui/text_view/buffer.rb
|
@@ -204,9 +205,9 @@ files:
|
|
204
205
|
- README.markdown
|
205
206
|
- !binary |-
|
206
207
|
YmluL3NtYXJ0ZGljdC1ndGs=
|
207
|
-
homepage: http://
|
208
|
+
homepage: http://smartdict.net
|
208
209
|
licenses:
|
209
|
-
-
|
210
|
+
- GPL
|
210
211
|
post_install_message:
|
211
212
|
rdoc_options: []
|
212
213
|
require_paths:
|
@@ -217,9 +218,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
217
218
|
- - ! '>='
|
218
219
|
- !ruby/object:Gem::Version
|
219
220
|
version: '0'
|
220
|
-
segments:
|
221
|
-
- 0
|
222
|
-
hash: 3712988387274917201
|
223
221
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
224
222
|
none: false
|
225
223
|
requirements:
|
@@ -228,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
228
226
|
version: '0'
|
229
227
|
requirements: []
|
230
228
|
rubyforge_project:
|
231
|
-
rubygems_version: 1.8.
|
229
|
+
rubygems_version: 1.8.24
|
232
230
|
signing_key:
|
233
231
|
specification_version: 3
|
234
232
|
summary: GTK GUI for Smartdict dictionary
|