dictionaries 0.2.182

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