Created
November 16, 2019 09:05
-
-
Save ktemkin/70c2bd76331ea30bd10d6b5343dc3e9c to your computer and use it in GitHub Desktop.
quick hack to resize GRC flowgraphs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import yaml | |
if len(sys.argv) != 3: | |
print("flowgraph scaler for demos on different-DPI machines") | |
print(">>> hey, kate, why don't you just fix this in GRC?") | |
print() | |
print("usage: {} <flowgraph> <scale-factor>\n".format(sys.argv[0])) | |
sys.exit(-1) | |
SCALE = float(sys.argv[2]) | |
FLOWGRAPH = sys.argv[1] | |
# Parse the GRC flowgraph. | |
with open(FLOWGRAPH, 'r') as f: | |
data = yaml.load(f, Loader=yaml.CLoader) | |
# Automatically scale each of our block positions. | |
# TODO: is there anything beyond blocks we need to scale? | |
for block in data['blocks']: | |
for key, value in block['states'].items(): | |
if key == 'coordinate': | |
value[0] *= SCALE | |
value[1] *= SCALE | |
# Dump the GRC flowgraph back into its file. | |
output = yaml.dump(data, Dumper=yaml.CDumper) | |
with open(FLOWGRAPH, 'w') as f: | |
f.write(output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment