Class: AsciiParadise::GUI::UniversalWidgets::Widget
- Inherits:
-
Base
- Object
- Base
- AsciiParadise::GUI::UniversalWidgets::Widget
show all
- Includes:
- UniversalWidgets::BaseModule
- Defined in:
- lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb
Overview
Constant Summary
collapse
- TITLE =
'AsciiParadise::GUI::Gtk::Widget'
- DEFAULT_DELAY =
0.080
- DEFAULT_TITLE_FOR_THE_START_BUTTON =
'⬅️ Run this ascii component'
- WIDTH =
'60% or minimum 1280px'
- HEIGHT =
'30% or minimum 880px'
- USE_THIS_FONT =
'Mono 20'
- LARGER_FONT =
:hack_25
- SMALLER_FONT =
:hack_20
- NUMBERED_LINES_WIDGET_HAS_N_LINES =
18
- FONT_SIZE =
'19'
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
animation_dir?, #animation_directory?, #clear_screen, #colour_parse_this_string, #debug?, #do_not_run_already, #do_not_use_clear, #do_use_random_colour, #do_wait_for_keypress_event, e, #e, #enable_debug, #is_animated?, #menu, #project_base_dir?, #register_sigint, #remove_trailing_ansci_escape_code, #report_how_many_animated_components_exist, #return_basename_of_this_file_without_the_extension, #return_random_colour, #rev, #royalblue, #set_use_this_colour, #sfancy, #sfile, #show_available_components, #show_help, #simp, #slategrey, #sort_files, #static_dir?, #steelblue, #swarn, #use_colours?
Constructor Details
#initialize(commandline_arguments = nil, run_already = true) ⇒ Widget
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 85
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
769
770
771
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 769
def self.[](i = ARGV)
new(i)
end
|
.run(i = ARGV) ⇒ Object
752
753
754
755
756
757
758
759
760
761
762
763
764
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 752
def self.run(
i = ARGV
)
require 'gtk_paradise/run'
_ = ::AsciiParadise::GUI::Gtk::Widget.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.top_left_then_run
end
|
Instance Method Details
#add_all_html_colours_to_the_main_text_view ⇒ Object
#
add_all_html_colours_to_the_main_text_view
#
180
181
182
183
184
185
186
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 180
def add_all_html_colours_to_the_main_text_view
return_the_html_colours.each {|this_html_colour|
this_html_colour = this_html_colour.to_s
@hash_all_tags[this_html_colour] =
@text_buffer.create_tag(nil, { foreground: this_html_colour })
}
end
|
#border_size? ⇒ Boolean
306
307
308
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 306
def border_size?
10
end
|
#clear_main_buffer ⇒ Object
#
clear_main_buffer
This method is triggered when the user clicks on the clear-button.
#
299
300
301
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 299
def clear_main_buffer
set_text_in_the_buffer('')
end
|
#connect_the_skeleton ⇒ Object
#
connect_the_skeleton (connect tag)
#
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 498
def connect_the_skeleton
abort_on_exception
outer_vbox = create_vbox
@box_vertical = create_vbox
@label_for_the_title = create_label
@box_vertical.minimal(@label_for_the_title)
hbox = create_hbox
@numbered_lines = ::Gtk::NumberedLines.new {{ upper_range: NUMBERED_LINES_WIDGET_HAS_N_LINES }}
@numbered_lines.set_use_this_font("Mono #{FONT_SIZE}")
hbox.minimal(@numbered_lines, 1)
hbox.maximal(@scrolled_window)
@box_vertical.minimal(hbox, 1)
@combo_box.on_changed {
sync_combo_box_to_main_gtk_entry
stop_the_current_iteration
}
@combo_box.active = 92
@combo_box.add_tearoffs = true hbox_for_the_combo_box_and_the_start_button = create_hbox
hbox_for_the_combo_box_and_the_start_button << @combo_box
hbox_for_the_combo_box_and_the_start_button.maximal(
create_and_return_the_start_button
)
@box_vertical.minimal(hbox_for_the_combo_box_and_the_start_button)
button1 = button('_Clear')
button1.hint = ' Click this button to <b>clear the buffer</b> above. '
button1.on_click_event {
clear_main_buffer
}
@button_stop_the_animation = button('_Stop')
@button_stop_the_animation.hint = ' Click this button to <b>stop the animation</b> above. '
@button_stop_the_animation.on_click_event {
do_stop_the_animation
}
text = '_Run a random AsciiParadise animation'
@button_random_ascii_animation = button(text)
@button_random_ascii_animation.on_click_event {
do_show_a_random_ascii_paradise_animation
}
@button_random_ascii_animation.hint =
' Click this button to <b>run a random ASCII animation</b>. '
hbox_for_the_horizontal_button_box = create_hbox
hbox_for_the_horizontal_button_box.minimal(button1)
hbox_for_the_horizontal_button_box.minimal(@button_stop_the_animation)
hbox_for_the_horizontal_button_box.maximal(@button_random_ascii_animation)
@box_vertical.minimal(hbox_for_the_horizontal_button_box)
hbox_for_label_and_combo_box_for_picking_a_colour = create_hbox
hbox_for_label_and_combo_box_for_picking_a_colour.minimal(
text('Pick a colour to use for the animation (default is <b>black</b>) ➡️ ',
1)
)
index = ::Colours.html_colours.find_index {|entry| entry == 'black' }
@combo_box_for_picking_a_colour.active = index
hbox_for_label_and_combo_box_for_picking_a_colour.maximal(
@combo_box_for_picking_a_colour
)
@box_vertical.minimal(hbox_for_label_and_combo_box_for_picking_a_colour, 1)
hbox_with_control_elements = create_hbox
label_for_delay = bold_label(
'Determine how fast the animation shall be:'
)
label_for_delay.is_selectable
label_for_delay.hint = 'The lower the value to the right, '\
'the faster the animation will run.'
hbox_with_control_elements << label_for_delay
@entry_for_delay = entry(@default_delay.to_s)
@entry_for_delay.to_the_middle
@entry_for_delay.on_key_pressed(:enter) {
start_button?.signal_emit(:clicked)
}
scale_button = create_hscale(0.1, 3.0, 0.05)
scale_button.set_digits(2)
scale_button.set_value(@default_delay.to_f) scale_button.signal_connect(:value_changed) { |inner_widget|
inner_value = inner_widget.value
@entry_for_delay.set_text(inner_value.to_s)
}
hbox_with_control_elements.pack_start(
@entry_for_delay, expand: true, fill: false, padding: 1
)
hbox_with_control_elements << scale_button
@box_vertical.minimal(hbox_with_control_elements)
label = bold_label('Determine how often to run: ')
label.is_selectable
hbox_with_label_and_entry_run_n_times = create_hbox
hbox_with_label_and_entry_run_n_times.pack_start(
label, expand: true, fill: false, padding: 1
)
hbox_with_label_and_entry_run_n_times.minimal(label('👉')) hbox_with_label_and_entry_run_n_times.maximal(@entry_run_n_times, 2)
@box_vertical.minimal(hbox_with_label_and_entry_run_n_times)
@array_buttons = []
@array_buttons << @button_stop_the_animation
@array_buttons << button1
@array_buttons << @button_random_ascii_animation
@array_buttons << @start_button_run_this_ascii_component
process_each_button
hbox = create_hbox
hbox.maximal(@entry_which_component_to_use)
@box_vertical.minimal(hbox)
outer_vbox.add(@box_vertical)
window = create_window_or_runner
window << outer_vbox
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
|
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 398
def create_and_return_the_start_button
@start_button_run_this_ascii_component = button(
DEFAULT_TITLE_FOR_THE_START_BUTTON
)
@start_button_run_this_ascii_component.fancy_tooltip =
' Click this button to <b>run the specified ascii-component</b>. '
@start_button_run_this_ascii_component.on_clicked {
component = return_text_from_the_currently_selected_entry_in_the_combo_box
if component.empty?
_ = 'Please supply an entry for the dataset.'
e _
set_text_in_buffer(_)
else
dataset = ::AsciiParadise.return_dataset_for(component.to_sym) if dataset
update_the_buffer_n_times_with_this_dataset(dataset)
else
set_text(
'This component ('+@entry_which_component_to_use.text.to_s+
') has no .dataset? method.'
)
end
end
}
return @start_button_run_this_ascii_component
end
|
#create_combo_boxes ⇒ Object
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 445
def create_combo_boxes
@combo_box_for_picking_a_colour = combo_box_text
@combo_box_for_picking_a_colour.populate(
::Colours.html_colours
)
@combo_box_for_picking_a_colour.bblack1
@combo_box_for_picking_a_colour.hint = 'You can also change the '\
'colour as the text-view buffer iterates through.'
@combo_box = create_combo_box(
return_valid_and_available_ascii_paradise_components
)
@combo_box.bblack1
end
|
#create_gtk_entries ⇒ Object
#
create_gtk_entries (entries tag, entry tag)
#
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 237
def create_gtk_entries
@entry_run_n_times = create_spin_button(1, 1000, 1)
@entry_run_n_times.to_the_middle
@entry_run_n_times.very_light_yellow_background_colour
@entry_which_component_to_use = create_entry { :align_to_the_center }
@entry_which_component_to_use.make_bold
end
|
#create_text_buffer_and_textview ⇒ Object
#
create_text_buffer_and_textview
#
669
670
671
672
673
674
675
676
677
678
679
680
681
682
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 669
def create_text_buffer_and_textview
@text_buffer = create_text_buffer
@text_view = create_text_view(@text_buffer)
@text_view.the_cursor_is_not_visible
@text_view.use_this_font = :hack_12
@text_view.indent = 10
@text_view.set_left_margin(2)
@text_view.set_editable(true)
@text_view.set_name('black')
add_all_html_colours_to_the_main_text_view
end
|
#create_the_combo_box_entry ⇒ Object
#
create_the_combo_box_entry
#
481
482
483
484
485
486
487
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 481
def create_the_combo_box_entry
@combo_box_entry = create_combo_box_text
@combo_box_entry.css_class('combo_box1')
end
|
703
704
705
706
707
708
709
710
711
712
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 703
def create_the_scrolled_window
@scrolled_window = create_scrolled_window(@text_view)
@scrolled_window.set_name('scrolledwindow1')
@scrolled_window.width_height(880, 380)
if @scrolled_window.respond_to? :min_content_height
@scrolled_window.min_content_width = 880
@scrolled_window.min_content_height = 380
end
@scrolled_window.show_scrollbars
end
|
#create_the_skeleton ⇒ Object
#
create_the_skeleton (create tag, skeleton tag)
#
717
718
719
720
721
722
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 717
def create_the_skeleton
create_combo_boxes
create_gtk_entries
create_text_buffer_and_textview
create_the_scrolled_window
end
|
492
493
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 492
def do_all_startup_related_actions
end
|
#do_show_a_random_ascii_paradise_animation ⇒ Object
#
do_show_a_random_ascii_paradise_animation (random tag)
This method can be used to pick a random animation.
#
689
690
691
692
693
694
695
696
697
698
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 689
def do_show_a_random_ascii_paradise_animation
array = return_valid_and_available_ascii_paradise_components
sample = array.sample
dataset = ::AsciiParadise.return_dataset_for(sample.to_sym) if dataset
update_the_buffer_n_times_with_this_dataset(dataset)
@combo_box.active = array.index(sample)
set_top_title(sample.to_s)
end
end
|
#do_stop_the_animation ⇒ Object
Also known as:
stop_the_current_iteration
#
do_stop_the_animation
#
137
138
139
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 137
def do_stop_the_animation
@thread_is_running = false
end
|
#entry_which_component_to_use? ⇒ Boolean
Also known as:
main_entry?
#
entry_which_component_to_use?
#
290
291
292
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 290
def entry_which_component_to_use?
@entry_which_component_to_use
end
|
#favicon? ⇒ Boolean
255
256
257
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 255
def favicon?
:tabble
end
|
#handle_CSS_rules ⇒ Object
#
handle_CSS_rules (CSS tag)
#
269
270
271
272
273
274
275
276
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 269
def handle_CSS_rules
use_gtk_paradise_project_css_file
append_project_css_file
more_CSS_then_apply_it '
'
end
|
#minimum_height? ⇒ Boolean
329
330
331
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 329
def minimum_height?
200
end
|
#minimum_width? ⇒ Boolean
336
337
338
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 336
def minimum_width?
120
end
|
#padding? ⇒ Boolean
313
314
315
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 313
def padding?
0
end
|
#populate_the_combo_box ⇒ Object
#
populate_the_combo_box
#
471
472
473
474
475
476
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 471
def populate_the_combo_box
@available_components.each {|entry|
@combo_box_entry.append_text(entry.to_s)
}
end
|
170
171
172
173
174
175
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 170
def process_each_button
@array_buttons.each {|this_button|
this_button.mediumaquamarine
this_button.set_name('button1')
}
end
|
#reset ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 102
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, "Mono #{FONT_SIZE}")
if use_gtk3?
handle_CSS_rules
end
infer_the_size_automatically
@default_delay = DEFAULT_DELAY
@thread_is_running = false
@hash_all_tags = {}
end
|
#reset_the_shared_module ⇒ Object
#
reset_the_shared_module
This method can be used for ruby-gtk3 and ruby-libui, among other toolkits.
#
284
285
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 284
def reset_the_shared_module
end
|
#return_text_from_the_currently_selected_entry_in_the_combo_box ⇒ Object
#
return_text_from_the_currently_selected_entry_in_the_combo_box
#
727
728
729
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 727
def return_text_from_the_currently_selected_entry_in_the_combo_box
@combo_box.active_text.to_s
end
|
#return_the_html_colours ⇒ Object
#
return_the_html_colours
#
191
192
193
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 191
def return_the_html_colours
::Colours.html_colours
end
|
#return_valid_and_available_ascii_paradise_components ⇒ Object
#
return_valid_and_available_ascii_paradise_components
#
198
199
200
201
202
203
204
205
206
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 198
def return_valid_and_available_ascii_paradise_components
::AsciiParadise.available_components.reject {|entry|
(entry == 'Counter') or
(entry == 'ProgressBar') or
(entry == 'RotatingDna') or
(entry == 'RotatingSlash') or
(entry == 'RotatingCube')
}
end
|
#run ⇒ Object
745
746
747
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 745
def run
run_super
end
|
#run_n_times? ⇒ Boolean
391
392
393
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 391
def run_n_times?
@entry_run_n_times.text.to_i
end
|
#run_the_main_loop(dataset, run_n_times = run_n_times?
) ⇒ Object
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 343
def run_the_main_loop(
dataset, run_n_times = run_n_times?
)
Thread.new { @start_button_run_this_ascii_component.grey_out
@button_random_ascii_animation.grey_out
@thread_is_running = true
run_n_times.times {
dataset.each {|entry|
break unless @thread_is_running == true
set_in_buffer(entry)
sleep(@sleep_for_this_duration)
}
}
@start_button_run_this_ascii_component.grey_in
@button_random_ascii_animation.grey_in
}
end
|
#set_text_in_the_buffer(i) ⇒ Object
Also known as:
set_text_in_buffer, set_text, set_in_buffer
#
set_text_in_the_buffer
If an Array is given to this method then it will be converted into a String.
#
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 214
def set_text_in_the_buffer(i)
if i.is_a? Array
i = i.join(N)
end
colour_to_use = @combo_box_for_picking_a_colour.active_text.to_s
@text_buffer.clear @text_view.set_name(colour_to_use) @text_buffer.insert(
@text_buffer.start_iter,
i,
tags: [ @hash_all_tags[colour_to_use] ]
)
end
|
#set_top_title_to(title) ⇒ Object
Also known as:
set_top_title
144
145
146
147
148
149
150
151
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 144
def set_top_title_to(title)
@label_for_the_title.set_markup(
%Q[<markup><span weight='bold' foreground='darkblue'>#{title}</span></markup>], true
)
end
|
#smaller_font? ⇒ Boolean
262
263
264
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 262
def smaller_font?
SMALLER_FONT
end
|
163
164
165
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 163
def start_button?
@start_button_run_this_ascii_component
end
|
#sync_combo_box_to_main_gtk_entry ⇒ Object
#
sync_combo_box_to_main_gtk_entry
#
734
735
736
737
738
739
740
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 734
def sync_combo_box_to_main_gtk_entry
if @combo_box.active_iter
main_entry?.set_text(
return_text_from_the_currently_selected_entry_in_the_combo_box
)
end
end
|
#update_the_buffer_n_times_with_this_dataset(dataset, run_n_times = run_n_times?,
, sleep_for_this_duration = @entry_for_delay.text) ⇒ Object
#
update_the_buffer_n_times_with_this_dataset
This method will update the text-buffer containing the “frame”.
#
373
374
375
376
377
378
379
380
381
382
383
384
385
386
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 373
def update_the_buffer_n_times_with_this_dataset(
dataset,
run_n_times = run_n_times?,
sleep_for_this_duration = @entry_for_delay.text
)
if sleep_for_this_duration and sleep_for_this_duration.empty?
sleep_for_this_duration = DEFAULT_DELAY
else
sleep_for_this_duration = sleep_for_this_duration.to_f
end
@sleep_for_this_duration = sleep_for_this_duration
set_top_title_to(@entry_which_component_to_use.text.to_s)
run_the_main_loop(dataset, run_n_times?)
end
|
#use_which_delay? ⇒ Boolean
156
157
158
|
# File 'lib/ascii_paradise/gui/universal_widgets/animated_frame/widget.rb', line 156
def use_which_delay?
@entry_for_delay.text.to_f
end
|