mittens_ui 0.0.5 → 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: f9bb06a2dc0614c5422fba2fea822e4aef8e43a3badae8903eff97eb71320df5
4
- data.tar.gz: '0912a1df162d187597ddadeb6e0aa636db8ac9e0098ab917bff559cb66164412'
3
+ metadata.gz: d4f5d25f3b7c96a792bc79fcaacc9fd9b564cd42bd25b0eb019ee890cf8e7645
4
+ data.tar.gz: 3d498df47afc937af7cb7995c7789703189e9a32b05548bd8617c6894fffd802
5
5
  SHA512:
6
- metadata.gz: e6667ac4f28f95fef9da6079239afd1e283272f31014c8ccab6fcb3de1d91a2f05fc911bb4db2c3eb6eacd0643b1c96874e20bb987693c740a32638c082609f7
7
- data.tar.gz: 8b194c5486856230016accc0c815ab0085a2f3c28ee1cf5c39ed250518e1069c8b364a9c13b33a8154bc819e35102b54b1c11a0c0f181e69f6a51a2d67c7e7e6
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.0.2)
4
+ mittens_ui (0.0.5)
5
5
  gtk3
6
6
 
7
7
  GEM
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 'mittens_ui'
27
27
 
28
28
  app_options = {
29
29
  name: "say_hello",
@@ -33,28 +33,23 @@ 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 }
58
53
  end
59
54
  ```
60
55
 
@@ -8,26 +8,21 @@ 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, initial_value: 30 }
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 }
33
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
@@ -9,69 +9,42 @@ require "mittens_ui/widgets/slider"
9
9
  require "gtk3"
10
10
 
11
11
  module MittensUi
12
+
12
13
  class Error < StandardError; end
13
14
 
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
15
+ def self.Slider(options = {})
16
+ MittensUi::Widgets::Slider.new(options)
19
17
  end
20
18
 
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
19
+ def self.ListBox(options = {})
20
+ MittensUi::Widgets::ListBox.new(options)
25
21
  end
26
22
 
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
23
+ def self.Alert(message, options = {})
24
+ MittensUi::Widgets::Alert.new(message, options)
31
25
  end
32
26
 
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
27
+ def self.Label(text, options = {})
28
+ MittensUi::Widgets::Label.new(text, options)
37
29
  end
38
30
 
39
- def self.Textbox(layout, options = {})
40
- textbox = MittensUi::Widgets::Textbox.new(layout, options)
41
- Application.set_visible_elements(textbox)
42
- return textbox
31
+ def self.Textbox(options = {})
32
+ MittensUi::Widgets::Textbox.new(options)
43
33
  end
44
34
 
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
35
+ def self.Button(options = {})
36
+ MittensUi::Widgets::Button.new(options)
50
37
  end
51
38
 
52
- def self.HideVisible
53
- Application.visible_elements.each(&:remove)
54
- Application.reset_visible_elements
39
+ def self.RemoveWidget(widget)
40
+ widget.remove
55
41
  end
56
42
 
57
43
  class Application
58
44
  class << self
59
45
  def Window(options = {}, &block)
60
- @@visible_elements = []
61
46
  init_gtk_application(options, block)
62
47
  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
48
 
76
49
  private
77
50
 
@@ -95,16 +68,16 @@ module MittensUi
95
68
  app = Gtk::Application.new(gtk_app_name, :flags_none)
96
69
 
97
70
  app.signal_connect("activate") do |application|
98
- app_window = Gtk::ApplicationWindow.new(application)
71
+ $app_window = Gtk::ApplicationWindow.new(application)
99
72
  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
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
108
81
  end
109
82
 
110
83
  app.run
@@ -1,3 +1,3 @@
1
1
  module MittensUi
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
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,10 +1,10 @@
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
8
  init_value = options[:initial_value].nil? ? 1.0 : options[:initial_value]
9
9
 
10
10
  @scale = Gtk::Scale.new(:horizontal, start_value, stop_value, step_value)
@@ -12,15 +12,17 @@ module MittensUi
12
12
  @scale.draw_value = true
13
13
  @scale.value = init_value
14
14
 
15
- @scale.signal_connect "value_changed" do |scale_widget|
16
- block.call(scale_widget)
17
- end
15
+ $vertical_box.pack_start(@scale)
16
+ end
18
17
 
19
- if layout
20
- layout.pack_start(@scale)
18
+ def move
19
+ @scale.signal_connect "value_changed" do |scale_widget|
20
+ yield(scale_widget)
21
21
  end
22
22
  end
23
23
 
24
+ alias :slide :move
25
+
24
26
  def remove
25
27
  return if @scale.nil?
26
28
  @scale.destroy
@@ -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
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.5
4
+ version: 0.0.6
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
@@ -73,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
74
  - !ruby/object:Gem::Version
74
75
  version: '0'
75
76
  requirements: []
76
- rubygems_version: 3.1.4
77
+ rubygems_version: 3.2.3
77
78
  signing_key:
78
79
  specification_version: 4
79
80
  summary: A tiny GUI toolkit written on top of GTK3