dictionaries 0.3.24
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.
- checksums.yaml +7 -0
- data/README.md +250 -0
- data/bin/dictionaries +7 -0
- data/bin/unique_words_in_this_file +7 -0
- data/dictionaries.gemspec +85 -0
- data/doc/README.gen +210 -0
- data/doc/todo/todo.md +5 -0
- data/lib/dictionaries/ask_english_word.rb +141 -0
- data/lib/dictionaries/ask_italian_word.rb +84 -0
- data/lib/dictionaries/class/ask_word_from_dictionary.rb +693 -0
- data/lib/dictionaries/class/colours.rb +55 -0
- data/lib/dictionaries/class/constants.rb +16 -0
- data/lib/dictionaries/class/set_search_for_this_word.rb +163 -0
- data/lib/dictionaries/commandline/parse_commandline.rb +75 -0
- data/lib/dictionaries/constants.rb +133 -0
- data/lib/dictionaries/gui/gtk3/dictionary/dictionary.rb +457 -0
- data/lib/dictionaries/gui/tk/README.md +2 -0
- data/lib/dictionaries/gui/tk/dictionary.rb +85 -0
- data/lib/dictionaries/helper_module/helper_module.rb +60 -0
- data/lib/dictionaries/project/project.rb +36 -0
- data/lib/dictionaries/require_project/require_project.rb +14 -0
- data/lib/dictionaries/sinatra/app.rb +118 -0
- data/lib/dictionaries/sinatra/english_to_german.rb +84 -0
- data/lib/dictionaries/statistics/statistics.rb +58 -0
- data/lib/dictionaries/toplevel_methods/e.rb +16 -0
- data/lib/dictionaries/toplevel_methods/english_to_german.rb +31 -0
- data/lib/dictionaries/toplevel_methods/has_key.rb +32 -0
- data/lib/dictionaries/toplevel_methods/is_on_roebe.rb +16 -0
- data/lib/dictionaries/toplevel_methods/main_file.rb +88 -0
- data/lib/dictionaries/toplevel_methods/misc.rb +185 -0
- data/lib/dictionaries/toplevel_methods/module_methods.rb +9 -0
- data/lib/dictionaries/toplevel_methods/show_help.rb +31 -0
- data/lib/dictionaries/version/version.rb +19 -0
- data/lib/dictionaries/yaml/chinese.yml +25 -0
- data/lib/dictionaries/yaml/danish.yml +4 -0
- data/lib/dictionaries/yaml/deutsche_fremdw/303/266rter.yml +1 -0
- data/lib/dictionaries/yaml/dutch.yml +3 -0
- data/lib/dictionaries/yaml/english.yml +2661 -0
- data/lib/dictionaries/yaml/farsi.yml +8 -0
- data/lib/dictionaries/yaml/finnish.yml +2 -0
- data/lib/dictionaries/yaml/italian.yml +532 -0
- data/lib/dictionaries/yaml/japanese.yml +15 -0
- data/lib/dictionaries/yaml/norwegian.yml +26 -0
- data/lib/dictionaries/yaml/portugese.yml +41 -0
- data/lib/dictionaries/yaml/russian.yml +10 -0
- data/lib/dictionaries/yaml/spanish.yml +133 -0
- data/lib/dictionaries/yaml/swedish.yml +104 -0
- data/lib/dictionaries.rb +1 -0
- metadata +209 -0
@@ -0,0 +1,457 @@
|
|
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/dictionaries/dictionaries.rb'
|
8
|
+
# Dictionaries::GUI::Gtk::Dictionary.run
|
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 # === Dictionaries::GUI::Gtk::Dictionary
|
19
|
+
|
20
|
+
require 'dictionaries/toplevel_methods/e.rb'
|
21
|
+
require 'dictionaries/toplevel_methods/misc.rb'
|
22
|
+
require 'dictionaries/class/ask_word_from_dictionary.rb'
|
23
|
+
|
24
|
+
require 'gtk_paradise/requires/require_the_base_module.rb'
|
25
|
+
include ::Gtk::BaseModule
|
26
|
+
|
27
|
+
# ========================================================================= #
|
28
|
+
# === NAMESPACE
|
29
|
+
# ========================================================================= #
|
30
|
+
NAMESPACE = inspect
|
31
|
+
|
32
|
+
# ========================================================================= #
|
33
|
+
# === TITLE
|
34
|
+
# ========================================================================= #
|
35
|
+
TITLE = 'Dictionary'
|
36
|
+
|
37
|
+
# ========================================================================= #
|
38
|
+
# === WIDTH
|
39
|
+
# ========================================================================= #
|
40
|
+
WIDTH = '25% or minimum 200px'
|
41
|
+
|
42
|
+
# ========================================================================= #
|
43
|
+
# === HEIGHT
|
44
|
+
# ========================================================================= #
|
45
|
+
HEIGHT = '25% or minimum 200px'
|
46
|
+
|
47
|
+
# ========================================================================= #
|
48
|
+
# === USE_THIS_FONT
|
49
|
+
# ========================================================================= #
|
50
|
+
USE_THIS_FONT = :dejavu_condensed_22
|
51
|
+
|
52
|
+
# ========================================================================= #
|
53
|
+
# === SMALLER_FONT
|
54
|
+
#
|
55
|
+
# This one should be relative to the font used above.
|
56
|
+
# ========================================================================= #
|
57
|
+
SMALLER_FONT = :dejavu_condensed_18
|
58
|
+
|
59
|
+
# ========================================================================= #
|
60
|
+
# === initialize
|
61
|
+
# ========================================================================= #
|
62
|
+
def initialize(
|
63
|
+
commandline_arguments = ARGV,
|
64
|
+
run_already = true
|
65
|
+
)
|
66
|
+
super(:vertical)
|
67
|
+
reset
|
68
|
+
set_commandline_arguments(
|
69
|
+
commandline_arguments
|
70
|
+
)
|
71
|
+
run if run_already
|
72
|
+
end
|
73
|
+
|
74
|
+
# ========================================================================= #
|
75
|
+
# === reset (reset tag)
|
76
|
+
# ========================================================================= #
|
77
|
+
def reset
|
78
|
+
reset_the_internal_variables
|
79
|
+
# ======================================================================= #
|
80
|
+
# === @configuration
|
81
|
+
# ======================================================================= #
|
82
|
+
@configuration = [true, __dir__, NAMESPACE]
|
83
|
+
# ======================================================================= #
|
84
|
+
# === Set the title, width, height and the font in use.
|
85
|
+
# ======================================================================= #
|
86
|
+
title_width_height_font(TITLE, WIDTH, HEIGHT, USE_THIS_FONT)
|
87
|
+
infer_the_size_automatically
|
88
|
+
# ======================================================================= #
|
89
|
+
# === @dictionaries
|
90
|
+
# ======================================================================= #
|
91
|
+
@dictionaries = Dictionaries.new(:do_not_run_yet)
|
92
|
+
Dictionaries.set_main_file(:default)
|
93
|
+
@dictionaries.load_the_english_file
|
94
|
+
# ======================================================================= #
|
95
|
+
# === @array_style_these_buttons
|
96
|
+
# ======================================================================= #
|
97
|
+
@array_style_these_buttons = []
|
98
|
+
handle_CSS
|
99
|
+
end
|
100
|
+
|
101
|
+
# ========================================================================= #
|
102
|
+
# === handle_CSS
|
103
|
+
# ========================================================================= #
|
104
|
+
def handle_CSS
|
105
|
+
use_gtk_paradise_project_css_file
|
106
|
+
end
|
107
|
+
|
108
|
+
# ========================================================================= #
|
109
|
+
# === padding?
|
110
|
+
# ========================================================================= #
|
111
|
+
def padding?
|
112
|
+
2
|
113
|
+
end
|
114
|
+
|
115
|
+
# ========================================================================= #
|
116
|
+
# === border_size?
|
117
|
+
# ========================================================================= #
|
118
|
+
def border_size?
|
119
|
+
2
|
120
|
+
end
|
121
|
+
|
122
|
+
# ========================================================================= #
|
123
|
+
# === e
|
124
|
+
# ========================================================================= #
|
125
|
+
def e(i = '')
|
126
|
+
::Dictionaries.e(i)
|
127
|
+
end
|
128
|
+
|
129
|
+
# ========================================================================= #
|
130
|
+
# === add_ask_the_question_button
|
131
|
+
# ========================================================================= #
|
132
|
+
def add_ask_the_question_button
|
133
|
+
button = bold_button('_Translate into german')
|
134
|
+
button.clear_background
|
135
|
+
button.bblack2
|
136
|
+
button.hint =
|
137
|
+
'Click this button in order to <b>translate the english '\
|
138
|
+
'word into the german equivalent word</b>.'
|
139
|
+
button.on_clicked {
|
140
|
+
button_pressed_so_try_to_convert_the_input
|
141
|
+
}
|
142
|
+
@array_style_these_buttons << button
|
143
|
+
hbox1 = gtk_hbox
|
144
|
+
hbox1.minimal(button, 1)
|
145
|
+
hbox1.halign_center
|
146
|
+
minimal(hbox1, 5)
|
147
|
+
end
|
148
|
+
|
149
|
+
# ========================================================================= #
|
150
|
+
# === create_answer_field
|
151
|
+
#
|
152
|
+
# This method builds up the "answer-widget".
|
153
|
+
# ========================================================================= #
|
154
|
+
def create_answer_field
|
155
|
+
# ======================================================================= #
|
156
|
+
# === @answer_field
|
157
|
+
# ======================================================================= #
|
158
|
+
@answer_field = gtk_input_field
|
159
|
+
@answer_field.center
|
160
|
+
@answer_field.hint = 'The translated string may appear here.'
|
161
|
+
@answer_field.very_light_yellow_background
|
162
|
+
end
|
163
|
+
|
164
|
+
# ========================================================================= #
|
165
|
+
# === button_pressed_so_try_to_convert_the_input (click tag)
|
166
|
+
#
|
167
|
+
# This action is called when the user clicks on the button.
|
168
|
+
# ========================================================================= #
|
169
|
+
def button_pressed_so_try_to_convert_the_input
|
170
|
+
user_input = @input_field.return_input
|
171
|
+
unless user_input.empty? # We check whether the user did input something.
|
172
|
+
translated_word = @dictionaries.translate(user_input)
|
173
|
+
e "#{::Colours.sfancy(user_input)} → "\
|
174
|
+
"#{::Colours.simp(translated_word)}"
|
175
|
+
@answer_field.set_text(translated_word)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
# ========================================================================= #
|
180
|
+
# === add_the_widget_for_remote_query_of_the_dictionary_at_leo (bottom tag)
|
181
|
+
#
|
182
|
+
# This is the bottom widget.
|
183
|
+
# ========================================================================= #
|
184
|
+
def add_the_widget_for_remote_query_of_the_dictionary_at_leo
|
185
|
+
bottom_vbox = gtk_vbox
|
186
|
+
bold_label = gtk_bold_label(
|
187
|
+
'Query from a remote website instead (more entries available)'
|
188
|
+
)
|
189
|
+
bottom_vbox.minimal(bold_label, 15)
|
190
|
+
# This is the user-input entry at the bottom.
|
191
|
+
@entry_for_the_remote_query = gtk_entry
|
192
|
+
@entry_for_the_remote_query.center
|
193
|
+
@entry_for_the_remote_query.on_key_press_event { |widget, event|
|
194
|
+
case Gdk::Keyval.to_name(event.keyval)
|
195
|
+
when 'Return', 'KP_Enter'
|
196
|
+
do_perform_a_remote_query_to_the_leo_dictionary
|
197
|
+
end
|
198
|
+
}
|
199
|
+
bottom_vbox.minimal(@entry_for_the_remote_query)
|
200
|
+
# ======================================================================= #
|
201
|
+
# === button_for_the_remote_query
|
202
|
+
# ======================================================================= #
|
203
|
+
button_for_the_remote_query = button(
|
204
|
+
'_Query from a remote dictionary'
|
205
|
+
)
|
206
|
+
button_for_the_remote_query.clear_background
|
207
|
+
button_for_the_remote_query.bblack2
|
208
|
+
button_for_the_remote_query.make_bold
|
209
|
+
button_for_the_remote_query.hint =
|
210
|
+
'This will <b>query the remote dictionary</b> at leo instead. '\
|
211
|
+
'The <b>advantage</b> here is that the dataset at leo will '\
|
212
|
+
'contain many more entries than does the knowledgebase '\
|
213
|
+
'distributed with the <b>dictionaries gem</b>.'
|
214
|
+
button_for_the_remote_query.on_clicked {
|
215
|
+
do_perform_a_remote_query_to_the_leo_dictionary
|
216
|
+
}
|
217
|
+
bottom_vbox.minimal(
|
218
|
+
@entry_at_the_bottom_showing_the_result_from_online_leo, 2
|
219
|
+
)
|
220
|
+
@array_style_these_buttons << button_for_the_remote_query
|
221
|
+
small_hbox = gtk_hbox
|
222
|
+
small_hbox.minimal(button_for_the_remote_query, 1)
|
223
|
+
small_hbox.halign_center
|
224
|
+
bottom_vbox.minimal(
|
225
|
+
small_hbox, 2
|
226
|
+
)
|
227
|
+
maximal(bottom_vbox, 2)
|
228
|
+
end
|
229
|
+
|
230
|
+
# ========================================================================= #
|
231
|
+
# === update_the_statistics_frame (update tag)
|
232
|
+
# ========================================================================= #
|
233
|
+
def update_the_statistics_frame(i = return_currently_selected_file)
|
234
|
+
@label_currently_selected_file.set_text(i)
|
235
|
+
@label_currently_selected_file.do_markify
|
236
|
+
end
|
237
|
+
|
238
|
+
# ========================================================================= #
|
239
|
+
# === do_perform_a_remote_query_to_the_leo_dictionary
|
240
|
+
# ========================================================================= #
|
241
|
+
def do_perform_a_remote_query_to_the_leo_dictionary(
|
242
|
+
i = @entry_for_the_remote_query.text.to_s
|
243
|
+
)
|
244
|
+
if i and !i.empty?
|
245
|
+
array = ::Dictionaries.return_array_of_translated_words_from_online_leo(i)
|
246
|
+
result = array.first
|
247
|
+
@entry_at_the_bottom_showing_the_result_from_online_leo.set_text(result)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
# ========================================================================= #
|
252
|
+
# === create_the_statistics_frame
|
253
|
+
# ========================================================================= #
|
254
|
+
def create_the_statistics_frame
|
255
|
+
# ======================================================================= #
|
256
|
+
# === @frame_statistics
|
257
|
+
# ======================================================================= #
|
258
|
+
@frame_statistics = gtk_frame(' Statistics ')
|
259
|
+
@frame_statistics.make_bold
|
260
|
+
@frame_statistics.use_this_font = smaller_font?
|
261
|
+
vbox = gtk_vbox
|
262
|
+
@label_currently_selected_file = gtk_label(return_currently_selected_file)
|
263
|
+
vbox.minimal(
|
264
|
+
@label_currently_selected_file, 0
|
265
|
+
)
|
266
|
+
@frame_statistics.add(vbox)
|
267
|
+
end
|
268
|
+
|
269
|
+
# ========================================================================= #
|
270
|
+
# === return_currently_selected_file
|
271
|
+
# ========================================================================= #
|
272
|
+
def return_currently_selected_file
|
273
|
+
'Currently selected file: <b>'+
|
274
|
+
File.basename(
|
275
|
+
@dictionaries.currently_selected_file?.to_s
|
276
|
+
)+'</b>'
|
277
|
+
end
|
278
|
+
|
279
|
+
# ========================================================================= #
|
280
|
+
# === create_input_field_on_top
|
281
|
+
#
|
282
|
+
# This is the main widget for user input. The user types in some
|
283
|
+
# words, and then hits the main button on the bottom, in order
|
284
|
+
# to translate the (english) word to german.
|
285
|
+
# ========================================================================= #
|
286
|
+
def create_input_field_on_top
|
287
|
+
text_for_the_label = 'Input an english word in the field below'
|
288
|
+
text = gtk_label(text_for_the_label)
|
289
|
+
text.slateblue
|
290
|
+
text.set_markup(
|
291
|
+
'<span size="x-large" weight="bold">'+text_for_the_label+'</span>',
|
292
|
+
use_underline: true
|
293
|
+
)
|
294
|
+
# ======================================================================= #
|
295
|
+
# Add the "input field" next for the english word that is to
|
296
|
+
# be translated.
|
297
|
+
# ======================================================================= #
|
298
|
+
@input_field = gtk_input_field
|
299
|
+
@input_field.hint = 'Input the word that should be translated '\
|
300
|
+
'here. Then, press the "enter" key or the button '\
|
301
|
+
'"Translate into german" below.'
|
302
|
+
@input_field.very_light_yellow_background
|
303
|
+
completion = gtk_entry_completion
|
304
|
+
@input_field.completion = completion # Assign the completion.
|
305
|
+
completion_model = gtk_list_store(String)
|
306
|
+
@dictionaries.array.each { |word|
|
307
|
+
iter = completion_model.append
|
308
|
+
iter[0] = word
|
309
|
+
}
|
310
|
+
completion.model = completion_model
|
311
|
+
# ======================================================================= #
|
312
|
+
# Use model column 0 as the text column
|
313
|
+
# ======================================================================= #
|
314
|
+
completion.text_column = 0
|
315
|
+
@input_field.center
|
316
|
+
@input_field.on_key_press_event { |widget, event|
|
317
|
+
case Gdk::Keyval.to_name(event.keyval)
|
318
|
+
when 'Return', 'KP_Enter'
|
319
|
+
button_pressed_so_try_to_convert_the_input
|
320
|
+
end
|
321
|
+
}
|
322
|
+
hbox_holding_label_and_input_field = gtk_vbox(
|
323
|
+
text, @input_field
|
324
|
+
)
|
325
|
+
minimal(hbox_holding_label_and_input_field, 2)
|
326
|
+
end
|
327
|
+
|
328
|
+
# ========================================================================= #
|
329
|
+
# === run (run tag)
|
330
|
+
# ========================================================================= #
|
331
|
+
def run
|
332
|
+
super()
|
333
|
+
update_the_statistics_frame
|
334
|
+
do_style_the_important_buttons
|
335
|
+
show_all
|
336
|
+
end
|
337
|
+
|
338
|
+
# ========================================================================= #
|
339
|
+
# === smaller_font?
|
340
|
+
# ========================================================================= #
|
341
|
+
def smaller_font?
|
342
|
+
SMALLER_FONT
|
343
|
+
end
|
344
|
+
|
345
|
+
# ========================================================================= #
|
346
|
+
# === create_the_header_bar
|
347
|
+
# ========================================================================= #
|
348
|
+
def create_the_header_bar
|
349
|
+
# ======================================================================= #
|
350
|
+
# === @header_bar
|
351
|
+
# ======================================================================= #
|
352
|
+
@header_bar = default_header_bar
|
353
|
+
@header_bar.title = 'Dictionary'
|
354
|
+
end
|
355
|
+
|
356
|
+
# ========================================================================= #
|
357
|
+
# === create_skeleton (create tag, skeleton tag)
|
358
|
+
# ========================================================================= #
|
359
|
+
def create_skeleton
|
360
|
+
create_the_entries
|
361
|
+
create_the_header_bar
|
362
|
+
add_the_header_bar
|
363
|
+
create_input_field_on_top
|
364
|
+
create_answer_field
|
365
|
+
create_the_statistics_frame
|
366
|
+
end
|
367
|
+
|
368
|
+
# ========================================================================= #
|
369
|
+
# === create_the_entries (entries tag, entry tag)
|
370
|
+
# ========================================================================= #
|
371
|
+
def create_the_entries
|
372
|
+
# ======================================================================= #
|
373
|
+
# === @entry_at_the_bottom_showing_the_result_from_online_leo
|
374
|
+
# ======================================================================= #
|
375
|
+
@entry_at_the_bottom_showing_the_result_from_online_leo = gtk_entry
|
376
|
+
@entry_at_the_bottom_showing_the_result_from_online_leo.center
|
377
|
+
end
|
378
|
+
|
379
|
+
# ========================================================================= #
|
380
|
+
# === add_the_header_bar
|
381
|
+
# ========================================================================= #
|
382
|
+
def add_the_header_bar
|
383
|
+
minimal(@header_bar, 1)
|
384
|
+
end
|
385
|
+
|
386
|
+
# ========================================================================= #
|
387
|
+
# === add_the_statistics_frame
|
388
|
+
# ========================================================================= #
|
389
|
+
def add_the_statistics_frame
|
390
|
+
maximal(@frame_statistics, 2)
|
391
|
+
end
|
392
|
+
|
393
|
+
# ========================================================================= #
|
394
|
+
# === add_the_answer_field
|
395
|
+
# ========================================================================= #
|
396
|
+
def add_the_answer_field
|
397
|
+
minimal(@answer_field) # ← Translation appears here.
|
398
|
+
end
|
399
|
+
|
400
|
+
# ========================================================================= #
|
401
|
+
# === connect_skeleton (connect tag)
|
402
|
+
# ========================================================================= #
|
403
|
+
def connect_skeleton
|
404
|
+
abort_on_exception
|
405
|
+
add_the_answer_field
|
406
|
+
add_ask_the_question_button
|
407
|
+
add_the_widget_for_remote_query_of_the_dictionary_at_leo
|
408
|
+
add_the_statistics_frame
|
409
|
+
end
|
410
|
+
|
411
|
+
# ========================================================================= #
|
412
|
+
# === do_style_the_important_buttons
|
413
|
+
# ========================================================================= #
|
414
|
+
def do_style_the_important_buttons
|
415
|
+
@array_style_these_buttons.each {|this_button|
|
416
|
+
this_button.modify_background(:normal, :khaki) # ← default colour
|
417
|
+
this_button.modify_background(:prelight, :paleturquoise) # ← mouse-on-over events
|
418
|
+
this_button.modify_background(:active, :slategray) # ← colour on mouse-press-event
|
419
|
+
}
|
420
|
+
end
|
421
|
+
|
422
|
+
# ========================================================================= #
|
423
|
+
# === Dictionaries::GUI::Gtk::Dictionary.run
|
424
|
+
#
|
425
|
+
# Use this method if you wish to start a new gtk-application window.
|
426
|
+
# ========================================================================= #
|
427
|
+
def self.run(
|
428
|
+
i = ARGV
|
429
|
+
)
|
430
|
+
require 'gtk_paradise/app/app.rb'
|
431
|
+
_ = ::Dictionaries::GUI::Gtk::Dictionary.new(i)
|
432
|
+
r = ::Gtk.run
|
433
|
+
r << _
|
434
|
+
r.automatic_size_then_automatic_title
|
435
|
+
r.enable_quick_exit
|
436
|
+
r.border_width = 12
|
437
|
+
r.top_left_then_run
|
438
|
+
end
|
439
|
+
|
440
|
+
end; end; end
|
441
|
+
|
442
|
+
# =========================================================================== #
|
443
|
+
# === Dictionaries.gtk_widget
|
444
|
+
#
|
445
|
+
# This toplevel-method can be used to return the gtk-widget, which
|
446
|
+
# can then be embedded by other ruby-gtk applications, in particular
|
447
|
+
# admin_panel.rb of the gtk_paradise project.
|
448
|
+
# =========================================================================== #
|
449
|
+
def self.gtk_widget
|
450
|
+
Dictionaries::GUI::Gtk::Dictionary.new
|
451
|
+
end
|
452
|
+
|
453
|
+
end
|
454
|
+
|
455
|
+
if __FILE__ == $PROGRAM_NAME
|
456
|
+
Dictionaries::GUI::Gtk::Dictionary.run
|
457
|
+
end
|
@@ -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,60 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'dictionaries/helper_module/helper_module.rb'
|
6
|
+
# include Dictionaries::HelperModule
|
7
|
+
# =========================================================================== #
|
8
|
+
module Dictionaries
|
9
|
+
|
10
|
+
module HelperModule
|
11
|
+
|
12
|
+
require 'html_tags'
|
13
|
+
include HtmlTags
|
14
|
+
|
15
|
+
# ========================================================================= #
|
16
|
+
# === Dictionaries::HelperModule.return_search_button
|
17
|
+
# ========================================================================= #
|
18
|
+
def self.return_search_button
|
19
|
+
'<input type="submit" name="user_input_submit" value="Search" '\
|
20
|
+
'style="font-weight: bold; font-size: larger; '\
|
21
|
+
'border: 2px dotted slateblue; margin: 4px; margin-left: 2em">'
|
22
|
+
end
|
23
|
+
|
24
|
+
# ========================================================================= #
|
25
|
+
# === Dictionaries::HelperModule.html_header_default_title_and_start_of_the_body_tag
|
26
|
+
# ========================================================================= #
|
27
|
+
def self.html_header_default_title_and_start_of_the_body_tag
|
28
|
+
"<html>\n"\
|
29
|
+
"<title>Dictionaries</title>\n"\
|
30
|
+
"<body>\n"
|
31
|
+
end
|
32
|
+
|
33
|
+
# ========================================================================= #
|
34
|
+
# === Dictionaries::HelperModule.return_english_to_german_form
|
35
|
+
# ========================================================================= #
|
36
|
+
def self.return_english_to_german_form
|
37
|
+
route_to_this_action = '/english_to_german/'
|
38
|
+
html_header_default_title_and_start_of_the_body_tag+
|
39
|
+
HtmlTags.h5('Input an english word to see the translation.')+
|
40
|
+
HtmlTags.div(css_style: 'padding: 0.1em') {
|
41
|
+
HtmlTags.p(
|
42
|
+
'<b>Enter the word here:</b>',
|
43
|
+
css_style: 'padding: 0.15em'
|
44
|
+
)+
|
45
|
+
HtmlTags.form(action: route_to_this_action,
|
46
|
+
id: 'english_to_german',
|
47
|
+
css_style: 'margin-left:1em; margin-top:2px') {
|
48
|
+
'<input type="text" name="user_input" style="border:3px solid slateblue; padding: 4px"><br>'+
|
49
|
+
return_search_button
|
50
|
+
}
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
end; end
|
55
|
+
|
56
|
+
if __FILE__ == $PROGRAM_NAME
|
57
|
+
alias e puts
|
58
|
+
include Dictionaries::HelperModule
|
59
|
+
e Dictionaries::HelperModule.return_english_to_german_form
|
60
|
+
end
|
@@ -0,0 +1,36 @@
|
|
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.rb'
|
8
|
+
# =========================================================================== #
|
9
|
+
module Dictionaries
|
10
|
+
|
11
|
+
# ========================================================================= #
|
12
|
+
# === Dictionaries::PROJECT_BASE_DIRECTORY
|
13
|
+
# ========================================================================= #
|
14
|
+
PROJECT_BASE_DIRECTORY =
|
15
|
+
File.absolute_path("#{__dir__}/..")+'/'
|
16
|
+
|
17
|
+
# ========================================================================= #
|
18
|
+
# === Dictionaries.project_base_dir?
|
19
|
+
# ========================================================================= #
|
20
|
+
def self.project_base_dir?
|
21
|
+
PROJECT_BASE_DIRECTORY
|
22
|
+
end
|
23
|
+
|
24
|
+
# ========================================================================= #
|
25
|
+
# === PROJECT_YAML_DIRECTORY
|
26
|
+
# ========================================================================= #
|
27
|
+
PROJECT_YAML_DIRECTORY = "#{PROJECT_BASE_DIRECTORY}yaml/"
|
28
|
+
|
29
|
+
# ========================================================================= #
|
30
|
+
# === Dictionaries.project_yaml_dir?
|
31
|
+
# ========================================================================= #
|
32
|
+
def self.project_yaml_dir?
|
33
|
+
PROJECT_YAML_DIRECTORY
|
34
|
+
end; self.instance_eval { alias dictionary_directory? project_yaml_dir? } # === Dictionaries.dictionary_directory?
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'dictionaries/require_project/require_project.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'dictionaries/project/project.rb'
|
8
|
+
require 'dictionaries/ask_italian_word.rb'
|
9
|
+
require 'dictionaries/toplevel_methods/has_key.rb' # This file requires the files above.
|
10
|
+
require 'dictionaries/toplevel_methods/module_methods.rb'
|
11
|
+
require 'dictionaries/toplevel_methods/english_to_german.rb'
|
12
|
+
require 'dictionaries/toplevel_methods/is_on_roebe.rb'
|
13
|
+
require 'dictionaries/sinatra/app.rb'
|
14
|
+
require 'dictionaries/statistics/statistics.rb'
|