dictionaries 0.2.179

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of dictionaries might be problematic. Click here for more details.

Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +126 -0
  3. data/bin/dictionaries +7 -0
  4. data/dictionaries.gemspec +85 -0
  5. data/doc/README.gen +109 -0
  6. data/lib/dictionaries.rb +1 -0
  7. data/lib/dictionaries/ask_english_word.rb +135 -0
  8. data/lib/dictionaries/ask_italian_word.rb +84 -0
  9. data/lib/dictionaries/class/ask_word_from_dictionary.rb +693 -0
  10. data/lib/dictionaries/class/colours.rb +55 -0
  11. data/lib/dictionaries/class/constants.rb +16 -0
  12. data/lib/dictionaries/class/set_search_for_this_word.rb +163 -0
  13. data/lib/dictionaries/commandline/parse_commandline.rb +60 -0
  14. data/lib/dictionaries/constants.rb +133 -0
  15. data/lib/dictionaries/gui/gtk/constants.rb +25 -0
  16. data/lib/dictionaries/gui/gtk/dictionary.rb +330 -0
  17. data/lib/dictionaries/gui/tk/README.md +2 -0
  18. data/lib/dictionaries/gui/tk/dictionary.rb +85 -0
  19. data/lib/dictionaries/project/project_base_directory.rb +22 -0
  20. data/lib/dictionaries/project/project_yaml_directory.rb +23 -0
  21. data/lib/dictionaries/require_project/require_project.rb +10 -0
  22. data/lib/dictionaries/sinatra/app.rb +100 -0
  23. data/lib/dictionaries/sinatra/english_to_german.rb +81 -0
  24. data/lib/dictionaries/toplevel_methods/e.rb +16 -0
  25. data/lib/dictionaries/toplevel_methods/english_to_german.rb +31 -0
  26. data/lib/dictionaries/toplevel_methods/has_key.rb +32 -0
  27. data/lib/dictionaries/toplevel_methods/is_on_roebe.rb +16 -0
  28. data/lib/dictionaries/toplevel_methods/main_file.rb +88 -0
  29. data/lib/dictionaries/toplevel_methods/misc.rb +76 -0
  30. data/lib/dictionaries/toplevel_methods/module_methods.rb +9 -0
  31. data/lib/dictionaries/toplevel_methods/show_help.rb +30 -0
  32. data/lib/dictionaries/version/version.rb +17 -0
  33. data/lib/dictionaries/yaml/chinese.yml +19 -0
  34. data/lib/dictionaries/yaml/danish.yml +4 -0
  35. data/lib/dictionaries/yaml/deutsche_fremdwoerter.yml +1 -0
  36. data/lib/dictionaries/yaml/dutch.yml +3 -0
  37. data/lib/dictionaries/yaml/english.yml +2259 -0
  38. data/lib/dictionaries/yaml/farsi.yml +8 -0
  39. data/lib/dictionaries/yaml/finnish.yml +2 -0
  40. data/lib/dictionaries/yaml/italian.yml +499 -0
  41. data/lib/dictionaries/yaml/japanese.yml +15 -0
  42. data/lib/dictionaries/yaml/portugese.yml +42 -0
  43. data/lib/dictionaries/yaml/russian.yml +10 -0
  44. data/lib/dictionaries/yaml/spanish.yml +128 -0
  45. data/lib/dictionaries/yaml/swedish.yml +113 -0
  46. metadata +205 -0
@@ -0,0 +1,330 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === Dictionaries::GUI::Gtk::Dictionary
6
+ #
7
+ # This is a small GUI-wrapper.
8
+ # =========================================================================== #
9
+ # require 'dictionaries/gui/gtk/dictionary.rb'
10
+ # Dictionaries.gtk_widget
11
+ # =========================================================================== #
12
+ begin
13
+ require 'gtk_paradise/requires/require_the_base_module.rb'
14
+ rescue LoadError
15
+ puts 'error: gtk_paradise has a problem.'
16
+ end
17
+ require 'dictionaries/class/ask_word_from_dictionary.rb'
18
+ require 'dictionaries/gui/gtk/constants.rb'
19
+
20
+ module Dictionaries
21
+
22
+ module GUI
23
+
24
+ module Gtk
25
+
26
+ class Dictionary < ::Gtk::VBox
27
+
28
+ require 'dictionaries/toplevel_methods/e.rb'
29
+
30
+ include ::Gtk::BaseModule
31
+ include ::Colours
32
+
33
+ # ========================================================================= #
34
+ # === initialize
35
+ # ========================================================================= #
36
+ def initialize(
37
+ run_already = true
38
+ )
39
+ super()
40
+ reset
41
+ run if run_already
42
+ end
43
+
44
+ # ========================================================================= #
45
+ # === reset
46
+ # ========================================================================= #
47
+ def reset
48
+ # ======================================================================= #
49
+ # === @dictionaries
50
+ # ======================================================================= #
51
+ @dictionaries = Dictionaries.new(:do_not_run_yet)
52
+ Dictionaries.set_main_file(:default)
53
+ @dictionaries.load_the_english_file
54
+ set_gtk_font_size :default
55
+ end
56
+
57
+ # ========================================================================= #
58
+ # === e
59
+ # ========================================================================= #
60
+ def e(i = '')
61
+ ::Dictionaries.e(i)
62
+ end
63
+
64
+ # ========================================================================= #
65
+ # === add_ask_the_question_button
66
+ # ========================================================================= #
67
+ def add_ask_the_question_button
68
+ button = gtk_bold_button('Translate into german')
69
+ button.fancy_tooltip =
70
+ 'Click this button in order to <b>translate the english '\
71
+ 'word into the german equivalent word</b>.'
72
+ button.on_clicked {
73
+ button_pressed_so_try_to_convert_the_input
74
+ }
75
+ button.modify_background(:normal, :khaki) # ← default colour
76
+ button.modify_background(:prelight, :paleturquoise) # ← mouse-on-over events
77
+ button.modify_background(:active, :slategray) # ← colour on mouse-press-event
78
+ pack_start(button, false, true, 0)
79
+ end
80
+
81
+ # ========================================================================= #
82
+ # === create_input_field_on_top
83
+ #
84
+ # This is the main widget for user input. The user types in some
85
+ # words, and then hits the main button on the bottom, in order
86
+ # to translate the (english) word to german.
87
+ # ========================================================================= #
88
+ def create_input_field_on_top
89
+ text_for_the_label = 'Input an english word in the field below'
90
+ text = gtk_label(text_for_the_label)
91
+ text.set_markup(
92
+ '<span size="x-large" weight="bold">'+text_for_the_label+'</span>', true
93
+ )
94
+ # ======================================================================= #
95
+ # Add the "input field" next for the english word that is to
96
+ # be translated.
97
+ # ======================================================================= #
98
+ @input_field = gtk_input_field
99
+ completion = gtk_entry_completion
100
+ @input_field.completion = completion # Assign the completion.
101
+ completion_model = ::Gtk::ListStore.new(String)
102
+ @dictionaries.array.each { |word|
103
+ iter = completion_model.append
104
+ iter[0] = word
105
+ }
106
+ completion.model = completion_model
107
+ # ======================================================================= #
108
+ # Use model column 0 as the text column
109
+ # ======================================================================= #
110
+ completion.text_column = 0
111
+ @input_field.center
112
+ @input_field.signal_connect(:key_press_event) { |widget, event|
113
+ case Gdk::Keyval.to_name(event.keyval)
114
+ when 'Return', 'KP_Enter'
115
+ button_pressed_so_try_to_convert_the_input
116
+ end
117
+ }
118
+ hbox_holding_label_and_input_field = gtk_vbox(
119
+ text, @input_field
120
+ )
121
+ pack_start(hbox_holding_label_and_input_field, false, false, 4)
122
+ end
123
+
124
+ # ========================================================================= #
125
+ # === title?
126
+ # ========================================================================= #
127
+ def title?
128
+ 'Dictionary'
129
+ end
130
+
131
+ # ========================================================================= #
132
+ # === width?
133
+ # ========================================================================= #
134
+ def width?
135
+ WIDTH # Return the default width for our widget.
136
+ end
137
+
138
+ # ========================================================================= #
139
+ # === height?
140
+ # ========================================================================= #
141
+ def height?
142
+ HEIGHT # Return the default height for our widget.
143
+ end
144
+
145
+ # ========================================================================= #
146
+ # === create_answer_field
147
+ #
148
+ # This method builds up the "answer-widget".
149
+ # ========================================================================= #
150
+ def create_answer_field
151
+ @answer_field = gtk_input_field
152
+ @answer_field.center
153
+ end
154
+
155
+ # ========================================================================= #
156
+ # === button_pressed_so_try_to_convert_the_input (click tag)
157
+ #
158
+ # This action is called when the user clicks on the button.
159
+ # ========================================================================= #
160
+ def button_pressed_so_try_to_convert_the_input
161
+ user_input = @input_field.return_input
162
+ unless user_input.empty? # We check whether the user did input something.
163
+ translated_word = @dictionaries.translate(user_input)
164
+ e "#{sfancy(user_input)} → #{simp(translated_word)}"
165
+ @answer_field.set_text(translated_word)
166
+ end
167
+ end
168
+
169
+ # ========================================================================= #
170
+ # === create_skeleton
171
+ # ========================================================================= #
172
+ def create_skeleton
173
+ create_input_field_on_top
174
+ create_answer_field
175
+ create_the_statistics_frame
176
+ end
177
+
178
+ # ========================================================================= #
179
+ # === add_the_widget_for_remote_query_of_the_dictionary_at_leo (bottom tag)
180
+ #
181
+ # This is the bottom widget.
182
+ # ========================================================================= #
183
+ def add_the_widget_for_remote_query_of_the_dictionary_at_leo
184
+ bottom_vbox = gtk_vbox
185
+ bold_label = gtk_bold_label(
186
+ 'Query from a remote website instead (more entries available)'
187
+ )
188
+ bottom_vbox.pack_start(
189
+ bold_label, false, false
190
+ )
191
+ # This is the user-input entry at the bottom.
192
+ @entry_for_the_remote_query = gtk_entry
193
+ @entry_for_the_remote_query.center
194
+ @entry_for_the_remote_query.signal_connect(:key_press_event) { |widget, event|
195
+ case Gdk::Keyval.to_name(event.keyval)
196
+ when 'Return', 'KP_Enter'
197
+ do_perform_a_remote_query_to_the_leo_dictionary
198
+ end
199
+ }
200
+ bottom_vbox.pack_start(
201
+ @entry_for_the_remote_query, false, false
202
+ )
203
+ button_for_the_remote_query = gtk_button(
204
+ 'Query from a remote dictionary'
205
+ )
206
+ button_for_the_remote_query.fancy_tooltips =
207
+ 'This will <b>query the remote dictionary</b> at leo instead. '\
208
+ 'The <b>advantage</b> here is that the dataset at leo will '\
209
+ 'contain many more entries than does the knowledgebase '\
210
+ 'distributed with the <b>dictionaries gem</b>.'
211
+ button_for_the_remote_query.on_clicked {
212
+ do_perform_a_remote_query_to_the_leo_dictionary
213
+ }
214
+ @entry_at_the_bottom_showing_the_result_from_online_leo = gtk_entry
215
+ @entry_at_the_bottom_showing_the_result_from_online_leo.center
216
+ bottom_vbox.pack_start(
217
+ @entry_at_the_bottom_showing_the_result_from_online_leo, false, false
218
+ )
219
+ bottom_vbox.pack_start(
220
+ button_for_the_remote_query, false, false
221
+ )
222
+ pack_start(bottom_vbox)
223
+ end
224
+
225
+ # ========================================================================= #
226
+ # === connect_skeleton (skeleton tag, connect tag)
227
+ # ========================================================================= #
228
+ def connect_skeleton
229
+ pack_start(@answer_field, false) # <- Translation appears here.
230
+ add_ask_the_question_button
231
+ add_the_widget_for_remote_query_of_the_dictionary_at_leo
232
+ add_the_statistics_frame
233
+ end
234
+
235
+ # ========================================================================= #
236
+ # === add_the_statistics_frame
237
+ # ========================================================================= #
238
+ def add_the_statistics_frame
239
+ pack_start(@frame_statistics, true, true, 2)
240
+ end
241
+
242
+ # ========================================================================= #
243
+ # === run
244
+ # ========================================================================= #
245
+ def run
246
+ create_skeleton
247
+ connect_skeleton
248
+ update_the_statistics_frame
249
+ show_all
250
+ end
251
+
252
+ # ========================================================================= #
253
+ # === update_the_statistics_frame (update tag)
254
+ # ========================================================================= #
255
+ def update_the_statistics_frame(i = return_currently_selected_file)
256
+ @label_currently_selected_file.set_text(i)
257
+ end
258
+
259
+ # ========================================================================= #
260
+ # === do_perform_a_remote_query_to_the_leo_dictionary
261
+ # ========================================================================= #
262
+ def do_perform_a_remote_query_to_the_leo_dictionary(
263
+ i = @entry_for_the_remote_query.text.to_s
264
+ )
265
+ if i and !i.empty?
266
+ array = ::Dictionaries.return_array_of_translated_words_from_online_leo(i)
267
+ result = array.first
268
+ @entry_at_the_bottom_showing_the_result_from_online_leo.set_text(result)
269
+ end
270
+ end
271
+
272
+ # ========================================================================= #
273
+ # === create_the_statistics_frame
274
+ # ========================================================================= #
275
+ def create_the_statistics_frame
276
+ @frame_statistics = gtk_frame(' Statistics ')
277
+ @frame_statistics.make_bold
278
+ vbox = gtk_vbox
279
+ @label_currently_selected_file = gtk_label(return_currently_selected_file)
280
+ vbox.pack_start(
281
+ @label_currently_selected_file, false, true, 0
282
+ )
283
+ @frame_statistics.add(vbox)
284
+ end
285
+
286
+ # ========================================================================= #
287
+ # === return_currently_selected_file
288
+ # ========================================================================= #
289
+ def return_currently_selected_file
290
+ 'Currently selected file: '+
291
+ File.basename(
292
+ @dictionaries.currently_selected_file?.to_s
293
+ )
294
+ end
295
+
296
+ # ========================================================================= #
297
+ # === Dictionaries::GUI::Gtk::Dictionary.run
298
+ #
299
+ # Use this method if you wish to start a new gtk-application window.
300
+ # ========================================================================= #
301
+ def self.run
302
+ require 'gtk_paradise/run'
303
+ dictionary = new
304
+ r = ::Gtk::Runner.new
305
+ r.set_size_request(
306
+ dictionary.width?,
307
+ dictionary.height?
308
+ )
309
+ r.border_width = 10
310
+ r.top_left_then_run(use_this_widget: dictionary)
311
+ end
312
+
313
+ end; end; end
314
+
315
+ # =========================================================================== #
316
+ # === Dictionaries.gtk_widget
317
+ #
318
+ # This toplevel-method can be used to return the gtk-widget, which
319
+ # can then be embedded by other ruby-gtk applications, in particular
320
+ # admin_panel.rb of the gtk_paradise project.
321
+ # =========================================================================== #
322
+ def self.gtk_widget
323
+ Dictionaries::GUI::Gtk::Dictionary.new
324
+ end
325
+
326
+ end
327
+
328
+ if __FILE__ == $PROGRAM_NAME
329
+ Dictionaries::GUI::Gtk::Dictionary.run
330
+ end
@@ -0,0 +1,2 @@
1
+ This directory includes experimental tk code. The main GUI is
2
+ ruby-gtk, so this is just a fallback.
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === Dictionaries::GUI::Tk::Dictionary
6
+ #
7
+ # This is a small TK-wrapper.
8
+ # =========================================================================== #
9
+ # require 'dictionaries/gui/tk/dictionary.rb'
10
+ # =========================================================================== #
11
+ begin
12
+ require 'tk'
13
+ rescue LoadError; end
14
+ require 'dictionaries/class/ask_word_from_dictionary.rb'
15
+ require 'dictionaries/toplevel_methods/e.rb'
16
+
17
+ module Dictionaries
18
+
19
+ module GUI
20
+
21
+ module Tk
22
+
23
+ class Dictionary < ::TkFrame # < Base === Dictionaries::GUI::Tk::Dictionary.new
24
+
25
+ include Colours::E
26
+
27
+ # ========================================================================= #
28
+ # === initialize
29
+ # ========================================================================= #
30
+ def initialize(
31
+ i = nil,
32
+ run_already = true
33
+ )
34
+ super()
35
+ reset
36
+ set_input(i)
37
+ title "TK wrapper for the Dictionaries project"
38
+ run if run_already
39
+ end
40
+
41
+ # ========================================================================= #
42
+ # === reset (reset tag)
43
+ # ========================================================================= #
44
+ def reset
45
+ end
46
+
47
+ # ========================================================================= #
48
+ # === set_input
49
+ # ========================================================================= #
50
+ def set_input(i = '')
51
+ i = i.first if i.is_a? Array
52
+ i = i.to_s.dup
53
+ @input = i
54
+ end
55
+
56
+ # ========================================================================= #
57
+ # === input?
58
+ # ========================================================================= #
59
+ def input?
60
+ @input
61
+ end
62
+
63
+ # ========================================================================= #
64
+ # === run (run tag)
65
+ # ========================================================================= #
66
+ def run
67
+ TkLabel.new(root) do
68
+ text 'Hello, World!'
69
+ pack { padx 15 ; pady 15; side 'left' }
70
+ end
71
+ end
72
+
73
+ # ========================================================================= #
74
+ # === Dictionaries::GUI:Tk::Dictionary[]
75
+ # ========================================================================= #
76
+ def self.[](i = '')
77
+ self.new(i)
78
+ end
79
+
80
+ end; end; end; end
81
+
82
+ if __FILE__ == $PROGRAM_NAME
83
+ Dictionaries::GUI:Tk::Dictionary.new(ARGV)
84
+ ::Tk.mainloop
85
+ end # dictionary.rb
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'dictionaries/project/project_base_directory.rb'
6
+ # =========================================================================== #
7
+ module Dictionaries
8
+
9
+ # ========================================================================= #
10
+ # === Dictionaries::PROJECT_BASE_DIRECTORY
11
+ # ========================================================================= #
12
+ PROJECT_BASE_DIRECTORY =
13
+ File.absolute_path("#{__dir__}/..")+'/'
14
+
15
+ # ========================================================================= #
16
+ # === Dictionaries.project_base_dir?
17
+ # ========================================================================= #
18
+ def self.project_base_dir?
19
+ PROJECT_BASE_DIRECTORY
20
+ end
21
+
22
+ end
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # This file will point to the yaml directory of the Dictionaries project.
6
+ # =========================================================================== #
7
+ require 'dictionaries/project/project_base_directory.rb'
8
+
9
+ module Dictionaries # require 'dictionaries/project_base_directory.rb'
10
+
11
+ # ========================================================================= #
12
+ # === PROJECT_YAML_DIRECTORY
13
+ # ========================================================================= #
14
+ PROJECT_YAML_DIRECTORY = "#{PROJECT_BASE_DIRECTORY}yaml/"
15
+
16
+ # ========================================================================= #
17
+ # === Dictionaries.project_yaml_dir?
18
+ # ========================================================================= #
19
+ def self.project_yaml_dir?
20
+ PROJECT_YAML_DIRECTORY
21
+ end; self.instance_eval { alias dictionary_directory? project_yaml_dir? } # === Dictionaries.dictionary_directory?
22
+
23
+ end