summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuergen Bocklage-Ryannel <juergen@ryannel.org>2018-12-24 15:46:42 +0100
committerDominik Holland <dominik.holland@googlemail.com>2022-01-27 13:50:04 +0100
commit031743b53259dd73b611cd9965d392558e76a79c (patch)
tree6a1664759516b3fdc02894e20f966281f1a2d45c
parentca2868a450c4090d5460827a896648280bb72eb0 (diff)
downloadqtivi-qface-031743b53259dd73b611cd9965d392558e76a79c.tar.gz
add run option to qface script
-rw-r--r--qface/app.py10
-rw-r--r--qface/shell.py11
-rw-r--r--qface/templates/qface/qtcpp.j222
-rw-r--r--qface/utils.py4
4 files changed, 38 insertions, 9 deletions
diff --git a/qface/app.py b/qface/app.py
index 38a26d6..434195e 100644
--- a/qface/app.py
+++ b/qface/app.py
@@ -8,12 +8,13 @@ from path import Path
from qface.generator import FileSystem, RuleGenerator
from qface.watch import monitor
from qface.utils import load_filters
+from qface.shell import sh
here = Path(__file__).dirname()
logging.basicConfig()
-def run(spec, src, dst, features, force):
+def run_generator(spec, src, dst, features, force):
spec = Path(spec)
project = Path(dst).name
system = FileSystem.parse(src)
@@ -45,9 +46,10 @@ def run(spec, src, dst, features, force):
@click.option('--scaffold/--no-scaffold', default=False, help="Add extrac scaffolding code")
@click.option('--watch', type=click.Path(exists=False, file_okay=False))
@click.option('--feature', multiple=True)
+@click.option('--run', help="run script after generation")
@click.option('--force/--no-force', default=False, help="forces overwriting of files")
@click.argument('source', nargs=-1, type=click.Path(exists=True))
-def main(rules, target, reload, source, watch, scaffold, feature, force):
+def main(rules, target, reload, source, watch, scaffold, feature, force, run):
rules = Path(rules)
if reload:
argv = sys.argv.copy()
@@ -61,7 +63,9 @@ def main(rules, target, reload, source, watch, scaffold, feature, force):
features = set(feature)
if scaffold:
features.add('scaffold')
- run(rules, source, target, features=features, force=force)
+ run_generator(rules, source, target, features=features, force=force)
+ if run:
+ sh(run)
if __name__ == '__main__':
diff --git a/qface/shell.py b/qface/shell.py
index bf76f7c..32a4ee1 100644
--- a/qface/shell.py
+++ b/qface/shell.py
@@ -1,5 +1,5 @@
import click
-from subprocess import call
+import subprocess
"""
API for interacting with the system shell
@@ -10,7 +10,14 @@ def sh(args, **kwargs):
"""
runs the given cmd as shell command
"""
+ if isinstance(args, str):
+ args = args.split()
if not args:
return
click.echo('$ {0}'.format(' '.join(args)))
- return call(args, **kwargs)
+ try:
+ return subprocess.check_call(args, **kwargs)
+ except subprocess.CalledProcessError as exc:
+ click.secho('run error {}'.format(exc))
+ except OSError as exc:
+ click.secho('not found error {}'.format(exc))
diff --git a/qface/templates/qface/qtcpp.j2 b/qface/templates/qface/qtcpp.j2
index b2e3bff..1f0fb16 100644
--- a/qface/templates/qface/qtcpp.j2
+++ b/qface/templates/qface/qtcpp.j2
@@ -17,10 +17,14 @@
Q_PROPERTY({{property|qt.returnType}} {{property}} READ {{property}} {% if not property.readonly %}WRITE push{{property|upperfirst}}{% endif %}{% if not property.const and notifiable %} NOTIFY {{property}}Changed{% endif %})
{%- endmacro %}
-{% macro property_setter_decl(property, ending=";", prefix='virtual') -%}
+{% macro property_pusher_decl(property, ending=";", prefix='virtual') -%}
{{prefix}} void push{{property|upperfirst}}({{ property|qt.parameterType }}){{ending}}
{%- endmacro %}
+{% macro property_setter_decl(property, ending=";", prefix='virtual') -%}
+{{prefix}} void set{{property|upperfirst}}({{ property|qt.parameterType }}){{ending}}
+{%- endmacro %}
+
{% macro property_getter_decl(property, ending=";", prefix='virtual') -%}
{{prefix}} {{property|qt.returnType}} {{property}}() const{{ending}}
{%- endmacro %}
@@ -33,6 +37,20 @@ void {{symbol}}{{postfix}}();
{{property|qt.returnType}} m_{{property}};
{%- endmacro %}
+{% macro property_pusher_impl(class, property, notifiable=True) -%}
+void {{class}}::push{{property|upperfirst}}({{ property|qt.parameterType }})
+{
+{% if notifiable %}
+ if (m_{{property}} != {{property}}) {
+ m_{{property}} = {{property}};
+ Q_EMIT {{property}}Changed();
+ }
+{% else %}
+ m_{{property}} = {{property}};
+{% endif %}
+}
+{%- endmacro %}
+
{% macro property_setter_impl(class, property, notifiable=True) -%}
/*!
\qmlproperty {{property.type}} {{class}}::{{property}}
@@ -41,7 +59,7 @@ void {{symbol}}{{postfix}}();
{{doc.description|join("\n ")}}
{% endwith %}
*/
-void {{class}}::push{{property|upperfirst}}({{ property|qt.parameterType }})
+void {{class}}::set{{property|upperfirst}}({{ property|qt.parameterType }})
{
{% if notifiable %}
if (m_{{property}} != {{property}}) {
diff --git a/qface/utils.py b/qface/utils.py
index 889d862..d784bff 100644
--- a/qface/utils.py
+++ b/qface/utils.py
@@ -1,6 +1,6 @@
from .generator import FileSystem
from .helper import doc
-
+import click
def module_info(text):
system = FileSystem.parse_text(text)
@@ -13,9 +13,9 @@ def module_info(text):
def load_filters(path):
if not path.exists():
- print('filter module does not exist')
return {}
+ click.secho('loading extra filters from {}'.format(path), fg='green')
ctx = {
'filters': {}
}