Module: LibuiParadise::BaseModule

Overview

LibuiParadise::BaseModule

Constant Summary collapse

WIDTH =
#

WIDTH

Define a default value for the WIDTH constant.

#
1024
HEIGHT =
#

HEIGHT

#
680

Instance Method Summary collapse

Instance Method Details

#abort_on_exceptionObject

#

abort_on_exception

#


1096
1097
1098
# File 'lib/libui_paradise/base_module/base_module.rb', line 1096

def abort_on_exception
  Thread.abort_on_exception
end

#append_this_array_to_that_combobox(this_array, that_combobox) ⇒ Object

#

append_this_array_to_that_combobox

#


984
985
986
987
988
989
990
991
# File 'lib/libui_paradise/base_module/base_module.rb', line 984

def append_this_array_to_that_combobox(
    this_array,
    that_combobox
  )
  this_array.each {|this_entry|
    ::LibUI.combobox_append(that_combobox, this_entry)
  }
end

#area(i = :use_new_area_handler) ⇒ Object Also known as: area_handler

#

area

AreaHandler defines the functionality needed for handling events from an Area.

Upstream documentation, at the least for Go, can be found here:

https://github.com/andlabs/ui/blob/master/areahandler.go
#


255
256
257
258
259
# File 'lib/libui_paradise/base_module/base_module.rb', line 255

def area(
    i = :use_new_area_handler
  )
  return ::LibuiParadise.area(i)
end

#assumed_height?Boolean Also known as: assumed_max_height?

#

assumed_height?

#

Returns:

  • (Boolean)


1267
1268
1269
# File 'lib/libui_paradise/base_module/base_module.rb', line 1267

def assumed_height?
  return_the_resolution_using_xrandr.split('x').last.to_i
end

#assumed_width?Boolean Also known as: assumed_max_width?

#

assumed_width?

#

Returns:

  • (Boolean)


1285
1286
1287
# File 'lib/libui_paradise/base_module/base_module.rb', line 1285

def assumed_width?
  return_the_resolution_using_xrandr.split('x').first.to_i
end

#bold_button(i) ⇒ Object

#

bold_button

This currently does not work. We have to wait until upstream libui supports bold font text.

#


600
601
602
# File 'lib/libui_paradise/base_module/base_module.rb', line 600

def bold_button(i)
  button(i)
end

#bold_label(i = '') ⇒ Object Also known as: bold_text

#

bold_label

This currently does NOT make the text bold - the method exists solely as a placeholder, until upstream libui supports bold text as such.

Actually libui already supports this; I just don’t know how to use it.

#


826
827
828
# File 'lib/libui_paradise/base_module/base_module.rb', line 826

def bold_label(i = '')
  return label(i)
end

#bold_text_left_aligned(i = '') ⇒ Object Also known as: left_aligned_bold_label

#

bold_text_left_aligned

#


783
784
785
# File 'lib/libui_paradise/base_module/base_module.rb', line 783

def bold_text_left_aligned(i = '')
  return label(i)
end

#button(text = '', &block) ⇒ Object Also known as: ui_button, create_button

#

button (button tag)

This method will create a libui-button. Note that the alias create_button() is an important alias to this method.

#


118
119
120
121
122
123
# File 'lib/libui_paradise/base_module/base_module.rb', line 118

def button(
    text = '',
    &block
  )
  return ::LibuiParadise.button(text, &block)
end

#chdir(i) ⇒ Object Also known as: cd

#

chdir (cd tag, chdir tag)

#


1103
1104
1105
1106
1107
# File 'lib/libui_paradise/base_module/base_module.rb', line 1103

def chdir(i)
  if i and File.directory?(i)
    Dir.chdir(i)
  end
end

#checkbox(i = '') ⇒ Object Also known as: ui_checkbox, ui_check_button

#

checkbox

Delegate towards LibuiParadise.checkbox().

#


514
515
516
# File 'lib/libui_paradise/base_module/base_module.rb', line 514

def checkbox(i = '')
  ::LibuiParadise.checkbox(i)
end

#checked_checkbox(i = '') ⇒ Object

#

checked_checkbox

#


522
523
524
525
526
# File 'lib/libui_paradise/base_module/base_module.rb', line 522

def checked_checkbox(i = '')
  _ = checkbox(i)
  _.is_active
  return _
end

#close_properly(main_window = LibuiParadise.main_window?) ⇒ Object Also known as: simple_exit

#

close_properly

#


1412
1413
1414
1415
1416
1417
1418
# File 'lib/libui_paradise/base_module/base_module.rb', line 1412

def close_properly(
    main_window = LibuiParadise.main_window?
  )
  LibUI.window_on_closing(main_window) {
    LibUI.exit_from(main_window)
  }
end

#colour_buttonObject Also known as: color_button, ui_colour_button

#

colour_button

#


239
240
241
# File 'lib/libui_paradise/base_module/base_module.rb', line 239

def colour_button
  ::LibuiParadise.new_colour_button
end

#colour_to_rgb(colour = :steelblue) ⇒ Object

#

colour_to_rgb

#


1336
1337
1338
1339
1340
1341
# File 'lib/libui_paradise/base_module/base_module.rb', line 1336

def colour_to_rgb(
    colour = :steelblue
  )
  array = Colours.colour_to_rgb(colour)
  return array
end

#combobox(optional_array = nil, &block) ⇒ Object Also known as: ui_combo_box, ui_combobox, libui_combo_box, combo_box_entry, combo_box, create_combo_box

#

combobox

The first argument can be an Array.

#


658
659
660
661
662
663
# File 'lib/libui_paradise/base_module/base_module.rb', line 658

def combobox(
    optional_array = nil,
    &block
  )
  return ::LibuiParadise.combobox(optional_array, &block)
end

#commandline_arguments?Boolean

#

commandline_arguments?

#

Returns:

  • (Boolean)


1211
1212
1213
# File 'lib/libui_paradise/base_module/base_module.rb', line 1211

def commandline_arguments?
  @commandline_arguments
end

#connect_skeletonObject

#

connect_skeleton

This is a stub method, because we want to allow the user to modify it.

#


1122
1123
# File 'lib/libui_paradise/base_module/base_module.rb', line 1122

def connect_skeleton
end

#copy(from, to) ⇒ Object

#

copy

#


913
914
915
916
# File 'lib/libui_paradise/base_module/base_module.rb', line 913

def copy(from, to)
  require 'fileutils'
  FileUtils.cp(from, to)
end

#copy_file(from, to) ⇒ Object Also known as: cp_file

#

copy_file

#


1260
1261
1262
# File 'lib/libui_paradise/base_module/base_module.rb', line 1260

def copy_file(from, to)
  FileUtils.cp(from, to)
end

#create_directory(i) ⇒ Object Also known as: mkdir

#

create_directory

#


1089
1090
1091
# File 'lib/libui_paradise/base_module/base_module.rb', line 1089

def create_directory(i)
  FileUtils.mkdir_p(i)
end

#create_gridObject Also known as: grid, ui_grid, create_default_grid

#

create_grid

#


88
89
90
# File 'lib/libui_paradise/base_module/base_module.rb', line 88

def create_grid
  ::LibuiParadise.create_grid
end

#create_skeleton_then_connect_skeletonObject

#

create_skeleton_then_connect_skeleton

#


1112
1113
1114
1115
# File 'lib/libui_paradise/base_module/base_module.rb', line 1112

def create_skeleton_then_connect_skeleton
  create_skeleton
  connect_skeleton
end

#create_table(model) ⇒ Object

#

create_table

#


422
423
424
# File 'lib/libui_paradise/base_module/base_module.rb', line 422

def create_table(model)
  ::LibuiParadise.table(model)
end

#create_the_skeletonObject Also known as: create_skeleton

#

create_the_skeleton

#


1192
1193
# File 'lib/libui_paradise/base_module/base_module.rb', line 1192

def create_the_skeleton
end

#current_widget_pointer_type?Boolean

#

current_widget_pointer_type?

#

Returns:

  • (Boolean)


1071
1072
1073
# File 'lib/libui_paradise/base_module/base_module.rb', line 1071

def current_widget_pointer_type?
  LibuiParadise.hash_fiddle_pointer_widgets?.values.last.last
end

#delete_file(i) ⇒ Object

#

delete_file

This method can be used if you want to quickly delete a (local) file.

#


1325
1326
1327
1328
1329
1330
1331
# File 'lib/libui_paradise/base_module/base_module.rb', line 1325

def delete_file(i)
  if i and File.file?(i)
    File.delete(i)
  else
    e "Not a file: #{i}"
  end
end

#do_quitObject

#

do_quit

#


906
907
908
# File 'lib/libui_paradise/base_module/base_module.rb', line 906

def do_quit
  ::LibUI.quit
end

#editable_combobox(optional_array = nil, &block) ⇒ Object Also known as: editable_combo_box, ui_editable_combo_box

#

editable_combobox

#


264
265
266
267
268
# File 'lib/libui_paradise/base_module/base_module.rb', line 264

def editable_combobox(
    optional_array = nil, &block
  )
  return ::LibuiParadise.editable_combobox(optional_array, &block)
end

#entry(optional_text = '') ⇒ Object Also known as: ui_entry, hcentered_entry, create_entry

#

entry (entry tag)

This method is tapping into LibUI.new_entry.

An alias exists to this method, called hcentered_entry. This currently does not work for libui, and is thus only added for compatibility reasons.

Usage example:

entry1 = ui_entry('ATG')
#


401
402
403
404
405
# File 'lib/libui_paradise/base_module/base_module.rb', line 401

def entry(
    optional_text = ''
  )
  ::LibuiParadise.entry(optional_text)
end

#error_msg(text) ⇒ Object

#

error_msg

#


538
539
540
# File 'lib/libui_paradise/base_module/base_module.rb', line 538

def error_msg(text)
  message_box_error(:default, text)
end

#esystem(i) ⇒ Object

#

esystem

This method can be used to run system(), with output. Thread.new is used because that seems to work better in a GUI setup.

#


1081
1082
1083
1084
# File 'lib/libui_paradise/base_module/base_module.rb', line 1081

def esystem(i)
  e i
  Thread.new { system i }
end

#exit_from(main_window = main_window? ) ⇒ Object

#

exit_from

This method essentially combines UI.control_destroy() and UI.quit( into one method.

#


924
925
926
927
928
929
930
# File 'lib/libui_paradise/base_module/base_module.rb', line 924

def exit_from(
    main_window = main_window?
  )
  LibUI.control_destroy(main_window)
  LibUI.quit
  0
end

#fancy_text(i = '') ⇒ Object Also known as: attributed_string

#

fancy_text

This text variant can be styled.

#


811
812
813
814
815
# File 'lib/libui_paradise/base_module/base_module.rb', line 811

def fancy_text(i = '')
  _ = LibUI.new_attributed_string(i.to_s)
  add_to_the_registered_widgets(_, __method__)
  return _
end

#font(&block) ⇒ Object Also known as: ui_font

#

font

Wrapper-method towards LibuiParadise.font().

#


682
683
684
# File 'lib/libui_paradise/base_module/base_module.rb', line 682

def font(&block)
  ::LibuiParadise.font(&block)
end

#font_buttonObject Also known as: ui_font_button

#

font_button

Create a new font button via this method.

#


1158
1159
1160
# File 'lib/libui_paradise/base_module/base_module.rb', line 1158

def font_button
  return ::LibuiParadise.font_button
end

#free_table_model(model) ⇒ Object

#

free_table_model

#


214
215
216
# File 'lib/libui_paradise/base_module/base_module.rb', line 214

def free_table_model(model)
  ::LibUI.free_table_model(model)
end

#gtk3?Boolean Also known as: is_on_gtk?, uses_gtk3?

#

gtk3?

#

Returns:

  • (Boolean)


976
977
978
# File 'lib/libui_paradise/base_module/base_module.rb', line 976

def gtk3?
  false
end

#hbox(*optional_widgets) ⇒ Object Also known as: ui_hbox, horizontal_box, create_hbox, libui_hbox

#

hbox (hbox tag)

#


143
144
145
# File 'lib/libui_paradise/base_module/base_module.rb', line 143

def hbox(*optional_widgets)
  ::LibuiParadise.hbox(optional_widgets)
end

#height?Boolean

#

height?

#

Returns:

  • (Boolean)


574
575
576
# File 'lib/libui_paradise/base_module/base_module.rb', line 574

def height?
  @internal_hash[:height]
end

#horizontal_separatorObject Also known as: ui_hseparator, ui_hsep, hspacer, horizontal_spacer, hsep, libui_hsep

#

horizontal_separator

#


327
328
329
# File 'lib/libui_paradise/base_module/base_module.rb', line 327

def horizontal_separator
  ::LibuiParadise.new_horizontal_separator
end

#image(this_file, width = :try_to_infer_automatically, height = :infer_automatically) ⇒ Object Also known as: ui_image

#

image (image tag)

This is currently limited to .png files only, due to ChunkyPNG.

At some later point in the future this limitation may be lifted. For now it has to remain in place.

#


1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
# File 'lib/libui_paradise/base_module/base_module.rb', line 1170

def image(
    this_file,
    width  = :try_to_infer_automatically,
    height = :infer_automatically
  )
  Libuiparadise.image(
    this_file,
    width,
    height
  )
end

#is_on_roebe?Boolean

#

is_on_roebe?

This is only useful on my home system.

#

Returns:

  • (Boolean)


583
584
585
# File 'lib/libui_paradise/base_module/base_module.rb', line 583

def is_on_roebe?
  ENV['IS_ROEBE'].to_s == '1'
end

#is_on_windows?Boolean

#

is_on_windows?

#

Returns:

  • (Boolean)


790
791
792
# File 'lib/libui_paradise/base_module/base_module.rb', line 790

def is_on_windows?
  Gem.win_platform?
end

#label(i = '') ⇒ Object Also known as: text, ui_text, ui_label, left_aligned_label, left_aligned_text

#

label

The last two aliases, left_aligned_label, should be different, but right now I don’t know how to do this in libui.

#


876
877
878
879
880
# File 'lib/libui_paradise/base_module/base_module.rb', line 876

def label(
    i = ''
  )
  ::LibuiParadise.label(i)
end

#last_pointer?Boolean Also known as: current_pointer?, current_widget_pointer?

#

last_pointer?

This used to return the “current” widget pointer, but past September 2021 this is rarely in use anymore. Use current_widget_pointer? instead, based on the main Hash that keeps all widgets registered.

#

Returns:

  • (Boolean)


1350
1351
1352
# File 'lib/libui_paradise/base_module/base_module.rb', line 1350

def last_pointer?
  LibuiParadise.current_widget_pointer?
end

#left_arrow?Boolean

#

left_arrow?

This is simply a unicode left arrow, a text (label) widget.

#

Returns:

  • (Boolean)


891
892
893
# File 'lib/libui_paradise/base_module/base_module.rb', line 891

def left_arrow?
  text('')
end

#main_hash?Boolean Also known as: toplevel_hash?

#

main_hash?

Access the main hash defined above.

#

Returns:

  • (Boolean)


1385
1386
1387
# File 'lib/libui_paradise/base_module/base_module.rb', line 1385

def main_hash?
  ::LibuiParadise.hash_fiddle_pointer_widgets?
end

#main_then_quitObject

#

main_then_quit

#


898
899
900
901
# File 'lib/libui_paradise/base_module/base_module.rb', line 898

def main_then_quit
  ::LibUI.main
  do_quit
end
#

menu (menu tag)

#


690
691
692
693
694
# File 'lib/libui_paradise/base_module/base_module.rb', line 690

def menu(
    title = ''
  )
  return ::LibuiParadise.menu(title)
end

#message_box_error(main_window = main_window?, , title_to_use = '', whatever = '') ⇒ Object Also known as: ui_msg_box_error, ui_error_message, ui_error_msg, error_message_to_the_user

#

message_box_error

#


1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
# File 'lib/libui_paradise/base_module/base_module.rb', line 1218

def message_box_error(
    main_window  = main_window?,
    title_to_use = '',
    whatever     = ''
  )
  return ::LibuiParadise.message_box_error(
    main_window,
    title_to_use,
    whatever
  )
end

#multiline_entry(optional_content = nil) ⇒ Object Also known as: ui_multiline_entry, textview, text_view, ui_text_view, ui_textview, ui_text_buffer, input_field, input

#

multiline_entry

Wrapper-method towards LibuiParadise.multiline_entry().

#


223
224
225
226
227
# File 'lib/libui_paradise/base_module/base_module.rb', line 223

def multiline_entry(
    optional_content = nil
  )
  ::LibuiParadise.multiline_entry(optional_content)
end

#new_brushObject

#

new_brush

#


996
997
998
# File 'lib/libui_paradise/base_module/base_module.rb', line 996

def new_brush
  ::LibUI::FFI::DrawBrush.malloc
end

#non_wrapping_multiline_entryObject

#

non_wrapping_multiline_entry

Delegate towards LibuiParadise.non_wrapping_multiline_entry() here.

#


701
702
703
# File 'lib/libui_paradise/base_module/base_module.rb', line 701

def non_wrapping_multiline_entry
  return ::LibuiParadise.non_wrapping_multiline_entry
end

#parse_this_file_into_a_table(this_file) ⇒ Object Also known as: parse_into_table

#

parse_this_file_into_a_table

Note that Gtk::Table has been deprecated. Use GtkGrid instead. It provides the same capabilities as GtkTable for arranging widgets in a rectangular grid, but does support height-for-width geometry management.

Usage example:

parse_into_table '/Depot/j/animals.yml'
#


843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
# File 'lib/libui_paradise/base_module/base_module.rb', line 843

def parse_this_file_into_a_table(this_file)
  if this_file and File.exist?(this_file)
    table = create_grid
    table.uniform_spacing(8)
    table.pad8px
    if this_file.end_with?('.yml')
      dataset = YAML.load_file(this_file)
    else
      dataset = File.readlines(this_file)
    end
    if dataset.is_a? Hash
      dataset = dataset.to_a.flatten
    end
    dataset.flatten! if dataset.respond_to?(:flatten!)
    dataset.each_with_index {|entry, index|
      entry = entry.to_s
      case index % 2
      when 0
        table.left(text(entry))
      when 1
        table.right(text(entry))
      end
    }
    return table
  end
end

#password_entryObject Also known as: ui_password_entry

#

password_entry

Usage example:

entry = ui_password_entry
#


196
197
198
# File 'lib/libui_paradise/base_module/base_module.rb', line 196

def password_entry
  ::LibuiParadise.password_entry
end

#quit_button(optional_arguments = {}) ⇒ Object Also known as: ui_quit_button

#

quit_button (quit tag)

This method can be used to, by default, implement a quit button that, upon a click-event, will cause the application to exit and close/quit.

#


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
# File 'lib/libui_paradise/base_module/base_module.rb', line 611

def quit_button(
    optional_arguments = {}
  )
  use_this_text = 'Quit'
  if optional_arguments and optional_arguments.is_a?(Hash)
    # ===================================================================== #
    # === :text
    # ===================================================================== #
    if optional_arguments.has_key? :text
      use_this_text = optional_arguments.delete(:text)
    end
  end
  if block_given?
    yielded = yield
    case yielded
    # ===================================================================== #
    # === :with_emoji
    # ===================================================================== #
    when :with_emoji,
         :with_icon
      use_this_text = use_this_text.to_s.dup
      use_this_text << ' 🛑'
    end
  end
  quit_button = button(use_this_text)
  quit_button.on_clicked {
    ::LibUI.quit
    0
  }
  return quit_button
end

#radio_buttons(optional_array = []) ⇒ Object Also known as: ui_radio_buttons

#

radio_buttons

#


590
591
592
# File 'lib/libui_paradise/base_module/base_module.rb', line 590

def radio_buttons(optional_array = [])
  return ::LibuiParadise.radio_buttons(optional_array)
end

#register_this_fiddle_pointer_widget(the_fiddle_pointer_widget, the_type_of_the_widget = nil) ⇒ Object Also known as: add_to_the_registered_widgets

#

register_this_fiddle_pointer_widget

This method will simply delegate towards:

LibuiParadise.register_this_fiddle_pointer_widget()
#


102
103
104
105
106
107
108
109
110
# File 'lib/libui_paradise/base_module/base_module.rb', line 102

def register_this_fiddle_pointer_widget(
    the_fiddle_pointer_widget,
    the_type_of_the_widget = nil
  )
  ::LibuiParadise.register_this_fiddle_pointer_widget(
    the_fiddle_pointer_widget,
    the_type_of_the_widget
  )
end

#resetObject

#

reset

#


74
75
76
# File 'lib/libui_paradise/base_module/base_module.rb', line 74

def reset
  reset_the_internal_hash
end

#reset_the_internal_hashObject

#

reset_the_internal_hash

#


81
82
83
# File 'lib/libui_paradise/base_module/base_module.rb', line 81

def reset_the_internal_hash
  @internal_hash = {}
end

#return_button_for_opening_a_local_file(connect_this_button_with_that_widget = nil) ⇒ Object Also known as: return_the_default_open_file_button

#

return_button_for_opening_a_local_file

This method will return a button, which can be used for opening a local file.

It is recommended to passs a libui-widget into this method, so that the “open-file” functionality can have a callback. Usually that callback should be a libui-entry, so that we can fill it with the file path that we chose.

#


1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
# File 'lib/libui_paradise/base_module/base_module.rb', line 1431

def return_button_for_opening_a_local_file(
    connect_this_button_with_that_widget = nil
  )
  button_open_file = create_button('Open file')
  button_open_file.on_clicked {
    begin
      # filename = ui_open_file(window).to_s
      filename = LibUI.open_file(main_window).to_s
      # e "The filename was: #{filename}" # This line is for debugging.
      if connect_this_button_with_that_widget # This widget is usually an entry.
        filename = File.absolute_path(filename) # We need the full path here.
        connect_this_button_with_that_widget.set_text(filename) if connect_this_button_with_that_widget.respond_to?(:set_text)
      end
    rescue ArgumentError => error # Rescue from "NULL pointer given"
      pp error
    end
  }
  return button_open_file # Always return that button here.
end

#return_default_window(title = title?, , width = width?, , height = height? ) ⇒ Object

#

return_default_window

#


1392
1393
1394
1395
1396
1397
1398
# File 'lib/libui_paradise/base_module/base_module.rb', line 1392

def return_default_window(
    title  = title?,
    width  = width?,
    height = height?
  )
  return padded_main_window(title, width, height, 0)
end

#return_pwdObject

#

return_pwd

#


949
950
951
# File 'lib/libui_paradise/base_module/base_module.rb', line 949

def return_pwd
  "#{Dir.pwd}/".squeeze('/')
end

#return_the_resolution_using_xrandrObject

#

return_the_resolution_using_xrandr

This method will only work on e. g. Linux.

It will then return a String such as “1920x1080”.

#


497
498
499
500
501
502
503
504
505
506
507
# File 'lib/libui_paradise/base_module/base_module.rb', line 497

def return_the_resolution_using_xrandr
  _ = '800x600' # This is a generic failsafe value.
  begin
    xrandr_result = `xrandr`
    _ = xrandr_result.split("\n").select {|line|
      line.include? '*'
    }.first.strip.squeeze(' ').split(' ').first.to_s
  rescue Errno::ENOENT # Rescue for Windows systems.
  end
  return _ # This will yield e. g. "1920x1080"
end

#runObject

#

run

#


1185
1186
1187
# File 'lib/libui_paradise/base_module/base_module.rb', line 1185

def run
  create_skeleton_then_connect_skeleton
end

#run_mainObject

#

run_main

#


1198
1199
# File 'lib/libui_paradise/base_module/base_module.rb', line 1198

def run_main
end

#scrolling_area(optional_widget = nil) ⇒ Object Also known as: ui_scrolling_area, ui_scrolled_window

#

scrolling_area

It seems as if scrolling is not yet easily available in libui.

The upstream API is like this:

uiArea *area = uiNewScrollingArea(&handler, 400, 400);
#


722
723
724
725
726
# File 'lib/libui_paradise/base_module/base_module.rb', line 722

def scrolling_area(
    optional_widget = nil
  )
  ::LibuiParadise.scrolling_area(optional_widget)
end

#search_entryObject Also known as: ui_search_entry, create_search_entry

#

search_entry

#


339
340
341
# File 'lib/libui_paradise/base_module/base_module.rb', line 339

def search_entry
  ::LibuiParadise.search_entry
end

#selected?(pointer) ⇒ Boolean

#

selected?

Unsure whether this works. It appears to work, but I am not even certain as to why.

#

Returns:

  • (Boolean)


649
650
651
# File 'lib/libui_paradise/base_module/base_module.rb', line 649

def selected?(pointer)
  ::LibUI.combobox_selected(pointer).to_s
end

#set_commandline_arguments(i = ARGV) ⇒ Object

#

set_commandline_arguments

#


1204
1205
1206
# File 'lib/libui_paradise/base_module/base_module.rb', line 1204

def set_commandline_arguments(i = ARGV)
  @commandline_arguments = [i].flatten.compact
end

#set_height(i = 800) ⇒ Object

#

set_height

#


1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
# File 'lib/libui_paradise/base_module/base_module.rb', line 1236

def set_height(
    i = 800
  )
  case i
  # ======================================================================= #
  # === :max_width
  # ======================================================================= #
  when :max_height
    i = assumed_max_height?
  end
  if i.is_a?(String) and i.include?('%')
    # ===================================================================== #
    # In this case we have to modify this a bit.
    # ===================================================================== #
    max_height = assumed_max_height?
    i = (max_height.to_f * i.to_i) / 100.0
  end
  i = i.to_i
  @internal_hash[:height] = i
end

#set_main_window(i) ⇒ Object

#

set_main_window

#


775
776
777
778
# File 'lib/libui_paradise/base_module/base_module.rb', line 775

def set_main_window(i)
  ::LibuiParadise.set_main_window(i)
  return ::LibuiParadise.main_window?
end

#set_title(i) ⇒ Object

#

set_title

#


531
532
533
# File 'lib/libui_paradise/base_module/base_module.rb', line 531

def set_title(i)
  @internal_hash[:title] = i
end

#set_width(i = 1024) ⇒ Object

#

set_width

#


1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
# File 'lib/libui_paradise/base_module/base_module.rb', line 1292

def set_width(
    i = 1024
  )
  case i
  # ======================================================================= #
  # === :max_width
  # ======================================================================= #
  when :max_width
    i = assumed_max_width?
  end
  if i.is_a?(String) and i.include?('%')
    # ===================================================================== #
    # In this case we have to modify this a bit.
    # ===================================================================== #
    max_width = assumed_max_width?
    i = (max_width.to_f * i.to_i) / 100.0
  end
  i = i.to_i
  @internal_hash[:width] = i
end

#set_window(i = return_default_window) ⇒ Object

#

set_window

Simply assign to @window here.

#


1405
1406
1407
# File 'lib/libui_paradise/base_module/base_module.rb', line 1405

def set_window(i = return_default_window)
  ::LibuiParadise.set_window(i)
end

#sfancy(i = '') ⇒ Object

#

sfancy

#


136
137
138
# File 'lib/libui_paradise/base_module/base_module.rb', line 136

def sfancy(i = '')
  ::Colours.sfancy(i)
end

#sfile(i = '') ⇒ Object

#

sfile

#


129
130
131
# File 'lib/libui_paradise/base_module/base_module.rb', line 129

def sfile(i = '')
  ::Colours.sfile(i)
end

#slider(start_value = 0, end_value = 100) ⇒ Object Also known as: ui_slider, create_slider

#

slider (slider tag)

#


1010
1011
1012
1013
1014
1015
# File 'lib/libui_paradise/base_module/base_module.rb', line 1010

def slider(
    start_value =   0,
    end_value   = 100
  )
  return ::LibuiParadise.slider(start_value, end_value)
end

#spinbox(start_point = 0, end_point = 100) ⇒ Object Also known as: ui_spinbox, ui_spinbutton, create_spinbox, up_and_down_counter, spinbutton, centered_spin_button

#

spinbox

This method will return a spin-button, also called a spin-box.

#


734
735
736
737
738
739
# File 'lib/libui_paradise/base_module/base_module.rb', line 734

def spinbox(
    start_point =   0,
    end_point   = 100
  )
  ::LibuiParadise.spinbox(start_point, end_point)
end

#tabObject Also known as: ui_tab, ui_tabs, notebook, ui_notebook, notebook_tab

#

tab

This could be also called “notebook_tab”.

#


180
181
182
# File 'lib/libui_paradise/base_module/base_module.rb', line 180

def tab
  ::LibuiParadise.tab
end

#table(i) ⇒ Object Also known as: ui_table

#

table

#


708
709
710
# File 'lib/libui_paradise/base_module/base_module.rb', line 708

def table(i)
  ::LibuiParadise.table(i)
end

#text?(from_this_pointer) ⇒ Boolean

#

text?

This method will guarantee a String to be returned.

This is a bit weird, though. We may have to remove this method one day. I forgot why I added it to entry.rb specifically. After all other widgets also should respond to .text?.

#

Returns:

  • (Boolean)


435
436
437
438
439
# File 'lib/libui_paradise/base_module/base_module.rb', line 435

def text?(from_this_pointer)
  _ = ::LibUI.entry_text(from_this_pointer).to_s # Here we ensure a String will be returned.
  add_to_the_registered_widgets(_, __method__)
  return _
end

#text_layout(i = '') ⇒ Object

#

text_layout

Wrapper-method towards LibuiParadise.text_layout().

#


205
206
207
208
209
# File 'lib/libui_paradise/base_module/base_module.rb', line 205

def text_layout(
    i = ''
  )
  ::LibuiParadise.text_layout(i)
end

#title?Boolean

#

title?

#

Returns:

  • (Boolean)


567
568
569
# File 'lib/libui_paradise/base_module/base_module.rb', line 567

def title?
  @internal_hash[:title]
end

#title_width_height(title, width = WIDTH, height = 800) ⇒ Object Also known as: set_title_width_height

#

title_width_height

#


1143
1144
1145
1146
1147
1148
1149
1150
1151
# File 'lib/libui_paradise/base_module/base_module.rb', line 1143

def title_width_height(
    title,
    width  = WIDTH,
    height =  800
  )
  set_title(title)
  set_width(width)
  set_height(height)
end

#title_width_height_font(title = '', width = WIDTH, height = 800, font = :currently_not_handled) ⇒ Object

#

title_width_height_font

The font-argument is presently not handled. Perhaps one day in the future.

#


1131
1132
1133
1134
1135
1136
1137
1138
# File 'lib/libui_paradise/base_module/base_module.rb', line 1131

def title_width_height_font(
    title  = '',
    width  = WIDTH,
    height =  800,
    font   = :currently_not_handled
  )
  title_width_height(title, width, height)
end

#try_to_parse_this_config_file(i) ⇒ Object Also known as: parse_this_config_file

#

try_to_parse_this_config_file

This method can be used to parse a .config file for data it stores.

The .config file must have “width:”, “height:” and “title:” settings.

#


753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
# File 'lib/libui_paradise/base_module/base_module.rb', line 753

def try_to_parse_this_config_file(i)
  if File.exist? i
    dataset = File.readlines(i)
    # ===================================================================== #
    # Next check for width, height and title:
    # ===================================================================== #
    width  = dataset.select {|line| line.include? 'width:' }.first.
             split(':').last.strip.to_i
    height = dataset.select {|line| line.include? 'height:' }.first.
             split(':').last.strip.to_i
    title  = dataset.select {|line| line.include? 'title:' }.first.
             split(':').last.strip
    window = LibuiParadise.window(title, width, height)
    return window
  else
    e 'No file exists at `'+i+'`.'
  end
end

#try_to_use_this_font(i = nil) ⇒ Object Also known as: use_this_font=, set_use_this_font

#

try_to_use_this_font

This is currently not in use - once libui supports setting a font then this can be enabled.

Actually this should in theory already work as-is - I just don’t understand the toplevel API to be used here.

#


962
# File 'lib/libui_paradise/base_module/base_module.rb', line 962

def try_to_use_this_font(i = nil); end

#two_elements_hbox(widget1, widget2, options = { layout_to_use: :maximal # This is the default. }) ⇒ Object

#

two_elements_hbox

This method will return a horizontal box (hbox) that is accepting two arguments (two widgets) that will be embedded onto that hbox. Then the result is returned.

#


351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# File 'lib/libui_paradise/base_module/base_module.rb', line 351

def two_elements_hbox(
    widget1,
    widget2,
    options = {
      layout_to_use: :maximal # This is the default.
    }
  )
  _ = create_hbox
  # ======================================================================= #
  # === Handle :layout_to_use
  #
  # This is mostly done to distinguish between maximal() and minimal()
  # for widgets.
  # ======================================================================= #
  if options.is_a?(Hash) and options.has_key?(:layout_to_use)
    case options[:layout_to_use]
    # ===================================================================== #
    # === :maximal
    # ===================================================================== #
    when :maximal
      _.maximal(widget1)
      _.maximal(widget2)
    # ===================================================================== #
    # === :minimal
    # ===================================================================== #
    when :minimal
      _.minimal(widget1)
      _.minimal(widget2)
    end
  else
    _.minimal(widget1)
    _.minimal(widget2)
  end
  return _
end

#ui_draw_text_layout_paramsObject

#

ui_draw_text_layout_params

#


1003
1004
1005
# File 'lib/libui_paradise/base_module/base_module.rb', line 1003

def ui_draw_text_layout_params
  ::LibUI::FFI::DrawTextLayoutParams.malloc
end

#ui_font_descriptor(use_this_font_family = 'Hack', use_this_size = 25, use_this_weight = 500, is_in_italic_font_variant = :no, stretch_factor = 4) ⇒ Object Also known as: font_descriptor

#

ui_font_descriptor

This method will return a new font-descriptor pointer.

Usage example:

ui_font_descriptor('Hack')
#


1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
# File 'lib/libui_paradise/base_module/base_module.rb', line 1045

def ui_font_descriptor(
    use_this_font_family      = 'Hack',
    use_this_size             = 25,
    use_this_weight           = 500,
    is_in_italic_font_variant = :no,
    stretch_factor            = 4
  )
  case is_in_italic_font_variant
  when :yes
    is_in_italic_font_variant = 1 # true
  when :no
    is_in_italic_font_variant = 0 # false
  end
  font_descriptor = UI::FFI::FontDescriptor.malloc
  font_descriptor.to_ptr.free = Fiddle::RUBY_FREE
  font_descriptor.Family = use_this_font_family
  font_descriptor.Size = use_this_size
  font_descriptor.Weight = use_this_weight
  font_descriptor.Italic = is_in_italic_font_variant
  font_descriptor.Stretch = stretch_factor
  return font_descriptor
end

#ui_margined_main_window(the_title = '', width = 500, height = 300, has_menubar = 1) ⇒ Object Also known as: ui_margined_window, ui_padded_main_window, padded_main_window, margined_window, padded_window, ui_padded_window, ui_main_window, ui_window, window_or_vbox, margined_main_window, create_padded_main_window

#

ui_margined_main_window

This variant is like ui_main_window() but it will automatically put a margin on the window, via .is_margined().

Note that the variant name “ui_padded_main_window” is a misnomer, since it is a margin rather than padding - but I found that it is easier to not care about this, so for the time being (September 2021) this is how it is. It may be subject to change in the future, though.

#


283
284
285
286
287
288
289
290
291
292
293
# File 'lib/libui_paradise/base_module/base_module.rb', line 283

def ui_margined_main_window(
    the_title   = '',  # Pick a title for the window here.
    width       = 500, # width  in n pixels.
    height      = 300, # height in n pixels.
    has_menubar =   1  # hasMenubar or has not.
  )
  _ = ::LibuiParadise.window(the_title, width, height, has_menubar)
  _.is_margined
  #_.intelligent_exit # This does not work right now.
  return _
end

#ui_msg_box(main_window = :default_window, title_to_use = '', whatever = '') ⇒ Object Also known as: message_to_the_user, message_box, popup_over_this_widget, popup_message

#

ui_msg_box

This method is a convenience-wrapper over UI.msg_box().

#


547
548
549
550
551
552
553
554
555
556
557
# File 'lib/libui_paradise/base_module/base_module.rb', line 547

def ui_msg_box(
    main_window  = :default_window,
    title_to_use = '',
    whatever     = ''
  )
  ::LibuiParadise.msg_box(
    main_window,
    title_to_use,
    whatever
  )
end

#ui_open_file(main_window = ::LibuiParadise.main_window?) ⇒ Object

#

ui_open_file

This method can be used as a wrapper towards an “open local file” functionality.

#


800
801
802
803
804
# File 'lib/libui_paradise/base_module/base_module.rb', line 800

def ui_open_file(
    main_window = ::LibuiParadise.main_window?
  )
  return ::LibuiParadise.open_file(main_window)
end

#ui_padded_gridObject Also known as: padded_grid, default_grid

#

ui_padded_grid

#


412
413
414
415
416
# File 'lib/libui_paradise/base_module/base_module.rb', line 412

def ui_padded_grid
  _ = create_grid # This is defined in the method above ^^^ this method.
  _.is_padded
  return _
end

#ui_padded_hbox(*optional_widgets) ⇒ Object Also known as: padded_hbox, create_padded_hbox

#

ui_padded_hbox

This method will call .is_padded on the hbox after it has been initialized.

#


156
157
158
# File 'lib/libui_paradise/base_module/base_module.rb', line 156

def ui_padded_hbox(*optional_widgets)
  return ::LibuiParadise.ui_padded_hbox(optional_widgets)
end

#ui_padded_vbox(*optional_widgets) ⇒ Object Also known as: padded_vbox, create_padded_vbox

#

ui_padded_vbox

#


319
320
321
# File 'lib/libui_paradise/base_module/base_module.rb', line 319

def ui_padded_vbox(*optional_widgets)
  return ::LibuiParadise.ui_padded_vbox(optional_widgets)
end

#ui_sync_connect(widget1, widget2, optional_array = nil) ⇒ Object Also known as: sync_connect

#

ui_sync_connect

This method can connect two widgets: the first one should be a combo-box, and the second one a ui-entry.

#


1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
# File 'lib/libui_paradise/base_module/base_module.rb', line 1361

def ui_sync_connect(
    widget1,
    widget2,
    optional_array = nil
  )
  combobox_selected_callback = proc { |pointer|
    selected_value = selected?(pointer)
    if optional_array and optional_array.is_a?(Array)
      selected_value = optional_array[selected_value.to_i]
    end
    widget2.set_text(
      selected_value
    )
  }
  ::LibUI.combobox_on_selected(
    widget1, combobox_selected_callback, nil
  )
end

#ui_table_params_malloc(optional_model = nil) ⇒ Object

#

ui_table_params_malloc

This will basically wrap over LibUI::FFI::TableParams.malloc().

#


1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
# File 'lib/libui_paradise/base_module/base_module.rb', line 1023

def ui_table_params_malloc(
    optional_model = nil
  )
  _ = ::LibUI::FFI::TableParams.malloc
  if optional_model
    _.to_ptr.free = Fiddle::RUBY_FREE
    _.Model = optional_model
    _.RowBackgroundColorModelColumn = -1
  end
  return _
end

#ui_text_then_entry(text = '', hash = { padding: 0 }) ⇒ Object Also known as: text_then_entry

#

ui_text_then_entry

This method must return an Array containing three elements.

Note that :padding specifies whether we will use padding or not in libui. In ruby-gtk3 we can pass the pixels here; I am not sure whether this is possible via libui as such.

#


450
451
452
453
454
455
456
457
458
459
460
461
462
# File 'lib/libui_paradise/base_module/base_module.rb', line 450

def ui_text_then_entry(
    text = '',
    hash = {
      padding: 0
    }
  )
  hbox = padded_hbox   # First element.
  text = ui_text(text) # Second element.
  hbox.minimal(text,  hash[:padding])
  entry = ui_entry     # Third element.
  hbox.minimal(entry, hash[:padding])
  return [hbox, text, entry]
end

#use_gtk3?Boolean

#

use_gtk3?

#

Returns:

  • (Boolean)


969
970
971
# File 'lib/libui_paradise/base_module/base_module.rb', line 969

def use_gtk3?
  Object.const_defined?(:Gtk)
end

#use_gtk?Boolean Also known as: uses_gtk4?

#

use_gtk?

#

Returns:

  • (Boolean)


935
936
937
# File 'lib/libui_paradise/base_module/base_module.rb', line 935

def use_gtk?
  false
end

#use_libui?Boolean

#

use_libui?

#

Returns:

  • (Boolean)


942
943
944
# File 'lib/libui_paradise/base_module/base_module.rb', line 942

def use_libui?
  true
end

#vbox(*optional_widgets) ⇒ Object Also known as: ui_vbox, vertical_box, create_vbox, libui_vbox, gtk_box

#

vbox

Note that the alias gtk_box is just a helper-method for ruby-gtk3 compatibility.

#


167
168
169
# File 'lib/libui_paradise/base_module/base_module.rb', line 167

def vbox(*optional_widgets)
  return ::LibuiParadise.vbox(optional_widgets)
end

#vertical_separatorObject Also known as: ui_vseparator, ui_vsep, vertical_spacer, vspacer, vsep

#

vertical_separator

#


308
309
310
# File 'lib/libui_paradise/base_module/base_module.rb', line 308

def vertical_separator
  ::LibuiParadise.vertical_separator
end

#width?Boolean

#

width?

#

Returns:

  • (Boolean)


1316
1317
1318
# File 'lib/libui_paradise/base_module/base_module.rb', line 1316

def width?
  @internal_hash[:width]
end

#window(the_title = '', width = 500, height = 300, has_menubar = 1) ⇒ Object Also known as: create_main_window, create_window

#

window

#


467
468
469
470
471
472
473
474
475
476
477
478
479
# File 'lib/libui_paradise/base_module/base_module.rb', line 467

def window(
    the_title   = '',  # Pick a title for the window here.
    width       = 500, # width  in n pixels.
    height      = 300, # height in n pixels.
    has_menubar =   1  # hasMenubar or has not.
  )
  ::LibuiParadise.window(
    the_title,
    width,
    height,
    has_menubar
  )
end

#window?Boolean Also known as: main_window?, main_window

#

window?

#

Returns:

  • (Boolean)


485
486
487
# File 'lib/libui_paradise/base_module/base_module.rb', line 485

def window?
  ::LibuiParadise.main_window?
end

#without_trailing_comment(i) ⇒ Object

#

without_trailing_comment

#


1274
1275
1276
1277
1278
1279
1280
# File 'lib/libui_paradise/base_module/base_module.rb', line 1274

def without_trailing_comment(i)
  i = i.dup
  if i and i.end_with?('#')
    i = i[0 .. -2]
  end
  return i
end

#wrapper_new_progress_barObject Also known as: progress_bar

#

wrapper_new_progress_bar

#


673
674
675
# File 'lib/libui_paradise/base_module/base_module.rb', line 673

def wrapper_new_progress_bar
  return ::LibuiParadise.wrapper_new_progress_bar
end