-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetFile.py
More file actions
185 lines (134 loc) · 5.93 KB
/
Copy pathgetFile.py
File metadata and controls
185 lines (134 loc) · 5.93 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
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
import copy
from tkinter import *
from tkinter import filedialog
import tkinter.messagebox
import tkinter.colorchooser
import xml.etree.ElementTree as ET
import random
import time
import os,sys
import tumbletiles as TT
def getFile():
return filedialog.askopenfilename()
#parse file will get the data from a file and now return both a board object and a preview tile object
def parseFile(filename):
tree = ET.parse(filename)
treeroot = tree.getroot()
#self.Log("\nLoad "+filename+"\n")
#default size of board, changes if new board size data is read from the file
rows = 15
columns = 15
boardSizeExits = False
glueFuncExists = False
previewTilesExist = False
tileDataExists = False
CommandsExists = False
#check if the xml attributes are found
if tree.find("GlueFunction") != None:
glueFuncExists = True
if tree.find("PreviewTiles") != None:
previewTilesExist = True
if tree.find("BoardSize") != None:
boardSizeExists = True
if tree.find("TileData") != None:
tileDataExists = True
if tree.find("Commands") != None:
CommandsExists = True
#data set that will be passed back to tumblegui
tile_set_data = {"glueFunc": {}, "prevTiles": [], "tileData": []}
if boardSizeExists:
rows = treeroot[0].attrib["height"]
columns = treeroot[0].attrib["width"]
#add glue function to the data set
if glueFuncExists:
glueFuncTree = treeroot[1]
for fun in glueFuncTree:
tile_set_data["glueFunc"][fun.find('Labels').attrib['L1']] = (fun.find('Strength').text)
#add preview tiles to the data set
if previewTilesExist:
prevTilesTree = treeroot[2];
for prev in prevTilesTree:
newPrevTile = {}
newPrevTile["color"] = "#555555"
newPrevTile["northGlue"] = " "
newPrevTile["southGlue"] = " "
newPrevTile["westGlue"] = " "
newPrevTile["eastGlue"] = " "
newPrevTile["label"] = "X"
newPrevTile["concrete"] = " "
if prev.find('Color') != None:
if prev.find('Concrete').text == "True":
newPrevTile["color"] = "#686868"
else:
newPrevTile["color"] = "#" + prev.find('Color').text
if prev.find('NorthGlue') != None:
newPrevTile["northGlue"] = prev.find('NorthGlue').text
if prev.find('EastGlue') != None:
newPrevTile["eastGlue"] = prev.find('EastGlue').text
if prev.find('SouthGlue') != None:
newPrevTile["southGlue"] = prev.find('SouthGlue').text
if prev.find('WestGlue') != None:
newPrevTile["westGlue"] = prev.find('WestGlue').text
if prev.find('label') != None:
newPrevTile["label"] = prev.find('label').text
if prev.find('Concrete') != None:
newPrevTile["concrete"] = prev.find('Concrete').text
tile_set_data["prevTiles"].append(newPrevTile)
#add tile data to the data set, these are the tiles that will actually be loaded onto the plane
if tileDataExists:
tileDataTree = treeroot[3]
for tile in tileDataTree:
newTile = {}
newTile["location"] = {'x': 0, 'y': 0}
newTile["color"] = "#555555"
newTile["northGlue"] = " "
newTile["southGlue"] = " "
newTile["westGlue"] = " "
newTile["eastGlue"] = " "
newTile["label"] = "X"
newTile["concrete"] = " "
if tile.find('Location') != None:
newTile["location"]["x"] = int(tile.find('Location').attrib['x'])
newTile["location"]["y"] = int(tile.find('Location').attrib['y'])
if tile.find('Color') != None:
if tile.find('Concrete').text == "True":
newTile["color"] = "#686868"
else:
newTile["color"] = "#" + tile.find('Color').text
if tile.find('NorthGlue') != None:
newTile["northGlue"] = tile.find('NorthGlue').text
if tile.find('EastGlue') != None:
newTile["eastGlue"] = tile.find('EastGlue').text
if tile.find('SouthGlue') != None:
newTile["southGlue"] = tile.find('SouthGlue').text
if tile.find('WestGlue') != None:
newTile["westGlue"] = tile.find('WestGlue').text
if tile.find('label') != None:
newTile["label"] = tile.find('label').text
if tile.find('Concrete') != None:
newTile["concrete"] = tile.find('Concrete').text
tile_set_data["tileData"].append(newTile)
board = TT.Board(int(rows), int(columns))
glueFunc = tile_set_data["glueFunc"]
prevTiles = tile_set_data["prevTiles"]
prevTileList = []
for tile in tile_set_data["tileData"]:
if tile["concrete"] != "True":
glues = [tile["northGlue"],tile["eastGlue"],tile["southGlue"],tile["westGlue"]]
board.Add(TT.Polyomino(0, tile["location"]["x"], tile["location"]["y"], glues, tile["color"]))
else:
glues = []
board.AddConc(TT.Tile(None, 0, tile["location"]["x"], tile["location"]["y"], glues, tile["color"], "True"))
for prevTile in prevTiles:
prevGlues = [prevTile["northGlue"],prevTile["eastGlue"],prevTile["southGlue"],prevTile["westGlue"]]
prevTileList.append(TT.Tile( None, 0, 0, 0, prevGlues, prevTile["color"], prevTile["concrete"]))
commands = []
if CommandsExists:
listOfCommands = treeroot[4]
print (listOfCommands)
for c in listOfCommands:
print (c)
print ("NAME: ",c.attrib["name"]," FILENAME: ",c.attrib["filename"])
commands.append((c.attrib["name"], c.attrib["filename"]))
data = [board, glueFunc, prevTileList, commands]
return data