class RBT::GUI::UniversalWidgets::RecipeMaker

Constants

ARRAY_AVAILABLE_PROGRAMS
#

ARRAY_AVAILABLE_PROGRAMS

#
ARRAY_WITH_PROGRAM_DIRS
#

ARRAY_WITH_PROGRAM_DIRS

#
AUTHOR_NAME
#

AUTHOR_NAME

#
DEBUG
#

DEBUG

#
DEFAULT_FONT_SIZE
#

DEFAULT_FONT_SIZE

#
GUESS_NAME
#

GUESS_NAME

#
HEIGHT
#

HEIGHT

#
LARGER_FONT
#

LARGER_FONT

#
SMALLER_FONT
#

SMALLER_FONT

#
TITLE
#

TITLE

#
USE_OVERRIDE
#

USE_OVERRIDE

#
USE_THESE_CSS_RULES
#

USE_THESE_CSS_RULES

#
USE_THIS_FONT
#

USE_THIS_FONT

#
USE_THIS_MONOSPACED_FONT
#

USE_THIS_MONOSPACED_FONT

#
VERSION_RECIPE_MAKER
#

VERSION_RECIPE_MAKER

#
WIDTH
#

WIDTH

#

Public Class Methods

[](i = ARGV) click to toggle source
#

RBT::GUI::UniversalWidgets::RecipeMaker[]

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 763
def self.[](i = ARGV)
  new(i)
end
height?() click to toggle source
#

RBT::GUI::Gtk::RecipeMaker.height?

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 69
def self.height?
  HEIGHT
end
new( commandline_arguments = ARGV, run_already = true ) click to toggle source
#

initialize

The second argument is the text which can be shown on the compile-button. The default text is ‘Compile’. The reason why this option exists is because we may want to have this widget ‘Install’ rather than ‘Compile’ sometimes.

#
Calls superclass method RBT::LeanPrototype::new
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 157
def initialize(
    commandline_arguments       = ARGV,
    run_already                 = true
  )
  super(:vertical) if use_gtk3?
  determine_the_GUI_to_be_used(commandline_arguments) # This must come first, even before reset().
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  on_delete_event_quit_the_application
  run if run_already
end
run( i = ARGV ) click to toggle source
#

RBT::GUI::Gtk::RecipeMaker.run

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 743
def self.run(
    i = ARGV
  )
  require 'gtk_paradise/run'
  _ = ::RBT::GUI::Gtk::RecipeMaker.new(i)
  r = ::Gtk.run
  _.set_parent_widget(r) # Must come before we enable the key-combinations.
  r << _
  r.add_shortcut(1,  'focus_on_entry', :alt)
  r.add_shortcut(:a, 'focus_on_entry', :alt)
  r.automatic_size_then_automatic_title
  r.enable_quick_exit
  r.set_background :white
  r.is_resizable # <- This line was added due to a possible prior .maximize action.
  r.top_left_then_run
end
width?() click to toggle source
#

RBT::GUI::Gtk::RecipeMaker.width?

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 76
def self.width?
  WIDTH
end

Public Instance Methods

append( i, append_this_string = "\n" ) click to toggle source
#

append

This will, by default, append via a newline. See the second argument to this method.

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 406
def append(
    i,
    append_this_string = "\n"
  )
  @text_buffer.append(
    "#{i}#{append_this_string}"
  )
end
border_size?() click to toggle source
#

border_size?

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 236
def border_size?
  2
end
colourize_the_buffer() click to toggle source
#

colourize_the_buffer

This method will colourize the buffer at hand.

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 439
def colourize_the_buffer
  _ = @text_buffer.text?
  @text_buffer.clear
  iter = @text_buffer.start_iter
  _.split(N).each { |line|
    case line
    when /^ last_update:/i
      @text_buffer.insert(iter, line+N,tags: ['bold','tomato'])
    # ===================================================================== #
    # === name:
    # ===================================================================== #
    when /name:$/,
         /^#{program_name?}:$/
      @text_buffer.insert(iter, line+N,tags: ['bold','seagreen'])
    # ===================================================================== #
    # === program_name
    # ===================================================================== #
    when /program_name/
      @text_buffer.insert(iter, line+N,tags: ['bold','darkblue'])
    # ===================================================================== #
    # === description
    # ===================================================================== #
    when /description/
      @text_buffer.insert(iter, line+N,tags: ['bold','darkgreen'])
    # ===================================================================== #
    # === required_deps
    # ===================================================================== #
    when /required_deps/
      @text_buffer.insert(iter, line+N,tags: ['bold','slateblue'])
    # ===================================================================== #
    # === true
    # ===================================================================== #
    when /true/, / t$/
      line.gsub!(/ true/,'')
      line.gsub!(/ t$/,'') if line =~ / t$/
      @text_buffer.insert(iter, line)
      @text_buffer.insert(iter, ' yes'+N, tags: ['bold','red'])
    # ===================================================================== #
    # === false
    # ===================================================================== #
    when /false/, / f$/
      line.gsub!(/ false/,'')
      line.gsub!(/ f$/,'') if line =~ / f$/
      @text_buffer.insert(iter, line)
      @text_buffer.insert(iter, ' no'+N, tags: ['bold','red'])
    else
      @text_buffer.insert(iter, line+N)
    end
  }
end
compile_this_program?()
Alias for: program_name?
connect_the_skeleton() click to toggle source
#

connect_the_skeleton (connect tag)

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 559
def connect_the_skeleton
  abort_on_exception

  outer_vbox = create_vbox # A new vbox.

  _ = default_top_bar
  _.title = 'Recipe maker - create a new .yml file, a recipe'
  _.css_class('pad0px')
  # ======================================================================= #
  # === Create the open-file-button
  # ======================================================================= #
  @button_open_file = create_button('Open File')
  @button_open_file.bblack1
  @button_open_file.hint = 'Click on this button in order to '\
                           'select a local .cfdg file to open.'
  @button_open_file.on_clicked {
    do_open_a_local_recipe
  }
  _.pack_start(@button_open_file)
  # ======================================================================= #
  # Add the about-dialog next.
  # ======================================================================= #
  button_about_dialog = button('About')
  button_about_dialog.bblack1
  button_about_dialog.on_clicked {
    create_a_new_about_dialog
  }
  _.pack_end(button_about_dialog)
  outer_vbox.minimal(_)
  hbox_for_the_name_of_the_program = create_hbox
  hbox_for_the_name_of_the_program.minimal(
    text('Input the name of the program:', 2)
  )
  @entry_name_of_the_program = entry('htop')
  @entry_name_of_the_program.default_entry
  @entry_name_of_the_program.pad8px
  @entry_name_of_the_program.on_click_select_everything
  @entry_name_of_the_program.width_height(250, 50)
  @entry_name_of_the_program.center
  # @entry_name_of_the_program.set_completion(
  #   ARRAY_AVAILABLE_PROGRAMS
  # ) if @entry_name_of_the_program.respond_to? :set_completion
  @entry_name_of_the_program.do_focus
  @entry_name_of_the_program.on_enter {
    do_assign_data_from_this_program
  }
  hbox_for_the_name_of_the_program.minimal(@entry_name_of_the_program, 2)
  # === button_assign_data_to_the_buffer
  button_assign_data_to_the_buffer = button('_Assign')
  button_assign_data_to_the_buffer.hint = 'Click this button in '\
    'order to assign to the text view below this widget. Note that '\
    'this will only work if that program is registered in the '\
    'RBT project.'
  button_assign_data_to_the_buffer.bblack1
  button_assign_data_to_the_buffer.on_clicked {
    do_assign_data_from_this_program(@entry_name_of_the_program.text?)
  }
  hbox_for_the_name_of_the_program.minimal(button_assign_data_to_the_buffer, 2)
  hbox_for_the_name_of_the_program.minimal(@button_clear, 2)
  hbox_for_the_name_of_the_program.minimal(@button_traditional, 2)
  hbox_for_the_name_of_the_program.minimal(@button_download, 2)
  hbox_for_the_name_of_the_program.minimal(@button_save, 2)

  outer_vbox.minimal(hbox_for_the_name_of_the_program, 4)
  outer_vbox.minimal(@outermost_vbox, 1)

  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
create_a_new_about_dialog() click to toggle source
#

create_a_new_about_dialog

This creates our about dialog.

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 510
def create_a_new_about_dialog
  @about_dialog = gtk_about_dialog
  @about_dialog.artists = [ AUTHOR_NAME ]
  @about_dialog.authors = [ AUTHOR_NAME ]
  @about_dialog.comments = 'This Script creates recipe information '\
    'which will be stored in sources.yaml'
  @about_dialog.copyright = 'None'
  @about_dialog.documenters = ['']
  @about_dialog.license = 'This program is licenced under the same license '\
    'as Ruby. There is one additional license part - which simply '\
    'encourages you to send bug reports to '\
    'me so that I can improve the program. ;-)'
  @about_dialog.name = 'Ruby::Gtk::ReciperMaker'
  # @about_dialog.translator_credits = "Here you can insert the credits of the translator.\n"
  @about_dialog.version = VERSION_RECIPE_MAKER
  @about_dialog.website = 'https://rubygems.org/gems/rbt'
  @about_dialog.website_label = 'RBT on rubygems.org'
  _ = ENV['IMG'].to_s+'/STD/UHR.png'
  if File.exist? _
    @about_dialog.logo = GdkPixbuf::Pixbuf.new(file: _)
  end
  @about_dialog.popup
end
create_the_buttons() click to toggle source
#

create_the_buttons

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 320
def create_the_buttons
  # ======================================================================= #
  # === The traditional button aka prefix: t
  # ======================================================================= #
  @button_traditional = check_button('_Traditional')
  @button_traditional.hint = 'This button can be used to toggle between '\
    'the /usr/ prefix and the corresponding app-dir prefix.'
  @button_traditional.on_toggled { |widget|
    this_program = compile_this_program?
    hash = return_hash_from_sanitize_cookbook(this_program)
    if widget.active?
      hash[:prefix] = '/usr/'
    else
      hash[:prefix] =
        RBT.determine_appdir_prefix_from_this_input_by_guessing_the_program_version(this_program)
    end
    mass_append(hash)
  }
  # ======================================================================= #
  # === The save-button is created next
  # ======================================================================= #
  @button_save = button('_Save')
  @button_save.hint = 'Click this button in order to save the content '\
    'of the text view component, below this widget. This will save '\
    'within the directory <b>'+RBT.log_directory?+'</b>.'
  @button_save.bblack1
  @button_save.on_clicked {
    location = do_save_the_buffer
    pop_up_this_message_over_that_widget(location, @button_save)
  }
  # ======================================================================= #
  # === The clear-button is created next
  # ======================================================================= #
  @button_clear = button('_Clear')
  @button_clear.hint = 'Click this button in '\
    'order to clear the content of the text view component, '\
    'below this widget.'
  @button_clear.bblack1
  @button_clear.on_clicked {
    @entry_name_of_the_program.clear
    main_text_view?.clear
  }
  # ======================================================================= #
  # === The download button comes next
  #
  # This button can be used to quickly download the program at hand.
  # ======================================================================= #
  @button_download = button('_Download' )
  @button_download.hint = 'Click this button in '\
    'order to download the remote URL associated with the '\
    'given program at hand. This only works for programs '\
    'that are registered within the RBT project, though.'
  @button_download.bblack1
  @button_download.on_clicked {
    download_program(RBT.return_url1_of(handle_which_program?))
  }
end
create_the_skeleton() click to toggle source
#

create_the_skeleton (create tag, skeleton tag)

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 500
def create_the_skeleton
  create_the_buttons
  create_the_text_buffer
end
create_the_text_buffer() click to toggle source
#

create_the_text_buffer

This method will create the textedit stuff.

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 649
def create_the_text_buffer
  @outermost_vbox = create_vbox
  @text_buffer = create_text_buffer
  if use_gtk3?
    require 'gtk_paradise/toplevel_methods/tokenizer_and_text_buffer_tags.rb'
    @text_buffer = ::Gtk::TextBufferTags.create_default_tags(@text_buffer)
  end
  @text_view = create_text_view(@text_buffer)
  # @text_view.it_can_not_be_edited
  @text_view.use_this_font = USE_THIS_MONOSPACED_FONT
  hbox = create_hbox
  _ = return_widget_with_line_numbers {{ n_lines: 40 }}
  _.use_this_font = USE_THIS_MONOSPACED_FONT
  hbox.minimal(_)
  hbox.maximal(@text_view)

  another_scrolled_window = create_scrolled_window(hbox) { :always }
  another_scrolled_window.set_policy(:never, :always)
  another_scrolled_window.bblack3
  another_scrolled_window.width_height(720, 520)
  another_scrolled_window.pad5px
  @outermost_vbox.minimal(another_scrolled_window, 1)
end
do_assign_data_from_this_program( this_program = @entry_name_of_the_program.text? ) click to toggle source
#

do_assign_data_from_this_program

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 256
def do_assign_data_from_this_program(
    this_program = @entry_name_of_the_program.text?
  )
  # ======================================================================= #
  # We have to check whether the program is included in RBT or
  # whether it is not.
  # ======================================================================= #
  if ::RBT.is_this_program_included?(this_program)
    mass_append(return_hash_from_sanitize_cookbook(this_program))
  else
    e "The program `#{this_program}` is not included."
  end
end
Also aliased as: update_the_main_buffer
do_open_a_local_recipe() click to toggle source
#

do_open_a_local_recipe (open tag)

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 537
def do_open_a_local_recipe
  create_a_new_file_chooser_dialog(self) {{
    start_dir:              ::RBT.project_base_directory?+'yaml/cookbooks/',
    additional_directories: ::RBT.project_base_directory?+'yaml/cookbooks/'
  }}
  _ = ::Gtk.main_file?
  if _ and File.exist?(_)
    @entry_name_of_the_program.set_text(File.basename(_).delete_suffix('.yml'))
    do_assign_data_from_this_program
  end
end
do_process_the_commandline_arguments() click to toggle source
#

do_process_the_commandline_arguments

For now the first argument given is assumed to be a program.

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 420
def do_process_the_commandline_arguments
  _ = commandline_arguments?
  if _ and !_.empty?
    set_handle_this_program(_.first)
  end
end
do_save_the_buffer( what = main_buffer?.text.to_s ) click to toggle source
#

do_save_the_buffer (save tag)

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 243
def do_save_the_buffer(
    what = main_buffer?.text.to_s
  )
  into = RBT.log_directory?+
         main_entry?.text.to_s+'.yml'
  e "Saving into `#{into}`."
  RBT.write_what_into(what, into)
  return into
end
download_program( url = RBT.return_url1_of(handle_which_program?) ) click to toggle source
#

download_program

This will download a program by using our Download module.

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 391
def download_program(
    url = RBT.return_url1_of(handle_which_program?)
  )
  e "Downloading #{url} next, into the directory at #{sfancy(Dir.pwd)}:"
  Cliner.cliner {
    Wget.download(url)
  }
end
favicon?() click to toggle source
#

favicon?

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 197
def favicon?
  :tabble
end
handle_CSS_rules() click to toggle source
#

handle_CSS_rules (CSS tag)

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 211
def handle_CSS_rules
  use_gtk_paradise_project_css_file
  append_project_css_file
  more_CSS_then_apply_it(USE_THESE_CSS_RULES)
end
handle_which_program?()
Alias for: program_name?
main_buffer?() click to toggle source
#

main_buffer?

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 430
def main_buffer?
  @text_buffer
end
main_entry?() click to toggle source
#

main_entry?

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 273
def main_entry?
  @entry_name_of_the_program
end
main_text_view?() click to toggle source
#

main_text_view?

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 493
def main_text_view?
  @text_view
end
mass_append(hash) click to toggle source
#

mass_append

The first argument to this method must be a Hash that contains all relevant data.

Whenever this method is used, the old text-buffer is cleared.

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 681
def mass_append(hash)
  @text_buffer.clear # Clear the old content first.
  append(hash[:short_name].to_s+':') # This entry is mandatory.
  append(' # blfs:')
  append(' # -')
  unless hash[:binaries].empty?
    append(' binaries:')
    append(' - ')
  end
  append(
    ' # program_name_and_program_version: '+hash[:program_name_and_program_version]
  )
  append(' configure_options: |')
  append('  enable-shared')
  if hash.has_key? :short_description
    append(' short_description: |')
    append('  '+hash[:short_description].to_s)
  end
  append(' description: |')
  append(
    '  '+RBT.word_wrap(hash[:description], 60)
  )
  append(' extra_information: |')
  append('  '+hash[:extra_information].to_s)
  append(' licence: '+hash[:licence].to_s)
  append(' url1: '+hash[:url1].to_s)
  append(' url1: '+hash[:url2].to_s)
  append(' homepage: '+hash[:homepage].to_s)
  append(' git_url: '+hash[:git_url].to_s) if hash[:git_url]
  append(' prefix: '+hash[:prefix].to_s)
  append(' use_autogen: '+hash[:use_autogen].to_s)
  append(' keep_extracted: '+hash[:keep_extracted].to_s)
  append(' use_build_directory: '+hash[:use_build_directory].to_s)
  if hash[:tags] and hash[:tags].is_a? Array
    append(' tags:')
    hash[:tags].each {|inner_entry|
      append('  - '+inner_entry.to_s)
    }
  end
  append(' required_deps_on:')
  hash[:required_deps_on].each {|this_dependency|
    append('  - '+this_dependency)
  }
  append(' last_update: '+hash[:last_update].to_s)
  colourize_the_buffer
end
padding?() click to toggle source
#

padding?

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 229
def padding?
  0
end
program_name?() click to toggle source
#

program_name?

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 381
def program_name?
  @entry_name_of_the_program.text?
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::LeanPrototype#reset
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 174
def reset
  super() if respond_to?(:super)
  reset_the_shared_module # This can come early.
  reset_the_base_module
  reset_the_internal_variables
  infer_the_namespace
  # ======================================================================= #
  # === @configuration
  # ======================================================================= #
  @configuration = [true, __dir__, namespace?]
  # ======================================================================= #
  # === Set the title, width, height and the font in use.
  # ======================================================================= #
  title_width_height_font(TITLE, WIDTH, HEIGHT, USE_THIS_FONT)
  if use_gtk3?
    handle_CSS_rules
  end
  infer_the_size_automatically
end
reset_the_shared_module() click to toggle source
#

reset_the_shared_module

This method can be used for ruby-gtk3 and ruby-libui, among other toolkits.

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 223
def reset_the_shared_module
end
return_hash_from_sanitize_cookbook( for_this_program = @entry_name_of_the_program.text? ) click to toggle source
#

return_hash_from_sanitize_cookbook

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 288
def return_hash_from_sanitize_cookbook(
    for_this_program = @entry_name_of_the_program.text?
  )
  _ = RBT::Cookbooks::SanitizeCookbook.new(for_this_program)
  binaries = _.binaries?
  hash = {
    short_name: _.short_name?,
    binaries: binaries,
    program_name_and_program_version: _.program_name_and_program_version?,
    short_description: _.short_description?,
    description: _.description?,
    extra_information: _.extra_information?,
    licence: _.licence?,
    url1: _.url1?,
    url2: _.url2?,
    homepage: _.homepage?,
    git_url: _.git_url?,
    prefix: _.prefix?,
    use_autogen: _.use_autogen?,
    keep_extracted: _.keep_extracted?,
    use_build_directory: _.use_build_directory?,
    tags: _.tags?,
    required_deps_on: _.required_deps_on?,
    last_update: _.last_update?
  }
  return hash
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 552
def run
  run_super
end
Also aliased as: start_gui_application
set_handle_this_program(i) click to toggle source
#

set_handle_this_program

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 280
def set_handle_this_program(i)
  @entry_name_of_the_program.set_text(i)
  update_the_main_buffer
end
smaller_font?() click to toggle source
#

smaller_font?

#
# File lib/rbt/gui/universal_widgets/recipe_maker/recipe_maker.rb, line 204
def smaller_font?
  SMALLER_FONT
end
start_gui_application()
Alias for: run
update_the_main_buffer( this_program = @entry_name_of_the_program.text? )