mittens_ui 0.0.7 → 0.0.11
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/.gitignore +2 -0
- data/.ruby-version +1 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +5 -2
- data/LICENSE +21 -0
- data/README.md +78 -21
- data/examples/app.rb +101 -8
- data/examples/assets/gnome_logo.png +0 -0
- data/examples/assets/mittens_ui_preview.gif +0 -0
- data/examples/contacts.rb +80 -0
- data/examples/file_menu_example.rb +52 -0
- data/examples/notify_example.rb +19 -0
- data/lib/mittens_ui.rb +40 -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 +40 -0
- data/lib/mittens_ui/checkbox.rb +24 -0
- data/lib/mittens_ui/core.rb +34 -0
- data/lib/mittens_ui/file_menu.rb +83 -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 +46 -0
- data/lib/mittens_ui/helpers.rb +41 -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 +33 -0
- data/lib/mittens_ui/notify.rb +61 -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 +53 -0
- data/lib/mittens_ui/version.rb +1 -1
- data/lib/mittens_ui/web_link.rb +22 -0
- data/mittens_ui.gemspec +3 -3
- data/notes/dev_setup.txt +14 -0
- metadata +37 -16
- data/examples/brightness_controller.rb +0 -64
- 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 -34
- data/lib/mittens_ui/widgets/label.rb +0 -41
- data/lib/mittens_ui/widgets/listbox.rb +0 -45
- data/lib/mittens_ui/widgets/slider.rb +0 -32
- data/lib/mittens_ui/widgets/switch.rb +0 -57
- data/lib/mittens_ui/widgets/textbox.rb +0 -25
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
|
|
10
|
+
has_password = options[:password].nil? ? false : options[:password]
|
|
11
|
+
|
|
12
|
+
placeholder_text = options[:placeholder] || ""
|
|
13
|
+
|
|
14
|
+
if has_password
|
|
15
|
+
@textbox.set_visibility(false)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
@textbox.set_editable(can_edit) unless can_edit.nil?
|
|
19
|
+
@textbox.set_max_length(max_length) unless max_length.nil?
|
|
20
|
+
@textbox.set_placeholder_text(placeholder_text)
|
|
21
|
+
|
|
22
|
+
super(@textbox, options)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def clear
|
|
26
|
+
@textbox.text = ""
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def enable_text_completion(data)
|
|
30
|
+
completion = Gtk::EntryCompletion.new
|
|
31
|
+
@textbox.completion = completion
|
|
32
|
+
|
|
33
|
+
model = Gtk::ListStore.new(String)
|
|
34
|
+
|
|
35
|
+
data.each do |value|
|
|
36
|
+
iter = model.append
|
|
37
|
+
iter[0] = value
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
completion.model = model
|
|
41
|
+
completion.text_column = 0
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def text
|
|
45
|
+
@textbox.text
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def render
|
|
49
|
+
$vertical_box.pack_start(@textbox)
|
|
50
|
+
return self
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
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/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")
|
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.11
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Zach Tuttle
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-08-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: gtk3
|
|
@@ -26,37 +26,58 @@ 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
|
|
42
44
|
- bin/setup
|
|
43
45
|
- examples/app.rb
|
|
44
|
-
- examples/
|
|
46
|
+
- examples/assets/gnome_logo.png
|
|
47
|
+
- examples/assets/mittens_ui_preview.gif
|
|
48
|
+
- examples/contacts.rb
|
|
49
|
+
- examples/file_menu_example.rb
|
|
50
|
+
- examples/notify_example.rb
|
|
45
51
|
- lib/mittens_ui.rb
|
|
46
|
-
- lib/mittens_ui/
|
|
47
|
-
- lib/mittens_ui/
|
|
52
|
+
- lib/mittens_ui/alert.rb
|
|
53
|
+
- lib/mittens_ui/assets/icon.png
|
|
54
|
+
- lib/mittens_ui/assets/mittens_ui_preview.gif
|
|
55
|
+
- lib/mittens_ui/button.rb
|
|
56
|
+
- lib/mittens_ui/checkbox.rb
|
|
57
|
+
- lib/mittens_ui/core.rb
|
|
58
|
+
- lib/mittens_ui/file_menu.rb
|
|
59
|
+
- lib/mittens_ui/file_picker.rb
|
|
60
|
+
- lib/mittens_ui/grid.rb
|
|
61
|
+
- lib/mittens_ui/hbox.rb
|
|
62
|
+
- lib/mittens_ui/header_bar.rb
|
|
63
|
+
- lib/mittens_ui/helpers.rb
|
|
64
|
+
- lib/mittens_ui/image.rb
|
|
65
|
+
- lib/mittens_ui/label.rb
|
|
66
|
+
- lib/mittens_ui/listbox.rb
|
|
67
|
+
- lib/mittens_ui/loader.rb
|
|
68
|
+
- lib/mittens_ui/notify.rb
|
|
69
|
+
- lib/mittens_ui/slider.rb
|
|
70
|
+
- lib/mittens_ui/switch.rb
|
|
71
|
+
- lib/mittens_ui/table_view.rb
|
|
72
|
+
- lib/mittens_ui/textbox.rb
|
|
48
73
|
- lib/mittens_ui/version.rb
|
|
49
|
-
- lib/mittens_ui/
|
|
50
|
-
- lib/mittens_ui/widgets/button.rb
|
|
51
|
-
- lib/mittens_ui/widgets/label.rb
|
|
52
|
-
- lib/mittens_ui/widgets/listbox.rb
|
|
53
|
-
- lib/mittens_ui/widgets/slider.rb
|
|
54
|
-
- lib/mittens_ui/widgets/switch.rb
|
|
55
|
-
- lib/mittens_ui/widgets/textbox.rb
|
|
74
|
+
- lib/mittens_ui/web_link.rb
|
|
56
75
|
- mittens_ui.gemspec
|
|
76
|
+
- notes/dev_setup.txt
|
|
57
77
|
- notes/gtk.txt
|
|
58
78
|
homepage: https://github.com/tuttza/mittens_ui
|
|
59
|
-
licenses:
|
|
79
|
+
licenses:
|
|
80
|
+
- MIT
|
|
60
81
|
metadata:
|
|
61
82
|
homepage_uri: https://github.com/tuttza/mittens_ui
|
|
62
83
|
source_code_uri: https://github.com/tuttza/mittens_ui
|
|
@@ -75,8 +96,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
75
96
|
- !ruby/object:Gem::Version
|
|
76
97
|
version: '0'
|
|
77
98
|
requirements: []
|
|
78
|
-
rubygems_version: 3.2.
|
|
99
|
+
rubygems_version: 3.2.22
|
|
79
100
|
signing_key:
|
|
80
101
|
specification_version: 4
|
|
81
|
-
summary: A tiny GUI toolkit written on top of
|
|
102
|
+
summary: A tiny GUI toolkit written on top of GTK
|
|
82
103
|
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
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
module MittensUi
|
|
2
|
-
module Layouts
|
|
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
|
|
10
|
-
|
|
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]
|
|
15
|
-
|
|
16
|
-
filterd_options = {
|
|
17
|
-
expaned: expand,
|
|
18
|
-
fill: fill,
|
|
19
|
-
padding: padding
|
|
20
|
-
}.freeze
|
|
21
|
-
|
|
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)
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def remove
|
|
33
|
-
return if @box.nil?
|
|
34
|
-
@box.destroy
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
module MittensUi
|
|
2
|
-
module Layouts
|
|
3
|
-
class Grid
|
|
4
|
-
def initialize(window, &block)
|
|
5
|
-
@grid = Gtk::Grid.new
|
|
6
|
-
yield(self)
|
|
7
|
-
window.add_child(@grid)
|
|
8
|
-
end
|
|
9
|
-
|
|
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]
|
|
15
|
-
|
|
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)
|
|
20
|
-
end
|
|
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
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
module MittensUi
|
|
2
|
-
module Widgets
|
|
3
|
-
class Alert
|
|
4
|
-
def initialize(message, options)
|
|
5
|
-
dialog_options = {
|
|
6
|
-
title: "Alert",
|
|
7
|
-
parent: $app_window,
|
|
8
|
-
flags: [:modal, :destroy_with_parent],
|
|
9
|
-
:buttons => [["_OK", :none]]
|
|
10
|
-
}.freeze
|
|
11
|
-
|
|
12
|
-
alert_dialog = Gtk::Dialog.new(dialog_options)
|
|
13
|
-
alert_dialog.set_transient_for($app_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)
|
|
18
|
-
|
|
19
|
-
message_label = Gtk::Label.new(message)
|
|
20
|
-
message_label.set_margin_top(65)
|
|
21
|
-
|
|
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
|
|
28
|
-
|
|
29
|
-
response == :none ? alert_dialog.destroy : alert_dialog.destroy
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
module MittensUi
|
|
2
|
-
module Widgets
|
|
3
|
-
class Button
|
|
4
|
-
def initialize(options={})
|
|
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
|
-
$vertical_box.pack_start(@button)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def click
|
|
23
|
-
@button.signal_connect "clicked" do |button_widget|
|
|
24
|
-
yield(button_widget)
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def remove
|
|
29
|
-
return if @button.nil?
|
|
30
|
-
@button.destroy
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
module MittensUi
|
|
2
|
-
module Widgets
|
|
3
|
-
class Label
|
|
4
|
-
def initialize(text, options)
|
|
5
|
-
if text.nil? || text == "" || text == " "
|
|
6
|
-
text = "Label"
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
margin_top = options[:top].nil? ? nil : options[:top]
|
|
10
|
-
margin_bottom = options[:bottom].nil? ? nil : options[:bottom]
|
|
11
|
-
margin_right = options[:right].nil? ? nil : options[:right]
|
|
12
|
-
margin_left = options[:left].nil? ? nil : options[:left]
|
|
13
|
-
|
|
14
|
-
@label = Gtk::Label.new(text)
|
|
15
|
-
|
|
16
|
-
unless margin_top.nil?
|
|
17
|
-
@label.set_margin_top(margin_top)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
unless margin_bottom.nil?
|
|
21
|
-
@label.set_margin_bottom(margin_top)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
unless margin_left.nil?
|
|
25
|
-
@label.set_margin_left(margin_left)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
unless margin_right.nil?
|
|
29
|
-
@label.set_margin_right(margin_right)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
$vertical_box.pack_start(@label)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def remove
|
|
36
|
-
return if @label.nil?
|
|
37
|
-
@label.destroy
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|