ldraw.py

changeset 3
1dc58f44d556
parent 2
50d3086070df
child 4
8eb83f200486
--- a/ldraw.py	Sun Dec 10 15:46:47 2017 +0200
+++ b/ldraw.py	Mon Dec 11 00:46:35 2017 +0200
@@ -1,16 +1,11 @@
-#!/usr/bin/env python3
-from parse import parse_ldraw_code
-
-def read_ldraw(file, *, libraries):
-    result = list()
-    for line in file:
-        result.append(parse_ldraw_code(line))
-    return result
-
-if __name__ == '__main__':
-    from sys import argv
-    libraries = [{'path': '/home/teemu/ldraw', 'role': 'official'}]
-    with open(argv[1], 'r') as file:
-        model = read_ldraw(file, libraries = libraries)
-        from pprint import pprint
-        pprint(model)
+class Color:
+    def __init__(self, index):
+        self.index = int(index, 0)
+    def __str__(self):
+        if self.is_direct_color():
+            # write direct colors with hex codes
+            return '0x%07X' % self.index
+        else:
+            return str(self.index)
+    def is_direct_color(self):
+        return self.index >= 0x2000000

mercurial