libui_paradise 0.2.49 → 0.4.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +405 -259
- data/bin/libui_message +7 -0
- data/doc/README.gen +356 -131
- data/doc/todo/todo.md +14 -5
- data/lib/libui_paradise/autoinclude.rb +2 -1
- data/lib/libui_paradise/base/base.rb +51 -62
- data/lib/libui_paradise/base_module/base_module.rb +1514 -0
- data/lib/libui_paradise/colours/colours.rb +14 -2
- data/lib/libui_paradise/domain_specific_language/README.md +6 -0
- data/lib/libui_paradise/examples/complex/002_tabs_example.rb +1 -2
- data/lib/libui_paradise/examples/complex/003_open_file_button_example.rb +3 -5
- data/lib/libui_paradise/examples/complex/006_coloured_boxes_example.rb +2 -2
- data/lib/libui_paradise/examples/complex/007_slider_example.rb +10 -4
- data/lib/libui_paradise/examples/complex/008_radio_button_example.rb +2 -2
- data/lib/libui_paradise/examples/complex/009_separator_example.rb +2 -2
- data/lib/libui_paradise/examples/complex/010_table_example.rb +139 -49
- data/lib/libui_paradise/examples/complex/011_two_buttons_showing_how_to_enable_and_disable_them.rb +2 -1
- data/lib/libui_paradise/examples/complex/012_password_entry_example.rb +1 -1
- data/lib/libui_paradise/examples/complex/013_form_example.rb +1 -1
- data/lib/libui_paradise/examples/complex/014_text_example.rb +1 -1
- data/lib/libui_paradise/examples/complex/015_text_view_example.rb +4 -4
- data/lib/libui_paradise/examples/complex/016_grid_example.rb +20 -11
- data/lib/libui_paradise/examples/complex/017_unicode_text_example.rb +2 -2
- data/lib/libui_paradise/examples/complex/018_spinbutton_example.rb +1 -1
- data/lib/libui_paradise/examples/complex/019_combo_box_example.rb +1 -1
- data/lib/libui_paradise/examples/complex/020_checkbox_example.rb +5 -5
- data/lib/libui_paradise/examples/complex/021_font_example.rb +4 -3
- data/lib/libui_paradise/examples/complex/022_simple_notepad_example.rb +3 -3
- data/lib/libui_paradise/examples/complex/023_msg_box_error.rb +5 -5
- data/lib/libui_paradise/examples/complex/024_parse_config_file_example.rb +2 -2
- data/lib/libui_paradise/examples/complex/025_colour_button.rb +1 -1
- data/lib/libui_paradise/examples/complex/026_basic_table_image.rb +5 -8
- data/lib/libui_paradise/examples/complex/027_basic_button_example.rb +3 -3
- data/lib/libui_paradise/examples/complex/028_try_for_automatic_button_press_event_after_a_delay.rb +4 -5
- data/lib/libui_paradise/examples/complex/029_progressbar_example.rb +4 -5
- data/lib/libui_paradise/examples/complex/030_entry_responds_to_comment_as_synonymous_to_the_enter_key_pressed_example.rb +5 -6
- data/lib/libui_paradise/examples/complex/031_notification_functionality_example.rb +3 -2
- data/lib/libui_paradise/examples/complex/032_simple_window_example.rb +2 -1
- data/lib/libui_paradise/examples/complex/033_daemonize_and_exit_after_delay_example.rb +3 -2
- data/lib/libui_paradise/examples/complex/034_bold_text_example.rb +115 -0
- data/lib/libui_paradise/examples/complex/035_parse_into_table_example.rb +109 -0
- data/lib/libui_paradise/examples/simple/001_open_file_example.rb +1 -1
- data/lib/libui_paradise/examples/simple/002_histogram_example.rb +6 -6
- data/lib/libui_paradise/examples/simple/003_fancy_text_example.rb +80 -43
- data/lib/libui_paradise/examples/simple/005_text_drawing_example.rb +11 -11
- data/lib/libui_paradise/examples/simple/007_control_gallery.rb +21 -14
- data/lib/libui_paradise/examples/simple/009_spectrum.rb +7 -1
- data/lib/libui_paradise/examples/simple/010_font_button.rb +31 -0
- data/lib/libui_paradise/examples/simple/011_simple_notepad.rb +24 -0
- data/lib/libui_paradise/examples/simple/012_table_example.rb +71 -0
- data/lib/libui_paradise/examples/simple/013_scrolling_pane_example.rb +28 -0
- data/lib/libui_paradise/examples/simple/014_simple_entry_example.rb +30 -0
- data/lib/libui_paradise/examples/simple/015_slider_example.rb +32 -0
- data/lib/libui_paradise/fiddle/{pointer.rb → fiddle.rb} +768 -615
- data/lib/libui_paradise/generic_window/generic_window.rb +1 -1
- data/lib/libui_paradise/images/README.md +5 -2
- data/lib/libui_paradise/libui_classes/button.rb +31 -0
- data/lib/libui_paradise/libui_classes/entry.rb +35 -0
- data/lib/libui_paradise/libui_classes/grid.rb +14 -23
- data/lib/libui_paradise/libui_classes/hbox.rb +39 -0
- data/lib/libui_paradise/libui_classes/libui_classes.rb +9 -1595
- data/lib/libui_paradise/libui_classes/msg_box.rb +121 -0
- data/lib/libui_paradise/libui_classes/msg_box_error.rb +41 -0
- data/lib/libui_paradise/libui_classes/slider.rb +28 -0
- data/lib/libui_paradise/libui_classes/spinbox.rb +48 -0
- data/lib/libui_paradise/libui_classes/vbox.rb +38 -0
- data/lib/libui_paradise/project/project.rb +6 -1
- data/lib/libui_paradise/prototype/prototype.rb +8 -10
- data/lib/libui_paradise/requires/require_the_libui_classes.rb +2 -2
- data/lib/libui_paradise/requires/require_the_libui_paradise_project.rb +5 -3
- data/lib/libui_paradise/toplevel_methods/add_to_the_registered_widgets.rb +70 -0
- data/lib/libui_paradise/toplevel_methods/hash_fiddle_pointer_widgets.rb +37 -0
- data/lib/libui_paradise/toplevel_methods/toplevel_counters.rb +83 -0
- data/lib/libui_paradise/toplevel_methods/toplevel_methods.rb +792 -0
- data/lib/libui_paradise/version/version.rb +2 -2
- data/lib/libui_paradise.rb +0 -0
- data/libui_paradise.gemspec +5 -4
- data/test/testing_generic_window.rb +2 -0
- metadata +35 -30
- data/doc/SNIPPETS.md +0 -94
- data/lib/libui_paradise/extensions/counters.rb +0 -58
- data/lib/libui_paradise/extensions/extensions.rb +0 -29
- data/lib/libui_paradise/extensions/hash_fiddle_pointer_widgets.rb +0 -150
- data/lib/libui_paradise/extensions/misc.rb +0 -754
- data/lib/libui_paradise/libui_classes/box.rb +0 -156
- data/lib/libui_paradise/toplevel_methods/misc.rb +0 -13
|
@@ -0,0 +1,1514 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# === LibuiParadise::BaseModule
|
|
6
|
+
#
|
|
7
|
+
# The module defined in this .rb file is primarly used to "extend"
|
|
8
|
+
# libui in a convenient way. Upon this file being required, several
|
|
9
|
+
# additional actions are performed or made available, such as "alias
|
|
10
|
+
# e puts". That way we only have to require this file and the rest
|
|
11
|
+
# will be set up correctly for us automatically, for reasons of
|
|
12
|
+
# convenience.
|
|
13
|
+
# =========================================================================== #
|
|
14
|
+
# require 'libui_paradise/base_module/base_module.rb'
|
|
15
|
+
# include LibuiParadise::BaseModule
|
|
16
|
+
# =========================================================================== #
|
|
17
|
+
module LibuiParadise
|
|
18
|
+
|
|
19
|
+
require 'libui' # Mandatory require-call.
|
|
20
|
+
|
|
21
|
+
# =========================================================================== #
|
|
22
|
+
# === LibuiParadise.initializer
|
|
23
|
+
# =========================================================================== #
|
|
24
|
+
def self.initializer
|
|
25
|
+
::LibuiParadise.register_sigint
|
|
26
|
+
Object.const_set('UI', LibUI) # This is equal to: UI = LibUI
|
|
27
|
+
::LibUI.extend(LibuiParadise::BaseModule) # This call will also trigger the extended-hook.
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
module BaseModule # === LibuiParadise::BaseModule
|
|
31
|
+
|
|
32
|
+
alias e puts
|
|
33
|
+
|
|
34
|
+
require 'yaml' # Yaml is really useful, so we'll load it up here as well.
|
|
35
|
+
|
|
36
|
+
require 'fileutils' # A useful require-call.
|
|
37
|
+
require 'libui_paradise/project/project.rb'
|
|
38
|
+
require 'libui_paradise/colours/colours.rb'
|
|
39
|
+
require 'libui_paradise/fiddle/fiddle.rb'
|
|
40
|
+
require 'libui_paradise/toplevel_methods/add_to_the_registered_widgets.rb'
|
|
41
|
+
require 'libui_paradise/toplevel_methods/hash_fiddle_pointer_widgets.rb'
|
|
42
|
+
require 'libui_paradise/toplevel_methods/toplevel_methods.rb'
|
|
43
|
+
require 'libui_paradise/libui_classes/libui_classes.rb'
|
|
44
|
+
require 'libui_paradise/libui_classes/button.rb'
|
|
45
|
+
require 'libui_paradise/libui_classes/entry.rb'
|
|
46
|
+
require 'libui_paradise/libui_classes/msg_box.rb'
|
|
47
|
+
require 'libui_paradise/libui_classes/msg_box_error.rb'
|
|
48
|
+
require 'libui_paradise/libui_classes/grid.rb'
|
|
49
|
+
require 'libui_paradise/libui_classes/hbox.rb'
|
|
50
|
+
require 'libui_paradise/libui_classes/slider.rb'
|
|
51
|
+
require 'libui_paradise/libui_classes/spinbox.rb'
|
|
52
|
+
require 'libui_paradise/libui_classes/vbox.rb'
|
|
53
|
+
|
|
54
|
+
# ========================================================================= #
|
|
55
|
+
# Add support for fiddle next:
|
|
56
|
+
# ========================================================================= #
|
|
57
|
+
require 'libui_paradise/fiddle/fiddle.rb'
|
|
58
|
+
|
|
59
|
+
# ========================================================================= #
|
|
60
|
+
# === WIDTH
|
|
61
|
+
#
|
|
62
|
+
# Define a default value for the WIDTH constant.
|
|
63
|
+
# ========================================================================= #
|
|
64
|
+
WIDTH = 1024
|
|
65
|
+
|
|
66
|
+
# ========================================================================= #
|
|
67
|
+
# === HEIGHT
|
|
68
|
+
# ========================================================================= #
|
|
69
|
+
HEIGHT = 680
|
|
70
|
+
|
|
71
|
+
# ========================================================================= #
|
|
72
|
+
# === reset
|
|
73
|
+
# ========================================================================= #
|
|
74
|
+
def reset
|
|
75
|
+
reset_the_internal_hash
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# ========================================================================= #
|
|
79
|
+
# === reset_the_internal_hash
|
|
80
|
+
# ========================================================================= #
|
|
81
|
+
def reset_the_internal_hash
|
|
82
|
+
@internal_hash = {}
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# ========================================================================= #
|
|
86
|
+
# === create_grid
|
|
87
|
+
# ========================================================================= #
|
|
88
|
+
def create_grid
|
|
89
|
+
::LibuiParadise.create_grid
|
|
90
|
+
end; alias grid create_grid # === grid
|
|
91
|
+
alias ui_grid create_grid # === ui_grid
|
|
92
|
+
alias create_default_grid create_grid # === create_default_grid
|
|
93
|
+
|
|
94
|
+
# ========================================================================= #
|
|
95
|
+
# === register_this_fiddle_pointer_widget
|
|
96
|
+
#
|
|
97
|
+
# This method will simply delegate towards:
|
|
98
|
+
#
|
|
99
|
+
# LibuiParadise.register_this_fiddle_pointer_widget()
|
|
100
|
+
#
|
|
101
|
+
# ========================================================================= #
|
|
102
|
+
def register_this_fiddle_pointer_widget(
|
|
103
|
+
the_fiddle_pointer_widget,
|
|
104
|
+
the_type_of_the_widget = nil
|
|
105
|
+
)
|
|
106
|
+
::LibuiParadise.register_this_fiddle_pointer_widget(
|
|
107
|
+
the_fiddle_pointer_widget,
|
|
108
|
+
the_type_of_the_widget
|
|
109
|
+
)
|
|
110
|
+
end; alias add_to_the_registered_widgets register_this_fiddle_pointer_widget # === add_to_the_registered_widgets
|
|
111
|
+
|
|
112
|
+
# ========================================================================= #
|
|
113
|
+
# === button (button tag)
|
|
114
|
+
#
|
|
115
|
+
# This method will create a libui-button. Note that the alias
|
|
116
|
+
# create_button() is an important alias to this method.
|
|
117
|
+
# ========================================================================= #
|
|
118
|
+
def button(
|
|
119
|
+
text = '',
|
|
120
|
+
&block
|
|
121
|
+
)
|
|
122
|
+
return ::LibuiParadise.button(text, &block)
|
|
123
|
+
end; alias ui_button button # === ui_button
|
|
124
|
+
alias create_button button # === create_button
|
|
125
|
+
|
|
126
|
+
# ========================================================================= #
|
|
127
|
+
# === sfile
|
|
128
|
+
# ========================================================================= #
|
|
129
|
+
def sfile(i = '')
|
|
130
|
+
::Colours.sfile(i)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# ========================================================================= #
|
|
134
|
+
# === sfancy
|
|
135
|
+
# ========================================================================= #
|
|
136
|
+
def sfancy(i = '')
|
|
137
|
+
::Colours.sfancy(i)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
# ========================================================================= #
|
|
141
|
+
# === hbox (hbox tag)
|
|
142
|
+
# ========================================================================= #
|
|
143
|
+
def hbox(*optional_widgets)
|
|
144
|
+
::LibuiParadise.hbox(optional_widgets)
|
|
145
|
+
end; alias ui_hbox hbox # === ui_hbox
|
|
146
|
+
alias horizontal_box hbox # === horizontal_box
|
|
147
|
+
alias create_hbox hbox # === create_hbox
|
|
148
|
+
alias libui_hbox hbox # === libui_hbox
|
|
149
|
+
|
|
150
|
+
# ========================================================================= #
|
|
151
|
+
# === ui_padded_hbox
|
|
152
|
+
#
|
|
153
|
+
# This method will call .is_padded on the hbox after it has been
|
|
154
|
+
# initialized.
|
|
155
|
+
# ========================================================================= #
|
|
156
|
+
def ui_padded_hbox(*optional_widgets)
|
|
157
|
+
return ::LibuiParadise.ui_padded_hbox(optional_widgets)
|
|
158
|
+
end; alias padded_hbox ui_padded_hbox # === padded_hbox
|
|
159
|
+
alias create_padded_hbox ui_padded_hbox # === create_padded_hbox
|
|
160
|
+
|
|
161
|
+
# ========================================================================= #
|
|
162
|
+
# === vbox
|
|
163
|
+
#
|
|
164
|
+
# Note that the alias gtk_box is just a helper-method for ruby-gtk3
|
|
165
|
+
# compatibility.
|
|
166
|
+
# ========================================================================= #
|
|
167
|
+
def vbox(*optional_widgets)
|
|
168
|
+
return ::LibuiParadise.vbox(optional_widgets)
|
|
169
|
+
end; alias ui_vbox vbox # === ui_vbox
|
|
170
|
+
alias vertical_box vbox # === vertical_box
|
|
171
|
+
alias create_vbox vbox # === create_vbox
|
|
172
|
+
alias libui_vbox vbox # === libui_vbox
|
|
173
|
+
alias gtk_box vbox # === gtk_box
|
|
174
|
+
|
|
175
|
+
# ========================================================================= #
|
|
176
|
+
# === tab
|
|
177
|
+
#
|
|
178
|
+
# This could be also called "notebook_tab".
|
|
179
|
+
# ========================================================================= #
|
|
180
|
+
def tab
|
|
181
|
+
::LibuiParadise.tab
|
|
182
|
+
end; alias ui_tab tab # === ui_tab
|
|
183
|
+
alias ui_tabs tab # === ui_tabs
|
|
184
|
+
alias notebook tab # === notebook
|
|
185
|
+
alias ui_notebook tab # === ui_notebook
|
|
186
|
+
alias notebook_tab tab # === notebook_tab
|
|
187
|
+
|
|
188
|
+
# ========================================================================= #
|
|
189
|
+
# === password_entry
|
|
190
|
+
#
|
|
191
|
+
# Usage example:
|
|
192
|
+
#
|
|
193
|
+
# entry = ui_password_entry
|
|
194
|
+
#
|
|
195
|
+
# ========================================================================= #
|
|
196
|
+
def password_entry
|
|
197
|
+
::LibuiParadise.password_entry
|
|
198
|
+
end; alias ui_password_entry password_entry # === ui_password_entry
|
|
199
|
+
|
|
200
|
+
# ========================================================================= #
|
|
201
|
+
# === text_layout
|
|
202
|
+
#
|
|
203
|
+
# Wrapper-method towards LibuiParadise.text_layout().
|
|
204
|
+
# ========================================================================= #
|
|
205
|
+
def text_layout(
|
|
206
|
+
i = ''
|
|
207
|
+
)
|
|
208
|
+
::LibuiParadise.text_layout(i)
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
# ========================================================================= #
|
|
212
|
+
# === free_table_model
|
|
213
|
+
# ========================================================================= #
|
|
214
|
+
def free_table_model(model)
|
|
215
|
+
::LibUI.free_table_model(model)
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
# ========================================================================= #
|
|
219
|
+
# === multiline_entry
|
|
220
|
+
#
|
|
221
|
+
# Wrapper-method towards LibuiParadise.multiline_entry().
|
|
222
|
+
# ========================================================================= #
|
|
223
|
+
def multiline_entry(
|
|
224
|
+
optional_content = nil
|
|
225
|
+
)
|
|
226
|
+
::LibuiParadise.multiline_entry(optional_content)
|
|
227
|
+
end; alias ui_multiline_entry multiline_entry # === ui_multiline_entry
|
|
228
|
+
alias textview multiline_entry # === textview
|
|
229
|
+
alias text_view multiline_entry # === text_view
|
|
230
|
+
alias ui_text_view multiline_entry # === ui_text_view
|
|
231
|
+
alias ui_textview multiline_entry # === ui_textview
|
|
232
|
+
alias ui_text_buffer multiline_entry # === ui_text_buffer
|
|
233
|
+
alias input_field multiline_entry # === input_field
|
|
234
|
+
alias input multiline_entry # === input
|
|
235
|
+
|
|
236
|
+
# ========================================================================= #
|
|
237
|
+
# === colour_button
|
|
238
|
+
# ========================================================================= #
|
|
239
|
+
def colour_button
|
|
240
|
+
::LibuiParadise.new_colour_button
|
|
241
|
+
end; alias color_button colour_button # === color_button
|
|
242
|
+
alias ui_colour_button colour_button # === ui_color_button
|
|
243
|
+
|
|
244
|
+
# ========================================================================= #
|
|
245
|
+
# === area
|
|
246
|
+
#
|
|
247
|
+
# AreaHandler defines the functionality needed for handling events
|
|
248
|
+
# from an Area.
|
|
249
|
+
#
|
|
250
|
+
# Upstream documentation, at the least for Go, can be found here:
|
|
251
|
+
#
|
|
252
|
+
# https://github.com/andlabs/ui/blob/master/areahandler.go
|
|
253
|
+
#
|
|
254
|
+
# ========================================================================= #
|
|
255
|
+
def area(
|
|
256
|
+
i = :use_new_area_handler
|
|
257
|
+
)
|
|
258
|
+
return ::LibuiParadise.area(i)
|
|
259
|
+
end; alias area_handler area # === area_handler
|
|
260
|
+
|
|
261
|
+
# ========================================================================= #
|
|
262
|
+
# === editable_combobox
|
|
263
|
+
# ========================================================================= #
|
|
264
|
+
def editable_combobox(
|
|
265
|
+
optional_array = nil, &block
|
|
266
|
+
)
|
|
267
|
+
return ::LibuiParadise.editable_combobox(optional_array, &block)
|
|
268
|
+
end; alias editable_combo_box editable_combobox # === editable_combo_box
|
|
269
|
+
alias ui_editable_combo_box editable_combobox # === ui_editable_combo_box
|
|
270
|
+
|
|
271
|
+
# ========================================================================= #
|
|
272
|
+
# === ui_margined_main_window
|
|
273
|
+
#
|
|
274
|
+
# This variant is like ui_main_window() but it will automatically
|
|
275
|
+
# put a margin on the window, via .is_margined().
|
|
276
|
+
#
|
|
277
|
+
# Note that the variant name "ui_padded_main_window" is a misnomer,
|
|
278
|
+
# since it is a margin rather than padding - but I found that it
|
|
279
|
+
# is easier to not care about this, so for the time being (September
|
|
280
|
+
# 2021) this is how it is. It may be subject to change in the future,
|
|
281
|
+
# though.
|
|
282
|
+
# ========================================================================= #
|
|
283
|
+
def ui_margined_main_window(
|
|
284
|
+
the_title = '', # Pick a title for the window here.
|
|
285
|
+
width = 500, # width in n pixels.
|
|
286
|
+
height = 300, # height in n pixels.
|
|
287
|
+
has_menubar = 1 # hasMenubar or has not.
|
|
288
|
+
)
|
|
289
|
+
_ = ::LibuiParadise.window(the_title, width, height, has_menubar)
|
|
290
|
+
_.is_margined
|
|
291
|
+
#_.intelligent_exit # This does not work right now.
|
|
292
|
+
return _
|
|
293
|
+
end; alias ui_margined_window ui_margined_main_window # === ui_margined_window
|
|
294
|
+
alias ui_padded_main_window ui_margined_main_window # === ui_padded_main_window
|
|
295
|
+
alias padded_main_window ui_margined_main_window # === padded_main_window
|
|
296
|
+
alias margined_window ui_margined_main_window # === margined_window
|
|
297
|
+
alias padded_window ui_margined_main_window # === padded_window
|
|
298
|
+
alias ui_padded_window ui_margined_main_window # === ui_padded_window
|
|
299
|
+
alias ui_main_window ui_margined_main_window # === ui_main_window
|
|
300
|
+
alias ui_window ui_margined_main_window # === ui_window
|
|
301
|
+
alias window_or_vbox ui_margined_main_window # === window_or_vbox
|
|
302
|
+
alias margined_main_window ui_margined_main_window # === margined_main_window
|
|
303
|
+
alias create_padded_main_window ui_margined_main_window # === create_padded_main_window
|
|
304
|
+
|
|
305
|
+
# ========================================================================= #
|
|
306
|
+
# === vertical_separator
|
|
307
|
+
# ========================================================================= #
|
|
308
|
+
def vertical_separator
|
|
309
|
+
::LibuiParadise.vertical_separator
|
|
310
|
+
end; alias ui_vseparator vertical_separator # === ui_vseparator
|
|
311
|
+
alias ui_vsep vertical_separator # === ui_vsep
|
|
312
|
+
alias vertical_spacer vertical_separator # === vertical_spacer
|
|
313
|
+
alias vspacer vertical_separator # === vspacer
|
|
314
|
+
alias vsep vertical_separator # === vsep
|
|
315
|
+
|
|
316
|
+
# ========================================================================= #
|
|
317
|
+
# === ui_padded_vbox
|
|
318
|
+
# ========================================================================= #
|
|
319
|
+
def ui_padded_vbox(*optional_widgets)
|
|
320
|
+
return ::LibuiParadise.ui_padded_vbox(optional_widgets)
|
|
321
|
+
end; alias padded_vbox ui_padded_vbox # === padded_vbox
|
|
322
|
+
alias create_padded_vbox ui_padded_vbox # === create_padded_vbox
|
|
323
|
+
|
|
324
|
+
# ========================================================================= #
|
|
325
|
+
# === horizontal_separator
|
|
326
|
+
# ========================================================================= #
|
|
327
|
+
def horizontal_separator
|
|
328
|
+
::LibuiParadise.new_horizontal_separator
|
|
329
|
+
end; alias ui_hseparator horizontal_separator # === ui_hseparator
|
|
330
|
+
alias ui_hsep horizontal_separator # === ui_hsep
|
|
331
|
+
alias hspacer horizontal_separator # === hspacer
|
|
332
|
+
alias horizontal_spacer horizontal_separator # === horizontal_spacer
|
|
333
|
+
alias hsep horizontal_separator # === hsep
|
|
334
|
+
alias libui_hsep horizontal_separator # === libui_hsep
|
|
335
|
+
|
|
336
|
+
# ========================================================================= #
|
|
337
|
+
# === search_entry
|
|
338
|
+
# ========================================================================= #
|
|
339
|
+
def search_entry
|
|
340
|
+
::LibuiParadise.search_entry
|
|
341
|
+
end; alias ui_search_entry search_entry # === ui_search_entry
|
|
342
|
+
alias create_search_entry search_entry # === create_search_entry
|
|
343
|
+
|
|
344
|
+
# ========================================================================= #
|
|
345
|
+
# === two_elements_hbox
|
|
346
|
+
#
|
|
347
|
+
# This method will return a horizontal box (hbox) that is accepting
|
|
348
|
+
# two arguments (two widgets) that will be embedded onto that hbox.
|
|
349
|
+
# Then the result is returned.
|
|
350
|
+
# ========================================================================= #
|
|
351
|
+
def two_elements_hbox(
|
|
352
|
+
widget1,
|
|
353
|
+
widget2,
|
|
354
|
+
options = {
|
|
355
|
+
layout_to_use: :maximal # This is the default.
|
|
356
|
+
}
|
|
357
|
+
)
|
|
358
|
+
_ = create_hbox
|
|
359
|
+
# ======================================================================= #
|
|
360
|
+
# === Handle :layout_to_use
|
|
361
|
+
#
|
|
362
|
+
# This is mostly done to distinguish between maximal() and minimal()
|
|
363
|
+
# for widgets.
|
|
364
|
+
# ======================================================================= #
|
|
365
|
+
if options.is_a?(Hash) and options.has_key?(:layout_to_use)
|
|
366
|
+
case options[:layout_to_use]
|
|
367
|
+
# ===================================================================== #
|
|
368
|
+
# === :maximal
|
|
369
|
+
# ===================================================================== #
|
|
370
|
+
when :maximal
|
|
371
|
+
_.maximal(widget1)
|
|
372
|
+
_.maximal(widget2)
|
|
373
|
+
# ===================================================================== #
|
|
374
|
+
# === :minimal
|
|
375
|
+
# ===================================================================== #
|
|
376
|
+
when :minimal
|
|
377
|
+
_.minimal(widget1)
|
|
378
|
+
_.minimal(widget2)
|
|
379
|
+
end
|
|
380
|
+
else
|
|
381
|
+
_.minimal(widget1)
|
|
382
|
+
_.minimal(widget2)
|
|
383
|
+
end
|
|
384
|
+
return _
|
|
385
|
+
end
|
|
386
|
+
|
|
387
|
+
# ========================================================================= #
|
|
388
|
+
# === entry (entry tag)
|
|
389
|
+
#
|
|
390
|
+
# This method is tapping into LibUI.new_entry.
|
|
391
|
+
#
|
|
392
|
+
# An alias exists to this method, called hcentered_entry. This currently
|
|
393
|
+
# does not work for libui, and is thus only added for compatibility
|
|
394
|
+
# reasons.
|
|
395
|
+
#
|
|
396
|
+
# Usage example:
|
|
397
|
+
#
|
|
398
|
+
# entry1 = ui_entry('ATG')
|
|
399
|
+
#
|
|
400
|
+
# ========================================================================= #
|
|
401
|
+
def entry(
|
|
402
|
+
optional_text = ''
|
|
403
|
+
)
|
|
404
|
+
::LibuiParadise.entry(optional_text)
|
|
405
|
+
end; alias ui_entry entry # === ui_entry
|
|
406
|
+
alias hcentered_entry entry # === hcentered_entry
|
|
407
|
+
alias create_entry entry # === create_entry
|
|
408
|
+
|
|
409
|
+
# ========================================================================= #
|
|
410
|
+
# === ui_padded_grid
|
|
411
|
+
# ========================================================================= #
|
|
412
|
+
def ui_padded_grid
|
|
413
|
+
_ = create_grid # This is defined in the method above ^^^ this method.
|
|
414
|
+
_.is_padded
|
|
415
|
+
return _
|
|
416
|
+
end; alias padded_grid ui_padded_grid # === padded_grid
|
|
417
|
+
alias default_grid ui_padded_grid # === default_grid
|
|
418
|
+
|
|
419
|
+
# ========================================================================= #
|
|
420
|
+
# === create_table
|
|
421
|
+
# ========================================================================= #
|
|
422
|
+
def create_table(model)
|
|
423
|
+
::LibuiParadise.table(model)
|
|
424
|
+
end
|
|
425
|
+
|
|
426
|
+
# ========================================================================= #
|
|
427
|
+
# === text?
|
|
428
|
+
#
|
|
429
|
+
# This method will guarantee a String to be returned.
|
|
430
|
+
#
|
|
431
|
+
# This is a bit weird, though. We may have to remove this method one
|
|
432
|
+
# day. I forgot why I added it to entry.rb specifically. After all
|
|
433
|
+
# other widgets also should respond to .text?.
|
|
434
|
+
# ========================================================================= #
|
|
435
|
+
def text?(from_this_pointer)
|
|
436
|
+
_ = ::LibUI.entry_text(from_this_pointer).to_s # Here we ensure a String will be returned.
|
|
437
|
+
add_to_the_registered_widgets(_, __method__)
|
|
438
|
+
return _
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
# ========================================================================= #
|
|
442
|
+
# === ui_text_then_entry
|
|
443
|
+
#
|
|
444
|
+
# This method must return an Array containing three elements.
|
|
445
|
+
#
|
|
446
|
+
# Note that :padding specifies whether we will use padding or not in
|
|
447
|
+
# libui. In ruby-gtk3 we can pass the pixels here; I am not sure
|
|
448
|
+
# whether this is possible via libui as such.
|
|
449
|
+
# ========================================================================= #
|
|
450
|
+
def ui_text_then_entry(
|
|
451
|
+
text = '',
|
|
452
|
+
hash = {
|
|
453
|
+
padding: 0
|
|
454
|
+
}
|
|
455
|
+
)
|
|
456
|
+
hbox = padded_hbox # First element.
|
|
457
|
+
text = ui_text(text) # Second element.
|
|
458
|
+
hbox.minimal(text, hash[:padding])
|
|
459
|
+
entry = ui_entry # Third element.
|
|
460
|
+
hbox.minimal(entry, hash[:padding])
|
|
461
|
+
return [hbox, text, entry]
|
|
462
|
+
end; alias text_then_entry ui_text_then_entry # === text_then_entry
|
|
463
|
+
|
|
464
|
+
# ========================================================================= #
|
|
465
|
+
# === window
|
|
466
|
+
# ========================================================================= #
|
|
467
|
+
def window(
|
|
468
|
+
the_title = '', # Pick a title for the window here.
|
|
469
|
+
width = 500, # width in n pixels.
|
|
470
|
+
height = 300, # height in n pixels.
|
|
471
|
+
has_menubar = 1 # hasMenubar or has not.
|
|
472
|
+
)
|
|
473
|
+
::LibuiParadise.window(
|
|
474
|
+
the_title,
|
|
475
|
+
width,
|
|
476
|
+
height,
|
|
477
|
+
has_menubar
|
|
478
|
+
)
|
|
479
|
+
end; alias create_main_window window # === main_window
|
|
480
|
+
alias create_window window # === create_window
|
|
481
|
+
|
|
482
|
+
# ========================================================================= #
|
|
483
|
+
# === window?
|
|
484
|
+
# ========================================================================= #
|
|
485
|
+
def window?
|
|
486
|
+
::LibuiParadise.main_window?
|
|
487
|
+
end; alias main_window? window? # === main_window?
|
|
488
|
+
alias main_window window? # === main_window
|
|
489
|
+
|
|
490
|
+
# ========================================================================= #
|
|
491
|
+
# === return_the_resolution_using_xrandr
|
|
492
|
+
#
|
|
493
|
+
# This method will only work on e. g. Linux.
|
|
494
|
+
#
|
|
495
|
+
# It will then return a String such as "1920x1080".
|
|
496
|
+
# ========================================================================= #
|
|
497
|
+
def return_the_resolution_using_xrandr
|
|
498
|
+
_ = '800x600' # This is a generic failsafe value.
|
|
499
|
+
begin
|
|
500
|
+
xrandr_result = `xrandr`
|
|
501
|
+
_ = xrandr_result.split("\n").select {|line|
|
|
502
|
+
line.include? '*'
|
|
503
|
+
}.first.strip.squeeze(' ').split(' ').first.to_s
|
|
504
|
+
rescue Errno::ENOENT # Rescue for Windows systems.
|
|
505
|
+
end
|
|
506
|
+
return _ # This will yield e. g. "1920x1080"
|
|
507
|
+
end
|
|
508
|
+
|
|
509
|
+
# ========================================================================= #
|
|
510
|
+
# === set_title
|
|
511
|
+
# ========================================================================= #
|
|
512
|
+
def set_title(i)
|
|
513
|
+
@internal_hash[:title] = i
|
|
514
|
+
end
|
|
515
|
+
|
|
516
|
+
# ========================================================================= #
|
|
517
|
+
# === title?
|
|
518
|
+
# ========================================================================= #
|
|
519
|
+
def title?
|
|
520
|
+
@internal_hash[:title]
|
|
521
|
+
end
|
|
522
|
+
|
|
523
|
+
# ========================================================================= #
|
|
524
|
+
# === height?
|
|
525
|
+
# ========================================================================= #
|
|
526
|
+
def height?
|
|
527
|
+
@internal_hash[:height]
|
|
528
|
+
end
|
|
529
|
+
|
|
530
|
+
# ========================================================================= #
|
|
531
|
+
# === is_on_roebe?
|
|
532
|
+
#
|
|
533
|
+
# This is only useful on my home system.
|
|
534
|
+
# ========================================================================= #
|
|
535
|
+
def is_on_roebe?
|
|
536
|
+
ENV['IS_ROEBE'].to_s == '1'
|
|
537
|
+
end
|
|
538
|
+
|
|
539
|
+
# ========================================================================= #
|
|
540
|
+
# === radio_buttons
|
|
541
|
+
# ========================================================================= #
|
|
542
|
+
def radio_buttons(optional_array = [])
|
|
543
|
+
return ::LibuiParadise.radio_buttons(optional_array)
|
|
544
|
+
end; alias ui_radio_buttons radio_buttons # === ui_radio_buttons
|
|
545
|
+
|
|
546
|
+
# ========================================================================= #
|
|
547
|
+
# === bold_button
|
|
548
|
+
#
|
|
549
|
+
# This currently does not work. We have to wait until upstream libui
|
|
550
|
+
# supports bold font text.
|
|
551
|
+
# ========================================================================= #
|
|
552
|
+
def bold_button(i)
|
|
553
|
+
button(i)
|
|
554
|
+
end
|
|
555
|
+
|
|
556
|
+
# ========================================================================= #
|
|
557
|
+
# === quit_button (quit tag)
|
|
558
|
+
#
|
|
559
|
+
# This method can be used to, by default, implement a quit button
|
|
560
|
+
# that, upon a click-event, will cause the application to exit
|
|
561
|
+
# and close/quit.
|
|
562
|
+
# ========================================================================= #
|
|
563
|
+
def quit_button(
|
|
564
|
+
optional_arguments = {}
|
|
565
|
+
)
|
|
566
|
+
use_this_text = 'Quit'
|
|
567
|
+
if optional_arguments and optional_arguments.is_a?(Hash)
|
|
568
|
+
# ===================================================================== #
|
|
569
|
+
# === :text
|
|
570
|
+
# ===================================================================== #
|
|
571
|
+
if optional_arguments.has_key? :text
|
|
572
|
+
use_this_text = optional_arguments.delete(:text)
|
|
573
|
+
end
|
|
574
|
+
end
|
|
575
|
+
if block_given?
|
|
576
|
+
yielded = yield
|
|
577
|
+
case yielded
|
|
578
|
+
# ===================================================================== #
|
|
579
|
+
# === :with_emoji
|
|
580
|
+
# ===================================================================== #
|
|
581
|
+
when :with_emoji,
|
|
582
|
+
:with_icon
|
|
583
|
+
use_this_text = use_this_text.to_s.dup
|
|
584
|
+
use_this_text << ' 🛑'
|
|
585
|
+
end
|
|
586
|
+
end
|
|
587
|
+
quit_button = button(use_this_text)
|
|
588
|
+
quit_button.on_clicked {
|
|
589
|
+
::LibUI.quit
|
|
590
|
+
0
|
|
591
|
+
}
|
|
592
|
+
return quit_button
|
|
593
|
+
end; alias ui_quit_button quit_button # === ui_quit_button
|
|
594
|
+
|
|
595
|
+
# ========================================================================= #
|
|
596
|
+
# === selected?
|
|
597
|
+
#
|
|
598
|
+
# Unsure whether this works. It appears to work, but I am not even
|
|
599
|
+
# certain as to why.
|
|
600
|
+
# ========================================================================= #
|
|
601
|
+
def selected?(pointer)
|
|
602
|
+
::LibUI.combobox_selected(pointer).to_s
|
|
603
|
+
end
|
|
604
|
+
|
|
605
|
+
# ========================================================================= #
|
|
606
|
+
# === combobox
|
|
607
|
+
#
|
|
608
|
+
# The first argument can be an Array.
|
|
609
|
+
# ========================================================================= #
|
|
610
|
+
def combobox(
|
|
611
|
+
optional_array = nil,
|
|
612
|
+
&block
|
|
613
|
+
)
|
|
614
|
+
return ::LibuiParadise.combobox(optional_array, &block)
|
|
615
|
+
end; alias ui_combo_box combobox # === ui_combo_box
|
|
616
|
+
alias ui_combobox combobox # === ui_combobox
|
|
617
|
+
alias libui_combo_box combobox # === libui_combo_box
|
|
618
|
+
alias combo_box_entry combobox # === combo_box_entry
|
|
619
|
+
alias combo_box combobox # === combo_box
|
|
620
|
+
alias create_combo_box combobox # === create_combo_box
|
|
621
|
+
|
|
622
|
+
# ========================================================================= #
|
|
623
|
+
# === wrapper_new_progress_bar
|
|
624
|
+
# ========================================================================= #
|
|
625
|
+
def wrapper_new_progress_bar
|
|
626
|
+
return ::LibuiParadise.wrapper_new_progress_bar
|
|
627
|
+
end; alias progress_bar wrapper_new_progress_bar # === progress_bar
|
|
628
|
+
|
|
629
|
+
# ========================================================================= #
|
|
630
|
+
# === font
|
|
631
|
+
#
|
|
632
|
+
# Wrapper-method towards LibuiParadise.font().
|
|
633
|
+
# ========================================================================= #
|
|
634
|
+
def font(&block)
|
|
635
|
+
::LibuiParadise.font(&block)
|
|
636
|
+
end; alias ui_font font # === ui_font
|
|
637
|
+
alias font_descriptor font # === font_descriptor
|
|
638
|
+
|
|
639
|
+
# ========================================================================= #
|
|
640
|
+
# === menu (menu tag)
|
|
641
|
+
# ========================================================================= #
|
|
642
|
+
def menu(
|
|
643
|
+
title = ''
|
|
644
|
+
)
|
|
645
|
+
return ::LibuiParadise.menu(title)
|
|
646
|
+
end; alias ui_menu menu # === ui_menu
|
|
647
|
+
|
|
648
|
+
# ========================================================================= #
|
|
649
|
+
# === non_wrapping_multiline_entry
|
|
650
|
+
#
|
|
651
|
+
# Delegate towards LibuiParadise.non_wrapping_multiline_entry() here.
|
|
652
|
+
# ========================================================================= #
|
|
653
|
+
def non_wrapping_multiline_entry
|
|
654
|
+
return ::LibuiParadise.non_wrapping_multiline_entry
|
|
655
|
+
end
|
|
656
|
+
|
|
657
|
+
# ========================================================================= #
|
|
658
|
+
# === table
|
|
659
|
+
# ========================================================================= #
|
|
660
|
+
def table(i)
|
|
661
|
+
::LibuiParadise.table(i)
|
|
662
|
+
end; alias ui_table table # === ui_table
|
|
663
|
+
|
|
664
|
+
# ========================================================================= #
|
|
665
|
+
# === scrolling_area
|
|
666
|
+
#
|
|
667
|
+
# It seems as if scrolling is not yet easily available in libui.
|
|
668
|
+
#
|
|
669
|
+
# The upstream API is like this:
|
|
670
|
+
#
|
|
671
|
+
# uiArea *area = uiNewScrollingArea(&handler, 400, 400);
|
|
672
|
+
#
|
|
673
|
+
# ========================================================================= #
|
|
674
|
+
def scrolling_area(
|
|
675
|
+
optional_widget = nil
|
|
676
|
+
)
|
|
677
|
+
::LibuiParadise.scrolling_area(optional_widget)
|
|
678
|
+
end; alias ui_scrolling_area scrolling_area # === ui_scrolling_area
|
|
679
|
+
alias ui_scrolled_window scrolling_area # === ui_scrolling_window
|
|
680
|
+
|
|
681
|
+
# ========================================================================= #
|
|
682
|
+
# === spinbox
|
|
683
|
+
#
|
|
684
|
+
# This method will return a spin-button, also called a spin-box.
|
|
685
|
+
# ========================================================================= #
|
|
686
|
+
def spinbox(
|
|
687
|
+
start_point = 0,
|
|
688
|
+
end_point = 100
|
|
689
|
+
)
|
|
690
|
+
::LibuiParadise.spinbox(start_point, end_point)
|
|
691
|
+
end; alias ui_spinbox spinbox # === ui_spinbox
|
|
692
|
+
alias ui_spinbutton spinbox # === ui_spinbutton
|
|
693
|
+
alias create_spinbox spinbox # === create_spinbox
|
|
694
|
+
alias up_and_down_counter spinbox # === up_and_down_counter
|
|
695
|
+
alias spinbutton spinbox # === spinbutton
|
|
696
|
+
alias centered_spin_button spinbox # === centered_spin_button
|
|
697
|
+
|
|
698
|
+
# ========================================================================= #
|
|
699
|
+
# === try_to_parse_this_config_file
|
|
700
|
+
#
|
|
701
|
+
# This method can be used to parse a .config file for data it stores.
|
|
702
|
+
#
|
|
703
|
+
# The .config file must have "width:", "height:" and "title:" settings.
|
|
704
|
+
# ========================================================================= #
|
|
705
|
+
def try_to_parse_this_config_file(i)
|
|
706
|
+
if File.exist? i
|
|
707
|
+
dataset = File.readlines(i)
|
|
708
|
+
# ===================================================================== #
|
|
709
|
+
# Next check for width, height and title:
|
|
710
|
+
# ===================================================================== #
|
|
711
|
+
width = dataset.select {|line| line.include? 'width:' }.first.
|
|
712
|
+
split(':').last.strip.to_i
|
|
713
|
+
height = dataset.select {|line| line.include? 'height:' }.first.
|
|
714
|
+
split(':').last.strip.to_i
|
|
715
|
+
title = dataset.select {|line| line.include? 'title:' }.first.
|
|
716
|
+
split(':').last.strip
|
|
717
|
+
window = LibuiParadise.window(title, width, height)
|
|
718
|
+
return window
|
|
719
|
+
else
|
|
720
|
+
e 'No file exists at `'+i+'`.'
|
|
721
|
+
end
|
|
722
|
+
end; alias parse_this_config_file try_to_parse_this_config_file # === parse_this_config_file
|
|
723
|
+
|
|
724
|
+
# ========================================================================= #
|
|
725
|
+
# === set_main_window
|
|
726
|
+
# ========================================================================= #
|
|
727
|
+
def set_main_window(i)
|
|
728
|
+
::LibuiParadise.set_main_window(i)
|
|
729
|
+
return ::LibuiParadise.main_window?
|
|
730
|
+
end
|
|
731
|
+
|
|
732
|
+
# ========================================================================= #
|
|
733
|
+
# === bold_text_left_aligned
|
|
734
|
+
# ========================================================================= #
|
|
735
|
+
def bold_text_left_aligned(i = '')
|
|
736
|
+
return label(i)
|
|
737
|
+
end; alias left_aligned_bold_label bold_text_left_aligned # === left_aligned_bold_label
|
|
738
|
+
|
|
739
|
+
# ========================================================================= #
|
|
740
|
+
# === is_on_windows?
|
|
741
|
+
# ========================================================================= #
|
|
742
|
+
def is_on_windows?
|
|
743
|
+
Gem.win_platform?
|
|
744
|
+
end
|
|
745
|
+
|
|
746
|
+
# ========================================================================= #
|
|
747
|
+
# === checkbox
|
|
748
|
+
#
|
|
749
|
+
# Delegate towards LibuiParadise.checkbox().
|
|
750
|
+
# ========================================================================= #
|
|
751
|
+
def checkbox(
|
|
752
|
+
i = ''
|
|
753
|
+
)
|
|
754
|
+
::LibuiParadise.checkbox(i)
|
|
755
|
+
end; alias ui_checkbox checkbox # === ui_checkbox
|
|
756
|
+
alias ui_check_button checkbox # === ui_check_button
|
|
757
|
+
alias create_checkbox checkbox # === create_checkbox
|
|
758
|
+
alias create_check_box checkbox # === create_check_box
|
|
759
|
+
|
|
760
|
+
# ========================================================================= #
|
|
761
|
+
# === checked_checkbox
|
|
762
|
+
# ========================================================================= #
|
|
763
|
+
def checked_checkbox(i = '')
|
|
764
|
+
_ = checkbox(i)
|
|
765
|
+
_.is_active
|
|
766
|
+
return _
|
|
767
|
+
end
|
|
768
|
+
|
|
769
|
+
# ========================================================================= #
|
|
770
|
+
# === ui_open_file
|
|
771
|
+
#
|
|
772
|
+
# This method can be used as a wrapper towards an "open local file"
|
|
773
|
+
# functionality.
|
|
774
|
+
# ========================================================================= #
|
|
775
|
+
def ui_open_file(
|
|
776
|
+
main_window = ::LibuiParadise.main_window?
|
|
777
|
+
)
|
|
778
|
+
return ::LibuiParadise.open_file(main_window)
|
|
779
|
+
end
|
|
780
|
+
|
|
781
|
+
# ========================================================================= #
|
|
782
|
+
# === fancy_text
|
|
783
|
+
#
|
|
784
|
+
# This text variant can be styled.
|
|
785
|
+
# ========================================================================= #
|
|
786
|
+
def fancy_text(i = '')
|
|
787
|
+
_ = LibUI.new_attributed_string(i.to_s)
|
|
788
|
+
add_to_the_registered_widgets(_, __method__)
|
|
789
|
+
return _
|
|
790
|
+
end; alias attributed_string fancy_text # === attributed_string
|
|
791
|
+
|
|
792
|
+
# ========================================================================= #
|
|
793
|
+
# === bold_label
|
|
794
|
+
#
|
|
795
|
+
# This currently does NOT make the text bold - the method exists solely
|
|
796
|
+
# as a placeholder, until upstream libui supports bold text as such.
|
|
797
|
+
#
|
|
798
|
+
# Actually libui already supports this; I just don't know how to use
|
|
799
|
+
# it.
|
|
800
|
+
# ========================================================================= #
|
|
801
|
+
def bold_label(i = '')
|
|
802
|
+
return label(i)
|
|
803
|
+
end; alias bold_text bold_label # === bold_text
|
|
804
|
+
|
|
805
|
+
# ========================================================================= #
|
|
806
|
+
# === parse_this_file_into_a_table
|
|
807
|
+
#
|
|
808
|
+
# Note that Gtk::Table has been deprecated. Use GtkGrid instead. It
|
|
809
|
+
# provides the same capabilities as GtkTable for arranging widgets
|
|
810
|
+
# in a rectangular grid, but does support height-for-width geometry
|
|
811
|
+
# management.
|
|
812
|
+
#
|
|
813
|
+
# Usage example:
|
|
814
|
+
#
|
|
815
|
+
# parse_into_table '/Depot/j/animals.yml'
|
|
816
|
+
#
|
|
817
|
+
# ========================================================================= #
|
|
818
|
+
def parse_this_file_into_a_table(this_file)
|
|
819
|
+
if this_file and File.exist?(this_file)
|
|
820
|
+
table = create_grid
|
|
821
|
+
table.uniform_spacing(8)
|
|
822
|
+
table.pad8px
|
|
823
|
+
if this_file.end_with?('.yml')
|
|
824
|
+
dataset = YAML.load_file(this_file)
|
|
825
|
+
else
|
|
826
|
+
dataset = File.readlines(this_file)
|
|
827
|
+
end
|
|
828
|
+
if dataset.is_a? Hash
|
|
829
|
+
dataset = dataset.to_a.flatten
|
|
830
|
+
end
|
|
831
|
+
dataset.flatten! if dataset.respond_to?(:flatten!)
|
|
832
|
+
dataset.each_with_index {|entry, index|
|
|
833
|
+
entry = entry.to_s
|
|
834
|
+
case index % 2
|
|
835
|
+
when 0
|
|
836
|
+
table.left(text(entry))
|
|
837
|
+
when 1
|
|
838
|
+
table.right(text(entry))
|
|
839
|
+
end
|
|
840
|
+
}
|
|
841
|
+
return table
|
|
842
|
+
end
|
|
843
|
+
end; alias parse_into_table parse_this_file_into_a_table # === parse_into_table
|
|
844
|
+
|
|
845
|
+
# ========================================================================= #
|
|
846
|
+
# === label
|
|
847
|
+
#
|
|
848
|
+
# The last two aliases, left_aligned_label, should be different, but
|
|
849
|
+
# right now I don't know how to do this in libui.
|
|
850
|
+
# ========================================================================= #
|
|
851
|
+
def label(
|
|
852
|
+
i = ''
|
|
853
|
+
)
|
|
854
|
+
::LibuiParadise.label(i)
|
|
855
|
+
end; alias text label # === text
|
|
856
|
+
alias ui_text label # === ui_text
|
|
857
|
+
alias ui_label label # === ui_label
|
|
858
|
+
alias left_aligned_label label # === left_aligned_label
|
|
859
|
+
alias left_aligned_text label # === left_aligned_text
|
|
860
|
+
|
|
861
|
+
# ========================================================================= #
|
|
862
|
+
# === left_arrow?
|
|
863
|
+
#
|
|
864
|
+
# This is simply a unicode left arrow, a text (label) widget.
|
|
865
|
+
# ========================================================================= #
|
|
866
|
+
def left_arrow?
|
|
867
|
+
text('→')
|
|
868
|
+
end
|
|
869
|
+
|
|
870
|
+
# ========================================================================= #
|
|
871
|
+
# === main_then_quit
|
|
872
|
+
# ========================================================================= #
|
|
873
|
+
def main_then_quit
|
|
874
|
+
::LibUI.main
|
|
875
|
+
do_quit
|
|
876
|
+
end
|
|
877
|
+
|
|
878
|
+
# ========================================================================= #
|
|
879
|
+
# === do_quit
|
|
880
|
+
# ========================================================================= #
|
|
881
|
+
def do_quit
|
|
882
|
+
::LibUI.quit
|
|
883
|
+
end
|
|
884
|
+
|
|
885
|
+
# ========================================================================= #
|
|
886
|
+
# === copy
|
|
887
|
+
# ========================================================================= #
|
|
888
|
+
def copy(from, to)
|
|
889
|
+
require 'fileutils'
|
|
890
|
+
FileUtils.cp(from, to)
|
|
891
|
+
end
|
|
892
|
+
|
|
893
|
+
# ========================================================================= #
|
|
894
|
+
# === exit_from
|
|
895
|
+
#
|
|
896
|
+
# This method essentially combines UI.control_destroy() and UI.quit(
|
|
897
|
+
# into one method.
|
|
898
|
+
# ========================================================================= #
|
|
899
|
+
def exit_from(
|
|
900
|
+
main_window = main_window?
|
|
901
|
+
)
|
|
902
|
+
LibUI.control_destroy(main_window)
|
|
903
|
+
LibUI.quit
|
|
904
|
+
0
|
|
905
|
+
end
|
|
906
|
+
|
|
907
|
+
# ========================================================================= #
|
|
908
|
+
# === use_gtk?
|
|
909
|
+
# ========================================================================= #
|
|
910
|
+
def use_gtk?
|
|
911
|
+
false
|
|
912
|
+
end; alias uses_gtk4? use_gtk? # === uses_gtk4?
|
|
913
|
+
|
|
914
|
+
# ========================================================================= #
|
|
915
|
+
# === use_libui?
|
|
916
|
+
# ========================================================================= #
|
|
917
|
+
def use_libui?
|
|
918
|
+
true
|
|
919
|
+
end
|
|
920
|
+
|
|
921
|
+
# ========================================================================= #
|
|
922
|
+
# === return_pwd
|
|
923
|
+
# ========================================================================= #
|
|
924
|
+
def return_pwd
|
|
925
|
+
"#{Dir.pwd}/".squeeze('/')
|
|
926
|
+
end
|
|
927
|
+
|
|
928
|
+
# ========================================================================= #
|
|
929
|
+
# === try_to_use_this_font
|
|
930
|
+
#
|
|
931
|
+
# This is currently not in use - once libui supports setting
|
|
932
|
+
# a font then this can be enabled.
|
|
933
|
+
#
|
|
934
|
+
# Actually this should in theory already work as-is - I just don't
|
|
935
|
+
# understand the toplevel API to be used here.
|
|
936
|
+
# ========================================================================= #
|
|
937
|
+
def try_to_use_this_font(i = nil); end
|
|
938
|
+
alias use_this_font= try_to_use_this_font # === use_this_font=
|
|
939
|
+
alias set_use_this_font try_to_use_this_font # === set_use_this_font
|
|
940
|
+
|
|
941
|
+
# ========================================================================= #
|
|
942
|
+
# === use_gtk3?
|
|
943
|
+
# ========================================================================= #
|
|
944
|
+
def use_gtk3?
|
|
945
|
+
Object.const_defined?(:Gtk)
|
|
946
|
+
end
|
|
947
|
+
|
|
948
|
+
# ========================================================================= #
|
|
949
|
+
# === gtk3?
|
|
950
|
+
# ========================================================================= #
|
|
951
|
+
def gtk3?
|
|
952
|
+
false
|
|
953
|
+
end; alias is_on_gtk? gtk3? # === is_on_gtk?
|
|
954
|
+
alias uses_gtk3? gtk3? # === uses_gtk3?
|
|
955
|
+
|
|
956
|
+
# ========================================================================= #
|
|
957
|
+
# === append_this_array_to_that_combobox
|
|
958
|
+
# ========================================================================= #
|
|
959
|
+
def append_this_array_to_that_combobox(
|
|
960
|
+
this_array,
|
|
961
|
+
that_combobox
|
|
962
|
+
)
|
|
963
|
+
this_array.each {|this_entry|
|
|
964
|
+
::LibUI.combobox_append(that_combobox, this_entry)
|
|
965
|
+
}
|
|
966
|
+
end
|
|
967
|
+
|
|
968
|
+
# ========================================================================= #
|
|
969
|
+
# === new_brush
|
|
970
|
+
# ========================================================================= #
|
|
971
|
+
def new_brush
|
|
972
|
+
::LibUI::FFI::DrawBrush.malloc
|
|
973
|
+
end
|
|
974
|
+
|
|
975
|
+
# ========================================================================= #
|
|
976
|
+
# === ui_draw_text_layout_params
|
|
977
|
+
# ========================================================================= #
|
|
978
|
+
def ui_draw_text_layout_params
|
|
979
|
+
::LibUI::FFI::DrawTextLayoutParams.malloc
|
|
980
|
+
end
|
|
981
|
+
|
|
982
|
+
# ========================================================================= #
|
|
983
|
+
# === slider (slider tag)
|
|
984
|
+
# ========================================================================= #
|
|
985
|
+
def slider(
|
|
986
|
+
start_value = 0,
|
|
987
|
+
end_value = 100
|
|
988
|
+
)
|
|
989
|
+
return ::LibuiParadise.slider(start_value, end_value)
|
|
990
|
+
end; alias ui_slider slider # === ui_slider
|
|
991
|
+
alias create_slider slider # === create_slider
|
|
992
|
+
|
|
993
|
+
# ========================================================================= #
|
|
994
|
+
# === ui_table_params_malloc
|
|
995
|
+
#
|
|
996
|
+
# This will basically wrap over LibUI::FFI::TableParams.malloc().
|
|
997
|
+
# ========================================================================= #
|
|
998
|
+
def ui_table_params_malloc(
|
|
999
|
+
optional_model = nil
|
|
1000
|
+
)
|
|
1001
|
+
_ = ::LibUI::FFI::TableParams.malloc
|
|
1002
|
+
if optional_model
|
|
1003
|
+
_.to_ptr.free = Fiddle::RUBY_FREE
|
|
1004
|
+
_.Model = optional_model
|
|
1005
|
+
_.RowBackgroundColorModelColumn = -1
|
|
1006
|
+
end
|
|
1007
|
+
return _
|
|
1008
|
+
end
|
|
1009
|
+
|
|
1010
|
+
# ========================================================================= #
|
|
1011
|
+
# === ui_font_descriptor
|
|
1012
|
+
#
|
|
1013
|
+
# This method will return a new font-descriptor pointer.
|
|
1014
|
+
#
|
|
1015
|
+
# Usage example:
|
|
1016
|
+
#
|
|
1017
|
+
# ui_font_descriptor('Hack')
|
|
1018
|
+
#
|
|
1019
|
+
# ========================================================================= #
|
|
1020
|
+
def ui_font_descriptor(
|
|
1021
|
+
use_this_font_family = 'Hack',
|
|
1022
|
+
use_this_size = 25,
|
|
1023
|
+
use_this_weight = 500,
|
|
1024
|
+
is_in_italic_font_variant = :no,
|
|
1025
|
+
stretch_factor = 4
|
|
1026
|
+
)
|
|
1027
|
+
case is_in_italic_font_variant
|
|
1028
|
+
when :yes
|
|
1029
|
+
is_in_italic_font_variant = 1 # true
|
|
1030
|
+
when :no
|
|
1031
|
+
is_in_italic_font_variant = 0 # false
|
|
1032
|
+
end
|
|
1033
|
+
font_descriptor = UI::FFI::FontDescriptor.malloc
|
|
1034
|
+
font_descriptor.to_ptr.free = Fiddle::RUBY_FREE
|
|
1035
|
+
font_descriptor.Family = use_this_font_family
|
|
1036
|
+
font_descriptor.Size = use_this_size
|
|
1037
|
+
font_descriptor.Weight = use_this_weight
|
|
1038
|
+
font_descriptor.Italic = is_in_italic_font_variant
|
|
1039
|
+
font_descriptor.Stretch = stretch_factor
|
|
1040
|
+
return font_descriptor
|
|
1041
|
+
end; alias font_descriptor ui_font_descriptor # === font_descriptor
|
|
1042
|
+
|
|
1043
|
+
# ========================================================================= #
|
|
1044
|
+
# === current_widget_pointer_type?
|
|
1045
|
+
# ========================================================================= #
|
|
1046
|
+
def current_widget_pointer_type?
|
|
1047
|
+
LibuiParadise.hash_fiddle_pointer_widgets?.values.last.last
|
|
1048
|
+
end
|
|
1049
|
+
|
|
1050
|
+
# ========================================================================= #
|
|
1051
|
+
# === esystem
|
|
1052
|
+
#
|
|
1053
|
+
# This method can be used to run system(), with output. Thread.new is
|
|
1054
|
+
# used because that seems to work better in a GUI setup.
|
|
1055
|
+
# ========================================================================= #
|
|
1056
|
+
def esystem(i)
|
|
1057
|
+
e i
|
|
1058
|
+
Thread.new { system i }
|
|
1059
|
+
end
|
|
1060
|
+
|
|
1061
|
+
# ========================================================================= #
|
|
1062
|
+
# === create_directory
|
|
1063
|
+
# ========================================================================= #
|
|
1064
|
+
def create_directory(i)
|
|
1065
|
+
FileUtils.mkdir_p(i)
|
|
1066
|
+
end; alias mkdir create_directory # === mkdir
|
|
1067
|
+
|
|
1068
|
+
# ========================================================================= #
|
|
1069
|
+
# === abort_on_exception
|
|
1070
|
+
# ========================================================================= #
|
|
1071
|
+
def abort_on_exception
|
|
1072
|
+
Thread.abort_on_exception
|
|
1073
|
+
end
|
|
1074
|
+
|
|
1075
|
+
# ========================================================================= #
|
|
1076
|
+
# === chdir (cd tag, chdir tag)
|
|
1077
|
+
# ========================================================================= #
|
|
1078
|
+
def chdir(i)
|
|
1079
|
+
if i and File.directory?(i)
|
|
1080
|
+
Dir.chdir(i)
|
|
1081
|
+
end
|
|
1082
|
+
end; alias cd chdir # === cd
|
|
1083
|
+
|
|
1084
|
+
# ========================================================================= #
|
|
1085
|
+
# === create_skeleton_then_connect_skeleton
|
|
1086
|
+
# ========================================================================= #
|
|
1087
|
+
def create_skeleton_then_connect_skeleton
|
|
1088
|
+
create_skeleton
|
|
1089
|
+
connect_skeleton
|
|
1090
|
+
end
|
|
1091
|
+
|
|
1092
|
+
# ========================================================================= #
|
|
1093
|
+
# === connect_skeleton
|
|
1094
|
+
#
|
|
1095
|
+
# This is a stub method, because we want to allow the user to modify it.
|
|
1096
|
+
# ========================================================================= #
|
|
1097
|
+
def connect_skeleton
|
|
1098
|
+
end
|
|
1099
|
+
|
|
1100
|
+
# ========================================================================= #
|
|
1101
|
+
# === title_width_height_font
|
|
1102
|
+
#
|
|
1103
|
+
# The font-argument is presently not handled. Perhaps one day in the
|
|
1104
|
+
# future.
|
|
1105
|
+
# ========================================================================= #
|
|
1106
|
+
def title_width_height_font(
|
|
1107
|
+
title = '',
|
|
1108
|
+
width = WIDTH,
|
|
1109
|
+
height = 800,
|
|
1110
|
+
font = :currently_not_handled
|
|
1111
|
+
)
|
|
1112
|
+
title_width_height(title, width, height)
|
|
1113
|
+
end
|
|
1114
|
+
|
|
1115
|
+
# ========================================================================= #
|
|
1116
|
+
# === title_width_height
|
|
1117
|
+
# ========================================================================= #
|
|
1118
|
+
def title_width_height(
|
|
1119
|
+
title,
|
|
1120
|
+
width = WIDTH,
|
|
1121
|
+
height = 800
|
|
1122
|
+
)
|
|
1123
|
+
set_title(title)
|
|
1124
|
+
set_width(width)
|
|
1125
|
+
set_height(height)
|
|
1126
|
+
end; alias set_title_width_height title_width_height # === title_width_height
|
|
1127
|
+
|
|
1128
|
+
# ========================================================================= #
|
|
1129
|
+
# === font_button
|
|
1130
|
+
#
|
|
1131
|
+
# Create a new font button via this method.
|
|
1132
|
+
# ========================================================================= #
|
|
1133
|
+
def font_button
|
|
1134
|
+
return ::LibuiParadise.font_button
|
|
1135
|
+
end; alias ui_font_button font_button # === ui_font_button
|
|
1136
|
+
|
|
1137
|
+
# ========================================================================= #
|
|
1138
|
+
# === image (image tag)
|
|
1139
|
+
#
|
|
1140
|
+
# This is currently limited to .png files only, due to ChunkyPNG.
|
|
1141
|
+
#
|
|
1142
|
+
# At some later point in the future this limitation may be lifted. For
|
|
1143
|
+
# now it has to remain in place.
|
|
1144
|
+
# ========================================================================= #
|
|
1145
|
+
def image(
|
|
1146
|
+
this_file,
|
|
1147
|
+
width = :try_to_infer_automatically,
|
|
1148
|
+
height = :infer_automatically
|
|
1149
|
+
)
|
|
1150
|
+
Libuiparadise.image(
|
|
1151
|
+
this_file,
|
|
1152
|
+
width,
|
|
1153
|
+
height
|
|
1154
|
+
)
|
|
1155
|
+
end; alias ui_image image # === ui_image
|
|
1156
|
+
|
|
1157
|
+
# ========================================================================= #
|
|
1158
|
+
# === run
|
|
1159
|
+
# ========================================================================= #
|
|
1160
|
+
def run
|
|
1161
|
+
create_skeleton_then_connect_skeleton
|
|
1162
|
+
end
|
|
1163
|
+
|
|
1164
|
+
# ========================================================================= #
|
|
1165
|
+
# === create_the_skeleton
|
|
1166
|
+
# ========================================================================= #
|
|
1167
|
+
def create_the_skeleton
|
|
1168
|
+
end; alias create_skeleton create_the_skeleton # === create_skeleton
|
|
1169
|
+
|
|
1170
|
+
# ========================================================================= #
|
|
1171
|
+
# === run_main
|
|
1172
|
+
# ========================================================================= #
|
|
1173
|
+
def run_main
|
|
1174
|
+
end
|
|
1175
|
+
|
|
1176
|
+
# ========================================================================= #
|
|
1177
|
+
# === set_commandline_arguments
|
|
1178
|
+
# ========================================================================= #
|
|
1179
|
+
def set_commandline_arguments(i = ARGV)
|
|
1180
|
+
@commandline_arguments = [i].flatten.compact
|
|
1181
|
+
end
|
|
1182
|
+
|
|
1183
|
+
# ========================================================================= #
|
|
1184
|
+
# === commandline_arguments?
|
|
1185
|
+
# ========================================================================= #
|
|
1186
|
+
def commandline_arguments?
|
|
1187
|
+
@commandline_arguments
|
|
1188
|
+
end
|
|
1189
|
+
|
|
1190
|
+
# ========================================================================= #
|
|
1191
|
+
# === set_height
|
|
1192
|
+
# ========================================================================= #
|
|
1193
|
+
def set_height(
|
|
1194
|
+
i = 800
|
|
1195
|
+
)
|
|
1196
|
+
case i
|
|
1197
|
+
# ======================================================================= #
|
|
1198
|
+
# === :max_width
|
|
1199
|
+
# ======================================================================= #
|
|
1200
|
+
when :max_height
|
|
1201
|
+
i = assumed_max_height?
|
|
1202
|
+
end
|
|
1203
|
+
if i.is_a?(String) and i.include?('%')
|
|
1204
|
+
# ===================================================================== #
|
|
1205
|
+
# In this case we have to modify this a bit.
|
|
1206
|
+
# ===================================================================== #
|
|
1207
|
+
max_height = assumed_max_height?
|
|
1208
|
+
i = (max_height.to_f * i.to_i) / 100.0
|
|
1209
|
+
end
|
|
1210
|
+
i = i.to_i
|
|
1211
|
+
@internal_hash[:height] = i
|
|
1212
|
+
end
|
|
1213
|
+
|
|
1214
|
+
# ========================================================================= #
|
|
1215
|
+
# === copy_file
|
|
1216
|
+
# ========================================================================= #
|
|
1217
|
+
def copy_file(from, to)
|
|
1218
|
+
FileUtils.cp(from, to)
|
|
1219
|
+
end; alias cp_file copy_file # === cp_file
|
|
1220
|
+
|
|
1221
|
+
# ========================================================================= #
|
|
1222
|
+
# === assumed_height?
|
|
1223
|
+
# ========================================================================= #
|
|
1224
|
+
def assumed_height?
|
|
1225
|
+
return_the_resolution_using_xrandr.split('x').last.to_i
|
|
1226
|
+
end; alias assumed_max_height? assumed_height? # === assumed_max_height?
|
|
1227
|
+
|
|
1228
|
+
# ========================================================================= #
|
|
1229
|
+
# === without_trailing_comment
|
|
1230
|
+
# ========================================================================= #
|
|
1231
|
+
def without_trailing_comment(i)
|
|
1232
|
+
i = i.dup
|
|
1233
|
+
if i and i.end_with?('#')
|
|
1234
|
+
i = i[0 .. -2]
|
|
1235
|
+
end
|
|
1236
|
+
return i
|
|
1237
|
+
end
|
|
1238
|
+
|
|
1239
|
+
# ========================================================================= #
|
|
1240
|
+
# === assumed_width?
|
|
1241
|
+
# ========================================================================= #
|
|
1242
|
+
def assumed_width?
|
|
1243
|
+
return_the_resolution_using_xrandr.split('x').first.to_i
|
|
1244
|
+
end; alias assumed_max_width? assumed_width? # === assumed_max_width?
|
|
1245
|
+
|
|
1246
|
+
# ========================================================================= #
|
|
1247
|
+
# === set_width
|
|
1248
|
+
# ========================================================================= #
|
|
1249
|
+
def set_width(
|
|
1250
|
+
i = 1024
|
|
1251
|
+
)
|
|
1252
|
+
case i
|
|
1253
|
+
# ======================================================================= #
|
|
1254
|
+
# === :max_width
|
|
1255
|
+
# ======================================================================= #
|
|
1256
|
+
when :max_width
|
|
1257
|
+
i = assumed_max_width?
|
|
1258
|
+
end
|
|
1259
|
+
if i.is_a?(String) and i.include?('%')
|
|
1260
|
+
# ===================================================================== #
|
|
1261
|
+
# In this case we have to modify this a bit.
|
|
1262
|
+
# ===================================================================== #
|
|
1263
|
+
max_width = assumed_max_width?
|
|
1264
|
+
i = (max_width.to_f * i.to_i) / 100.0
|
|
1265
|
+
end
|
|
1266
|
+
i = i.to_i
|
|
1267
|
+
@internal_hash[:width] = i
|
|
1268
|
+
end
|
|
1269
|
+
|
|
1270
|
+
# ========================================================================= #
|
|
1271
|
+
# === width?
|
|
1272
|
+
# ========================================================================= #
|
|
1273
|
+
def width?
|
|
1274
|
+
@internal_hash[:width]
|
|
1275
|
+
end
|
|
1276
|
+
|
|
1277
|
+
# ========================================================================= #
|
|
1278
|
+
# === delete_file
|
|
1279
|
+
#
|
|
1280
|
+
# This method can be used if you want to quickly delete a (local) file.
|
|
1281
|
+
# ========================================================================= #
|
|
1282
|
+
def delete_file(i)
|
|
1283
|
+
if i and File.file?(i)
|
|
1284
|
+
File.delete(i)
|
|
1285
|
+
else
|
|
1286
|
+
e "Not a file: #{i}"
|
|
1287
|
+
end
|
|
1288
|
+
end
|
|
1289
|
+
|
|
1290
|
+
# ========================================================================= #
|
|
1291
|
+
# === colour_to_rgb
|
|
1292
|
+
# ========================================================================= #
|
|
1293
|
+
def colour_to_rgb(
|
|
1294
|
+
colour = :steelblue
|
|
1295
|
+
)
|
|
1296
|
+
array = Colours.colour_to_rgb(colour)
|
|
1297
|
+
return array
|
|
1298
|
+
end
|
|
1299
|
+
|
|
1300
|
+
# ========================================================================= #
|
|
1301
|
+
# === last_pointer?
|
|
1302
|
+
#
|
|
1303
|
+
# This used to return the "current" widget pointer, but past September
|
|
1304
|
+
# 2021 this is rarely in use anymore. Use current_widget_pointer?
|
|
1305
|
+
# instead, based on the main Hash that keeps all widgets registered.
|
|
1306
|
+
# ========================================================================= #
|
|
1307
|
+
def last_pointer?
|
|
1308
|
+
LibuiParadise.current_widget_pointer?
|
|
1309
|
+
end; alias current_pointer? last_pointer? # === current_pointer?
|
|
1310
|
+
alias current_widget_pointer? last_pointer? # === current_widget_pointer?
|
|
1311
|
+
|
|
1312
|
+
# ========================================================================= #
|
|
1313
|
+
# === ui_sync_connect
|
|
1314
|
+
#
|
|
1315
|
+
# This method can connect two widgets: the first one should be a
|
|
1316
|
+
# combo-box, and the second one a ui-entry.
|
|
1317
|
+
# ========================================================================= #
|
|
1318
|
+
def ui_sync_connect(
|
|
1319
|
+
widget1,
|
|
1320
|
+
widget2,
|
|
1321
|
+
optional_array = nil
|
|
1322
|
+
)
|
|
1323
|
+
combobox_selected_callback = proc { |pointer|
|
|
1324
|
+
selected_value = selected?(pointer)
|
|
1325
|
+
if optional_array and optional_array.is_a?(Array)
|
|
1326
|
+
selected_value = optional_array[selected_value.to_i]
|
|
1327
|
+
end
|
|
1328
|
+
widget2.set_text(
|
|
1329
|
+
selected_value
|
|
1330
|
+
)
|
|
1331
|
+
}
|
|
1332
|
+
::LibUI.combobox_on_selected(
|
|
1333
|
+
widget1, combobox_selected_callback, nil
|
|
1334
|
+
)
|
|
1335
|
+
end; alias sync_connect ui_sync_connect # === sync_connect
|
|
1336
|
+
|
|
1337
|
+
# ========================================================================= #
|
|
1338
|
+
# === main_hash?
|
|
1339
|
+
#
|
|
1340
|
+
# Access the main hash defined above.
|
|
1341
|
+
# ========================================================================= #
|
|
1342
|
+
def main_hash?
|
|
1343
|
+
::LibuiParadise.hash_fiddle_pointer_widgets?
|
|
1344
|
+
end; alias toplevel_hash? main_hash? # === toplevel_hash?
|
|
1345
|
+
|
|
1346
|
+
# ======================================================================= #
|
|
1347
|
+
# === return_default_window
|
|
1348
|
+
# ======================================================================= #
|
|
1349
|
+
def return_default_window(
|
|
1350
|
+
title = title?,
|
|
1351
|
+
width = width?,
|
|
1352
|
+
height = height?
|
|
1353
|
+
)
|
|
1354
|
+
return padded_main_window(title, width, height, 0)
|
|
1355
|
+
end
|
|
1356
|
+
|
|
1357
|
+
# ========================================================================= #
|
|
1358
|
+
# === set_window
|
|
1359
|
+
#
|
|
1360
|
+
# Simply assign to @window here.
|
|
1361
|
+
# ========================================================================= #
|
|
1362
|
+
def set_window(i = return_default_window)
|
|
1363
|
+
::LibuiParadise.set_window(i)
|
|
1364
|
+
end
|
|
1365
|
+
|
|
1366
|
+
# ========================================================================= #
|
|
1367
|
+
# === close_properly
|
|
1368
|
+
# ========================================================================= #
|
|
1369
|
+
def close_properly(
|
|
1370
|
+
main_window = LibuiParadise.main_window?
|
|
1371
|
+
)
|
|
1372
|
+
LibUI.window_on_closing(main_window) {
|
|
1373
|
+
LibUI.exit_from(main_window)
|
|
1374
|
+
}
|
|
1375
|
+
end; alias simple_exit close_properly # === simple_exit
|
|
1376
|
+
|
|
1377
|
+
# ========================================================================= #
|
|
1378
|
+
# === return_button_for_opening_a_local_file
|
|
1379
|
+
#
|
|
1380
|
+
# This method will return a button, which can be used for opening a
|
|
1381
|
+
# local file.
|
|
1382
|
+
#
|
|
1383
|
+
# It is recommended to passs a libui-widget into this method, so that
|
|
1384
|
+
# the "open-file" functionality can have a callback. Usually that
|
|
1385
|
+
# callback should be a libui-entry, so that we can fill it with
|
|
1386
|
+
# the file path that we chose.
|
|
1387
|
+
# ========================================================================= #
|
|
1388
|
+
def return_button_for_opening_a_local_file(
|
|
1389
|
+
connect_this_button_with_that_widget = nil
|
|
1390
|
+
)
|
|
1391
|
+
button_open_file = create_button('Open file')
|
|
1392
|
+
button_open_file.on_clicked {
|
|
1393
|
+
begin
|
|
1394
|
+
# filename = ui_open_file(window).to_s
|
|
1395
|
+
filename = LibUI.open_file(main_window).to_s
|
|
1396
|
+
# e "The filename was: #{filename}" # This line is for debugging.
|
|
1397
|
+
if connect_this_button_with_that_widget # This widget is usually an entry.
|
|
1398
|
+
filename = File.absolute_path(filename) # We need the full path here.
|
|
1399
|
+
connect_this_button_with_that_widget.set_text(filename) if connect_this_button_with_that_widget.respond_to?(:set_text)
|
|
1400
|
+
end
|
|
1401
|
+
rescue ArgumentError => error # Rescue from "NULL pointer given"
|
|
1402
|
+
pp error
|
|
1403
|
+
end
|
|
1404
|
+
}
|
|
1405
|
+
return button_open_file # Always return that button here.
|
|
1406
|
+
end; alias return_the_default_open_file_button return_button_for_opening_a_local_file # === return_the_default_open_file_button
|
|
1407
|
+
|
|
1408
|
+
::LibuiParadise.initializer # Make LibUI known here.
|
|
1409
|
+
|
|
1410
|
+
# ========================================================================= #
|
|
1411
|
+
# === open_file
|
|
1412
|
+
#
|
|
1413
|
+
# This here creates a problem, because ::Libui.open_file is already
|
|
1414
|
+
# defined. We'd have to use an alias to make this work.
|
|
1415
|
+
# ========================================================================= #
|
|
1416
|
+
# def open_file(
|
|
1417
|
+
# main_window = LibuiParadise::Extensions.main_window?
|
|
1418
|
+
# )
|
|
1419
|
+
# return ::LibuiParadise::Extensions.open_file(main_window)
|
|
1420
|
+
# end; alias ui_open_file open_file # === ui_open_file
|
|
1421
|
+
|
|
1422
|
+
# ========================================================================= #
|
|
1423
|
+
# === error_msg
|
|
1424
|
+
# ========================================================================= #
|
|
1425
|
+
def error_msg(text)
|
|
1426
|
+
message_box_error(:default, text)
|
|
1427
|
+
end
|
|
1428
|
+
|
|
1429
|
+
# ========================================================================= #
|
|
1430
|
+
# === message_box_error
|
|
1431
|
+
#
|
|
1432
|
+
# This is specifically for displaying an error-message to the user.
|
|
1433
|
+
# ========================================================================= #
|
|
1434
|
+
def message_box_error(
|
|
1435
|
+
main_window = main_window?,
|
|
1436
|
+
title_to_use = '',
|
|
1437
|
+
whatever = ''
|
|
1438
|
+
)
|
|
1439
|
+
return ::LibuiParadise.message_box_error(
|
|
1440
|
+
main_window,
|
|
1441
|
+
title_to_use,
|
|
1442
|
+
whatever
|
|
1443
|
+
)
|
|
1444
|
+
end; alias ui_msg_box_error message_box_error # === ui_msg_box_error
|
|
1445
|
+
alias ui_error_message message_box_error # === ui_error_message
|
|
1446
|
+
alias ui_error_msg message_box_error # === ui_error_msg
|
|
1447
|
+
alias error_message_to_the_user message_box_error # === error_message_to_the_user
|
|
1448
|
+
|
|
1449
|
+
# ========================================================================= #
|
|
1450
|
+
# === ui_msg_box
|
|
1451
|
+
#
|
|
1452
|
+
# This method is a convenience-wrapper over UI.msg_box().
|
|
1453
|
+
# ========================================================================= #
|
|
1454
|
+
def ui_msg_box(
|
|
1455
|
+
main_window = :default_window,
|
|
1456
|
+
title_to_use = '',
|
|
1457
|
+
description_to_use = nil # This could be a widget, but for now it is not in use.
|
|
1458
|
+
)
|
|
1459
|
+
::LibuiParadise.msg_box(
|
|
1460
|
+
main_window,
|
|
1461
|
+
title_to_use,
|
|
1462
|
+
description_to_use
|
|
1463
|
+
)
|
|
1464
|
+
end; alias message_to_the_user ui_msg_box # === message_to_the_user
|
|
1465
|
+
alias message_box ui_msg_box # === message_box
|
|
1466
|
+
alias popup_over_this_widget ui_msg_box # === popup_over_this_widget
|
|
1467
|
+
alias popup_message ui_msg_box # === popup_message
|
|
1468
|
+
alias create_message_box ui_msg_box # === create_message_box
|
|
1469
|
+
# alias msg_box ui_msg_box # === msg_box
|
|
1470
|
+
# ^^^ this would lead to an error.
|
|
1471
|
+
|
|
1472
|
+
# ========================================================================= #
|
|
1473
|
+
# === popover_message
|
|
1474
|
+
# ========================================================================= #
|
|
1475
|
+
def popover_message(
|
|
1476
|
+
title_to_use,
|
|
1477
|
+
description_to_use
|
|
1478
|
+
)
|
|
1479
|
+
create_message_box(
|
|
1480
|
+
:default_window,
|
|
1481
|
+
title_to_use,
|
|
1482
|
+
description_to_use
|
|
1483
|
+
)
|
|
1484
|
+
end
|
|
1485
|
+
|
|
1486
|
+
end
|
|
1487
|
+
|
|
1488
|
+
# =========================================================================== #
|
|
1489
|
+
# === LibuiParadise.extended
|
|
1490
|
+
#
|
|
1491
|
+
# This method taps into the extended-hook - see the code in the method
|
|
1492
|
+
# shown above this method.
|
|
1493
|
+
#
|
|
1494
|
+
# The purpose of this hook is to automatically call .init on LibUI. This
|
|
1495
|
+
# saves us one line of code.
|
|
1496
|
+
#
|
|
1497
|
+
# In regular LibUI code this is equal to:
|
|
1498
|
+
#
|
|
1499
|
+
# LibUI.init
|
|
1500
|
+
#
|
|
1501
|
+
# =========================================================================== #
|
|
1502
|
+
def self.extended(i)
|
|
1503
|
+
if i.respond_to? :init
|
|
1504
|
+
i.init
|
|
1505
|
+
else
|
|
1506
|
+
::LibUI.init
|
|
1507
|
+
end
|
|
1508
|
+
end
|
|
1509
|
+
|
|
1510
|
+
end
|
|
1511
|
+
|
|
1512
|
+
if __FILE__ == $PROGRAM_NAME
|
|
1513
|
+
include LibuiParadise::BaseModule
|
|
1514
|
+
end # base_module
|