-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathReadStyle.py
More file actions
52 lines (46 loc) · 1.71 KB
/
Copy pathReadStyle.py
File metadata and controls
52 lines (46 loc) · 1.71 KB
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
#!/usr/bin/env python
# Written by: DGC
from xml.dom.minidom import parseString
#==============================================================================
def read_style(style):
"""
Reads style information in from an xml document in the same directory
called style.xml
"""
# open the file, convert it to a string then close it
style_file = open("style.xml","r")
data = style_file.read()
style_file.close()
#parse the xml
dom = parseString(data)
style_codes = []
style_node = get_style_node(style, dom)
if (not style_node):
return style_codes
for widget in style_node.childNodes:
for tag in widget.childNodes:
# if it is an attribute node
if (tag.nodeType == 1):
style_codes.append(
[widget.nodeName, tag.nodeName,tag.firstChild.data]
)
return style_codes
#==============================================================================
def get_style_node(style, data):
"""Returns the <Style> node with Name == style"""
styles = data.getElementsByTagName("Style")
for node in styles:
for i in range(0, node.attributes.length):
if (node.attributes.item(i).name == "Name"):
if (node.attributes.item(i).value == style):
return node
return []
#==============================================================================
if (__name__ == "__main__"):
#
# History
# When What
# -------- ----------------------------------------------------------------
# 15/06/12 Written.
#--------------------------------------------------------------------------
print(read_style("DGC"))