mittens_ui 0.0.9 → 0.0.10
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 +1 -1
- data/Gemfile.lock +2 -2
- data/README.md +65 -61
- data/examples/app.rb +9 -1
- data/examples/assets/mittens_ui_preview.gif +0 -0
- data/examples/contacts.rb +75 -0
- data/lib/mittens_ui.rb +21 -67
- data/lib/mittens_ui/alert.rb +32 -0
- data/lib/mittens_ui/assets/icon.png +0 -0
- data/lib/mittens_ui/assets/mittens_ui_preview.gif +0 -0
- data/lib/mittens_ui/button.rb +29 -0
- data/lib/mittens_ui/checkbox.rb +24 -0
- data/lib/mittens_ui/core.rb +34 -0
- data/lib/mittens_ui/file_picker.rb +29 -0
- data/lib/mittens_ui/grid.rb +29 -0
- data/lib/mittens_ui/hbox.rb +56 -0
- data/lib/mittens_ui/header_bar.rb +48 -0
- data/lib/mittens_ui/image.rb +46 -0
- data/lib/mittens_ui/label.rb +19 -0
- data/lib/mittens_ui/listbox.rb +47 -0
- data/lib/mittens_ui/loader.rb +35 -0
- data/lib/mittens_ui/slider.rb +32 -0
- data/lib/mittens_ui/switch.rb +36 -0
- data/lib/mittens_ui/table_view.rb +179 -0
- data/lib/mittens_ui/textbox.rb +31 -0
- data/lib/mittens_ui/version.rb +1 -1
- data/lib/mittens_ui/web_link.rb +22 -0
- data/notes/dev_setup.txt +14 -0
- metadata +28 -23
- data/examples/brightness_controller.rb +0 -64
- data/lib/mittens_ui/dialogs/file_dialog.rb +0 -29
- data/lib/mittens_ui/layouts/box.rb +0 -38
- data/lib/mittens_ui/layouts/grid.rb +0 -31
- data/lib/mittens_ui/widgets/alert.rb +0 -33
- data/lib/mittens_ui/widgets/button.rb +0 -25
- data/lib/mittens_ui/widgets/checkbox.rb +0 -28
- data/lib/mittens_ui/widgets/core.rb +0 -32
- data/lib/mittens_ui/widgets/image.rb +0 -36
- data/lib/mittens_ui/widgets/label.rb +0 -21
- data/lib/mittens_ui/widgets/listbox.rb +0 -45
- data/lib/mittens_ui/widgets/loader.rb +0 -34
- data/lib/mittens_ui/widgets/slider.rb +0 -31
- data/lib/mittens_ui/widgets/switch.rb +0 -37
- data/lib/mittens_ui/widgets/table_view.rb +0 -159
- data/lib/mittens_ui/widgets/textbox.rb +0 -28
- data/lib/mittens_ui/widgets/web_link.rb +0 -23
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require_relative "./core"
|
|
2
|
+
|
|
3
|
+
module MittensUi
|
|
4
|
+
class Switch < Core
|
|
5
|
+
def initialize(options = {})
|
|
6
|
+
@switch = Gtk::Switch.new
|
|
7
|
+
@switch.set_active(false)
|
|
8
|
+
|
|
9
|
+
# We need a Grid within our global $vertical_box layout
|
|
10
|
+
# in order to make the Widget look good (meaning not overly streched).
|
|
11
|
+
@grid = Gtk::Grid.new
|
|
12
|
+
@grid.set_column_spacing(1)
|
|
13
|
+
@grid.set_row_spacing(1)
|
|
14
|
+
@grid.attach(@switch, 0, 0, 1, 1)
|
|
15
|
+
|
|
16
|
+
super(@switch, options)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def activate
|
|
20
|
+
@switch.signal_connect('notify::active') do |switch_widget|
|
|
21
|
+
switch_widget.active? ? switch_widget.set_active(true) : switch_widget.set_active(false)
|
|
22
|
+
yield
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
alias :on :activate
|
|
26
|
+
|
|
27
|
+
def render
|
|
28
|
+
$vertical_box.pack_start(@grid)
|
|
29
|
+
return self
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def status
|
|
33
|
+
@switch.active? ? :on : :off
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
require_relative "./core"
|
|
2
|
+
|
|
3
|
+
module MittensUi
|
|
4
|
+
class TableView < Core
|
|
5
|
+
|
|
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
|
+
@scrolled_window = Gtk::ScrolledWindow.new
|
|
19
|
+
calc_min_height = (data.size ** 2 ) * 10
|
|
20
|
+
@scrolled_window.min_content_height = calc_min_height
|
|
21
|
+
|
|
22
|
+
@tree_view = Gtk::TreeView.new(@list_store)
|
|
23
|
+
@tree_view.selection.set_mode(:single)
|
|
24
|
+
|
|
25
|
+
@columns.each { |col| @tree_view.append_column(col) }
|
|
26
|
+
|
|
27
|
+
init_sortable_columns
|
|
28
|
+
|
|
29
|
+
init_data_rows(data)
|
|
30
|
+
|
|
31
|
+
@scrolled_window.add(@tree_view)
|
|
32
|
+
|
|
33
|
+
super(@tree_view, options)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def add(data, direction=:append)
|
|
37
|
+
return if data.size.zero?
|
|
38
|
+
|
|
39
|
+
case direction
|
|
40
|
+
when :append
|
|
41
|
+
iter = @list_store.append
|
|
42
|
+
when :prepend
|
|
43
|
+
iter = @list_store.prepend
|
|
44
|
+
else
|
|
45
|
+
iter = @list_store.append
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
data.each_with_index do |item, idx|
|
|
49
|
+
iter[idx] = item
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def clear
|
|
54
|
+
@list_store.clear
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def render
|
|
58
|
+
$vertical_box.pack_start(@scrolled_window)
|
|
59
|
+
return self
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def row_count
|
|
63
|
+
count = 0
|
|
64
|
+
@list_store.each { |item| count += 1 }
|
|
65
|
+
|
|
66
|
+
return count
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def remove_selected
|
|
70
|
+
iter = @tree_view.selection.selected
|
|
71
|
+
|
|
72
|
+
values = []
|
|
73
|
+
|
|
74
|
+
if iter.nil?
|
|
75
|
+
return values
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
@list_store.n_columns.times do |x|
|
|
79
|
+
values << @list_store.get_value(iter, x)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
@list_store.remove(iter)
|
|
83
|
+
|
|
84
|
+
return values
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def row_clicked
|
|
88
|
+
@tree_view.signal_connect("row-activated") do |tv, path, column|
|
|
89
|
+
row = tv.selection.selected
|
|
90
|
+
|
|
91
|
+
values = []
|
|
92
|
+
|
|
93
|
+
@list_store.n_columns.times { |x| values << row.get_value(x) if row }
|
|
94
|
+
|
|
95
|
+
yield(values)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
private
|
|
100
|
+
|
|
101
|
+
def is_data_valid?(headers, data)
|
|
102
|
+
column_size = headers.size
|
|
103
|
+
|
|
104
|
+
data_is_array = data.class == Array
|
|
105
|
+
headers_is_array = headers.class == Array
|
|
106
|
+
|
|
107
|
+
valid = true
|
|
108
|
+
|
|
109
|
+
unless data_is_array
|
|
110
|
+
puts "=====[MittensUi: Critical Error]====="
|
|
111
|
+
puts "Incoming data must be an Array of Arrays: data = [ [el..], [el...] ]"
|
|
112
|
+
valid = false
|
|
113
|
+
return valid
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
unless headers_is_array
|
|
117
|
+
puts "=====[MittensUi: Critical Error]====="
|
|
118
|
+
puts "Incoming data must be an Array of Arrays: data = [ [el..], [el...] ]"
|
|
119
|
+
valid = false
|
|
120
|
+
return valid
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
data.each_with_index do |row, idx|
|
|
124
|
+
# Row data must be an Array.
|
|
125
|
+
# The size of the Row Array must match the size of the Header columns.
|
|
126
|
+
valid = (row.class == Array && column_size == row.size) ? true : false
|
|
127
|
+
|
|
128
|
+
unless valid
|
|
129
|
+
puts
|
|
130
|
+
puts "=====[MittensUi: Critical Error]====="
|
|
131
|
+
puts "The length of your data(Row) must match the length of the headers."
|
|
132
|
+
puts "Failed at Row: #{idx}"
|
|
133
|
+
puts "Row Length: #{row.size} elements"
|
|
134
|
+
puts "Header Length #{column_size} elements"
|
|
135
|
+
puts
|
|
136
|
+
return valid
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def init_sortable_columns
|
|
142
|
+
@columns.each_with_index do |col, idx|
|
|
143
|
+
col.sort_indicator = true
|
|
144
|
+
col.sort_column_id = idx
|
|
145
|
+
|
|
146
|
+
col.signal_connect('clicked') do |w|
|
|
147
|
+
w.sort_order = w.sort_order == :ascending ? :descending : :ascending
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def init_list_store
|
|
153
|
+
types = []
|
|
154
|
+
@columns.size.times { types << String }
|
|
155
|
+
@list_store = Gtk::ListStore.new(*types)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def init_data_rows(data)
|
|
159
|
+
data.each_with_index do |items_arr|
|
|
160
|
+
iter = @list_store.append
|
|
161
|
+
items_arr.each_with_index do |item, idx|
|
|
162
|
+
iter[idx] = item
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def init_column_headers(headers_list)
|
|
168
|
+
renderer = Gtk::CellRendererText.new
|
|
169
|
+
|
|
170
|
+
@columns = []
|
|
171
|
+
|
|
172
|
+
headers_list.each_with_index do |h, i|
|
|
173
|
+
next unless h.class == String
|
|
174
|
+
@columns << Gtk::TreeViewColumn.new(h, renderer, text: i)
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
end
|
|
179
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require_relative "./core"
|
|
2
|
+
|
|
3
|
+
module MittensUi
|
|
4
|
+
class Textbox < Core
|
|
5
|
+
def initialize(options={})
|
|
6
|
+
@textbox = Gtk::Entry.new
|
|
7
|
+
can_edit = options[:can_edit].nil? ? true : options[:can_edit]
|
|
8
|
+
max_length = options[:max_length].nil? ? 200 : options[:max_length]
|
|
9
|
+
placeholder_text = options[:placeholder] || ""
|
|
10
|
+
|
|
11
|
+
@textbox.set_editable(can_edit) unless can_edit.nil?
|
|
12
|
+
@textbox.set_max_length(max_length) unless max_length.nil?
|
|
13
|
+
@textbox.set_placeholder_text(placeholder_text)
|
|
14
|
+
|
|
15
|
+
super(@textbox, options)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def clear
|
|
19
|
+
@textbox.text = ""
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def text
|
|
23
|
+
@textbox.text
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def render
|
|
27
|
+
$vertical_box.pack_start(@textbox)
|
|
28
|
+
return self
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
data/lib/mittens_ui/version.rb
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require_relative "./core"
|
|
2
|
+
|
|
3
|
+
module MittensUi
|
|
4
|
+
class WebLink < Core
|
|
5
|
+
attr_accessor :url
|
|
6
|
+
|
|
7
|
+
def initialize(name, url, options={})
|
|
8
|
+
@name = name || ""
|
|
9
|
+
|
|
10
|
+
@url = url || nil
|
|
11
|
+
|
|
12
|
+
@web_link = Gtk::LinkButton.new(@url, @name)
|
|
13
|
+
|
|
14
|
+
super(@web_link, options)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def render
|
|
18
|
+
$vertical_box.pack_start(@web_link)
|
|
19
|
+
return self
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
data/notes/dev_setup.txt
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
====[ OS stuff ]====
|
|
2
|
+
I use Ubuntu 99% of the time when developing Mittens.
|
|
3
|
+
|
|
4
|
+
sudo apt install build-essential git sqlite3 lib-gtk-3*
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
====[ Ruby ]====
|
|
8
|
+
|
|
9
|
+
First install Ruby:
|
|
10
|
+
|
|
11
|
+
https://github.com/postmodern/ruby-install#readme
|
|
12
|
+
|
|
13
|
+
Make sure to add the path of the new ruby installation
|
|
14
|
+
to your $PATH.
|
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.10
|
|
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: 2021-07
|
|
11
|
+
date: 2021-08-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: gtk3
|
|
@@ -44,27 +44,32 @@ files:
|
|
|
44
44
|
- bin/setup
|
|
45
45
|
- examples/app.rb
|
|
46
46
|
- examples/assets/gnome_logo.png
|
|
47
|
-
- examples/
|
|
47
|
+
- examples/assets/mittens_ui_preview.gif
|
|
48
|
+
- examples/contacts.rb
|
|
48
49
|
- lib/mittens_ui.rb
|
|
49
|
-
- lib/mittens_ui/
|
|
50
|
+
- lib/mittens_ui/alert.rb
|
|
51
|
+
- lib/mittens_ui/assets/icon.png
|
|
52
|
+
- lib/mittens_ui/assets/mittens_ui_preview.gif
|
|
53
|
+
- lib/mittens_ui/button.rb
|
|
54
|
+
- lib/mittens_ui/checkbox.rb
|
|
55
|
+
- lib/mittens_ui/core.rb
|
|
56
|
+
- lib/mittens_ui/file_picker.rb
|
|
57
|
+
- lib/mittens_ui/grid.rb
|
|
58
|
+
- lib/mittens_ui/hbox.rb
|
|
59
|
+
- lib/mittens_ui/header_bar.rb
|
|
50
60
|
- lib/mittens_ui/helpers.rb
|
|
51
|
-
- lib/mittens_ui/
|
|
52
|
-
- lib/mittens_ui/
|
|
61
|
+
- lib/mittens_ui/image.rb
|
|
62
|
+
- lib/mittens_ui/label.rb
|
|
63
|
+
- lib/mittens_ui/listbox.rb
|
|
64
|
+
- lib/mittens_ui/loader.rb
|
|
65
|
+
- lib/mittens_ui/slider.rb
|
|
66
|
+
- lib/mittens_ui/switch.rb
|
|
67
|
+
- lib/mittens_ui/table_view.rb
|
|
68
|
+
- lib/mittens_ui/textbox.rb
|
|
53
69
|
- lib/mittens_ui/version.rb
|
|
54
|
-
- lib/mittens_ui/
|
|
55
|
-
- lib/mittens_ui/widgets/button.rb
|
|
56
|
-
- lib/mittens_ui/widgets/checkbox.rb
|
|
57
|
-
- lib/mittens_ui/widgets/core.rb
|
|
58
|
-
- lib/mittens_ui/widgets/image.rb
|
|
59
|
-
- lib/mittens_ui/widgets/label.rb
|
|
60
|
-
- lib/mittens_ui/widgets/listbox.rb
|
|
61
|
-
- lib/mittens_ui/widgets/loader.rb
|
|
62
|
-
- lib/mittens_ui/widgets/slider.rb
|
|
63
|
-
- lib/mittens_ui/widgets/switch.rb
|
|
64
|
-
- lib/mittens_ui/widgets/table_view.rb
|
|
65
|
-
- lib/mittens_ui/widgets/textbox.rb
|
|
66
|
-
- lib/mittens_ui/widgets/web_link.rb
|
|
70
|
+
- lib/mittens_ui/web_link.rb
|
|
67
71
|
- mittens_ui.gemspec
|
|
72
|
+
- notes/dev_setup.txt
|
|
68
73
|
- notes/gtk.txt
|
|
69
74
|
homepage: https://github.com/tuttza/mittens_ui
|
|
70
75
|
licenses:
|
|
@@ -72,7 +77,7 @@ licenses:
|
|
|
72
77
|
metadata:
|
|
73
78
|
homepage_uri: https://github.com/tuttza/mittens_ui
|
|
74
79
|
source_code_uri: https://github.com/tuttza/mittens_ui
|
|
75
|
-
post_install_message:
|
|
80
|
+
post_install_message:
|
|
76
81
|
rdoc_options: []
|
|
77
82
|
require_paths:
|
|
78
83
|
- lib
|
|
@@ -87,8 +92,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
87
92
|
- !ruby/object:Gem::Version
|
|
88
93
|
version: '0'
|
|
89
94
|
requirements: []
|
|
90
|
-
rubygems_version: 3.2.
|
|
91
|
-
signing_key:
|
|
95
|
+
rubygems_version: 3.2.22
|
|
96
|
+
signing_key:
|
|
92
97
|
specification_version: 4
|
|
93
98
|
summary: A tiny GUI toolkit written on top of GTK
|
|
94
99
|
test_files: []
|
|
@@ -1,64 +0,0 @@
|
|
|
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
|