gtk3assist 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/gtk3assist.gemspec +74 -0
- data/lib/gtk3assist_builder.rb +5 -1
- data/lib/gtk3assist_combobox.rb +102 -0
- data/lib/gtk3assist_msgbox.rb +152 -0
- data/spec/gtk3assist_combobox_spec.rb +42 -0
- data/spec/gtk3assist_msgbox_spec.rb +21 -0
- metadata +8 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/gtk3assist.gemspec
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "gtk3assist"
|
8
|
+
s.version = "0.0.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Kasper Johansen"]
|
12
|
+
s.date = "2012-09-13"
|
13
|
+
s.description = "A class for making it easier to develop Gtk3 based applications with the 'gir_ffi-gtk'-gem."
|
14
|
+
s.email = "k@spernj.org"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"gtk3assist.gemspec",
|
29
|
+
"lib/gtk3assist.rb",
|
30
|
+
"lib/gtk3assist_builder.rb",
|
31
|
+
"lib/gtk3assist_combobox.rb",
|
32
|
+
"lib/gtk3assist_msgbox.rb",
|
33
|
+
"lib/gtk3assist_treeview.rb",
|
34
|
+
"spec/gtk3assist_builder.glade",
|
35
|
+
"spec/gtk3assist_builder_spec.rb",
|
36
|
+
"spec/gtk3assist_combobox_spec.rb",
|
37
|
+
"spec/gtk3assist_msgbox_spec.rb",
|
38
|
+
"spec/gtk3assist_treeview_spec.rb",
|
39
|
+
"spec/spec_helper.rb"
|
40
|
+
]
|
41
|
+
s.homepage = "http://github.com/kaspernj/gtk3assist"
|
42
|
+
s.licenses = ["MIT"]
|
43
|
+
s.require_paths = ["lib"]
|
44
|
+
s.rubygems_version = "1.8.24"
|
45
|
+
s.summary = "A class for making it easier to develop Gtk3 based applications with the 'gir_ffi-gtk'-gem."
|
46
|
+
|
47
|
+
if s.respond_to? :specification_version then
|
48
|
+
s.specification_version = 3
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_runtime_dependency(%q<gir_ffi-gtk>, [">= 0"])
|
52
|
+
s.add_runtime_dependency(%q<xml-simple>, [">= 0"])
|
53
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
54
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
55
|
+
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
56
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<gir_ffi-gtk>, [">= 0"])
|
59
|
+
s.add_dependency(%q<xml-simple>, [">= 0"])
|
60
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
61
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
62
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
63
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
64
|
+
end
|
65
|
+
else
|
66
|
+
s.add_dependency(%q<gir_ffi-gtk>, [">= 0"])
|
67
|
+
s.add_dependency(%q<xml-simple>, [">= 0"])
|
68
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
69
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
70
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
71
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
data/lib/gtk3assist_builder.rb
CHANGED
@@ -4,7 +4,7 @@ class Gtk3assist::Builder
|
|
4
4
|
ARGS_ALLOWED = [:builder]
|
5
5
|
|
6
6
|
#Constructor.
|
7
|
-
def initialize(args)
|
7
|
+
def initialize(args = {})
|
8
8
|
raise "'args' was not a hash." if !args.is_a?(Hash)
|
9
9
|
args.each do |key, val|
|
10
10
|
raise "Invalid argument: '#{key}'." if !ARGS_ALLOWED.include?(key)
|
@@ -16,7 +16,11 @@ class Gtk3assist::Builder
|
|
16
16
|
#Adds the given filepath to the builder and sets filepath for signal-connects.
|
17
17
|
def add_from_file(fpath)
|
18
18
|
@fpath = fpath
|
19
|
+
|
20
|
+
@builder = Gtk::Builder.new if !@builder
|
19
21
|
@builder.add_from_file(fpath)
|
22
|
+
|
23
|
+
return self
|
20
24
|
end
|
21
25
|
|
22
26
|
#Returns a widget from a given key.
|
@@ -0,0 +1,102 @@
|
|
1
|
+
#This class contains code than can optimize productivity when coding comboboxes.
|
2
|
+
class Gtk3assist::Combobox
|
3
|
+
#An array containing allowed arguments for the constructor.
|
4
|
+
ARGS_ALLOWED = [:cb]
|
5
|
+
|
6
|
+
#An array containing allowed arguments for the 'add_item'-method.
|
7
|
+
ARGS_ALLOWED_ADD_ITEM = [:id, :title]
|
8
|
+
|
9
|
+
#The combobox-widget that this object handels.
|
10
|
+
attr_reader :cb
|
11
|
+
|
12
|
+
#Constructor.
|
13
|
+
def initialize(args = {})
|
14
|
+
raise "'args' was not a hash." if !args.is_a?(Hash)
|
15
|
+
args.each do |key, val|
|
16
|
+
raise "Invalid argument: '#{key}'." if !ARGS_ALLOWED.include?(key)
|
17
|
+
end
|
18
|
+
|
19
|
+
@objs = {}
|
20
|
+
|
21
|
+
if args[:cb]
|
22
|
+
@cb = args[:cb]
|
23
|
+
else
|
24
|
+
@cb = Gtk::ComboBox.new
|
25
|
+
end
|
26
|
+
|
27
|
+
@rend = Gtk::CellRendererText.new
|
28
|
+
@cb.pack_start(@rend, false)
|
29
|
+
@cb.add_attribute(@rend, "text", 0)
|
30
|
+
|
31
|
+
@model = Gtk::ListStore.new([GObject::TYPE_STRING, GObject::TYPE_STRING])
|
32
|
+
@cb.set_model(@model)
|
33
|
+
@cb.show
|
34
|
+
end
|
35
|
+
|
36
|
+
#Adds a new item to the combobox with ID and title.
|
37
|
+
def add_item(args)
|
38
|
+
raise "'args' was not a hash." if !args.is_a?(Hash)
|
39
|
+
args.each do |key, val|
|
40
|
+
raise "Invalid argument: '#{key}'." if !ARGS_ALLOWED_ADD_ITEM.include?(key)
|
41
|
+
end
|
42
|
+
|
43
|
+
raise "No ':title' was given." if !args[:title]
|
44
|
+
raise "No ':id' was given." if !args[:id]
|
45
|
+
|
46
|
+
iter = @model.append
|
47
|
+
@model.set_value(iter, 0, args[:title])
|
48
|
+
|
49
|
+
@objs[args[:id]] = {:iter => iter}
|
50
|
+
end
|
51
|
+
|
52
|
+
#Selects a certain item by id.
|
53
|
+
def sel_id(args)
|
54
|
+
raise "'args' was not a hash." if !args.is_a?(Hash)
|
55
|
+
raise "No ':id' was given." if !args.key?(:id)
|
56
|
+
|
57
|
+
@objs.each do |id, data|
|
58
|
+
if id == args[:id]
|
59
|
+
@cb.set_active_iter(data[:iter])
|
60
|
+
return nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
raise "Could not find item by that id: '#{args[:id]}'."
|
65
|
+
end
|
66
|
+
|
67
|
+
#Returns the selected item.
|
68
|
+
def sel
|
69
|
+
return self.items(:selected => true).next
|
70
|
+
end
|
71
|
+
|
72
|
+
#Enumerates over every single item in the combobox.
|
73
|
+
def items(args = nil, &blk)
|
74
|
+
enum = Enumerator.new do |y|
|
75
|
+
if args and args[:selected]
|
76
|
+
iter_cur = @cb.get_active_iter.last
|
77
|
+
else
|
78
|
+
iter_cur = @model.iter_first.last
|
79
|
+
end
|
80
|
+
|
81
|
+
while iter_cur
|
82
|
+
match = true
|
83
|
+
|
84
|
+
if match
|
85
|
+
y << {
|
86
|
+
:data => {
|
87
|
+
:title => @model.get_value(iter_cur, 0).get_string
|
88
|
+
}
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
break if !@model.iter_next(iter_cur) or (args and args[:selected])
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
if blk
|
97
|
+
enum.each(&blk)
|
98
|
+
else
|
99
|
+
return enum
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
class Gtk3assist::Msgbox
|
2
|
+
#An array of possible arguments that the constructor accepts.
|
3
|
+
ARGS_ALLOWED = [:msg, :parent, :run, :title, :type]
|
4
|
+
|
5
|
+
#Various data like the current showing messagebox.
|
6
|
+
DATA = {}
|
7
|
+
|
8
|
+
#The Gtk::Dialog-object.
|
9
|
+
attr_reader :dialog
|
10
|
+
|
11
|
+
#The result of the dialog.
|
12
|
+
attr_reader :result
|
13
|
+
|
14
|
+
def self.current
|
15
|
+
raise "No current showing message-box." if !DATA[:current]
|
16
|
+
end
|
17
|
+
|
18
|
+
#Constructor.
|
19
|
+
def initialize(args)
|
20
|
+
raise "'args' wasnt a hash." if !args.is_a?(Hash)
|
21
|
+
args.each do |key, val|
|
22
|
+
raise "Invalid argument: '#{key}'." if !ARGS_ALLOWED.include?(key)
|
23
|
+
end
|
24
|
+
|
25
|
+
raise "No ':msg' was given." if args[:msg].to_s.strip.empty?
|
26
|
+
args[:type] = :info if !args[:type]
|
27
|
+
|
28
|
+
if !args[:title]
|
29
|
+
case args[:type]
|
30
|
+
when :warning
|
31
|
+
args[:title] = _("Warning")
|
32
|
+
when :yesno
|
33
|
+
args[:title] = _("Question")
|
34
|
+
when :info
|
35
|
+
args[:title] = _("Information")
|
36
|
+
else
|
37
|
+
raise "Unknown type: '#{args[:type]}'."
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
@dialog = Gtk::Dialog.new
|
42
|
+
@dialog.resize(350, 1)
|
43
|
+
@dialog.set_title(args[:title])
|
44
|
+
|
45
|
+
DATA[:current] = self
|
46
|
+
@dialog.signal_connect("destroy") do
|
47
|
+
DATA.delete(:current)
|
48
|
+
end
|
49
|
+
|
50
|
+
box = Gtk::Box.new(Gtk::Orientation[:horizontal], 4)
|
51
|
+
@dialog.get_content_area.add(box)
|
52
|
+
|
53
|
+
case args[:type]
|
54
|
+
when :warning, :info
|
55
|
+
if args[:type] == :info
|
56
|
+
image = Gtk::Image.new_from_stock(Gtk::STOCK_DIALOG_INFO, Gtk::IconSize[:dialog])
|
57
|
+
elsif args[:type] == :warning
|
58
|
+
image = Gtk::Image.new_from_stock(Gtk::STOCK_DIALOG_WARNING, Gtk::IconSize[:dialog])
|
59
|
+
else
|
60
|
+
raise "Unknown type: '#{args[:type]}'."
|
61
|
+
end
|
62
|
+
|
63
|
+
box.pack_start(image, false, false, 4)
|
64
|
+
image.show
|
65
|
+
|
66
|
+
lab = Gtk::Label.new(args[:msg])
|
67
|
+
lab.set_selectable(true)
|
68
|
+
lab.set_justify(Gtk::Justification[:left])
|
69
|
+
|
70
|
+
box.pack_start(lab, false, false, 4)
|
71
|
+
lab.show
|
72
|
+
|
73
|
+
but = Gtk::Button.new_from_stock(Gtk::STOCK_OK)
|
74
|
+
but.signal_connect("clicked") do
|
75
|
+
@result = Gtk::ResponseType[:ok]
|
76
|
+
@dialog.response(@result)
|
77
|
+
@dialog.destroy
|
78
|
+
end
|
79
|
+
|
80
|
+
res = Gtk::ResponseType[:ok]
|
81
|
+
@dialog.get_action_area.add(but)
|
82
|
+
but.show
|
83
|
+
when :yesno
|
84
|
+
image = Gtk::Image.new_from_stock(Gtk::STOCK_DIALOG_QUESTION, Gtk::IconSize[:dialog])
|
85
|
+
|
86
|
+
box.pack_start(image, false, false, 4)
|
87
|
+
image.show
|
88
|
+
|
89
|
+
lab = Gtk::Label.new(args[:msg])
|
90
|
+
lab.set_selectable(true)
|
91
|
+
lab.set_justify(Gtk::Justification[:left])
|
92
|
+
|
93
|
+
box.pack_start(lab, false, false, 4)
|
94
|
+
lab.show
|
95
|
+
|
96
|
+
but_yes = Gtk::Button.new_from_stock(Gtk::STOCK_YES)
|
97
|
+
but_yes.signal_connect("clicked") do
|
98
|
+
@result = Gtk::ResponseType[:yes]
|
99
|
+
@dialog.response(@result)
|
100
|
+
end
|
101
|
+
|
102
|
+
but_no = Gtk::Button.new_from_stock(Gtk::STOCK_NO)
|
103
|
+
but_no.signal_connect("clicked") do
|
104
|
+
@result = Gtk::ResponseType[:no]
|
105
|
+
@dialog.response(@result)
|
106
|
+
end
|
107
|
+
else
|
108
|
+
raise "Unknown type: '#{args[:type]}'."
|
109
|
+
end
|
110
|
+
|
111
|
+
box.show
|
112
|
+
@result = @dialog.run if !args.key?(:run) or args[:run]
|
113
|
+
end
|
114
|
+
|
115
|
+
#Runs the dialog.
|
116
|
+
def run
|
117
|
+
@result = @dialog.run
|
118
|
+
return @result
|
119
|
+
end
|
120
|
+
|
121
|
+
#Shows the dialog but doesnt run it.
|
122
|
+
def show
|
123
|
+
@dialog.show
|
124
|
+
end
|
125
|
+
|
126
|
+
#Responds to the dialog.
|
127
|
+
def respond(res)
|
128
|
+
case res
|
129
|
+
when :cancel, :no, :ok, :yes
|
130
|
+
@result = Gtk::ResponseType[res]
|
131
|
+
@dialog.response(@result)
|
132
|
+
else
|
133
|
+
raise "Unknown response: '#{res}'."
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
#Returns the result as a string.
|
138
|
+
def result_text
|
139
|
+
raise "No result yet." if !@result
|
140
|
+
return Gtk::ResponseType[@result].to_sym
|
141
|
+
end
|
142
|
+
|
143
|
+
#Contains a fallback method for '_' which is used to translate texts in the GetText-library.
|
144
|
+
def method_missing(method, *args, &block)
|
145
|
+
case method
|
146
|
+
when :_
|
147
|
+
return args[0]
|
148
|
+
else
|
149
|
+
raise NameError, "No such method: '#{method}'."
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Gtk3assist_combobox" do
|
4
|
+
it "should work" do
|
5
|
+
Gtk.init
|
6
|
+
|
7
|
+
win = Gtk::Window.new(:toplevel)
|
8
|
+
win.resize(640, 5)
|
9
|
+
win.signal_connect("destroy") do
|
10
|
+
Gtk.main_quit
|
11
|
+
end
|
12
|
+
|
13
|
+
cba = Gtk3assist::Combobox.new
|
14
|
+
cba.add_item(:id => 1, :title => "Kasper")
|
15
|
+
cba.add_item(:id => 2, :title => "Christina")
|
16
|
+
|
17
|
+
win.add(cba.cb)
|
18
|
+
win.show_all
|
19
|
+
|
20
|
+
cba.sel_id(:id => 1)
|
21
|
+
data = cba.sel
|
22
|
+
|
23
|
+
raise "Expected selected data to be a hash but it wasnt: '#{data.class.name}'." if !data.is_a?(Hash)
|
24
|
+
raise "Expected selected title to be 'Kasper' but it wasnt: '#{data[:data][:title]}'." if data[:data][:title] != "Kasper"
|
25
|
+
|
26
|
+
cba.sel_id(:id => 2)
|
27
|
+
data = cba.sel
|
28
|
+
|
29
|
+
raise "Expected selected data to be a hash but it wasnt: '#{data.class.name}'." if !data.is_a?(Hash)
|
30
|
+
raise "Expected selected title to be 'Kasper' but it wasnt: '#{data[:data][:title]}'." if data[:data][:title] != "Christina"
|
31
|
+
|
32
|
+
count = 0
|
33
|
+
cba.rows do |data|
|
34
|
+
#puts data
|
35
|
+
count += 1
|
36
|
+
end
|
37
|
+
|
38
|
+
raise "Expected count to be 2 but it wasnt: '#{count}'." if count != 2
|
39
|
+
|
40
|
+
#Gtk.main
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Gtk3assist_msgbox" do
|
4
|
+
it "should work" do
|
5
|
+
Gtk.init
|
6
|
+
|
7
|
+
|
8
|
+
msg = Gtk3assist::Msgbox.new(:type => :warning, :msg => "This is a test.", :run => false)
|
9
|
+
msg.show
|
10
|
+
msg.respond(:cancel)
|
11
|
+
res = msg.result_text
|
12
|
+
raise "Expected cancel but got: '#{res}'." if res != :cancel
|
13
|
+
|
14
|
+
|
15
|
+
msg = Gtk3assist::Msgbox.new(:type => :yesno, :msg => "Do you like ice-cream?", :run => false)
|
16
|
+
msg.show
|
17
|
+
msg.respond(:yes)
|
18
|
+
res = msg.result_text
|
19
|
+
raise "Expected yes but got: '#{res}'." if res != :yes
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: gtk3assist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Kasper Johansen
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-09-
|
13
|
+
date: 2012-09-13 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: gir_ffi-gtk
|
@@ -96,11 +96,16 @@ files:
|
|
96
96
|
- README.rdoc
|
97
97
|
- Rakefile
|
98
98
|
- VERSION
|
99
|
+
- gtk3assist.gemspec
|
99
100
|
- lib/gtk3assist.rb
|
100
101
|
- lib/gtk3assist_builder.rb
|
102
|
+
- lib/gtk3assist_combobox.rb
|
103
|
+
- lib/gtk3assist_msgbox.rb
|
101
104
|
- lib/gtk3assist_treeview.rb
|
102
105
|
- spec/gtk3assist_builder.glade
|
103
106
|
- spec/gtk3assist_builder_spec.rb
|
107
|
+
- spec/gtk3assist_combobox_spec.rb
|
108
|
+
- spec/gtk3assist_msgbox_spec.rb
|
104
109
|
- spec/gtk3assist_treeview_spec.rb
|
105
110
|
- spec/spec_helper.rb
|
106
111
|
homepage: http://github.com/kaspernj/gtk3assist
|
@@ -116,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
121
|
requirements:
|
117
122
|
- - ">="
|
118
123
|
- !ruby/object:Gem::Version
|
119
|
-
hash: -
|
124
|
+
hash: -4119379591708986058
|
120
125
|
segments:
|
121
126
|
- 0
|
122
127
|
version: "0"
|