dictionaries 0.3.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of dictionaries might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/README.md +354 -0
- data/bin/dictionaries +7 -0
- data/bin/unique_words_in_this_file +7 -0
- data/dictionaries.gemspec +84 -0
- data/doc/README.gen +292 -0
- data/doc/todo/todo.md +8 -0
- data/lib/dictionaries/ask_english_word.rb +141 -0
- data/lib/dictionaries/ask_italian_word.rb +84 -0
- data/lib/dictionaries/base/base.rb +78 -0
- data/lib/dictionaries/class/class.rb +903 -0
- data/lib/dictionaries/commandline/parse_commandline.rb +85 -0
- data/lib/dictionaries/constants/constants.rb +134 -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 +123 -0
- data/lib/dictionaries/sinatra/english_to_german.rb +84 -0
- data/lib/dictionaries/spell_checker/README.md +5 -0
- data/lib/dictionaries/spell_checker/spell_checker.rb +133 -0
- data/lib/dictionaries/statistics/statistics.rb +59 -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 +231 -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 +3157 -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/polish.yml +2 -0
- data/lib/dictionaries/yaml/portugese.yml +41 -0
- data/lib/dictionaries/yaml/russian.yml +10 -0
- data/lib/dictionaries/yaml/spanish.yml +147 -0
- data/lib/dictionaries/yaml/swedish.yml +104 -0
- data/lib/dictionaries.rb +1 -0
- data/test/translation_example.html +2758 -0
- metadata +211 -0
@@ -0,0 +1,85 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'dictionaries/commandline/parse_commandline.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module Dictionaries
|
8
|
+
|
9
|
+
require 'dictionaries/toplevel_methods/show_help.rb'
|
10
|
+
require 'dictionaries/class/class.rb'
|
11
|
+
require 'dictionaries/statistics/statistics.rb'
|
12
|
+
|
13
|
+
# ========================================================================= #
|
14
|
+
# === Dictionaries.start_gtk_component
|
15
|
+
#
|
16
|
+
# This module-method will start the GTK component.
|
17
|
+
# ========================================================================= #
|
18
|
+
def self.start_gtk_component
|
19
|
+
require 'dictionaries/gui/gtk3/dictionary/dictionary.rb'
|
20
|
+
Dictionaries::GUI::Gtk::Dictionary.run
|
21
|
+
end
|
22
|
+
|
23
|
+
# ========================================================================= #
|
24
|
+
# === Dictionaries.parse_commandline
|
25
|
+
# ========================================================================= #
|
26
|
+
def self.parse_commandline(
|
27
|
+
i = ARGV
|
28
|
+
)
|
29
|
+
if i.is_a? Array
|
30
|
+
i.each {|entry| parse_commandline(entry) }
|
31
|
+
else
|
32
|
+
case i # case tag
|
33
|
+
# ===================================================================== #
|
34
|
+
# === dictionaries --stats
|
35
|
+
#
|
36
|
+
# This entry point allows the user to show some statistics about
|
37
|
+
# this project.
|
38
|
+
# ===================================================================== #
|
39
|
+
when /^-?-?stats\??$/i,
|
40
|
+
/^-?-?statistics\??$/i
|
41
|
+
Dictionaries::Statistics.report
|
42
|
+
# ===================================================================== #
|
43
|
+
# === dictionaries --read=www.nytimes.com.html
|
44
|
+
# ===================================================================== #
|
45
|
+
when /^-?-?read=(.+)$/i
|
46
|
+
_ = $1.to_s.dup
|
47
|
+
require 'dictionaries/toplevel_methods/misc.rb'
|
48
|
+
if File.exist? _
|
49
|
+
e 'Finding unique words ... this may take a while. Please be'
|
50
|
+
e 'patient.'
|
51
|
+
unique_words = ::Dictionaries.return_unique_words_from_this_file(_, :default, :remove_HTML_tags).sort
|
52
|
+
pp unique_words
|
53
|
+
e 'n entries: '+unique_words.size.to_s
|
54
|
+
else
|
55
|
+
e 'No file exists at '+sfile(_)+'.'
|
56
|
+
end
|
57
|
+
# ===================================================================== #
|
58
|
+
# === dictionaries --gui
|
59
|
+
# ===================================================================== #
|
60
|
+
when /^-?-?gui$/i,
|
61
|
+
/^-?-?gtk$/i,
|
62
|
+
/^-?-?start(-|_)?gtk$/i
|
63
|
+
start_gtk_component
|
64
|
+
# ===================================================================== #
|
65
|
+
# === dictionaries --sinatra
|
66
|
+
# ===================================================================== #
|
67
|
+
when /^-?-?sinatra$/i
|
68
|
+
require 'dictionaries/sinatra/app.rb'
|
69
|
+
Dictionaries.start_sinatra_interface
|
70
|
+
# ===================================================================== #
|
71
|
+
# === dictionaries --n-words?
|
72
|
+
# ===================================================================== #
|
73
|
+
when /^-?-?n(_|-)?words\??$/i
|
74
|
+
e "#{Colours.sfancy(Dictionaries.n_entries?)} english-to-german "\
|
75
|
+
"translations are presently registered in this project."
|
76
|
+
# ===================================================================== #
|
77
|
+
# === dictionaries --help
|
78
|
+
# ===================================================================== #
|
79
|
+
when /help/
|
80
|
+
show_help
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'dictionaries/constants/constants.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
|
8
|
+
module Dictionaries
|
9
|
+
|
10
|
+
require 'dictionaries/project/project.rb'
|
11
|
+
require 'dictionaries/version/version.rb'
|
12
|
+
|
13
|
+
# ========================================================================= #
|
14
|
+
# === Dictionaries::N
|
15
|
+
# ========================================================================= #
|
16
|
+
N = "\n"
|
17
|
+
|
18
|
+
# ========================================================================= #
|
19
|
+
# === Dictionaries::URL_FOR_DICT_LEO
|
20
|
+
# ========================================================================= #
|
21
|
+
URL_FOR_DICT_LEO = 'http://dict.leo.org/'
|
22
|
+
|
23
|
+
# ========================================================================= #
|
24
|
+
# === URL_FOR_ITALIAN_DICTIONARY
|
25
|
+
# ========================================================================= #
|
26
|
+
URL_FOR_ITALIAN_DICTIONARY = 'http://www.wordreference.com/iten/'
|
27
|
+
|
28
|
+
# ========================================================================= #
|
29
|
+
# === LPAD
|
30
|
+
# ========================================================================= #
|
31
|
+
LPAD = ' '
|
32
|
+
|
33
|
+
# ========================================================================= #
|
34
|
+
# === RUBY_SRC
|
35
|
+
# ========================================================================= #
|
36
|
+
if ENV['RUBY_SRC']
|
37
|
+
RUBY_SRC = ENV['RUBY_SRC'].to_s.dup+'/'
|
38
|
+
else # else we just hardcode it anyway.
|
39
|
+
RUBY_SRC = '/home/x/programming/ruby/src/'
|
40
|
+
end
|
41
|
+
|
42
|
+
# ========================================================================= #
|
43
|
+
# === MY_DICTIONARIES
|
44
|
+
#
|
45
|
+
# This constant is only valid for my own system.
|
46
|
+
# ========================================================================= #
|
47
|
+
MY_DICTIONARIES = "#{RUBY_SRC}dictionaries/lib/dictionaries/yaml/"
|
48
|
+
|
49
|
+
# ========================================================================= #
|
50
|
+
# === SCIENCE_DIR
|
51
|
+
# ========================================================================= #
|
52
|
+
SCIENCE_DIR = ENV['SCIENCE'].to_s+'/'
|
53
|
+
|
54
|
+
# ========================================================================= #
|
55
|
+
# === DEPOT_INFORMATION_DIR
|
56
|
+
# ========================================================================= #
|
57
|
+
DEPOT_INFORMATION_DIR = '/Depot/Information/'
|
58
|
+
|
59
|
+
# ========================================================================= #
|
60
|
+
# === DICTIONARIES_DIR
|
61
|
+
#
|
62
|
+
# This constant will point at a path such as this one here:
|
63
|
+
#
|
64
|
+
# /Programs/Ruby/2.6.3/lib/ruby/site_ruby/2.6.0/dictionaries/yaml/
|
65
|
+
#
|
66
|
+
# ========================================================================= #
|
67
|
+
DICTIONARIES_DIR = Dictionaries.dictionary_directory?
|
68
|
+
|
69
|
+
# ========================================================================= #
|
70
|
+
# === ENGLISH_WORDS
|
71
|
+
#
|
72
|
+
# This constant is no longer that important because we can now
|
73
|
+
# automatically infer the name of the .yml file.
|
74
|
+
# ========================================================================= #
|
75
|
+
ENGLISH_WORDS = DICTIONARIES_DIR+'english.yml'
|
76
|
+
ENGLISH_YAML_FILE = ENGLISH_WORDS # === ENGLISH_YAML_FILE
|
77
|
+
FILE_ENGLISH_WORDS = ENGLISH_WORDS # === FILE_ENGLISH_WORDS
|
78
|
+
FILE_ENGLISH_DICTIONARY = ENGLISH_YAML_FILE
|
79
|
+
|
80
|
+
# ========================================================================= #
|
81
|
+
# === Dictionaries.file_english
|
82
|
+
# ========================================================================= #
|
83
|
+
def self.file_english
|
84
|
+
FILE_ENGLISH_DICTIONARY
|
85
|
+
end; self.instance_eval { alias file_english? file_english } # === Dictionaries.file_english?
|
86
|
+
|
87
|
+
# ========================================================================= #
|
88
|
+
# === ITALIAN_WORDS
|
89
|
+
#
|
90
|
+
# This constant is no longer that important because we can now
|
91
|
+
# automatically infer the name of the .yml file.
|
92
|
+
# ========================================================================= #
|
93
|
+
ITALIAN_WORDS = DICTIONARIES_DIR+'italian.yml'
|
94
|
+
ITALIAN_YAML_FILE = ITALIAN_WORDS
|
95
|
+
FILE_ITALIAN_DICTIONARY = ITALIAN_YAML_FILE
|
96
|
+
|
97
|
+
# ========================================================================= #
|
98
|
+
# === STORE_LINE_NUMBER_HERE
|
99
|
+
# ========================================================================= #
|
100
|
+
STORE_LINE_NUMBER_HERE = DEPOT_INFORMATION_DIR+'line_number_of_the_last_word'
|
101
|
+
|
102
|
+
# ========================================================================= #
|
103
|
+
# === STORE_LAST_ENGLISH_QUESTION_ASKED_HERE
|
104
|
+
# ========================================================================= #
|
105
|
+
STORE_LAST_ENGLISH_QUESTION_ASKED_HERE =
|
106
|
+
DEPOT_INFORMATION_DIR+'last_english_question_asked' # cat $MY_TEMP/last_english_question_asked
|
107
|
+
|
108
|
+
# ========================================================================= #
|
109
|
+
# === STORE_LAST_ITALIAN_QUESTION_ASKED_HERE
|
110
|
+
# ========================================================================= #
|
111
|
+
STORE_LAST_ITALIAN_QUESTION_ASKED_HERE =
|
112
|
+
DEPOT_INFORMATION_DIR+'last_italian_question_asked' # cat $MY_TEMP/last_italian_question_asked
|
113
|
+
|
114
|
+
# ========================================================================= #
|
115
|
+
# === SHALL_WE_DOWNCASE
|
116
|
+
# ========================================================================= #
|
117
|
+
SHALL_WE_DOWNCASE = true
|
118
|
+
|
119
|
+
# ========================================================================= #
|
120
|
+
# === USE_THIS_ENCODING
|
121
|
+
#
|
122
|
+
# This is the main encoding to use.
|
123
|
+
# ========================================================================= #
|
124
|
+
USE_THIS_ENCODING = 'ISO-8859-1'
|
125
|
+
MAIN_ENCODING = USE_THIS_ENCODING
|
126
|
+
|
127
|
+
# ========================================================================= #
|
128
|
+
# === DEFAULT_DELAY
|
129
|
+
#
|
130
|
+
# Specify how long to wait before revealing the translated word.
|
131
|
+
# ========================================================================= #
|
132
|
+
DEFAULT_DELAY = 1.6
|
133
|
+
|
134
|
+
end
|
@@ -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/class.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/run'
|
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
|