Class: Dictionaries::GUI::UniversalWidgets::Dictionary
- Inherits:
-
Base
- Object
- Base
- Dictionaries::GUI::UniversalWidgets::Dictionary
show all
- Includes:
- UniversalWidgets::BaseModule
- Defined in:
- lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb
Overview
Constant Summary
collapse
- TITLE =
'Dictionary'
- WIDTH =
'28% or minimum 280px'
- HEIGHT =
'26% or minimum 240px'
- USE_THIS_FONT =
:dejavu_condensed_22
- LARGER_FONT =
:hack_25
- SMALLER_FONT =
#
SMALLER_FONT
This one should be relative to the font used above.
#
:dejavu_condensed_18
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#commandline_arguments?, #first_argument?, #opne, #rev, #set_commandline_arguments, #sfancy
Constructor Details
#initialize(commandline_arguments = nil, run_already = true) ⇒ Dictionary
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 67
def initialize(
commandline_arguments = nil,
run_already = true
)
super(:vertical) if use_gtk3?
determine_the_GUI_to_be_used(commandline_arguments) reset
set_commandline_arguments(
commandline_arguments
)
on_delete_event_quit_the_application
run if run_already
end
|
Class Method Details
.[](i = ARGV) ⇒ Object
495
496
497
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 495
def self.[](i = ARGV)
new(i)
end
|
.run(i = ARGV) ⇒ Object
#
Dictionaries::GUI::Gtk::Dictionary.run
#
477
478
479
480
481
482
483
484
485
486
487
488
489
490
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 477
def self.run(
i = ARGV
)
require 'gtk_paradise/run'
_ = ::Dictionaries::GUI::Gtk::Dictionary.new(i)
r = ::Gtk.run
_.set_parent_widget(r) r << _
r.automatic_size_then_automatic_title
r.enable_quick_exit
r.set_background :white
r.border_width = 12
r.top_left_then_run
end
|
Instance Method Details
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 158
def add_ask_the_question_button
button = bold_button('_Translate into german')
button.clear_background
button.bblack2
button.hint =
'Click this button in order to <b>translate the english '\
'word into the german equivalent word</b>.'
button.on_clicked {
button_pressed_so_try_to_convert_the_input
}
@array_style_these_buttons << button
hbox1 = create_hbox
hbox1.minimal(button, 1)
hbox1.halign_center
return hbox1
end
|
#add_the_answer_field ⇒ Object
434
435
436
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 434
def add_the_answer_field
return @answer_field end
|
420
421
422
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 420
def
return @header_bar
end
|
#add_the_statistics_frame ⇒ Object
#
add_the_statistics_frame
#
427
428
429
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 427
def add_the_statistics_frame
return @frame_statistics
end
|
#
This is the bottom widget.
#
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 235
def add_the_widget_for_remote_query_of_the_dictionary_at_leo
bottom_vbox = create_vbox
bold_label = bold_label(
'Query from a remote website instead (more entries available)'
)
bottom_vbox.minimal(bold_label, 15)
@entry_for_the_remote_query = create_entry
@entry_for_the_remote_query.center
@entry_for_the_remote_query.on_key_press_event { |widget, event|
case Gdk::Keyval.to_name(event.keyval)
when 'Return', 'KP_Enter'
do_perform_a_remote_query_to_the_leo_dictionary
end
}
bottom_vbox.minimal(@entry_for_the_remote_query)
button_for_the_remote_query = button(
'_Query from a remote dictionary'
)
button_for_the_remote_query.clear_background
button_for_the_remote_query.bblack2
button_for_the_remote_query.make_bold
button_for_the_remote_query.hint =
'This will <b>query the remote dictionary</b> at leo instead. '\
'The <b>advantage</b> here is that the dataset at leo will '\
'contain many more entries than does the knowledgebase '\
'distributed with the <b>dictionaries gem</b>.'
button_for_the_remote_query.on_clicked {
do_perform_a_remote_query_to_the_leo_dictionary
}
bottom_vbox.minimal(
@entry_at_the_bottom_showing_the_result_from_online_leo, 2
)
@array_style_these_buttons << button_for_the_remote_query
small_hbox = create_hbox
small_hbox.minimal(button_for_the_remote_query, 1)
small_hbox.halign_center
bottom_vbox.minimal(
small_hbox, 2
)
return bottom_vbox
end
|
#border_size? ⇒ Boolean
185
186
187
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 185
def border_size?
2
end
|
#
This action is called when the user clicks on the button.
#
220
221
222
223
224
225
226
227
228
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 220
def button_pressed_so_try_to_convert_the_input
user_input = @input_field.return_input
unless user_input.empty? translated_word = @dictionaries.translate(user_input)
e "#{::Colours.sfancy(user_input)} → "\
"#{::Colours.simp(translated_word)}"
@answer_field.set_text(translated_word)
end
end
|
#connect_the_skeleton ⇒ Object
#
connect_the_skeleton (connect tag)
#
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 333
def connect_the_skeleton
abort_on_exception
outer_box = create_vbox
outer_box.add()
outer_box.add(return_input_field_on_top)
outer_box.add(add_the_answer_field)
outer_box.add(add_ask_the_question_button)
outer_box.add(add_the_widget_for_remote_query_of_the_dictionary_at_leo)
outer_box.add(add_the_statistics_frame)
window = create_window_or_runner(nil, width?, height?, title?)
window << outer_box
properly_prepare_this_window(window,
{
title: title?,
font: font?,
width: width?,
height: height?,
padding: padding?,
border_size: border_size?
}
)
window.show_all
window.top_left
do_all_startup_related_actions
run_main
end
|
#create_answer_field ⇒ Object
#
create_answer_field
This method builds up the “answer-widget”.
#
205
206
207
208
209
210
211
212
213
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 205
def create_answer_field
@answer_field = create_input_field
@answer_field.center
@answer_field.hint = 'The translated string may appear here.'
@answer_field.very_light_yellow_background
end
|
#create_the_entries ⇒ Object
#
create_the_entries (entries tag, entry tag)
#
409
410
411
412
413
414
415
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 409
def create_the_entries
@entry_at_the_bottom_showing_the_result_from_online_leo = create_entry
@entry_at_the_bottom_showing_the_result_from_online_leo.center
end
|
192
193
194
195
196
197
198
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 192
def
@header_bar =
@header_bar.title = 'Dictionary'
end
|
#create_the_skeleton ⇒ Object
#
create_the_skeleton (create tag, skeleton tag)
#
441
442
443
444
445
446
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 441
def create_the_skeleton
create_the_entries
create_answer_field
create_the_statistics_frame
end
|
#create_the_statistics_frame ⇒ Object
#
create_the_statistics_frame
#
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 451
def create_the_statistics_frame
@frame_statistics = create_frame
@frame_statistics.set_label((' Statistics '))
@frame_statistics.make_bold
@frame_statistics.use_this_font = smaller_font?
vbox = create_vbox
@label_currently_selected_file = label(return_currently_selected_file)
vbox.minimal(
@label_currently_selected_file, 0
)
@frame_statistics.add(vbox)
end
|
367
368
369
370
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 367
def do_all_startup_related_actions
update_the_statistics_frame
do_style_the_important_buttons
end
|
386
387
388
389
390
391
392
393
394
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 386
def do_perform_a_remote_query_to_the_leo_dictionary(
i = @entry_for_the_remote_query.text.to_s
)
if i and !i.empty?
array = ::Dictionaries.return_array_of_translated_words_from_online_leo(i)
result = array.first
@entry_at_the_bottom_showing_the_result_from_online_leo.set_text(result)
end
end
|
375
376
377
378
379
380
381
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 375
def do_style_the_important_buttons
@array_style_these_buttons.each {|this_button|
this_button.modify_background(:normal, :khaki) this_button.modify_background(:prelight, :paleturquoise) this_button.modify_background(:active, :slategray) }
end
|
#e(i = '') ⇒ Object
141
142
143
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 141
def e(i = '')
::Dictionaries.e(i)
end
|
#handle_CSS_rules ⇒ Object
#
handle_CSS_rules (CSS tag)
#
124
125
126
127
128
129
130
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 124
def handle_CSS_rules
use_gtk_paradise_project_css_file
append_project_css_file
more_CSS_then_apply_it '
'
end
|
#padding? ⇒ Boolean
178
179
180
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 178
def padding?
2
end
|
#reset ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 84
def reset
super() if respond_to?(:super)
reset_the_shared_module reset_the_base_module
reset_the_internal_variables
infer_the_namespace
@configuration = [true, __dir__, namespace?]
title_width_height_font(TITLE, WIDTH, HEIGHT, USE_THIS_FONT)
if use_gtk3?
handle_CSS_rules
end
infer_the_size_automatically
@dictionaries = Dictionaries.new(:do_not_run_yet)
Dictionaries.set_main_file(:default)
@dictionaries.load_the_english_file
@array_style_these_buttons = []
end
|
#reset_the_shared_module ⇒ Object
#
reset_the_shared_module
#
135
136
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 135
def reset_the_shared_module
end
|
#return_currently_selected_file ⇒ Object
#
return_currently_selected_file
#
399
400
401
402
403
404
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 399
def return_currently_selected_file
'Currently selected file: <b>'+
File.basename(
@dictionaries.currently_selected_file?.to_s
)+'</b>'
end
|
#
This is the main widget for user input. The user types in some words, and then hits the main button on the bottom, in order to translate the (english) word to german.
#
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 288
def return_input_field_on_top
text_for_the_label = 'Input an english word in the field below'
text = label(text_for_the_label)
text.slateblue
text.set_markup(
'<span size="x-large" weight="bold">'+text_for_the_label+'</span>',
use_underline: true
)
@input_field = create_input_field
@input_field.hint = 'Input the word that should be translated '\
'here. Then, press the "enter" key or the button '\
'"Translate into german" below.'
@input_field.very_light_yellow_background
completion = create_entry_completion
@input_field.completion = completion completion_model = ::Gtk::ListStore.new(String)
@dictionaries.array.each { |word|
iter = completion_model.append
iter[0] = word
}
completion.model = completion_model
completion.text_column = 0
@input_field.center
@input_field.on_key_press_event { |widget, event|
case Gdk::Keyval.to_name(event.keyval)
when 'Return', 'KP_Enter'
button_pressed_so_try_to_convert_the_input
end
}
hbox_holding_label_and_input_field = create_vbox(
text, @input_field
)
return hbox_holding_label_and_input_field
end
|
#run ⇒ Object
470
471
472
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 470
def run
run_super
end
|
#smaller_font? ⇒ Boolean
117
118
119
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 117
def smaller_font?
SMALLER_FONT
end
|
#update_the_statistics_frame(i = return_currently_selected_file) ⇒ Object
#
update_the_statistics_frame (update tag)
#
148
149
150
151
152
153
|
# File 'lib/dictionaries/gui/universal_widgets/dictionary/dictionary.rb', line 148
def update_the_statistics_frame(
i = return_currently_selected_file
)
@label_currently_selected_file.set_text(i)
@label_currently_selected_file.do_markify
end
|