File: embed-python.e

package info (click to toggle)
entity 0.7.2-6
  • links: PTS
  • area: main
  • in suites: woody
  • size: 5,352 kB
  • ctags: 5,272
  • sloc: ansic: 61,707; sh: 7,921; makefile: 732; perl: 399
file content (204 lines) | stat: -rwxr-xr-x 4,878 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/usr/bin/env entity
<!-- #!/usr/local/bin/entity -->

<object default-lang="python">
  <window ondelete="entity:quit">
    <button name="enode_test"
	    label="Basic ENode Object Test"
	    onclick="enode_test"/>
    <button name="newchild_test"
	    label="Create New Child Test"
	    onclick="newchild_test"/>
    <button name="call_test"
	    label="Call function test"
	    onclick="call_test"/>
    <button name="search_test" 
	    label="Node Search functions Test" 
	    onclick="search_funcs"/>
    <button name="xml_test"
            label="XML function test"
	    onclick="xml_test"/>
  </window>

<?python
import sys, traceback, pprint
def enode_test(node, myval=[0]):
	print "\n\n\n**************************************"

	try:
		print "    I was passed this node:"
		print node
	except:
		print "BUG - this should not trigger an exception."
		type, val, tb =  sys.exc_info()
		traceback.print_exception(type, val, tb)
		
	try:
		foo = enode(53, "meow")
		print "BUG - this line should be skipped."
	except:
		print "GOOD - this should print"
		type, val, tb =  sys.exc_info()
		traceback.print_exception(type, val, tb)

	try:
		foo = enode(53)
		print "BUG - this should be skipped."
	except:
		print "GOOD - this should print"
		type, val, tb =  sys.exc_info()
		traceback.print_exception(type, val, tb)



	
	try:
		label = enode("button.enode_test")
		label.attrib({"label": "Attribute Test (%d)" % myval[0]})
		myval[0] = myval[0] + 1
		print "GOOD All went OK, as far as i can tell."
	except:
		print "BUG something borked in the attribute set/get test."


	try:
		bork = enode("fake.node")
		print "BUG - the previous line should have trapped to an exception."
	except:
		print "GOOD - expected exception was raised."
		type, val, tb =  sys.exc_info()
		traceback.print_exception(type, val, tb)


	try:
		print "    value of this node's 'label' attribute:"
		print  node["label"]
		print "   prefixing that with 'foo':"
		node["label"] = "foo"+node["label"]
		print node["label"]
		print "GOOD - all went OK, as fas as i can tell."
		print "* insure that the buttons title is now: 'fooAttribute Test (%d)'" % myval[0]
	except:
		print "BUG - Got exception while fooling with indexing:"
		type, val, tb =  sys.exc_info()
		traceback.print_exception(type, val, tb)


	print "next line should be an empty string:"	
	print node["this-is-fake"]
	

	try:
		print "type:"
		print node.type()
		print "path:"
		print node.path()
		print "basename:"
		print node.basename()	
		print "description:"
		print node.description()
		print "GOOD - all went ok, as far as i can tell."
		print "* insure that the values above are reasonable."
	except:
		print "BUG - Got exception while doing basic functions:"
		type, val, tb =  sys.exc_info()
		traceback.print_exception(type, val, tb)


	try:
		othernode = enode("button.search_test")
		if (node == othernode):
			print "BUG They compare the same"
		else:
			print "GOOD They compare differently"
	except:
		print "BUG: Somehow, an exception occurred while testing a failing compare."
		type, val, tb =  sys.exc_info()
		traceback.print_exception(type, val, tb)

	try:
		othernode = enode("button.enode_test")
		if (node == othernode):
			print "GOOD They compare the same"
		else:
			print "BUG They compare differently"
	except:
		print "Somehow, an exception occurred while testing a passing match."
		type, val, tb =  sys.exc_info()
		traceback.print_exception(type, val, tb)


def newchild_test(node):
	print "\n***** I will now add a new button to this windows:"
	parent = node.parent()
	parent.new_child("button.foo", {"label":"Test"})
	
	


def search_funcs(node):
	print "\n******** tree functions testing !"

	print "this node is:"
	print node
	print

	print "this node's parent is:"
	print node.parent()
	print

	print "(from now on, we'll use that node to work from.)"
	node = node.parent()
	print node
	print

	print "node's children:"
	print node.children()
	print

	print "regexp'd child finder with exp '.*se.*'"
	print node.children_rx(".*se.*")
	print

	print "result of enode.child('button'):"
	print node.child('button')
	print "result of enode.child('button.search_test'):"
	print node.child('button.search_test')
	print

	print "result of enode.child_rx('.*se.*')"
	print node.child_rx('.*se.*')
	print

	
def xml_test(node):
	print "\n\n--**-- XML of this object:"
	node = node.parent("object")
	print node.get_xml()
	

	print "\n\n--**-- : appending this:"
	object = '<label text="This is appended!"/>'
	print object
	print "-- to xml.."

	node.append_xml(object)

	print "\n\n--**-- XML of this object:"
	print node.get_xml()

def call_test_target(node, str):
	print "*** CALL_TEST_TARGET:"
	print "args are:"
	#pprint.pprint(args)
	print "args are node", node, "string ", str

def call_test(node):
	try:
		node.call("call_test_target","s","test")
	except:
		print "call failed."

?>

</object>