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.
@@ -0,0 +1,159 @@
1
+ require_relative "./core"
2
+
3
+ module MittensUi
4
+ module Widgets
5
+ class TableView < Core
6
+ def initialize(options={})
7
+ headers = options[:headers] || []
8
+ data = options[:data] || []
9
+
10
+ unless is_data_valid?(headers, data)
11
+ exit 1
12
+ end
13
+
14
+ init_column_headers(headers)
15
+
16
+ init_list_store
17
+
18
+ @tree_view = Gtk::TreeView.new(@list_store)
19
+ @tree_view.selection.set_mode(:single)
20
+
21
+ @columns.each { |col| @tree_view.append_column(col) }
22
+
23
+ init_sortable_columns
24
+
25
+ init_data_rows(data)
26
+
27
+ $vertical_box.pack_start(@tree_view)
28
+
29
+ super(@tree_view)
30
+ end
31
+
32
+ def add(data, direction=:append)
33
+ return if data.size.zero?
34
+
35
+ case direction
36
+ when :append
37
+ iter = @list_store.append
38
+ when :prepend
39
+ iter = @list_store.prepend
40
+ else
41
+ iter = @list_store.append
42
+ end
43
+
44
+ data.each_with_index do |item, idx|
45
+ iter[idx] = item
46
+ end
47
+ end
48
+
49
+ def clear
50
+ @list_store.clear
51
+ end
52
+
53
+
54
+ def row_count
55
+ count = 0
56
+ @list_store.each { |item| count += 1 }
57
+
58
+ return count
59
+ end
60
+
61
+ def remove_selected
62
+ iter = @tree_view.selection.selected
63
+ iter ? @list_store.remove(iter) : nil
64
+ end
65
+
66
+ def row_clicked
67
+ @tree_view.signal_connect("row-activated") do |tv, path, column|
68
+ row = tv.selection.selected
69
+
70
+ values = []
71
+
72
+ @list_store.n_columns.times { |x| values << row.get_value(x) if row }
73
+
74
+ yield(values)
75
+ end
76
+ end
77
+
78
+ private
79
+
80
+ def is_data_valid?(headers, data)
81
+ column_size = headers.size
82
+
83
+ data_is_array = data.class == Array
84
+ headers_is_array = headers.class == Array
85
+
86
+ valid = true
87
+
88
+ unless data_is_array
89
+ puts "=====[MittensUi: Critical Error]====="
90
+ puts "Incoming data must be an Array of Arrays: data = [ [el..], [el...] ]"
91
+ valid = false
92
+ return valid
93
+ end
94
+
95
+ unless headers_is_array
96
+ puts "=====[MittensUi: Critical Error]====="
97
+ puts "Incoming data must be an Array of Arrays: data = [ [el..], [el...] ]"
98
+ valid = false
99
+ return valid
100
+ end
101
+
102
+ data.each_with_index do |row, idx|
103
+ # Row data must be an Array.
104
+ # The size of the Row Array must match the size of the Header columns.
105
+ valid = row.class == Array && column_size == row.size ? true : false
106
+
107
+ unless valid
108
+ puts
109
+ puts "=====[MittensUi: Critical Error]====="
110
+ puts "The length of your data(Row) must match the length of the headers."
111
+ puts "Failed at Row: #{idx}"
112
+ puts "Row Length: #{row.size} elements"
113
+ puts "Header Length #{column_size} elements"
114
+ puts
115
+ return valid
116
+ end
117
+ end
118
+ end
119
+
120
+ def init_sortable_columns
121
+ @columns.each_with_index do |col, idx|
122
+ col.sort_indicator = true
123
+ col.sort_column_id = idx
124
+
125
+ col.signal_connect('clicked') do |w|
126
+ w.sort_order = w.sort_order == :ascending ? :descending : :ascending
127
+ end
128
+ end
129
+ end
130
+
131
+ def init_list_store
132
+ types = []
133
+ @columns.size.times { types << String }
134
+ @list_store = Gtk::ListStore.new(*types)
135
+ end
136
+
137
+ def init_data_rows(data)
138
+ data.each_with_index do |items_arr|
139
+ iter = @list_store.append
140
+ items_arr.each_with_index do |item, idx|
141
+ iter[idx] = item
142
+ end
143
+ end
144
+ end
145
+
146
+ def init_column_headers(headers_list)
147
+ renderer = Gtk::CellRendererText.new
148
+
149
+ @columns = []
150
+
151
+ headers_list.each_with_index do |h, i|
152
+ next unless h.class == String
153
+ @columns << Gtk::TreeViewColumn.new(h, renderer, text: i)
154
+ end
155
+ end
156
+
157
+ end
158
+ end
159
+ end
@@ -1,7 +1,9 @@
1
+ require_relative "./core"
2
+
1
3
  module MittensUi
2
4
  module Widgets
3
- class Textbox
4
- def initialize(layout, options)
5
+ class Textbox < Core
6
+ def initialize(options={})
5
7
  @textbox = Gtk::Entry.new
6
8
  can_edit = options[:can_edit].nil? ? true : options[:can_edit]
7
9
  max_length = options[:max_length].nil? ? 200 : options[:max_length]
@@ -9,20 +11,17 @@ module MittensUi
9
11
  @textbox.set_editable(can_edit) unless can_edit.nil?
10
12
  @textbox.set_max_length(max_length) unless max_length.nil?
11
13
 
12
- if layout
13
- layout.pack_start(@textbox)
14
- end
14
+ $vertical_box.pack_start(@textbox)
15
15
 
16
- return @textbox
16
+ super(@textbox)
17
17
  end
18
18
 
19
- def text
20
- @textbox.text
19
+ def clear
20
+ @textbox.text = ""
21
21
  end
22
22
 
23
- def remove
24
- return if @textbox.nil?
25
- @textbox.destroy
23
+ def text
24
+ @textbox.text
26
25
  end
27
26
  end
28
27
  end
@@ -0,0 +1,23 @@
1
+ require_relative "./core"
2
+
3
+ module MittensUi
4
+ module Widgets
5
+ class WebLink < Core
6
+ attr_accessor :url
7
+
8
+ def initialize(name, url, options={})
9
+ @name = name || ""
10
+
11
+ @url = url || nil
12
+
13
+ @web_link = Gtk::LinkButton.new(@url, @name)
14
+
15
+ set_margin_from_opts_for(@web_link, options)
16
+
17
+ $vertical_box.pack_start(@web_link)
18
+
19
+ super(@web_link)
20
+ end
21
+ end
22
+ end
23
+ end
data/mittens_ui.gemspec CHANGED
@@ -4,9 +4,9 @@ Gem::Specification.new do |spec|
4
4
  spec.name = "mittens_ui"
5
5
  spec.version = MittensUi::VERSION
6
6
  spec.authors = ["Zach Tuttle"]
7
- spec.email = ["zachtuttle@tutanota.com"]
8
-
9
- spec.summary = "A tiny GUI toolkit written on top of GTK3"
7
+ spec.email = ["tuttle_zach@icloud.com"]
8
+ spec.licenses = ['MIT']
9
+ spec.summary = "A tiny GUI toolkit written on top of GTK"
10
10
  spec.description = "GUI Toolkit!"
11
11
  spec.homepage = "https://github.com/tuttza/mittens_ui"
12
12
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
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.4
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Tuttle
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-14 00:00:00.000000000 Z
11
+ date: 2021-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gtk3
@@ -26,39 +26,53 @@ dependencies:
26
26
  version: '0'
27
27
  description: GUI Toolkit!
28
28
  email:
29
- - zachtuttle@tutanota.com
29
+ - tuttle_zach@icloud.com
30
30
  executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
34
  - ".gitignore"
35
35
  - ".rspec"
36
+ - ".ruby-version"
36
37
  - ".travis.yml"
37
38
  - Gemfile
38
39
  - Gemfile.lock
40
+ - LICENSE
39
41
  - README.md
40
42
  - Rakefile
41
43
  - bin/console
42
44
  - bin/setup
43
45
  - examples/app.rb
46
+ - examples/assets/gnome_logo.png
47
+ - examples/brightness_controller.rb
44
48
  - lib/mittens_ui.rb
49
+ - lib/mittens_ui/dialogs/file_dialog.rb
50
+ - lib/mittens_ui/helpers.rb
45
51
  - lib/mittens_ui/layouts/box.rb
46
52
  - lib/mittens_ui/layouts/grid.rb
47
53
  - lib/mittens_ui/version.rb
48
54
  - lib/mittens_ui/widgets/alert.rb
49
55
  - lib/mittens_ui/widgets/button.rb
56
+ - lib/mittens_ui/widgets/checkbox.rb
57
+ - lib/mittens_ui/widgets/core.rb
58
+ - lib/mittens_ui/widgets/image.rb
50
59
  - lib/mittens_ui/widgets/label.rb
51
60
  - lib/mittens_ui/widgets/listbox.rb
61
+ - lib/mittens_ui/widgets/loader.rb
52
62
  - lib/mittens_ui/widgets/slider.rb
63
+ - lib/mittens_ui/widgets/switch.rb
64
+ - lib/mittens_ui/widgets/table_view.rb
53
65
  - lib/mittens_ui/widgets/textbox.rb
66
+ - lib/mittens_ui/widgets/web_link.rb
54
67
  - mittens_ui.gemspec
55
68
  - notes/gtk.txt
56
69
  homepage: https://github.com/tuttza/mittens_ui
57
- licenses: []
70
+ licenses:
71
+ - MIT
58
72
  metadata:
59
73
  homepage_uri: https://github.com/tuttza/mittens_ui
60
74
  source_code_uri: https://github.com/tuttza/mittens_ui
61
- post_install_message:
75
+ post_install_message:
62
76
  rdoc_options: []
63
77
  require_paths:
64
78
  - lib
@@ -73,8 +87,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
87
  - !ruby/object:Gem::Version
74
88
  version: '0'
75
89
  requirements: []
76
- rubygems_version: 3.1.4
77
- signing_key:
90
+ rubygems_version: 3.2.15
91
+ signing_key:
78
92
  specification_version: 4
79
- summary: A tiny GUI toolkit written on top of GTK3
93
+ summary: A tiny GUI toolkit written on top of GTK
80
94
  test_files: []