gtkbuilder 0.1

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.
data/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ Copyright (c) 2012 Fabian Streitel
2
+
3
+ This program is free software: you can redistribute it and/or modify
4
+ it under the terms of the GNU General Public License as published by
5
+ the Free Software Foundation, either version 3 of the License, or
6
+ (at your option) any later version.
7
+
8
+ This program is distributed in the hope that it will be useful,
9
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ GNU General Public License for more details.
12
+
13
+ You should have received a copy of the GNU General Public License
14
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
15
+
@@ -0,0 +1,22 @@
1
+ # Builder::Gtk
2
+
3
+ A simple DSL for creating Gtk windows.
4
+
5
+ ## Example
6
+
7
+ require 'gtkbuilder'
8
+
9
+ Gtk.init
10
+ window = Builder::Gtk.new do |w|
11
+ w.vbox(true, 0) do |v|
12
+ v.start(true, true, 1) do
13
+ v.text_view do |t|
14
+ t.set_size_request(200, 200)
15
+ end
16
+ v.entry
17
+ end
18
+ end
19
+ end
20
+ window.show_all
21
+ Gtk.main
22
+
@@ -0,0 +1,17 @@
1
+ module Builder
2
+
3
+ module Gtk
4
+
5
+ def self.new(*args, &block)
6
+ proxy = Builder::Gtk::WindowProxy.new(*args)
7
+ block.call(proxy) if block
8
+ return proxy.widget
9
+ end
10
+
11
+ end
12
+
13
+ end
14
+
15
+ require 'proxies/window.rb'
16
+ require 'proxies/box.rb'
17
+
@@ -0,0 +1,43 @@
1
+ require 'proxies/layout.rb'
2
+
3
+ module Builder::Gtk
4
+
5
+ class BoxProxy
6
+
7
+ include LayoutProxy
8
+
9
+ def initialize(widget)
10
+ @widget = widget
11
+ @data = {
12
+ :position => :start,
13
+ :args => [false, false, 0],
14
+ }
15
+ end
16
+
17
+ def start(*args, &block)
18
+ return _pack(:start, args, block)
19
+ end
20
+
21
+ def end(*args, &block)
22
+ return _pack(:end, args, block)
23
+ end
24
+
25
+ private
26
+
27
+ def _pack(position, args, block)
28
+ @data = {
29
+ :position => position,
30
+ :args => args,
31
+ }
32
+ block.call(self) if block
33
+ return self
34
+ end
35
+
36
+ def _pack_widget(widget)
37
+ @widget.send("pack_#{@data[:position]}", widget, *@data[:args])
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+
@@ -0,0 +1,49 @@
1
+ require 'gtk2'
2
+
3
+ module Builder::Gtk
4
+
5
+ module LayoutProxy
6
+
7
+ attr_accessor :widget
8
+
9
+ def method_missing(name, *args, &block)
10
+ widget = _get_widget(name, args, &block)
11
+ proxy = _get_proxy(name, widget) || widget
12
+ block.call(proxy) if block
13
+ _pack_widget(widget)
14
+ return self
15
+ end
16
+
17
+ private
18
+
19
+ def _get_widget(name, args, &block)
20
+ class_name = _find_gtk_class(name)
21
+ raise RuntimeError.new("no widget found for name #{name}") unless class_name
22
+ klass = ::Gtk.const_get(class_name)
23
+ return klass.new(*args, &block)
24
+ end
25
+
26
+ def _find_gtk_class(name)
27
+ name = name.to_s.gsub("_", "").downcase
28
+ return ::Gtk.constants.find do |constant|
29
+ constant.to_s.downcase == name
30
+ end
31
+ end
32
+
33
+ def _get_proxy(name, widget)
34
+ case name.to_s
35
+ when "winodw" then return WindowvboxProxy.new(widget)
36
+ when "vbox" then return BoxProxy.new(widget)
37
+ when "hbox" then return BoxProxy.new(widget)
38
+ else return nil
39
+ end
40
+ end
41
+
42
+ def _pack_widget(widget)
43
+ raise RuntimeError.new("cannot pack inside this widget")
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+
@@ -0,0 +1,22 @@
1
+ require 'proxies/layout.rb'
2
+
3
+ module Builder::Gtk
4
+
5
+ class WindowProxy
6
+
7
+ include LayoutProxy
8
+
9
+ def initialize(*args)
10
+ @widget = ::Gtk::Window.new(*args)
11
+ end
12
+
13
+ private
14
+
15
+ def _pack_widget(widget)
16
+ @widget.add(widget)
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gtkbuilder
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Fabian Streitel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-20 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Builder::Gtk provides a DSL for generating Gtk2 windows.
15
+ email:
16
+ - github@rottenrei.be
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/proxies/box.rb
22
+ - lib/proxies/window.rb
23
+ - lib/proxies/layout.rb
24
+ - lib/gtkbuilder.rb
25
+ - LICENSE
26
+ - README.mkd
27
+ homepage: http://github.com/karottenreibe/ruby-gtkbuilder
28
+ licenses: []
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: 1.3.6
45
+ requirements: []
46
+ rubyforge_project:
47
+ rubygems_version: 1.8.11
48
+ signing_key:
49
+ specification_version: 3
50
+ summary: Easy creation of Gtk windows
51
+ test_files: []