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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 324fbc94f63593ea41d2eb4eec17ff975f2eae84f9e0187eca390f4c8804d157
4
- data.tar.gz: 2f0817770780a0f15846fde876e81467f287721dc90eb1916a276cbe4989d972
3
+ metadata.gz: 9976f7810db4c1f9ed61a4a1f1f639617ee9c84bf117d37e174b14fd54b21dbc
4
+ data.tar.gz: 0224ed85d93f9366f7f594e19ed74827c72b33c949ea7ce9efc78a230dc44121
5
5
  SHA512:
6
- metadata.gz: 28e5e9926830ae66529664e40003b681b8fa15db65b4d5a10171b588837fdb0643fce74b7aec786a9a1d73e94ca84ba37cec97250deeffa8e736c0f68d1d58ba
7
- data.tar.gz: 728fe8237aa4f4140af931edb405fc1c35ff60419fddda91075358fff8ff8f26788d0b6d6eeacc4e3c5cf13af73a5d5761a79a400f420b5839bb1a64c2b6e865
6
+ metadata.gz: 68fbe929734690f1a21377b914fc200c54307e5393a98da9324e017b6bc59b3270577e4e09843aad88f49d61f6fd732c25f5e635d0ad2b0536d518898750e40b
7
+ data.tar.gz: edaecba0f03a65f2c79cab04345434cd8f8539c4a7930480eb6e792e89c90ee969416b7bcd36efba77be11f28210cf08e4a9c1c2d7cb3990cf5ca5940be3db67
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.0.0
data/Gemfile CHANGED
@@ -1,9 +1,11 @@
1
1
  source "https://rubygems.org"
2
2
 
3
+ ruby "3.0.1"
4
+
3
5
  # Specify your gem's dependencies in mittens_ui.gemspec
4
6
  gemspec
5
7
 
6
8
  gem "rake", "~> 12.0"
7
9
  gem "rake-compiler"
8
10
  gem "rspec", "~> 3.0"
9
- gem "gtk3"
11
+ gem "gtk3"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mittens_ui (0.0.2)
4
+ mittens_ui (0.0.9)
5
5
  gtk3
6
6
 
7
7
  GEM
@@ -67,5 +67,8 @@ DEPENDENCIES
67
67
  rake-compiler
68
68
  rspec (~> 3.0)
69
69
 
70
+ RUBY VERSION
71
+ ruby 3.0.1p64
72
+
70
73
  BUNDLED WITH
71
- 2.1.4
74
+ 2.2.15
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Zach Tuttle
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -26,43 +26,99 @@ Or install it yourself as:
26
26
  require "mittens_ui"
27
27
 
28
28
  app_options = {
29
- name: "say_hello",
30
- title: "Say Hello!",
31
- height: 450,
32
- width: 350,
29
+ name: "hello_world",
30
+ title: "Hello World App!",
31
+ height: 650,
32
+ width: 550,
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
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}!")
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 }
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
+
63
+ switch = MittensUi::Switch(left: 120 )
64
+
65
+ img.click do
66
+ unless switch.hidden?
67
+ switch.show
68
+ else
69
+ switch.hide
70
+ end
52
71
  end
53
72
 
54
- slider_opts = { start_value: 1, stop_value: 100 }
55
- MittensUi::Slider(layout, slider_opts) do |s|
56
- puts "value changed: #{s.value}"
73
+ switch.on do
74
+ unless img.hidden?
75
+ img.show
76
+ else
77
+ img.hide
78
+ end
57
79
  end
80
+
81
+ cb = MittensUi::CheckBox(label: "Enable")
82
+ cb.value = "Some Value"
83
+ cb.toggle { puts "checkbox was toggled! associated value: #{cb.value}" }
84
+
85
+ link = MittensUi::WebLink("YouTube", "https://www.youtube.com", left: 200)
86
+
87
+ table_view_options = {
88
+ headers: ["Name", "Address", "Phone #"],
89
+ data: [
90
+ [ "John Appleseed", "123 abc st.", "111-555-3333"],
91
+ [ "Jane Doe", "122 abc st.", "111-555-4444" ],
92
+ [ "Bobby Jones", "434 bfef ave.", "442-333-1342"],
93
+ ],
94
+ }
95
+
96
+ table = MittensUi::TableView(table_view_options)
97
+ table.add(["Sara Akigawa", "777 tyo ave.", "932-333-1325"], :prepend)
98
+
99
+ remove_ct = MittensUi::Button(title: "Remove Contact")
100
+ remove_ct.click { |btn| table.remove_selected }
101
+
58
102
  end
103
+
104
+
59
105
  ```
60
106
 
61
107
  ## Development
62
108
 
63
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
109
+ Simply fork and clone this repo to your machine, cd into it and run `bundle install`.
110
+
111
+ This does require GTK ruby gem which requires `gtk` native dependencies to be complied and installed on your system.
112
+
113
+ #### Fedora
114
+ Using dnf:
115
+ * `$ sudo dnf install ruby ruby-devel cairo cairo-devel gtk3-devel`
116
+
117
+ #### MacOS
64
118
 
65
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
119
+ Using Brew:
120
+ * `$ brew install gtk+3`
121
+ * `$ brew install cairo`
66
122
 
67
123
  ## Contributing
68
124
 
data/examples/app.rb CHANGED
@@ -1,33 +1,116 @@
1
1
  require '../lib/mittens_ui'
2
2
 
3
3
  app_options = {
4
- name: "say_hello",
5
- title: "Say Hello!",
6
- height: 450,
7
- width: 350,
8
- can_resize: true
4
+ name: "hello_world",
5
+ title: "Hello World App!",
6
+ height: 650,
7
+ width: 550,
8
+ can_resize: false
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
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}!")
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 }
28
+
29
+ img_opts = {
30
+ tooltip_text: "The Gnome LOGO!",
31
+ width: 200,
32
+ height: 200,
33
+ left: 20
34
+ }.freeze
35
+
36
+ img = MittensUi::Image("./assets/gnome_logo.png", img_opts)
37
+
38
+ switch = MittensUi::Switch(left: 220 )
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
55
+
56
+ cb = MittensUi::CheckBox(label: "Enable")
57
+ cb.value = "Some Value"
58
+ cb.toggle { puts "checkbox was toggled! associated value: #{cb.value}" }
59
+
60
+ link = MittensUi::WebLink("YouTube", "https://www.youtube.com", left: 200)
61
+
62
+ MittensUi::Label("Contact Info (use delimiter: ',')", top: 30)
63
+ contact_tb = MittensUi::Textbox(can_edit: true)
64
+
65
+ table_view_options = {
66
+ headers: ["Name", "Address", "Phone #"],
67
+ data: [
68
+ [ "John Appleseed", "123 abc st.", "111-555-3333"],
69
+ [ "Jane Doe", "122 abc st.", "111-555-4444" ],
70
+ [ "Bobby Jones", "434 bfef ave.", "442-333-1342"],
71
+ ],
72
+ }
73
+
74
+ table = MittensUi::TableView(table_view_options)
75
+ table.add(["Sara Akigawa", "777 tyo ave.", "932-333-1325"], :prepend)
76
+
77
+ add_ct = MittensUi::Button(title: "Add Contact")
78
+ add_ct.click {|_b| table.add(contact_tb.text.split(",")); contact_tb.clear; puts "Row Count: #{table.row_count}" }
79
+
80
+ table.row_clicked { |row| puts row.inspect }
81
+
82
+ remove_ct = MittensUi::Button(title: "Remove Contact")
83
+ remove_ct.click { |btn| table.remove_selected }
84
+
85
+ MittensUi::Shutdown() do
86
+ puts "quitting...."
27
87
  end
28
88
 
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}"
89
+ open_file_picker = MittensUi::Button(title: "Choose File")
90
+
91
+ open_file_picker.click do
92
+ picked_file_path = MittensUi::FilePicker()
93
+ puts picked_file_path.inspect
94
+ open_file_picker.remove
32
95
  end
33
- end
96
+
97
+ start_loader = MittensUi::Button(title: "Start Loader")
98
+
99
+ loader = MittensUi::Loader()
100
+
101
+ start_loader.click do
102
+ loader.start {
103
+ puts "Doing some work..."
104
+ num = 0
105
+ 100.times do
106
+ num += 1
107
+ puts num
108
+ sleep 0.2
109
+ end
110
+
111
+ start_loader.remove
112
+ }
113
+ end
114
+
115
+ end
116
+
Binary file
@@ -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
data/lib/mittens_ui.rb CHANGED
@@ -5,83 +5,94 @@ 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"
9
+ require "mittens_ui/widgets/image"
10
+ require "mittens_ui/widgets/checkbox"
11
+ require "mittens_ui/widgets/web_link"
12
+ require "mittens_ui/widgets/table_view"
13
+ require "mittens_ui/widgets/loader"
14
+
15
+ require "mittens_ui/dialogs/file_dialog"
8
16
 
9
17
  require "gtk3"
10
18
 
11
19
  module MittensUi
12
20
  class Error < StandardError; end
13
21
 
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
22
+ def self.Loader(options={})
23
+ MittensUi::Widgets::Loader.new(options)
19
24
  end
20
25
 
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
26
+ def self.FilePicker
27
+ fp = MittensUi::Dialogs::File.new
28
+ return fp.path
29
+ end
30
+
31
+ def self.TableView(options={})
32
+ MittensUi::Widgets::TableView.new(options)
25
33
  end
26
34
 
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
35
+ def self.WebLink(url, name, options={})
36
+ MittensUi::Widgets::WebLink.new(url, name, options)
31
37
  end
32
38
 
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
39
+ def self.CheckBox(options={})
40
+ MittensUi::Widgets::Checkbox.new(options)
37
41
  end
38
42
 
39
- def self.Textbox(layout, options = {})
40
- textbox = MittensUi::Widgets::Textbox.new(layout, options)
41
- Application.set_visible_elements(textbox)
42
- return textbox
43
+ def self.Image(path, options={})
44
+ MittensUi::Widgets::Image.new(path, options)
43
45
  end
44
46
 
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
47
+ def self.Switch(options = {})
48
+ MittensUi::Widgets::Switch.new(options)
50
49
  end
51
50
 
52
- def self.HideVisible
53
- Application.visible_elements.each(&:remove)
54
- Application.reset_visible_elements
51
+ def self.Slider(options = {})
52
+ MittensUi::Widgets::Slider.new(options)
55
53
  end
56
54
 
57
- class Application
58
- class << self
59
- def Window(options = {}, &block)
60
- @@visible_elements = []
61
- init_gtk_application(options, block)
62
- end
55
+ def self.ListBox(options = {})
56
+ MittensUi::Widgets::ListBox.new(options)
57
+ end
63
58
 
64
- def set_visible_elements(element)
65
- @@visible_elements << element
66
- end
59
+ def self.Alert(message, options = {})
60
+ MittensUi::Widgets::Alert.new(message, options)
61
+ end
67
62
 
68
- def visible_elements
69
- @@visible_elements
70
- end
63
+ def self.Label(text, options = {})
64
+ MittensUi::Widgets::Label.new(text, options)
65
+ end
66
+
67
+ def self.Textbox(options = {})
68
+ MittensUi::Widgets::Textbox.new(options)
69
+ end
70
+
71
+ def self.Button(options = {})
72
+ MittensUi::Widgets::Button.new(options)
73
+ end
71
74
 
72
- def reset_visible_elements
73
- @@visible_elements = []
75
+ def self.Shutdown
76
+ $app_window.signal_connect("delete-event") do |_widget|
77
+ yield
78
+ end
79
+ end
80
+
81
+ class Application
82
+ class << self
83
+ def Window(options = {}, &block)
84
+ init_gtk_application(options, &block)
74
85
  end
75
-
76
- private
86
+
87
+ private
77
88
 
78
89
  def set_process_name(name)
79
- # Doesn't work in MacOS Activity Monitor or Windows Task Manager. It shows up as "Ruby".
80
90
  Process.setproctitle(name)
81
91
  $PROGRAM_NAME = name
92
+ $0 = name
82
93
  end
83
94
 
84
- def init_gtk_application(options, block)
95
+ def init_gtk_application(options, &block)
85
96
  app_name = options[:name].nil? ? "mittens_ui_app" : options[:name]
86
97
  height = options[:height].nil? ? 600 : options[:height]
87
98
  width = options[:width].nil? ? 400 : options[:width]
@@ -90,44 +101,25 @@ module MittensUi
90
101
 
91
102
  set_process_name(app_name)
92
103
 
93
- gtk_app_name = "org.gtk.mittens_ui.#{app_name}"
104
+ gtk_app_name = "org.mittens_ui.#{app_name}"
94
105
 
95
106
  app = Gtk::Application.new(gtk_app_name, :flags_none)
96
107
 
97
108
  app.signal_connect("activate") do |application|
98
- app_window = Gtk::ApplicationWindow.new(application)
109
+ $app_window = Gtk::ApplicationWindow.new(application)
99
110
  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
111
+ $vertical_box = Gtk::Box.new(:vertical, 10)
112
+ scrolled_window.add($vertical_box)
113
+ $app_window.add(scrolled_window)
114
+ yield($app_window, $vertical_box)
115
+ $app_window.set_size_request(width, height)
116
+ $app_window.set_title(title)
117
+ $app_window.set_resizable(can_resize)
118
+ $app_window.show_all
108
119
  end
109
120
 
110
121
  app.run
111
122
  end
112
123
  end
113
124
  end
114
-
115
- class Job
116
- attr_reader :name, :status
117
-
118
- def initialize(name)
119
- @name = name
120
- @status = nil
121
- end
122
-
123
- def run(&block)
124
- job_t = Thread.new { |_t| yield }
125
- set_status(job_t)
126
- end
127
-
128
- private
129
- def set_status(thread)
130
- @status = thread.status
131
- end
132
- end
133
125
  end