mittens_ui 0.0.3 → 0.0.8
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 +38 -16
- data/examples/app.rb +38 -16
- data/examples/assets/gnome_logo.png +0 -0
- data/examples/brightness_controller.rb +64 -0
- data/lib/mittens_ui.rb +29 -51
- data/lib/mittens_ui/helpers.rb +27 -0
- data/lib/mittens_ui/version.rb +1 -1
- data/lib/mittens_ui/widgets/alert.rb +3 -3
- data/lib/mittens_ui/widgets/button.rb +13 -22
- data/lib/mittens_ui/widgets/core.rb +28 -0
- data/lib/mittens_ui/widgets/image.rb +36 -0
- data/lib/mittens_ui/widgets/label.rb +10 -28
- data/lib/mittens_ui/widgets/listbox.rb +9 -12
- data/lib/mittens_ui/widgets/slider.rb +15 -16
- data/lib/mittens_ui/widgets/switch.rb +37 -0
- data/lib/mittens_ui/widgets/textbox.rb +6 -11
- data/mittens_ui.gemspec +1 -1
- metadata +10 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2de74ee20b66d0c56c6ba2eb8cb7316ebbf57deebe990615decce1eb0008fd9e
|
|
4
|
+
data.tar.gz: 93ad5cde1ef87a5bce92fb8db71d02b812f980777ea84d47dbb4a9c29bb75bc0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 51353cb720d6be4c84e8198642368292a3313510e1f683d129c83f30d55ac46e0a07d933dcec679b14eea20229796124e80324f34e2959ac02ecf6bbd0e96c5b
|
|
7
|
+
data.tar.gz: fbe1746d213f60ae5bde487b81ed6b13f455ac1b5d82c3762d150d2a47874380f06001c57fbdb20f0fa4705a42d08d4efb1c953acdc83ec22e33cf79251785b2
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -27,33 +27,55 @@ require "mittens_ui"
|
|
|
27
27
|
|
|
28
28
|
app_options = {
|
|
29
29
|
name: "say_hello",
|
|
30
|
-
title: "Say Hello!",
|
|
31
|
-
height:
|
|
32
|
-
width:
|
|
30
|
+
title: "The Say Hello App!",
|
|
31
|
+
height: 650,
|
|
32
|
+
width: 550,
|
|
33
33
|
can_resize: true
|
|
34
34
|
}.freeze
|
|
35
35
|
|
|
36
|
-
MittensUi::Application.Window(app_options) do
|
|
37
|
-
|
|
38
|
-
MittensUi::Label("Enter Name:", layout, label_opts)
|
|
36
|
+
MittensUi::Application.Window(app_options) do
|
|
37
|
+
MittensUi::Label("Enter Name:", top: 30)
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
text_box = MittensUi::Textbox(layout, textbox_options)
|
|
39
|
+
text_box = MittensUi::Textbox(can_edit: true)
|
|
42
40
|
|
|
43
41
|
listbox_options = {
|
|
44
|
-
top: 10,
|
|
42
|
+
top: 10,
|
|
45
43
|
items: ["item_1", "item_2", "item_3"]
|
|
46
44
|
}.freeze
|
|
47
|
-
listbox = MittensUi::ListBox(layout, listbox_options)
|
|
48
45
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
listbox = MittensUi::ListBox(listbox_options)
|
|
47
|
+
|
|
48
|
+
btn = MittensUi::Button(title: "Click Here")
|
|
49
|
+
btn.click {|_b| MittensUi::Alert("Hello #{text_box.text} AND! #{listbox.selected_value} was selected.") }
|
|
50
|
+
|
|
51
|
+
s = MittensUi::Slider({ start_value: 1, stop_value: 100, initial_value: 30 })
|
|
52
|
+
s.slide { |s| puts s.value }
|
|
53
|
+
|
|
54
|
+
img_opts = {
|
|
55
|
+
tooltip_text: "The Gnome LOGO!",
|
|
56
|
+
width: 200,
|
|
57
|
+
height: 200,
|
|
58
|
+
left: 50
|
|
59
|
+
}.freeze
|
|
60
|
+
|
|
61
|
+
img = MittensUi::Image("./assets/gnome_logo.png", img_opts)
|
|
62
|
+
|
|
63
|
+
switch = MittensUi::Switch(left: 120 )
|
|
64
|
+
|
|
65
|
+
img.click do
|
|
66
|
+
unless switch.hidden?
|
|
67
|
+
switch.show
|
|
68
|
+
else
|
|
69
|
+
switch.hide
|
|
70
|
+
end
|
|
52
71
|
end
|
|
53
72
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
73
|
+
switch.on do
|
|
74
|
+
unless img.hidden?
|
|
75
|
+
img.show
|
|
76
|
+
else
|
|
77
|
+
img.hide
|
|
78
|
+
end
|
|
57
79
|
end
|
|
58
80
|
end
|
|
59
81
|
```
|
data/examples/app.rb
CHANGED
|
@@ -2,32 +2,54 @@ require '../lib/mittens_ui'
|
|
|
2
2
|
|
|
3
3
|
app_options = {
|
|
4
4
|
name: "say_hello",
|
|
5
|
-
title: "Say Hello!",
|
|
6
|
-
height:
|
|
7
|
-
width:
|
|
5
|
+
title: "The Say Hello App!",
|
|
6
|
+
height: 650,
|
|
7
|
+
width: 550,
|
|
8
8
|
can_resize: true
|
|
9
9
|
}.freeze
|
|
10
10
|
|
|
11
|
-
MittensUi::Application.Window(app_options) do
|
|
12
|
-
|
|
13
|
-
MittensUi::Label("Enter Name:", layout, label_opts)
|
|
11
|
+
MittensUi::Application.Window(app_options) do
|
|
12
|
+
MittensUi::Label("Enter Name:", top: 30)
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
text_box = MittensUi::Textbox(layout, textbox_options)
|
|
14
|
+
text_box = MittensUi::Textbox(can_edit: true)
|
|
17
15
|
|
|
18
16
|
listbox_options = {
|
|
19
|
-
top: 10,
|
|
17
|
+
top: 10,
|
|
20
18
|
items: ["item_1", "item_2", "item_3"]
|
|
21
19
|
}.freeze
|
|
22
|
-
listbox = MittensUi::ListBox(layout, listbox_options)
|
|
23
20
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
listbox = MittensUi::ListBox(listbox_options)
|
|
22
|
+
|
|
23
|
+
btn = MittensUi::Button(title: "Click Here")
|
|
24
|
+
btn.click {|_b| MittensUi::Alert("Hello #{text_box.text} AND! #{listbox.selected_value} was selected.") }
|
|
25
|
+
|
|
26
|
+
s = MittensUi::Slider({ start_value: 1, stop_value: 100, initial_value: 30 })
|
|
27
|
+
s.slide { |s| puts s.value }
|
|
28
|
+
|
|
29
|
+
img_opts = {
|
|
30
|
+
tooltip_text: "The Gnome LOGO!",
|
|
31
|
+
width: 200,
|
|
32
|
+
height: 200,
|
|
33
|
+
left: 50
|
|
34
|
+
}.freeze
|
|
35
|
+
|
|
36
|
+
img = MittensUi::Image("./assets/gnome_logo.png", img_opts)
|
|
37
|
+
|
|
38
|
+
switch = MittensUi::Switch(left: 120 )
|
|
39
|
+
|
|
40
|
+
img.click do
|
|
41
|
+
unless switch.hidden?
|
|
42
|
+
switch.show
|
|
43
|
+
else
|
|
44
|
+
switch.hide
|
|
45
|
+
end
|
|
27
46
|
end
|
|
28
47
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
48
|
+
switch.on do
|
|
49
|
+
unless img.hidden?
|
|
50
|
+
img.show
|
|
51
|
+
else
|
|
52
|
+
img.hide
|
|
53
|
+
end
|
|
32
54
|
end
|
|
33
55
|
end
|
|
Binary file
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#! /usr/bin/ruby
|
|
2
|
+
|
|
3
|
+
require 'mittens_ui'
|
|
4
|
+
|
|
5
|
+
app_options = {
|
|
6
|
+
name: "brightness_controller",
|
|
7
|
+
title: "Brightness Controller",
|
|
8
|
+
height: 350,
|
|
9
|
+
width: 350,
|
|
10
|
+
can_resize: true
|
|
11
|
+
}.freeze
|
|
12
|
+
|
|
13
|
+
class Brightness
|
|
14
|
+
attr_accessor :max_value, :current_value
|
|
15
|
+
|
|
16
|
+
def initialize
|
|
17
|
+
# Only works for on-board Intel based graphics.
|
|
18
|
+
@current_path = "/sys/class/backlight/intel_backlight/brightness"
|
|
19
|
+
@current_value = get_current
|
|
20
|
+
@max_path = "/sys/class/backlight/intel_backlight/max_brightness"
|
|
21
|
+
@max_value = get_max
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def set(value)
|
|
25
|
+
File.write(@current_path, value)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def is_root?
|
|
29
|
+
case Process.uid
|
|
30
|
+
when 0 then true
|
|
31
|
+
else false
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def get_max
|
|
38
|
+
File.open(@max_path, "r") { |f| f.read }.strip
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def get_current
|
|
42
|
+
File.open(@current_path, "r") { |f| f.read }.strip
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
MittensUi::Application.Window(app_options) do
|
|
47
|
+
brightness = Brightness.new
|
|
48
|
+
|
|
49
|
+
unless brightness.is_root?
|
|
50
|
+
MittensUi::Alert(window, "To change your screen brightness level you must run this App as root.")
|
|
51
|
+
window
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
MittensUi::Label("Current Brightness Level:", top: 25)
|
|
55
|
+
|
|
56
|
+
slider_opts = {
|
|
57
|
+
start_value: 1,
|
|
58
|
+
stop_value: brightness.max_value,
|
|
59
|
+
initial_value: brightness.current_value
|
|
60
|
+
}.freeze
|
|
61
|
+
|
|
62
|
+
brightness_slider = MittensUi::Slider(layout, slider_opts)
|
|
63
|
+
brightness.set(brightness_slider.value.to_i.to_s)
|
|
64
|
+
end
|
data/lib/mittens_ui.rb
CHANGED
|
@@ -5,73 +5,51 @@ require "mittens_ui/widgets/button"
|
|
|
5
5
|
require "mittens_ui/widgets/textbox"
|
|
6
6
|
require "mittens_ui/widgets/listbox"
|
|
7
7
|
require "mittens_ui/widgets/slider"
|
|
8
|
+
require "mittens_ui/widgets/switch"
|
|
9
|
+
require "mittens_ui/widgets/image"
|
|
8
10
|
|
|
9
11
|
require "gtk3"
|
|
10
12
|
|
|
11
13
|
module MittensUi
|
|
12
14
|
class Error < StandardError; end
|
|
13
15
|
|
|
14
|
-
def self.
|
|
15
|
-
|
|
16
|
-
slider = MittensUi::Widgets::Slider.new(layout, options, &block)
|
|
17
|
-
Application.set_visible_elements(slider)
|
|
18
|
-
return slider
|
|
16
|
+
def self.Image(path, options={})
|
|
17
|
+
MittensUi::Widgets::Image.new(path, options)
|
|
19
18
|
end
|
|
20
19
|
|
|
21
|
-
def self.
|
|
22
|
-
|
|
23
|
-
Application.set_visible_elements(list_box)
|
|
24
|
-
return list_box
|
|
20
|
+
def self.Switch(options = {})
|
|
21
|
+
MittensUi::Widgets::Switch.new(options)
|
|
25
22
|
end
|
|
26
23
|
|
|
27
|
-
def self.
|
|
28
|
-
|
|
29
|
-
Application.set_visible_elements(alert)
|
|
30
|
-
return alert
|
|
24
|
+
def self.Slider(options = {})
|
|
25
|
+
MittensUi::Widgets::Slider.new(options)
|
|
31
26
|
end
|
|
32
27
|
|
|
33
|
-
def self.
|
|
34
|
-
|
|
35
|
-
Application.set_visible_elements(label)
|
|
36
|
-
return label
|
|
28
|
+
def self.ListBox(options = {})
|
|
29
|
+
MittensUi::Widgets::ListBox.new(options)
|
|
37
30
|
end
|
|
38
31
|
|
|
39
|
-
def self.
|
|
40
|
-
|
|
41
|
-
Application.set_visible_elements(textbox)
|
|
42
|
-
return textbox
|
|
32
|
+
def self.Alert(message, options = {})
|
|
33
|
+
MittensUi::Widgets::Alert.new(message, options)
|
|
43
34
|
end
|
|
44
35
|
|
|
45
|
-
def self.
|
|
46
|
-
|
|
47
|
-
button = MittensUi::Widgets::Button.new(layout, options, &block)
|
|
48
|
-
Application.set_visible_elements(button)
|
|
49
|
-
return button
|
|
36
|
+
def self.Label(text, options = {})
|
|
37
|
+
MittensUi::Widgets::Label.new(text, options)
|
|
50
38
|
end
|
|
51
39
|
|
|
52
|
-
def self.
|
|
53
|
-
|
|
54
|
-
|
|
40
|
+
def self.Textbox(options = {})
|
|
41
|
+
MittensUi::Widgets::Textbox.new(options)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def self.Button(options = {})
|
|
45
|
+
MittensUi::Widgets::Button.new(options)
|
|
55
46
|
end
|
|
56
47
|
|
|
57
48
|
class Application
|
|
58
49
|
class << self
|
|
59
50
|
def Window(options = {}, &block)
|
|
60
|
-
@@visible_elements = []
|
|
61
51
|
init_gtk_application(options, block)
|
|
62
52
|
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 = []
|
|
74
|
-
end
|
|
75
53
|
|
|
76
54
|
private
|
|
77
55
|
|
|
@@ -95,16 +73,16 @@ module MittensUi
|
|
|
95
73
|
app = Gtk::Application.new(gtk_app_name, :flags_none)
|
|
96
74
|
|
|
97
75
|
app.signal_connect("activate") do |application|
|
|
98
|
-
app_window = Gtk::ApplicationWindow.new(application)
|
|
76
|
+
$app_window = Gtk::ApplicationWindow.new(application)
|
|
99
77
|
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
|
|
78
|
+
$vertical_box = Gtk::Box.new(:vertical, 10)
|
|
79
|
+
scrolled_window.add($vertical_box)
|
|
80
|
+
$app_window.add(scrolled_window)
|
|
81
|
+
block.call($app_window, $vertical_box)
|
|
82
|
+
$app_window.set_size_request(width, height)
|
|
83
|
+
$app_window.set_title(title)
|
|
84
|
+
$app_window.set_resizable(can_resize)
|
|
85
|
+
$app_window.show_all
|
|
108
86
|
end
|
|
109
87
|
|
|
110
88
|
app.run
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module MittensUi
|
|
2
|
+
module Helpers
|
|
3
|
+
def set_margin_from_opts_for(widget, options={})
|
|
4
|
+
margin_top = options[:top].nil? ? nil : options[:top]
|
|
5
|
+
margin_bottom = options[:bottom].nil? ? nil : options[:bottom]
|
|
6
|
+
margin_right = options[:right].nil? ? nil : options[:right]
|
|
7
|
+
margin_left = options[:left].nil? ? nil : options[:left]
|
|
8
|
+
|
|
9
|
+
unless margin_top.nil?
|
|
10
|
+
widget.set_margin_top(margin_top)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
unless margin_bottom.nil?
|
|
14
|
+
widget.set_margin_bottom(margin_top)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
unless margin_left.nil?
|
|
18
|
+
widget.set_margin_left(margin_left)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
unless margin_right.nil?
|
|
22
|
+
widget.set_margin_right(margin_right)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
data/lib/mittens_ui/version.rb
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
module MittensUi
|
|
2
2
|
module Widgets
|
|
3
3
|
class Alert
|
|
4
|
-
def initialize(
|
|
4
|
+
def initialize(message, options)
|
|
5
5
|
dialog_options = {
|
|
6
6
|
title: "Alert",
|
|
7
|
-
parent:
|
|
7
|
+
parent: $app_window,
|
|
8
8
|
flags: [:modal, :destroy_with_parent],
|
|
9
9
|
:buttons => [["_OK", :none]]
|
|
10
10
|
}.freeze
|
|
11
11
|
|
|
12
12
|
alert_dialog = Gtk::Dialog.new(dialog_options)
|
|
13
|
-
alert_dialog.set_transient_for(
|
|
13
|
+
alert_dialog.set_transient_for($app_window)
|
|
14
14
|
alert_dialog.set_default_width(420)
|
|
15
15
|
alert_dialog.set_default_height(200)
|
|
16
16
|
alert_dialog.set_modal(true)
|
|
@@ -1,34 +1,25 @@
|
|
|
1
|
+
require_relative "./core"
|
|
2
|
+
|
|
1
3
|
module MittensUi
|
|
2
4
|
module Widgets
|
|
3
|
-
class Button
|
|
4
|
-
def initialize(
|
|
5
|
+
class Button < Core
|
|
6
|
+
def initialize(options={})
|
|
5
7
|
button_title = options[:title] || "Button"
|
|
6
8
|
|
|
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
9
|
@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
10
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
set_margin_from_opts_for(@button, options)
|
|
12
|
+
|
|
13
|
+
$vertical_box.pack_start(@button)
|
|
14
|
+
|
|
15
|
+
super(@button)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def click
|
|
23
19
|
@button.signal_connect "clicked" do |button_widget|
|
|
24
|
-
|
|
20
|
+
yield(button_widget)
|
|
25
21
|
end
|
|
26
22
|
end
|
|
27
|
-
|
|
28
|
-
def remove
|
|
29
|
-
return if @button.nil?
|
|
30
|
-
@button.destroy
|
|
31
|
-
end
|
|
32
23
|
end
|
|
33
24
|
end
|
|
34
25
|
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require "mittens_ui/helpers"
|
|
2
|
+
|
|
3
|
+
module MittensUi
|
|
4
|
+
module Widgets
|
|
5
|
+
class Core
|
|
6
|
+
include Helpers
|
|
7
|
+
|
|
8
|
+
# All MittenUi::Widget classes should inherit from this base class.
|
|
9
|
+
|
|
10
|
+
def initialize(widget)
|
|
11
|
+
@core_widget = widget
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def show
|
|
15
|
+
@core_widget.show_all
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def hidden?
|
|
19
|
+
@core_widget.visible?
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def hide
|
|
23
|
+
return if @core_widget.nil?
|
|
24
|
+
@core_widget.hide
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require_relative "./core"
|
|
2
|
+
|
|
3
|
+
module MittensUi
|
|
4
|
+
module Widgets
|
|
5
|
+
class Image < Core
|
|
6
|
+
attr_reader :path
|
|
7
|
+
|
|
8
|
+
def initialize(path, options = {})
|
|
9
|
+
@path = File.join(path.strip)
|
|
10
|
+
|
|
11
|
+
tooltip_text = options[:tooltip_text].nil? ? "" : options[:tooltip_text]
|
|
12
|
+
width = options[:width].nil? ? 80 : options[:width]
|
|
13
|
+
height = options[:height].nil? ? 80 : options[:height]
|
|
14
|
+
|
|
15
|
+
pixbuf = GdkPixbuf::Pixbuf.new(file: @path, width: width, height: height)
|
|
16
|
+
|
|
17
|
+
@image = Gtk::Image.new(pixbuf: pixbuf)
|
|
18
|
+
@image.tooltip_text = tooltip_text
|
|
19
|
+
|
|
20
|
+
set_margin_from_opts_for(@image, options)
|
|
21
|
+
|
|
22
|
+
@event_box = Gtk::EventBox.new.add_child(@image)
|
|
23
|
+
|
|
24
|
+
$vertical_box.pack_start(@event_box)
|
|
25
|
+
|
|
26
|
+
super(@image)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def click
|
|
30
|
+
@event_box.signal_connect("button_press_event") do
|
|
31
|
+
yield
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -1,38 +1,20 @@
|
|
|
1
|
+
require_relative "./core"
|
|
2
|
+
|
|
1
3
|
module MittensUi
|
|
2
4
|
module Widgets
|
|
3
|
-
class Label
|
|
4
|
-
def initialize(text,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
margin_right = options[:right].nil? ? nil : options[:right]
|
|
8
|
-
margin_left = options[:left].nil? ? nil : options[:left]
|
|
9
|
-
|
|
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)
|
|
5
|
+
class Label < Core
|
|
6
|
+
def initialize(text, options)
|
|
7
|
+
if text.nil? || text == "" || text == " "
|
|
8
|
+
text = "Label"
|
|
18
9
|
end
|
|
19
10
|
|
|
20
|
-
|
|
21
|
-
@label.set_margin_left(margin_left)
|
|
22
|
-
end
|
|
11
|
+
@label = Gtk::Label.new(text)
|
|
23
12
|
|
|
24
|
-
|
|
25
|
-
@label.set_margin_right(margin_right)
|
|
26
|
-
end
|
|
13
|
+
set_margin_from_opts_for(@label, options)
|
|
27
14
|
|
|
28
|
-
|
|
29
|
-
layout.pack_start(@label)
|
|
30
|
-
end
|
|
31
|
-
end
|
|
15
|
+
$vertical_box.pack_start(@label)
|
|
32
16
|
|
|
33
|
-
|
|
34
|
-
return if @label.nil?
|
|
35
|
-
@label.destroy
|
|
17
|
+
super(@label)
|
|
36
18
|
end
|
|
37
19
|
end
|
|
38
20
|
end
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
require_relative "./core"
|
|
2
|
+
|
|
1
3
|
module MittensUi
|
|
2
4
|
module Widgets
|
|
3
|
-
class ListBox
|
|
5
|
+
class ListBox < Core
|
|
4
6
|
attr_reader :items
|
|
5
7
|
|
|
6
|
-
def initialize(
|
|
7
|
-
@items
|
|
8
|
+
def initialize(options={})
|
|
9
|
+
@items = options[:items]
|
|
8
10
|
|
|
9
11
|
list_store = Gtk::ListStore.new(String)
|
|
10
12
|
|
|
@@ -24,25 +26,20 @@ module MittensUi
|
|
|
24
26
|
|
|
25
27
|
@gtk_combobox.set_active(0)
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
layout.pack_start(@gtk_combobox)
|
|
29
|
-
end
|
|
29
|
+
$vertical_box.pack_start(@gtk_combobox)
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
super(@gtk_combobox)
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
def set_selected_value(value)
|
|
35
35
|
@selected_value = value
|
|
36
36
|
end
|
|
37
|
+
alias :set_value :set_selected_value
|
|
37
38
|
|
|
38
39
|
def get_selected_value
|
|
39
40
|
@selected_value
|
|
40
41
|
end
|
|
41
|
-
|
|
42
|
-
def remove
|
|
43
|
-
return if @gtk_combobox.nil?
|
|
44
|
-
@gtk_combobox.destroy
|
|
45
|
-
end
|
|
42
|
+
alias :selected_value :get_selected_value
|
|
46
43
|
end
|
|
47
44
|
end
|
|
48
45
|
end
|
|
@@ -1,32 +1,31 @@
|
|
|
1
|
+
require_relative "./core"
|
|
2
|
+
|
|
1
3
|
module MittensUi
|
|
2
4
|
module Widgets
|
|
3
|
-
class Slider
|
|
4
|
-
def initialize(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
step_value = options[:step_value].nil? ? 1.0 : options[:step_value]
|
|
5
|
+
class Slider < Core
|
|
6
|
+
def initialize(options={})
|
|
7
|
+
start_value = options[:start_value].nil? ? 1.0 : options[:start_value]
|
|
8
|
+
stop_value = options[:stop_value].nil? ? 10.0 : options[:stop_value]
|
|
9
|
+
step_value = options[:step_value].nil? ? 1.0 : options[:step_value]
|
|
9
10
|
init_value = options[:initial_value].nil? ? 1.0 : options[:initial_value]
|
|
10
11
|
|
|
11
12
|
@scale = Gtk::Scale.new(:horizontal, start_value, stop_value, step_value)
|
|
12
|
-
puts @scale.methods
|
|
13
13
|
@scale.digits = 0
|
|
14
14
|
@scale.draw_value = true
|
|
15
15
|
@scale.value = init_value
|
|
16
16
|
|
|
17
|
-
@scale
|
|
18
|
-
block.call(scale_widget)
|
|
19
|
-
end
|
|
17
|
+
$vertical_box.pack_start(@scale)
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
layout.pack_start(@scale)
|
|
23
|
-
end
|
|
19
|
+
super(@scale)
|
|
24
20
|
end
|
|
25
21
|
|
|
26
|
-
def
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
def move
|
|
23
|
+
@scale.signal_connect "value_changed" do |scale_widget|
|
|
24
|
+
yield(scale_widget)
|
|
25
|
+
end
|
|
29
26
|
end
|
|
27
|
+
|
|
28
|
+
alias :slide :move
|
|
30
29
|
end
|
|
31
30
|
end
|
|
32
31
|
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require_relative "./core"
|
|
2
|
+
|
|
3
|
+
module MittensUi
|
|
4
|
+
module Widgets
|
|
5
|
+
class Switch < Core
|
|
6
|
+
def initialize(options = {})
|
|
7
|
+
@switch = Gtk::Switch.new
|
|
8
|
+
@switch.set_active(false)
|
|
9
|
+
|
|
10
|
+
set_margin_from_opts_for(@switch, options)
|
|
11
|
+
|
|
12
|
+
# We need a Grid within our global $vertical_box layout
|
|
13
|
+
# in order to make the Widget look good (meaning not overly streched).
|
|
14
|
+
grid = Gtk::Grid.new
|
|
15
|
+
grid.set_column_spacing(1)
|
|
16
|
+
grid.set_row_spacing(1)
|
|
17
|
+
grid.attach(@switch, 0, 0, 1, 1)
|
|
18
|
+
|
|
19
|
+
$vertical_box.pack_start(grid)
|
|
20
|
+
|
|
21
|
+
super(@switch)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def activate
|
|
25
|
+
@switch.signal_connect('notify::active') do |switch_widget|
|
|
26
|
+
switch_widget.active? ? switch_widget.set_active(true) : switch_widget.set_active(false)
|
|
27
|
+
yield
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
alias :on :activate
|
|
31
|
+
|
|
32
|
+
def status
|
|
33
|
+
@switch.active? ? 'on' : 'off'
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
require_relative "./core"
|
|
2
|
+
|
|
1
3
|
module MittensUi
|
|
2
4
|
module Widgets
|
|
3
|
-
class Textbox
|
|
4
|
-
def initialize(
|
|
5
|
+
class Textbox < Core
|
|
6
|
+
def initialize(options={})
|
|
5
7
|
@textbox = Gtk::Entry.new
|
|
6
8
|
can_edit = options[:can_edit].nil? ? true : options[:can_edit]
|
|
7
9
|
max_length = options[:max_length].nil? ? 200 : options[:max_length]
|
|
@@ -9,21 +11,14 @@ module MittensUi
|
|
|
9
11
|
@textbox.set_editable(can_edit) unless can_edit.nil?
|
|
10
12
|
@textbox.set_max_length(max_length) unless max_length.nil?
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
layout.pack_start(@textbox)
|
|
14
|
-
end
|
|
14
|
+
$vertical_box.pack_start(@textbox)
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
super(@textbox)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def text
|
|
20
20
|
@textbox.text
|
|
21
21
|
end
|
|
22
|
-
|
|
23
|
-
def remove
|
|
24
|
-
return if @textbox.nil?
|
|
25
|
-
@textbox.destroy
|
|
26
|
-
end
|
|
27
22
|
end
|
|
28
23
|
end
|
|
29
24
|
end
|
data/mittens_ui.gemspec
CHANGED
|
@@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
|
|
|
6
6
|
spec.authors = ["Zach Tuttle"]
|
|
7
7
|
spec.email = ["zachtuttle@tutanota.com"]
|
|
8
8
|
|
|
9
|
-
spec.summary = "A tiny GUI
|
|
9
|
+
spec.summary = "A tiny GUI toolkit written on top of GTK3"
|
|
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.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Zach Tuttle
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-12-
|
|
11
|
+
date: 2020-12-31 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: gtk3
|
|
@@ -41,15 +41,21 @@ files:
|
|
|
41
41
|
- bin/console
|
|
42
42
|
- bin/setup
|
|
43
43
|
- examples/app.rb
|
|
44
|
+
- examples/assets/gnome_logo.png
|
|
45
|
+
- examples/brightness_controller.rb
|
|
44
46
|
- lib/mittens_ui.rb
|
|
47
|
+
- lib/mittens_ui/helpers.rb
|
|
45
48
|
- lib/mittens_ui/layouts/box.rb
|
|
46
49
|
- lib/mittens_ui/layouts/grid.rb
|
|
47
50
|
- lib/mittens_ui/version.rb
|
|
48
51
|
- lib/mittens_ui/widgets/alert.rb
|
|
49
52
|
- lib/mittens_ui/widgets/button.rb
|
|
53
|
+
- lib/mittens_ui/widgets/core.rb
|
|
54
|
+
- lib/mittens_ui/widgets/image.rb
|
|
50
55
|
- lib/mittens_ui/widgets/label.rb
|
|
51
56
|
- lib/mittens_ui/widgets/listbox.rb
|
|
52
57
|
- lib/mittens_ui/widgets/slider.rb
|
|
58
|
+
- lib/mittens_ui/widgets/switch.rb
|
|
53
59
|
- lib/mittens_ui/widgets/textbox.rb
|
|
54
60
|
- mittens_ui.gemspec
|
|
55
61
|
- notes/gtk.txt
|
|
@@ -73,8 +79,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
73
79
|
- !ruby/object:Gem::Version
|
|
74
80
|
version: '0'
|
|
75
81
|
requirements: []
|
|
76
|
-
rubygems_version: 3.
|
|
82
|
+
rubygems_version: 3.2.3
|
|
77
83
|
signing_key:
|
|
78
84
|
specification_version: 4
|
|
79
|
-
summary: A tiny GUI
|
|
85
|
+
summary: A tiny GUI toolkit written on top of GTK3
|
|
80
86
|
test_files: []
|