mittens_ui 0.0.8 → 0.0.9
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/.ruby-version +1 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +5 -2
- data/LICENSE +21 -0
- data/README.md +43 -9
- data/examples/app.rb +72 -11
- data/lib/mittens_ui.rb +41 -27
- data/lib/mittens_ui/dialogs/file_dialog.rb +29 -0
- data/lib/mittens_ui/helpers.rb +1 -1
- data/lib/mittens_ui/version.rb +1 -1
- data/lib/mittens_ui/widgets/alert.rb +2 -2
- data/lib/mittens_ui/widgets/button.rb +1 -1
- data/lib/mittens_ui/widgets/checkbox.rb +28 -0
- data/lib/mittens_ui/widgets/core.rb +5 -1
- data/lib/mittens_ui/widgets/loader.rb +34 -0
- data/lib/mittens_ui/widgets/table_view.rb +159 -0
- data/lib/mittens_ui/widgets/textbox.rb +4 -0
- data/lib/mittens_ui/widgets/web_link.rb +23 -0
- data/mittens_ui.gemspec +3 -3
- metadata +17 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9976f7810db4c1f9ed61a4a1f1f639617ee9c84bf117d37e174b14fd54b21dbc
|
|
4
|
+
data.tar.gz: 0224ed85d93f9366f7f594e19ed74827c72b33c949ea7ce9efc78a230dc44121
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 68fbe929734690f1a21377b914fc200c54307e5393a98da9324e017b6bc59b3270577e4e09843aad88f49d61f6fd732c25f5e635d0ad2b0536d518898750e40b
|
|
7
|
+
data.tar.gz: edaecba0f03a65f2c79cab04345434cd8f8539c4a7930480eb6e792e89c90ee969416b7bcd36efba77be11f28210cf08e4a9c1c2d7cb3990cf5ca5940be3db67
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.0.0
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Zach Tuttle
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
|
@@ -26,8 +26,8 @@ Or install it yourself as:
|
|
|
26
26
|
require "mittens_ui"
|
|
27
27
|
|
|
28
28
|
app_options = {
|
|
29
|
-
name: "
|
|
30
|
-
title: "
|
|
29
|
+
name: "hello_world",
|
|
30
|
+
title: "Hello World App!",
|
|
31
31
|
height: 650,
|
|
32
32
|
width: 550,
|
|
33
33
|
can_resize: true
|
|
@@ -39,7 +39,7 @@ MittensUi::Application.Window(app_options) do
|
|
|
39
39
|
text_box = MittensUi::Textbox(can_edit: true)
|
|
40
40
|
|
|
41
41
|
listbox_options = {
|
|
42
|
-
top: 10,
|
|
42
|
+
top: 10,
|
|
43
43
|
items: ["item_1", "item_2", "item_3"]
|
|
44
44
|
}.freeze
|
|
45
45
|
|
|
@@ -52,9 +52,9 @@ MittensUi::Application.Window(app_options) do
|
|
|
52
52
|
s.slide { |s| puts s.value }
|
|
53
53
|
|
|
54
54
|
img_opts = {
|
|
55
|
-
tooltip_text: "The Gnome LOGO!",
|
|
56
|
-
width: 200,
|
|
57
|
-
height: 200,
|
|
55
|
+
tooltip_text: "The Gnome LOGO!",
|
|
56
|
+
width: 200,
|
|
57
|
+
height: 200,
|
|
58
58
|
left: 50
|
|
59
59
|
}.freeze
|
|
60
60
|
|
|
@@ -75,16 +75,50 @@ MittensUi::Application.Window(app_options) do
|
|
|
75
75
|
img.show
|
|
76
76
|
else
|
|
77
77
|
img.hide
|
|
78
|
-
end
|
|
78
|
+
end
|
|
79
79
|
end
|
|
80
|
+
|
|
81
|
+
cb = MittensUi::CheckBox(label: "Enable")
|
|
82
|
+
cb.value = "Some Value"
|
|
83
|
+
cb.toggle { puts "checkbox was toggled! associated value: #{cb.value}" }
|
|
84
|
+
|
|
85
|
+
link = MittensUi::WebLink("YouTube", "https://www.youtube.com", left: 200)
|
|
86
|
+
|
|
87
|
+
table_view_options = {
|
|
88
|
+
headers: ["Name", "Address", "Phone #"],
|
|
89
|
+
data: [
|
|
90
|
+
[ "John Appleseed", "123 abc st.", "111-555-3333"],
|
|
91
|
+
[ "Jane Doe", "122 abc st.", "111-555-4444" ],
|
|
92
|
+
[ "Bobby Jones", "434 bfef ave.", "442-333-1342"],
|
|
93
|
+
],
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
table = MittensUi::TableView(table_view_options)
|
|
97
|
+
table.add(["Sara Akigawa", "777 tyo ave.", "932-333-1325"], :prepend)
|
|
98
|
+
|
|
99
|
+
remove_ct = MittensUi::Button(title: "Remove Contact")
|
|
100
|
+
remove_ct.click { |btn| table.remove_selected }
|
|
101
|
+
|
|
80
102
|
end
|
|
103
|
+
|
|
104
|
+
|
|
81
105
|
```
|
|
82
106
|
|
|
83
107
|
## Development
|
|
84
108
|
|
|
85
|
-
|
|
109
|
+
Simply fork and clone this repo to your machine, cd into it and run `bundle install`.
|
|
110
|
+
|
|
111
|
+
This does require GTK ruby gem which requires `gtk` native dependencies to be complied and installed on your system.
|
|
112
|
+
|
|
113
|
+
#### Fedora
|
|
114
|
+
Using dnf:
|
|
115
|
+
* `$ sudo dnf install ruby ruby-devel cairo cairo-devel gtk3-devel`
|
|
116
|
+
|
|
117
|
+
#### MacOS
|
|
86
118
|
|
|
87
|
-
|
|
119
|
+
Using Brew:
|
|
120
|
+
* `$ brew install gtk+3`
|
|
121
|
+
* `$ brew install cairo`
|
|
88
122
|
|
|
89
123
|
## Contributing
|
|
90
124
|
|
data/examples/app.rb
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
require '../lib/mittens_ui'
|
|
2
2
|
|
|
3
3
|
app_options = {
|
|
4
|
-
name: "
|
|
5
|
-
title: "
|
|
4
|
+
name: "hello_world",
|
|
5
|
+
title: "Hello World App!",
|
|
6
6
|
height: 650,
|
|
7
7
|
width: 550,
|
|
8
|
-
can_resize:
|
|
8
|
+
can_resize: false
|
|
9
9
|
}.freeze
|
|
10
10
|
|
|
11
11
|
MittensUi::Application.Window(app_options) do
|
|
@@ -14,7 +14,7 @@ MittensUi::Application.Window(app_options) do
|
|
|
14
14
|
text_box = MittensUi::Textbox(can_edit: true)
|
|
15
15
|
|
|
16
16
|
listbox_options = {
|
|
17
|
-
top: 10,
|
|
17
|
+
top: 10,
|
|
18
18
|
items: ["item_1", "item_2", "item_3"]
|
|
19
19
|
}.freeze
|
|
20
20
|
|
|
@@ -27,15 +27,15 @@ MittensUi::Application.Window(app_options) do
|
|
|
27
27
|
s.slide { |s| puts s.value }
|
|
28
28
|
|
|
29
29
|
img_opts = {
|
|
30
|
-
tooltip_text: "The Gnome LOGO!",
|
|
31
|
-
width: 200,
|
|
32
|
-
height: 200,
|
|
33
|
-
left:
|
|
30
|
+
tooltip_text: "The Gnome LOGO!",
|
|
31
|
+
width: 200,
|
|
32
|
+
height: 200,
|
|
33
|
+
left: 20
|
|
34
34
|
}.freeze
|
|
35
35
|
|
|
36
36
|
img = MittensUi::Image("./assets/gnome_logo.png", img_opts)
|
|
37
37
|
|
|
38
|
-
switch = MittensUi::Switch(left:
|
|
38
|
+
switch = MittensUi::Switch(left: 220 )
|
|
39
39
|
|
|
40
40
|
img.click do
|
|
41
41
|
unless switch.hidden?
|
|
@@ -50,6 +50,67 @@ MittensUi::Application.Window(app_options) do
|
|
|
50
50
|
img.show
|
|
51
51
|
else
|
|
52
52
|
img.hide
|
|
53
|
-
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
cb = MittensUi::CheckBox(label: "Enable")
|
|
57
|
+
cb.value = "Some Value"
|
|
58
|
+
cb.toggle { puts "checkbox was toggled! associated value: #{cb.value}" }
|
|
59
|
+
|
|
60
|
+
link = MittensUi::WebLink("YouTube", "https://www.youtube.com", left: 200)
|
|
61
|
+
|
|
62
|
+
MittensUi::Label("Contact Info (use delimiter: ',')", top: 30)
|
|
63
|
+
contact_tb = MittensUi::Textbox(can_edit: true)
|
|
64
|
+
|
|
65
|
+
table_view_options = {
|
|
66
|
+
headers: ["Name", "Address", "Phone #"],
|
|
67
|
+
data: [
|
|
68
|
+
[ "John Appleseed", "123 abc st.", "111-555-3333"],
|
|
69
|
+
[ "Jane Doe", "122 abc st.", "111-555-4444" ],
|
|
70
|
+
[ "Bobby Jones", "434 bfef ave.", "442-333-1342"],
|
|
71
|
+
],
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
table = MittensUi::TableView(table_view_options)
|
|
75
|
+
table.add(["Sara Akigawa", "777 tyo ave.", "932-333-1325"], :prepend)
|
|
76
|
+
|
|
77
|
+
add_ct = MittensUi::Button(title: "Add Contact")
|
|
78
|
+
add_ct.click {|_b| table.add(contact_tb.text.split(",")); contact_tb.clear; puts "Row Count: #{table.row_count}" }
|
|
79
|
+
|
|
80
|
+
table.row_clicked { |row| puts row.inspect }
|
|
81
|
+
|
|
82
|
+
remove_ct = MittensUi::Button(title: "Remove Contact")
|
|
83
|
+
remove_ct.click { |btn| table.remove_selected }
|
|
84
|
+
|
|
85
|
+
MittensUi::Shutdown() do
|
|
86
|
+
puts "quitting...."
|
|
54
87
|
end
|
|
55
|
-
|
|
88
|
+
|
|
89
|
+
open_file_picker = MittensUi::Button(title: "Choose File")
|
|
90
|
+
|
|
91
|
+
open_file_picker.click do
|
|
92
|
+
picked_file_path = MittensUi::FilePicker()
|
|
93
|
+
puts picked_file_path.inspect
|
|
94
|
+
open_file_picker.remove
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
start_loader = MittensUi::Button(title: "Start Loader")
|
|
98
|
+
|
|
99
|
+
loader = MittensUi::Loader()
|
|
100
|
+
|
|
101
|
+
start_loader.click do
|
|
102
|
+
loader.start {
|
|
103
|
+
puts "Doing some work..."
|
|
104
|
+
num = 0
|
|
105
|
+
100.times do
|
|
106
|
+
num += 1
|
|
107
|
+
puts num
|
|
108
|
+
sleep 0.2
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
start_loader.remove
|
|
112
|
+
}
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
end
|
|
116
|
+
|
data/lib/mittens_ui.rb
CHANGED
|
@@ -7,12 +7,39 @@ require "mittens_ui/widgets/listbox"
|
|
|
7
7
|
require "mittens_ui/widgets/slider"
|
|
8
8
|
require "mittens_ui/widgets/switch"
|
|
9
9
|
require "mittens_ui/widgets/image"
|
|
10
|
+
require "mittens_ui/widgets/checkbox"
|
|
11
|
+
require "mittens_ui/widgets/web_link"
|
|
12
|
+
require "mittens_ui/widgets/table_view"
|
|
13
|
+
require "mittens_ui/widgets/loader"
|
|
14
|
+
|
|
15
|
+
require "mittens_ui/dialogs/file_dialog"
|
|
10
16
|
|
|
11
17
|
require "gtk3"
|
|
12
18
|
|
|
13
19
|
module MittensUi
|
|
14
20
|
class Error < StandardError; end
|
|
15
21
|
|
|
22
|
+
def self.Loader(options={})
|
|
23
|
+
MittensUi::Widgets::Loader.new(options)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.FilePicker
|
|
27
|
+
fp = MittensUi::Dialogs::File.new
|
|
28
|
+
return fp.path
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.TableView(options={})
|
|
32
|
+
MittensUi::Widgets::TableView.new(options)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.WebLink(url, name, options={})
|
|
36
|
+
MittensUi::Widgets::WebLink.new(url, name, options)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.CheckBox(options={})
|
|
40
|
+
MittensUi::Widgets::Checkbox.new(options)
|
|
41
|
+
end
|
|
42
|
+
|
|
16
43
|
def self.Image(path, options={})
|
|
17
44
|
MittensUi::Widgets::Image.new(path, options)
|
|
18
45
|
end
|
|
@@ -45,21 +72,27 @@ module MittensUi
|
|
|
45
72
|
MittensUi::Widgets::Button.new(options)
|
|
46
73
|
end
|
|
47
74
|
|
|
75
|
+
def self.Shutdown
|
|
76
|
+
$app_window.signal_connect("delete-event") do |_widget|
|
|
77
|
+
yield
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
48
81
|
class Application
|
|
49
82
|
class << self
|
|
50
|
-
def Window(options = {}, &block)
|
|
51
|
-
init_gtk_application(options, block)
|
|
83
|
+
def Window(options = {}, &block)
|
|
84
|
+
init_gtk_application(options, &block)
|
|
52
85
|
end
|
|
53
|
-
|
|
54
|
-
private
|
|
86
|
+
|
|
87
|
+
private
|
|
55
88
|
|
|
56
89
|
def set_process_name(name)
|
|
57
|
-
# Doesn't work in MacOS Activity Monitor or Windows Task Manager. It shows up as "Ruby".
|
|
58
90
|
Process.setproctitle(name)
|
|
59
91
|
$PROGRAM_NAME = name
|
|
92
|
+
$0 = name
|
|
60
93
|
end
|
|
61
94
|
|
|
62
|
-
def init_gtk_application(options, block)
|
|
95
|
+
def init_gtk_application(options, &block)
|
|
63
96
|
app_name = options[:name].nil? ? "mittens_ui_app" : options[:name]
|
|
64
97
|
height = options[:height].nil? ? 600 : options[:height]
|
|
65
98
|
width = options[:width].nil? ? 400 : options[:width]
|
|
@@ -68,7 +101,7 @@ module MittensUi
|
|
|
68
101
|
|
|
69
102
|
set_process_name(app_name)
|
|
70
103
|
|
|
71
|
-
gtk_app_name = "org.
|
|
104
|
+
gtk_app_name = "org.mittens_ui.#{app_name}"
|
|
72
105
|
|
|
73
106
|
app = Gtk::Application.new(gtk_app_name, :flags_none)
|
|
74
107
|
|
|
@@ -78,7 +111,7 @@ module MittensUi
|
|
|
78
111
|
$vertical_box = Gtk::Box.new(:vertical, 10)
|
|
79
112
|
scrolled_window.add($vertical_box)
|
|
80
113
|
$app_window.add(scrolled_window)
|
|
81
|
-
|
|
114
|
+
yield($app_window, $vertical_box)
|
|
82
115
|
$app_window.set_size_request(width, height)
|
|
83
116
|
$app_window.set_title(title)
|
|
84
117
|
$app_window.set_resizable(can_resize)
|
|
@@ -89,23 +122,4 @@ module MittensUi
|
|
|
89
122
|
end
|
|
90
123
|
end
|
|
91
124
|
end
|
|
92
|
-
|
|
93
|
-
class Job
|
|
94
|
-
attr_reader :name, :status
|
|
95
|
-
|
|
96
|
-
def initialize(name)
|
|
97
|
-
@name = name
|
|
98
|
-
@status = nil
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
def run(&block)
|
|
102
|
-
job_t = Thread.new { |_t| yield }
|
|
103
|
-
set_status(job_t)
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
private
|
|
107
|
-
def set_status(thread)
|
|
108
|
-
@status = thread.status
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
125
|
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module MittensUi
|
|
2
|
+
module Dialogs
|
|
3
|
+
class File
|
|
4
|
+
attr_reader :path
|
|
5
|
+
|
|
6
|
+
def initialize(options={})
|
|
7
|
+
@path = ""
|
|
8
|
+
|
|
9
|
+
dialog_options = {
|
|
10
|
+
title: "Select File",
|
|
11
|
+
parent: $app_window,
|
|
12
|
+
action: options[:action] || :open,
|
|
13
|
+
buttons: [
|
|
14
|
+
[Gtk::Stock::OPEN, Gtk::ResponseType::ACCEPT],
|
|
15
|
+
[Gtk::Stock::CANCEL, Gtk::ResponseType::CANCEL]
|
|
16
|
+
]
|
|
17
|
+
}.freeze
|
|
18
|
+
|
|
19
|
+
dialog = Gtk::FileChooserDialog.new(dialog_options)
|
|
20
|
+
|
|
21
|
+
if dialog.run == :accept
|
|
22
|
+
@path = dialog.filename
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
dialog.destroy
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/mittens_ui/helpers.rb
CHANGED
data/lib/mittens_ui/version.rb
CHANGED
|
@@ -3,10 +3,10 @@ module MittensUi
|
|
|
3
3
|
class Alert
|
|
4
4
|
def initialize(message, options)
|
|
5
5
|
dialog_options = {
|
|
6
|
-
title: "Alert",
|
|
6
|
+
title: options[:title] || "Alert",
|
|
7
7
|
parent: $app_window,
|
|
8
8
|
flags: [:modal, :destroy_with_parent],
|
|
9
|
-
:buttons => [[
|
|
9
|
+
:buttons => [[Gtk::Stock::OK, :none]]
|
|
10
10
|
}.freeze
|
|
11
11
|
|
|
12
12
|
alert_dialog = Gtk::Dialog.new(dialog_options)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require_relative "./core"
|
|
2
|
+
|
|
3
|
+
module MittensUi
|
|
4
|
+
module Widgets
|
|
5
|
+
class Checkbox < Core
|
|
6
|
+
attr_accessor :value
|
|
7
|
+
|
|
8
|
+
def initialize(options={})
|
|
9
|
+
label = options[:label] || "Checkbox"
|
|
10
|
+
|
|
11
|
+
@value = nil
|
|
12
|
+
@checkbox = Gtk::CheckButton.new(label)
|
|
13
|
+
|
|
14
|
+
set_margin_from_opts_for(@checkbox, options)
|
|
15
|
+
|
|
16
|
+
$vertical_box.pack_start(@checkbox)
|
|
17
|
+
|
|
18
|
+
super(@checkbox)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def toggle
|
|
22
|
+
@checkbox.signal_connect "toggled" do
|
|
23
|
+
yield
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -5,7 +5,7 @@ module MittensUi
|
|
|
5
5
|
class Core
|
|
6
6
|
include Helpers
|
|
7
7
|
|
|
8
|
-
# All MittenUi::
|
|
8
|
+
# All MittenUi::Widgets::* classes should inherit from this base class.
|
|
9
9
|
|
|
10
10
|
def initialize(widget)
|
|
11
11
|
@core_widget = widget
|
|
@@ -23,6 +23,10 @@ module MittensUi
|
|
|
23
23
|
return if @core_widget.nil?
|
|
24
24
|
@core_widget.hide
|
|
25
25
|
end
|
|
26
|
+
|
|
27
|
+
def remove
|
|
28
|
+
$vertical_box.remove(@core_widget)
|
|
29
|
+
end
|
|
26
30
|
end
|
|
27
31
|
end
|
|
28
32
|
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require_relative "./core"
|
|
2
|
+
|
|
3
|
+
module MittensUi
|
|
4
|
+
module Widgets
|
|
5
|
+
class Loader < Core
|
|
6
|
+
def initialize(options={})
|
|
7
|
+
@spinner = Gtk::Spinner.new
|
|
8
|
+
|
|
9
|
+
@processing = false
|
|
10
|
+
|
|
11
|
+
set_margin_from_opts_for(@spinner, options)
|
|
12
|
+
|
|
13
|
+
$vertical_box.pack_end(@spinner)
|
|
14
|
+
|
|
15
|
+
super(@spinner)
|
|
16
|
+
|
|
17
|
+
self.hide
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def start(&block)
|
|
21
|
+
return if @processing
|
|
22
|
+
|
|
23
|
+
return if @worker_thread && @worker_thread.alive?
|
|
24
|
+
|
|
25
|
+
self.show
|
|
26
|
+
|
|
27
|
+
@spinner.start
|
|
28
|
+
|
|
29
|
+
@worker_thread = Thread.new { yield; self.remove; @processing = true }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
require_relative "./core"
|
|
2
|
+
|
|
3
|
+
module MittensUi
|
|
4
|
+
module Widgets
|
|
5
|
+
class TableView < Core
|
|
6
|
+
def initialize(options={})
|
|
7
|
+
headers = options[:headers] || []
|
|
8
|
+
data = options[:data] || []
|
|
9
|
+
|
|
10
|
+
unless is_data_valid?(headers, data)
|
|
11
|
+
exit 1
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
init_column_headers(headers)
|
|
15
|
+
|
|
16
|
+
init_list_store
|
|
17
|
+
|
|
18
|
+
@tree_view = Gtk::TreeView.new(@list_store)
|
|
19
|
+
@tree_view.selection.set_mode(:single)
|
|
20
|
+
|
|
21
|
+
@columns.each { |col| @tree_view.append_column(col) }
|
|
22
|
+
|
|
23
|
+
init_sortable_columns
|
|
24
|
+
|
|
25
|
+
init_data_rows(data)
|
|
26
|
+
|
|
27
|
+
$vertical_box.pack_start(@tree_view)
|
|
28
|
+
|
|
29
|
+
super(@tree_view)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def add(data, direction=:append)
|
|
33
|
+
return if data.size.zero?
|
|
34
|
+
|
|
35
|
+
case direction
|
|
36
|
+
when :append
|
|
37
|
+
iter = @list_store.append
|
|
38
|
+
when :prepend
|
|
39
|
+
iter = @list_store.prepend
|
|
40
|
+
else
|
|
41
|
+
iter = @list_store.append
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
data.each_with_index do |item, idx|
|
|
45
|
+
iter[idx] = item
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def clear
|
|
50
|
+
@list_store.clear
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def row_count
|
|
55
|
+
count = 0
|
|
56
|
+
@list_store.each { |item| count += 1 }
|
|
57
|
+
|
|
58
|
+
return count
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def remove_selected
|
|
62
|
+
iter = @tree_view.selection.selected
|
|
63
|
+
iter ? @list_store.remove(iter) : nil
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def row_clicked
|
|
67
|
+
@tree_view.signal_connect("row-activated") do |tv, path, column|
|
|
68
|
+
row = tv.selection.selected
|
|
69
|
+
|
|
70
|
+
values = []
|
|
71
|
+
|
|
72
|
+
@list_store.n_columns.times { |x| values << row.get_value(x) if row }
|
|
73
|
+
|
|
74
|
+
yield(values)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
private
|
|
79
|
+
|
|
80
|
+
def is_data_valid?(headers, data)
|
|
81
|
+
column_size = headers.size
|
|
82
|
+
|
|
83
|
+
data_is_array = data.class == Array
|
|
84
|
+
headers_is_array = headers.class == Array
|
|
85
|
+
|
|
86
|
+
valid = true
|
|
87
|
+
|
|
88
|
+
unless data_is_array
|
|
89
|
+
puts "=====[MittensUi: Critical Error]====="
|
|
90
|
+
puts "Incoming data must be an Array of Arrays: data = [ [el..], [el...] ]"
|
|
91
|
+
valid = false
|
|
92
|
+
return valid
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
unless headers_is_array
|
|
96
|
+
puts "=====[MittensUi: Critical Error]====="
|
|
97
|
+
puts "Incoming data must be an Array of Arrays: data = [ [el..], [el...] ]"
|
|
98
|
+
valid = false
|
|
99
|
+
return valid
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
data.each_with_index do |row, idx|
|
|
103
|
+
# Row data must be an Array.
|
|
104
|
+
# The size of the Row Array must match the size of the Header columns.
|
|
105
|
+
valid = row.class == Array && column_size == row.size ? true : false
|
|
106
|
+
|
|
107
|
+
unless valid
|
|
108
|
+
puts
|
|
109
|
+
puts "=====[MittensUi: Critical Error]====="
|
|
110
|
+
puts "The length of your data(Row) must match the length of the headers."
|
|
111
|
+
puts "Failed at Row: #{idx}"
|
|
112
|
+
puts "Row Length: #{row.size} elements"
|
|
113
|
+
puts "Header Length #{column_size} elements"
|
|
114
|
+
puts
|
|
115
|
+
return valid
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def init_sortable_columns
|
|
121
|
+
@columns.each_with_index do |col, idx|
|
|
122
|
+
col.sort_indicator = true
|
|
123
|
+
col.sort_column_id = idx
|
|
124
|
+
|
|
125
|
+
col.signal_connect('clicked') do |w|
|
|
126
|
+
w.sort_order = w.sort_order == :ascending ? :descending : :ascending
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def init_list_store
|
|
132
|
+
types = []
|
|
133
|
+
@columns.size.times { types << String }
|
|
134
|
+
@list_store = Gtk::ListStore.new(*types)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def init_data_rows(data)
|
|
138
|
+
data.each_with_index do |items_arr|
|
|
139
|
+
iter = @list_store.append
|
|
140
|
+
items_arr.each_with_index do |item, idx|
|
|
141
|
+
iter[idx] = item
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def init_column_headers(headers_list)
|
|
147
|
+
renderer = Gtk::CellRendererText.new
|
|
148
|
+
|
|
149
|
+
@columns = []
|
|
150
|
+
|
|
151
|
+
headers_list.each_with_index do |h, i|
|
|
152
|
+
next unless h.class == String
|
|
153
|
+
@columns << Gtk::TreeViewColumn.new(h, renderer, text: i)
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require_relative "./core"
|
|
2
|
+
|
|
3
|
+
module MittensUi
|
|
4
|
+
module Widgets
|
|
5
|
+
class WebLink < Core
|
|
6
|
+
attr_accessor :url
|
|
7
|
+
|
|
8
|
+
def initialize(name, url, options={})
|
|
9
|
+
@name = name || ""
|
|
10
|
+
|
|
11
|
+
@url = url || nil
|
|
12
|
+
|
|
13
|
+
@web_link = Gtk::LinkButton.new(@url, @name)
|
|
14
|
+
|
|
15
|
+
set_margin_from_opts_for(@web_link, options)
|
|
16
|
+
|
|
17
|
+
$vertical_box.pack_start(@web_link)
|
|
18
|
+
|
|
19
|
+
super(@web_link)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
data/mittens_ui.gemspec
CHANGED
|
@@ -4,9 +4,9 @@ Gem::Specification.new do |spec|
|
|
|
4
4
|
spec.name = "mittens_ui"
|
|
5
5
|
spec.version = MittensUi::VERSION
|
|
6
6
|
spec.authors = ["Zach Tuttle"]
|
|
7
|
-
spec.email = ["
|
|
8
|
-
|
|
9
|
-
spec.summary = "A tiny GUI toolkit written on top of
|
|
7
|
+
spec.email = ["tuttle_zach@icloud.com"]
|
|
8
|
+
spec.licenses = ['MIT']
|
|
9
|
+
spec.summary = "A tiny GUI toolkit written on top of GTK"
|
|
10
10
|
spec.description = "GUI Toolkit!"
|
|
11
11
|
spec.homepage = "https://github.com/tuttza/mittens_ui"
|
|
12
12
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
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.9
|
|
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:
|
|
11
|
+
date: 2021-07-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: gtk3
|
|
@@ -26,16 +26,18 @@ dependencies:
|
|
|
26
26
|
version: '0'
|
|
27
27
|
description: GUI Toolkit!
|
|
28
28
|
email:
|
|
29
|
-
-
|
|
29
|
+
- tuttle_zach@icloud.com
|
|
30
30
|
executables: []
|
|
31
31
|
extensions: []
|
|
32
32
|
extra_rdoc_files: []
|
|
33
33
|
files:
|
|
34
34
|
- ".gitignore"
|
|
35
35
|
- ".rspec"
|
|
36
|
+
- ".ruby-version"
|
|
36
37
|
- ".travis.yml"
|
|
37
38
|
- Gemfile
|
|
38
39
|
- Gemfile.lock
|
|
40
|
+
- LICENSE
|
|
39
41
|
- README.md
|
|
40
42
|
- Rakefile
|
|
41
43
|
- bin/console
|
|
@@ -44,27 +46,33 @@ files:
|
|
|
44
46
|
- examples/assets/gnome_logo.png
|
|
45
47
|
- examples/brightness_controller.rb
|
|
46
48
|
- lib/mittens_ui.rb
|
|
49
|
+
- lib/mittens_ui/dialogs/file_dialog.rb
|
|
47
50
|
- lib/mittens_ui/helpers.rb
|
|
48
51
|
- lib/mittens_ui/layouts/box.rb
|
|
49
52
|
- lib/mittens_ui/layouts/grid.rb
|
|
50
53
|
- lib/mittens_ui/version.rb
|
|
51
54
|
- lib/mittens_ui/widgets/alert.rb
|
|
52
55
|
- lib/mittens_ui/widgets/button.rb
|
|
56
|
+
- lib/mittens_ui/widgets/checkbox.rb
|
|
53
57
|
- lib/mittens_ui/widgets/core.rb
|
|
54
58
|
- lib/mittens_ui/widgets/image.rb
|
|
55
59
|
- lib/mittens_ui/widgets/label.rb
|
|
56
60
|
- lib/mittens_ui/widgets/listbox.rb
|
|
61
|
+
- lib/mittens_ui/widgets/loader.rb
|
|
57
62
|
- lib/mittens_ui/widgets/slider.rb
|
|
58
63
|
- lib/mittens_ui/widgets/switch.rb
|
|
64
|
+
- lib/mittens_ui/widgets/table_view.rb
|
|
59
65
|
- lib/mittens_ui/widgets/textbox.rb
|
|
66
|
+
- lib/mittens_ui/widgets/web_link.rb
|
|
60
67
|
- mittens_ui.gemspec
|
|
61
68
|
- notes/gtk.txt
|
|
62
69
|
homepage: https://github.com/tuttza/mittens_ui
|
|
63
|
-
licenses:
|
|
70
|
+
licenses:
|
|
71
|
+
- MIT
|
|
64
72
|
metadata:
|
|
65
73
|
homepage_uri: https://github.com/tuttza/mittens_ui
|
|
66
74
|
source_code_uri: https://github.com/tuttza/mittens_ui
|
|
67
|
-
post_install_message:
|
|
75
|
+
post_install_message:
|
|
68
76
|
rdoc_options: []
|
|
69
77
|
require_paths:
|
|
70
78
|
- lib
|
|
@@ -79,8 +87,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
79
87
|
- !ruby/object:Gem::Version
|
|
80
88
|
version: '0'
|
|
81
89
|
requirements: []
|
|
82
|
-
rubygems_version: 3.2.
|
|
83
|
-
signing_key:
|
|
90
|
+
rubygems_version: 3.2.15
|
|
91
|
+
signing_key:
|
|
84
92
|
specification_version: 4
|
|
85
|
-
summary: A tiny GUI toolkit written on top of
|
|
93
|
+
summary: A tiny GUI toolkit written on top of GTK
|
|
86
94
|
test_files: []
|