Class: RBT::GUI::LibUI::CompileViaSQLDatabase

Inherits:
LibuiParadise::Base
  • Object
show all
Defined in:
lib/rbt/gui/libui/compile_via_sql_database/compile_via_sql_database.rb

Overview

RBT::GUI::LibUI::CompileViaSQLDatabase

Constant Summary collapse

TITLE =
#

TITLE

#
'Compile via SQL Database'
WIDTH =
#

WIDTH

#
1280
HEIGHT =
#

HEIGHT

#
880

Instance Method Summary collapse

Constructor Details

#initialize(run_already = true) ⇒ CompileViaSQLDatabase

#

initialize

#


38
39
40
41
42
43
# File 'lib/rbt/gui/libui/compile_via_sql_database/compile_via_sql_database.rb', line 38

def initialize(
    run_already = true
  )
  reset
  run if run_already
end

Instance Method Details

#compile_object?Boolean

#

compile_object?

#

Returns:

  • (Boolean)


158
159
160
# File 'lib/rbt/gui/libui/compile_via_sql_database/compile_via_sql_database.rb', line 158

def compile_object?
  @compile_object
end

#compile_which_program?Boolean

#

compile_which_program?

#

Returns:

  • (Boolean)


165
166
167
# File 'lib/rbt/gui/libui/compile_via_sql_database/compile_via_sql_database.rb', line 165

def compile_which_program?
  @entry_compile_this_program.text?
end

#create_a_new_compile_objectObject

#

create_a_new_compile_object

#


135
136
137
138
139
140
141
142
# File 'lib/rbt/gui/libui/compile_via_sql_database/compile_via_sql_database.rb', line 135

def create_a_new_compile_object
  # ======================================================================= #
  # === @compile_object
  #
  # Create a new compile-object. We will re-use it lateron.
  # ======================================================================= #
  @compile_object = RBT::CompileViaSQLDatabase.new(nil, :do_not_run_yet)
end

#create_skeletonObject

#

create_skeleton (create tag, skeleton tag)

#


56
57
58
59
60
61
62
63
64
65
# File 'lib/rbt/gui/libui/compile_via_sql_database/compile_via_sql_database.rb', line 56

def create_skeleton
  # ======================================================================= #
  # === @window
  # ======================================================================= #
  @window = padded_main_window(title?, width?, height?, 0)
  create_the_labels
  create_the_entries
  create_the_buttons
  create_the_grid
end

#create_the_buttonsObject

#

create_the_buttons (buttons tag)

#


80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/rbt/gui/libui/compile_via_sql_database/compile_via_sql_database.rb', line 80

def create_the_buttons
  # ======================================================================= #
  # === @button_do_compile_the_program
  # ======================================================================= #
  @button_do_compile_the_program = button(
    'Compile the program'
  )
  @button_do_compile_the_program.on_clicked {
    ensure_that_the_prefix_is_not_a_symbol
    ensure_that_the_prefix_entry_has_a_trailing_forward_slash
    do_compile_this_program
  }
end

#create_the_entriesObject

#

create_the_entries (entries tag, entry tag)

#


108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/rbt/gui/libui/compile_via_sql_database/compile_via_sql_database.rb', line 108

def create_the_entries
  # ======================================================================= #
  # === @entry_target_prefix
  # ======================================================================= #
  @entry_target_prefix = entry('/usr/')
  # ======================================================================= #
  # === @entry_compile_this_program
  # ======================================================================= #
  @entry_compile_this_program = entry
  @entry_compile_this_program.on_changed {|something|
    proc { |pointer|
      evaluate_the_current_input(@entry_compile_this_program, pointer)
    }
  }
  @entry_location_of_the_database = entry
end

#create_the_gridObject

#

create_the_grid

#


70
71
72
73
74
75
# File 'lib/rbt/gui/libui/compile_via_sql_database/compile_via_sql_database.rb', line 70

def create_the_grid
  # ======================================================================= #
  # === @grid
  # ======================================================================= #
  @grid = padded_grid
end

#create_the_labelsObject

#

create_the_labels (labels tag, label tag)

#


262
263
264
265
266
267
# File 'lib/rbt/gui/libui/compile_via_sql_database/compile_via_sql_database.rb', line 262

def create_the_labels
  # ======================================================================= #
  # === @label_file_size_of_the_source_archive
  # ======================================================================= #
  @label_file_size_of_the_source_archive = text('File size of the source archive: ')
end

#determine_the_location_of_the_compile_databaseObject

#

determine_the_location_of_the_compile_database

#


147
148
149
150
151
152
153
# File 'lib/rbt/gui/libui/compile_via_sql_database/compile_via_sql_database.rb', line 147

def determine_the_location_of_the_compile_database
  target = @compile_object.database_location?.to_s
  unless File.directory? File.dirname(target)
    mkdir(File.dirname(target))
  end
  @entry_location_of_the_database.set_text(target)
end

#do_compile_this_program(text = compile_which_program? ) ⇒ Object

#

do_compile_this_program (compile tag)

#


172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/rbt/gui/libui/compile_via_sql_database/compile_via_sql_database.rb', line 172

def do_compile_this_program(
    text = compile_which_program?
  )
  text = text.dup
  if text and text.include?('-')
    text.delete!('-')
  end
  require 'rbt/compile_via_sql_database/compile_via_sql_database.rb'
  @compile_object.set_compile_this_program(text)
  @compile_object.set_prefix(prefix?)
  if @compile_object.is_this_program_included? text
    Thread.new {
      _ = @compile_object.assumed_local_file_path_for?(text)
      if File.exist? _
        @label_file_size_of_the_source_archive.set_text(
          'File size of the source archive: '+
          (File.size(_) / 1000).round(2).to_s+' kb'
        )
      end
      @compile_object.do_the_actual_compilation
      message_box(
        text: "Finished compiling `#{text}` into the "\
              "prefix #{prefix?}"\
              "!\n\n Hopefully everything worked ok-ish."
      )
    }
  else
    message_box(
        text: 'The program `'+text+'` is NOT included. '\
              'Make sure the program is registered in '\
              'the RBT project.'
      )
  end
end

#do_compile_via_this_program(i) ⇒ Object

#

do_compile_via_this_program

#


217
218
219
220
221
222
# File 'lib/rbt/gui/libui/compile_via_sql_database/compile_via_sql_database.rb', line 217

def do_compile_via_this_program(i)
  ensure_that_the_prefix_is_not_a_symbol
  ensure_that_the_prefix_entry_has_a_trailing_forward_slash
  set_compile_this_program(i)
  do_compile_this_program
end

#ensure_that_the_prefix_entry_has_a_trailing_forward_slashObject

#

ensure_that_the_prefix_entry_has_a_trailing_forward_slash

#


227
228
229
230
231
232
# File 'lib/rbt/gui/libui/compile_via_sql_database/compile_via_sql_database.rb', line 227

def ensure_that_the_prefix_entry_has_a_trailing_forward_slash
  _ = prefix?
  unless _.end_with? '/'
    @entry_target_prefix.set_text("#{_}/")
  end
end

#ensure_that_the_prefix_is_not_a_symbolObject

#

ensure_that_the_prefix_is_not_a_symbol

#


237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/rbt/gui/libui/compile_via_sql_database/compile_via_sql_database.rb', line 237

def ensure_that_the_prefix_is_not_a_symbol
  _ = @entry_target_prefix.text?
  if _.start_with? ':'
    _ = _.delete(':')
    case _
    when 'appdir'
      try_to_compile_this_program = compile_which_program?
      # =================================================================== #
      # We must use SQL here to determine the assumed version.
      # But first we will specify a default.
      # =================================================================== #
      assumed_version = '1.0.0'
      assumed_version = @compile_object.assumed_version_of_this_program?(try_to_compile_this_program)
      use_this_prefix = RBT.return_appdir_prefix(
        try_to_compile_this_program+'-'+
        assumed_version
      )
      @entry_target_prefix.set_text(use_this_prefix)
    end
  end
end

#evaluate_the_current_input(entry, pointer) ⇒ Object

#

evaluate_the_current_input

#


97
98
99
100
101
102
103
# File 'lib/rbt/gui/libui/compile_via_sql_database/compile_via_sql_database.rb', line 97

def evaluate_the_current_input(entry, pointer)
  text = entry.text?
  if text and text.end_with?('#')
    entry.set_text( without_trailing_comment(text) )
    do_compile_via_this_program(entry.text?)
  end
end

#prefix?Boolean

#

prefix?

#

Returns:

  • (Boolean)


210
211
212
# File 'lib/rbt/gui/libui/compile_via_sql_database/compile_via_sql_database.rb', line 210

def prefix?
  @entry_target_prefix.text?.to_s
end

#resetObject

#

reset (reset tag)

#


48
49
50
51
# File 'lib/rbt/gui/libui/compile_via_sql_database/compile_via_sql_database.rb', line 48

def reset
  reset_the_internal_hash
  title_width_height(TITLE, WIDTH, HEIGHT)
end

#runObject

#

run (run tag)

#


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
# File 'lib/rbt/gui/libui/compile_via_sql_database/compile_via_sql_database.rb', line 272

def run
  create_skeleton_then_connect_skeleton
  create_a_new_compile_object

  determine_the_location_of_the_compile_database
  outer_vbox = padded_vbox
  outer_vbox.add_hsep

  
  #                         widget, left, top, xspan, yspan, hexpand, halign, vexpand, valign
  @grid.left( text('Compile this program → ') )
  @grid.right( @entry_compile_this_program )
  @grid.right( @button_do_compile_the_program )
  @grid.new_row
  @grid.left(text('The SQL database is kept at the following location:'), :default, :default, 3)
  @grid.new_row
  @grid.left(@entry_location_of_the_database, :default, :default, 3)
  @grid.new_row
  @grid.left( text('Use this target prefix → ') )
  @grid.right(@entry_target_prefix, :default, :default, 2)
  @grid.new_row
  @grid.left(
    @label_file_size_of_the_source_archive
  )
  @grid.new_row
  @grid.left(
    text('n registered programs are available in the SQL database → ')
  )
  n_programs_available = compile_object?.n_programs_available?
  @grid.right( text(n_programs_available.to_s))
  outer_vbox.minimal(@grid)
  outer_vbox.add_hsep
  outer_vbox.minimal(quit_button)
  outer_vbox.add_hsep

  @window.add(outer_vbox)
  @window.intelligent_exit
end

#set_compile_this_program(i) ⇒ Object

#

set_compile_this_program

#


128
129
130
# File 'lib/rbt/gui/libui/compile_via_sql_database/compile_via_sql_database.rb', line 128

def set_compile_this_program(i)
  @entry_compile_this_program.set_text(i.to_s)
end