mittens_ui 0.0.10 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb39340bda7c9c473ade8a1cfa92300cd87f6fdd29e96431507b0fc21133a6a7
4
- data.tar.gz: 3ed7082dfca8a2475e6d86bae2bb36e5740464044bc6d67ce140b3de00eb4d8c
3
+ metadata.gz: 391008eacae8c2d65697cf656f208d4103fd4f92718c229d84b6a66da4daa2c6
4
+ data.tar.gz: 63d8e5a6721751bb98e18243aec0c456e4ba646451bf0817533df3eb63637779
5
5
  SHA512:
6
- metadata.gz: 5a47bf32490fb765cb9084bdb6aea8ca5fba19b572d81cc321c1cd56e13c45cc317f39f99bf63834a867f513817a02000e5819379501f0a3a36334f02d458aeb
7
- data.tar.gz: 54149cd2b1f4d2d3d45ea434e244a746de45226bea12597d6166f31ae2b127208ad848d630d859297ecf70a32fac568fbfd356d8d1eb8776609550c96547dc32
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/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mittens_ui (0.0.9)
4
+ mittens_ui (0.0.10)
5
5
  gtk3
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -36,20 +36,13 @@ app_options = {
36
36
  }.freeze
37
37
 
38
38
 
39
- require '../lib/mittens_ui'
40
-
41
- app_options = {
42
- name: "contacts",
43
- title: "Contacts",
44
- height: 615,
45
- width: 570,
46
- can_resize: true
47
- }.freeze
48
-
49
-
50
39
  MittensUi::Application.Window(app_options) do
51
- add_contact_button = MittensUi::Button.new(title: "Add")
52
- remove_contact_button = MittensUi::Button.new(title: "Remove")
40
+ file_menus = { "File": { sub_menus: ["Exit"] } }.freeze
41
+
42
+ fm = MittensUi::FileMenu.new(file_menus).render
43
+
44
+ add_contact_button = MittensUi::Button.new(title: "Add", icon: :add_green)
45
+ remove_contact_button = MittensUi::Button.new(title: "Remove", icon: :remove_red)
53
46
 
54
47
  buttons = [ add_contact_button, remove_contact_button ]
55
48
 
@@ -80,7 +73,6 @@ MittensUi::Application.Window(app_options) do
80
73
  MittensUi::HBox.new(tb_list, spacing: 10).render
81
74
 
82
75
  # ACTONS
83
-
84
76
  add_contact_button.click do |_b|
85
77
  if tb_list.map { |tb| tb.text.length > 0 }.all?
86
78
  contacts_table.add(tb_list.map {|tb| tb.text })
@@ -92,7 +84,7 @@ MittensUi::Application.Window(app_options) do
92
84
  removed = contacts_table.remove_selected
93
85
 
94
86
  if removed.size > 0
95
- MittensUi::Alert.new("#{removed[0]} was removed.").render
87
+ MittensUi::Notify.new("#{removed[0]} was removed.", type: :info).render
96
88
  end
97
89
  end
98
90
 
@@ -107,8 +99,12 @@ MittensUi::Application.Window(app_options) do
107
99
 
108
100
  MittensUi::Alert.new(msg).render
109
101
  end
110
- end
111
102
 
103
+ fm.exit do |fm|
104
+ MittensUi::Application.exit { print "Exiting App!"}
105
+ end
106
+
107
+ end
112
108
  ```
113
109
 
114
110
  ## Development
data/examples/contacts.rb CHANGED
@@ -10,8 +10,12 @@ app_options = {
10
10
 
11
11
 
12
12
  MittensUi::Application.Window(app_options) do
13
- add_contact_button = MittensUi::Button.new(title: "Add")
14
- remove_contact_button = MittensUi::Button.new(title: "Remove")
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)
15
19
 
16
20
  buttons = [ add_contact_button, remove_contact_button ]
17
21
 
@@ -41,15 +45,11 @@ MittensUi::Application.Window(app_options) do
41
45
 
42
46
  MittensUi::HBox.new(tb_list, spacing: 10).render
43
47
 
44
- fp = MittensUi::FilePicker.new
45
-
46
48
  # ACTONS
47
-
48
49
  add_contact_button.click do |_b|
49
50
  if tb_list.map { |tb| tb.text.length > 0 }.all?
50
51
  contacts_table.add(tb_list.map {|tb| tb.text })
51
52
  tb_list.map {|tb| tb.clear }
52
- puts "#{fp.render.path}"
53
53
  end
54
54
  end
55
55
 
@@ -57,7 +57,7 @@ MittensUi::Application.Window(app_options) do
57
57
  removed = contacts_table.remove_selected
58
58
 
59
59
  if removed.size > 0
60
- MittensUi::Alert.new("#{removed[0]} was removed.").render
60
+ MittensUi::Notify.new("#{removed[0]} was removed.", type: :info).render
61
61
  end
62
62
  end
63
63
 
@@ -72,4 +72,9 @@ MittensUi::Application.Window(app_options) do
72
72
 
73
73
  MittensUi::Alert.new(msg).render
74
74
  end
75
+
76
+ fm.exit do |fm|
77
+ MittensUi::Application.exit { print "Exiting App!"}
78
+ end
79
+
75
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
@@ -0,0 +1,19 @@
1
+ require '../lib/mittens_ui'
2
+
3
+ app_options = {
4
+ name: "notify_example",
5
+ title: "Notify This",
6
+ height: 615,
7
+ width: 570,
8
+ can_resize: true
9
+ }.freeze
10
+
11
+
12
+ MittensUi::Application.Window(app_options) do
13
+ btn = MittensUi::Button.new(title: "Notify Me")
14
+ btn.render
15
+
16
+ btn.click do
17
+ MittensUi::Notify.new("Updated!").render
18
+ end
19
+ end
data/lib/mittens_ui.rb CHANGED
@@ -13,25 +13,30 @@ require "mittens_ui/table_view"
13
13
  require "mittens_ui/loader"
14
14
  require "mittens_ui/header_bar"
15
15
  require "mittens_ui/file_picker"
16
+ require "mittens_ui/file_menu"
16
17
  require "mittens_ui/hbox"
18
+ require "mittens_ui/notify"
17
19
 
18
20
  require "gtk3"
19
21
 
20
22
  module MittensUi
21
23
  class Error < StandardError; end
22
24
 
23
- def self.Shutdown
24
- $app_window.signal_connect("delete-event") do |_widget|
25
- yield
26
- end
27
- end
28
-
29
25
  class Application
30
26
  class << self
31
27
  def Window(options = {}, &block)
32
28
  init_gtk_application(options, &block)
33
29
  end
34
30
 
31
+ def exit(&block)
32
+ begin
33
+ yield if block_given?
34
+ Kernel.exit(0)
35
+ rescue => _error
36
+ Kernel.exit(1)
37
+ end
38
+ end
39
+
35
40
  private
36
41
 
37
42
  def set_process_name(name)
@@ -1,11 +1,22 @@
1
1
  require_relative "./core"
2
+ require "mittens_ui/helpers"
2
3
 
3
4
  module MittensUi
4
5
  class Button < Core
6
+ include Helpers
7
+
5
8
  def initialize(options={})
6
- button_title = options[:title] || "Button"
9
+ button_title = options[:title] || "Button"
10
+
11
+ icon_type = options[:icon] || nil
7
12
 
8
- @button = Gtk::Button.new(label: button_title)
13
+ if icon_type
14
+ image = Gtk::Image.new(icon_name: icon_map[icon_type], size: @button)
15
+ @button = Gtk::Button.new
16
+ @button.add(image)
17
+ else
18
+ @button = Gtk::Button.new(label: button_title)
19
+ end
9
20
 
10
21
  super(@button, options)
11
22
  end
@@ -0,0 +1,83 @@
1
+ require_relative "./core"
2
+
3
+ module MittensUi
4
+ class FileMenu < Core
5
+ def initialize(menu_items, options = {})
6
+ @menu_items = menu_items
7
+
8
+ @menu_bar = Gtk::MenuBar.new
9
+
10
+ # menu_name => menu_item(gtk)
11
+ @raw_menu_items = {}
12
+
13
+ associate_menu_items
14
+
15
+ create_menu_methods
16
+
17
+ super(@menu_bar, options)
18
+ end
19
+
20
+ def render
21
+ $vertical_box.pack_start(@menu_bar)
22
+ return self
23
+ end
24
+
25
+ private
26
+
27
+ def create_menu_methods
28
+ @raw_menu_items.each do |menu_label, menu_item|
29
+ menu_label = menu_label.downcase.gsub(/ /, "_").to_sym
30
+
31
+ define_singleton_method(menu_label) do |&blk|
32
+ menu_item.signal_connect("activate") do
33
+ blk.call(self)
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ def associate_menu_items
40
+ @menu_items.each do |root_menu_label, menu_item_data|
41
+ root_menu = Gtk::Menu.new
42
+
43
+ root_menu_item = Gtk::MenuItem.new(label: root_menu_label.to_s)
44
+ root_menu_item.set_submenu(root_menu)
45
+
46
+ next unless menu_item_data.is_a?(Hash)
47
+
48
+ menu_item_data.each do |sub_menus_key, sub_menus_item_data|
49
+ next unless sub_menus_key.to_sym == :sub_menus
50
+ sub_menus_item_data.each do |sub_menu_data|
51
+ sub_menu_data.is_a?(String) ? create_root_menu(sub_menu_data.to_s, root_menu) : nil
52
+ sub_menu_data.is_a?(Hash) ? create_sub_menu(sub_menu_data, root_menu) : nil
53
+ end
54
+ end
55
+
56
+ @menu_bar.append(root_menu_item)
57
+ end
58
+ end
59
+
60
+ def create_sub_menu(hsh, root_menu)
61
+ hsh.each do |sub_menu_label, sub_menu_data|
62
+ sub_menu = Gtk::Menu.new
63
+ sub_menu_item = Gtk::MenuItem.new(label: sub_menu_label.to_s)
64
+ sub_menu_item.set_submenu(sub_menu)
65
+ root_menu.append(sub_menu_item)
66
+
67
+ if sub_menu_data.is_a?(Array)
68
+ sub_menu_data.each do |label|
69
+ nested_sub_item = Gtk::MenuItem.new(label: label.to_s)
70
+ sub_menu.append(nested_sub_item)
71
+ @raw_menu_items[label.to_s] = nested_sub_item
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ def create_root_menu(label, root_menu)
78
+ menu_item = Gtk::MenuItem.new(label: label)
79
+ root_menu.append(menu_item)
80
+ @raw_menu_items[label] = menu_item
81
+ end
82
+ end
83
+ end
@@ -34,13 +34,11 @@ module MittensUi
34
34
  @header.pack_end(box)
35
35
  end
36
36
 
37
- $app_window.titlebar = @header
38
-
39
37
  super(@header, options)
40
38
  end
41
39
 
42
40
  def render
43
- $vertical_box.pack_start(@header)
41
+ $app_window.titlebar = @header
44
42
  return self
45
43
  end
46
44
 
@@ -1,5 +1,19 @@
1
1
  module MittensUi
2
2
  module Helpers
3
+ def icon_map
4
+ {
5
+ add: "list-add-symbolic",
6
+ remove: "list-remove-symbolic",
7
+ add_green: 'add',
8
+ remove_red: 'remove'
9
+ }.freeze
10
+ end
11
+
12
+ def list_system_icons
13
+ @theme = Gtk::IconTheme.default
14
+ puts @theme.icons
15
+ end
16
+
3
17
  def set_margin_from_opts_for(widget, options={})
4
18
  margin_top = options[:top].nil? ? nil : options[:top]
5
19
  margin_bottom = options[:bottom].nil? ? nil : options[:bottom]
@@ -7,8 +7,6 @@ module MittensUi
7
7
 
8
8
  @processing = false
9
9
 
10
- $vertical_box.pack_end(@spinner)
11
-
12
10
  super(@spinner, options)
13
11
 
14
12
  self.hide
@@ -0,0 +1,61 @@
1
+ require_relative "./core"
2
+
3
+ module MittensUi
4
+ class Notify < Core
5
+ def initialize(msg, options={})
6
+ @activate_timer = options[:timer] || true
7
+
8
+ @notify_bar = Gtk::InfoBar.new
9
+
10
+ @notify_bar.set_show_close_button(true)
11
+
12
+ msg_label = Gtk::Label.new(msg)
13
+
14
+ @notify_bar.message_type = set_msg_type(options)
15
+
16
+ @notify_bar.content_area.pack_start(msg_label)
17
+
18
+ setup_close_notification
19
+
20
+ super(@notify_bar, options)
21
+ end
22
+
23
+ def render
24
+ $vertical_box.pack_start(@notify_bar) unless $vertical_box.children.include?(@notify_bar)
25
+ $vertical_box.reorder_child(@notify_bar, 0)
26
+
27
+ @notify_bar.show_all
28
+
29
+ trigger_notify_timer if @activate_timer
30
+
31
+ return self
32
+ end
33
+
34
+ private
35
+ def set_msg_type(options={})
36
+ case options[:type]
37
+ when :question then Gtk::MessageType::QUESTION
38
+ when :error then Gtk::MessageType::ERROR
39
+ when :info then Gtk::MessageType::INFO
40
+ else Gtk::MessageType::INFO
41
+ end
42
+ end
43
+
44
+ def trigger_notify_timer
45
+ Thread.new {
46
+ sleep 8
47
+
48
+ if @notify_bar.visible?
49
+ @notify_bar.hide
50
+ end
51
+ }
52
+ end
53
+
54
+ def setup_close_notification
55
+ @notify_bar.signal_connect("response") do |info_bar, response_id|
56
+ @notify_bar.hide if response_id == Gtk::ResponseType::CLOSE
57
+ end
58
+ end
59
+
60
+ end
61
+ end
@@ -6,8 +6,15 @@ module MittensUi
6
6
  @textbox = Gtk::Entry.new
7
7
  can_edit = options[:can_edit].nil? ? true : options[:can_edit]
8
8
  max_length = options[:max_length].nil? ? 200 : options[:max_length]
9
+
10
+ has_password = options[:password].nil? ? false : options[:password]
11
+
9
12
  placeholder_text = options[:placeholder] || ""
10
13
 
14
+ if has_password
15
+ @textbox.set_visibility(false)
16
+ end
17
+
11
18
  @textbox.set_editable(can_edit) unless can_edit.nil?
12
19
  @textbox.set_max_length(max_length) unless max_length.nil?
13
20
  @textbox.set_placeholder_text(placeholder_text)
@@ -19,6 +26,21 @@ module MittensUi
19
26
  @textbox.text = ""
20
27
  end
21
28
 
29
+ def enable_text_completion(data)
30
+ completion = Gtk::EntryCompletion.new
31
+ @textbox.completion = completion
32
+
33
+ model = Gtk::ListStore.new(String)
34
+
35
+ data.each do |value|
36
+ iter = model.append
37
+ iter[0] = value
38
+ end
39
+
40
+ completion.model = model
41
+ completion.text_column = 0
42
+ end
43
+
22
44
  def text
23
45
  @textbox.text
24
46
  end
@@ -1,3 +1,3 @@
1
1
  module MittensUi
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
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.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Tuttle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-07 00:00:00.000000000 Z
11
+ date: 2021-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gtk3
@@ -46,6 +46,8 @@ files:
46
46
  - examples/assets/gnome_logo.png
47
47
  - examples/assets/mittens_ui_preview.gif
48
48
  - examples/contacts.rb
49
+ - examples/file_menu_example.rb
50
+ - examples/notify_example.rb
49
51
  - lib/mittens_ui.rb
50
52
  - lib/mittens_ui/alert.rb
51
53
  - lib/mittens_ui/assets/icon.png
@@ -53,6 +55,7 @@ files:
53
55
  - lib/mittens_ui/button.rb
54
56
  - lib/mittens_ui/checkbox.rb
55
57
  - lib/mittens_ui/core.rb
58
+ - lib/mittens_ui/file_menu.rb
56
59
  - lib/mittens_ui/file_picker.rb
57
60
  - lib/mittens_ui/grid.rb
58
61
  - lib/mittens_ui/hbox.rb
@@ -62,6 +65,7 @@ files:
62
65
  - lib/mittens_ui/label.rb
63
66
  - lib/mittens_ui/listbox.rb
64
67
  - lib/mittens_ui/loader.rb
68
+ - lib/mittens_ui/notify.rb
65
69
  - lib/mittens_ui/slider.rb
66
70
  - lib/mittens_ui/switch.rb
67
71
  - lib/mittens_ui/table_view.rb