btk 0.1.0

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.
Files changed (2) hide show
  1. data/lib/btk.rb +77 -0
  2. metadata +55 -0
@@ -0,0 +1,77 @@
1
+ require 'gtk2'
2
+
3
+ module Btk
4
+ def self.parse_params(name,argv)
5
+ (0..Array(argv).size-1).collect{|idx| "#{name}[#{idx}]"}.join(',')
6
+ end
7
+
8
+ def self.get_options(argv)
9
+ options={}
10
+ if argv.last.is_a? Hash
11
+ options=argv.pop
12
+ end
13
+ options
14
+ end
15
+
16
+ def self.method_missing(name,*argv,&block)
17
+ real_name=nil
18
+ [Gtk,Object].each{|t|
19
+ if t.const_defined?(name.to_sym)
20
+ real_name="#{t.name}::#{name}"
21
+ end
22
+ }
23
+ raise "undefined class #{name}" unless real_name
24
+ name=real_name
25
+ options=get_options(argv)
26
+
27
+ #create object
28
+ ob=eval("#{name}.new(#{parse_params(:argv,argv)})")
29
+
30
+ #parse options
31
+ options.each{|key,value|
32
+ #ignore :pack
33
+ next if key==:pack
34
+ ob_method=nil
35
+
36
+ #two methods supported
37
+ methods=["#{key}=".to_s,"set_#{key}".to_s]
38
+ methods.each{|method|
39
+ if ob.respond_to?(method)
40
+ ob_method=method
41
+ break
42
+ end
43
+ }
44
+ ob_method or raise "cannot find method in #{methods.join(',')}"
45
+ value=Array(value)
46
+ eval("ob.send(ob_method,#{parse_params(:value,value)})")
47
+ }
48
+ if block_given?
49
+ yield(ob)
50
+ end
51
+ ob
52
+ end
53
+
54
+ def method_missing(name,*argv,&block)
55
+ if name.to_s =~ /^sig_(.*)$/
56
+ return self.signal_connect($1,&block)
57
+ else
58
+ ob=eval("Btk.#{name}(*argv,&block)")
59
+ if self.respond_to? 'pack_start'
60
+ opts=Array(Btk.get_options(argv)[:pack])
61
+ default_opts=[true,true,0]
62
+ opts.each_index{|idx|
63
+ default_opts[idx]=opts[idx] unless opts[idx].nil?
64
+ }
65
+ opts=default_opts
66
+ self.pack_start(ob,opts[0],opts[1],opts[2])
67
+ elsif self.respond_to? 'add'
68
+ self.add(ob)
69
+ end
70
+ return ob
71
+ end
72
+ end
73
+ end
74
+
75
+ class Gtk::Widget
76
+ include Btk
77
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: btk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Miao Jiang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-24 00:00:00 +08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: simple and quick package for ruby-gtk2
17
+ email: jiangfriend@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/btk.rb
26
+ has_rdoc: true
27
+ homepage: http://btk.rubyforge.org
28
+ licenses: []
29
+
30
+ post_install_message:
31
+ rdoc_options: []
32
+
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: "0"
40
+ version:
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ requirements: []
48
+
49
+ rubyforge_project: btk
50
+ rubygems_version: 1.3.5
51
+ signing_key:
52
+ specification_version: 3
53
+ summary: simple and quick package for ruby-gtk2
54
+ test_files: []
55
+