gtk3assist 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +41 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/lib/gtk3assist.rb +12 -0
- data/lib/gtk3assist_builder.rb +67 -0
- data/lib/gtk3assist_treeview.rb +148 -0
- data/spec/gtk3assist_builder.glade +154 -0
- data/spec/gtk3assist_builder_spec.rb +36 -0
- data/spec/gtk3assist_treeview_spec.rb +40 -0
- data/spec/spec_helper.rb +12 -0
- metadata +137 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem "gir_ffi-gtk"
|
7
|
+
gem "xml-simple"
|
8
|
+
|
9
|
+
# Add dependencies to develop your gem here.
|
10
|
+
# Include everything needed to run rake, tests, features, etc.
|
11
|
+
group :development do
|
12
|
+
gem "rspec", "~> 2.8.0"
|
13
|
+
gem "rdoc", "~> 3.12"
|
14
|
+
gem "bundler", ">= 1.0.0"
|
15
|
+
gem "jeweler", "~> 1.8.4"
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
ffi (1.0.11)
|
6
|
+
gir_ffi (0.4.0)
|
7
|
+
ffi (~> 1.0.8)
|
8
|
+
indentation (~> 0.0.6)
|
9
|
+
gir_ffi-gtk (0.4.0)
|
10
|
+
gir_ffi (~> 0.4.0)
|
11
|
+
git (1.2.5)
|
12
|
+
indentation (0.0.6)
|
13
|
+
jeweler (1.8.4)
|
14
|
+
bundler (~> 1.0)
|
15
|
+
git (>= 1.2.5)
|
16
|
+
rake
|
17
|
+
rdoc
|
18
|
+
json (1.7.5)
|
19
|
+
rake (0.9.2.2)
|
20
|
+
rdoc (3.12)
|
21
|
+
json (~> 1.4)
|
22
|
+
rspec (2.8.0)
|
23
|
+
rspec-core (~> 2.8.0)
|
24
|
+
rspec-expectations (~> 2.8.0)
|
25
|
+
rspec-mocks (~> 2.8.0)
|
26
|
+
rspec-core (2.8.0)
|
27
|
+
rspec-expectations (2.8.0)
|
28
|
+
diff-lcs (~> 1.1.2)
|
29
|
+
rspec-mocks (2.8.0)
|
30
|
+
xml-simple (1.1.1)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
bundler (>= 1.0.0)
|
37
|
+
gir_ffi-gtk
|
38
|
+
jeweler (~> 1.8.4)
|
39
|
+
rdoc (~> 3.12)
|
40
|
+
rspec (~> 2.8.0)
|
41
|
+
xml-simple
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Kasper Johansen
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= gtk3assist
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to gtk3assist
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2012 Kasper Johansen. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "gtk3assist"
|
18
|
+
gem.homepage = "http://github.com/kaspernj/gtk3assist"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{A class for making it easier to develop Gtk3 based applications with the 'gir_ffi-gtk'-gem.}
|
21
|
+
gem.description = %Q{A class for making it easier to develop Gtk3 based applications with the 'gir_ffi-gtk'-gem.}
|
22
|
+
gem.email = "k@spernj.org"
|
23
|
+
gem.authors = ["Kasper Johansen"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "gtk3assist #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/lib/gtk3assist.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "gir_ffi"
|
2
|
+
require "gir_ffi-gtk3"
|
3
|
+
|
4
|
+
#This class has various sub-classes which can help developing applications using the 'gir_ffi-gtk'-gtk3-framework.
|
5
|
+
class Gtk3assist
|
6
|
+
#Autoloader for subclasses.
|
7
|
+
def self.const_missing(name)
|
8
|
+
require "#{File.dirname(__FILE__)}/gtk3assist_#{name.to_s.downcase}.rb"
|
9
|
+
raise "Still not defined: '#{name}'." if !Gtk3assist.const_defined?(name)
|
10
|
+
return Gtk3assist.const_get(name)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#Helper class for Gtk::Builder which can do automatic signal-connect by scanning the Xml-file and more.
|
2
|
+
class Gtk3assist::Builder
|
3
|
+
#Array containing allowed arguments for contructor.
|
4
|
+
ARGS_ALLOWED = [:builder]
|
5
|
+
|
6
|
+
#Constructor.
|
7
|
+
def initialize(args)
|
8
|
+
raise "'args' was not a hash." if !args.is_a?(Hash)
|
9
|
+
args.each do |key, val|
|
10
|
+
raise "Invalid argument: '#{key}'." if !ARGS_ALLOWED.include?(key)
|
11
|
+
end
|
12
|
+
|
13
|
+
@builder = args[:builder]
|
14
|
+
end
|
15
|
+
|
16
|
+
#Adds the given filepath to the builder and sets filepath for signal-connects.
|
17
|
+
def add_from_file(fpath)
|
18
|
+
@fpath = fpath
|
19
|
+
@builder.add_from_file(fpath)
|
20
|
+
end
|
21
|
+
|
22
|
+
#Returns a widget from a given key.
|
23
|
+
def [](key)
|
24
|
+
obj = @builder.get_object(key)
|
25
|
+
raise "No object by that name: '#{key}'." if !obj
|
26
|
+
return obj
|
27
|
+
end
|
28
|
+
|
29
|
+
#Connects all signals to methods given by the supplied block.
|
30
|
+
def connect_signals(&blk)
|
31
|
+
str = File.read(@fpath)
|
32
|
+
|
33
|
+
require "xmlsimple"
|
34
|
+
data = XmlSimple.xml_in(str)
|
35
|
+
connect_signals_from_filepath_helper(data, blk)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
#Used to recursivly scan XML-file for signals.
|
41
|
+
def connect_signals_from_filepath_helper(data, blk)
|
42
|
+
data.each do |item|
|
43
|
+
if item.is_a?(Hash) and item.key?("id") and item.key?("signal")
|
44
|
+
item["signal"].each do |signal_data|
|
45
|
+
method = blk.call(signal_data["handler"])
|
46
|
+
object = self[item["id"].to_s]
|
47
|
+
|
48
|
+
object.signal_connect(signal_data["name"]) do |*args|
|
49
|
+
#Convert arguments to fit the arity-count of the Proc-object (the block, the method or whatever you want to call it).
|
50
|
+
newargs = []
|
51
|
+
0.upto(method.arity - 1) do |number|
|
52
|
+
if paras[number]
|
53
|
+
newargs << args[number]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
method.call(*newargs)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
if item.is_a?(Array) or item.is_a?(Hash)
|
63
|
+
connect_signals_from_filepath_helper(item, blk)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
#This class contains various code that can greatly speed up the building and handeling of treeviews.
|
2
|
+
class Gtk3assist::Treeview
|
3
|
+
#The treeview that this object manipulates.
|
4
|
+
attr_reader :tv
|
5
|
+
|
6
|
+
#The model-object that is used by the treeview.
|
7
|
+
attr_reader :model
|
8
|
+
|
9
|
+
#An array of allowed arguments for the 'initialize'-method.
|
10
|
+
ALLOWED_ARGS = [:tv, :cols, :model]
|
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 !ALLOWED_ARGS.include?(key)
|
17
|
+
end
|
18
|
+
|
19
|
+
@columns = []
|
20
|
+
@tv = args[:tv]
|
21
|
+
raise "No ':tv' argument was given." if !@tv.is_a?(Gtk::TreeView)
|
22
|
+
|
23
|
+
if args[:cols]
|
24
|
+
args[:cols].each do |val|
|
25
|
+
self.add_column(val)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
if args[:model]
|
30
|
+
if args[:model] == :liststore
|
31
|
+
self.init_liststore
|
32
|
+
else
|
33
|
+
raise "Unknown model: '#{args[:model]}'."
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
#Initializes a new list-store on the treeview.
|
39
|
+
def init_liststore
|
40
|
+
liststore_args = []
|
41
|
+
@columns.each do |col_data|
|
42
|
+
if col_data[:type] == :string
|
43
|
+
liststore_args << GObject::TYPE_STRING
|
44
|
+
else
|
45
|
+
raise "Unknown column-type: '#{col_data[:type]}'."
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
@model = Gtk::ListStore.new(liststore_args)
|
50
|
+
@tv.set_model(@model)
|
51
|
+
end
|
52
|
+
|
53
|
+
#Adds a new column to the treeview.
|
54
|
+
def add_column(args)
|
55
|
+
if args.is_a?(Hash)
|
56
|
+
#ignore.
|
57
|
+
elsif args.is_a?(String)
|
58
|
+
args = {:type => :string, :title => args, :id => args.to_s.downcase.to_sym}
|
59
|
+
else
|
60
|
+
raise "Unknown argument given: '#{argument.class.name}'."
|
61
|
+
end
|
62
|
+
|
63
|
+
renderer = Gtk::CellRendererText.new
|
64
|
+
lab = Gtk::Label.new(args[:title])
|
65
|
+
|
66
|
+
col = Gtk::TreeViewColumn.new
|
67
|
+
col.set_widget(lab)
|
68
|
+
col.pack_start(renderer, true)
|
69
|
+
col.add_attribute(renderer, "text", @columns.length)
|
70
|
+
|
71
|
+
lab.show
|
72
|
+
@tv.append_column(col)
|
73
|
+
|
74
|
+
@columns << {
|
75
|
+
:col => col,
|
76
|
+
:lab => lab,
|
77
|
+
:id => args[:id],
|
78
|
+
:type => args[:type]
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
#Add a new row to the treeview.
|
83
|
+
def add_row(args)
|
84
|
+
if @model.is_a?(Gtk::ListStore)
|
85
|
+
data = []
|
86
|
+
@columns.each do |col_data|
|
87
|
+
found = false
|
88
|
+
args[:data].each do |key, val|
|
89
|
+
if key == col_data[:id]
|
90
|
+
data << val
|
91
|
+
found = true
|
92
|
+
break
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
raise "Not found: '#{col_data[:id]}' (#{col_data})." if !found
|
97
|
+
end
|
98
|
+
|
99
|
+
iter = @model.append
|
100
|
+
count = 0
|
101
|
+
data.each do |val|
|
102
|
+
col_data = @columns[count]
|
103
|
+
|
104
|
+
if col_data[:type] == :string
|
105
|
+
@model.set_value(iter, count, val.to_s)
|
106
|
+
else
|
107
|
+
raise "Unknown column-type: '#{col_data[:type]}'."
|
108
|
+
end
|
109
|
+
|
110
|
+
count += 1
|
111
|
+
end
|
112
|
+
else
|
113
|
+
raise "Unknown model: '#{@model.class.name}'."
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
#Enumerates over every row in the treeview.
|
118
|
+
def rows(args = nil, &block)
|
119
|
+
enum = Enumerator.new do |y|
|
120
|
+
iter_cur = @model.iter_first.last
|
121
|
+
|
122
|
+
while iter_cur
|
123
|
+
match = true
|
124
|
+
|
125
|
+
if match
|
126
|
+
data = []
|
127
|
+
@columns.each do |col_data|
|
128
|
+
if col_data[:type] == :string
|
129
|
+
data << @model.get_value(iter_cur, 1).get_string
|
130
|
+
else
|
131
|
+
raise "Unknown column-type: '#{col_data[:type]}'."
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
y << {:data => data}
|
136
|
+
end
|
137
|
+
|
138
|
+
break if !@model.iter_next(iter_cur)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
if block
|
143
|
+
enum.each(&block)
|
144
|
+
else
|
145
|
+
return enum
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<interface>
|
3
|
+
<!-- interface-requires gtk+ 3.0 -->
|
4
|
+
<object class="GtkWindow" id="window">
|
5
|
+
<property name="can_focus">False</property>
|
6
|
+
<property name="border_width">4</property>
|
7
|
+
<property name="title" translatable="yes">Test window</property>
|
8
|
+
<property name="window_position">center</property>
|
9
|
+
<property name="default_width">640</property>
|
10
|
+
<property name="default_height">480</property>
|
11
|
+
<signal name="destroy" handler="on_window_destroy" swapped="no"/>
|
12
|
+
<child>
|
13
|
+
<object class="GtkBox" id="box1">
|
14
|
+
<property name="visible">True</property>
|
15
|
+
<property name="can_focus">False</property>
|
16
|
+
<property name="orientation">vertical</property>
|
17
|
+
<child>
|
18
|
+
<object class="GtkFrame" id="frame1">
|
19
|
+
<property name="visible">True</property>
|
20
|
+
<property name="can_focus">False</property>
|
21
|
+
<property name="label_xalign">0</property>
|
22
|
+
<property name="shadow_type">none</property>
|
23
|
+
<child>
|
24
|
+
<object class="GtkAlignment" id="alignment1">
|
25
|
+
<property name="visible">True</property>
|
26
|
+
<property name="can_focus">False</property>
|
27
|
+
<property name="left_padding">12</property>
|
28
|
+
<child>
|
29
|
+
<object class="GtkBox" id="box2">
|
30
|
+
<property name="visible">True</property>
|
31
|
+
<property name="can_focus">False</property>
|
32
|
+
<property name="orientation">vertical</property>
|
33
|
+
<property name="spacing">4</property>
|
34
|
+
<child>
|
35
|
+
<object class="GtkGrid" id="grid1">
|
36
|
+
<property name="visible">True</property>
|
37
|
+
<property name="can_focus">False</property>
|
38
|
+
<property name="row_spacing">4</property>
|
39
|
+
<property name="column_spacing">4</property>
|
40
|
+
<child>
|
41
|
+
<object class="GtkLabel" id="label3">
|
42
|
+
<property name="visible">True</property>
|
43
|
+
<property name="can_focus">False</property>
|
44
|
+
<property name="label" translatable="yes">Name:</property>
|
45
|
+
</object>
|
46
|
+
<packing>
|
47
|
+
<property name="left_attach">0</property>
|
48
|
+
<property name="top_attach">0</property>
|
49
|
+
<property name="width">1</property>
|
50
|
+
<property name="height">1</property>
|
51
|
+
</packing>
|
52
|
+
</child>
|
53
|
+
<child>
|
54
|
+
<object class="GtkEntry" id="txtName">
|
55
|
+
<property name="visible">True</property>
|
56
|
+
<property name="can_focus">True</property>
|
57
|
+
<property name="hexpand">True</property>
|
58
|
+
<property name="invisible_char">•</property>
|
59
|
+
</object>
|
60
|
+
<packing>
|
61
|
+
<property name="left_attach">1</property>
|
62
|
+
<property name="top_attach">0</property>
|
63
|
+
<property name="width">1</property>
|
64
|
+
<property name="height">1</property>
|
65
|
+
</packing>
|
66
|
+
</child>
|
67
|
+
</object>
|
68
|
+
<packing>
|
69
|
+
<property name="expand">False</property>
|
70
|
+
<property name="fill">True</property>
|
71
|
+
<property name="position">0</property>
|
72
|
+
</packing>
|
73
|
+
</child>
|
74
|
+
<child>
|
75
|
+
<object class="GtkButtonBox" id="buttonbox1">
|
76
|
+
<property name="visible">True</property>
|
77
|
+
<property name="can_focus">False</property>
|
78
|
+
<property name="spacing">4</property>
|
79
|
+
<property name="layout_style">end</property>
|
80
|
+
<child>
|
81
|
+
<object class="GtkButton" id="btnSave">
|
82
|
+
<property name="label">gtk-save</property>
|
83
|
+
<property name="use_action_appearance">False</property>
|
84
|
+
<property name="visible">True</property>
|
85
|
+
<property name="can_focus">True</property>
|
86
|
+
<property name="receives_default">True</property>
|
87
|
+
<property name="use_action_appearance">False</property>
|
88
|
+
<property name="use_stock">True</property>
|
89
|
+
<signal name="clicked" handler="on_btnSave_clicked" swapped="no"/>
|
90
|
+
</object>
|
91
|
+
<packing>
|
92
|
+
<property name="expand">False</property>
|
93
|
+
<property name="fill">True</property>
|
94
|
+
<property name="position">0</property>
|
95
|
+
</packing>
|
96
|
+
</child>
|
97
|
+
<child>
|
98
|
+
<object class="GtkButton" id="btnDelete">
|
99
|
+
<property name="label">gtk-delete</property>
|
100
|
+
<property name="use_action_appearance">False</property>
|
101
|
+
<property name="visible">True</property>
|
102
|
+
<property name="can_focus">True</property>
|
103
|
+
<property name="receives_default">True</property>
|
104
|
+
<property name="use_action_appearance">False</property>
|
105
|
+
<property name="use_stock">True</property>
|
106
|
+
<signal name="clicked" handler="on_btnDelete_clicked" swapped="no"/>
|
107
|
+
</object>
|
108
|
+
<packing>
|
109
|
+
<property name="expand">False</property>
|
110
|
+
<property name="fill">True</property>
|
111
|
+
<property name="position">1</property>
|
112
|
+
</packing>
|
113
|
+
</child>
|
114
|
+
</object>
|
115
|
+
<packing>
|
116
|
+
<property name="expand">False</property>
|
117
|
+
<property name="fill">True</property>
|
118
|
+
<property name="position">1</property>
|
119
|
+
</packing>
|
120
|
+
</child>
|
121
|
+
</object>
|
122
|
+
</child>
|
123
|
+
</object>
|
124
|
+
</child>
|
125
|
+
<child type="label">
|
126
|
+
<object class="GtkLabel" id="label2">
|
127
|
+
<property name="visible">True</property>
|
128
|
+
<property name="can_focus">False</property>
|
129
|
+
<property name="label" translatable="yes"><b>Enter details</b></property>
|
130
|
+
<property name="use_markup">True</property>
|
131
|
+
</object>
|
132
|
+
</child>
|
133
|
+
</object>
|
134
|
+
<packing>
|
135
|
+
<property name="expand">False</property>
|
136
|
+
<property name="fill">True</property>
|
137
|
+
<property name="position">0</property>
|
138
|
+
</packing>
|
139
|
+
</child>
|
140
|
+
<child>
|
141
|
+
<object class="GtkLabel" id="label1">
|
142
|
+
<property name="visible">True</property>
|
143
|
+
<property name="can_focus">False</property>
|
144
|
+
</object>
|
145
|
+
<packing>
|
146
|
+
<property name="expand">False</property>
|
147
|
+
<property name="fill">True</property>
|
148
|
+
<property name="position">1</property>
|
149
|
+
</packing>
|
150
|
+
</child>
|
151
|
+
</object>
|
152
|
+
</child>
|
153
|
+
</object>
|
154
|
+
</interface>
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Gtk3assist_builder" do
|
4
|
+
it "should work" do
|
5
|
+
Gtk.init
|
6
|
+
|
7
|
+
builder = Gtk::Builder.new
|
8
|
+
|
9
|
+
gui = Gtk3assist::Builder.new(:builder => builder)
|
10
|
+
gui.add_from_file("#{File.dirname(__FILE__)}/gtk3assist_builder.glade")
|
11
|
+
gui.connect_signals{|h| method(h)}
|
12
|
+
|
13
|
+
gui["window"].show_all
|
14
|
+
|
15
|
+
gui["btnSave"].clicked
|
16
|
+
gui["btnDelete"].clicked
|
17
|
+
|
18
|
+
raise "Expected save-event to be called but it wasnt." if !@save_pressed
|
19
|
+
raise "Expected delete-event to be called but it wasnt." if !@delete_pressed
|
20
|
+
gui["window"].destroy
|
21
|
+
|
22
|
+
#Gtk.main
|
23
|
+
end
|
24
|
+
|
25
|
+
def on_window_destroy
|
26
|
+
#Gtk.main_quit
|
27
|
+
end
|
28
|
+
|
29
|
+
def on_btnSave_clicked
|
30
|
+
@save_pressed = true
|
31
|
+
end
|
32
|
+
|
33
|
+
def on_btnDelete_clicked
|
34
|
+
@delete_pressed = true
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Gtk3assist_treeview" do
|
4
|
+
it "should work" do
|
5
|
+
Gtk.init
|
6
|
+
|
7
|
+
win = Gtk::Window.new(:toplevel)
|
8
|
+
GObject.signal_connect(win, "destroy") do
|
9
|
+
Gtk.main_quit
|
10
|
+
end
|
11
|
+
|
12
|
+
tv = Gtk::TreeView.new
|
13
|
+
|
14
|
+
tva = Gtk3assist::Treeview.new(:tv => tv, :cols => ["ID", "Name"], :model => :liststore)
|
15
|
+
|
16
|
+
tva.add_row(:data => {
|
17
|
+
:id => 1,
|
18
|
+
:name => "Kasper"
|
19
|
+
})
|
20
|
+
|
21
|
+
tva.add_row(:data => {
|
22
|
+
:id => 2,
|
23
|
+
:name => "Christina"
|
24
|
+
})
|
25
|
+
|
26
|
+
count = 0
|
27
|
+
tva.rows do |data|
|
28
|
+
count += 1
|
29
|
+
#puts data
|
30
|
+
end
|
31
|
+
|
32
|
+
raise "Expected count to be 2 but it wasnt: '#{count}'." if count != 2
|
33
|
+
|
34
|
+
win.resize(640, 480)
|
35
|
+
win.add(tv)
|
36
|
+
win.show_all
|
37
|
+
|
38
|
+
#Gtk.main
|
39
|
+
end
|
40
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'gtk3assist'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gtk3assist
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kasper Johansen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-09-05 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: gir_ffi-gtk
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: xml-simple
|
28
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 2.8.0
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rdoc
|
50
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "3.12"
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: bundler
|
61
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 1.0.0
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *id005
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: jeweler
|
72
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.8.4
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *id006
|
81
|
+
description: A class for making it easier to develop Gtk3 based applications with the 'gir_ffi-gtk'-gem.
|
82
|
+
email: k@spernj.org
|
83
|
+
executables: []
|
84
|
+
|
85
|
+
extensions: []
|
86
|
+
|
87
|
+
extra_rdoc_files:
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.rdoc
|
90
|
+
files:
|
91
|
+
- .document
|
92
|
+
- .rspec
|
93
|
+
- Gemfile
|
94
|
+
- Gemfile.lock
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.rdoc
|
97
|
+
- Rakefile
|
98
|
+
- VERSION
|
99
|
+
- lib/gtk3assist.rb
|
100
|
+
- lib/gtk3assist_builder.rb
|
101
|
+
- lib/gtk3assist_treeview.rb
|
102
|
+
- spec/gtk3assist_builder.glade
|
103
|
+
- spec/gtk3assist_builder_spec.rb
|
104
|
+
- spec/gtk3assist_treeview_spec.rb
|
105
|
+
- spec/spec_helper.rb
|
106
|
+
homepage: http://github.com/kaspernj/gtk3assist
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
hash: -825655960913752223
|
120
|
+
segments:
|
121
|
+
- 0
|
122
|
+
version: "0"
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: "0"
|
129
|
+
requirements: []
|
130
|
+
|
131
|
+
rubyforge_project:
|
132
|
+
rubygems_version: 1.8.24
|
133
|
+
signing_key:
|
134
|
+
specification_version: 3
|
135
|
+
summary: A class for making it easier to develop Gtk3 based applications with the 'gir_ffi-gtk'-gem.
|
136
|
+
test_files: []
|
137
|
+
|