class ImageParadise::GUI::Gtk::CfdgWidget
Constants
- HEIGHT
#¶ ↑
HEIGHT
¶ ↑#¶ ↑
- IMG_DIRECTORY
#¶ ↑
IMG_DIRECTORY
¶ ↑This constant only works for my home setup.
#¶ ↑
- NAMESPACE
#¶ ↑
NAMESPACE
¶ ↑#¶ ↑
- POSSIBLE_RESOLUTIONS
#¶ ↑
POSSIBLE_RESOLUTIONS
¶ ↑The first entry should be the default variant.
#¶ ↑
- SMALLER_FONT
#¶ ↑
SMALLER_FONT
¶ ↑#¶ ↑
- TITLE
#¶ ↑
TITLE
¶ ↑#¶ ↑
- TOOLTIP_EDITOR
#¶ ↑
TOOLTIP_EDITOR
¶ ↑#¶ ↑
- USE_THIS_FONT
#¶ ↑
USE_THIS_FONT
¶ ↑#¶ ↑
- WIDTH
#¶ ↑
WIDTH
¶ ↑#¶ ↑
- YOUR_FAVOURITE_EDITOR
#¶ ↑
YOUR_FAVOURITE_EDITOR
¶ ↑Easier constant “alias” to the editor in use.
#¶ ↑
Public Class Methods
new( commandline_arguments = ARGV, run_already = true )
click to toggle source
run( i = ARGV )
click to toggle source
#¶ ↑
ImageParadise::GUI::Gtk::CfdgWidgetModule.run¶ ↑
#¶ ↑
# File lib/image_paradise/gui/gtk3/cfdg_widget/cfdg_widget.rb, line 1028 def self.run( i = ARGV ) require 'gtk_paradise/app/app' _ = ::ImageParadise::GUI::Gtk::CfdgWidget.new(i) r = ::Gtk.app r << _ r.enable_context_menu r.on_button_press_event { |widget, event| if ::Gtk.right_mouse_click?(event) # right mouse click event. _.context_menu?.popup_based_on_this_event(event) end } r.automatic_size_and_automatic_title r.middle_of_the_screen_then_run end
Public Instance Methods
border_size?()
click to toggle source
clear_buffer()
click to toggle source
connect_skeleton()
click to toggle source
#¶ ↑
connect_skeleton
(connect tag)¶ ↑
#¶ ↑
# File lib/image_paradise/gui/gtk3/cfdg_widget/cfdg_widget.rb, line 233 def connect_skeleton abort_on_exception @text_buffer = gtk_text_buffer use_this_cfdg_file(@show_this_cfdg_file) @text_view = gtk_text_view(@text_buffer) mini_hbox_containing_the_numbered_lines_and_the_text_view = gtk_hbox _ = @numbered_lines _.set_use_this_font(USE_THIS_FONT) # Sync the font in use here. mini_hbox_containing_the_numbered_lines_and_the_text_view.minimal( _ ) mini_hbox_containing_the_numbered_lines_and_the_text_view.maximal(@text_view) @scrolled_window1 = gtk_scrolled_window( mini_hbox_containing_the_numbered_lines_and_the_text_view ) { :always } @scrolled_window1.width_height(400, 800) @scrolled_window1.bblack1 @scrolled_window1.css_class('pad2px') # ======================================================================= # # === @image1 # ======================================================================= # @image1 = gtk_image @image1.bblack1 @image1.css_class('mar8px') # ======================================================================= # # Put that image into the second scrolled window. # ======================================================================= # vbox = gtk_vbox small_hbox = padded_hbox small_hbox.minimal(return_the_spinner_on_top, 5) small_hbox.maximal(@button_render_again) vbox.minimal(small_hbox) vbox.maximal(@image1) @scrolled_window2 = gtk_scrolled_window(vbox) { :always } @scrolled_window2.width_height(300, 300) @scrolled_window2.css_class('pad5px') pane_top_to_bottom = gtk_pane_top_to_bottom( @scrolled_window1, @scrolled_window2 ) pane_top_to_bottom.position = 900 small_vbox = gtk_vbox small_vbox.minimal(@label_file_name_top) pane_top_to_bottom_and_scrolled_widget = gtk_hbox # ======================================================================= # # Add the widget containing each .cfdg file as a button. # ======================================================================= # pane_top_to_bottom_and_scrolled_widget.maximal(pane_top_to_bottom) pane_top_to_bottom_and_scrolled_widget.minimal( return_scrolled_window_widget_containing_each_cfdg_file_as_a_button, 2 ) small_vbox.maximal(pane_top_to_bottom_and_scrolled_widget) # ======================================================================= # # Add the widget with lots of buttons, via the method called # .return_button_widget(). This one is on the very right side. # ======================================================================= # _ = gtk_pane_top_to_bottom(small_vbox, return_button_widget) minimal(_) _.position = 1520 do_style_all_the_buttons_uniformly end
create_combo_box()
click to toggle source
#¶ ↑
create_combo_box
¶ ↑
#¶ ↑
# File lib/image_paradise/gui/gtk3/cfdg_widget/cfdg_widget.rb, line 361 def create_combo_box @combo_box = gtk_combo_box_text @combo_box.bblack1 POSSIBLE_RESOLUTIONS.each { |entry| @combo_box.append_text(entry) } @combo_box.active = 0 # @combo_box.set_halign(::Gtk::Align::CENTER) # @combo_box.set_hexpand(true) end
create_skeleton()
click to toggle source
#¶ ↑
create_skeleton
(create tag)¶ ↑
#¶ ↑
# File lib/image_paradise/gui/gtk3/cfdg_widget/cfdg_widget.rb, line 219 def create_skeleton create_the_context_menu create_combo_box create_the_checkboxes create_the_event_box_for_the_browser create_the_buttons create_the_label_file_name_on_top create_the_entries create_the_event_box_for_the_bluefish_editor end
create_the_checkboxes()
click to toggle source
create_the_entries()
click to toggle source
#¶ ↑
create_the_entries
(entries tag, entry tag)¶ ↑
#¶ ↑
# File lib/image_paradise/gui/gtk3/cfdg_widget/cfdg_widget.rb, line 321 def create_the_entries # ======================================================================= # # @entry_width is on the top. # ======================================================================= # @entry_width = gtk_entry @entry_width.set_max_length(8) @entry_width.center @entry_width.on_click_select_everything @entry_width.lightgreen_background @entry_width.bblack1 @entry_width.set_text( ::ImageParadise::ConfreeGenerator::DEFAULT_WIDTH.to_s ) @entry_width.on_changed { |widget, event| @entry_height.text = @entry_width.text if @button_check_coupled.active? } # ======================================================================= # # === @entry_height # # The height entry comes next. # ======================================================================= # @entry_height = gtk_entry @entry_height.set_max_length(8) @entry_height.center @entry_height.on_click_select_everything @entry_height.lightgreen_background @entry_height.bblack1 @entry_height.set_text( ::ImageParadise::ConfreeGenerator::DEFAULT_HEIGHT.to_s ) @entry_height.on_changed { |w,event| if @button_check_coupled.active? @entry_width.text = @entry_height.text end } end
create_the_event_box_for_the_bluefish_editor()
click to toggle source
#¶ ↑
create_the_event_box_for_the_bluefish_editor
¶ ↑
#¶ ↑
# File lib/image_paradise/gui/gtk3/cfdg_widget/cfdg_widget.rb, line 819 def create_the_event_box_for_the_bluefish_editor image_bluefish = gtk_image # Will be "filled" lateron. target_file = IMG_DIRECTORY+'/PC/EDITORS/BLUEFISH/BLUEFISH.png' if File.exist? target_file image_bluefish.set_from_file(target_file) else # ===================================================================== # # In this case we will use a custom image from the stock-items. # ===================================================================== # # image_bluefish.set(image_document_open, 25,25) image_bluefish.set_pixbuf( icon_theme_default(:document_open, 25), 25, 25 ) end @event_box_for_the_bluefish_editor = gtk_event_box @event_box_for_the_bluefish_editor.add(image_bluefish) @event_box_for_the_bluefish_editor.hint = TOOLTIP_EDITOR @event_box_for_the_bluefish_editor.on_clicked { open_file_in_editor } end
create_the_event_box_for_the_browser()
click to toggle source
#¶ ↑
create_the_event_box_for_the_browser
¶ ↑
#¶ ↑
# File lib/image_paradise/gui/gtk3/cfdg_widget/cfdg_widget.rb, line 375 def create_the_event_box_for_the_browser _ = IMG_DIRECTORY+'firefox/FIREFOX_FAVICON.png' if File.exist? _ @event_box_for_firefox = gtk_event_box firefox_image = gtk_image_from_file(_) firefox_image.hint = 'Opens a tab in the browser.' @event_box_for_firefox.add(firefox_image) # Add the firefox image here. @event_box_for_firefox.on_button_press_event { do_open_the_current_image_in_the_browser } end end
create_the_label_file_name_on_top( i = @show_this_cfdg_file )
click to toggle source
#¶ ↑
create_the_label_file_name_on_top
¶ ↑
#¶ ↑
# File lib/image_paradise/gui/gtk3/cfdg_widget/cfdg_widget.rb, line 884 def create_the_label_file_name_on_top( i = @show_this_cfdg_file ) @label_file_name_top = gtk_label @label_file_name_top.css_class('royalblue') @label_file_name_top.set_font(:hack_20) @label_file_name_top.make_bold @label_file_name_top.left_align @label_file_name_top.hint = 'This text will show the current '\ 'active .cfdg file assigned. The text-view widget below '\ 'this text holds the content of the .cfdg file.' @label_file_name_top.set_text( File.basename(i).to_s ) end
current_buffer?()
click to toggle source
do_create_a_new_file_chooser_dialog_and_then_set_the_main_entry_to( i = main_file?.to_s )
click to toggle source
#¶ ↑
do_create_a_new_file_chooser_dialog_and_then_set_the_main_entry_to
¶ ↑
#¶ ↑
# File lib/image_paradise/gui/gtk3/cfdg_widget/cfdg_widget.rb, line 1011 def do_create_a_new_file_chooser_dialog_and_then_set_the_main_entry_to( i = main_file?.to_s ) create_a_new_file_chooser_dialog(self) {{ filter: '.cfdg', additional_folders: ::ImageParadise.project_base_directory?+'cfdg/', start_dir: ::ImageParadise.project_base_directory?+'cfdg/' }} _ = ::Gtk.main_file? if _ and File.exist?(_) use_this_cfdg_file(_) end end
do_generate_all_cfdg_images()
click to toggle source
#¶ ↑
do_generate_all_cfdg_images
¶ ↑
This is the batch-generation part.
#¶ ↑
# File lib/image_paradise/gui/gtk3/cfdg_widget/cfdg_widget.rb, line 697 def do_generate_all_cfdg_images ::ImageParadise::ConfreeGenerator.batch_generate_all_images end
Also aliased as: create_batch_gallery
do_open_the_current_image_in_the_browser( _ = @output_file_location )
click to toggle source
#¶ ↑
do_open_the_current_image_in_the_browser
¶ ↑
#¶ ↑
# File lib/image_paradise/gui/gtk3/cfdg_widget/cfdg_widget.rb, line 775 def do_open_the_current_image_in_the_browser( _ = @output_file_location ) require 'open' if _ and !_.empty? e "Opening the image at #{_} next." Open.in_browser(_) else e 'You first have to create a new image file. Click '\ 'the run-button to generate a new image.' end end
Also aliased as: open_firefox_tab
do_randomize_all_hue_entries()
click to toggle source
#¶ ↑
do_randomize_all_hue_entries
¶ ↑
#¶ ↑
# File lib/image_paradise/gui/gtk3/cfdg_widget/cfdg_widget.rb, line 1073 def do_randomize_all_hue_entries old_content = text_buffer?.text?.dup if old_content.include? 'hue ' regex = /(hue \d{1,3})/ # See: https://rubular.com/r/nLkepmPs8U8WRe scanned_results = old_content.scan(regex) # The results may look like this: # # [["hue 270"], ["hue 75"]] # scanned_results.flatten.each {|this_hue_related_entry| # "hue 270" number = this_hue_related_entry.split(' ').last.to_i case rand(2) when 0 # For minus. number = number - rand(number) number = 1 if number < 0 when 1 # For upper. number = number + rand(250) number = 255 if number > 255 end old_content.gsub!(/#{this_hue_related_entry}/, 'hue '+number.to_s) } @text_buffer.set_text(old_content) render_anew # This may be commented out at some later point in time. end end
do_render_again()
click to toggle source
#¶ ↑
do_render_again
¶ ↑
#¶ ↑
# File lib/image_paradise/gui/gtk3/cfdg_widget/cfdg_widget.rb, line 1102 def do_render_again render_the_cfdg_file_again(:make_use_of_the_spinner_as_well) end
Also aliased as: render_anew
do_render_the_cfdg_file( i = nil )
do_scramble_the_cfdg_content()
click to toggle source
#¶ ↑
do_scramble_the_cfdg_content
¶ ↑
This will randomly “scramble” the cfdg content, then run the cfdg binary.
#¶ ↑
# File lib/image_paradise/gui/gtk3/cfdg_widget/cfdg_widget.rb, line 856 def do_scramble_the_cfdg_content _ = @text_buffer.text?.dup _.gsub!(/260/,'268') _.gsub!(/100/,'105') _.gsub!(/110/,'115') _.gsub!(/#{rand(300)}/,"#{rand(300)}") _.gsub!(/#{rand(300)}/,"#{rand(300)}") _.gsub!(/#{rand(300)}/,"#{rand(300)}") _.gsub!(/#{rand(300)}/,"#{rand(300)}") _.gsub!(/#{rand(300)}/,"#{rand(300)}") _.gsub!(/#{rand(300)}/,"#{rand(300)}") _.gsub!(/#{rand(300)}/,"#{rand(300)}") _.gsub!(/#{rand(300)}/,"#{rand(300)}") _.gsub!(/90/,(95+rand(60)).to_s) _.gsub!(/80/,(85+rand(50)).to_s) _.gsub!(/70/,(70+rand(40)).to_s) _.gsub!(/240/,(220+rand(40)).to_s) _.gsub!( /0.15/, (0.10 + ( rand(100) /100.0 ) ).to_s ) set_source_buffer(_) do_run end
do_use_a_new_random_cfdg_file()
click to toggle source
#¶ ↑
do_use_a_new_random_cfdg_file
¶ ↑
#¶ ↑
# File lib/image_paradise/gui/gtk3/cfdg_widget/cfdg_widget.rb, line 1000 def do_use_a_new_random_cfdg_file random_file = return_random_cfdg_file use_this_cfdg_file(random_file) if @checkbox_automatically_render_this_cfdg.is_checked? do_render_the_cfdg_file end end
do_use_the_current_buffer_for_creating_a_new_image_file( i = nil )
click to toggle source
#¶ ↑
do_use_the_current_buffer_for_creating_a_new_image_file
¶ ↑
#¶ ↑
# File lib/image_paradise/gui/gtk3/cfdg_widget/cfdg_widget.rb, line 1109 def do_use_the_current_buffer_for_creating_a_new_image_file( i = nil ) _ = current_buffer? # ======================================================================= # # We will create a new file and use that. # ======================================================================= # @home_dir = ENV['HOME'].to_s+'/image_paradise/' ::ImageParadise.mkdir(@home_dir) unless File.directory?(@home_dir) @into = @home_dir+'default_cfdg_file.cfdg' ::ImageParadise.write_what_into(_, @into) # ======================================================================= # # We need to use a consistent output-file here, as an image. # ======================================================================= # @output_file_location = @home_dir+'output.png' Thread.new { case i when :make_use_of_the_spinner_as_well the_spinner_is_now_active end result = ::ImageParadise.confreegenerator(@into) {{ output_location: @output_file_location, open_in_browser_tab: false, width: @entry_width.text?, height: @entry_height.text? }} if result.was_an_error_encountered? notify_the_user_that_the_text_view_contains_an_error end update_the_main_image_with_this_path(@output_file_location) case i # === :make_use_of_the_spinner_as_well when :make_use_of_the_spinner_as_well the_spinner_is_now_inactive end } end
favicon?()
click to toggle source
main_buffer?()
click to toggle source
#¶ ↑
main_buffer?¶ ↑
#¶ ↑
# File lib/image_paradise/gui/gtk3/cfdg_widget/cfdg_widget.rb, line 1048 def main_buffer? @text_buffer end
Also aliased as: text_buffer?
main_font?()
click to toggle source
notify_the_user_that_the_text_view_contains_an_error()
click to toggle source
#¶ ↑
notify_the_user_that_the_text_view_contains_an_error
¶ ↑
#¶ ↑
# File lib/image_paradise/gui/gtk3/cfdg_widget/cfdg_widget.rb, line 1153 def notify_the_user_that_the_text_view_contains_an_error popup_over_this_widget( text_view?, 'The buffer (text content) contains some error. Have a '\ 'look at it and correct the error, if possible.' ).popup end
open_a_random_cfdg_file()
click to toggle source
#¶ ↑
open_a_random_cfdg_file
¶ ↑
Open a random cfdg file here. This method will then invoke the method open_this_file().
#¶ ↑
# File lib/image_paradise/gui/gtk3/cfdg_widget/cfdg_widget.rb, line 987 def open_a_random_cfdg_file random_file = return_random_cfdg_file use_this_cfdg_file(random_file) e "Loading this `#{sfile(random_file)}` random file now." open_file_in_editor(random_file) if @checkbox_automatically_render_this_cfdg.is_checked? do_render_the_cfdg_file end end
open_file_in_editor( this_file = @show_this_cfdg_file )
click to toggle source
padding?()
click to toggle source
path_to_the_cfdg_directory()
click to toggle source
program_exists?(this_program)
click to toggle source
#¶ ↑
program_exists?¶ ↑
Find out whether a program exists or not.
#¶ ↑
# File lib/image_paradise/gui/gtk3/cfdg_widget/cfdg_widget.rb, line 713 def program_exists?(this_program) does_program_exist = false # default is false array_available_paths = [ ENV['SYSBIN'].to_s, '/usr/bin/'] array_available_paths.each { |path| _ = path+'/'+this_program does_program_exist = true if File.exist? _ } return does_program_exist end
render_the_cfdg_file_again( i = nil )
reset()
click to toggle source
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
# File lib/image_paradise/gui/gtk3/cfdg_widget/cfdg_widget.rb, line 121 def reset reset_the_internal_variables # ======================================================================= # # === @configuration # ======================================================================= # @configuration = [true, __dir__, NAMESPACE] # ======================================================================= # # === @title # ======================================================================= # set_title(TITLE) # ======================================================================= # # === @width # ======================================================================= # set_width(WIDTH) # ======================================================================= # # === @height # ======================================================================= # set_height(HEIGHT) set_use_this_font(USE_THIS_FONT) use_gtk_paradise_project_css_file infer_the_size_automatically # ======================================================================= # # === @numbered_lines # ======================================================================= # @numbered_lines = return_numbered_lines_widget # ======================================================================= # # === @output_file_location # ======================================================================= # @output_file_location = nil # ======================================================================= # # === @event_box_for_firefox # # The following event-box is only used on my home setup for now. # ======================================================================= # @event_box_for_firefox = nil # ======================================================================= # # === @show_this_cfdg_file # ======================================================================= # @show_this_cfdg_file = path_to_the_cfdg_directory+'water_ink.cfdg' end
return_all_cfdg_files( i = path_to_the_cfdg_directory )
click to toggle source
return_random_cfdg_file()
click to toggle source
return_the_spinner_on_top()
click to toggle source
#¶ ↑
return_the_spinner_on_top
¶ ↑
#¶ ↑
# File lib/image_paradise/gui/gtk3/cfdg_widget/cfdg_widget.rb, line 1191 def return_the_spinner_on_top # ======================================================================= # # === @spinner_on_top # ======================================================================= # @spinner_on_top = gtk_spinner return @spinner_on_top end
run()
click to toggle source
set_source_buffer(i = '')
click to toggle source
text_view?()
click to toggle source
the_spinner_is_now_active()
click to toggle source
#¶ ↑
the_spinner_is_now_active
¶ ↑
#¶ ↑
# File lib/image_paradise/gui/gtk3/cfdg_widget/cfdg_widget.rb, line 1171 def the_spinner_is_now_active @spinner_on_top.is_active # ======================================================================= # # Whenever the spinner is spinning, such as defined in the line above, # the render-again button becomes inactive (aka insensitive). # ======================================================================= # @button_render_again.is_inactive end
the_spinner_is_now_inactive()
click to toggle source
update_the_main_image_with_this_path(i)
click to toggle source
use_this_cfdg_file(i = nil)
click to toggle source
#¶ ↑
use_this_cfdg_file
¶ ↑
#¶ ↑
# File lib/image_paradise/gui/gtk3/cfdg_widget/cfdg_widget.rb, line 186 def use_this_cfdg_file(i = nil) case i when nil, 'default' i = return_random_cfdg end if i and File.exist?(i) # ===================================================================== # # Update the @show_this_cfdg_file variable. # ===================================================================== # @show_this_cfdg_file = i opn; e 'A .cfdg file was found at: '+sfile(i)+'.' @label_file_name_top.set_text(File.basename(i)) @label_file_name_top.is_selectable dataset = File.read(i) n_lines = dataset.split("\n").size if n_lines < @numbered_lines.n_entries? # =================================================================== # # Chop it down in this case. This has a bug right now; I may have # to improve on this at a later time. # =================================================================== # new_amount_of_lines = @numbered_lines.n_entries? - n_lines @numbered_lines.hide_the_last_n_lines( new_amount_of_lines ) @numbered_lines.set_use_n_lines(n_lines) end @text_buffer.set_text(dataset) # Sync the content onto the main buffer as well. end end
Also aliased as: set_file_location