module AsciiParadise::GUI::Gtk::WidgetModule
Constants
- HEIGHT
#¶ ↑
HEIGHT
¶ ↑#¶ ↑
- NAMESPACE
#¶ ↑
NAMESPACE
¶ ↑#¶ ↑
- NUMBERED_LINES_WIDGET_HAS_N_LINES
#¶ ↑
NUMBERED_LINES_WIDGET_HAS_N_LINES
¶ ↑#¶ ↑
- TITLE
#¶ ↑
TITLE
¶ ↑#¶ ↑
- WIDTH
#¶ ↑
WIDTH
¶ ↑#¶ ↑
Public Class Methods
new( optional_file = nil, run_already = true )
click to toggle source
run()
click to toggle source
#¶ ↑
AsciiParadise::GUI::Gtk::WidgetModule.run
¶ ↑
#¶ ↑
# File lib/ascii_paradise/gui/shared_code/animated_frame/widget_module.rb, line 413 def self.run require 'gtk_paradise/run' r = ::Gtk.run r.set_title( ::AsciiParadise::GUI::Gtk::WidgetModule::TITLE ) r << ::AsciiParadise::GUI::Gtk::Widget.new # r.status_icon # This one does not quite work. r.automatic_size_and_automatic_title r.top_left_then_run end
Public Instance Methods
add_all_html_colours_to_the_main_text_view()
click to toggle source
#¶ ↑
add_all_html_colours_to_the_main_text_view
¶ ↑
#¶ ↑
# File lib/ascii_paradise/gui/shared_code/animated_frame/widget_module.rb, line 161 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?()
click to toggle source
clear_main_buffer()
click to toggle source
connect_skeleton()
click to toggle source
#¶ ↑
connect_skeleton
¶ ↑
#¶ ↑
# File lib/ascii_paradise/gui/shared_code/animated_frame/widget_module.rb, line 442 def connect_skeleton abort_on_exception @box_vertical = gtk_vbox @label_for_the_title = gtk_label @box_vertical.minimal(@label_for_the_title) hbox = gtk_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 # Add some tearoffs. # ======================================================================= # # === hbox_for_the_combo_box_and_the_start_button # # Add the start button next, together with a combo-box on the # left hand side. # ======================================================================= # hbox_for_the_combo_box_and_the_start_button = gtk_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) # ======================================================================= # # === hbox_for_the_horizontal_button_box # # Next we will add a small panel with buttons that can be used to # clear the main dataset. # ======================================================================= # button1 = button('_Clear') button1.fancy_tooltip = ' Click this button to <b>clear the buffer</b> above. ' button1.on_click_event { clear_main_buffer } # ======================================================================= # # == The stop-the-animation button # ======================================================================= # @button_stop_the_animation = button('_Stop') @button_stop_the_animation.fancy_tooltip = ' 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>. ' # ======================================================================= # # === The three buttons # # Three buttons will be added next. # ======================================================================= # hbox_for_the_horizontal_button_box = gtk_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) # ======================================================================= # # Next, add the label and combo-box to pick a colour. # ======================================================================= # hbox_for_label_and_combo_box_for_picking_a_colour = gtk_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) # ======================================================================= # # Next add some control-elements, such as how fast the animation shall be. # ======================================================================= # hbox_with_control_elements = gtk_hbox label_for_delay = gtk_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 # ======================================================================= # # Add the Gtk::Entry that holds the amount of seconds between the # individual frames. # ======================================================================= # @entry_for_delay = entry(@default_delay) @entry_for_delay.to_the_middle # ======================================================================= # # When the user hits enter, run the animation at once. # ======================================================================= # @entry_for_delay.on_key_pressed(:enter) { start_button?.signal_emit(:clicked) } # ======================================================================= # # Next, add the HScale button. # ======================================================================= # scale_button = gtk_hscale(0.1, 3.0, 0.05) scale_button.set_digits(2) scale_button.set_value(@default_delay.to_f) # We have to sue the above default. scale_button.signal_connect(:value_changed) { |inner_widget| inner_value = inner_widget.value @entry_for_delay.set_text(inner_value.to_s) } if ::Gtk.use_gtk2? hbox_with_control_elements.pack_start(@entry_for_delay,true,false,1) else hbox_with_control_elements.pack_start( @entry_for_delay, expand: true, fill: false, padding: 1 ) end hbox_with_control_elements << scale_button @box_vertical.minimal(hbox_with_control_elements) # ======================================================================= # # === Determine how often the animated ASCII should be run # ======================================================================= # label = bold_label('Determine how often to run: ') label.is_selectable hbox_with_label_and_entry_run_n_times = gtk_hbox if ::Gtk.use_gtk2? hbox_with_label_and_entry_run_n_times.pack_start(label,true,false,1) else hbox_with_label_and_entry_run_n_times.pack_start( label, expand: true, fill: false, padding: 1 ) end # ======================================================================= # # Add the pointer emoji next: # ======================================================================= # hbox_with_label_and_entry_run_n_times.minimal(gtk_label('👉')) # A slight indicator. 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 = gtk_hbox hbox.maximal(@entry_which_component_to_use) @box_vertical.minimal(hbox) add(@box_vertical) end
create_combo_boxes()
click to toggle source
#¶ ↑
create_combo_boxes
¶ ↑
#¶ ↑
# File lib/ascii_paradise/gui/shared_code/animated_frame/widget_module.rb, line 361 def create_combo_boxes # ======================================================================= # # === @combo_box_for_picking_a_colour # ======================================================================= # @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 # # Next, add the combo box that has all AsciiParadise components, # and a hbox that keeps them all there. # ======================================================================= # @combo_box = gtk_combo_box( return_valid_and_available_ascii_paradise_components ) @combo_box.bblack1 end
create_gtk_entries()
click to toggle source
#¶ ↑
create_gtk_entries
(entries tag, entry tag)¶ ↑
#¶ ↑
# File lib/ascii_paradise/gui/shared_code/animated_frame/widget_module.rb, line 218 def create_gtk_entries # ======================================================================= # # === @entry_run_n_times # ======================================================================= # #@entry_run_n_times = entry(DEFAULT_RUN_N_TIMES.to_s) @entry_run_n_times = gtk_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 # ======================================================================= # @entry_which_component_to_use = gtk_entry { :align_to_the_center } @entry_which_component_to_use.make_bold end
create_skeleton()
click to toggle source
create_text_buffer_and_textview()
click to toggle source
#¶ ↑
create_text_buffer_and_textview
¶ ↑
#¶ ↑
# File lib/ascii_paradise/gui/shared_code/animated_frame/widget_module.rb, line 618 def create_text_buffer_and_textview @text_buffer = gtk_text_buffer # ======================================================================= # # === @text_view # ======================================================================= # @text_view = gtk_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_scrolled_window()
click to toggle source
#¶ ↑
create_the_scrolled_window
¶ ↑
#¶ ↑
# File lib/ascii_paradise/gui/shared_code/animated_frame/widget_module.rb, line 428 def create_the_scrolled_window @scrolled_window = gtk_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
do_handle_CSS()
click to toggle source
do_show_a_random_ascii_paradise_animation()
click to toggle source
#¶ ↑
do_show_a_random_ascii_paradise_animation
(random tag)¶ ↑
This method can be used to pick a random animation.
#¶ ↑
# File lib/ascii_paradise/gui/shared_code/animated_frame/widget_module.rb, line 399 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) # Returns false if it does not find the input. 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()
click to toggle source
#¶ ↑
do_stop_the_animation
¶ ↑
#¶ ↑
# File lib/ascii_paradise/gui/shared_code/animated_frame/widget_module.rb, line 118 def do_stop_the_animation @thread_is_running = false end
Also aliased as: stop_the_current_iteration
entry_which_component_to_use?()
click to toggle source
#¶ ↑
entry_which_component_to_use?¶ ↑
#¶ ↑
# File lib/ascii_paradise/gui/shared_code/animated_frame/widget_module.rb, line 236 def entry_which_component_to_use? @entry_which_component_to_use end
Also aliased as: main_entry?
reset()
click to toggle source
#¶ ↑
reset¶ ↑
#¶ ↑
# File lib/ascii_paradise/gui/shared_code/animated_frame/widget_module.rb, line 72 def reset reset_the_internal_variables # ======================================================================= # # === @configuration # ======================================================================= # @configuration = [true, __dir__, NAMESPACE] # ======================================================================= # # === @title # ======================================================================= # set_title(TITLE) # ======================================================================= # # === @height # ======================================================================= # set_height(HEIGHT) # ======================================================================= # # === @width # ======================================================================= # set_width(WIDTH) # ======================================================================= # # === @default_delay # ======================================================================= # @default_delay = DEFAULT_DELAY # ======================================================================= # # === @thread_is_running # ======================================================================= # @thread_is_running = false # ======================================================================= # # === @hash_all_tags # ======================================================================= # @hash_all_tags = {} infer_the_size_automatically increase_font_size do_handle_CSS end
return_text_from_the_currently_selected_entry_in_the_combo_box()
click to toggle source
return_the_html_colours()
click to toggle source
return_valid_and_available_ascii_paradise_components()
click to toggle source
#¶ ↑
return_valid_and_available_ascii_paradise_components
¶ ↑
#¶ ↑
# File lib/ascii_paradise/gui/shared_code/animated_frame/widget_module.rb, line 179 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()
click to toggle source
run_n_times?()
click to toggle source
run_the_main_loop( dataset, run_n_times = run_n_times? )
click to toggle source
#¶ ↑
run_the_main_loop
¶ ↑
#¶ ↑
# File lib/ascii_paradise/gui/shared_code/animated_frame/widget_module.rb, line 259 def run_the_main_loop( dataset, run_n_times = run_n_times? ) Thread.new { # Use a thread here. @start_button_run_this_ascii_component.grey_out @button_random_ascii_animation.grey_out @thread_is_running = true run_n_times.times { # =================================================================== # # Iterate over the dataset there. # =================================================================== # dataset.each {|entry| break unless @thread_is_running == true # ================================================================= # # Since this is an individual frame, we can simply set the buffer. # ================================================================= # 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)
click to toggle source
#¶ ↑
set_text_in_the_buffer
¶ ↑
If an Array is given to this method then it will be converted into a String.
#¶ ↑
# File lib/ascii_paradise/gui/shared_code/animated_frame/widget_module.rb, line 195 def set_text_in_the_buffer(i) if i.is_a? Array i = i.join(N) end # ======================================================================= # # We also must sync to use the right colour, by making use of CSS. # ======================================================================= # colour_to_use = @combo_box_for_picking_a_colour.active_text.to_s @text_buffer.clear # Clear the old dataset, just in case. @text_view.set_name(colour_to_use) # Pointless, but whatever. @text_buffer.insert( @text_buffer.start_iter, i, tags: [ @hash_all_tags[colour_to_use] ] ) # @text_buffer.set_text(i) # ← This was the old variant up to 22.01.2021 end
set_top_title_to(title)
click to toggle source
#¶ ↑
set_top_title_to
¶ ↑
#¶ ↑
# File lib/ascii_paradise/gui/shared_code/animated_frame/widget_module.rb, line 125 def set_top_title_to(title) # ======================================================================= # # === Set a new title for the top-label # ======================================================================= # @label_for_the_title.set_markup( %Q[<markup><span weight='bold' foreground='darkblue'>#{title}</span></markup>], true ) end
Also aliased as: set_top_title
sync_combo_box_to_main_gtk_entry()
click to toggle source
update_the_buffer_n_times_with_this_dataset( dataset, run_n_times = run_n_times?, sleep_for_this_duration = @entry_for_delay.text )
click to toggle source
#¶ ↑
update_the_buffer_n_times_with_this_dataset
¶ ↑
This method will update the text-buffer containing the “frame”.
#¶ ↑
# File lib/ascii_paradise/gui/shared_code/animated_frame/widget_module.rb, line 289 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