mittens_ui 0.0.1 → 0.0.2
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/Gemfile.lock +2 -2
- data/README.md +28 -26
- data/examples/app.rb +20 -18
- data/lib/mittens_ui.rb +97 -51
- data/lib/mittens_ui/layouts/box.rb +29 -27
- data/lib/mittens_ui/layouts/grid.rb +21 -18
- data/lib/mittens_ui/version.rb +1 -1
- data/lib/mittens_ui/widgets/alert.rb +22 -21
- data/lib/mittens_ui/widgets/button.rb +27 -22
- data/lib/mittens_ui/widgets/label.rb +30 -15
- data/lib/mittens_ui/widgets/listbox.rb +48 -0
- data/lib/mittens_ui/widgets/slider.rb +28 -0
- data/lib/mittens_ui/widgets/textbox.rb +21 -18
- data/notes/gtk.txt +3 -0
- metadata +9 -8
- data/lib/mittens_ui/dsl_parser.rb +0 -17
- data/lib/mittens_ui/layouts/stack.rb +0 -21
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 76c72facca9e7aa37399945d8f44467ac96a1471c4abeeb76f45965ad3aeccc0
|
|
4
|
+
data.tar.gz: 7b29e79fe7aa038d8bb12e5299bcb6f07bf30cb3c866e7d034b4e842a7184ac7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c94f656a8bd97f7a3eb497d3fd5b1a1d430972c477216fbbd2a99ca2ec7f194beda429951f3d29eb89b5bcdba29bfa8249500250fe726bfe008fc0dd523b1619
|
|
7
|
+
data.tar.gz: 5327faf9eb9c9ddaded5e40af6e4774484ee19d894b31d6423df66a7d2b1565a57e967d8f9fde7b109ad92aa5d685fe7696d070ffeff9266fbf48ff6dc37f196
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# MittensUi
|
|
2
2
|
|
|
3
|
-
This is a small GUI toolkit inspired by Ruby Shoes and built on top of the GTK Ruby
|
|
4
|
-
around GTK
|
|
3
|
+
This is a small vertical stacking GUI toolkit inspired by Ruby Shoes and built on top of the GTK Ruby library. This isn't meant to be a full wrapper
|
|
4
|
+
around GTK. The goal of this project is make creating GUIs in Ruby dead simple
|
|
5
5
|
without the UI framework/library getting your way.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
@@ -26,32 +26,34 @@ Or install it yourself as:
|
|
|
26
26
|
require "mittens_ui"
|
|
27
27
|
|
|
28
28
|
app_options = {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
name: "say_hello",
|
|
30
|
+
title: "Say Hello!",
|
|
31
|
+
height: 450,
|
|
32
|
+
width: 350,
|
|
33
|
+
can_resize: true
|
|
33
34
|
}.freeze
|
|
34
35
|
|
|
35
|
-
MittensUi::Application.Window(app_options) do |window|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
36
|
+
MittensUi::Application.Window(app_options) do |window, layout|
|
|
37
|
+
label_opts = { top: 30 }
|
|
38
|
+
MittensUi::Label("Enter Name:", layout, label_opts)
|
|
39
|
+
|
|
40
|
+
textbox_options = { can_edit: true }
|
|
41
|
+
text_box = MittensUi::Textbox(layout, textbox_options)
|
|
42
|
+
|
|
43
|
+
listbox_options = {
|
|
44
|
+
top: 10,
|
|
45
|
+
items: ["item_1", "item_2", "item_3"]
|
|
46
|
+
}.freeze
|
|
47
|
+
listbox = MittensUi::ListBox(layout, listbox_options)
|
|
48
|
+
|
|
49
|
+
btn1_options = { title: "Click Here" }
|
|
50
|
+
MittensUi::Button(layout, btn1_options) do
|
|
51
|
+
MittensUi::Alert(window, "Hello #{text_box.text}!")
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
slider_opts = { start_value: 1, stop_value: 100 }
|
|
55
|
+
MittensUi::Slider(layout, slider_opts) do |s|
|
|
56
|
+
puts "value changed: #{s.value}"
|
|
55
57
|
end
|
|
56
58
|
end
|
|
57
59
|
```
|
data/examples/app.rb
CHANGED
|
@@ -1,31 +1,33 @@
|
|
|
1
1
|
require '../lib/mittens_ui'
|
|
2
2
|
|
|
3
3
|
app_options = {
|
|
4
|
+
name: "say_hello",
|
|
4
5
|
title: "Say Hello!",
|
|
5
|
-
height:
|
|
6
|
+
height: 450,
|
|
6
7
|
width: 350,
|
|
7
8
|
can_resize: true
|
|
8
9
|
}.freeze
|
|
9
10
|
|
|
10
|
-
MittensUi::Application.Window(app_options) do |window|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
layout: { box: box }
|
|
14
|
-
}
|
|
15
|
-
MittensUi::Label("Enter Name:", label_opts)
|
|
11
|
+
MittensUi::Application.Window(app_options) do |window, layout|
|
|
12
|
+
label_opts = { top: 30 }
|
|
13
|
+
MittensUi::Label("Enter Name:", layout, label_opts)
|
|
16
14
|
|
|
17
|
-
textbox_options = {
|
|
18
|
-
|
|
19
|
-
layout: { box: box }
|
|
20
|
-
}
|
|
21
|
-
text_box = MittensUi::Textbox(textbox_options)
|
|
15
|
+
textbox_options = { can_edit: true }
|
|
16
|
+
text_box = MittensUi::Textbox(layout, textbox_options)
|
|
22
17
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
MittensUi::
|
|
18
|
+
listbox_options = {
|
|
19
|
+
top: 10,
|
|
20
|
+
items: ["item_1", "item_2", "item_3"]
|
|
21
|
+
}.freeze
|
|
22
|
+
listbox = MittensUi::ListBox(layout, listbox_options)
|
|
23
|
+
|
|
24
|
+
btn1_options = { title: "Click Here" }
|
|
25
|
+
MittensUi::Button(layout, btn1_options) do
|
|
28
26
|
MittensUi::Alert(window, "Hello #{text_box.text}!")
|
|
29
27
|
end
|
|
30
|
-
|
|
28
|
+
|
|
29
|
+
slider_opts = { start_value: 1, stop_value: 100 }
|
|
30
|
+
MittensUi::Slider(layout, slider_opts) do |s|
|
|
31
|
+
puts "value changed: #{s.value}"
|
|
32
|
+
end
|
|
31
33
|
end
|
data/lib/mittens_ui.rb
CHANGED
|
@@ -1,87 +1,133 @@
|
|
|
1
1
|
require "mittens_ui/version"
|
|
2
|
-
|
|
3
|
-
require "mittens_ui/layouts/grid"
|
|
4
|
-
require "mittens_ui/layouts/stack"
|
|
5
|
-
require "mittens_ui/layouts/box"
|
|
6
|
-
|
|
7
2
|
require "mittens_ui/widgets/alert"
|
|
8
3
|
require "mittens_ui/widgets/label"
|
|
9
4
|
require "mittens_ui/widgets/button"
|
|
10
5
|
require "mittens_ui/widgets/textbox"
|
|
6
|
+
require "mittens_ui/widgets/listbox"
|
|
7
|
+
require "mittens_ui/widgets/slider"
|
|
11
8
|
|
|
12
9
|
require "gtk3"
|
|
13
10
|
|
|
14
11
|
module MittensUi
|
|
15
12
|
class Error < StandardError; end
|
|
16
13
|
|
|
17
|
-
def self.
|
|
18
|
-
|
|
14
|
+
def self.Slider(layout, options = {}, &block)
|
|
15
|
+
raise Error.new("Slider must be passed a block.") unless block_given?
|
|
16
|
+
slider = MittensUi::Widgets::Slider.new(layout, options, &block)
|
|
17
|
+
Application.set_visible_elements(slider)
|
|
18
|
+
return slider
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
def self.
|
|
22
|
-
MittensUi::Widgets::
|
|
21
|
+
def self.ListBox(layout, options = {})
|
|
22
|
+
list_box = MittensUi::Widgets::ListBox.new(layout, options)
|
|
23
|
+
Application.set_visible_elements(list_box)
|
|
24
|
+
return list_box
|
|
23
25
|
end
|
|
24
26
|
|
|
25
|
-
def self.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
textbox = MittensUi::Widgets::Textbox.init(options, nil)
|
|
30
|
-
else
|
|
31
|
-
textbox = MittensUi::Widgets::Textbox.init(options, block = Proc.new)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
if block_given?
|
|
35
|
-
block.call textbox
|
|
36
|
-
else
|
|
37
|
-
return textbox
|
|
38
|
-
end
|
|
27
|
+
def self.Alert(window, message, options = {})
|
|
28
|
+
alert = MittensUi::Widgets::Alert.new(window, message, options)
|
|
29
|
+
Application.set_visible_elements(alert)
|
|
30
|
+
return alert
|
|
39
31
|
end
|
|
40
32
|
|
|
41
|
-
def self.
|
|
42
|
-
|
|
43
|
-
|
|
33
|
+
def self.Label(text, layout, options = {})
|
|
34
|
+
label = MittensUi::Widgets::Label.new(text, layout, options)
|
|
35
|
+
Application.set_visible_elements(label)
|
|
36
|
+
return label
|
|
44
37
|
end
|
|
45
38
|
|
|
46
|
-
def self.
|
|
47
|
-
|
|
48
|
-
|
|
39
|
+
def self.Textbox(layout, options = {})
|
|
40
|
+
textbox = MittensUi::Widgets::Textbox.new(layout, options)
|
|
41
|
+
Application.set_visible_elements(textbox)
|
|
42
|
+
return textbox
|
|
49
43
|
end
|
|
50
44
|
|
|
51
|
-
def self.
|
|
52
|
-
raise "
|
|
53
|
-
MittensUi::
|
|
45
|
+
def self.Button(layout, options = {}, &block)
|
|
46
|
+
raise Error.new("Button must be passed a block.") unless block_given?
|
|
47
|
+
button = MittensUi::Widgets::Button.new(layout, options, &block)
|
|
48
|
+
Application.set_visible_elements(button)
|
|
49
|
+
return button
|
|
54
50
|
end
|
|
55
51
|
|
|
56
|
-
def self.
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
def self.HideVisible
|
|
53
|
+
Application.visible_elements.each(&:remove)
|
|
54
|
+
Application.reset_visible_elements
|
|
59
55
|
end
|
|
60
56
|
|
|
61
57
|
class Application
|
|
62
58
|
class << self
|
|
63
59
|
def Window(options = {}, &block)
|
|
64
|
-
|
|
65
|
-
block
|
|
66
|
-
|
|
67
|
-
|
|
60
|
+
@@visible_elements = []
|
|
61
|
+
init_gtk_application(options, block)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def set_visible_elements(element)
|
|
65
|
+
@@visible_elements << element
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def visible_elements
|
|
69
|
+
@@visible_elements
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def reset_visible_elements
|
|
73
|
+
@@visible_elements = []
|
|
68
74
|
end
|
|
69
75
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
private
|
|
77
|
+
|
|
78
|
+
def set_process_name(name)
|
|
79
|
+
# Doesn't work in MacOS Activity Monitor or Windows Task Manager. It shows up as "Ruby".
|
|
80
|
+
Process.setproctitle(name)
|
|
81
|
+
$PROGRAM_NAME = name
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def init_gtk_application(options, block)
|
|
85
|
+
app_name = options[:name].nil? ? "mittens_ui_app" : options[:name]
|
|
86
|
+
height = options[:height].nil? ? 600 : options[:height]
|
|
87
|
+
width = options[:width].nil? ? 400 : options[:width]
|
|
88
|
+
title = options[:title].nil? ? "Mittens App" : options[:title]
|
|
76
89
|
can_resize = options[:can_resize].nil? ? true : options[:can_resize]
|
|
77
|
-
|
|
78
|
-
@@GTK_WINDOW.set_size_request(width, height)
|
|
79
|
-
@@GTK_WINDOW.set_title(title)
|
|
80
|
-
@@GTK_WINDOW.set_resizable(can_resize)
|
|
81
90
|
|
|
82
|
-
|
|
91
|
+
set_process_name(app_name)
|
|
92
|
+
|
|
93
|
+
gtk_app_name = "org.gtk.mittens_ui.#{app_name}"
|
|
94
|
+
|
|
95
|
+
app = Gtk::Application.new(gtk_app_name, :flags_none)
|
|
96
|
+
|
|
97
|
+
app.signal_connect("activate") do |application|
|
|
98
|
+
app_window = Gtk::ApplicationWindow.new(application)
|
|
99
|
+
scrolled_window = Gtk::ScrolledWindow.new
|
|
100
|
+
vertical_box = Gtk::Box.new(:vertical, 10)
|
|
101
|
+
scrolled_window.add(vertical_box)
|
|
102
|
+
app_window.add(scrolled_window)
|
|
103
|
+
block.call(app_window, vertical_box)
|
|
104
|
+
app_window.set_size_request(width, height)
|
|
105
|
+
app_window.set_title(title)
|
|
106
|
+
app_window.set_resizable(can_resize)
|
|
107
|
+
app_window.show_all
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
app.run
|
|
83
111
|
end
|
|
84
|
-
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
class Job
|
|
116
|
+
attr_reader :name, :status
|
|
117
|
+
|
|
118
|
+
def initialize(name)
|
|
119
|
+
@name = name
|
|
120
|
+
@status = nil
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def run(&block)
|
|
124
|
+
job_t = Thread.new { |_t| yield }
|
|
125
|
+
set_status(job_t)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
private
|
|
129
|
+
def set_status(thread)
|
|
130
|
+
@status = thread.status
|
|
85
131
|
end
|
|
86
132
|
end
|
|
87
133
|
end
|
|
@@ -1,36 +1,38 @@
|
|
|
1
1
|
module MittensUi
|
|
2
2
|
module Layouts
|
|
3
|
-
class Box
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def attach(widget, options)
|
|
12
|
-
box_ref = options[:box]
|
|
3
|
+
class Box
|
|
4
|
+
def initialize(window, options={}, &block)
|
|
5
|
+
box_spacing = options[:spacing].nil? ? 6 : options[:spacing]
|
|
6
|
+
@box = Gtk::Box.new(:vertical, box_spacing)
|
|
7
|
+
yield(self)
|
|
8
|
+
window.add(@box)
|
|
9
|
+
end
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
def attach(widget, options)
|
|
12
|
+
expand = options[:expand].nil? ? true : options[:expand]
|
|
13
|
+
fill = options[:fill].nil? ? true : options[:fill]
|
|
14
|
+
padding = options[:padding].nil? ? 0 : options[:padding]
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
filterd_options = {
|
|
17
|
+
expaned: expand,
|
|
18
|
+
fill: fill,
|
|
19
|
+
padding: padding
|
|
20
|
+
}.freeze
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
end
|
|
22
|
+
case options.dig(:position)
|
|
23
|
+
when :start
|
|
24
|
+
@box.pack_start(widget, filterd_options)
|
|
25
|
+
when :end
|
|
26
|
+
@box.pack_end(widget, filterd_options)
|
|
27
|
+
when nil
|
|
28
|
+
@box.pack_start(widget, filterd_options)
|
|
32
29
|
end
|
|
33
30
|
end
|
|
31
|
+
|
|
32
|
+
def remove
|
|
33
|
+
return if @box.nil?
|
|
34
|
+
@box.destroy
|
|
35
|
+
end
|
|
34
36
|
end
|
|
35
37
|
end
|
|
36
|
-
end
|
|
38
|
+
end
|
|
@@ -1,28 +1,31 @@
|
|
|
1
1
|
module MittensUi
|
|
2
2
|
module Layouts
|
|
3
3
|
class Grid
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
end
|
|
4
|
+
def initialize(window, &block)
|
|
5
|
+
@grid = Gtk::Grid.new
|
|
6
|
+
yield(self)
|
|
7
|
+
window.add_child(@grid)
|
|
8
|
+
end
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
grid_left = options[:left]
|
|
10
|
+
def attach(widget, options)
|
|
11
|
+
grid_height = options[:height]
|
|
12
|
+
grid_width = options[:width]
|
|
13
|
+
grid_top = options[:top]
|
|
14
|
+
grid_left = options[:left]
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
end
|
|
16
|
+
# Place widget next to each other in the direction determined by the “orientation” property
|
|
17
|
+
# defaults to :horizontal.
|
|
18
|
+
if options.size >= 1
|
|
19
|
+
@grid.add(widget)
|
|
23
20
|
end
|
|
24
21
|
|
|
22
|
+
unless options[:attach_to].nil?
|
|
23
|
+
return
|
|
24
|
+
@grid.attach_next_to()
|
|
25
|
+
else
|
|
26
|
+
@grid.attach(widget, grid_left, grid_top, grid_width, grid_height)
|
|
27
|
+
end
|
|
25
28
|
end
|
|
26
29
|
end
|
|
27
30
|
end
|
|
28
|
-
end
|
|
31
|
+
end
|
data/lib/mittens_ui/version.rb
CHANGED
|
@@ -1,31 +1,32 @@
|
|
|
1
1
|
module MittensUi
|
|
2
2
|
module Widgets
|
|
3
3
|
class Alert
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}.freeze
|
|
4
|
+
def initialize(window, message, options)
|
|
5
|
+
dialog_options = {
|
|
6
|
+
title: "Alert",
|
|
7
|
+
parent: window,
|
|
8
|
+
flags: [:modal, :destroy_with_parent],
|
|
9
|
+
:buttons => [["_OK", :none]]
|
|
10
|
+
}.freeze
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
alert_dialog = Gtk::Dialog.new(dialog_options)
|
|
13
|
+
alert_dialog.set_transient_for(window)
|
|
14
|
+
alert_dialog.set_default_width(420)
|
|
15
|
+
alert_dialog.set_default_height(200)
|
|
16
|
+
alert_dialog.set_modal(true)
|
|
17
|
+
alert_dialog.set_resizable(false)
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
dialog_box.add(message_label)
|
|
21
|
-
|
|
22
|
-
alert_dialog.show_all
|
|
23
|
-
|
|
24
|
-
response = alert_dialog.run
|
|
19
|
+
message_label = Gtk::Label.new(message)
|
|
20
|
+
message_label.set_margin_top(65)
|
|
25
21
|
|
|
26
|
-
|
|
22
|
+
dialog_box = alert_dialog.content_area
|
|
23
|
+
dialog_box.add(message_label)
|
|
24
|
+
|
|
25
|
+
alert_dialog.show_all
|
|
26
|
+
|
|
27
|
+
response = alert_dialog.run
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
response == :none ? alert_dialog.destroy : alert_dialog.destroy
|
|
29
30
|
end
|
|
30
31
|
end
|
|
31
32
|
end
|
|
@@ -1,29 +1,34 @@
|
|
|
1
1
|
module MittensUi
|
|
2
2
|
module Widgets
|
|
3
3
|
class Button
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
4
|
+
def initialize(layout, options, &block)
|
|
5
|
+
button_title = options[:title] || "Button"
|
|
6
|
+
|
|
7
|
+
margin_top = options[:top].nil? ? nil : options[:top]
|
|
8
|
+
margin_bottom = options[:bottom].nil? ? nil : options[:bottom]
|
|
9
|
+
margin_right = options[:right].nil? ? nil : options[:right]
|
|
10
|
+
margin_left = options[:left].nil? ? nil : options[:left]
|
|
11
|
+
|
|
12
|
+
@button = Gtk::Button.new(label: button_title)
|
|
13
|
+
|
|
14
|
+
@button.set_margin_top(margin_top) unless margin_top.nil?
|
|
15
|
+
@button.set_margin_left(margin_left) unless margin_left.nil?
|
|
16
|
+
@button.set_margin_right(margin_right) unless margin_right.nil?
|
|
17
|
+
@button.set_margin_bottom(margin_bottom) unless margin_bottom.nil?
|
|
18
|
+
|
|
19
|
+
if layout
|
|
20
|
+
layout.pack_start(@button)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
@button.signal_connect "clicked" do |button_widget|
|
|
24
|
+
block.call(button_widget)
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
|
+
|
|
28
|
+
def remove
|
|
29
|
+
return if @button.nil?
|
|
30
|
+
@button.destroy
|
|
31
|
+
end
|
|
27
32
|
end
|
|
28
33
|
end
|
|
29
|
-
end
|
|
34
|
+
end
|
|
@@ -1,23 +1,38 @@
|
|
|
1
1
|
module MittensUi
|
|
2
2
|
module Widgets
|
|
3
3
|
class Label
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
def initialize(text, layout, options)
|
|
5
|
+
margin_top = options[:top].nil? ? nil : options[:top]
|
|
6
|
+
margin_bottom = options[:bottom].nil? ? nil : options[:bottom]
|
|
7
|
+
margin_right = options[:right].nil? ? nil : options[:right]
|
|
8
|
+
margin_left = options[:left].nil? ? nil : options[:left]
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
elsif window
|
|
18
|
-
window.add_child(label)
|
|
19
|
-
end
|
|
10
|
+
@label = Gtk::Label.new(text)
|
|
11
|
+
|
|
12
|
+
unless margin_top.nil?
|
|
13
|
+
@label.set_margin_top(margin_top)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
unless margin_bottom.nil?
|
|
17
|
+
@label.set_margin_bottom(margin_top)
|
|
20
18
|
end
|
|
19
|
+
|
|
20
|
+
unless margin_left.nil?
|
|
21
|
+
@label.set_margin_left(margin_left)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
unless margin_right.nil?
|
|
25
|
+
@label.set_margin_right(margin_right)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
if layout
|
|
29
|
+
layout.pack_start(@label)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def remove
|
|
34
|
+
return if @label.nil?
|
|
35
|
+
@label.destroy
|
|
21
36
|
end
|
|
22
37
|
end
|
|
23
38
|
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
module MittensUi
|
|
2
|
+
module Widgets
|
|
3
|
+
class ListBox
|
|
4
|
+
attr_reader :items
|
|
5
|
+
|
|
6
|
+
def initialize(layout, options={})
|
|
7
|
+
@items = options[:items]
|
|
8
|
+
|
|
9
|
+
list_store = Gtk::ListStore.new(String)
|
|
10
|
+
|
|
11
|
+
@items.each do |i|
|
|
12
|
+
iter = list_store.append
|
|
13
|
+
iter[0] = i
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
renderer = Gtk::CellRendererText.new
|
|
17
|
+
|
|
18
|
+
@gtk_combobox = Gtk::ComboBox.new(model: list_store)
|
|
19
|
+
@gtk_combobox.pack_start(renderer, true)
|
|
20
|
+
@gtk_combobox.set_attributes(renderer, "text" => 0)
|
|
21
|
+
@gtk_combobox.set_cell_data_func(renderer) do |_layout, _cell_renderer, _model, iter|
|
|
22
|
+
set_selected_value(iter[0])
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
@gtk_combobox.set_active(0)
|
|
26
|
+
|
|
27
|
+
if layout
|
|
28
|
+
layout.pack_start(@gtk_combobox)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
return self
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def set_selected_value(value)
|
|
35
|
+
@selected_value = value
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def get_selected_value
|
|
39
|
+
@selected_value
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def remove
|
|
43
|
+
return if @gtk_combobox.nil?
|
|
44
|
+
@gtk_combobox.destroy
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module MittensUi
|
|
2
|
+
module Widgets
|
|
3
|
+
class Slider
|
|
4
|
+
def initialize(layout, options={}, &block)
|
|
5
|
+
start_value = options[:start_value].nil? ? 1.0 : options[:start_value]
|
|
6
|
+
stop_value = options[:stop_value].nil? ? 10.0 : options[:stop_value]
|
|
7
|
+
step_value = options[:step_value].nil? ? 1.0 : options[:step_value]
|
|
8
|
+
|
|
9
|
+
@scale = Gtk::Scale.new(:horizontal, start_value, stop_value, step_value)
|
|
10
|
+
@scale.digits = 0
|
|
11
|
+
@scale.draw_value = true
|
|
12
|
+
|
|
13
|
+
@scale.signal_connect "value_changed" do |scale_widget|
|
|
14
|
+
block.call(scale_widget)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
if layout
|
|
18
|
+
layout.pack_start(@scale)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def remove
|
|
23
|
+
return if @scale.nil?
|
|
24
|
+
@scale.destroy
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
module MittensUi
|
|
2
2
|
module Widgets
|
|
3
3
|
class Textbox
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
textbox.set_max_length(max_length)
|
|
12
|
-
|
|
13
|
-
if layout[:grid]
|
|
14
|
-
MittensUi::Layouts::Grid.attach(textbox, layout)
|
|
15
|
-
elsif layout[:stack]
|
|
16
|
-
MittensUi::Layouts::Stack.attach(textbox, layout)
|
|
17
|
-
elsif layout[:box]
|
|
18
|
-
MittensUi::Layouts::Box.attach(textbox, layout)
|
|
19
|
-
end
|
|
4
|
+
def initialize(layout, options)
|
|
5
|
+
@textbox = Gtk::Entry.new
|
|
6
|
+
can_edit = options[:can_edit].nil? ? true : options[:can_edit]
|
|
7
|
+
max_length = options[:max_length].nil? ? 200 : options[:max_length]
|
|
8
|
+
|
|
9
|
+
@textbox.set_editable(can_edit) unless can_edit.nil?
|
|
10
|
+
@textbox.set_max_length(max_length) unless max_length.nil?
|
|
20
11
|
|
|
21
|
-
|
|
12
|
+
if layout
|
|
13
|
+
layout.pack_start(@textbox)
|
|
22
14
|
end
|
|
15
|
+
|
|
16
|
+
return @textbox
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def text
|
|
20
|
+
@textbox.text
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def remove
|
|
24
|
+
return if @textbox.nil?
|
|
25
|
+
@textbox.destroy
|
|
23
26
|
end
|
|
24
27
|
end
|
|
25
28
|
end
|
|
26
|
-
end
|
|
29
|
+
end
|
data/notes/gtk.txt
ADDED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mittens_ui
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Zach Tuttle
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-
|
|
11
|
+
date: 2020-12-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: gtk3
|
|
@@ -42,22 +42,23 @@ files:
|
|
|
42
42
|
- bin/setup
|
|
43
43
|
- examples/app.rb
|
|
44
44
|
- lib/mittens_ui.rb
|
|
45
|
-
- lib/mittens_ui/dsl_parser.rb
|
|
46
45
|
- lib/mittens_ui/layouts/box.rb
|
|
47
46
|
- lib/mittens_ui/layouts/grid.rb
|
|
48
|
-
- lib/mittens_ui/layouts/stack.rb
|
|
49
47
|
- lib/mittens_ui/version.rb
|
|
50
48
|
- lib/mittens_ui/widgets/alert.rb
|
|
51
49
|
- lib/mittens_ui/widgets/button.rb
|
|
52
50
|
- lib/mittens_ui/widgets/label.rb
|
|
51
|
+
- lib/mittens_ui/widgets/listbox.rb
|
|
52
|
+
- lib/mittens_ui/widgets/slider.rb
|
|
53
53
|
- lib/mittens_ui/widgets/textbox.rb
|
|
54
54
|
- mittens_ui.gemspec
|
|
55
|
+
- notes/gtk.txt
|
|
55
56
|
homepage: https://github.com/tuttza/mittens_ui
|
|
56
57
|
licenses: []
|
|
57
58
|
metadata:
|
|
58
59
|
homepage_uri: https://github.com/tuttza/mittens_ui
|
|
59
60
|
source_code_uri: https://github.com/tuttza/mittens_ui
|
|
60
|
-
post_install_message:
|
|
61
|
+
post_install_message:
|
|
61
62
|
rdoc_options: []
|
|
62
63
|
require_paths:
|
|
63
64
|
- lib
|
|
@@ -72,8 +73,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
72
73
|
- !ruby/object:Gem::Version
|
|
73
74
|
version: '0'
|
|
74
75
|
requirements: []
|
|
75
|
-
rubygems_version: 3.
|
|
76
|
-
signing_key:
|
|
76
|
+
rubygems_version: 3.1.4
|
|
77
|
+
signing_key:
|
|
77
78
|
specification_version: 4
|
|
78
79
|
summary: A tiny GUI tool kit written on top of GTK3
|
|
79
80
|
test_files: []
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
module MittensUi
|
|
2
|
-
module Layouts
|
|
3
|
-
class Stack
|
|
4
|
-
class << self
|
|
5
|
-
def init(window, block = Proc.new)
|
|
6
|
-
stack = Gtk::Stack.new
|
|
7
|
-
block.call(stack)
|
|
8
|
-
window.add_child(stack)
|
|
9
|
-
stack
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def attach(widget, options)
|
|
13
|
-
stack = options[:stack]
|
|
14
|
-
if stack
|
|
15
|
-
stack.add(widget)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|