mittens_ui 0.0.1 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d32efa4db9206db28408060f91ed79079017480cc8842b9e63f0631e19681312
4
- data.tar.gz: 24b8fcd5e02eea0ee33f4c33a1c990819170a7d3759ba9bc0bbb19252ea866e0
3
+ metadata.gz: d4f5d25f3b7c96a792bc79fcaacc9fd9b564cd42bd25b0eb019ee890cf8e7645
4
+ data.tar.gz: 3d498df47afc937af7cb7995c7789703189e9a32b05548bd8617c6894fffd802
5
5
  SHA512:
6
- metadata.gz: e91dd5b43aa3e93400142759029e823e7f6f905c38b10aa1551d619d3b94dd0185b2650e25f1c0b4e6fc5f5114b9c512df362c8456f67d8581b6026be36283e0
7
- data.tar.gz: 9dde2bd8508f239ca99f9a1fd0bee0baec875f401aaa7b3283cc0da735aaf46b0e7d853767e096395b743b5edd9d60e62a799c5b6621f554c7aca499ecfb56f2
6
+ metadata.gz: b12928f2e7228a6d8c871ba3a8c3ba952db166695a05d71408f527ce59b7a84769015a6033c6b92ab04afc4a3f82316e9567fba0190a197c65c52202f8249266
7
+ data.tar.gz: 967a5b3b12549407e0afd26a31dafae1498b5a345e4b664f17162ef169c73847d9a449bcbe38e5ce577693f8d9f526504565fe42481887d4419f6b1a7fcae433
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mittens_ui (0.1.0)
4
+ mittens_ui (0.0.5)
5
5
  gtk3
6
6
 
7
7
  GEM
@@ -39,23 +39,23 @@ GEM
39
39
  pango (3.4.3)
40
40
  cairo-gobject (= 3.4.3)
41
41
  gobject-introspection (= 3.4.3)
42
- pkg-config (1.4.2)
42
+ pkg-config (1.4.4)
43
43
  rake (12.3.3)
44
44
  rake-compiler (1.1.1)
45
45
  rake
46
- rspec (3.9.0)
47
- rspec-core (~> 3.9.0)
48
- rspec-expectations (~> 3.9.0)
49
- rspec-mocks (~> 3.9.0)
50
- rspec-core (3.9.2)
51
- rspec-support (~> 3.9.3)
52
- rspec-expectations (3.9.2)
46
+ rspec (3.10.0)
47
+ rspec-core (~> 3.10.0)
48
+ rspec-expectations (~> 3.10.0)
49
+ rspec-mocks (~> 3.10.0)
50
+ rspec-core (3.10.0)
51
+ rspec-support (~> 3.10.0)
52
+ rspec-expectations (3.10.0)
53
53
  diff-lcs (>= 1.2.0, < 2.0)
54
- rspec-support (~> 3.9.0)
55
- rspec-mocks (3.9.1)
54
+ rspec-support (~> 3.10.0)
55
+ rspec-mocks (3.10.0)
56
56
  diff-lcs (>= 1.2.0, < 2.0)
57
- rspec-support (~> 3.9.0)
58
- rspec-support (3.9.3)
57
+ rspec-support (~> 3.10.0)
58
+ rspec-support (3.10.0)
59
59
 
60
60
  PLATFORMS
61
61
  ruby
@@ -68,4 +68,4 @@ DEPENDENCIES
68
68
  rspec (~> 3.0)
69
69
 
70
70
  BUNDLED WITH
71
- 1.17.3
71
+ 2.1.4
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # MittensUi
2
2
 
3
- This is a small GUI toolkit inspired by Ruby Shoes and built on top of the GTK Ruby libraries. This isn't meant to be a wrapper
4
- around GTK (but kind of is right now in its early stage). The goal of this project is make creating GUIs in Ruby dead simple
3
+ This is a small vertical stacking GUI toolkit inspired by Ruby Shoes and built on top of the GTK Ruby library. This isn't meant to be a full wrapper
4
+ around GTK. The goal of this project is make creating GUIs in Ruby dead simple
5
5
  without the UI framework/library getting your way.
6
6
 
7
7
  ## Installation
@@ -23,36 +23,33 @@ Or install it yourself as:
23
23
  ## Usage
24
24
 
25
25
  ```ruby
26
- require "mittens_ui"
26
+ require 'mittens_ui'
27
27
 
28
28
  app_options = {
29
- title: "Mittens App Window Test!",
30
- height: 400,
31
- width: 350,
32
- can_resize: true
29
+ name: "say_hello",
30
+ title: "Say Hello!",
31
+ height: 450,
32
+ width: 350,
33
+ can_resize: true
33
34
  }.freeze
34
35
 
35
- MittensUi::Application.Window(app_options) do |window|
36
- MittensUi::Box(window) do |box|
37
- label_opts = {
38
- layout: { box: box }
39
- }
40
- MittensUi::Label("Enter Name:", label_opts)
41
-
42
- textbox_options = {
43
- can_edit: true,
44
- layout: { box: box }
45
- }
46
- text_box = MittensUi::Textbox(textbox_options)
47
-
48
- btn1_options ={
49
- title: "Click Here",
50
- layout: { box: box }
51
- }
52
- MittensUi::Button(btn1_options) do
53
- MittensUi::Alert(window, "Hello #{text_box.text}!")
54
- end
55
- end
36
+ MittensUi::Application.Window(app_options) do
37
+ MittensUi::Label("Enter Name:", top: 30)
38
+
39
+ text_box = MittensUi::Textbox(can_edit: true)
40
+
41
+ listbox_options = {
42
+ top: 10,
43
+ items: ["item_1", "item_2", "item_3"]
44
+ }.freeze
45
+
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 }
56
53
  end
57
54
  ```
58
55
 
@@ -1,31 +1,28 @@
1
1
  require '../lib/mittens_ui'
2
2
 
3
3
  app_options = {
4
+ name: "say_hello",
4
5
  title: "Say Hello!",
5
- height: 400,
6
+ height: 450,
6
7
  width: 350,
7
8
  can_resize: true
8
9
  }.freeze
9
10
 
10
- MittensUi::Application.Window(app_options) do |window|
11
- MittensUi::Box(window) do |box|
12
- label_opts = {
13
- layout: { box: box }
14
- }
15
- MittensUi::Label("Enter Name:", label_opts)
11
+ MittensUi::Application.Window(app_options) do
12
+ MittensUi::Label("Enter Name:", top: 30)
16
13
 
17
- textbox_options = {
18
- can_edit: true,
19
- layout: { box: box }
20
- }
21
- text_box = MittensUi::Textbox(textbox_options)
14
+ text_box = MittensUi::Textbox(can_edit: true)
22
15
 
23
- btn1_options ={
24
- title: "Click Here",
25
- layout: { box: box }
26
- }
27
- MittensUi::Button(btn1_options) do
28
- MittensUi::Alert(window, "Hello #{text_box.text}!")
29
- end
30
- end
16
+ listbox_options = {
17
+ top: 10,
18
+ items: ["item_1", "item_2", "item_3"]
19
+ }.freeze
20
+
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 }
31
28
  end
@@ -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
@@ -1,87 +1,106 @@
1
1
  require "mittens_ui/version"
2
-
3
- require "mittens_ui/layouts/grid"
4
- require "mittens_ui/layouts/stack"
5
- require "mittens_ui/layouts/box"
6
-
7
2
  require "mittens_ui/widgets/alert"
8
3
  require "mittens_ui/widgets/label"
9
4
  require "mittens_ui/widgets/button"
10
5
  require "mittens_ui/widgets/textbox"
6
+ require "mittens_ui/widgets/listbox"
7
+ require "mittens_ui/widgets/slider"
11
8
 
12
9
  require "gtk3"
13
10
 
14
11
  module MittensUi
12
+
15
13
  class Error < StandardError; end
16
14
 
17
- def self.Alert(window, message, options={})
18
- MittensUi::Widgets::Alert.init(window, message, options)
15
+ def self.Slider(options = {})
16
+ MittensUi::Widgets::Slider.new(options)
19
17
  end
20
18
 
21
- def self.Label(text, options)
22
- MittensUi::Widgets::Label.init(text, options)
19
+ def self.ListBox(options = {})
20
+ MittensUi::Widgets::ListBox.new(options)
23
21
  end
24
22
 
25
- def self.Textbox(options, &block)
26
- textbox = nil
27
-
28
- unless block_given?
29
- textbox = MittensUi::Widgets::Textbox.init(options, nil)
30
- else
31
- textbox = MittensUi::Widgets::Textbox.init(options, block = Proc.new)
32
- end
33
-
34
- if block_given?
35
- block.call textbox
36
- else
37
- return textbox
38
- end
23
+ def self.Alert(message, options = {})
24
+ MittensUi::Widgets::Alert.new(message, options)
39
25
  end
40
26
 
41
- def self.Box(window, &block)
42
- raise Error.new("A MittensUi::Box must be passed a block.") unless block_given?
43
- MittensUi::Layouts::Box.init(window, block = Proc.new)
27
+ def self.Label(text, options = {})
28
+ MittensUi::Widgets::Label.new(text, options)
44
29
  end
45
30
 
46
- def self.Grid(window, &block)
47
- raise "A Grid must be passed a block." unless block_given?
48
- MittensUi::Layouts::Grid.init(window, block = Proc.new)
31
+ def self.Textbox(options = {})
32
+ MittensUi::Widgets::Textbox.new(options)
49
33
  end
50
34
 
51
- def self.Stack(window, &block)
52
- raise "A Stack must be passed a block." unless block_given?
53
- MittensUi::Layouts::Stack.init(window, block = Proc.new)
35
+ def self.Button(options = {})
36
+ MittensUi::Widgets::Button.new(options)
54
37
  end
55
38
 
56
- def self.Button(options, &block)
57
- raise "Button must be passed a block." unless block_given?
58
- MittensUi::Widgets::Button.init(options, block = Proc.new)
39
+ def self.RemoveWidget(widget)
40
+ widget.remove
59
41
  end
60
42
 
61
43
  class Application
62
44
  class << self
63
45
  def Window(options = {}, &block)
64
- init_gtk_toplevel_window(options, &block)
65
- block.call(@@GTK_WINDOW)
66
- @@GTK_WINDOW.show_all
67
- Gtk.main
46
+ init_gtk_application(options, block)
68
47
  end
69
48
 
70
- def init_gtk_toplevel_window(options)
71
- @@GTK_WINDOW = Gtk::Window.new(:toplevel)
72
-
73
- height = options[:height].nil? ? 600 : options[:height]
74
- width = options[:width].nil? ? 400 : options[:width]
75
- title = options[:title].nil? ? "Mittens App" : options[:title]
49
+ private
50
+
51
+ def set_process_name(name)
52
+ # Doesn't work in MacOS Activity Monitor or Windows Task Manager. It shows up as "Ruby".
53
+ Process.setproctitle(name)
54
+ $PROGRAM_NAME = name
55
+ end
56
+
57
+ def init_gtk_application(options, block)
58
+ app_name = options[:name].nil? ? "mittens_ui_app" : options[:name]
59
+ height = options[:height].nil? ? 600 : options[:height]
60
+ width = options[:width].nil? ? 400 : options[:width]
61
+ title = options[:title].nil? ? "Mittens App" : options[:title]
76
62
  can_resize = options[:can_resize].nil? ? true : options[:can_resize]
77
-
78
- @@GTK_WINDOW.set_size_request(width, height)
79
- @@GTK_WINDOW.set_title(title)
80
- @@GTK_WINDOW.set_resizable(can_resize)
81
63
 
82
- @@GTK_WINDOW.signal_connect("delete-event") { |_widget| Gtk.main_quit }
64
+ set_process_name(app_name)
65
+
66
+ gtk_app_name = "org.gtk.mittens_ui.#{app_name}"
67
+
68
+ app = Gtk::Application.new(gtk_app_name, :flags_none)
69
+
70
+ app.signal_connect("activate") do |application|
71
+ $app_window = Gtk::ApplicationWindow.new(application)
72
+ scrolled_window = Gtk::ScrolledWindow.new
73
+ $vertical_box = Gtk::Box.new(:vertical, 10)
74
+ scrolled_window.add($vertical_box)
75
+ $app_window.add(scrolled_window)
76
+ block.call($app_window, $vertical_box)
77
+ $app_window.set_size_request(width, height)
78
+ $app_window.set_title(title)
79
+ $app_window.set_resizable(can_resize)
80
+ $app_window.show_all
81
+ end
82
+
83
+ app.run
83
84
  end
84
-
85
+ end
86
+ end
87
+
88
+ class Job
89
+ attr_reader :name, :status
90
+
91
+ def initialize(name)
92
+ @name = name
93
+ @status = nil
94
+ end
95
+
96
+ def run(&block)
97
+ job_t = Thread.new { |_t| yield }
98
+ set_status(job_t)
99
+ end
100
+
101
+ private
102
+ def set_status(thread)
103
+ @status = thread.status
85
104
  end
86
105
  end
87
106
  end
@@ -1,36 +1,38 @@
1
1
  module MittensUi
2
2
  module Layouts
3
- class Box
4
- class << self
5
- def init(window, block = Proc.new)
6
- box = Gtk::Box.new(:vertical, 6)
7
- block.call(box)
8
- window.add(box)
9
- end
10
-
11
- def attach(widget, options)
12
- box_ref = options[:box]
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
13
10
 
14
- expand = options.dig(:expand).nil? ? true : options.dig(:expand)
15
- fill = options.dig(:fill).nil? ? true : options.dig(:fill)
16
- padding = options.dig(:padding).nil? ? 0 : options.dig(:padding)
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]
17
15
 
18
- filterd_options = {
19
- expaned: expand,
20
- fill: fill,
21
- padding: padding
22
- }.freeze
16
+ filterd_options = {
17
+ expaned: expand,
18
+ fill: fill,
19
+ padding: padding
20
+ }.freeze
23
21
 
24
- case options.dig(:position)
25
- when :start
26
- box_ref.pack_start(widget, filterd_options)
27
- when :end
28
- box_ref.pack_end(widget, filterd_options)
29
- when nil
30
- box_ref.pack_start(widget, filterd_options)
31
- end
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)
32
29
  end
33
30
  end
31
+
32
+ def remove
33
+ return if @box.nil?
34
+ @box.destroy
35
+ end
34
36
  end
35
37
  end
36
- end
38
+ end
@@ -1,28 +1,31 @@
1
1
  module MittensUi
2
2
  module Layouts
3
3
  class Grid
4
- class << self
5
- def init(window, block = Proc.new)
6
- grid = Gtk::Grid.new
7
- block.call grid
8
- window.add_child(grid)
9
- end
4
+ def initialize(window, &block)
5
+ @grid = Gtk::Grid.new
6
+ yield(self)
7
+ window.add_child(@grid)
8
+ end
10
9
 
11
- def attach(widget, options)
12
- grid = options[:grid]
13
- grid_height = options[:height]
14
- grid_width = options[:width]
15
- grid_top = options[:top]
16
- grid_left = options[:left]
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]
17
15
 
18
- if !grid.nil?
19
- grid.attach(widget, grid_left, grid_top, grid_width, grid_height)
20
- else
21
- raise "You much pass a MittensUI:Grid or pass the Main app Window via the options hash."
22
- end
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)
23
20
  end
24
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
25
28
  end
26
29
  end
27
30
  end
28
- end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module MittensUi
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -1,31 +1,32 @@
1
1
  module MittensUi
2
2
  module Widgets
3
3
  class Alert
4
- class << self
5
- def init(window, message, options)
6
- dialog_options = {
7
- title: "Alert",
8
- parent: window,
9
- flags: [:modal, :destroy_with_parent],
10
- :buttons => [["_OK", :none]]
11
- }.freeze
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
12
11
 
13
- alert_dialog = Gtk::Dialog.new(dialog_options)
14
- alert_dialog.set_transient_for(window)
15
- alert_dialog.set_default_width(420)
16
- alert_dialog.set_default_height(200)
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)
17
18
 
18
- message_label = Gtk::Label.new(message)
19
- dialog_box = alert_dialog.content_area
20
- dialog_box.add(message_label)
21
-
22
- alert_dialog.show_all
23
-
24
- response = alert_dialog.run
19
+ message_label = Gtk::Label.new(message)
20
+ message_label.set_margin_top(65)
25
21
 
26
- response == :none ? alert_dialog.destroy : alert_dialog.destroy
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
27
28
 
28
- end
29
+ response == :none ? alert_dialog.destroy : alert_dialog.destroy
29
30
  end
30
31
  end
31
32
  end
@@ -1,29 +1,34 @@
1
1
  module MittensUi
2
2
  module Widgets
3
3
  class Button
4
- class << self
5
- def init(options, block = Proc.new)
6
- button_title = options[:title] || "MittensUi Button"
7
- layout = options[:layout]
8
- window = options[:window]
9
-
10
- button = Gtk::Button.new(label: button_title)
11
-
12
- if layout[:grid]
13
- MittensUi::Layouts::Grid.attach(button, layout)
14
- elsif layout[:stack]
15
- MittensUi::Layouts::Stack.attach(button, layout)
16
- elsif layout[:box]
17
- MittensUi::Layouts::Box.attach(button, layout)
18
- elsif window
19
- window.add_child(button)
20
- end
21
-
22
- button.signal_connect "clicked" do |widget|
23
- block.call
24
- end
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
25
  end
26
26
  end
27
+
28
+ def remove
29
+ return if @button.nil?
30
+ @button.destroy
31
+ end
27
32
  end
28
33
  end
29
- end
34
+ end
@@ -1,23 +1,40 @@
1
1
  module MittensUi
2
2
  module Widgets
3
3
  class Label
4
- class << self
5
- def init(text, options)
6
- layout = options[:layout]
7
- window = options[:window]
8
-
9
- label = Gtk::Label.new(text)
10
-
11
- if layout[:grid]
12
- MittensUi::Layouts::Grid.attach(label, layout)
13
- elsif layout[:stack]
14
- MittensUi::Layouts::Stack.attach(label, layout)
15
- elsif layout[:box]
16
- MittensUi::Layouts::Box.attach(label, layout)
17
- elsif window
18
- window.add_child(label)
19
- end
4
+ def initialize(text, options)
5
+ if text.nil? || text == "" || text == " "
6
+ text = "Label"
20
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
21
38
  end
22
39
  end
23
40
  end
@@ -0,0 +1,45 @@
1
+ module MittensUi
2
+ module Widgets
3
+ class ListBox
4
+ attr_reader :items
5
+
6
+ def initialize(options={})
7
+ @items = options[:items]
8
+
9
+ list_store = Gtk::ListStore.new(String)
10
+
11
+ @items.each do |i|
12
+ iter = list_store.append
13
+ iter[0] = i
14
+ end
15
+
16
+ renderer = Gtk::CellRendererText.new
17
+
18
+ @gtk_combobox = Gtk::ComboBox.new(model: list_store)
19
+ @gtk_combobox.pack_start(renderer, true)
20
+ @gtk_combobox.set_attributes(renderer, "text" => 0)
21
+ @gtk_combobox.set_cell_data_func(renderer) do |_layout, _cell_renderer, _model, iter|
22
+ set_selected_value(iter[0])
23
+ end
24
+
25
+ @gtk_combobox.set_active(0)
26
+
27
+ $vertical_box.pack_start(@gtk_combobox)
28
+ end
29
+
30
+ def set_selected_value(value)
31
+ @selected_value = value
32
+ end
33
+
34
+ def get_selected_value
35
+ @selected_value
36
+ end
37
+ alias :selected_value :get_selected_value
38
+
39
+ def remove
40
+ return if @gtk_combobox.nil?
41
+ @gtk_combobox.destroy
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,32 @@
1
+ module MittensUi
2
+ module Widgets
3
+ class Slider
4
+ def initialize(options={})
5
+ start_value = options[:start_value].nil? ? 1.0 : options[:start_value]
6
+ stop_value = options[:stop_value].nil? ? 10.0 : options[:stop_value]
7
+ step_value = options[:step_value].nil? ? 1.0 : options[:step_value]
8
+ init_value = options[:initial_value].nil? ? 1.0 : options[:initial_value]
9
+
10
+ @scale = Gtk::Scale.new(:horizontal, start_value, stop_value, step_value)
11
+ @scale.digits = 0
12
+ @scale.draw_value = true
13
+ @scale.value = init_value
14
+
15
+ $vertical_box.pack_start(@scale)
16
+ end
17
+
18
+ def move
19
+ @scale.signal_connect "value_changed" do |scale_widget|
20
+ yield(scale_widget)
21
+ end
22
+ end
23
+
24
+ alias :slide :move
25
+
26
+ def remove
27
+ return if @scale.nil?
28
+ @scale.destroy
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,26 +1,25 @@
1
1
  module MittensUi
2
2
  module Widgets
3
3
  class Textbox
4
- class << self
5
- def init(options, block = Proc.new)
6
- textbox = Gtk::Entry.new
7
- layout = options[:layout]
8
- can_edit = options[:can_edit].nil? ? true : options[:can_edit]
9
- max_length = options[:max_length].nil? ? 200 : options[:max_length]
10
- textbox.set_editable(can_edit)
11
- textbox.set_max_length(max_length)
12
-
13
- if layout[:grid]
14
- MittensUi::Layouts::Grid.attach(textbox, layout)
15
- elsif layout[:stack]
16
- MittensUi::Layouts::Stack.attach(textbox, layout)
17
- elsif layout[:box]
18
- MittensUi::Layouts::Box.attach(textbox, layout)
19
- end
4
+ def initialize(options={})
5
+ @textbox = Gtk::Entry.new
6
+ can_edit = options[:can_edit].nil? ? true : options[:can_edit]
7
+ max_length = options[:max_length].nil? ? 200 : options[:max_length]
8
+
9
+ @textbox.set_editable(can_edit) unless can_edit.nil?
10
+ @textbox.set_max_length(max_length) unless max_length.nil?
20
11
 
21
- textbox
22
- end
12
+ $vertical_box.pack_start(@textbox)
13
+ end
14
+
15
+ def text
16
+ @textbox.text
17
+ end
18
+
19
+ def remove
20
+ return if @textbox.nil?
21
+ @textbox.destroy
23
22
  end
24
23
  end
25
24
  end
26
- end
25
+ end
@@ -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 tool kit written on top of GTK3"
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")
@@ -0,0 +1,3 @@
1
+
2
+ GTK/GNOME application ids:
3
+ https://wiki.gnome.org/HowDoI/ChooseApplicationID
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.1
4
+ version: 0.0.6
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: 2020-08-25 00:00:00.000000000 Z
11
+ date: 2020-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gtk3
@@ -41,23 +41,25 @@ files:
41
41
  - bin/console
42
42
  - bin/setup
43
43
  - examples/app.rb
44
+ - examples/brightness_controller.rb
44
45
  - lib/mittens_ui.rb
45
- - lib/mittens_ui/dsl_parser.rb
46
46
  - lib/mittens_ui/layouts/box.rb
47
47
  - lib/mittens_ui/layouts/grid.rb
48
- - lib/mittens_ui/layouts/stack.rb
49
48
  - lib/mittens_ui/version.rb
50
49
  - lib/mittens_ui/widgets/alert.rb
51
50
  - lib/mittens_ui/widgets/button.rb
52
51
  - lib/mittens_ui/widgets/label.rb
52
+ - lib/mittens_ui/widgets/listbox.rb
53
+ - lib/mittens_ui/widgets/slider.rb
53
54
  - lib/mittens_ui/widgets/textbox.rb
54
55
  - mittens_ui.gemspec
56
+ - notes/gtk.txt
55
57
  homepage: https://github.com/tuttza/mittens_ui
56
58
  licenses: []
57
59
  metadata:
58
60
  homepage_uri: https://github.com/tuttza/mittens_ui
59
61
  source_code_uri: https://github.com/tuttza/mittens_ui
60
- post_install_message:
62
+ post_install_message:
61
63
  rdoc_options: []
62
64
  require_paths:
63
65
  - lib
@@ -72,8 +74,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
74
  - !ruby/object:Gem::Version
73
75
  version: '0'
74
76
  requirements: []
75
- rubygems_version: 3.0.3
76
- signing_key:
77
+ rubygems_version: 3.2.3
78
+ signing_key:
77
79
  specification_version: 4
78
- summary: A tiny GUI tool kit written on top of GTK3
80
+ summary: A tiny GUI toolkit written on top of GTK3
79
81
  test_files: []
@@ -1,17 +0,0 @@
1
- module MittensUi
2
-
3
- class DSLParser
4
- attr_reader :src_file
5
-
6
- def initialize(src_file)
7
- @src_file = src_file
8
- end
9
-
10
- def parse
11
- src_file_content = File.read(@src_file)
12
- instance_eval(src_file_content)
13
- end
14
-
15
- end
16
-
17
- end
@@ -1,21 +0,0 @@
1
- module MittensUi
2
- module Layouts
3
- class Stack
4
- class << self
5
- def init(window, block = Proc.new)
6
- stack = Gtk::Stack.new
7
- block.call(stack)
8
- window.add_child(stack)
9
- stack
10
- end
11
-
12
- def attach(widget, options)
13
- stack = options[:stack]
14
- if stack
15
- stack.add(widget)
16
- end
17
- end
18
- end
19
- end
20
- end
21
- end