mittens_ui 0.0.7 → 0.0.8

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: 9fd554ceb6ba103cc474483896a9871db34a417a01e761b9c0befe7c43205cb1
4
- data.tar.gz: 25ced2c5db0c26e27a9b29e85d635a2a8ef558da35cfe5ee690debd2a47eaa96
3
+ metadata.gz: 2de74ee20b66d0c56c6ba2eb8cb7316ebbf57deebe990615decce1eb0008fd9e
4
+ data.tar.gz: 93ad5cde1ef87a5bce92fb8db71d02b812f980777ea84d47dbb4a9c29bb75bc0
5
5
  SHA512:
6
- metadata.gz: 368761abc4d2b0a1170c52b6a2941a700913b263ef6c0be43ceca4c20e2b3d5714620e8eb805fb12eed09a78a0c742debe00ee288dfdbbee33d2b1baa1ada3a3
7
- data.tar.gz: 0db136bdea5ca1a8126d828c93d2e5cc16e5c1daadd4e45edcd69f6208650eb776c91867cbeb5feac3c42eedef395f952a03743b484283a31fc8a8a6bb0612cf
6
+ metadata.gz: 51353cb720d6be4c84e8198642368292a3313510e1f683d129c83f30d55ac46e0a07d933dcec679b14eea20229796124e80324f34e2959ac02ecf6bbd0e96c5b
7
+ data.tar.gz: fbe1746d213f60ae5bde487b81ed6b13f455ac1b5d82c3762d150d2a47874380f06001c57fbdb20f0fa4705a42d08d4efb1c953acdc83ec22e33cf79251785b2
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mittens_ui (0.0.6)
4
+ mittens_ui (0.0.7)
5
5
  gtk3
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -23,13 +23,13 @@ Or install it yourself as:
23
23
  ## Usage
24
24
 
25
25
  ```ruby
26
- require '../lib/mittens_ui'
26
+ require "mittens_ui"
27
27
 
28
28
  app_options = {
29
29
  name: "say_hello",
30
- title: "Say Hello!",
31
- height: 450,
32
- width: 350,
30
+ title: "The Say Hello App!",
31
+ height: 650,
32
+ width: 550,
33
33
  can_resize: true
34
34
  }.freeze
35
35
 
@@ -51,9 +51,32 @@ MittensUi::Application.Window(app_options) do
51
51
  s = MittensUi::Slider({ start_value: 1, stop_value: 100, initial_value: 30 })
52
52
  s.slide { |s| puts s.value }
53
53
 
54
+ img_opts = {
55
+ tooltip_text: "The Gnome LOGO!",
56
+ width: 200,
57
+ height: 200,
58
+ left: 50
59
+ }.freeze
60
+
61
+ img = MittensUi::Image("./assets/gnome_logo.png", img_opts)
62
+
54
63
  switch = MittensUi::Switch(left: 120 )
55
- switch.on { puts switch.status }
56
- end
64
+
65
+ img.click do
66
+ unless switch.hidden?
67
+ switch.show
68
+ else
69
+ switch.hide
70
+ end
71
+ end
72
+
73
+ switch.on do
74
+ unless img.hidden?
75
+ img.show
76
+ else
77
+ img.hide
78
+ end
79
+ end
57
80
  end
58
81
  ```
59
82
 
@@ -2,9 +2,9 @@ require '../lib/mittens_ui'
2
2
 
3
3
  app_options = {
4
4
  name: "say_hello",
5
- title: "Say Hello!",
6
- height: 450,
7
- width: 350,
5
+ title: "The Say Hello App!",
6
+ height: 650,
7
+ width: 550,
8
8
  can_resize: true
9
9
  }.freeze
10
10
 
@@ -26,6 +26,30 @@ MittensUi::Application.Window(app_options) do
26
26
  s = MittensUi::Slider({ start_value: 1, stop_value: 100, initial_value: 30 })
27
27
  s.slide { |s| puts s.value }
28
28
 
29
+ img_opts = {
30
+ tooltip_text: "The Gnome LOGO!",
31
+ width: 200,
32
+ height: 200,
33
+ left: 50
34
+ }.freeze
35
+
36
+ img = MittensUi::Image("./assets/gnome_logo.png", img_opts)
37
+
29
38
  switch = MittensUi::Switch(left: 120 )
30
- switch.on { puts switch.status }
39
+
40
+ img.click do
41
+ unless switch.hidden?
42
+ switch.show
43
+ else
44
+ switch.hide
45
+ end
46
+ end
47
+
48
+ switch.on do
49
+ unless img.hidden?
50
+ img.show
51
+ else
52
+ img.hide
53
+ end
54
+ end
31
55
  end
@@ -6,13 +6,17 @@ require "mittens_ui/widgets/textbox"
6
6
  require "mittens_ui/widgets/listbox"
7
7
  require "mittens_ui/widgets/slider"
8
8
  require "mittens_ui/widgets/switch"
9
+ require "mittens_ui/widgets/image"
9
10
 
10
11
  require "gtk3"
11
12
 
12
13
  module MittensUi
13
-
14
14
  class Error < StandardError; end
15
15
 
16
+ def self.Image(path, options={})
17
+ MittensUi::Widgets::Image.new(path, options)
18
+ end
19
+
16
20
  def self.Switch(options = {})
17
21
  MittensUi::Widgets::Switch.new(options)
18
22
  end
@@ -41,10 +45,6 @@ module MittensUi
41
45
  MittensUi::Widgets::Button.new(options)
42
46
  end
43
47
 
44
- def self.RemoveWidget(widget)
45
- widget.remove
46
- end
47
-
48
48
  class Application
49
49
  class << self
50
50
  def Window(options = {}, &block)
@@ -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_top)
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
+
@@ -1,3 +1,3 @@
1
1
  module MittensUi
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -1,22 +1,18 @@
1
+ require_relative "./core"
2
+
1
3
  module MittensUi
2
4
  module Widgets
3
- class Button
5
+ class Button < Core
4
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?
10
+
11
+ set_margin_from_opts_for(@button, options)
18
12
 
19
13
  $vertical_box.pack_start(@button)
14
+
15
+ super(@button)
20
16
  end
21
17
 
22
18
  def click
@@ -24,11 +20,6 @@ module MittensUi
24
20
  yield(button_widget)
25
21
  end
26
22
  end
27
-
28
- def remove
29
- return if @button.nil?
30
- @button.destroy
31
- end
32
23
  end
33
24
  end
34
25
  end
@@ -0,0 +1,28 @@
1
+ require "mittens_ui/helpers"
2
+
3
+ module MittensUi
4
+ module Widgets
5
+ class Core
6
+ include Helpers
7
+
8
+ # All MittenUi::Widget 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
+ end
27
+ end
28
+ 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,40 +1,20 @@
1
+ require_relative "./core"
2
+
1
3
  module MittensUi
2
4
  module Widgets
3
- class Label
5
+ class Label < Core
4
6
  def initialize(text, options)
5
7
  if text.nil? || text == "" || text == " "
6
8
  text = "Label"
7
9
  end
8
10
 
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
11
  @label = Gtk::Label.new(text)
15
12
 
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
13
+ set_margin_from_opts_for(@label, options)
31
14
 
32
15
  $vertical_box.pack_start(@label)
33
- end
34
16
 
35
- def remove
36
- return if @label.nil?
37
- @label.destroy
17
+ super(@label)
38
18
  end
39
19
  end
40
20
  end
@@ -1,6 +1,8 @@
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
8
  def initialize(options={})
@@ -25,21 +27,19 @@ module MittensUi
25
27
  @gtk_combobox.set_active(0)
26
28
 
27
29
  $vertical_box.pack_start(@gtk_combobox)
30
+
31
+ super(@gtk_combobox)
28
32
  end
29
33
 
30
34
  def set_selected_value(value)
31
35
  @selected_value = value
32
36
  end
37
+ alias :set_value :set_selected_value
33
38
 
34
39
  def get_selected_value
35
40
  @selected_value
36
41
  end
37
42
  alias :selected_value :get_selected_value
38
-
39
- def remove
40
- return if @gtk_combobox.nil?
41
- @gtk_combobox.destroy
42
- end
43
43
  end
44
44
  end
45
45
  end
@@ -1,6 +1,8 @@
1
+ require_relative "./core"
2
+
1
3
  module MittensUi
2
4
  module Widgets
3
- class Slider
5
+ class Slider < Core
4
6
  def initialize(options={})
5
7
  start_value = options[:start_value].nil? ? 1.0 : options[:start_value]
6
8
  stop_value = options[:stop_value].nil? ? 10.0 : options[:stop_value]
@@ -13,6 +15,8 @@ module MittensUi
13
15
  @scale.value = init_value
14
16
 
15
17
  $vertical_box.pack_start(@scale)
18
+
19
+ super(@scale)
16
20
  end
17
21
 
18
22
  def move
@@ -22,11 +26,6 @@ module MittensUi
22
26
  end
23
27
 
24
28
  alias :slide :move
25
-
26
- def remove
27
- return if @scale.nil?
28
- @scale.destroy
29
- end
30
29
  end
31
30
  end
32
31
  end
@@ -1,39 +1,24 @@
1
+ require_relative "./core"
2
+
1
3
  module MittensUi
2
4
  module Widgets
3
- class Switch
5
+ class Switch < Core
4
6
  def initialize(options = {})
5
7
  @switch = Gtk::Switch.new
6
8
  @switch.set_active(false)
7
9
 
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
10
+ set_margin_from_opts_for(@switch, options)
28
11
 
29
12
  # We need a Grid within our global $vertical_box layout
30
- # in order to make the Widget look good (mean not overly streched).
13
+ # in order to make the Widget look good (meaning not overly streched).
31
14
  grid = Gtk::Grid.new
32
15
  grid.set_column_spacing(1)
33
16
  grid.set_row_spacing(1)
34
17
  grid.attach(@switch, 0, 0, 1, 1)
35
18
 
36
19
  $vertical_box.pack_start(grid)
20
+
21
+ super(@switch)
37
22
  end
38
23
 
39
24
  def activate
@@ -47,11 +32,6 @@ module MittensUi
47
32
  def status
48
33
  @switch.active? ? 'on' : 'off'
49
34
  end
50
-
51
- def remove
52
- return if @switch.nil?
53
- @switch.destroy
54
- end
55
35
  end
56
36
  end
57
37
  end
@@ -1,6 +1,8 @@
1
+ require_relative "./core"
2
+
1
3
  module MittensUi
2
4
  module Widgets
3
- class Textbox
5
+ class Textbox < Core
4
6
  def initialize(options={})
5
7
  @textbox = Gtk::Entry.new
6
8
  can_edit = options[:can_edit].nil? ? true : options[:can_edit]
@@ -10,16 +12,13 @@ module MittensUi
10
12
  @textbox.set_max_length(max_length) unless max_length.nil?
11
13
 
12
14
  $vertical_box.pack_start(@textbox)
15
+
16
+ super(@textbox)
13
17
  end
14
18
 
15
19
  def text
16
20
  @textbox.text
17
21
  end
18
-
19
- def remove
20
- return if @textbox.nil?
21
- @textbox.destroy
22
- end
23
22
  end
24
23
  end
25
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mittens_ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Tuttle
@@ -41,13 +41,17 @@ files:
41
41
  - bin/console
42
42
  - bin/setup
43
43
  - examples/app.rb
44
+ - examples/assets/gnome_logo.png
44
45
  - examples/brightness_controller.rb
45
46
  - lib/mittens_ui.rb
47
+ - lib/mittens_ui/helpers.rb
46
48
  - lib/mittens_ui/layouts/box.rb
47
49
  - lib/mittens_ui/layouts/grid.rb
48
50
  - lib/mittens_ui/version.rb
49
51
  - lib/mittens_ui/widgets/alert.rb
50
52
  - lib/mittens_ui/widgets/button.rb
53
+ - lib/mittens_ui/widgets/core.rb
54
+ - lib/mittens_ui/widgets/image.rb
51
55
  - lib/mittens_ui/widgets/label.rb
52
56
  - lib/mittens_ui/widgets/listbox.rb
53
57
  - lib/mittens_ui/widgets/slider.rb