mittens_ui 0.0.4 → 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 +74 -18
- data/examples/app.rb +101 -18
- data/examples/assets/gnome_logo.png +0 -0
- data/examples/brightness_controller.rb +64 -0
- data/lib/mittens_ui.rb +68 -76
- data/lib/mittens_ui/dialogs/file_dialog.rb +29 -0
- data/lib/mittens_ui/helpers.rb +27 -0
- data/lib/mittens_ui/version.rb +1 -1
- data/lib/mittens_ui/widgets/alert.rb +5 -5
- data/lib/mittens_ui/widgets/button.rb +14 -23
- data/lib/mittens_ui/widgets/checkbox.rb +28 -0
- data/lib/mittens_ui/widgets/core.rb +32 -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/loader.rb +34 -0
- data/lib/mittens_ui/widgets/slider.rb +15 -15
- data/lib/mittens_ui/widgets/switch.rb +37 -0
- data/lib/mittens_ui/widgets/table_view.rb +159 -0
- data/lib/mittens_ui/widgets/textbox.rb +10 -11
- data/lib/mittens_ui/widgets/web_link.rb +23 -0
- data/mittens_ui.gemspec +3 -3
- metadata +23 -9
|
@@ -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
|
|
@@ -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_bottom)
|
|
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
|
-
title: "Alert",
|
|
7
|
-
parent:
|
|
6
|
+
title: options[:title] || "Alert",
|
|
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)
|
|
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,33 +1,24 @@
|
|
|
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
|
-
|
|
23
|
-
@button
|
|
24
|
-
block.call(button_widget)
|
|
25
|
-
end
|
|
11
|
+
set_margin_from_opts_for(@button, options)
|
|
12
|
+
|
|
13
|
+
$vertical_box.pack_start(@button)
|
|
14
|
+
|
|
15
|
+
super(@button)
|
|
26
16
|
end
|
|
27
|
-
|
|
28
|
-
def
|
|
29
|
-
|
|
30
|
-
|
|
17
|
+
|
|
18
|
+
def click
|
|
19
|
+
@button.signal_connect("clicked") do |button_widget|
|
|
20
|
+
yield(button_widget)
|
|
21
|
+
end
|
|
31
22
|
end
|
|
32
23
|
end
|
|
33
24
|
end
|
|
@@ -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
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require "mittens_ui/helpers"
|
|
2
|
+
|
|
3
|
+
module MittensUi
|
|
4
|
+
module Widgets
|
|
5
|
+
class Core
|
|
6
|
+
include Helpers
|
|
7
|
+
|
|
8
|
+
# All MittenUi::Widgets::* 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
|
+
|
|
27
|
+
def remove
|
|
28
|
+
$vertical_box.remove(@core_widget)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
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
|
|
@@ -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
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
+
require_relative "./core"
|
|
2
|
+
|
|
1
3
|
module MittensUi
|
|
2
4
|
module Widgets
|
|
3
|
-
class Slider
|
|
4
|
-
def initialize(
|
|
5
|
-
start_value = options[:start_value].nil?
|
|
6
|
-
stop_value = options[:stop_value].nil?
|
|
7
|
-
step_value = options[:step_value].nil?
|
|
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]
|
|
8
10
|
init_value = options[:initial_value].nil? ? 1.0 : options[:initial_value]
|
|
9
11
|
|
|
10
12
|
@scale = Gtk::Scale.new(:horizontal, start_value, stop_value, step_value)
|
|
11
|
-
puts @scale.methods
|
|
12
13
|
@scale.digits = 0
|
|
13
14
|
@scale.draw_value = true
|
|
14
15
|
@scale.value = init_value
|
|
15
16
|
|
|
16
|
-
@scale
|
|
17
|
-
block.call(scale_widget)
|
|
18
|
-
end
|
|
17
|
+
$vertical_box.pack_start(@scale)
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
layout.pack_start(@scale)
|
|
22
|
-
end
|
|
19
|
+
super(@scale)
|
|
23
20
|
end
|
|
24
21
|
|
|
25
|
-
def
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
def move
|
|
23
|
+
@scale.signal_connect "value_changed" do |scale_widget|
|
|
24
|
+
yield(scale_widget)
|
|
25
|
+
end
|
|
28
26
|
end
|
|
27
|
+
|
|
28
|
+
alias :slide :move
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
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
|