Skip to content

Commit

Permalink
Merge pull request #25 from garyservin/fix-configuring-parameters-ui
Browse files Browse the repository at this point in the history
Fixes issue with --configure argument for UI.py
  • Loading branch information
josauder committed Oct 30, 2016
2 parents e20f52d + a7e68ca commit e53d9a4
Showing 1 changed file with 31 additions and 24 deletions.
55 changes: 31 additions & 24 deletions UI.py
@@ -1,13 +1,15 @@
import sys, os
import os
import sys
import procedural_city_generation
donemessage="\n"+(150*"-")+"\n\t\t\t Done, waiting for command\n"+(150*"-")+"\n"
path=os.path.dirname(procedural_city_generation.__file__)
donemessage = "\n"+(150*"-")+"\n\t\t\t Done, waiting for command\n"+(150*"-")+"\n"
path = os.path.dirname(procedural_city_generation.__file__)
sys.path.append(path)
if not os.path.exists(path+"/temp/"):
os.system("mkdir "+path+"/temp")
if not os.path.exists(path+"/outputs/"):
os.system("mkdir "+path+"/outputs")


def setup_matplotlib():
"""
This function is used to set the matplotlib backend correctly.
Expand All @@ -21,7 +23,7 @@ def setup_matplotlib():
:return:
"""
if sys.version[0]=="3":
if sys.version[0] == "3":
import matplotlib
try:
matplotlib.use("Qt4Agg")
Expand All @@ -36,16 +38,19 @@ def setup_matplotlib():
from procedural_city_generation.building_generation import main as building_generation_main
from procedural_city_generation.additional_stuff.Singleton import Singleton


def setRoadmapGUI(gui):
roadmap_main.gui=gui
roadmap_main.gui = gui
Singleton("roadmap").kill()


def setPolygonsGUI(gui):
polygons_main.gui=gui
polygons_main.gui = gui
Singleton("polygons").kill()


def setBuilding_generationGUI(gui):
building_generation_main.gui=gui
building_generation_main.gui = gui
Singleton("building_generation").kill()


Expand All @@ -54,11 +59,13 @@ def roadmap():
Singleton("roadmap").kill()
print(donemessage)


def polygons():
polygons_main.main(None)
Singleton("polygons").kill()
print(donemessage)


def building_generation():
building_generation_main.main()
Singleton("building_generation").kill()
Expand Down Expand Up @@ -88,43 +95,43 @@ def main(args):
python UI.py <submodule-name> --configure <parameter-name> <new value>
"""
if len(args)==1:
if len(args) == 1:
print(main.__doc__)
return 0
if "configure" in args[2]:
if len(args)==3:
os.system("nano ./procedural_city_generation/inputs/"+args[1]+".conf")
config_file = os.path.join(os.path.dirname(os.path.realpath(__file__)),
"procedural_city_generation/inputs/{0}.conf".format(args[1]))
if len(args) == 3:
os.system("nano {0}".format(config_file))
sys.exit(0)

elif args[3] and args[4]:
import json
with open("./procedural_city_generation/inputs/"+args[1]+".conf", 'r') as f:
wb=json.loads(f.read())
i=0
with open(config_file, 'r') as f:
wb = json.loads(f.read())
i = 0
while True:
try:

old=wb[args[3+i]]
wb[args[3+i]]=eval(args[4+i])
print(args[3+i], " was changed from ", old, " to ", args[4+i])
i+=2
if len(args)-1<i+4:
old = wb[args[3+i]]['value']
wb[args[3+i]]['value'] = eval(args[4+i])
print("{0} was changed from {1} to {2}".format(args[3+i], old, args[4+i]))
i += 2
if len(args)-1 < i+4:
break


except:
print(i, len(args))
print("Either ", args[3+i], "is not a configurable parameter for ", args[1])
print("Either {0} is not a configurable parameter for {1}".format(args[3+i], args[1]))
return 0

with open("./procedural_city_generation/inputs/"+args[1]+".conf", 'w') as f:
f.write(json.dumps(wb))
with open(config_file, 'w') as f:
f.write(json.dumps(wb, indent=2))

return 0

elif "run" in args[2]:
setup_matplotlib()
eval(args[1])()

if __name__=='__main__':
if __name__ == '__main__':
main(sys.argv)

0 comments on commit e53d9a4

Please sign in to comment.