Skip to content

Commit

Permalink
Template can now include icons
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSekavcnik committed Apr 25, 2024
1 parent e34f957 commit aee9b08
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
17 changes: 16 additions & 1 deletion quasi/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from jinja2 import Environment, FileSystemLoader
import sys
from quasi.signals import *
import quasi.gui.icons.icon_list
import inspect
import re

Expand All @@ -27,6 +28,15 @@ def list_signals():
signals.append(name)
return signals

def list_icons():
icons = [None]
module = sys.modules['quasi.gui.icons.icon_list']
for name, obj in inspect.getmembers(module):
print(name, obj)
if isinstance(obj, str) and name.isupper():
icons.append(name)
return icons

def get_user_choice(options):
for index, option in enumerate(options, start=1):
print(f"{index}. {option}")
Expand Down Expand Up @@ -65,12 +75,17 @@ def main():
s_type = get_user_choice(signal_types)
output_ports[label] = s_type

icons = list_icons()
icon = get_user_choice(icons)

env = get_template_env()
template = env.get_template('device_template.jinja')
output = template.render(
name=args.name,
input_ports=input_ports,
output_ports=output_ports)
output_ports=output_ports,
gui_icon=icon
)
print(output)
if input("Save?(y/n): ").strip().lower() != 'y':
print("Operation cancelled.")
Expand Down
5 changes: 3 additions & 2 deletions quasi/templates/device_template.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ from quasi.devices import (GenericDevice,
from quasi.devices.port import Port
from quasi.simulation import ModeManager
from quasi.signals import *
from quasi.gui.icons import icon_list


class {{ name }}(GenericDevice):
Expand All @@ -35,9 +36,9 @@ class {{ name }}(GenericDevice):
{% endfor %}
}

gui_icon = None
gui_icon = icon_list.{{ gui_icon }}
gui_tags = None
gui_documentation= None
gui_documentation = None

power_peak = 0
power_average = 0
Expand Down

0 comments on commit aee9b08

Please sign in to comment.