Class: Roebe::GUI::InteractiveCaesarCipher
Overview
Roebe::GUI::InteractiveCaesarCipher
Constant Summary
Roebe::GUI::InteractiveCaesarCipherModule::ALPHABET, Roebe::GUI::InteractiveCaesarCipherModule::CSS_SMALL_BORDER, Roebe::GUI::InteractiveCaesarCipherModule::HEIGHT, Roebe::GUI::InteractiveCaesarCipherModule::HELPER_TEXT_FOR_THE_MAIN_HEADER_LABEL, Roebe::GUI::InteractiveCaesarCipherModule::LARGER_FONT, Roebe::GUI::InteractiveCaesarCipherModule::TITLE, Roebe::GUI::InteractiveCaesarCipherModule::USE_THIS_FONT, Roebe::GUI::InteractiveCaesarCipherModule::WIDTH
Class Method Summary
collapse
-
.[](i = ARGV) ⇒ Object
# === Roebe::GUI::InteractiveCaesarCipher[] ========================================================================= #.
Instance Method Summary
collapse
#add_to_array_entries, #array_entries?, #border_size?, #entry2?, #last_entry?, #padding?, #reset_the_shared_module, #return_text1, #return_text2, #return_text3, #set_top_right_entry, #title?, #top_left_entry?
Constructor Details
#initialize(commandline_arguments = ARGV, run_already = true) ⇒ InteractiveCaesarCipher
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/roebe/gui/universal_widgets/interactive_caesar_cipher/interactive_caesar_cipher.rb', line 46
def initialize(
commandline_arguments = ARGV,
run_already = true
)
super(:vertical) if use_gtk3?
reset
set_commandline_arguments(
commandline_arguments
)
run if run_already
end
|
Class Method Details
.[](i = ARGV) ⇒ Object
#
Roebe::GUI::InteractiveCaesarCipher[]
#
368
369
370
|
# File 'lib/roebe/gui/universal_widgets/interactive_caesar_cipher/interactive_caesar_cipher.rb', line 368
def self.[](i = ARGV)
new(i)
end
|
Instance Method Details
#append_a_hcentered_entry ⇒ Object
#
append_a_hcentered_entry
#
132
133
134
135
136
|
# File 'lib/roebe/gui/universal_widgets/interactive_caesar_cipher/interactive_caesar_cipher.rb', line 132
def append_a_hcentered_entry
add_to_array_entries(
hcentered_entry
)
end
|
#create_the_apple_entry_then_append_it_onto_the_proper_array ⇒ Object
#
create_the_apple_entry_then_append_it_onto_the_proper_array
The “APPLE” entry is the top-left entry.
#
214
215
216
217
218
219
220
221
222
223
224
|
# File 'lib/roebe/gui/universal_widgets/interactive_caesar_cipher/interactive_caesar_cipher.rb', line 214
def create_the_apple_entry_then_append_it_onto_the_proper_array
apple_entry = create_entry('APPLE')
if apple_entry.respond_to? :on_enter
apple_entry.on_enter {
do_evaluate_the_cipher
} unless uses_gtk4?
end
add_to_array_entries(
apple_entry
)
end
|
#create_the_crrng_entry_then_append_it_onto_the_proper_array ⇒ Object
#
create_the_crrng_entry_then_append_it_onto_the_proper_array
#
122
123
124
125
126
127
|
# File 'lib/roebe/gui/universal_widgets/interactive_caesar_cipher/interactive_caesar_cipher.rb', line 122
def create_the_crrng_entry_then_append_it_onto_the_proper_array
add_to_array_entries(
create_entry('CRRNG')
)
end
|
#create_the_grid ⇒ Object
#
create_the_grid (grid tag)
#
141
142
143
144
145
146
147
148
149
150
|
# File 'lib/roebe/gui/universal_widgets/interactive_caesar_cipher/interactive_caesar_cipher.rb', line 141
def create_the_grid
@grid = create_grid { :default }
@grid.set_border_width(10)
@grid.spacing1 = 2
@grid.spacing2 = 2
@grid.pad8px
end
|
#create_the_main_window ⇒ Object
#
create_the_main_window
#
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/roebe/gui/universal_widgets/interactive_caesar_cipher/interactive_caesar_cipher.rb', line 104
def create_the_main_window
@main_window = create_window(WIDTH, HEIGHT, TITLE, margin: true)
@main_window.enable_free_form_css
@main_window.try_to_add_default_CSS_rules
@main_window.try_to_use_this_font(USE_THIS_FONT)
@main_window.pad8px
@main_window.set_border_width 12
if use_gtk3?
@main_window.extend ::Gtk::BaseModule
@main_window.extend ::Gtk::RunModule
@main_window.easy_quit
end
end
|
#create_the_skeleton ⇒ Object
#
create_the_skeleton (create tag, skeleton tag)
#
95
96
97
98
99
|
# File 'lib/roebe/gui/universal_widgets/interactive_caesar_cipher/interactive_caesar_cipher.rb', line 95
def create_the_skeleton
create_the_main_window
create_the_spin_buttons
create_the_grid
end
|
236
237
238
239
240
241
242
|
# File 'lib/roebe/gui/universal_widgets/interactive_caesar_cipher/interactive_caesar_cipher.rb', line 236
def create_the_spin_buttons
@spin_button = centered_spin_button(0, 30) {{ start_value: '2' }}
@array_spin_buttons << @spin_button
end
|
195
196
197
198
199
200
201
202
203
204
205
206
207
|
# File 'lib/roebe/gui/universal_widgets/interactive_caesar_cipher/interactive_caesar_cipher.rb', line 195
def (
title = title?
)
= bold_text(title)
.use_this_font = LARGER_FONT
.hint = HELPER_TEXT_FOR_THE_MAIN_HEADER_LABEL
.align_to_the_left
.css_class('small_border')
return
end
|
#determine_the_top_right_entry(input_sequence = top_left_entry?
) ⇒ Object
Also known as:
do_evaluate_the_cipher
#
determine_the_top_right_entry
This method is typically called when the spin-button’s value is changed:
spin_button.on_changed {
determine_the_top_right_entry
}
Note that for the caesar-cipher, if we go above the letter ‘Z’ then we have to start at ‘A’ again. The old code until September 2022 did not factor in this situation.
The method .ord() will return a number, such as ‘A’.ord # => 65.
#
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
363
|
# File 'lib/roebe/gui/universal_widgets/interactive_caesar_cipher/interactive_caesar_cipher.rb', line 334
def determine_the_top_right_entry(
input_sequence = top_left_entry?
)
can_we_work_on_the_input_sequence = input_sequence.respond_to?(:text?)
if input_sequence.is_a?(String)
can_we_work_on_the_input_sequence = true
end
if input_sequence and can_we_work_on_the_input_sequence
base_value = 'A'.ord max_value = 'Z'.ord if input_sequence.respond_to?(:text?)
input_sequence = input_sequence.text?
end
modified_sequence = input_sequence.chars.map {|entry|
number_in_ASCII_for_the_character_at_hand = entry.ord
modifier_to_use = @array_spin_buttons[0].text?.to_i new_value = number_in_ASCII_for_the_character_at_hand +
modifier_to_use
if new_value > max_value
new_value = (new_value - max_value) + (base_value - 1)
end
new_value.chr }.join
set_top_right_entry(modified_sequence.upcase)
end
end
|
#do_colourize_all_entries(array = @array_entries) ⇒ Object
#
do_colourize_all_entries
#
155
156
157
158
159
160
161
|
# File 'lib/roebe/gui/universal_widgets/interactive_caesar_cipher/interactive_caesar_cipher.rb', line 155
def do_colourize_all_entries(
array = @array_entries
)
array.each {|entry|
entry.default_styling }
end
|
#do_populate_the_main_grid ⇒ Object
#
do_populate_the_main_grid
This variant is more specific to gtk. It was added into the module, though, because both ruby-gtk3 and ruby-gtk4 may benefit from this code. In theory libui and jruby-swing could also make use of this, but right now this has not been enabled yet.
#
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
# File 'lib/roebe/gui/universal_widgets/interactive_caesar_cipher/interactive_caesar_cipher.rb', line 171
def do_populate_the_main_grid
@grid.left(return_text1)
@grid.middle(return_text2)
@grid.right(return_text3)
create_the_apple_entry_then_append_it_onto_the_proper_array
@grid.left(last_entry?)
@grid.middle(last_array_spin_button?)
append_a_hcentered_entry
@grid.right(last_entry?)
create_the_crrng_entry_then_append_it_onto_the_proper_array
@grid.left(last_entry?)
@grid.middle(centered_spin_button('1'))
append_a_hcentered_entry
@grid.right(last_entry?)
@grid.hcenter
end
|
#handle_the_CSS_rules ⇒ Object
73
74
75
76
|
# File 'lib/roebe/gui/universal_widgets/interactive_caesar_cipher/interactive_caesar_cipher.rb', line 73
def handle_the_CSS_rules
use_gtk_paradise_project_css_file
more_CSS_defined_in_this_file
end
|
229
230
231
|
# File 'lib/roebe/gui/universal_widgets/interactive_caesar_cipher/interactive_caesar_cipher.rb', line 229
def last_array_spin_button?
@array_spin_buttons.last
end
|
#let_the_main_spin_button_respond_to_change_events ⇒ Object
#
let_the_main_spin_button_respond_to_change_events
#
247
248
249
250
251
|
# File 'lib/roebe/gui/universal_widgets/interactive_caesar_cipher/interactive_caesar_cipher.rb', line 247
def let_the_main_spin_button_respond_to_change_events
@spin_button.on_changed {
determine_the_top_right_entry
}
end
|
#more_CSS_defined_in_this_file ⇒ Object
#
more_CSS_defined_in_this_file
#
81
82
83
|
# File 'lib/roebe/gui/universal_widgets/interactive_caesar_cipher/interactive_caesar_cipher.rb', line 81
def more_CSS_defined_in_this_file
more_CSS(return_the_CSS_rules_for_this_module)
end
|
61
62
63
64
65
66
67
68
|
# File 'lib/roebe/gui/universal_widgets/interactive_caesar_cipher/interactive_caesar_cipher.rb', line 61
def reset
super() if respond_to?(:super)
reset_the_internal_variables
reset_the_shared_module infer_the_namespace
width_height(WIDTH, HEIGHT)
use_gtk_paradise_project_css_file
end
|
#return_the_CSS_rules_for_this_module ⇒ Object
#
return_the_CSS_rules_for_this_module
#
88
89
90
|
# File 'lib/roebe/gui/universal_widgets/interactive_caesar_cipher/interactive_caesar_cipher.rb', line 88
def return_the_CSS_rules_for_this_module
return CSS_SMALL_BORDER
end
|
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
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
|
# File 'lib/roebe/gui/universal_widgets/interactive_caesar_cipher/interactive_caesar_cipher.rb', line 256
def run
create_the_skeleton
outer_vbox = padded_vbox
text_on_top = outer_vbox.minimal(hsep)
outer_vbox.minimal(text_on_top)
if use_gtk3?
outer_vbox.minimal(@grid) else first_row = padded_hbox
_ = return_text1
_.pad8px
first_row.minimal(_)
_ = text('modifier')
_.pad8px
first_row.minimal(_)
_ = text('ciphertext')
_.pad8px
first_row.minimal(_)
outer_vbox.minimal(first_row)
second_row = padded_hbox
entry1 = entry('APPLE')
@array_entries << entry1
second_row.minimal(entry1)
spin_button1 = spinbutton @array_spin_buttons << spin_button1
second_row.minimal(spin_button1)
entry2 = entry('CRRNG')
@array_entries << entry2
second_row.minimal(entry2)
outer_vbox.minimal(second_row)
third_row = padded_hbox
third_row.minimal(entry('CRRNG'))
spin_button2 = spinbutton @array_spin_buttons << spin_button2
third_row.minimal(spin_button2)
entry3 = entry()
@array_entries << entry3
third_row.minimal(entry3)
outer_vbox.minimal(third_row)
end
do_populate_the_main_grid
do_colourize_all_entries
determine_the_top_right_entry
let_the_main_spin_button_respond_to_change_events
@main_window << outer_vbox
@main_window.intelligent_exit
@main_window.top_left
@main_window.show_all
run_main
end
|