Class: TkXML
- Inherits:
-
Object
show all
- Defined in:
- lib/tkxml.rb,
lib/tkxml/rexml.rb,
lib/tkxml/nokogiri.rb
Overview
A combination of Ruby, Tcl/Tk and Nokogiri or REXML to allow for fast and easy creation of Tk interfaces using standard XML.
xml = File.open("ui.xml")
tkxml_instance = TkXML.new(xml)
tkxml_instance.build
Defined Under Namespace
Classes: Nokogiri_Listener, REXML_Listener
Constant Summary
collapse
- VERSION =
Current version of TkXML.
'0.3.1'
Instance Method Summary
collapse
Constructor Details
#initialize(source, type = :nokogiri) ⇒ TkXML
Returns a new instance of TkXML.
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/tkxml.rb', line 16
def initialize(source, type=:nokogiri)
@widget = {}
@widget_stack = []
@parent = nil
case type
when :nokogiri
require 'tkxml/nokogiri'
else
require 'tkxml/rexml'
end
parse(source)
end
|
Instance Method Details
#build ⇒ Object
32
33
34
|
# File 'lib/tkxml.rb', line 32
def build
Tk.mainloop
end
|
#end_method(name) ⇒ Object
129
130
131
|
# File 'lib/tkxml.rb', line 129
def end_method(name)
puts "End Method: #{name}"
end
|
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/tkxml.rb', line 71
def end_widget(name)
@parent = @widget_stack[-2]
current = @widget_stack.last
case name.downcase
when "menu"
@parent.(current)
end
@widget_stack.pop
puts "End Widget: #{name}"
end
|
#parse(source) ⇒ Object
6
7
8
9
|
# File 'lib/tkxml/rexml.rb', line 6
def parse(source)
listener = REXML_Listener.new(self)
REXML::Document.parse_stream(source, listener)
end
|
#start ⇒ Object
36
37
38
39
|
# File 'lib/tkxml.rb', line 36
def start
@parent = @widget_stack.last
end
|
#start_method(name, attrs) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/tkxml.rb', line 87
def start_method(name, attrs)
puts "Applying Method: #{name} to #{@parent}"
attrs = assoc_to_hash(attrs)
p_arr = [] p_init = {} p_hash = {}
attrs.each do |n, v|
puts " #{n} => #{v}"
if n[0..0] == "_"
p_init[n] = v
else
p_hash[n] = v
end
end
if not p_init.empty?
p_init.sort
p_init.each do |a|
p_arr.push a[1]
end
end
if not p_hash.empty?
p_arr.push p_hash
end
@parent.send(name, *p_arr)
end
|
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/tkxml.rb', line 42
def start_widget(name, attrs)
puts "Creating Widget: #{name} of #{@parent}"
attrs = assoc_to_hash(attrs)
widget_class = "Tk" + name.capitalize
widget_name = attrs['name']
if @parent == nil
@widget[widget_name] = Tk.const_get(widget_class).new
else
@widget[widget_name] = Tk.const_get(widget_class).new(@parent)
end
attrs.each do |n, v|
if not n == 'name'
puts " #{n} => #{v}"
@widget[widget_name].send(n, v)
end
end
@widget_stack.push(@widget[widget_name])
end
|