Tue, 14 Feb 2017 07:57:27 +0200
Exported GLRenderer cameras into a new class, GLCamera.
1125
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
1 | #!/usr/bin/env python3 |
971
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | # coding: utf-8 |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | # |
1125
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
4 | # Copyright 2015 - 2017 Teemu Piippo |
971
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | # All rights reserved. |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | # |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | # Redistribution and use in source and binary forms, with or without |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | # modification, are permitted provided that the following conditions |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | # are met: |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | # |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | # 1. Redistributions of source code must retain the above copyright |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | # notice, this list of conditions and the following disclaimer. |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | # 2. Redistributions in binary form must reproduce the above copyright |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | # notice, this list of conditions and the following disclaimer in the |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | # documentation and/or other materials provided with the distribution. |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | # 3. Neither the name of the copyright holder nor the names of its |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | # contributors may be used to endorse or promote products derived from |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | # this software without specific prior written permission. |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | # |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | # OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
1126
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
25 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, |
971
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
1126
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
28 | # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING |
971
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | # |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | |
1126
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
33 | from argparse import ArgumentParser |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
34 | from collections import OrderedDict |
971
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | import caseconversions |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | import outputfile |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | |
1126
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
38 | # These types are passed by value |
1125
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
39 | passbyvalue = {'int', 'bool', 'float', 'double', 'qreal'} |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
40 | |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
41 | def deduce_type(value): |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
42 | ''' |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
43 | Try to determine the type of value from the value itself. |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
44 | ''' |
1126
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
45 | if value in('true', 'false'): |
1125
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
46 | return 'bool' |
1126
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
47 | elif value.startswith('"') and value.endswith('"'): |
1125
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
48 | return 'QString' |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
49 | |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
50 | try: |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
51 | int(value) |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
52 | return 'int' |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
53 | except: |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
54 | pass |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
55 | |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
56 | try: |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
57 | float(value) |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
58 | return 'double' |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
59 | except: |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
60 | pass |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
61 | |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
62 | if endswith(value, 'f'): |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
63 | try: |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
64 | float(value[:-1]) |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
65 | return 'float' |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
66 | except: |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
67 | pass |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
68 | |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
69 | raise ValueError('unable to deduce type of %r' % value) |
971
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | |
1126
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
71 | class ConfigCollector: |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
72 | def __init__(self, args): |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
73 | self.declarations = OrderedDict() |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
74 | self.qtTypes = set() |
971
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | self.args = args |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | |
1126
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
77 | def collect(self, filename): |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
78 | with open(filename) as file: |
1125
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
79 | for line in file: |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
80 | line = line.strip() |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
81 | if line and not line.startswith('#'): |
1126
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
82 | from re import search |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
83 | match = search('^option (\w+) = (.+)$', line) |
1125
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
84 | if not match: |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
85 | raise ValueError('unable to parse: %r' % line) |
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
86 | name, value = match.groups() |
1126
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
87 | match = search(r'^(\w+)\s*\{(.*)\}$', value) |
1125
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
88 | try: |
1126
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
89 | typename, value = match.groups() |
1125
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
90 | if not value: |
1126
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
91 | value = typename + ' {}' |
1125
d8f94e56d42e
Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents:
1017
diff
changeset
|
92 | except: |
1126
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
93 | typename = deduce_type(value) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
94 | self.declare(name, typename, value) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
95 | # Sort the declarations in alphabetical order |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
96 | self.declarations = OrderedDict(sorted(self.declarations.items(), key = lambda t: t[1]['name'])) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
97 | # Fill in additional information |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
98 | for declaration in self.declarations.values(): |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
99 | declaration['readgate'] = caseconversions.convert_case(declaration['name'], style='java') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
100 | declaration['writegate'] = 'set' + caseconversions.convert_case(declaration['name'], style='camel') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
101 | declaration['togglefunction'] = 'toggle' + caseconversions.convert_case(declaration['name'], style='camel') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
102 | if declaration['type'] in passbyvalue: |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
103 | declaration['typereference'] = declaration['type'] |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
104 | else: |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
105 | declaration['typereference'] = 'const %s&' % declaration['type'] |
971
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | |
1126
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
107 | def declare(self, name, typename, default): |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
108 | from re import findall |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
109 | if name in self.declarations: |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
110 | raise ValueError('Attempted to redeclare %r' % name) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
111 | self.declarations[name] = { |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
112 | 'name': name, |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
113 | 'type': typename, |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
114 | 'default': default |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
115 | } |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
116 | # Keep a file of any Qt types, we'll need to #include them. |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
117 | self.qtTypes.update(findall(r'Q\w+', typename)) |
971
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | |
1126
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
119 | def writeHeader(self, device): |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
120 | device.write('#pragma once\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
121 | device.write('#include <QMap>\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
122 | for qtType in sorted(self.qtTypes): |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
123 | device.write('#include <%s>\n' % qtType) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
124 | device.write('\n') |
971
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | formatargs = {} |
1126
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
126 | write = lambda value: device.write(value) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
127 | write('class Configuration\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
128 | write('{\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
129 | write('public:\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
130 | write('\tConfiguration();\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
131 | write('\t~Configuration();\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
132 | write('\tbool existsEntry(const QString& name);\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
133 | write('\tQVariant defaultValueByName(const QString& name);\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
134 | for declaration in self.declarations.values(): |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
135 | write('\t{type} {readgate}() const;\n'.format(**declaration)) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
136 | for declaration in self.declarations.values(): |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
137 | write('\tvoid {writegate}({typereference} value);\n'.format(**declaration)) |
971
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | |
1126
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
139 | for declaration in filter(lambda declaration: declaration['type'] == 'bool', self.declarations.values()): |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
140 | write('\tvoid {togglefunction}();\n'.format(**declaration)) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
141 | write('\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
142 | write('private:\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
143 | write('\tQMap<QString, QVariant> m_defaults;\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
144 | write('\tclass QSettings* m_settings;\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
145 | write('};\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
146 | |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
147 | def writeSource(self, device, headername): |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
148 | device.write('#include <QSet>\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
149 | device.write('#include <QSettings>\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
150 | device.write('#include <QVariant>\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
151 | device.write('#include "%s/mainwindow.h"\n' % (self.args.sourcedir)) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
152 | device.write('#include "%s"\n' % headername) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
153 | device.write( |
971
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
154 | '\n' |
1017
fc1c13db9618
Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1012
diff
changeset
|
155 | 'Configuration::Configuration() :\n' |
1126
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
156 | '\tm_settings(makeSettings(nullptr))\n' |
972
a34b73114823
Now doesn't crash anymore
Teemu Piippo <crimsondusk64@gmail.com>
parents:
971
diff
changeset
|
157 | '{\n') |
1126
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
158 | for declaration in self.declarations.values(): |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
159 | device.write('\tm_defaults["{name}"] = QVariant::fromValue<{type}>({default});\n'.format(**declaration)) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
160 | device.write('}\n' |
971
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
161 | '\n' |
1017
fc1c13db9618
Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1012
diff
changeset
|
162 | 'Configuration::~Configuration()\n' |
971
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
163 | '{\n' |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
164 | '\tm_settings->deleteLater();\n' |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
165 | '}\n' |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
166 | '\n') |
1126
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
167 | device.write('QVariant Configuration::defaultValueByName(const QString& name)\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
168 | device.write('{\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
169 | device.write('\tQMap<QString, QVariant>::iterator it = m_defaults.find(name);\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
170 | device.write('\tif(it != m_defaults.end())\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
171 | device.write('\t\treturn *it;\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
172 | device.write('\telse\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
173 | device.write('\t\treturn {};\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
174 | device.write('}\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
175 | device.write('\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
176 | device.write('bool Configuration::existsEntry(const QString& name)\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
177 | device.write('{\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
178 | device.write('\treturn m_defaults.find(name) != m_defaults.end();\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
179 | device.write('}\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
180 | device.write('\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
181 | for declaration in self.declarations.values(): |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
182 | device.write('{type} Configuration::{readgate}() const\n'.format(**declaration)) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
183 | device.write('{\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
184 | device.write('\tstatic const QVariant defaultvalue = QVariant::fromValue<{type}>({default});\n'.format(**declaration)) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
185 | device.write('\treturn m_settings->value("{name}", defaultvalue).value<{type}>();\n'.format(**declaration)) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
186 | device.write('}\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
187 | device.write('\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
188 | for declaration in self.declarations.values(): |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
189 | device.write('void Configuration::{writegate}({typereference} value)\n'.format(**declaration)) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
190 | device.write('{\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
191 | device.write('\tif(value != {default})\n'.format(**declaration)) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
192 | device.write('\t\tm_settings->setValue("{name}", QVariant::fromValue<{type}>(value));\n'.format(**declaration)) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
193 | device.write('\telse\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
194 | device.write('\t\tm_settings->remove("{name}");\n'.format(**declaration)) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
195 | device.write('}\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
196 | device.write('\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
197 | for declaration in filter(lambda declaration: declaration['type'] == 'bool', self.declarations.values()): |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
198 | device.write('void Configuration::{togglefunction}()\n'.format(**declaration)) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
199 | device.write('{\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
200 | device.write('\t{writegate}(not {readgate}());\n'.format(**declaration)) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
201 | device.write('}\n') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
202 | device.write('\n') |
1017
fc1c13db9618
Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1012
diff
changeset
|
203 | |
971
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
204 | def main(): |
1126
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
205 | parser = ArgumentParser(description='Collects a list of configuration objects') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
206 | parser.add_argument('input') |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
207 | parser.add_argument('--header', required=True) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
208 | parser.add_argument('--source', required=True) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
209 | parser.add_argument('--sourcedir', required=True) |
971
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
210 | args = parser.parse_args() |
1126
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
211 | collector = ConfigCollector(args) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
212 | collector.collect(args.input) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
213 | header = outputfile.OutputFile(args.header) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
214 | source = outputfile.OutputFile(args.source) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
215 | collector.writeSource(source, headername=args.header) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
216 | collector.writeHeader(header) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
217 | header.save(verbose = True) |
508950e27fcd
Refactored configcollector.py
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
218 | source.save(verbose = True) |
971
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
219 | |
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
220 | if __name__ == '__main__': |
1012 | 221 | main() |