mittens_ui 0.0.2 → 0.0.7

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: 76c72facca9e7aa37399945d8f44467ac96a1471c4abeeb76f45965ad3aeccc0
4
- data.tar.gz: 7b29e79fe7aa038d8bb12e5299bcb6f07bf30cb3c866e7d034b4e842a7184ac7
3
+ metadata.gz: 9fd554ceb6ba103cc474483896a9871db34a417a01e761b9c0befe7c43205cb1
4
+ data.tar.gz: 25ced2c5db0c26e27a9b29e85d635a2a8ef558da35cfe5ee690debd2a47eaa96
5
5
  SHA512:
6
- metadata.gz: c94f656a8bd97f7a3eb497d3fd5b1a1d430972c477216fbbd2a99ca2ec7f194beda429951f3d29eb89b5bcdba29bfa8249500250fe726bfe008fc0dd523b1619
7
- data.tar.gz: 5327faf9eb9c9ddaded5e40af6e4774484ee19d894b31d6423df66a7d2b1565a57e967d8f9fde7b109ad92aa5d685fe7696d070ffeff9266fbf48ff6dc37f196
6
+ metadata.gz: 368761abc4d2b0a1170c52b6a2941a700913b263ef6c0be43ceca4c20e2b3d5714620e8eb805fb12eed09a78a0c742debe00ee288dfdbbee33d2b1baa1ada3a3
7
+ data.tar.gz: 0db136bdea5ca1a8126d828c93d2e5cc16e5c1daadd4e45edcd69f6208650eb776c91867cbeb5feac3c42eedef395f952a03743b484283a31fc8a8a6bb0612cf
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mittens_ui (0.0.1)
4
+ mittens_ui (0.0.6)
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
- 2.1.4
71
+ 2.2.3
data/README.md CHANGED
@@ -23,7 +23,7 @@ Or install it yourself as:
23
23
  ## Usage
24
24
 
25
25
  ```ruby
26
- require "mittens_ui"
26
+ require '../lib/mittens_ui'
27
27
 
28
28
  app_options = {
29
29
  name: "say_hello",
@@ -33,28 +33,27 @@ app_options = {
33
33
  can_resize: true
34
34
  }.freeze
35
35
 
36
- MittensUi::Application.Window(app_options) do |window, layout|
37
- label_opts = { top: 30 }
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
- textbox_options = { can_edit: true }
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
- btn1_options = { title: "Click Here" }
50
- MittensUi::Button(layout, btn1_options) do
51
- MittensUi::Alert(window, "Hello #{text_box.text}!")
52
- end
46
+ listbox = MittensUi::ListBox(listbox_options)
53
47
 
54
- slider_opts = { start_value: 1, stop_value: 100 }
55
- MittensUi::Slider(layout, slider_opts) do |s|
56
- puts "value changed: #{s.value}"
57
- end
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
+ switch = MittensUi::Switch(left: 120 )
55
+ switch.on { puts switch.status }
56
+ end
58
57
  end
59
58
  ```
60
59
 
@@ -8,26 +8,24 @@ app_options = {
8
8
  can_resize: true
9
9
  }.freeze
10
10
 
11
- MittensUi::Application.Window(app_options) do |window, layout|
12
- label_opts = { top: 30 }
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
- textbox_options = { can_edit: true }
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
- btn1_options = { title: "Click Here" }
25
- MittensUi::Button(layout, btn1_options) do
26
- MittensUi::Alert(window, "Hello #{text_box.text}!")
27
- end
21
+ listbox = MittensUi::ListBox(listbox_options)
28
22
 
29
- slider_opts = { start_value: 1, stop_value: 100 }
30
- MittensUi::Slider(layout, slider_opts) do |s|
31
- puts "value changed: #{s.value}"
32
- end
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
+ switch = MittensUi::Switch(left: 120 )
30
+ switch.on { puts switch.status }
33
31
  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
@@ -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"
8
9
 
9
10
  require "gtk3"
10
11
 
11
12
  module MittensUi
13
+
12
14
  class Error < StandardError; end
13
15
 
14
- def self.Slider(layout, options = {}, &block)
15
- raise Error.new("Slider must be passed a block.") unless block_given?
16
- slider = MittensUi::Widgets::Slider.new(layout, options, &block)
17
- Application.set_visible_elements(slider)
18
- return slider
16
+ def self.Switch(options = {})
17
+ MittensUi::Widgets::Switch.new(options)
18
+ end
19
+
20
+ def self.Slider(options = {})
21
+ MittensUi::Widgets::Slider.new(options)
19
22
  end
20
23
 
21
- def self.ListBox(layout, options = {})
22
- list_box = MittensUi::Widgets::ListBox.new(layout, options)
23
- Application.set_visible_elements(list_box)
24
- return list_box
24
+ def self.ListBox(options = {})
25
+ MittensUi::Widgets::ListBox.new(options)
25
26
  end
26
27
 
27
- def self.Alert(window, message, options = {})
28
- alert = MittensUi::Widgets::Alert.new(window, message, options)
29
- Application.set_visible_elements(alert)
30
- return alert
28
+ def self.Alert(message, options = {})
29
+ MittensUi::Widgets::Alert.new(message, options)
31
30
  end
32
31
 
33
- def self.Label(text, layout, options = {})
34
- label = MittensUi::Widgets::Label.new(text, layout, options)
35
- Application.set_visible_elements(label)
36
- return label
32
+ def self.Label(text, options = {})
33
+ MittensUi::Widgets::Label.new(text, options)
37
34
  end
38
35
 
39
- def self.Textbox(layout, options = {})
40
- textbox = MittensUi::Widgets::Textbox.new(layout, options)
41
- Application.set_visible_elements(textbox)
42
- return textbox
36
+ def self.Textbox(options = {})
37
+ MittensUi::Widgets::Textbox.new(options)
43
38
  end
44
39
 
45
- def self.Button(layout, options = {}, &block)
46
- raise Error.new("Button must be passed a block.") unless block_given?
47
- button = MittensUi::Widgets::Button.new(layout, options, &block)
48
- Application.set_visible_elements(button)
49
- return button
40
+ def self.Button(options = {})
41
+ MittensUi::Widgets::Button.new(options)
50
42
  end
51
43
 
52
- def self.HideVisible
53
- Application.visible_elements.each(&:remove)
54
- Application.reset_visible_elements
44
+ def self.RemoveWidget(widget)
45
+ widget.remove
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
@@ -1,3 +1,3 @@
1
1
  module MittensUi
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -1,16 +1,16 @@
1
1
  module MittensUi
2
2
  module Widgets
3
3
  class Alert
4
- def initialize(window, message, options)
4
+ def initialize(message, options)
5
5
  dialog_options = {
6
6
  title: "Alert",
7
- parent: window,
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(window)
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,7 +1,7 @@
1
1
  module MittensUi
2
2
  module Widgets
3
3
  class Button
4
- def initialize(layout, options, &block)
4
+ def initialize(options={})
5
5
  button_title = options[:title] || "Button"
6
6
 
7
7
  margin_top = options[:top].nil? ? nil : options[:top]
@@ -16,12 +16,12 @@ module MittensUi
16
16
  @button.set_margin_right(margin_right) unless margin_right.nil?
17
17
  @button.set_margin_bottom(margin_bottom) unless margin_bottom.nil?
18
18
 
19
- if layout
20
- layout.pack_start(@button)
21
- end
22
-
19
+ $vertical_box.pack_start(@button)
20
+ end
21
+
22
+ def click
23
23
  @button.signal_connect "clicked" do |button_widget|
24
- block.call(button_widget)
24
+ yield(button_widget)
25
25
  end
26
26
  end
27
27
 
@@ -1,7 +1,11 @@
1
1
  module MittensUi
2
2
  module Widgets
3
3
  class Label
4
- def initialize(text, layout, options)
4
+ def initialize(text, options)
5
+ if text.nil? || text == "" || text == " "
6
+ text = "Label"
7
+ end
8
+
5
9
  margin_top = options[:top].nil? ? nil : options[:top]
6
10
  margin_bottom = options[:bottom].nil? ? nil : options[:bottom]
7
11
  margin_right = options[:right].nil? ? nil : options[:right]
@@ -25,9 +29,7 @@ module MittensUi
25
29
  @label.set_margin_right(margin_right)
26
30
  end
27
31
 
28
- if layout
29
- layout.pack_start(@label)
30
- end
32
+ $vertical_box.pack_start(@label)
31
33
  end
32
34
 
33
35
  def remove
@@ -3,8 +3,8 @@ module MittensUi
3
3
  class ListBox
4
4
  attr_reader :items
5
5
 
6
- def initialize(layout, options={})
7
- @items = options[:items]
6
+ def initialize(options={})
7
+ @items = options[:items]
8
8
 
9
9
  list_store = Gtk::ListStore.new(String)
10
10
 
@@ -24,11 +24,7 @@ module MittensUi
24
24
 
25
25
  @gtk_combobox.set_active(0)
26
26
 
27
- if layout
28
- layout.pack_start(@gtk_combobox)
29
- end
30
-
31
- return self
27
+ $vertical_box.pack_start(@gtk_combobox)
32
28
  end
33
29
 
34
30
  def set_selected_value(value)
@@ -38,6 +34,7 @@ module MittensUi
38
34
  def get_selected_value
39
35
  @selected_value
40
36
  end
37
+ alias :selected_value :get_selected_value
41
38
 
42
39
  def remove
43
40
  return if @gtk_combobox.nil?
@@ -1,24 +1,28 @@
1
1
  module MittensUi
2
2
  module Widgets
3
3
  class Slider
4
- def initialize(layout, options={}, &block)
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]
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]
8
9
 
9
10
  @scale = Gtk::Scale.new(:horizontal, start_value, stop_value, step_value)
10
11
  @scale.digits = 0
11
12
  @scale.draw_value = true
13
+ @scale.value = init_value
12
14
 
13
- @scale.signal_connect "value_changed" do |scale_widget|
14
- block.call(scale_widget)
15
- end
15
+ $vertical_box.pack_start(@scale)
16
+ end
16
17
 
17
- if layout
18
- layout.pack_start(@scale)
18
+ def move
19
+ @scale.signal_connect "value_changed" do |scale_widget|
20
+ yield(scale_widget)
19
21
  end
20
22
  end
21
23
 
24
+ alias :slide :move
25
+
22
26
  def remove
23
27
  return if @scale.nil?
24
28
  @scale.destroy
@@ -0,0 +1,57 @@
1
+ module MittensUi
2
+ module Widgets
3
+ class Switch
4
+ def initialize(options = {})
5
+ @switch = Gtk::Switch.new
6
+ @switch.set_active(false)
7
+
8
+ margin_top = options[:top].nil? ? nil : options[:top]
9
+ margin_bottom = options[:bottom].nil? ? nil : options[:bottom]
10
+ margin_right = options[:right].nil? ? nil : options[:right]
11
+ margin_left = options[:left].nil? ? nil : options[:left]
12
+
13
+ unless margin_top.nil?
14
+ @switch.set_margin_top(margin_top)
15
+ end
16
+
17
+ unless margin_bottom.nil?
18
+ @switch.set_margin_bottom(margin_top)
19
+ end
20
+
21
+ unless margin_left.nil?
22
+ @switch.set_margin_left(margin_left)
23
+ end
24
+
25
+ unless margin_right.nil?
26
+ @switch.set_margin_right(margin_right)
27
+ end
28
+
29
+ # We need a Grid within our global $vertical_box layout
30
+ # in order to make the Widget look good (mean not overly streched).
31
+ grid = Gtk::Grid.new
32
+ grid.set_column_spacing(1)
33
+ grid.set_row_spacing(1)
34
+ grid.attach(@switch, 0, 0, 1, 1)
35
+
36
+ $vertical_box.pack_start(grid)
37
+ end
38
+
39
+ def activate
40
+ @switch.signal_connect('notify::active') do |switch_widget|
41
+ switch_widget.active? ? switch_widget.set_active(true) : switch_widget.set_active(false)
42
+ yield
43
+ end
44
+ end
45
+ alias :on :activate
46
+
47
+ def status
48
+ @switch.active? ? 'on' : 'off'
49
+ end
50
+
51
+ def remove
52
+ return if @switch.nil?
53
+ @switch.destroy
54
+ end
55
+ end
56
+ end
57
+ end
@@ -1,7 +1,7 @@
1
1
  module MittensUi
2
2
  module Widgets
3
3
  class Textbox
4
- def initialize(layout, options)
4
+ def initialize(options={})
5
5
  @textbox = Gtk::Entry.new
6
6
  can_edit = options[:can_edit].nil? ? true : options[:can_edit]
7
7
  max_length = options[:max_length].nil? ? 200 : options[:max_length]
@@ -9,11 +9,7 @@ module MittensUi
9
9
  @textbox.set_editable(can_edit) unless can_edit.nil?
10
10
  @textbox.set_max_length(max_length) unless max_length.nil?
11
11
 
12
- if layout
13
- layout.pack_start(@textbox)
14
- end
15
-
16
- return @textbox
12
+ $vertical_box.pack_start(@textbox)
17
13
  end
18
14
 
19
15
  def text
@@ -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")
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.2
4
+ version: 0.0.7
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-14 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,6 +41,7 @@ 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
46
  - lib/mittens_ui/layouts/box.rb
46
47
  - lib/mittens_ui/layouts/grid.rb
@@ -50,6 +51,7 @@ files:
50
51
  - lib/mittens_ui/widgets/label.rb
51
52
  - lib/mittens_ui/widgets/listbox.rb
52
53
  - lib/mittens_ui/widgets/slider.rb
54
+ - lib/mittens_ui/widgets/switch.rb
53
55
  - lib/mittens_ui/widgets/textbox.rb
54
56
  - mittens_ui.gemspec
55
57
  - notes/gtk.txt
@@ -73,8 +75,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
75
  - !ruby/object:Gem::Version
74
76
  version: '0'
75
77
  requirements: []
76
- rubygems_version: 3.1.4
78
+ rubygems_version: 3.2.3
77
79
  signing_key:
78
80
  specification_version: 4
79
- summary: A tiny GUI tool kit written on top of GTK3
81
+ summary: A tiny GUI toolkit written on top of GTK3
80
82
  test_files: []