mittens_ui 0.0.7 → 0.0.11

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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.ruby-version +1 -0
  4. data/Gemfile +3 -1
  5. data/Gemfile.lock +5 -2
  6. data/LICENSE +21 -0
  7. data/README.md +78 -21
  8. data/examples/app.rb +101 -8
  9. data/examples/assets/gnome_logo.png +0 -0
  10. data/examples/assets/mittens_ui_preview.gif +0 -0
  11. data/examples/contacts.rb +80 -0
  12. data/examples/file_menu_example.rb +52 -0
  13. data/examples/notify_example.rb +19 -0
  14. data/lib/mittens_ui.rb +40 -67
  15. data/lib/mittens_ui/alert.rb +32 -0
  16. data/lib/mittens_ui/assets/icon.png +0 -0
  17. data/lib/mittens_ui/assets/mittens_ui_preview.gif +0 -0
  18. data/lib/mittens_ui/button.rb +40 -0
  19. data/lib/mittens_ui/checkbox.rb +24 -0
  20. data/lib/mittens_ui/core.rb +34 -0
  21. data/lib/mittens_ui/file_menu.rb +83 -0
  22. data/lib/mittens_ui/file_picker.rb +29 -0
  23. data/lib/mittens_ui/grid.rb +29 -0
  24. data/lib/mittens_ui/hbox.rb +56 -0
  25. data/lib/mittens_ui/header_bar.rb +46 -0
  26. data/lib/mittens_ui/helpers.rb +41 -0
  27. data/lib/mittens_ui/image.rb +46 -0
  28. data/lib/mittens_ui/label.rb +19 -0
  29. data/lib/mittens_ui/listbox.rb +47 -0
  30. data/lib/mittens_ui/loader.rb +33 -0
  31. data/lib/mittens_ui/notify.rb +61 -0
  32. data/lib/mittens_ui/slider.rb +32 -0
  33. data/lib/mittens_ui/switch.rb +36 -0
  34. data/lib/mittens_ui/table_view.rb +179 -0
  35. data/lib/mittens_ui/textbox.rb +53 -0
  36. data/lib/mittens_ui/version.rb +1 -1
  37. data/lib/mittens_ui/web_link.rb +22 -0
  38. data/mittens_ui.gemspec +3 -3
  39. data/notes/dev_setup.txt +14 -0
  40. metadata +37 -16
  41. data/examples/brightness_controller.rb +0 -64
  42. data/lib/mittens_ui/layouts/box.rb +0 -38
  43. data/lib/mittens_ui/layouts/grid.rb +0 -31
  44. data/lib/mittens_ui/widgets/alert.rb +0 -33
  45. data/lib/mittens_ui/widgets/button.rb +0 -34
  46. data/lib/mittens_ui/widgets/label.rb +0 -41
  47. data/lib/mittens_ui/widgets/listbox.rb +0 -45
  48. data/lib/mittens_ui/widgets/slider.rb +0 -32
  49. data/lib/mittens_ui/widgets/switch.rb +0 -57
  50. data/lib/mittens_ui/widgets/textbox.rb +0 -25
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9fd554ceb6ba103cc474483896a9871db34a417a01e761b9c0befe7c43205cb1
4
- data.tar.gz: 25ced2c5db0c26e27a9b29e85d635a2a8ef558da35cfe5ee690debd2a47eaa96
3
+ metadata.gz: 391008eacae8c2d65697cf656f208d4103fd4f92718c229d84b6a66da4daa2c6
4
+ data.tar.gz: 63d8e5a6721751bb98e18243aec0c456e4ba646451bf0817533df3eb63637779
5
5
  SHA512:
6
- metadata.gz: 368761abc4d2b0a1170c52b6a2941a700913b263ef6c0be43ceca4c20e2b3d5714620e8eb805fb12eed09a78a0c742debe00ee288dfdbbee33d2b1baa1ada3a3
7
- data.tar.gz: 0db136bdea5ca1a8126d828c93d2e5cc16e5c1daadd4e45edcd69f6208650eb776c91867cbeb5feac3c42eedef395f952a03743b484283a31fc8a8a6bb0612cf
6
+ metadata.gz: e56732b0ce5a8641eaac122aeaeaa55cf09d4e386681f7d3ca9704e1926472d5d7006d62354a0a32086d9d4a4caeae3a1b6f207944a5ad33f0c89ac0875ce58e
7
+ data.tar.gz: 11d93d50cc7132f6c768c8cb8b7bebf64f9c833fa8251d51c0084b668fff2289c1e78ac178eae0375ab2f294359836a32ccd996c67043bfbc692419ac4b8c8d5
data/.gitignore CHANGED
@@ -15,3 +15,5 @@ mkmf.log
15
15
 
16
16
  # rspec failure tracking
17
17
  .rspec_status
18
+
19
+ ./releases
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.2"
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.6)
4
+ mittens_ui (0.0.10)
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.2p107
72
+
70
73
  BUNDLED WITH
71
- 2.2.3
74
+ 2.2.22
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
@@ -4,6 +4,8 @@ This is a small vertical stacking GUI toolkit inspired by Ruby Shoes and built o
4
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
+ ![alt_text](https://github.com/tuttza/mittens_ui/blob/51e84d7c50282e3f2c856aa9e65fe3ed28b117ff/lib/mittens_ui/assets/mittens_ui_preview.gif "MittensUi Preview")
8
+
7
9
  ## Installation
8
10
 
9
11
  Add this line to your application's Gemfile:
@@ -23,45 +25,100 @@ Or install it yourself as:
23
25
  ## Usage
24
26
 
25
27
  ```ruby
26
- require '../lib/mittens_ui'
28
+ require 'mittens_ui'
27
29
 
28
30
  app_options = {
29
- name: "say_hello",
30
- title: "Say Hello!",
31
- height: 450,
32
- width: 350,
31
+ name: "contacts",
32
+ title: "Contacts",
33
+ height: 615,
34
+ width: 570,
33
35
  can_resize: true
34
36
  }.freeze
35
37
 
38
+
36
39
  MittensUi::Application.Window(app_options) do
37
- MittensUi::Label("Enter Name:", top: 30)
40
+ file_menus = { "File": { sub_menus: ["Exit"] } }.freeze
41
+
42
+ fm = MittensUi::FileMenu.new(file_menus).render
38
43
 
39
- text_box = MittensUi::Textbox(can_edit: true)
44
+ add_contact_button = MittensUi::Button.new(title: "Add", icon: :add_green)
45
+ remove_contact_button = MittensUi::Button.new(title: "Remove", icon: :remove_red)
40
46
 
41
- listbox_options = {
42
- top: 10,
43
- items: ["item_1", "item_2", "item_3"]
44
- }.freeze
47
+ buttons = [ add_contact_button, remove_contact_button ]
45
48
 
46
- listbox = MittensUi::ListBox(listbox_options)
49
+ MittensUi::HeaderBar.new(buttons.map(&:render), title: "Contacts", position: :left).render
47
50
 
48
- btn = MittensUi::Button(title: "Click Here")
49
- btn.click {|_b| MittensUi::Alert("Hello #{text_box.text} AND! #{listbox.selected_value} was selected.") }
51
+ table_view_options = {
52
+ headers: ["Name", "Address", "Phone #"],
53
+ data: [
54
+ [ "John Appleseed", "123 abc st.", "111-555-3333"],
55
+ [ "Jane Doe", "122 abc st.", "111-555-4444" ],
56
+ [ "Bobby Jones", "434 bfef ave.", "442-333-1342"],
57
+ [ "Sara Akigawa", "777 tyo ave.", "932-333-1325"],
58
+ ],
59
+ top: 20
60
+ }
61
+
62
+ contacts_table = MittensUi::TableView.new(table_view_options).render
50
63
 
51
- s = MittensUi::Slider({ start_value: 1, stop_value: 100, initial_value: 30 })
52
- s.slide { |s| puts s.value }
64
+ # FORM
65
+ MittensUi::Label.new("Add Contact", top: 30).render
66
+
67
+ name_tb = MittensUi::Textbox.new(can_edit: true, placeholder: "Name...")
68
+ addr_tb = MittensUi::Textbox.new(can_edit: true, placeholder: "Address...")
69
+ phne_tb = MittensUi::Textbox.new(can_edit: true, placeholder: "Phone #...")
70
+
71
+ tb_list = [name_tb, addr_tb, phne_tb].map(&:render).freeze
72
+
73
+ MittensUi::HBox.new(tb_list, spacing: 10).render
74
+
75
+ # ACTONS
76
+ add_contact_button.click do |_b|
77
+ if tb_list.map { |tb| tb.text.length > 0 }.all?
78
+ contacts_table.add(tb_list.map {|tb| tb.text })
79
+ tb_list.map {|tb| tb.clear }
80
+ end
81
+ end
82
+
83
+ remove_contact_button.click do |btn|
84
+ removed = contacts_table.remove_selected
85
+
86
+ if removed.size > 0
87
+ MittensUi::Notify.new("#{removed[0]} was removed.", type: :info).render
88
+ end
89
+ end
90
+
91
+ contacts_table.row_clicked do |data|
92
+ msg = <<~MSG
93
+ Contact Info:
94
+
95
+ Name: #{data[0]}
96
+ Address: #{data[1]}
97
+ Phone #: #{data[2]}
98
+ MSG
99
+
100
+ MittensUi::Alert.new(msg).render
101
+ end
102
+
103
+ fm.exit do |fm|
104
+ MittensUi::Application.exit { print "Exiting App!"}
105
+ end
53
106
 
54
- switch = MittensUi::Switch(left: 120 )
55
- switch.on { puts switch.status }
56
- end
57
107
  end
58
108
  ```
59
109
 
60
110
  ## Development
61
111
 
62
- 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.
112
+ Simply fork and clone this repo to your machine, cd into it and run `bundle install`.
113
+
114
+ This does require GTK ruby gem which requires `gtk` native dependencies to be complied and installed on your system.
115
+
116
+ #### Fedora
117
+ Using dnf:
118
+ * `$ sudo dnf install ruby ruby-devel cairo cairo-devel gtk3-devel`
63
119
 
64
- 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).
120
+ #### Ubuntu
121
+ * `sudo apt install build-essential git sqlite3 libsqlite3-dev lib-gtk-3 libcairo2-dev`
65
122
 
66
123
  ## Contributing
67
124
 
data/examples/app.rb CHANGED
@@ -1,20 +1,26 @@
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,
4
+ name: "hello_world",
5
+ title: "Hello World App!",
6
+ height: 650,
7
+ width: 550,
8
8
  can_resize: true
9
9
  }.freeze
10
10
 
11
11
  MittensUi::Application.Window(app_options) do
12
+
13
+ MittensUi::HeaderBar([
14
+ MittensUi::Button(title: "headerbar button"),
15
+ MittensUi::CheckBox(label: "Checkbox")
16
+ ], title: "Demo App", position: :left) {}
17
+
12
18
  MittensUi::Label("Enter Name:", top: 30)
13
19
 
14
20
  text_box = MittensUi::Textbox(can_edit: true)
15
21
 
16
22
  listbox_options = {
17
- top: 10,
23
+ top: 10,
18
24
  items: ["item_1", "item_2", "item_3"]
19
25
  }.freeze
20
26
 
@@ -26,6 +32,93 @@ MittensUi::Application.Window(app_options) do
26
32
  s = MittensUi::Slider({ start_value: 1, stop_value: 100, initial_value: 30 })
27
33
  s.slide { |s| puts s.value }
28
34
 
29
- switch = MittensUi::Switch(left: 120 )
30
- switch.on { puts switch.status }
31
- end
35
+ img_opts = {
36
+ tooltip_text: "The Gnome LOGO!",
37
+ width: 200,
38
+ height: 200,
39
+ left: 20
40
+ }.freeze
41
+
42
+ img = MittensUi::Image("./assets/gnome_logo.png", img_opts)
43
+
44
+ img2 = MittensUi::Image("./assets/mittens_ui_preview.gif", img_opts)
45
+
46
+ switch = MittensUi::Switch(left: 220 )
47
+
48
+ img.click do
49
+ unless switch.hidden?
50
+ switch.show
51
+ else
52
+ switch.hide
53
+ end
54
+ end
55
+
56
+ switch.on do
57
+ unless img.hidden?
58
+ img.show
59
+ else
60
+ img.hide
61
+ end
62
+ end
63
+
64
+ cb = MittensUi::CheckBox(label: "Enable")
65
+ cb.value = "Some Value"
66
+ cb.toggle { puts "checkbox was toggled! associated value: #{cb.value}" }
67
+
68
+ link = MittensUi::WebLink("YouTube", "https://www.youtube.com", left: 200)
69
+
70
+ MittensUi::Label("Contact Info (use delimiter: ',')", top: 30)
71
+ contact_tb = MittensUi::Textbox(can_edit: true)
72
+
73
+ table_view_options = {
74
+ headers: ["Name", "Address", "Phone #"],
75
+ data: [
76
+ [ "John Appleseed", "123 abc st.", "111-555-3333"],
77
+ [ "Jane Doe", "122 abc st.", "111-555-4444" ],
78
+ [ "Bobby Jones", "434 bfef ave.", "442-333-1342"],
79
+ ],
80
+ }
81
+
82
+ table = MittensUi::TableView(table_view_options)
83
+ table.add(["Sara Akigawa", "777 tyo ave.", "932-333-1325"], :prepend)
84
+
85
+ add_ct = MittensUi::Button(title: "Add Contact")
86
+ add_ct.click {|_b| table.add(contact_tb.text.split(",")); contact_tb.clear; puts "Row Count: #{table.row_count}" }
87
+
88
+ table.row_clicked { |row| puts row.inspect }
89
+
90
+ remove_ct = MittensUi::Button(title: "Remove Contact")
91
+ remove_ct.click { |btn| table.remove_selected }
92
+
93
+ MittensUi::Shutdown() do
94
+ puts "quitting...."
95
+ end
96
+
97
+ open_file_picker = MittensUi::Button(title: "Choose File")
98
+
99
+ open_file_picker.click do
100
+ picked_file_path = MittensUi::FilePicker()
101
+ puts picked_file_path.inspect
102
+ open_file_picker.remove
103
+ end
104
+
105
+ start_loader = MittensUi::Button(title: "Start Loader")
106
+
107
+ loader = MittensUi::Loader()
108
+
109
+ start_loader.click do
110
+ loader.start {
111
+ puts "Doing some work..."
112
+ num = 0
113
+ 100.times do
114
+ num += 1
115
+ puts num
116
+ sleep 0.2
117
+ end
118
+
119
+ start_loader.remove
120
+ }
121
+ end
122
+
123
+ end
124
+
Binary file
@@ -0,0 +1,80 @@
1
+ require '../lib/mittens_ui'
2
+
3
+ app_options = {
4
+ name: "contacts",
5
+ title: "Contacts",
6
+ height: 615,
7
+ width: 570,
8
+ can_resize: true
9
+ }.freeze
10
+
11
+
12
+ MittensUi::Application.Window(app_options) do
13
+ file_menus = { "File": { sub_menus: ["Exit"] } }.freeze
14
+
15
+ fm = MittensUi::FileMenu.new(file_menus).render
16
+
17
+ add_contact_button = MittensUi::Button.new(title: "Add", icon: :add_green)
18
+ remove_contact_button = MittensUi::Button.new(title: "Remove", icon: :remove_red)
19
+
20
+ buttons = [ add_contact_button, remove_contact_button ]
21
+
22
+ MittensUi::HeaderBar.new(buttons.map(&:render), title: "Contacts", position: :left).render
23
+
24
+ table_view_options = {
25
+ headers: ["Name", "Address", "Phone #"],
26
+ data: [
27
+ [ "John Appleseed", "123 abc st.", "111-555-3333"],
28
+ [ "Jane Doe", "122 abc st.", "111-555-4444" ],
29
+ [ "Bobby Jones", "434 bfef ave.", "442-333-1342"],
30
+ [ "Sara Akigawa", "777 tyo ave.", "932-333-1325"],
31
+ ],
32
+ top: 20
33
+ }
34
+
35
+ contacts_table = MittensUi::TableView.new(table_view_options).render
36
+
37
+ # FORM
38
+ MittensUi::Label.new("Add Contact", top: 30).render
39
+
40
+ name_tb = MittensUi::Textbox.new(can_edit: true, placeholder: "Name...")
41
+ addr_tb = MittensUi::Textbox.new(can_edit: true, placeholder: "Address...")
42
+ phne_tb = MittensUi::Textbox.new(can_edit: true, placeholder: "Phone #...")
43
+
44
+ tb_list = [name_tb, addr_tb, phne_tb].map(&:render).freeze
45
+
46
+ MittensUi::HBox.new(tb_list, spacing: 10).render
47
+
48
+ # ACTONS
49
+ add_contact_button.click do |_b|
50
+ if tb_list.map { |tb| tb.text.length > 0 }.all?
51
+ contacts_table.add(tb_list.map {|tb| tb.text })
52
+ tb_list.map {|tb| tb.clear }
53
+ end
54
+ end
55
+
56
+ remove_contact_button.click do |btn|
57
+ removed = contacts_table.remove_selected
58
+
59
+ if removed.size > 0
60
+ MittensUi::Notify.new("#{removed[0]} was removed.", type: :info).render
61
+ end
62
+ end
63
+
64
+ contacts_table.row_clicked do |data|
65
+ msg = <<~MSG
66
+ Contact Info:
67
+
68
+ Name: #{data[0]}
69
+ Address: #{data[1]}
70
+ Phone #: #{data[2]}
71
+ MSG
72
+
73
+ MittensUi::Alert.new(msg).render
74
+ end
75
+
76
+ fm.exit do |fm|
77
+ MittensUi::Application.exit { print "Exiting App!"}
78
+ end
79
+
80
+ end
@@ -0,0 +1,52 @@
1
+ require '../lib/mittens_ui'
2
+
3
+ app_options = {
4
+ name: "file_menu_example",
5
+ title: "File Menu",
6
+ height: 615,
7
+ width: 570,
8
+ can_resize: true
9
+ }.freeze
10
+
11
+
12
+ MittensUi::Application.Window(app_options) do
13
+ menu_items = {
14
+ "File": {
15
+ sub_menus: ["Hello", "One", "Quit"]
16
+ },
17
+
18
+ "Edit": {
19
+ sub_menus: ["World", "Two", "options with space"]
20
+ },
21
+
22
+ "Settings": {
23
+ sub_menus: [
24
+ { "App Update" => ["Upgrade", "Downgrade"] }
25
+ ]
26
+ }
27
+
28
+ }.freeze
29
+
30
+ file_menu = MittensUi::FileMenu.new(menu_items)
31
+ file_menu.render
32
+
33
+ puts file_menu.methods.sort.inspect
34
+
35
+ file_menu.hello do |_fm|
36
+ MittensUi::Alert.new("HELLO!").render
37
+ end
38
+
39
+ file_menu.one do |_fm|
40
+ puts "You clicked one!"
41
+ end
42
+
43
+ file_menu.world do |_fm|
44
+ MittensUi::Alert.new("WORLD!").render
45
+ end
46
+
47
+ file_menu.quit do |_fm|
48
+ MittensUi::Application.exit do
49
+ puts "quitting!"
50
+ end
51
+ end
52
+ end