gtk 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3eabee4039f3a4b759b2f49bd43657f0b2443433
4
+ data.tar.gz: e01310aeffcd3e7888351e0659852a89ba005546
5
+ SHA512:
6
+ metadata.gz: f157bce146eccffb647d37819e44b390acbf2e630192f8975d50bddc964b358b30dc2ca03d06474649df5b05d7f7b1618a925573864a58c05a0e4d6d26da4e03
7
+ data.tar.gz: 6c159375cf5e0ff9e508e87c93815c406cea34d525485c8c32d132caf849b1db7f5dffc3b328d002c709cbde9d68e9643565166891f70760cbafa0fd90e4f742
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+ gem 'ffi'
3
+ group :development do
4
+ gem "gtk", :path => '.'
5
+ gem "cairo", :git => 'https://github.com/patrickhno/rcairo.git'
6
+ gem "activesupport"
7
+ gem "bacon", ">= 0"
8
+ gem "rdoc", "~> 3.12"
9
+ gem "bundler", "~> 1.0"
10
+ gem "jeweler", "~> 2.0.1"
11
+ gem "simplecov", ">= 0"
12
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Patrick Hanevold
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.
@@ -0,0 +1,19 @@
1
+ = gtk
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to gtk
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) 2014 Patrick Hanevold. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,51 @@
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://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "gtk"
18
+ gem.homepage = "http://github.com/patrickhno/gtk"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{GTK FFI bindings for Ruby}
21
+ gem.description = %Q{GTK FFI bindings for Ruby}
22
+ gem.email = "patrick.hanevold@gmail.com"
23
+ gem.authors = ["Patrick Hanevold"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:spec) do |spec|
30
+ spec.libs << 'lib' << 'spec'
31
+ spec.pattern = 'spec/**/*_spec.rb'
32
+ spec.verbose = true
33
+ end
34
+
35
+ desc "Code coverage detail"
36
+ task :simplecov do
37
+ ENV['COVERAGE'] = "true"
38
+ Rake::Task['spec'].execute
39
+ end
40
+
41
+ task :default => :spec
42
+
43
+ require 'rdoc/task'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "gtk #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,141 @@
1
+ require 'gtk'
2
+ require 'cairo'
3
+
4
+ require 'active_support/core_ext/module/delegation'
5
+ require 'active_support/inflector'
6
+
7
+ NUM_COLS = 2
8
+
9
+ Gtk.init
10
+
11
+ window = Gtk::Window.new(:toplevel)
12
+ window.set_default_size(150, 100);
13
+
14
+ thread = nil
15
+ $running = true
16
+ window.signal_connect("delete_event") do
17
+ Gtk.main_quit
18
+ $running = false
19
+ end
20
+
21
+ liststore = Gtk::ListStore.new(NUM_COLS, :float, :string)
22
+ iter = Gtk::TreeIter.new
23
+ liststore.append(iter)
24
+ iter[0] = 0.5
25
+ #liststore.unref
26
+
27
+ view = Gtk::TreeView.new(liststore)
28
+
29
+ renderer = Gtk::CellRendererText.new
30
+ col = Gtk::TreeViewColumn.new
31
+ col.pack_start(renderer, true)
32
+ col.add_attribute(renderer, "text", 1)
33
+ col.set_title "Progress"
34
+ view.append_column(col)
35
+
36
+ class CustomCellRendererProgress < Gtk::CellRenderer
37
+
38
+ STEP = 0.01
39
+
40
+ def initialize *args
41
+ super
42
+ @progress = 0.5
43
+ @increasing = true
44
+ end
45
+
46
+ def get_size widget, cell_area
47
+ xpad,ypad = padding
48
+ xalign,yalign = alignment
49
+
50
+ width = xpad * 2 + 100
51
+ height = ypad * 2 + 10
52
+
53
+ x_offset = y_offset = nil
54
+ if cell_area
55
+ x_offset = xalign * (cell_area[:width] - width)
56
+ x_offset = [x_offset, 0].max
57
+ y_offset = yalign * (cell_area[:height] - height)
58
+ y_offset = [y_offset, 0].max
59
+ end
60
+
61
+ [x_offset,y_offset,width,height]
62
+ end
63
+
64
+ def self.init cell_class, object_class
65
+ # spec = Gtk::Lib.g_param_spec_double("percentage",
66
+ # "Percentage",
67
+ # "The fractional progress to display",
68
+ # 0, 1, 0,
69
+ # Gtk::G_PARAM_READWRITE)
70
+
71
+ # Gtk::Lib.g_object_class_install_property(object_class,1,spec)
72
+ end
73
+
74
+ def self.type
75
+ @type ||= Gtk::Lib.g_type_register_static(superclass.type,
76
+ name,
77
+ type_info.to_ptr,
78
+ 0)
79
+ end
80
+ def render cr, widget, background_area, cell_area, flags
81
+ context = widget.style_context
82
+
83
+ background_area[:x] -= 5
84
+
85
+ cr.save
86
+ cr.rectangle background_area[:x],background_area[:y],background_area[:width],background_area[:height]
87
+ cr.set_source_rgba 1, 0, 0, 0.80
88
+ cr.fill
89
+ cr.reset_clip
90
+
91
+ context.save
92
+ context.add_class 'cell'
93
+ Gtk.render_focus(context,cr,background_area[:x],background_area[:y],background_area[:width] * @progress,background_area[:height])
94
+
95
+ state = get_state(widget, flags)
96
+ context.state = state
97
+
98
+ context.restore
99
+ cr.restore
100
+ end
101
+ def step liststore
102
+ iter = liststore.to_tree_model.iter_first
103
+ perc = iter[0]
104
+
105
+ if perc > (1.0-STEP) || (perc < STEP && perc > 0.0)
106
+ @increasing = !@increasing
107
+ end
108
+
109
+ if @increasing
110
+ perc = perc + STEP
111
+ else
112
+ perc = perc - STEP
113
+ end
114
+
115
+ @progress = perc
116
+
117
+ iter.owner = liststore
118
+ iter[0] = perc
119
+ iter[1] = "#{(perc*100).floor} %"
120
+ end
121
+ end
122
+ renderer = CustomCellRendererProgress.new(Gtk::Lib.g_object_new(CustomCellRendererProgress.type,nil))
123
+
124
+ col = Gtk::TreeViewColumn.new
125
+ col.pack_start(renderer, true)
126
+ # col.add_attribute(renderer, "percentage", 0)
127
+ col.set_title "Progress bar"
128
+ view.append_column(col)
129
+
130
+ window.add(view)
131
+
132
+ Gtk.widget_show_all(window)
133
+
134
+ # Gtk.main
135
+ while $running do
136
+ while $running && Gtk.events_pending
137
+ Gtk.main_iteration if $running
138
+ end
139
+ sleep 0.005
140
+ renderer.step(liststore)
141
+ end
@@ -0,0 +1,97 @@
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
+ # stub: gtk 0.1.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "gtk"
9
+ s.version = "0.1.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["Patrick Hanevold"]
14
+ s.date = "2014-06-10"
15
+ s.description = "GTK FFI bindings for Ruby"
16
+ s.email = "patrick.hanevold@gmail.com"
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ "Gemfile",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "examples/custom_cell_renderer.rb",
29
+ "gtk.gemspec",
30
+ "lib/gtk.rb",
31
+ "lib/gtk/bin.rb",
32
+ "lib/gtk/buttons_type.rb",
33
+ "lib/gtk/cell_renderer.rb",
34
+ "lib/gtk/cell_renderer_text.rb",
35
+ "lib/gtk/container.rb",
36
+ "lib/gtk/dialog_flags.rb",
37
+ "lib/gtk/g_type.rb",
38
+ "lib/gtk/list_store.rb",
39
+ "lib/gtk/message_dialog.rb",
40
+ "lib/gtk/message_type.rb",
41
+ "lib/gtk/selection_mode.rb",
42
+ "lib/gtk/style_context.rb",
43
+ "lib/gtk/tree_iter.rb",
44
+ "lib/gtk/tree_model.rb",
45
+ "lib/gtk/tree_path.rb",
46
+ "lib/gtk/tree_selection.rb",
47
+ "lib/gtk/tree_store.rb",
48
+ "lib/gtk/tree_view.rb",
49
+ "lib/gtk/tree_view_column.rb",
50
+ "lib/gtk/window.rb",
51
+ "lib/gtk/window_position.rb",
52
+ "lib/gtk/window_type.rb",
53
+ "spec/gtk_spec.rb",
54
+ "spec/spec_helper.rb"
55
+ ]
56
+ s.homepage = "http://github.com/patrickhno/gtk"
57
+ s.licenses = ["MIT"]
58
+ s.rubygems_version = "2.2.0"
59
+ s.summary = "GTK FFI bindings for Ruby"
60
+
61
+ if s.respond_to? :specification_version then
62
+ s.specification_version = 4
63
+
64
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
65
+ s.add_runtime_dependency(%q<ffi>, [">= 0"])
66
+ s.add_development_dependency(%q<gtk>, [">= 0"])
67
+ s.add_development_dependency(%q<cairo>, [">= 0"])
68
+ s.add_development_dependency(%q<activesupport>, [">= 0"])
69
+ s.add_development_dependency(%q<bacon>, [">= 0"])
70
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
71
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
72
+ s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
73
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
74
+ else
75
+ s.add_dependency(%q<ffi>, [">= 0"])
76
+ s.add_dependency(%q<gtk>, [">= 0"])
77
+ s.add_dependency(%q<cairo>, [">= 0"])
78
+ s.add_dependency(%q<activesupport>, [">= 0"])
79
+ s.add_dependency(%q<bacon>, [">= 0"])
80
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
81
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
82
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
83
+ s.add_dependency(%q<simplecov>, [">= 0"])
84
+ end
85
+ else
86
+ s.add_dependency(%q<ffi>, [">= 0"])
87
+ s.add_dependency(%q<gtk>, [">= 0"])
88
+ s.add_dependency(%q<cairo>, [">= 0"])
89
+ s.add_dependency(%q<activesupport>, [">= 0"])
90
+ s.add_dependency(%q<bacon>, [">= 0"])
91
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
92
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
93
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
94
+ s.add_dependency(%q<simplecov>, [">= 0"])
95
+ end
96
+ end
97
+
@@ -0,0 +1,203 @@
1
+ require 'ffi'
2
+
3
+ module Gtk
4
+ class Enums
5
+ def self.[] symbol
6
+ const_get(symbol.to_s.upcase.to_sym)
7
+ end
8
+ end
9
+ end
10
+
11
+ module Gtk
12
+ G_PARAM_READABLE = 1
13
+ G_PARAM_WRITABLE = 2
14
+ G_PARAM_READWRITE = G_PARAM_READABLE | G_PARAM_WRITABLE
15
+ module Lib
16
+ extend FFI::Library
17
+ ffi_lib 'gtk-3'
18
+
19
+ def self.attached_methods
20
+ @attached_methods ||= {}
21
+ end
22
+
23
+ def self.attach_method method, args, ret
24
+ attached_methods[method] = { :name => method, :args => args, :ret => ret }
25
+ attach_function method,args.map{ |arg| arg.respond_to?(:superclass) && arg.superclass == Enums ? :long : arg },ret
26
+ end
27
+
28
+ attach_method :gtk_init, [:pointer, :pointer], :void
29
+ attach_method :gtk_main, [], :void
30
+ attach_method :gtk_main_quit, [], :void
31
+ attach_method :gtk_events_pending, [], :bool
32
+ attach_method :gtk_main_iteration, [], :bool
33
+ attach_method :gtk_render_focus, [:pointer, :pointer, :double, :double, :double, :double], :void
34
+ end
35
+
36
+ def self.init
37
+ Lib.gtk_init(nil,nil)
38
+ end
39
+
40
+ def self.method_missing method,*args
41
+ name = "gtk_#{method}".to_sym
42
+ m = Lib.attached_methods[name]
43
+ raise ArgumentError.new unless m[:args].size == args.size
44
+
45
+ args = args.map do |v|
46
+ case v
47
+ when GObject
48
+ v.native
49
+ when Cairo::Context
50
+ v.to_ptr
51
+ when Fixnum, Float
52
+ v
53
+ else
54
+ raise v.inspect
55
+ end
56
+ end
57
+
58
+ Lib.send(name,*args)
59
+ end
60
+ end
61
+
62
+ module Glib
63
+ extend FFI::Library
64
+ ffi_lib 'glib-2.0'
65
+ end
66
+
67
+ module GObject
68
+ extend FFI::Library
69
+ ffi_lib 'gobject-2.0'
70
+ end
71
+
72
+ module Gtk
73
+ module Lib
74
+ class GTypeInstance < FFI::Struct
75
+ end
76
+
77
+ attach_function :g_signal_connect_data, [:pointer, :string, :pointer, :pointer, :pointer, :long], :ulong
78
+ attach_function :g_param_spec_double, [:string, :string, :string, :double, :double, :double, :int], :pointer
79
+ attach_function :g_type_register_static, [:ulong, :string, :pointer, :int], :ulong
80
+
81
+ attach_function :g_object_class_install_property, [:pointer, :uint, :pointer], :void
82
+ attach_function :g_object_new, [:ulong, :string, :varargs], :pointer
83
+ attach_function :g_object_unref, [:pointer], :void
84
+
85
+ class GTypeInfo < FFI::Struct
86
+ layout :class_size, :uint,
87
+ :base_init, :pointer,
88
+ :base_finalize, :pointer,
89
+ :class_init, :pointer,
90
+ :class_finalize, :pointer,
91
+ :class_data, :pointer,
92
+ :instance_size, :uint,
93
+ :n_preallocs, :uint,
94
+ :instance_init, :pointer
95
+ end
96
+ end
97
+
98
+ class GObject
99
+ attr_accessor :native,:type
100
+
101
+ def initialize *args
102
+ raise "hell" unless args.size == 1 && args.first.is_a?(FFI::Pointer)
103
+ @native = args.first
104
+ end
105
+
106
+ def self.type_register
107
+ type_name = name.gsub(/::/,'__')
108
+ cell_progress_info = Lib::GTypeInfo.new
109
+ @type = Lib.g_type_register_static(
110
+ superclass.type,
111
+ type_name,
112
+ cell_progress_info.ref,
113
+ 0
114
+ )
115
+ end
116
+
117
+ def signal_connect(name,&block)
118
+ callback = FFI::Function.new(:void, [:pointer]) do |data|
119
+ block.call
120
+ end
121
+ Lib.g_signal_connect_data(native,name,callback,nil,nil,0)
122
+ end
123
+
124
+ def unref
125
+ Lib.g_object_unref(native)
126
+ end
127
+
128
+ def method_missing method,*args
129
+ method = "set_#{method.to_s[0..-2]}".to_sym if method.to_s[-1] == '='
130
+
131
+ getter = "get_#{method}".to_sym
132
+ klass = self.class
133
+ while klass
134
+ raise "hell #{method} #{self.inspect}" if klass == Object
135
+ return send(getter,*args) if respond_to?(getter)
136
+
137
+ name = "gtk_#{klass.name.split('::').last.underscore}_#{method}".to_sym
138
+ getter_name = "gtk_#{klass.name.split('::').last.underscore}_#{getter}".to_sym
139
+ if m = (Lib.attached_methods[name] || Lib.attached_methods[getter_name])
140
+ raise "#{self.class.name}: #{method}" unless m
141
+ if m[:args].last == :varargs
142
+ raise ArgumentError.new unless m[:args].size <= (args.size+1)
143
+ else
144
+ raise ArgumentError.new unless m[:args].size == (args.size+1)
145
+ end
146
+
147
+ types = m[:args][1..-1]
148
+ args = args.map do |arg|
149
+ type = types.shift
150
+ if arg.is_a?(GObject)
151
+ arg.native
152
+ elsif arg.is_a?(Symbol) && type.respond_to?(:superclass) && type.superclass == Enums
153
+ type[arg]
154
+ else
155
+ arg
156
+ end
157
+ end
158
+
159
+ return Lib.send(m[:name],@native,*args)
160
+ end
161
+ klass = klass.superclass
162
+ end
163
+ end
164
+ end
165
+ end
166
+
167
+ module Gtk
168
+ module Lib
169
+ attach_method :gtk_widget_show_all, [:pointer], :void
170
+ attach_method :gtk_widget_destroy, [:pointer], :void
171
+ attach_method :gtk_widget_get_style_context, [:pointer], :pointer
172
+ end
173
+
174
+ class Widget < GObject
175
+ def get_style_context
176
+ Gtk::StyleContext.new(Lib.gtk_widget_get_style_context(native))
177
+ end
178
+ end
179
+ end
180
+
181
+ require 'gtk/dialog_flags'
182
+ require 'gtk/message_type'
183
+ require 'gtk/buttons_type'
184
+ require 'gtk/g_type'
185
+ require 'gtk/window_type'
186
+ require 'gtk/window_position'
187
+ require 'gtk/tree_iter'
188
+ require 'gtk/selection_mode'
189
+
190
+ require 'gtk/container'
191
+ require 'gtk/bin'
192
+ require 'gtk/cell_renderer'
193
+ require 'gtk/cell_renderer_text'
194
+ require 'gtk/list_store'
195
+ require 'gtk/message_dialog'
196
+ require 'gtk/style_context'
197
+ require 'gtk/tree_model'
198
+ require 'gtk/tree_path'
199
+ require 'gtk/tree_selection'
200
+ require 'gtk/tree_store'
201
+ require 'gtk/tree_view'
202
+ require 'gtk/tree_view_column'
203
+ require 'gtk/window'