├── src
├── save_files
│ ├── test.lvs
│ ├── WhileLoopSample.lvs
│ └── divideby2.lvs
├── assets
│ ├── font
│ │ ├── roboto.ttf
│ │ └── robotoBold.ttf
│ └── images
│ │ ├── icon.ico
│ │ ├── splash.png
│ │ └── LargeLogo.png
├── LuaNodeEditor.exe.notanexecutable
├── constants.py
├── demo.py
├── settings.ini
├── lua_execute.py
├── helper.py
├── themes.py
├── globals.py
├── test.py
├── LuaNodeAttributes.py
├── main.py
└── LuaNodes.py
├── dist
└── assets
│ ├── settings.ini
│ ├── font
│ ├── roboto.ttf
│ └── robotoBold.ttf
│ └── images
│ ├── icon.ico
│ ├── splash.png
│ └── LargeLogo.png
├── distribute.bat
├── settings.ini
├── install-packs.bat
├── .github
├── FUNDING.yml
└── ISSUE_TEMPLATE
│ ├── features.yml
│ └── BugReport.yml
├── .gitignore
├── README.md
└── LICENSE
/src/save_files/test.lvs:
--------------------------------------------------------------------------------
1 | {
2 | "nodes": {},
3 | "links": {}
4 | }
--------------------------------------------------------------------------------
/dist/assets/settings.ini:
--------------------------------------------------------------------------------
1 | [Window][Debug##Default]
2 | Pos=60,60
3 | Size=400,400
4 | Collapsed=0
5 |
6 |
--------------------------------------------------------------------------------
/dist/assets/font/roboto.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SanForgeStudio/LuaNodeEditor/HEAD/dist/assets/font/roboto.ttf
--------------------------------------------------------------------------------
/dist/assets/images/icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SanForgeStudio/LuaNodeEditor/HEAD/dist/assets/images/icon.ico
--------------------------------------------------------------------------------
/src/assets/font/roboto.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SanForgeStudio/LuaNodeEditor/HEAD/src/assets/font/roboto.ttf
--------------------------------------------------------------------------------
/src/assets/images/icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SanForgeStudio/LuaNodeEditor/HEAD/src/assets/images/icon.ico
--------------------------------------------------------------------------------
/dist/assets/images/splash.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SanForgeStudio/LuaNodeEditor/HEAD/dist/assets/images/splash.png
--------------------------------------------------------------------------------
/src/assets/images/splash.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SanForgeStudio/LuaNodeEditor/HEAD/src/assets/images/splash.png
--------------------------------------------------------------------------------
/dist/assets/font/robotoBold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SanForgeStudio/LuaNodeEditor/HEAD/dist/assets/font/robotoBold.ttf
--------------------------------------------------------------------------------
/dist/assets/images/LargeLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SanForgeStudio/LuaNodeEditor/HEAD/dist/assets/images/LargeLogo.png
--------------------------------------------------------------------------------
/src/assets/font/robotoBold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SanForgeStudio/LuaNodeEditor/HEAD/src/assets/font/robotoBold.ttf
--------------------------------------------------------------------------------
/src/assets/images/LargeLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SanForgeStudio/LuaNodeEditor/HEAD/src/assets/images/LargeLogo.png
--------------------------------------------------------------------------------
/distribute.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | pyinstaller --onefile --name LuaNodeEditor --icon="src/assets/images/icon.ico" --noconsole "src/main.py"
3 |
--------------------------------------------------------------------------------
/src/LuaNodeEditor.exe.notanexecutable:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SanForgeStudio/LuaNodeEditor/HEAD/src/LuaNodeEditor.exe.notanexecutable
--------------------------------------------------------------------------------
/src/constants.py:
--------------------------------------------------------------------------------
1 | color_default = (0, 0, 255)
2 | color_math_operator = (0, 0, 255)
3 | color_variable = (255, 255, 255)
4 | color_function = (0, 0, 255)
5 | color_immediate_value = (252, 139, 86)
6 | color_keyword = (0, 0, 255)
7 |
8 | color_test = (255, 255, 255)
9 |
--------------------------------------------------------------------------------
/src/demo.py:
--------------------------------------------------------------------------------
1 | import dearpygui.dearpygui as dpg
2 | from dearpygui.demo import show_demo
3 |
4 | dpg.create_context()
5 | dpg.create_viewport()
6 | dpg.setup_dearpygui()
7 |
8 | show_demo()
9 |
10 | dpg.show_viewport()
11 | dpg.start_dearpygui()
12 | dpg.destroy_context()
--------------------------------------------------------------------------------
/settings.ini:
--------------------------------------------------------------------------------
1 | [Window][Debug##Default]
2 | Pos=60,60
3 | Size=400,400
4 | Collapsed=0
5 |
6 | [Window][###140]
7 | Pos=760,398
8 | Size=281,84
9 | Collapsed=0
10 |
11 | [Window][###148]
12 | Pos=584,382
13 | Size=233,84
14 | Collapsed=0
15 |
16 | [Window][###156]
17 | Pos=584,382
18 | Size=281,84
19 | Collapsed=0
20 |
21 | [Window][###142]
22 | Pos=139,149
23 | Size=922,501
24 | Collapsed=0
25 |
26 | [Window][###150]
27 | Pos=760,398
28 | Size=281,84
29 | Collapsed=0
30 |
31 | [Window][###158]
32 | Pos=300,125
33 | Size=922,459
34 | Collapsed=0
35 |
36 |
--------------------------------------------------------------------------------
/src/settings.ini:
--------------------------------------------------------------------------------
1 | [Window][Debug##Default]
2 | Pos=60,60
3 | Size=400,400
4 | Collapsed=0
5 |
6 | [Window][###301]
7 | Pos=1272,690
8 | Size=233,84
9 | Collapsed=0
10 |
11 | [Window][###171]
12 | Pos=584,382
13 | Size=233,84
14 | Collapsed=0
15 |
16 | [Window][###179]
17 | Pos=584,382
18 | Size=233,84
19 | Collapsed=0
20 |
21 | [Window][###190]
22 | Pos=1272,690
23 | Size=233,84
24 | Collapsed=0
25 |
26 | [Window][###141]
27 | Pos=204,134
28 | Size=922,459
29 | Collapsed=0
30 |
31 | [Window][###176]
32 | Pos=584,382
33 | Size=233,84
34 | Collapsed=0
35 |
36 | [Window][###177]
37 | Pos=483,358
38 | Size=233,84
39 | Collapsed=0
40 |
41 | [Window][###240]
42 | Pos=152,140
43 | Size=922,459
44 | Collapsed=0
45 |
46 |
--------------------------------------------------------------------------------
/install-packs.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | echo ============================================
3 | echo Installing required Python packages...
4 | echo ============================================
5 |
6 | :: Upgrade pip first
7 | python -m pip install --upgrade pip
8 |
9 | :: Install packages
10 | pip install dearpygui
11 | pip install pyperclip
12 | pip install pyinstaller
13 | pip install lupa
14 | pip install pillow
15 |
16 |
17 | :: pprint and threading are standard Python libraries — no install needed
18 | echo Skipping pprint and threading (already included in Python)
19 |
20 | echo.
21 | echo ============================================
22 | echo All packages installed successfully!
23 | echo ============================================
24 |
25 | pause
26 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | open_collective: # Replace with a single Open Collective username
5 | ko_fi: # Replace with a single Ko-fi username
6 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
7 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
8 | liberapay: # Replace with a single Liberapay username
9 | issuehunt: # Replace with a single IssueHunt username
10 | otechie: # Replace with a single Otechie username
11 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
12 | custom: https://www.paypal.com/paypalme/SanForgeStudio
13 |
--------------------------------------------------------------------------------
/src/lua_execute.py:
--------------------------------------------------------------------------------
1 | from lupa.lua54 import LuaRuntime
2 | import sys
3 |
4 | # def execute():
5 | def execute(code):
6 | # try:
7 | # with open("fileout.txt", "w") as file:
8 | # file.write(code)
9 | # print("String has been successfully written to", "fielout")
10 | # except Exception as e:
11 | # print("An error occurred:", str(e))
12 |
13 | lua = LuaRuntime()
14 | lua.execute(code)
15 |
16 | if __name__ == '__main__':
17 | globals()[sys.argv[1]](sys.argv[2])
18 |
19 | # execute("test")
20 | # execute()
21 |
22 | # execute('''
23 | # local Divider = {
24 | # Divide = 12,
25 | # }
26 | # local function calculateAndPrintHalf()
27 | # local halfValue = Divider.Divide / 2
28 | # return halfValue / 2
29 | # end
30 | # print(calculateAndPrintHalf())
31 | # ''')
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/features.yml:
--------------------------------------------------------------------------------
1 | name: Feature Request
2 | description: File a feature request
3 | title: "[features]: "
4 | labels: ["features"]
5 | body:
6 | - type: markdown
7 | attributes:
8 | value: |
9 | Thank you for making a Feature Request!
10 | - type: textarea
11 | id: what-happened
12 | attributes:
13 | label: What feature do you want to request?
14 | description: |
15 | Please tell us about the feature as detailed as possible.
16 | Feel free to also add Media!
17 | validations:
18 | required: true
19 |
20 | - type: textarea
21 | id: use-case
22 | attributes:
23 | label: Use Case
24 | description: |
25 | Explain the use case or scenario in which this feature would be beneficial.
26 | validations:
27 | required: true
28 |
29 | - type: textarea
30 | id: more-information
31 | attributes:
32 | label: More information
33 | description: Is there anything else relevant that you want/need to share.
34 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/BugReport.yml:
--------------------------------------------------------------------------------
1 | name: Bug Report
2 | description: File a bug report
3 | title: "[Bug]: "
4 | labels: ["bug"]
5 | body:
6 | - type: markdown
7 | attributes:
8 | value: |
9 | Thank you for making a Bug Report!
10 | - type: textarea
11 | id: what-happened
12 | attributes:
13 | label: What happened?
14 | description: |
15 | Please tell us about the bug as detailed as possible.
16 | Feel free to also add Media and CrashLogs!
17 | validations:
18 | required: true
19 | - type: dropdown
20 | id: lua-node-version
21 | attributes:
22 | label: Lua Node Editor Version
23 | description: Which version of the Lua Node Editor are you using?
24 | options:
25 | - "V1.0"
26 | validations:
27 | required: true
28 | # For if you have multiple Bug types
29 | # - type: checkboxes
30 | # id: related
31 | # attributes:
32 | # label: Type of Bug
33 | # description: What type of bug is this?
34 | # options:
35 | # - label: bugtype 1
36 | # - label: bugtype 2
37 | # - label: bugtype 3
38 | - type: textarea
39 | id: more-information
40 | attributes:
41 | label: More information
42 | description: Is there anything else relevant that you want/need to share.
43 |
--------------------------------------------------------------------------------
/src/helper.py:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright © 2023, SanForge Studio & Lua Node Editor, All Rights Reserved.
3 | # Licensed under the GNU General Public 3.0 License
4 | #
5 |
6 | import dearpygui.dearpygui as dpg
7 | def auto_align(item, alignment_type: int, x_align: float = 0.5, y_align: float = 0.5):
8 | def _center_h(_s, _d, data):
9 | parent = dpg.get_item_parent(data[0])
10 | while dpg.get_item_info(parent)['type'] != "mvAppItemType::mvWindowAppItem":
11 | parent = dpg.get_item_parent(parent)
12 | parent_width = dpg.get_item_rect_size(parent)[0]
13 | width = dpg.get_item_rect_size(data[0])[0]
14 | new_x = (parent_width // 2 - width // 2) * data[1] * 2
15 | dpg.set_item_pos(data[0], [new_x, dpg.get_item_pos(data[0])[1]])
16 |
17 | def _center_v(_s, _d, data):
18 | parent = dpg.get_item_parent(data[0])
19 | while dpg.get_item_info(parent)['type'] != "mvAppItemType::mvWindowAppItem":
20 | parent = dpg.get_item_parent(parent)
21 | parent_width = dpg.get_item_rect_size(parent)[1]
22 | height = dpg.get_item_rect_size(data[0])[1]
23 | new_y = (parent_width // 2 - height // 2) * data[1] * 2
24 | dpg.set_item_pos(data[0], [dpg.get_item_pos(data[0])[0], new_y])
25 |
26 | if 0 <= alignment_type <= 2:
27 | with dpg.item_handler_registry():
28 | if alignment_type == 0:
29 | # horizontal only alignment
30 | dpg.add_item_visible_handler(callback=_center_h, user_data=[item, x_align])
31 | elif alignment_type == 1:
32 | # vertical only alignment
33 | dpg.add_item_visible_handler(callback=_center_v, user_data=[item, y_align])
34 | elif alignment_type == 2:
35 | # both horizontal and vertical alignment
36 | dpg.add_item_visible_handler(callback=_center_h, user_data=[item, x_align])
37 | dpg.add_item_visible_handler(callback=_center_v, user_data=[item, y_align])
38 |
39 | dpg.bind_item_handler_registry(item, dpg.last_container())
40 |
--------------------------------------------------------------------------------
/src/themes.py:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright © 2023, SanForge Studio & Lua Node Editor, All Rights Reserved.
3 | # Licensed under the GNU General Public 3.0 License
4 | #
5 |
6 |
7 | import dearpygui.dearpygui as dpg
8 | from LuaNodes import *
9 |
10 | # dpg.add_theme_color(dpg.mvNodeCol_NodeBackground, (255, 0, 0, 0), category=dpg.mvThemeCat_Nodes)
11 | # dpg.add_theme_color(dpg.mvNodeCol_NodeBackgroundHovered, (255, 0, 0, 0), category=dpg.mvThemeCat_Nodes)
12 | # dpg.add_theme_color(dpg.mvNodeCol_NodeBackgroundSelected, (255, 0, 0, 0), category=dpg.mvThemeCat_Nodes)
13 | # dpg.add_theme_color(dpg.mvNodeCol_NodeOutline, (255, 0, 0, 0), category=dpg.mvThemeCat_Nodes)
14 | # dpg.add_theme_color(dpg.mvNodeCol_TitleBar, (255, 0, 0, 0), category=dpg.mvThemeCat_Nodes)
15 | # dpg.add_theme_color(dpg.mvNodeCol_TitleBarHovered, (255, 0, 0, 0), category=dpg.mvThemeCat_Nodes)
16 | # dpg.add_theme_color(dpg.mvNodeCol_TitleBarSelected, (255, 0, 0, 0), category=dpg.mvThemeCat_Nodes)
17 | themes = {
18 |
19 | }
20 |
21 | def create_theme_from_color(color):
22 | with dpg.theme() as ret:
23 | with dpg.theme_component(dpg.mvAll):
24 | dpg.add_theme_color(dpg.mvNodeCol_TitleBar, color, category=dpg.mvThemeCat_Nodes)
25 | dpg.add_theme_color(dpg.mvNodeCol_TitleBarHovered, (color[0] + 10, color[1] + 10, color[2] + 10), category=dpg.mvThemeCat_Nodes)
26 | dpg.add_theme_color(dpg.mvNodeCol_TitleBarSelected, (color[0] + 20, color[1] + 20, color[2] + 20), category=dpg.mvThemeCat_Nodes)
27 | return ret
28 |
29 | def init_themes():
30 | pink_theme = create_theme_from_color((105, 0, 105))
31 | green_theme = create_theme_from_color((20, 150, 10))
32 | blue_theme = create_theme_from_color((10, 20, 200))
33 | red_theme = create_theme_from_color((190, 10, 30))
34 | purple_theme = create_theme_from_color((190, 10, 180))
35 | yellow_theme = create_theme_from_color((140, 180, 10))
36 | brown_theme = create_theme_from_color((115, 42, 42))
37 | white_theme = create_theme_from_color((170, 170, 170))
38 |
39 | global themes
40 | themes[(lua_ntStart, )] = pink_theme
41 | themes[(lua_ntGreater, lua_ntGreaterOrEqual, lua_ntLess, lua_ntLessOrEqual, lua_ntEqual, lua_ntNotEqual)] = green_theme
42 | themes[(lua_ntAdd, lua_ntSubtract, lua_ntMultiply, lua_ntDivide,lua_ntModulus)] = blue_theme
43 | themes[(lua_ntVariable, lua_ntTable, lua_ntExpression)] = red_theme
44 | themes[(lua_ntFunctionCall, lua_ntFunctionDeclaration)] = purple_theme
45 | themes[(lua_ntWhileLoop, lua_ntForLoop, lua_ntIteratePairs, lua_ntIterateIPairs, lua_ntIf, lua_ntElseIf, lua_ntElse)] = yellow_theme
46 | themes[(lua_ntConcat, lua_ntChainExpression)] = brown_theme
47 | themes[(lua_ntAssign, lua_ntIndexTableByKey, lua_ntIndexTable)] = white_theme
48 |
49 | def apply_theme(node: LuaNode):
50 | for key, theme in themes.items():
51 | if node.node_type in key:
52 | dpg.bind_item_theme(node.id, theme)
53 |
--------------------------------------------------------------------------------
/src/globals.py:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright © 2023, SanForge Studio & Lua Node Editor, All Rights Reserved.
3 | # Licensed under the GNU General Public 3.0 License
4 | #
5 |
6 |
7 | from abc import ABC, abstractmethod
8 | import dearpygui.dearpygui as dpg
9 |
10 | nodes = []
11 | links = []
12 |
13 | indent_level = 0
14 |
15 |
16 | class Serializable(ABC):
17 |
18 | @abstractmethod
19 | def serialize(self):
20 | pass
21 |
22 | @abstractmethod
23 | def deserialize(self, obj):
24 | pass
25 |
26 | def ind():
27 | global indent_level
28 | return " " * indent_level
29 |
30 |
31 | def bcksl():
32 | return "\n"
33 |
34 |
35 | def inc_ind():
36 | global indent_level
37 | indent_level += 1
38 | return ""
39 |
40 |
41 | def dec_ind():
42 | global indent_level
43 | indent_level -= 1
44 | return ""
45 |
46 |
47 | def get_node_from_id(id):
48 | for node in nodes:
49 | if node.id == id:
50 | return node
51 | return None
52 |
53 |
54 | def get_link_from_id(id):
55 | for link in links:
56 | if link.id == id:
57 | return link
58 | return None
59 |
60 |
61 | def get_link_from_in_node_attribute(in_id):
62 | for link in links:
63 | if link.to_attribute == in_id:
64 | return link
65 | return None
66 |
67 |
68 | def get_link_from_out_node_attribute(out_id):
69 | for link in links:
70 | if link.from_attribute == out_id:
71 | return link
72 | return None
73 |
74 |
75 | def get_nodes_from_link(link):
76 | # for l in links:
77 | # if l == link:
78 | # return [l.from_node, l.to_node]
79 | # return None
80 | return [get_node_from_id(link.from_node), get_node_from_id(link.to_node)]
81 |
82 |
83 | def get_from_node_from_in_node_attribute(in_id):
84 | link = get_link_from_in_node_attribute(in_id)
85 | if link:
86 | return get_nodes_from_link(link)[0]
87 |
88 |
89 | def get_to_node_from_out_node_attribute(out_id):
90 | link = get_link_from_out_node_attribute(out_id)
91 | if link:
92 | return get_nodes_from_link(link)[1]
93 |
94 |
95 | def get_out_node_attribute_from_in_node_attribute(in_id):
96 | from LuaNodes import LuaNode, Link
97 | from LuaNodeAttributes import NodeAttribute
98 |
99 | link: Link = get_link_from_in_node_attribute(in_id)
100 | if link:
101 | node: LuaNode = get_nodes_from_link(link)[0]
102 | n_a: NodeAttribute
103 | for n_a in node.node_attributes:
104 | if n_a.id == link.from_attribute:
105 | return n_a
106 | # if link:
107 | # node: LuaNode = get_nodes_from_link(link)[0]
108 | # n_a: NodeAttribute
109 | # # just get the node attributes as the children of the node?
110 | # for n_a_id in dpg.get_item_children(node.id, slot=1):
111 | # if n_a_id == link.from_attribute:
112 | # return n_a
113 |
114 |
115 | def get_in_node_attribute_from_out_node_attribute(out_id):
116 | from LuaNodes import LuaNode, Link
117 | from LuaNodeAttributes import NodeAttribute
118 |
119 | link: Link = get_link_from_out_node_attribute(out_id)
120 | if link:
121 | node: LuaNode = get_nodes_from_link(link)[1]
122 | n_a: NodeAttribute
123 | for n_a in node.node_attributes:
124 | if n_a.id == link.to_attribute:
125 | return n_a
126 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | share/python-wheels/
24 | *.egg-info/
25 | .installed.cfg
26 | *.egg
27 | MANIFEST
28 |
29 | # PyInstaller
30 | # Usually these files are written by a python script from a template
31 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
32 | *.manifest
33 | *.spec
34 |
35 | # Installer logs
36 | pip-log.txt
37 | pip-delete-this-directory.txt
38 |
39 | # Unit test / coverage reports
40 | htmlcov/
41 | .tox/
42 | .nox/
43 | .coverage
44 | .coverage.*
45 | .cache
46 | nosetests.xml
47 | coverage.xml
48 | *.cover
49 | *.py,cover
50 | .hypothesis/
51 | .pytest_cache/
52 | cover/
53 |
54 | # Translations
55 | *.mo
56 | *.pot
57 |
58 | # Django stuff:
59 | *.log
60 | local_settings.py
61 | db.sqlite3
62 | db.sqlite3-journal
63 |
64 | # Flask stuff:
65 | instance/
66 | .webassets-cache
67 |
68 | # Scrapy stuff:
69 | .scrapy
70 |
71 | # Sphinx documentation
72 | docs/_build/
73 |
74 | # PyBuilder
75 | .pybuilder/
76 | target/
77 |
78 | # Jupyter Notebook
79 | .ipynb_checkpoints
80 |
81 | # IPython
82 | profile_default/
83 | ipython_config.py
84 |
85 | # pyenv
86 | # For a library or package, you might want to ignore these files since the code is
87 | # intended to run in multiple environments; otherwise, check them in:
88 | # .python-version
89 |
90 | # pipenv
91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
94 | # install all needed dependencies.
95 | #Pipfile.lock
96 |
97 | # poetry
98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99 | # This is especially recommended for binary packages to ensure reproducibility, and is more
100 | # commonly ignored for libraries.
101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102 | #poetry.lock
103 |
104 | # pdm
105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106 | #pdm.lock
107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108 | # in version control.
109 | # https://pdm.fming.dev/#use-with-ide
110 | .pdm.toml
111 |
112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113 | __pypackages__/
114 |
115 | # Celery stuff
116 | celerybeat-schedule
117 | celerybeat.pid
118 |
119 | # SageMath parsed files
120 | *.sage.py
121 |
122 | # Environments
123 | .env
124 | .venv
125 | env/
126 | venv/
127 | ENV/
128 | env.bak/
129 | venv.bak/
130 |
131 | # Spyder project settings
132 | .spyderproject
133 | .spyproject
134 |
135 | # Rope project settings
136 | .ropeproject
137 |
138 | # mkdocs documentation
139 | /site
140 |
141 | # mypy
142 | .mypy_cache/
143 | .dmypy.json
144 | dmypy.json
145 |
146 | # Pyre type checker
147 | .pyre/
148 |
149 | # pytype static type analyzer
150 | .pytype/
151 |
152 | # Cython debug symbols
153 | cython_debug/
154 |
155 | # PyCharm
156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158 | # and can be added to the global gitignore or merged into this file. For a more nuclear
159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160 | #.idea/
161 |
--------------------------------------------------------------------------------
/src/save_files/WhileLoopSample.lvs:
--------------------------------------------------------------------------------
1 | {
2 | "nodes": {
3 | "334": {
4 | "id": 334,
5 | "node_pos": [
6 | 3,
7 | 28
8 | ],
9 | "node_type": 1,
10 | "attributes": {
11 | "331": {
12 | "id": 331
13 | }
14 | }
15 | },
16 | "347": {
17 | "id": 347,
18 | "node_pos": [
19 | 260,
20 | 28
21 | ],
22 | "node_type": 0,
23 | "attributes": {
24 | "336": {
25 | "id": 336
26 | },
27 | "339": {
28 | "id": 339
29 | },
30 | "342": {
31 | "id": 342,
32 | "name": "i",
33 | "value": " 1",
34 | "multiline": false
35 | }
36 | }
37 | },
38 | "362": {
39 | "id": 362,
40 | "node_pos": [
41 | 685,
42 | 51
43 | ],
44 | "node_type": 4,
45 | "attributes": {
46 | "350": {
47 | "id": 350
48 | },
49 | "353": {
50 | "id": 353
51 | },
52 | "356": {
53 | "id": 356,
54 | "value": ""
55 | },
56 | "359": {
57 | "id": 359
58 | }
59 | }
60 | },
61 | "414": {
62 | "id": 414,
63 | "node_pos": [
64 | 470,
65 | 272
66 | ],
67 | "node_type": 15,
68 | "attributes": {
69 | "399": {
70 | "id": 399,
71 | "value": ""
72 | },
73 | "402": {
74 | "id": 402
75 | },
76 | "405": {
77 | "id": 405,
78 | "value": "5"
79 | },
80 | "408": {
81 | "id": 408,
82 | "value": false
83 | },
84 | "411": {
85 | "id": 411,
86 | "value": null
87 | }
88 | }
89 | },
90 | "426": {
91 | "id": 426,
92 | "node_pos": [
93 | 1090,
94 | 123
95 | ],
96 | "node_type": 2,
97 | "attributes": {
98 | "417": {
99 | "id": 417
100 | },
101 | "420": {
102 | "id": 420
103 | },
104 | "423": {
105 | "id": 423,
106 | "value": "\"Number:\", i"
107 | }
108 | }
109 | },
110 | "657": {
111 | "id": 657,
112 | "node_pos": [
113 | 1479,
114 | 145
115 | ],
116 | "node_type": 21,
117 | "attributes": {
118 | "642": {
119 | "id": 642
120 | },
121 | "645": {
122 | "id": 645
123 | },
124 | "648": {
125 | "id": 648,
126 | "value": "i"
127 | },
128 | "651": {
129 | "id": 651
130 | },
131 | "654": {
132 | "id": 654,
133 | "value": ""
134 | }
135 | }
136 | },
137 | "674": {
138 | "id": 674,
139 | "node_pos": [
140 | 1082,
141 | 258
142 | ],
143 | "node_type": 8,
144 | "attributes": {
145 | "659": {
146 | "id": 659,
147 | "value": "i"
148 | },
149 | "662": {
150 | "id": 662
151 | },
152 | "665": {
153 | "id": 665,
154 | "value": "1"
155 | },
156 | "668": {
157 | "id": 668,
158 | "value": false
159 | },
160 | "671": {
161 | "id": 671,
162 | "value": null
163 | }
164 | }
165 | }
166 | },
167 | "links": {
168 | "348": {
169 | "id": 348,
170 | "from_node": 334,
171 | "to_node": 347,
172 | "from_attribute": 331,
173 | "to_attribute": 336
174 | },
175 | "363": {
176 | "id": 363,
177 | "from_node": 347,
178 | "to_node": 362,
179 | "from_attribute": 339,
180 | "to_attribute": 350
181 | },
182 | "415": {
183 | "id": 415,
184 | "from_node": 414,
185 | "to_node": 362,
186 | "from_attribute": 411,
187 | "to_attribute": 356
188 | },
189 | "427": {
190 | "id": 427,
191 | "from_node": 362,
192 | "to_node": 426,
193 | "from_attribute": 359,
194 | "to_attribute": 417
195 | },
196 | "428": {
197 | "id": 428,
198 | "from_node": 347,
199 | "to_node": 414,
200 | "from_attribute": 342,
201 | "to_attribute": 399
202 | },
203 | "676": {
204 | "id": 676,
205 | "from_node": 674,
206 | "to_node": 657,
207 | "from_attribute": 671,
208 | "to_attribute": 654
209 | },
210 | "677": {
211 | "id": 677,
212 | "from_node": 426,
213 | "to_node": 657,
214 | "from_attribute": 420,
215 | "to_attribute": 642
216 | }
217 | }
218 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |

5 |
6 |
7 |

8 |
9 |
10 |
11 |
12 | #
13 |
14 |
15 | Lua Node Editor is a powerful visual scripting IDE that uses flow-nodes to program visually by using it with the Lua scripting language. Our tool is unique and powerful in its own way as it can be used for projects in multiple industries.
16 |
17 |
18 | # Why Lua?
19 | For those new to coding Lua is a very lightweight scripting language, because it is a quick and powerful language and a very needed language in alot of industries. It is used in massive projects for example Roblox, BeamNG, Xplane. For us we think that learning is key! With the Lua Node Editor, you see the logic unfold visually, in getting a deeper understanding of the programming concepts used by Lua.
20 |
21 |
22 | # Why Visual Programming?
23 | Simplicity simply Meets Power, embrace coding without the intimidation of having knowledge in programming. The Lua Node Editor simplifies Lua programming through a custom visual language, making it an ideal starting point for no experienced beginners, professionals and experts that wish to understand Lua better.
24 | The overall idea of this tool is to ensure everyone can use it how they want, either use our binaries or integrate it to your own system or software and customize it how you like.
25 |
26 |
27 |
28 | **The Advantage of a Visual Programming tool:**
29 | - It can make Lua programming easier, faster, and more fun, especially for beginners or people who are not comfortable with writing code.
30 | - It can provide a visual overview of the structure and functionality of the program, which can help with debugging, testing, and understanding the code.
31 | - It can enable rapid prototyping and experimentation, because you can quickly create and modify nodes and see fast results.
32 | - It eventually can easily integrate with other software and frameworks that use Lua like any other IDE.
33 | - Runnable code directly visually represented.
34 |
35 | *A simple application idea in a flowchart:*
36 |
37 |
38 |
39 | # The power of Nodes
40 | Because the Lua Node Editor is based on learning and exploring and making code more fun, similar to many tools that use visual programming for example Scratch or the Unreal Engine, We hope to accomplish alot of breakthroughs with this tool and making it a highly advanced tool.
41 | The Lua Node Editor has currently a total of 34 integrated nodes in which more will be added later, Every node is specifically designed to work with the lua programming workflow you can see them all explained and individually [here](https://github.com/SanForgeStudio/LuaNodeEditor/wiki/Nodes-Library#integrated-nodes).
42 |
43 | # Early development release?
44 | The Lua Node Editor has released but in a early development phase. Purely to receive community feedback and to showcase our innovation to the world. You can find all the old and new releases [here](https://github.com/SanForgeStudio/LuaNodeEditor/releases).
45 |
46 | # The Future?
47 | The Lua Node Editor, is a really impressive tool, but our idea is beyond the current scope of the Lua Node Editor, our main goal is to eventually build a "Mother" tool for multiple programming languages in one application that supports both sided scripting, this means if you were to program with normal code, the editor would make the nodes for you in real-time or even adding support for AI so that the AI can give a prompt that will be executed both in a code and a flow node structure.
48 |
49 | # License?
50 |
51 | ## Software License
52 | The primary repository license falls under the **GNU General Public 3.0** license, you can read it [here](https://github.com/SanForgeStudio/LuaNodeEditor/blob/main/LICENSE).
53 |
54 | ## Asset & Logo License
55 | Our Lua Node Editor logo's and graphical assets fall under the **Attribution NonCommercial 4.0 International** License, you can read it [here](https://creativecommons.org/licenses/by-nc/4.0/).
56 |
57 |
58 |
59 | # Author
60 | - Creator: Sander Kerkhoff
61 | - Author: SanForge Studio
62 | - Email: info@sanforgestudio.com
63 |
64 | *Copyright © All rights reserved SanForge Studio.*
65 |
--------------------------------------------------------------------------------
/src/save_files/divideby2.lvs:
--------------------------------------------------------------------------------
1 | {
2 | "nodes": {
3 | "144": {
4 | "id": 144,
5 | "node_pos": [
6 | 24,
7 | 216
8 | ],
9 | "node_type": 1,
10 | "attributes": {
11 | "141": {
12 | "id": 141
13 | }
14 | }
15 | },
16 | "165": {
17 | "id": 165,
18 | "node_pos": [
19 | 323,
20 | 222
21 | ],
22 | "node_type": 31,
23 | "attributes": {
24 | "146": {
25 | "id": 146
26 | },
27 | "149": {
28 | "id": 149
29 | },
30 | "152": {
31 | "id": 152,
32 | "value": "Divider"
33 | },
34 | "155": {
35 | "id": 155,
36 | "entries": [
37 | {
38 | "id": null,
39 | "name": {
40 | "id": 168,
41 | "value": "Divide"
42 | },
43 | "value": {
44 | "id": 171,
45 | "value": "12"
46 | }
47 | }
48 | ]
49 | },
50 | "162": {
51 | "id": 162
52 | },
53 | "168": {
54 | "id": 168,
55 | "value": "Divide"
56 | },
57 | "171": {
58 | "id": 171,
59 | "value": "12"
60 | }
61 | }
62 | },
63 | "196": {
64 | "id": 196,
65 | "node_pos": [
66 | 615,
67 | 243
68 | ],
69 | "node_type": 22,
70 | "attributes": {
71 | "174": {
72 | "id": 174
73 | },
74 | "177": {
75 | "id": 177
76 | },
77 | "180": {
78 | "id": 180,
79 | "value": "calculateAndPrintHalf"
80 | },
81 | "183": {
82 | "id": 183,
83 | "name": "Arguments",
84 | "arguments": []
85 | },
86 | "190": {
87 | "id": 190
88 | },
89 | "193": {
90 | "id": 193
91 | }
92 | }
93 | },
94 | "210": {
95 | "id": 210,
96 | "node_pos": [
97 | 926,
98 | 417
99 | ],
100 | "node_type": 0,
101 | "attributes": {
102 | "199": {
103 | "id": 199
104 | },
105 | "202": {
106 | "id": 202
107 | },
108 | "205": {
109 | "id": 205,
110 | "name": "halfValue",
111 | "value": " Divider.Divide / 2",
112 | "multiline": false
113 | }
114 | }
115 | },
116 | "222": {
117 | "id": 222,
118 | "node_pos": [
119 | 1736,
120 | 430
121 | ],
122 | "node_type": 2,
123 | "attributes": {
124 | "213": {
125 | "id": 213
126 | },
127 | "216": {
128 | "id": 216
129 | },
130 | "219": {
131 | "id": 219,
132 | "value": "halfValue"
133 | }
134 | }
135 | },
136 | "250": {
137 | "id": 250,
138 | "node_pos": [
139 | 934,
140 | 145
141 | ],
142 | "node_type": 23,
143 | "attributes": {
144 | "225": {
145 | "id": 225
146 | },
147 | "228": {
148 | "id": 228
149 | },
150 | "231": {
151 | "id": 231,
152 | "value": "calculateAndPrintHalf"
153 | },
154 | "234": {
155 | "id": 234,
156 | "value": ""
157 | },
158 | "237": {
159 | "id": 237,
160 | "value": false
161 | },
162 | "240": {
163 | "id": 240,
164 | "name": "Arguments",
165 | "arguments": []
166 | },
167 | "247": {
168 | "id": 247,
169 | "value": null
170 | }
171 | }
172 | },
173 | "259": {
174 | "id": 259,
175 | "node_pos": [
176 | 1721,
177 | 166
178 | ],
179 | "node_type": 25,
180 | "attributes": {
181 | "253": {
182 | "id": 253
183 | },
184 | "256": {
185 | "id": 256,
186 | "value": ""
187 | }
188 | }
189 | },
190 | "294": {
191 | "id": 294,
192 | "node_pos": [
193 | 1273,
194 | 611
195 | ],
196 | "node_type": 11,
197 | "attributes": {
198 | "279": {
199 | "id": 279,
200 | "value": "halfValue"
201 | },
202 | "282": {
203 | "id": 282
204 | },
205 | "285": {
206 | "id": 285,
207 | "value": "2"
208 | },
209 | "288": {
210 | "id": 288,
211 | "value": false
212 | },
213 | "291": {
214 | "id": 291,
215 | "value": null
216 | }
217 | }
218 | }
219 | },
220 | "links": {
221 | "166": {
222 | "id": 166,
223 | "from_node": 144,
224 | "to_node": 165,
225 | "from_attribute": 141,
226 | "to_attribute": 146
227 | },
228 | "197": {
229 | "id": 197,
230 | "from_node": 165,
231 | "to_node": 196,
232 | "from_attribute": 149,
233 | "to_attribute": 174
234 | },
235 | "211": {
236 | "id": 211,
237 | "from_node": 196,
238 | "to_node": 210,
239 | "from_attribute": 190,
240 | "to_attribute": 199
241 | },
242 | "223": {
243 | "id": 223,
244 | "from_node": 210,
245 | "to_node": 222,
246 | "from_attribute": 202,
247 | "to_attribute": 213
248 | },
249 | "251": {
250 | "id": 251,
251 | "from_node": 196,
252 | "to_node": 250,
253 | "from_attribute": 177,
254 | "to_attribute": 225
255 | },
256 | "260": {
257 | "id": 260,
258 | "from_node": 250,
259 | "to_node": 259,
260 | "from_attribute": 228,
261 | "to_attribute": 253
262 | },
263 | "297": {
264 | "id": 297,
265 | "from_node": 294,
266 | "to_node": 222,
267 | "from_attribute": 291,
268 | "to_attribute": 219
269 | },
270 | "309": {
271 | "id": 309,
272 | "from_node": 210,
273 | "to_node": 294,
274 | "from_attribute": 205,
275 | "to_attribute": 279
276 | }
277 | }
278 | }
--------------------------------------------------------------------------------
/src/test.py:
--------------------------------------------------------------------------------
1 | # import dearpygui.dearpygui as dpg
2 | #
3 | # dpg.create_context()
4 | # dpg.create_viewport(title=f"Test - {dpg.get_dearpygui_version()}", width=500, height=400)
5 | #
6 | # dpg.setup_dearpygui()
7 | #
8 | # with dpg.window(pos=(0, 30), width=500, height=350):
9 | # dpg.add_button(label="Drag me!")
10 | # with dpg.drag_payload(parent=dpg.last_item()):
11 | # dpg.add_text("A new node")
12 | #
13 | # node_editor = dpg.generate_uuid()
14 | #
15 | # def on_drop():
16 | # pos = dpg.get_mouse_pos(local=False)
17 | # ref_node = dpg.get_item_children(node_editor, slot=1)[0]
18 | # ref_screen_pos = dpg.get_item_rect_min(ref_node)
19 | # ref_grid_pos = dpg.get_item_pos(ref_node)
20 | #
21 | # NODE_PADDING = (8, 8)
22 | #
23 | # pos[0] = pos[0] - (ref_screen_pos[0] - NODE_PADDING[0]) + ref_grid_pos[0]
24 | # pos[1] = pos[1] - (ref_screen_pos[1] - NODE_PADDING[1]) + ref_grid_pos[1]
25 | #
26 | # with dpg.node(label="New", pos=pos, parent=node_editor):
27 | # with dpg.node_attribute(attribute_type=dpg.mvNode_Attr_Static):
28 | # dpg.add_text(f"I'm a new node")
29 | # dpg.add_text(f"at {pos}!")
30 | #
31 | # with dpg.group(drop_callback=on_drop):
32 | # with dpg.node_editor(tag=node_editor,
33 | # minimap=True,
34 | # minimap_location=dpg.mvNodeMiniMap_Location_BottomRight):
35 | #
36 | # with dpg.node(label="A real node", pos=[50, 30]):
37 | # with dpg.node_attribute(attribute_type=dpg.mvNode_Attr_Static):
38 | # pass
39 | #
40 | #
41 | # dpg.show_viewport()
42 | # dpg.start_dearpygui()
43 | # dpg.destroy_context()
44 |
45 |
46 |
47 | # multiple_instructions_lambda = lambda x: (
48 | # print("Executing instruction 1..."),
49 | # print("The value of x is:", x),
50 | # print("Executing instruction 2..."),
51 | # x * 2
52 | # )
53 | #
54 | # result = multiple_instructions_lambda(5)
55 | # print("Result:", result)
56 | #
57 |
58 |
59 | import dearpygui.dearpygui as dpg
60 | import random
61 | import math
62 |
63 |
64 | def create_drawing_layers():
65 | dpg.add_viewport_drawlist(tag='layer_00', front=True)
66 | dpg.add_viewport_drawlist(tag='layer_01', front=True)
67 | dpg.add_viewport_drawlist(tag='layer_02', front=True)
68 | dpg.add_viewport_drawlist(tag='layer_03', front=True)
69 | dpg.add_viewport_drawlist(tag='layer_04', front=True)
70 | dpg.add_viewport_drawlist(tag='layer_05', front=True)
71 | dpg.add_viewport_drawlist(tag='layer_06', front=True)
72 | dpg.add_viewport_drawlist(tag='layer_07', front=True)
73 | dpg.add_viewport_drawlist(tag='layer_08', front=True)
74 | dpg.add_viewport_drawlist(tag='layer_09', front=True)
75 | dpg.add_viewport_drawlist(tag='layer_10', front=True)
76 | dpg.add_viewport_drawlist(tag='layer_11', front=True)
77 |
78 |
79 | def load_texture(file):
80 | with dpg.texture_registry():
81 | image_width, image_height, image_channels, image_buffer = dpg.load_image(file)
82 | return dpg.add_static_texture(image_width, image_height, image_buffer)
83 |
84 |
85 | def make_image(file, x_pos, y_pos, layer):
86 | with dpg.texture_registry():
87 | image_width, image_height, image_channels, image_buffer = dpg.load_image(file)
88 | texture = dpg.add_static_texture(image_width, image_height, image_buffer)
89 | dpg.draw_image(texture_tag=texture, pmin=(x_pos, y_pos), pmax=(x_pos + image_width, y_pos + image_height),
90 | parent=layer)
91 |
92 |
93 | def create_scene():
94 | make_image('assets/scene/trunk.png', 80, 530, 'layer_01')
95 | make_image('assets/scene/rock_4.png', 510, 540, 'layer_03')
96 | make_image('assets/scene/rock_2.png', -30, 510, 'layer_03')
97 | make_image('assets/scene/grass.png', 0, 495, 'layer_05')
98 | make_image('assets/scene/rock_6.png', 400, 590, 'layer_05')
99 | make_image('assets/scene/rock_3.png', 200, 610, 'layer_05')
100 | make_image('assets/flame/logs_small.png', 280, 615, 'layer_07')
101 | make_image('assets/scene/rock_1.png', 530, 600, 'layer_09')
102 | make_image('assets/scene/rock_5.png', 400, 620, 'layer_09')
103 | make_image('assets/scene/foreground.png', 0, 605, 'layer_10')
104 |
105 |
106 | class Raccoon:
107 |
108 | def __init__(self, x, y, start_frame, direction, textures, image_width, image_height, face_direction,
109 | flip_face_setting, left_boundary, right_boundary, boundary_variation, layer):
110 | self.x = x
111 | self.y = y + 200 - image_height
112 | self.x_start = x
113 | self.direction = direction
114 | self.flip_face_setting = flip_face_setting
115 | self.left_boundary = left_boundary
116 | self.right_boundary = right_boundary
117 | self.boundary_variation = boundary_variation
118 | self.temp_boundary = 1
119 | self.face_direction = face_direction
120 | self.layer = layer
121 | self.frame = start_frame
122 | self.num_frames = 14
123 | self.textures = textures
124 | self.image_width = image_width
125 | self.image_height = image_height
126 | if face_direction == 'right':
127 | self.raccoon = dpg.draw_image(texture_tag=self.textures['dance_right'][start_frame], pmin=(self.x, self.y),
128 | pmax=(self.image_width + self.x, self.image_height + self.y),
129 | parent=self.layer)
130 | else:
131 | self.raccoon = dpg.draw_image(texture_tag=self.textures['dance_left'][start_frame], pmin=(self.x, self.y),
132 | pmax=(self.image_width + self.x, self.image_height + self.y),
133 | parent=self.layer)
134 |
135 | def flip_face_direction(self):
136 | self.face_direction = 'right' if self.face_direction == 'left' else 'left'
137 |
138 | def dance(self):
139 | if self.frame < self.num_frames - 1:
140 | self.frame += 1
141 | else:
142 | self.frame = 0
143 | self.x += self.direction
144 | if (self.x > self.x_start + self.right_boundary + self.temp_boundary) or \
145 | (self.x < self.x_start - self.left_boundary - self.temp_boundary):
146 | self.direction = -self.direction
147 | self.temp_boundary = random.randint(0, self.boundary_variation)
148 | if self.flip_face_setting:
149 | self.flip_face_direction()
150 | if self.face_direction == 'right':
151 | dpg.configure_item(self.raccoon, texture_tag=self.textures['dance_right'][self.frame],
152 | pmin=(self.x, self.y), pmax=(self.image_width + self.x, self.image_height + self.y))
153 | else:
154 | dpg.configure_item(self.raccoon, texture_tag=self.textures['dance_left'][self.frame], pmin=(self.x, self.y),
155 | pmax=(self.image_width + self.x, self.image_height + self.y))
156 |
157 | def idle(self):
158 | if self.frame < 11 - 1:
159 | self.frame += 1
160 | else:
161 | self.frame = 0
162 | if self.face_direction == 'right':
163 | dpg.configure_item(self.raccoon, texture_tag=self.textures['idle_right'][self.frame], pmin=(self.x, self.y),
164 | pmax=(self.image_width + self.x, self.image_height + self.y))
165 | else:
166 | dpg.configure_item(self.raccoon, texture_tag=self.textures['idle_left'][self.frame], pmin=(self.x, self.y),
167 | pmax=(self.image_width + self.x, self.image_height + self.y))
168 |
169 |
170 | class Animation:
171 |
172 | def __init__(self, x, y, num_frames, textures, image_width, image_height, max_variation, layer):
173 | self.x = x
174 | self.y = y
175 | self.frame = 0
176 | self.num_frames = num_frames
177 | self.textures = textures
178 | self.image_width = image_width
179 | self.image_height = image_height
180 | self.max_variation = max_variation
181 | self.variation_step_speed = 5
182 | self.variation_current_step = 0
183 | self.current_variation = 0
184 | self.decrease_size = True
185 | self.layer = layer
186 | self.sprite = dpg.draw_image(texture_tag=self.textures[0], pmin=(self.x, self.y),
187 | pmax=(image_width + self.x, image_height + self.y), parent=self.layer)
188 |
189 | def update(self):
190 | if self.frame < self.num_frames - 1:
191 | self.frame += 1
192 | else:
193 | self.frame = 0
194 |
195 | if self.max_variation != 0:
196 |
197 | if self.variation_current_step >= self.variation_step_speed:
198 |
199 | self.variation_current_step = 0
200 |
201 | if self.decrease_size:
202 | self.current_variation += 1 # steps have to be integers to avoid visual artefacts
203 | else:
204 | self.current_variation -= 1
205 |
206 | if self.current_variation > self.max_variation:
207 | self.decrease_size = False
208 | elif self.current_variation < 0:
209 | self.decrease_size = True
210 | else:
211 | self.variation_current_step += 1
212 |
213 | dpg.configure_item(self.sprite, texture_tag=self.textures[self.frame],
214 | pmin=(self.x, self.y - self.current_variation),
215 | pmax=(self.image_width + self.x, self.image_height + self.y))
216 |
217 |
218 | class Particle:
219 |
220 | def __init__(self, x, y, horizontal_speed, starting_frame, num_frames, interval, textures, image_width,
221 | image_height, layer):
222 | self.step = 1
223 | self.x = x
224 | self.horizontal_speed = horizontal_speed
225 | self.y_base = y
226 | self.sin_variation = random.randint(0, 628) / 100
227 | self.y = y
228 | self.vertical_trend = 1
229 | self.frame = starting_frame
230 | self.num_frames = num_frames
231 | self.interval = interval
232 | self.textures = textures
233 | self.image_width = image_width
234 | self.image_height = image_height
235 | self.layer = layer
236 | self.sprite = dpg.draw_image(texture_tag=self.textures[0], pmin=(self.x, self.y),
237 | pmax=(image_width + self.x, image_height + self.y), parent=self.layer)
238 |
239 | def reset(self):
240 | self.x = -50 - random.randint(0, 1000)
241 | self.y = 445 + random.randint(0, 50) + self.x / 10
242 | self.vertical_trend = 1
243 | self.y_base = self.y
244 | self.step = 1
245 |
246 | def update(self):
247 | self.interval += 1 # interval determines how many update calls it takes to update a frame
248 | if self.interval == 60:
249 | self.interval = 0
250 | if self.frame < self.num_frames - 1:
251 | self.frame += 1
252 | else:
253 | self.frame = 0
254 | self.step += 0.00001
255 | self.x = self.x + self.horizontal_speed + math.sin(self.step) / 100
256 | self.y_base = self.y_base + (3.1 / self.vertical_trend)
257 | # vertical_trend reversely impacts the vertical speed. A smaller number means faster downward speed.
258 | self.vertical_trend += 0.085
259 | self.y = self.y_base + math.sin(self.x / 20 + self.sin_variation) * 3
260 | dpg.configure_item(self.sprite, texture_tag=self.textures[self.frame], pmin=(self.x, self.y),
261 | pmax=(self.image_width + self.x, self.image_height + self.y))
262 |
263 |
264 | def load_logo():
265 | with dpg.viewport_drawlist(front=True, tag='viewport_front'):
266 |
267 | dpg.draw_text(pos=(213, 4), tag='logo_raccoon', text='Raccoon', size=140, color=(217, 131, 46))
268 | dpg.bind_item_font(item='logo_raccoon', font='font3')
269 |
270 | dpg.draw_text(pos=(275, 110), tag='logo_musicplayer', text='M U S I C P L A Y E R', size=21,
271 | color=(95, 59, 35))
272 | dpg.bind_item_font(item='logo_musicplayer', font='font4')
273 | dpg.draw_rectangle(tag='logo_text_filter', color=(0, 0, 0, 0), fill=(0, 0, 0, 0),
274 | pmin=(50, 30), pmax=(510, 150))
275 | dpg.draw_rectangle(tag='leaves_button_filter', color=(0, 0, 0, 0), fill=(222, 0, 0, 0),
276 | pmin=(540, 0), pmax=(630, 70))
277 | make_image('assets/raccoon/raccoon_logo_face.png', 82, 35, 'layer_01')
278 |
279 |
280 | def load_textures(filepath, asset_name, image_type, number_of_assets):
281 | textures = []
282 | with dpg.texture_registry():
283 | for frame in range(number_of_assets):
284 | file = filepath + '/' + asset_name + '_' + str(frame) + '.' + image_type
285 | image_width, image_height, image_channels, image_buffer = dpg.load_image(file)
286 | texture = dpg.add_static_texture(image_width, image_height, image_buffer)
287 | textures.append(texture)
288 | return textures
--------------------------------------------------------------------------------
/src/LuaNodeAttributes.py:
--------------------------------------------------------------------------------
1 | import dearpygui.dearpygui as dpg
2 | import globals
3 | from globals import ind, inc_ind, dec_ind, Serializable
4 | from abc import ABC, abstractmethod
5 | from pprint import pprint
6 |
7 | from constants import *
8 |
9 | class NodeAttribute(Serializable):
10 | def __init__(self):
11 | from LuaNodes import LuaNode
12 |
13 | self.parent_node: LuaNode = None
14 | self.id = None
15 | self.stage = None
16 |
17 | def generate_code(self, color_coded=False):
18 | if not color_coded:
19 | return ""
20 | else:
21 | return [[]]
22 |
23 | def serialize(self):
24 | return {
25 | "id": self.id
26 | }
27 |
28 | def deserialize(self, obj):
29 | pass
30 |
31 |
32 | class NodeAttributeVariable(NodeAttribute):
33 | def __init__(self):
34 | super().__init__()
35 | self.multiline = False
36 |
37 | with dpg.stage() as self.stage:
38 | with dpg.node_attribute(shape=dpg.mvNode_PinShape_CircleFilled,
39 | attribute_type=dpg.mvNode_Attr_Output) as self.id:
40 | self.name = dpg.add_input_text(hint="Variable name", width=150)
41 | self.value = dpg.add_input_text(hint="Value", width=150)
42 | self.checkbox = dpg.add_checkbox(label="Multiline", callback=self.checked)
43 |
44 | def checked(self):
45 | self.multiline = not self.multiline
46 | dpg.configure_item(self.value, multiline=self.multiline)
47 |
48 | def generate_code(self, color_coded=False):
49 | if not color_coded:
50 | return f"{dpg.get_value(self.name)}"
51 | else:
52 | return [[dpg.get_value(self.name), (255, 0, 0)]]
53 |
54 | def serialize(self):
55 | return {
56 | **super().serialize(),
57 | "name": dpg.get_value(self.name),
58 | "value": dpg.get_value(self.value),
59 | "multiline": self.multiline
60 | }
61 |
62 | def deserialize(self, obj):
63 | dpg.configure_item(self.name, default_value=obj["name"])
64 | dpg.configure_item(self.value, default_value=obj["value"])
65 | self.multiline = obj["multiline"]
66 | dpg.configure_item(self.value, multiline=self.multiline)
67 | dpg.set_value(self.checkbox, self.multiline)
68 |
69 |
70 | class NodeAttributeMultipleExpressionOut(NodeAttribute):
71 | def __init__(self, name):
72 | super().__init__()
73 | self.attribute_type = NodeAttributeExpressionOut
74 | self.name = name
75 | self.value = None
76 | self.invisible_static = None
77 | self.arguments = []
78 |
79 | with dpg.stage() as self.stage:
80 | with dpg.node_attribute(shape=dpg.mvNode_PinShape_CircleFilled,
81 | attribute_type=dpg.mvNode_Attr_Static) as self.id:
82 | with dpg.group(horizontal=True):
83 | self.name = dpg.add_text(name)
84 | dpg.add_button(label="+", callback=lambda: self.add_argument())
85 | dpg.add_button(label="-", callback=self.remove_argument)
86 | with dpg.node_attribute(shape=dpg.mvNode_PinShape_CircleFilled,
87 | attribute_type=dpg.mvNode_Attr_Static) as self.empty_static:
88 | pass
89 |
90 | def add_argument(self, hint=None, name=None):
91 | arg_name_hint = f"arg{len(self.arguments) + 1}" if hint is None else hint
92 | # new_arg: NodeAttributeExpressionOut = NodeAttributeExpressionOut(arg_name, simple=True)
93 | new_arg = self.attribute_type(arg_name_hint, simple=True, value=name)
94 | self.arguments.append(new_arg)
95 | dpg.move_item(new_arg.id, parent=self.parent_node.id, before=self.empty_static)
96 | dpg.delete_item(new_arg.stage)
97 | # TODO order matters for deserialization?
98 | self.parent_node.node_attributes.append(new_arg)
99 | # dpg.move_item(node_attribute.id, parent=self.id)
100 |
101 | def remove_argument(self):
102 | if len(self.arguments) == 0:
103 | return
104 | last_arg = self.arguments.pop()
105 | # TODO IMPORTANT check if attribute has connections and if so delete them
106 | dpg.delete_item(last_arg.id)
107 |
108 | def generate_code(self, color_coded=False):
109 | if not color_coded:
110 | return f"{dpg.get_value(self.name)}"
111 | else:
112 | return [[dpg.get_value(self.name), color_variable]]
113 |
114 | def serialize(self):
115 | return {
116 | **super().serialize(),
117 | "name": dpg.get_value(self.name),
118 | "arguments": [arg.serialize() for arg in self.arguments]
119 | }
120 |
121 | def deserialize(self, obj):
122 | dpg.configure_item(self.name, default_value=obj["name"])
123 | for arg in obj["arguments"]:
124 | # self.add_argument(arg["value"])
125 | self.add_argument(name=arg["value"])
126 |
127 |
128 | class NodeAttributeMultipleExpressionIn(NodeAttributeMultipleExpressionOut):
129 | def __init__(self, name):
130 | super().__init__(name)
131 | self.attribute_type = NodeAttributeExpressionIn
132 |
133 |
134 | class NodeAttributeMultipleTableEntry(NodeAttribute):
135 | def __init__(self):
136 | super().__init__()
137 | self.entries = []
138 |
139 | with dpg.stage() as self.stage:
140 | with dpg.node_attribute(shape=dpg.mvNode_PinShape_CircleFilled,
141 | attribute_type=dpg.mvNode_Attr_Static) as self.id:
142 | with dpg.group(horizontal=True):
143 | self.name = dpg.add_text("Entries")
144 | dpg.add_button(label="+", callback=lambda: self.add_argument())
145 | dpg.add_button(label="-", callback=self.remove_argument)
146 | with dpg.node_attribute(shape=dpg.mvNode_PinShape_CircleFilled,
147 | attribute_type=dpg.mvNode_Attr_Static) as self.empty_static:
148 | pass
149 |
150 | def add_argument(self, name=None, value=None):
151 | print(name, value)
152 | entry_name_hint = f"name{len(self.entries) + 1}" if name is None else name
153 | entry_value_hint = f"value{len(self.entries) + 1}" if value is None else value
154 | # new_arg: NodeAttributeExpressionOut = NodeAttributeExpressionOut(arg_name, simple=True)
155 | new_entry = NodeAttributeTableEntry(entry_name_hint, entry_value_hint)
156 | self.entries.append(new_entry)
157 | dpg.move_item(new_entry.name.id, parent=self.parent_node.id, before=self.empty_static)
158 | dpg.move_item(new_entry.value.id, parent=self.parent_node.id, before=self.empty_static)
159 | dpg.delete_item(new_entry.name.stage)
160 | dpg.delete_item(new_entry.value.stage)
161 | # TODO order matters for deserialization?
162 | self.parent_node.node_attributes.append(new_entry.name)
163 | self.parent_node.node_attributes.append(new_entry.value)
164 |
165 | def remove_argument(self):
166 | if len(self.entries) == 0:
167 | return
168 | last_arg = self.entries.pop()
169 | # TODO IMPORTANT check if attribute has connections and if so delete them
170 | dpg.delete_item(last_arg.name.id)
171 | dpg.delete_item(last_arg.value.id)
172 |
173 | def generate_code(self, color_coded=False):
174 | table_value_code = f"{{\n"
175 | inc_ind()
176 | for entry in self.entries:
177 | table_value_code += f"{ind()}{entry.generate_code()},\n"
178 | dec_ind()
179 | table_value_code += f"{ind()}}}"
180 |
181 |
182 | table_value_code_colored = []
183 | table_value_code_colored += [
184 | ["{{", color_default],
185 | ["\n"]
186 | ]
187 | inc_ind()
188 | for entry in self.entries:
189 | table_value_code_colored += [
190 | [ind()]
191 | ] + entry.generate_code(color_coded=True) + [
192 | [",", color_default],
193 | ["\n"]
194 | ]
195 | dec_ind()
196 | table_value_code_colored += [
197 | [ind()],
198 | ["}}", color_default]
199 | ]
200 |
201 | if not color_coded:
202 | return table_value_code
203 | return table_value_code_colored
204 |
205 | def serialize(self):
206 |
207 | return {
208 | **super().serialize(),
209 | "entries": [arg.serialize() for arg in self.entries]
210 | }
211 |
212 | def deserialize(self, obj):
213 | for arg in obj["entries"]:
214 | self.add_argument(arg["name"]["value"], arg["value"]["value"])
215 |
216 |
217 | class NodeAttributeTableEntry(NodeAttribute):
218 | def __init__(self, name, value):
219 | super().__init__()
220 | self.name = NodeAttributeExpressionOut(name, simple=True)
221 | self.value = NodeAttributeExpressionIn(value)
222 |
223 | def generate_code(self, color_coded=False):
224 | name_code = self.name.generate_code()
225 | value_code = self.value.generate_code()
226 |
227 | name_code_colored = self.name.generate_code(True)
228 | value_code_colored = self.value.generate_code(True)
229 |
230 | if name_code != "":
231 | if not color_coded:
232 | return f"{name_code} = {value_code}"
233 | return name_code_colored + [
234 | [" = ", color_math_operator],
235 | ] + value_code_colored
236 |
237 | if not color_coded:
238 | return value_code
239 | return value_code_colored
240 |
241 | def serialize(self):
242 | return {
243 | **super().serialize(),
244 | "name": self.name.serialize(),
245 | "value": self.value.serialize()
246 | }
247 |
248 | def deserialize(self, obj):
249 | dpg.set_value(self.name.value, obj["name"])
250 | dpg.set_value(self.value.value, obj["value"])
251 |
252 |
253 | class NodeAttributeExpressionOut(NodeAttribute):
254 | def __init__(self, hint="", simple=False, value=None):
255 | super().__init__()
256 | self.value = None
257 | self.simple = simple
258 |
259 | with dpg.stage() as self.stage:
260 | with dpg.node_attribute(shape=dpg.mvNode_PinShape_CircleFilled,
261 | attribute_type=dpg.mvNode_Attr_Output) as self.id:
262 | if simple:
263 | self.value = dpg.add_input_text(hint=hint, width=150)
264 | if value:
265 | dpg.set_value(self.value, value)
266 | else:
267 | dpg.add_text(hint)
268 |
269 | def generate_code(self, color_coded=False):
270 | # if not simple, we let the parent node decide what the code is for this
271 | if not self.simple:
272 | if self.parent_node:
273 | if not color_coded:
274 | return self.parent_node.generate_code()
275 | return self.parent_node.generate_code(color_coded=True)
276 |
277 | if not color_coded:
278 | return ""
279 | return [[]]
280 |
281 | if not color_coded:
282 | return dpg.get_value(self.value)
283 | else:
284 | return [
285 | [dpg.get_value(self.value), ]
286 | ]
287 |
288 | def serialize(self):
289 | return {
290 | **super().serialize(),
291 | "value": dpg.get_value(self.value)
292 | }
293 |
294 | def deserialize(self, obj):
295 | if obj["value"]:
296 | dpg.configure_item(self.value, default_value=obj["value"])
297 |
298 |
299 | class NodeAttributeExpressionIn(NodeAttribute):
300 | def __init__(self, hint="", simple=None, value=None):
301 | super().__init__()
302 | self.value = None
303 |
304 | with dpg.stage() as self.stage:
305 | with dpg.node_attribute(shape=dpg.mvNode_PinShape_CircleFilled,
306 | attribute_type=dpg.mvNode_Attr_Input) as self.id:
307 | self.value = dpg.add_input_text(hint=hint, width=150)
308 | if value:
309 | dpg.set_value(self.value, value)
310 |
311 | def generate_code(self, color_coded=False):
312 | # need to find the nodeAttribute object this is referring to
313 | expression_out = globals.get_out_node_attribute_from_in_node_attribute(self.id)
314 | if expression_out:
315 | if not color_coded:
316 | return expression_out.generate_code()
317 | return expression_out.generate_code(color_coded=True)
318 |
319 | if not color_coded:
320 | return dpg.get_value(self.value)
321 | return [[dpg.get_value(self.value), color_immediate_value]]
322 |
323 | def serialize(self):
324 | return {
325 | **super().serialize(),
326 | "value": dpg.get_value(self.value)
327 | }
328 |
329 | def deserialize(self, obj):
330 | dpg.configure_item(self.value, default_value=obj["value"])
331 |
332 |
333 | class NodeAttributeStaticText(NodeAttribute):
334 | def __init__(self, name):
335 | super().__init__()
336 | self.value = None
337 |
338 | with dpg.stage() as self.stage:
339 | with dpg.node_attribute(attribute_type=dpg.mvNode_Attr_Static) as self.id:
340 | self.value = dpg.add_text(name)
341 |
342 |
343 | class NodeAttributeStaticInputText(NodeAttribute):
344 | def __init__(self, name):
345 | super().__init__()
346 | self.value = None
347 |
348 | with dpg.stage() as self.stage:
349 | with dpg.node_attribute(attribute_type=dpg.mvNode_Attr_Static) as self.id:
350 | self.value = dpg.add_input_text(hint=name, width=150)
351 |
352 | def generate_code(self, color_coded=False):
353 | if not color_coded:
354 | return dpg.get_value(self.value)
355 | return [[dpg.get_value(self.value), (0, 255, 0)]]
356 |
357 | def serialize(self):
358 | return {
359 | **super().serialize(),
360 | "value": dpg.get_value(self.value)
361 | }
362 |
363 | def deserialize(self, obj):
364 | dpg.configure_item(self.value, default_value=obj["value"])
365 |
366 |
367 | class NodeAttributeExecuteIn(NodeAttribute):
368 | def __init__(self, text="Flow in"):
369 | super().__init__()
370 |
371 | with dpg.stage() as self.stage:
372 | with dpg.node_attribute(shape=dpg.mvNode_PinShape_Triangle,
373 | attribute_type=dpg.mvNode_Attr_Input) as self.id:
374 | dpg.add_text(text)
375 |
376 | def generate_code(self, color_coded=False):
377 | # execute parent node code
378 | if not color_coded:
379 | return self.parent_node.generate_code()
380 | else:
381 | return self.parent_node.generate_code(color_coded=True)
382 |
383 | def serialize(self):
384 | return {
385 | **super().serialize(),
386 | }
387 |
388 | def deserialize(self, obj):
389 | pass
390 |
391 |
392 | class NodeAttributeExecuteOut(NodeAttribute):
393 | def __init__(self, text="Flow out"):
394 | super().__init__()
395 |
396 | with dpg.stage() as self.stage:
397 | with dpg.node_attribute(shape=dpg.mvNode_PinShape_Triangle, attribute_type=dpg.mvNode_Attr_Output,
398 | indent=100) as self.id:
399 | dpg.add_text(text)
400 |
401 | def generate_code(self, color_coded=False):
402 | expression_in = globals.get_in_node_attribute_from_out_node_attribute(self.id)
403 | if expression_in:
404 | if not color_coded:
405 | return expression_in.generate_code()
406 | return expression_in.generate_code(color_coded=True)
407 | if not color_coded:
408 | return ""
409 | return [[]]
410 |
411 | def serialize(self):
412 | return {
413 | **super().serialize(),
414 | }
415 |
416 | def deserialize(self, obj):
417 | pass
418 |
419 |
420 | class NodeAttributeCheckbox(NodeAttribute):
421 | def __init__(self, name):
422 | super().__init__()
423 | self.checkbox = None
424 |
425 | with dpg.stage() as self.stage:
426 | with dpg.node_attribute(attribute_type=dpg.mvNode_Attr_Static) as self.id:
427 | self.checkbox = dpg.add_checkbox(label=name)
428 |
429 | def serialize(self):
430 | return {
431 | **super().serialize(),
432 | "value": dpg.get_value(self.checkbox)
433 | }
434 |
435 | def deserialize(self, obj):
436 | dpg.configure_item(self.checkbox, default_value=obj["value"])
437 |
438 |
439 | class NodeAttributeInlineDeclarationOut(NodeAttribute):
440 | def __init__(self):
441 | super().__init__()
442 |
443 | with dpg.stage() as self.stage:
444 | with dpg.node_attribute(attribute_type=dpg.mvNode_Attr_Output) as self.id:
445 | dpg.add_text("Inline declaration")
446 |
447 | def generate_code(self, color_coded=False):
448 | if not color_coded:
449 | return self.parent_node.generate_code(inline=True)
450 | return self.parent_node.generate_code(color_coded=True)
451 |
452 |
453 | class NodeAttributeCustomCallerOut(NodeAttribute):
454 | def __init__(self, name="Value", callback=None, params=None):
455 | super().__init__()
456 | self.name = name
457 | self.callback = callback
458 | self.params = params
459 |
460 | with dpg.stage() as self.stage:
461 | with dpg.node_attribute(shape=dpg.mvNode_PinShape_CircleFilled,
462 | attribute_type=dpg.mvNode_Attr_Output) as self.id:
463 | dpg.add_text(name)
464 |
465 | def generate_code(self, color_coded):
466 | return self.callback(self.params, color_coded=color_coded)
--------------------------------------------------------------------------------
/src/main.py:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright © 2023, SanForge Studio & Lua Node Editor, All Rights Reserved.
3 | # Licensed under the GNU General Public 3.0 License
4 | #
5 |
6 | import os
7 |
8 | import dearpygui.dearpygui as dpg
9 | from pprint import pprint
10 | import threading
11 |
12 | from lupa.lua54 import LuaRuntime
13 |
14 | import sys
15 | from io import StringIO
16 |
17 | import themes
18 | from LuaNodes import *
19 | import pyperclip as pc
20 | import json
21 |
22 | import tkinter as tk
23 | from PIL import Image, ImageTk
24 |
25 | def show_splash_screen():
26 | splash_root = tk.Tk()
27 | splash_root.overrideredirect(True)
28 | screen_width = splash_root.winfo_screenwidth()
29 | screen_height = splash_root.winfo_screenheight()
30 | center_x = int((screen_width - 600) / 2)
31 | center_y = int((screen_height - 200) / 2)
32 | splash_root.geometry(f"600x200+{center_x}+{center_y}")
33 |
34 | image_path = "assets/images/splash.png" # Remove Source/ if it cant find the image
35 | original_image = Image.open(image_path)
36 | desired_width = 600
37 | desired_height = 200
38 | resized_image = original_image.resize((desired_width, desired_height))
39 | resized_photo = ImageTk.PhotoImage(resized_image)
40 |
41 | resized_label = tk.Label(splash_root, image=resized_photo)
42 | resized_label.image = resized_photo
43 | resized_label.pack()
44 |
45 | splash_root.after(3000, splash_root.destroy)
46 |
47 | splash_root.mainloop()
48 |
49 | if __name__ == "__main__":
50 | show_splash_screen()
51 | dpg.create_context()
52 | dpg.configure_app(manual_callback_management=True)
53 | dpg.configure_app(init_file="settings.ini")
54 | dpg.create_viewport(title='Lua Node Editor', width=1200, height=800, small_icon="assets/images/icon.ico", large_icon="assets/images/icon.ico")
55 |
56 | # Variable list
57 | hasGeneratingCodeBeenLogged = False
58 | hasCopyCodeBeenLogged = False
59 | isCodeGenerated = False
60 | isNodeLibraryVisible = True
61 |
62 | def save_init():
63 | dpg.save_init_file("settings.ini")
64 |
65 | def call_threaded(function, args):
66 | my_thread = threading.Thread(target=function, args=args)
67 | my_thread.start()
68 |
69 | # callback runs when user attempts to connect attributes
70 | def link_callback(sender, app_data):
71 | # check for no other link to have the same end
72 | for l in globals.links:
73 | if l.to_attribute == app_data[1]:
74 | call_threaded(add_log, ("Can't have multiple inputs", ))
75 | add_log("Can't have multiple inputs")
76 | return
77 |
78 | id = dpg.add_node_link(app_data[0], app_data[1], parent=sender)
79 |
80 | from_node = dpg.get_item_parent(app_data[0])
81 | to_node = dpg.get_item_parent(app_data[1])
82 |
83 | globals.links += [Link(id, from_node, to_node, app_data[0], app_data[1])]
84 |
85 |
86 | # callback runs when user attempts to disconnect attributes
87 | def delink_callback(sender, app_data):
88 | # app_data -> link_id
89 | dpg.delete_item(app_data)
90 | globals.links = list(filter(lambda l: l.id != app_data, globals.links))
91 |
92 |
93 | def get_mouse_pos_relative_to(item):
94 | item_min_rect = dpg.get_item_state(item)["rect_min"]
95 | mouse_pos = dpg.get_mouse_pos(local=False)
96 |
97 | return [mouse_pos[0] - item_min_rect[0], mouse_pos[1] - item_min_rect[1]]
98 |
99 |
100 | def get_mouse_pos_in_node_editor():
101 | ref_node_rect_min = dpg.get_item_state("reference_node")["rect_min"]
102 |
103 | node_editor_rect_min = dpg.get_item_state("node_editor_container")["rect_min"]
104 | ref_node_rect_min = [ref_node_rect_min[0] - node_editor_rect_min[0], ref_node_rect_min[1] - node_editor_rect_min[1]]
105 |
106 | local_mouse_pos = get_mouse_pos_relative_to("node_editor_container")
107 | return [local_mouse_pos[0] - ref_node_rect_min[0], local_mouse_pos[1] - ref_node_rect_min[1]]
108 |
109 |
110 | def get_starting_node():
111 | for node in globals.nodes:
112 | if isinstance(node, LuaStartNode):
113 | return node
114 | return None
115 |
116 |
117 | def add_log(log_message):
118 | with dpg.stage() as stage:
119 | text_added = dpg.add_text(log_message, tracked=True, track_offset=1)
120 |
121 | dpg.push_container_stack("log_container")
122 | dpg.unstage(stage)
123 | dpg.pop_container_stack()
124 | dpg.delete_item(stage)
125 |
126 | dpg.split_frame(delay=1)
127 | dpg.configure_item(text_added, tracked=False)
128 |
129 | def show_modal(window_title, modal_message, ok_callback=None, show_cancel=False, cancel_callback=None):
130 | dpg.delete_item("modal")
131 | # with dpg.stage() as modal_stage:
132 | # modal window
133 | with dpg.window(modal=True, no_move=False, show=True,
134 | pos=[9999, 9999],
135 | no_resize=True, tag="modal", min_size=[0, 0]):
136 | dpg.add_text("", tag="modal_text")
137 | dpg.add_spacer()
138 | with dpg.group(horizontal=True):
139 | dpg.add_button(label="Ok", callback=default_modal_callback, tag="modal_ok")
140 | dpg.add_button(label="Cancel", show=False, tag="modal_cancel")
141 |
142 | dpg.configure_item("modal", label=window_title)
143 | dpg.configure_item("modal_text", default_value=modal_message)
144 |
145 | dpg.configure_item("modal_cancel", show=show_cancel)
146 | dpg.configure_item("modal_ok", callback=default_modal_callback if ok_callback is None else ok_callback)
147 |
148 | if show_cancel:
149 | dpg.configure_item("modal_cancel", callback=cancel_callback)
150 |
151 | def test():
152 | dpg.split_frame(delay=1)
153 |
154 | w = dpg.get_item_width("modal")
155 | h = dpg.get_item_height("modal")
156 | print(w, h)
157 | dpg.configure_item("modal", pos=[dpg.get_viewport_width() // 2 - w/2, dpg.get_viewport_height() // 2 - h/2])
158 |
159 | call_threaded(test, ())
160 | # dpg.delete_item(modal_stage)
161 |
162 |
163 | def show_help_modal():
164 | help_text = f'''
165 | Copyright © 2023, SanForge Studio & Lua Node Editor, All Rights Reserved.
166 | Licensed under the GNU General Public 3.0 License
167 |
168 | Interface Navigation: 1. Panning the View: Middle Mouse Button: Hold down the middle mouse button and move the
169 | mouse to pan the view across the editor canvas. 2. Selecting Nodes and Links: Click and Drag: Select multiple
170 | nodes and links by clicking and dragging a selection box around them. Clear Selection: Click outside of the
171 | selected area to clear the current selection. 3. Connecting Nodes: Drag to Connect: To establish connections
172 | between nodes, click on a pin of one node and drag to the pin of another. Release the mouse button to create a
173 | connection. 4. Disconnecting Nodes: Control + Drag: To disconnect a pin, hold down the Control key and drag the
174 | pin away from its connected node. 5. Node Creation: Right-Click: Open the context menu by right-clicking on the
175 | editor window. Select 'Create New Node' to add a new node to your workflow.
176 |
177 | File Management:
178 | 1. Creating a New File:
179 | Shortcut: Press File + New to create a new file.
180 | 2. Saving Your Work:
181 | Shortcut: Press File + Save As to save your current work. Specify a file name and location.
182 | 3. Loading a Previous File:
183 | Shortcut: Press File + Load to open a previously saved file.
184 |
185 | Code Generation:
186 | 1. Generating Code:
187 | Click 'Generate Code': Once you've designed your node network, click the 'Generate Code' button to automatically generate the corresponding code.
188 | 2. Copy Code:
189 | Click 'Copy Code': Once you've generated your node network and what to copy the code.
190 | '''
191 | show_modal("Help", help_text)
192 |
193 | pass
194 |
195 | def generate_code(color_coded=False):
196 | code = ""
197 | if color_coded:
198 | code = []
199 |
200 | # add variable declaration code
201 | # Variables
202 | global hasGeneratingCodeBeenLogged
203 | global hasCopyCodeBeenLogged
204 | global isCodeGenerated
205 | for node in globals.nodes:
206 | if isinstance(node, LuaVariableNode) or isinstance(node, LuaTable):
207 | # if isinstance(node, LuaVariableNode):
208 | if not node.has_from_node():
209 | code += node.generate_code(color_coded)
210 |
211 | # add global functions code
212 | for node in globals.nodes:
213 | if isinstance(node, LuaNodeFunction):
214 | if not node.has_from_node() and not node.is_inline():
215 | code += node.generate_code(color_coded)
216 |
217 | start_node = get_starting_node()
218 | if start_node is None:
219 | show_modal("Warning", "Start node not found! Please add nodes.")
220 | isCodeGenerated = False
221 | if not hasGeneratingCodeBeenLogged:
222 | call_threaded(add_log, ("Please add a starting node for proper code generation",))
223 | hasGeneratingCodeBeenLogged = True
224 | hasCopyCodeBeenLogged = False
225 | else:
226 | code += start_node.generate_code(color_coded)
227 | isCodeGenerated = True
228 |
229 | if not color_coded:
230 | dpg.configure_item("generated_code", default_value=code)
231 |
232 | if color_coded:
233 | dpg.delete_item("generated_code_group", children_only=True)
234 |
235 | code: []
236 |
237 | code += [["\n"]]
238 |
239 | with dpg.stage() as horizontal_group_stage:
240 | horizontal_group = dpg.add_group(horizontal=True)
241 | for entry in code:
242 | if len(entry) == 0:
243 | continue
244 | if len(entry) == 1 and entry[0] == '\n':
245 | # create new horizontal group
246 | dpg.move_item(horizontal_group, parent="generated_code_group")
247 | dpg.delete_item(horizontal_group_stage)
248 |
249 | with dpg.stage() as horizontal_group_stage:
250 | horizontal_group = dpg.add_group(horizontal=True)
251 | elif len(entry) >= 1:
252 | text = entry[0]
253 | color = entry[1] if len(entry) >= 2 else (255, 255, 255)
254 |
255 | with dpg.stage() as text_widget_stage:
256 | new_text = dpg.add_text(default_value=text, color=color)
257 |
258 | dpg.move_item(new_text, parent=horizontal_group)
259 | dpg.delete_item(text_widget_stage)
260 |
261 | dpg.delete_item(horizontal_group_stage)
262 |
263 |
264 | def copy_code():
265 | # Variables
266 | global hasGeneratingCodeBeenLogged
267 | global hasCopyCodeBeenLogged
268 | global isCodeGenerated
269 |
270 | if not isCodeGenerated:
271 | show_modal("Warning", "Generated code not found! Please generate code.")
272 | if not hasCopyCodeBeenLogged:
273 | call_threaded(add_log, ("Please generate code before copying the code.",))
274 | hasCopyCodeBeenLogged = True
275 | hasGeneratingCodeBeenLogged = False
276 | else:
277 | pc.copy(dpg.get_value("generated_code"))
278 |
279 |
280 | def call_external_function_and_get_output(function_name, code):
281 | # Construct the command to call the external script with the function name and arguments
282 | # command = ['python', 'lua_execute.py', function_name, code]
283 | command = ['python', 'lua_execute.py', function_name, code]
284 |
285 | import subprocess
286 | # Run the external script and capture its output
287 | print(f"executing {command}")
288 | result = subprocess.run(command, capture_output=True, text=True, check=True)
289 |
290 | # Check if the command was successful
291 | if result.returncode == 0:
292 | # Access the output from the result object
293 | captured_output = result.stdout
294 | # Now you can do whatever you want with the captured output
295 | return captured_output
296 | else:
297 | call_threaded(add_log, ("Error executing the external script.",))
298 | return None
299 |
300 | def run_code():
301 | code = dpg.get_value("generated_code")
302 | # print(code)
303 | try:
304 | # res = call_external_function_and_get_output("execute", code)
305 | res = call_external_function_and_get_output("execute", code)
306 | call_threaded(add_log, (res,))
307 | except Exception as e:
308 | # print("rip")
309 | call_threaded(add_log, ("Error executing code", ))
310 |
311 | def delete_selected_nodes():
312 | selected_nodes = dpg.get_selected_nodes("node_editor")
313 | globals.nodes = list(filter(lambda n: n.id not in selected_nodes, globals.nodes))
314 |
315 | # ref_node = dpg.get_item_label(node)
316 | for node in selected_nodes:
317 | if dpg.get_item_label(node) == dpg.get_item_label("reference_node"):
318 | continue
319 | dpg.delete_item(node)
320 | # dpg.delete_item(node)
321 |
322 | # delete links that are left hanging
323 | node_ids = [node.id for node in globals.nodes]
324 | globals.links = list(filter(lambda l: l.from_node in node_ids and l.to_node in node_ids, globals.links))
325 |
326 |
327 | def create_node(node_type):
328 | node: LuaNode = create_node_of_type(node_type)
329 |
330 | if node:
331 | node.submit("node_editor")
332 | dpg.configure_item(node.id, pos=get_mouse_pos_in_node_editor())
333 | globals.nodes.append(node)
334 | themes.apply_theme(node)
335 |
336 | dpg.configure_item("menu_create_node", show=False)
337 |
338 |
339 | def right_click_callback(sender, app_data, user_data):
340 | if dpg.is_item_hovered("node_editor"):
341 | dpg.configure_item("menu_create_node", show=True, pos=dpg.get_mouse_pos(local=False))
342 | dpg.focus_item("menu_input_create_node")
343 | dpg.set_value("menu_input_create_node", "")
344 | dpg.set_value("node_search_filter", "")
345 |
346 |
347 | def key_press_callback(s, key):
348 | if key == dpg.mvKey_Delete:
349 | delete_selected_nodes()
350 | elif key == dpg.mvKey_T:
351 | print(globals.nodes)
352 | print(globals.links)
353 | # for child in dpg.get_item_children("node_search_filter", slot=1):
354 | # print(dpg.get_item_state(child))
355 |
356 | elif dpg.is_key_down(dpg.mvKey_Control):
357 | if key == dpg.mvKey_1:
358 | dpg.show_item_registry()
359 | if key == dpg.mvKey_2:
360 | dpg.show_style_editor()
361 | elif key == dpg.mvKey_S:
362 | open_save_dialog()
363 | elif key == dpg.mvKey_L:
364 | open_load_dialog()
365 |
366 | def open_save_dialog():
367 | create_folder_if_not_exists("save_files")
368 | dpg.show_item("save_dialog")
369 |
370 | def open_load_dialog():
371 | create_folder_if_not_exists("save_files")
372 | dpg.show_item("load_dialog")
373 |
374 | def create_folder_if_not_exists(folder_path):
375 | if not os.path.exists(folder_path):
376 | try:
377 | os.makedirs(folder_path)
378 | print(f"Folder '{folder_path}' created successfully.")
379 | except OSError as e:
380 | print(f"Error creating folder '{folder_path}': {e}")
381 | else:
382 | print(f"Folder '{folder_path}' already exists.")
383 |
384 |
385 | def is_editor_empty():
386 | return globals.links == [] and globals.nodes == []
387 |
388 |
389 | def menu_pressed_new_file():
390 | # already empty, do nothing
391 | if is_editor_empty():
392 | return
393 |
394 | def clear_editor_and_hide_modal():
395 | reset_node_editor()
396 | default_modal_callback()
397 |
398 | show_modal("You are trying to create a new board", "All nodes will be erased. Continue?",
399 | ok_callback=clear_editor_and_hide_modal, show_cancel=True, cancel_callback=default_modal_callback)
400 |
401 |
402 | def reset_node_editor():
403 | globals.nodes = []
404 | globals.links = []
405 | children = dpg.get_item_children("node_editor", slot=1)
406 | for child in children:
407 | # avoid deleting the reference node
408 | if dpg.get_item_label(child) == dpg.get_item_label("reference_node"):
409 | continue
410 | # delete twice cuz it doesnt work otherwise
411 | dpg.delete_item(child)
412 |
413 |
414 | def save(file_path):
415 | with open(file_path, 'w') as save_file:
416 | json_obj = {
417 | "nodes": {},
418 | "links": {}
419 | }
420 |
421 | nod: LuaNode
422 | for node in globals.nodes:
423 | json_obj["nodes"][node.id] = node.serialize()
424 | link: Link
425 | for link in globals.links:
426 | json_obj["links"][link.id] = link.serialize()
427 |
428 | json_string = json.dumps(json_obj, indent=2)
429 | save_file.write(json_string)
430 |
431 |
432 | def load(file_path):
433 | # try:
434 | with open(file_path, 'r') as file:
435 | # Do something with the file, e.g., read its content
436 | json_string = file.read()
437 |
438 | data = json.loads(json_string)
439 | # after conversion to object was successful, reset node editor in order to populate again
440 | reset_node_editor()
441 |
442 | new_node_data = {}
443 | for node_id, node_data in data["nodes"].items():
444 | # try:
445 | new_node: LuaNode = create_node_of_type(node_data["node_type"])
446 | new_node.submit("node_editor")
447 |
448 | new_node.deserialize(node_data)
449 | new_node_data[node_id] = {
450 | "new_id": new_node.id,
451 | "new_attributes": dict(
452 | zip(list(node_data["attributes"].keys()), [attr.id for attr in new_node.node_attributes]))
453 | }
454 | globals.nodes.append(new_node)
455 | themes.apply_theme(new_node)
456 |
457 | # except:
458 | # pass
459 |
460 | for link_id, link_data in data["links"].items():
461 | # try:
462 | from_node = new_node_data[str(link_data["from_node"])]["new_id"]
463 | to_node = new_node_data[str(link_data["to_node"])]["new_id"]
464 | from_attribute = new_node_data[str(link_data["from_node"])]["new_attributes"][
465 | str(link_data["from_attribute"])]
466 | to_attribute = new_node_data[str(link_data["to_node"])]["new_attributes"][str(link_data["to_attribute"])]
467 |
468 | new_link_id = dpg.add_node_link(from_attribute, to_attribute, parent="node_editor")
469 | new_link = Link(new_link_id, from_node, to_node, from_attribute, to_attribute)
470 |
471 | globals.links.append(new_link)
472 | # except:
473 | # pass
474 |
475 | dpg.clear_selected_nodes("node_editor")
476 | dpg.clear_selected_links("node_editor")
477 |
478 | # except:
479 | # dpg.split_frame(delay=1)
480 | # show_modal("Error", "Something went wrong!")
481 |
482 |
483 | with dpg.handler_registry():
484 | dpg.add_mouse_click_handler(button=dpg.mvMouseButton_Right, callback=right_click_callback)
485 | dpg.add_key_press_handler(callback=key_press_callback)
486 |
487 | with dpg.theme() as reference_node_theme:
488 | with dpg.theme_component(dpg.mvAll):
489 | # make it invisible in the node editor
490 | dpg.add_theme_color(dpg.mvNodeCol_NodeBackground, (255, 0, 0, 0), category=dpg.mvThemeCat_Nodes)
491 | dpg.add_theme_color(dpg.mvNodeCol_NodeBackgroundHovered, (255, 0, 0, 0), category=dpg.mvThemeCat_Nodes)
492 | dpg.add_theme_color(dpg.mvNodeCol_NodeBackgroundSelected, (255, 0, 0, 0), category=dpg.mvThemeCat_Nodes)
493 | dpg.add_theme_color(dpg.mvNodeCol_NodeOutline, (255, 0, 0, 0), category=dpg.mvThemeCat_Nodes)
494 | dpg.add_theme_color(dpg.mvNodeCol_TitleBar, (255, 0, 0, 0), category=dpg.mvThemeCat_Nodes)
495 | dpg.add_theme_color(dpg.mvNodeCol_TitleBarHovered, (255, 0, 0, 0), category=dpg.mvThemeCat_Nodes)
496 | dpg.add_theme_color(dpg.mvNodeCol_TitleBarSelected, (255, 0, 0, 0), category=dpg.mvThemeCat_Nodes)
497 |
498 | # make it tiny in the node editor
499 | dpg.add_theme_style(dpg.mvNodeStyleVar_NodePadding, 1, 0, category=dpg.mvThemeCat_Nodes)
500 |
501 | themes.init_themes()
502 |
503 | with dpg.theme() as generated_code_theme:
504 | with dpg.theme_component(dpg.mvAll):
505 | dpg.add_theme_style(dpg.mvStyleVar_ItemSpacing, 0, 0, category=dpg.mvThemeCat_Core)
506 |
507 | def load_file_callback(sender, app_data):
508 | path = list(app_data["selections"].values())[0]
509 | load(path)
510 |
511 |
512 | def save_file_callback(sender, app_data):
513 | path = None
514 | if len(app_data["selections"]) == 0:
515 | print(app_data)
516 | path = app_data["file_path_name"]
517 | else:
518 | path = list(app_data["selections"].values())[0]
519 | print(path)
520 | save(path)
521 |
522 | def toggle_node_library():
523 | global isNodeLibraryVisible
524 | isNodeLibraryVisible = not isNodeLibraryVisible
525 |
526 | if isNodeLibraryVisible:
527 | dpg.show_item("node_library")
528 | else:
529 | dpg.hide_item("node_library")
530 |
531 | def file_dialog_cancel_callback(sender, app_data):
532 | pass
533 |
534 | def on_drop(s, a):
535 | create_node(a)
536 |
537 | with dpg.font_registry():
538 | # first argument ids the path to the .ttf or .otf file
539 | bold_font = dpg.add_font("assets/font/robotoBold.ttf", 18, tag="bold_roboto") # Remove Source\\ if it cant find the Font
540 | default_font = dpg.add_font("assets/font/roboto.ttf", 14, tag="roboto") # Remove Source\\ if it cant find the Font
541 |
542 | # file selector
543 | # load
544 | with dpg.file_dialog(
545 | directory_selector=False, show=False, callback=load_file_callback, tag="load_dialog",
546 | cancel_callback=file_dialog_cancel_callback, width=700, height=400, modal=True, default_path="save_files"):
547 | dpg.add_file_extension(".*")
548 | dpg.add_file_extension(".lvs", color=(0, 255, 0, 255), custom_text="[Lua Visual Script]")
549 |
550 | # save
551 | with dpg.file_dialog(
552 | directory_selector=False, show=False, callback=save_file_callback, tag="save_dialog",
553 | cancel_callback=file_dialog_cancel_callback, width=700, height=400, modal=True, default_path="save_files"):
554 | dpg.add_file_extension(".*")
555 | dpg.add_file_extension(".lvs", color=(0, 255, 0, 255), custom_text="[Lua Visual Script]")
556 |
557 | # create node window popup
558 | with dpg.window(label="Create node", show=False, tag="menu_create_node", no_title_bar=True, popup=True,
559 | no_move=True, max_size=(1000, 200)):
560 | dpg.add_input_text(hint="Search", tag="menu_input_create_node",
561 | callback=lambda s, a: dpg.set_value("node_search_filter", a))
562 | with dpg.group(horizontal=False):
563 | with dpg.filter_set(tag="node_search_filter"):
564 | # dpg.add_text("aaa1.c", filter_key="aaa1.c", bullet=True)
565 | for node_type, name in lua_ntNames.items():
566 | dpg.add_button(label=name, filter_key=str(name), user_data=node_type,
567 | callback=lambda s, a, u: create_node(u))
568 |
569 | # main window
570 | with dpg.window(tag="main_window") as main_win:
571 |
572 | with dpg.menu_bar():
573 | with dpg.menu(label="File"):
574 | dpg.add_menu_item(label="New", callback=lambda: menu_pressed_new_file())
575 | dpg.add_menu_item(label="Save as", callback=lambda: open_save_dialog())
576 | dpg.add_menu_item(label="Load", callback=lambda: open_load_dialog())
577 | with dpg.menu(label="Settings"):
578 | dpg.add_menu_item(label="Style editor", callback=lambda: dpg.show_style_editor())
579 | # dpg.add_menu_item(label="Save style", callback=lambda: save_init())
580 | dpg.add_menu_item(label="Help", callback=lambda: show_help_modal())
581 |
582 | with dpg.group(horizontal=True):
583 | dpg.add_button(tag="nodes_library_button", label="Nodes", callback=toggle_node_library)
584 |
585 | with dpg.child_window(tag="node_library", height=-1, width=150):
586 | # with dpg.group(tag="node_library", horizontal=False):
587 | for node_type, name in lua_ntNames.items():
588 | dpg.add_button(label=name)
589 | with dpg.drag_payload(parent=dpg.last_item(), drag_data=node_type, payload_type="node"):
590 | dpg.add_text(name)
591 |
592 |
593 | with dpg.group(tag="node_editor_container", payload_type="node", drop_callback=on_drop):
594 | # with dpg.child_window(tag="test_tag", width=-350):
595 | with dpg.node_editor(callback=link_callback, delink_callback=delink_callback, minimap=True,
596 | minimap_location=dpg.mvNodeMiniMap_Location_BottomRight,
597 | tag="node_editor", width=-350) as node_editor:
598 | with dpg.node(pos=(0, 0), label="", draggable=False, tag="reference_node"):
599 | pass
600 |
601 | # with dpg.node(label="Node 2", tag="node22"):
602 | # with dpg.node_attribute(label="Node A3"):
603 | # dpg.add_input_float(label="F3", width=200)
604 | #
605 | # with dpg.node_attribute(label="Node A4", attribute_type=dpg.mvNode_Attr_Output):
606 | # dpg.add_input_float(label="F4", width=200)
607 |
608 | code_output_text = False
609 |
610 | with dpg.group():
611 | with dpg.group(horizontal=True):
612 | # with dpg.child_window(tag="test_tag"):
613 | # if code_output_text:
614 | # dpg.add_button(label="Generate code", callback=lambda: generate_code())
615 | # else:
616 | # dpg.add_button(label="Generate code", callback=lambda: generate_code(True))
617 | dpg.add_button(label="Generate code", callback=lambda: (
618 | generate_code(),
619 | generate_code(True)
620 | ))
621 | dpg.add_button(label="Copy code", callback=lambda: copy_code())
622 | dpg.add_button(label="Run code", callback=lambda: run_code())
623 |
624 | with dpg.tab_bar():
625 | with dpg.tab(label="Generated"):
626 | with dpg.child_window(height=-200, width=350):
627 | with dpg.group(tag="generated_code_group"):
628 | pass
629 | dpg.bind_item_theme("generated_code_group", generated_code_theme)
630 | with dpg.tab(label="Editor"):
631 | dpg.add_input_text(height=-200, multiline=True, tag="generated_code", width=350)
632 |
633 | # if code_output_text:
634 | # else:
635 |
636 |
637 | with dpg.tab_bar():
638 | with dpg.tab(label="Log"):
639 | with dpg.child_window(height=-1, border=False, tag="log_container"):
640 | pass
641 |
642 | dpg.bind_font(default_font)
643 |
644 | # dpg.bind_item_handler_registry("node_editor", "node_editor_handler")
645 |
646 |
647 | def empty_func():
648 | pass
649 |
650 |
651 | def default_modal_callback():
652 | dpg.configure_item("modal", show=False)
653 |
654 |
655 | # hide reference node on first frame (actually cant do it because it wont have rect_min set properly)
656 | # dpg.set_frame_callback(frame=1, callback=lambda: dpg.hide_item("reference_node"))
657 | # so i just hide it instead
658 | dpg.bind_item_theme("reference_node", reference_node_theme)
659 |
660 | dpg.setup_dearpygui()
661 | dpg.show_viewport()
662 | dpg.set_primary_window(main_win, True)
663 |
664 | while dpg.is_dearpygui_running():
665 | jobs = dpg.get_callback_queue() # retrieves and clears queue
666 | dpg.run_callbacks(jobs)
667 |
668 | dpg.render_dearpygui_frame()
669 |
670 | # dpg.start_dearpygui()
671 | dpg.destroy_context()
672 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/src/LuaNodes.py:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright © 2023, SanForge Studio & Lua Node Editor, All Rights Reserved.
3 | # Licensed under the GNU General Public 3.0 License
4 | #
5 |
6 | import dearpygui.dearpygui as dpg
7 | import globals
8 | from globals import ind, inc_ind, dec_ind, Serializable, bcksl
9 | from LuaNodeAttributes import *
10 | from constants import *
11 |
12 | lua_ntVariable = 0
13 | lua_ntStart = 1
14 | lua_ntPrint = 2
15 | lua_ntExpression = 3
16 | lua_ntForLoop = 4
17 | lua_ntIf = 5
18 | lua_ntElseIf = 6
19 | lua_ntElse = 7
20 | lua_ntAdd = 8
21 | lua_ntSubtract = 9
22 | lua_ntMultiply = 10
23 | lua_ntDivide = 11
24 | lua_ntGreater = 12
25 | lua_ntGreaterOrEqual = 13
26 | lua_ntLess = 14
27 | lua_ntLessOrEqual = 15
28 | lua_ntEqual = 16
29 | lua_ntNotEqual = 17
30 | lua_ntAnd = 18
31 | lua_ntOr = 19
32 | lua_ntWhileLoop = 20
33 | lua_ntAssign = 21
34 | lua_ntFunctionDeclaration = 22
35 | lua_ntFunctionCall = 23
36 | lua_ntConcat = 24
37 | lua_ntReturn = 25
38 | lua_ntChainExpression = 26
39 | lua_ntIndexTable = 27
40 | lua_ntIndexTableByKey = 28
41 | lua_ntIteratePairs = 29
42 | lua_ntIterateIPairs = 30
43 | lua_ntTable = 31
44 | lua_ntNot = 32
45 | lua_ntModulus = 33
46 |
47 | lua_ntNames = {
48 | lua_ntStart: "Entry",
49 | lua_ntVariable: "Variable",
50 | lua_ntTable: "Variable Table",
51 | lua_ntPrint: "Print",
52 | lua_ntExpression: "Expression",
53 | lua_ntForLoop: "For Loop",
54 | lua_ntWhileLoop: "While Loop",
55 | lua_ntIf: "If",
56 | lua_ntElseIf: "Else If",
57 | lua_ntElse: "Else",
58 | lua_ntAdd: "Add(+)",
59 | lua_ntSubtract: "Subtract(-)",
60 | lua_ntMultiply: "Multiply(*)",
61 | lua_ntDivide: "Divide(/)",
62 | lua_ntModulus: "Modulus(%)",
63 | lua_ntGreater: "Greater(>)",
64 | lua_ntGreaterOrEqual: "Greater or equal(>=)",
65 | lua_ntLess: "Less(<)",
66 | lua_ntLessOrEqual: "Less or equal(<=)",
67 | lua_ntEqual: "Equal(==)",
68 | lua_ntNotEqual: "Not equal(~=)",
69 | lua_ntAnd: "And",
70 | lua_ntOr: "Or",
71 | lua_ntNot: "Not",
72 | lua_ntAssign: "Assign",
73 | lua_ntFunctionDeclaration: "Function Declaration",
74 | lua_ntFunctionCall: "Function Call",
75 | lua_ntConcat: "Concat",
76 | lua_ntReturn: "Return",
77 | lua_ntChainExpression: "Chain Expression",
78 | lua_ntIndexTable: "Index Table",
79 | lua_ntIndexTableByKey: "Index Table By Key",
80 | lua_ntIteratePairs: "Iterate Pairs",
81 | lua_ntIterateIPairs: "Iterate IPairs",
82 |
83 | }
84 |
85 |
86 | def create_node_of_type(type):
87 | node = None
88 | if type == lua_ntVariable:
89 | node = LuaVariableNode()
90 | elif type == lua_ntTable:
91 | node = LuaTable()
92 | elif type == lua_ntStart:
93 | node = LuaStartNode()
94 | elif type == lua_ntPrint:
95 | node = LuaPrintNode()
96 | elif type == lua_ntExpression:
97 | node = LuaExpressionNode()
98 | elif type == lua_ntForLoop:
99 | node = LuaNodeForLoop()
100 | elif type == lua_ntWhileLoop:
101 | node = LuaNodeWhileLoop()
102 | elif type == lua_ntIf:
103 | node = LuaIfNode()
104 | elif type == lua_ntElseIf:
105 | node = LuaElseIfNode()
106 | elif type == lua_ntElse:
107 | node = LuaElseNode()
108 | elif type == lua_ntAdd:
109 | node = LuaNodeAdd()
110 | elif type == lua_ntSubtract:
111 | node = LuaNodeSubtract()
112 | elif type == lua_ntMultiply:
113 | node = LuaNodeMultiply()
114 | elif type == lua_ntDivide:
115 | node = LuaNodeDivide()
116 | elif type == lua_ntGreater:
117 | node = LuaNodeGreater()
118 | elif type == lua_ntGreaterOrEqual:
119 | node = LuaNodeGreaterOrEqual()
120 | elif type == lua_ntLess:
121 | node = LuaNodeLess()
122 | elif type == lua_ntLessOrEqual:
123 | node = LuaNodeLessOrEqual()
124 | elif type == lua_ntEqual:
125 | node = LuaNodeEqual()
126 | elif type == lua_ntNotEqual:
127 | node = LuaNodeNotEqual()
128 | elif type == lua_ntAnd:
129 | node = LuaNodeAnd()
130 | elif type == lua_ntOr:
131 | node = LuaNodeOr()
132 | elif type == lua_ntAssign:
133 | node = LuaNodeAssign()
134 | elif type == lua_ntFunctionDeclaration:
135 | node = LuaNodeFunction()
136 | elif type == lua_ntFunctionCall:
137 | node = LuaNodeFunctionCall()
138 | elif type == lua_ntConcat:
139 | node = LuaNodeConcat()
140 | elif type == lua_ntReturn:
141 | node = LuaNodeReturn()
142 | elif type == lua_ntChainExpression:
143 | node = LuaNodeChainExpression()
144 | elif type == lua_ntIndexTable:
145 | node = LuaNodeIndexTable()
146 | elif type == lua_ntIndexTableByKey:
147 | node = LuaNodeIndexTableByKey()
148 | elif type == lua_ntIteratePairs:
149 | node = LuaNodeIteratePairs()
150 | elif type == lua_ntIterateIPairs:
151 | node = LuaNodeIterateIPairs()
152 | elif type == lua_ntNot:
153 | node = LuaNodeNot()
154 | elif type == lua_ntModulus:
155 | node = LuaNodeModulus()
156 |
157 | dpg.bind_item_font(node.id, "bold_roboto")
158 | return node
159 |
160 |
161 | class Link(Serializable):
162 | def __init__(self, id, from_node, to_node, from_attribute, to_attribute):
163 | self.id = id
164 | self.from_node = from_node
165 | self.to_node = to_node
166 | self.from_attribute = from_attribute
167 | self.to_attribute = to_attribute
168 |
169 | def serialize(self):
170 | return {
171 | "id": self.id,
172 | "from_node": self.from_node,
173 | "to_node": self.to_node,
174 | "from_attribute": self.from_attribute,
175 | "to_attribute": self.to_attribute
176 | }
177 |
178 | def deserialize(self, obj):
179 | pass
180 |
181 | def __str__(self):
182 | return f"{self.id} {self.from_node} {self.to_node} {self.from_attribute} {self.to_attribute}"
183 |
184 | def __repr__(self):
185 | return str(self)
186 |
187 |
188 | class LuaNode(Serializable):
189 | def __init__(self):
190 | self.node_type = None
191 | self.stage = None
192 | self.id = None
193 | self.node_attributes = []
194 |
195 | def submit(self, parent):
196 | node_attribute: NodeAttribute
197 | for node_attribute in self.node_attributes:
198 | node_attribute.parent_node = self
199 | for child in dpg.get_item_children(node_attribute.stage, slot=1):
200 | dpg.bind_item_font(child, "roboto")
201 | dpg.move_item(child, parent=self.id)
202 | # dpg.move_item(node_attribute.id, parent=self.id)
203 | dpg.delete_item(node_attribute.stage)
204 |
205 | dpg.push_container_stack(parent)
206 | dpg.unstage(self.stage)
207 | dpg.pop_container_stack()
208 | dpg.delete_item(self.stage)
209 |
210 | def generate_code(self, color_coded=False):
211 | if not color_coded:
212 | return ""
213 | else:
214 | return [[]]
215 |
216 | def serialize(self):
217 | return {
218 | "id": self.id,
219 | "node_pos": dpg.get_item_pos(self.id),
220 | "node_type": self.node_type,
221 | "attributes": dict(
222 | zip([attr.id for attr in self.node_attributes], [attr.serialize() for attr in self.node_attributes]))
223 | }
224 |
225 | def deserialize(self, obj):
226 | node_pos = obj["node_pos"]
227 | dpg.configure_item(self.id, pos=node_pos)
228 | self.node_type = obj["node_type"]
229 | i = 0
230 | for attribute_id, attribute_data in obj["attributes"].items():
231 | self.node_attributes[i].deserialize(attribute_data)
232 | i += 1
233 |
234 |
235 | class LuaVariableNode(LuaNode):
236 | def __init__(self):
237 | super().__init__()
238 | self.node_type = lua_ntVariable
239 |
240 | self.node_attributes = [
241 | NodeAttributeExecuteIn(),
242 | NodeAttributeExecuteOut(),
243 | NodeAttributeVariable()
244 | ]
245 |
246 | self.attribute_execute_in = self.node_attributes[0]
247 | self.attribute_execute_out = self.node_attributes[1]
248 | self.attribute_var = self.node_attributes[2]
249 |
250 | with dpg.stage() as self.stage:
251 | with dpg.node(label="Variable", pos=dpg.get_mouse_pos(),) as self.id:
252 | pass
253 |
254 | def has_from_node(self):
255 | return globals.get_from_node_from_in_node_attribute(self.attribute_execute_in.id) is not None
256 |
257 | def generate_code(self, color_coded=False):
258 | name = dpg.get_value(self.attribute_var.name)
259 | value = dpg.get_value(self.attribute_var.value)
260 | if not self.has_from_node():
261 | if not color_coded:
262 | return f'{name} = {value}\n'
263 | return [
264 | [name, color_variable],
265 | ['=', color_math_operator],
266 | [value, color_immediate_value],
267 | ["\n"]
268 | ]
269 | execute_out_code = self.attribute_execute_out.generate_code()
270 |
271 | assign_code = f"={value}" if value != "" else ""
272 | if not color_coded:
273 | return f"{ind()}local {name} {assign_code}\n{execute_out_code}"
274 | else:
275 | return [
276 | [ind()],
277 | ["local ", color_default],
278 | [name, color_variable],
279 | [" =", color_math_operator],
280 | [f" {assign_code[1:]}", color_test],
281 | ["\n"]
282 | ] + self.attribute_execute_out.generate_code(True)
283 |
284 | class LuaTable(LuaNode):
285 | def __init__(self):
286 | super().__init__()
287 | self.node_type = lua_ntTable
288 |
289 | self.node_attributes = [
290 | NodeAttributeExecuteIn(),
291 | NodeAttributeExecuteOut(),
292 | NodeAttributeExpressionOut("Table name", simple=True),
293 | NodeAttributeMultipleTableEntry(),
294 | NodeAttributeCustomCallerOut(callback=self.return_table_value)
295 | ]
296 |
297 | self.attribute_execute_in = self.node_attributes[0]
298 | self.attribute_execute_out = self.node_attributes[1]
299 | self.attribute_table_name = self.node_attributes[2]
300 | self.attribute_table_entries = self.node_attributes[3]
301 | self.attribute_expression_output = self.node_attributes[4]
302 |
303 | with dpg.stage() as self.stage:
304 | with dpg.node(label="Table") as self.id:
305 | pass
306 |
307 | def has_from_node(self):
308 | ret = globals.get_from_node_from_in_node_attribute(self.attribute_execute_in.id) is not None or globals.get_to_node_from_out_node_attribute(self.attribute_expression_output.id) is not None
309 | return ret
310 |
311 | def return_table_value(self, params):
312 | return self.attribute_table_entries.generate_code()
313 |
314 | def generate_code(self, color_coded=False):
315 | name_code = self.attribute_table_name.generate_code()
316 | local_code = ""
317 | if self.has_from_node():
318 | local_code = f"local "
319 | code_without_flow_out = f"{ind()}{local_code}{name_code} = {self.attribute_table_entries.generate_code()}\n"
320 | if not self.has_from_node():
321 | if not color_coded:
322 | return f"{name_code} = {self.attribute_table_entries.generate_code()}"
323 | else:
324 | name_code_color = self.attribute_table_name.generate_code(color_coded=True)
325 | entries_code_color = self.attribute_table_entries.generate_code(color_coded=True)
326 |
327 | return name_code_color + [
328 | [" = ", color_math_operator]
329 | ] + entries_code_color
330 | if not color_coded:
331 | out_code = self.attribute_execute_out.generate_code()
332 | return f"{code_without_flow_out}{out_code}"
333 | else:
334 | out_code_color = self.attribute_execute_out.generate_code(color_coded=True)
335 | name_code_color = self.attribute_table_name.generate_code(color_coded=True)
336 | entries_code_color = self.attribute_table_entries.generate_code(color_coded=True)
337 |
338 | ret = [
339 | [ind()],
340 | [local_code, color_keyword]
341 | ] + name_code_color + [
342 | [" = ", color_math_operator],
343 | ] + entries_code_color + [
344 | ["\n"]
345 | ] + out_code_color
346 |
347 | return ret
348 |
349 | class LuaStartNode(LuaNode):
350 | def __init__(self):
351 | super().__init__()
352 | self.node_type = lua_ntStart
353 |
354 | self.node_attributes = [
355 | NodeAttributeExecuteOut()
356 | ]
357 |
358 | self.attribute_execute_out = self.node_attributes[0]
359 |
360 | with dpg.stage() as self.stage:
361 | with dpg.node(label="Entry point") as self.id:
362 | pass
363 |
364 | def generate_code(self, color_coded=False):
365 | to_node: LuaNode = globals.get_to_node_from_out_node_attribute(self.attribute_execute_out.id)
366 | if to_node:
367 | if not color_coded:
368 | return to_node.generate_code()
369 | return to_node.generate_code(color_coded)
370 |
371 | if not color_coded:
372 | return ""
373 | return [[]]
374 |
375 | class LuaPrintNode(LuaNode):
376 | def __init__(self):
377 | super().__init__()
378 | self.node_type = lua_ntPrint
379 |
380 | self.node_attributes = [
381 | NodeAttributeExecuteIn(),
382 | NodeAttributeExecuteOut(),
383 | NodeAttributeExpressionIn("Value")
384 | ]
385 |
386 | self.attribute_execute_out = self.node_attributes[1]
387 | self.attribute_expression = self.node_attributes[2]
388 |
389 | with dpg.stage() as self.stage:
390 | with dpg.node(label="Print") as self.id:
391 | pass
392 |
393 | def generate_code(self, color_coded=False):
394 | my_code = self.attribute_expression.generate_code()
395 |
396 | if not color_coded:
397 | return f"{ind()}print({my_code})\n{self.attribute_execute_out.generate_code()}"
398 | else:
399 | my_code_colored = self.attribute_expression.generate_code(color_coded=True)
400 | out_code_colored = self.attribute_execute_out.generate_code(color_coded=True)
401 | return [
402 | [ind()],
403 | ["print(", color_default],
404 | ] + my_code_colored + [
405 | [")", color_default],
406 | ["\n"],
407 | ] + out_code_colored
408 |
409 | class LuaExpressionNode(LuaNode):
410 | def __init__(self):
411 | super().__init__()
412 | self.node_type = lua_ntExpression
413 |
414 | self.node_attributes = [
415 | NodeAttributeExpressionOut("Value", simple=True)
416 | ]
417 |
418 | self.attribute_expression = self.node_attributes[0]
419 |
420 | with dpg.stage() as self.stage:
421 | with dpg.node(label="Expression") as self.id:
422 | pass
423 |
424 | def generate_code(self, color_coded=False):
425 | if not color_coded:
426 | return f"{dpg.get_value(self.attribute_expression.value)}"
427 | else:
428 | return [
429 | [dpg.get_value(self.attribute_expression.value), color_immediate_value]
430 | ]
431 |
432 | class LuaNodeForLoop(LuaNode):
433 | def __init__(self):
434 | super().__init__()
435 | self.node_type = lua_ntForLoop
436 |
437 | self.node_attributes = [
438 | NodeAttributeExecuteIn(),
439 | NodeAttributeExecuteOut(),
440 | NodeAttributeExpressionOut("Iterator", simple=True),
441 | NodeAttributeExpressionIn("From"),
442 | NodeAttributeExpressionIn("To"),
443 | NodeAttributeExecuteOut("Execute"),
444 | ]
445 |
446 | self.attribute_execute_out = self.node_attributes[1]
447 | self.attribute_iterator = self.node_attributes[2]
448 | self.attribute_from = self.node_attributes[3]
449 | self.attribute_to = self.node_attributes[4]
450 | self.attribute_code_to_execute = self.node_attributes[5]
451 |
452 | with dpg.stage() as self.stage:
453 | with dpg.node(label="For Loop") as self.id:
454 | pass
455 |
456 | def generate_code(self, color_coded=False):
457 | inc_ind()
458 | execute_code = f"{self.attribute_code_to_execute.generate_code()}"
459 | dec_ind()
460 |
461 | iterator_code = self.attribute_iterator.generate_code()
462 | from_value = self.attribute_from.generate_code()
463 | to_value = self.attribute_to.generate_code()
464 |
465 | execute_out_code = self.attribute_execute_out.generate_code()
466 |
467 | if not color_coded:
468 | return f"{ind()}for {iterator_code} = {from_value}, {to_value} do\n{execute_code}{ind()}end\n{execute_out_code}"
469 | else:
470 |
471 | inc_ind()
472 | execute_code_colored = self.attribute_code_to_execute.generate_code(color_coded=True)
473 | dec_ind()
474 |
475 | iterator_code_colored = self.attribute_iterator.generate_code(color_coded=True)
476 | from_value_colored = self.attribute_from.generate_code(color_coded=True)
477 | to_value_colored = self.attribute_to.generate_code(color_coded=True)
478 |
479 | execute_out_code_colored = self.attribute_execute_out.generate_code(color_coded=True)
480 | return [
481 | [ind()],
482 | ["for ", color_keyword]
483 | ] + iterator_code_colored + [
484 | [" = ", color_math_operator]
485 | ] + from_value_colored + [
486 | [", ", color_default]
487 | ] + to_value_colored + [
488 | [" do", color_keyword]
489 | ] + execute_code_colored + [
490 | ["end", color_keyword],
491 | ["\n"]
492 | ] + execute_out_code_colored
493 |
494 | class LuaNodeWhileLoop(LuaNode):
495 | def __init__(self):
496 | super().__init__()
497 | self.node_type = lua_ntWhileLoop
498 |
499 | self.node_attributes = [
500 | NodeAttributeExecuteIn(),
501 | NodeAttributeExecuteOut(),
502 | NodeAttributeExpressionIn("Condition"),
503 | NodeAttributeExecuteOut("Execute"),
504 | ]
505 |
506 | self.attribute_execute_out = self.node_attributes[1]
507 | self.attribute_condition_expression = self.node_attributes[2]
508 | self.attribute_code_to_execute = self.node_attributes[3]
509 |
510 | with dpg.stage() as self.stage:
511 | with dpg.node(label="While Loop") as self.id:
512 | pass
513 |
514 | def generate_code(self, color_coded=False):
515 | inc_ind()
516 | execute_code = f"{self.attribute_code_to_execute.generate_code()}"
517 | dec_ind()
518 |
519 | condition_code = self.attribute_condition_expression.generate_code()
520 | execute_out_code = self.attribute_execute_out.generate_code()
521 |
522 | if not color_coded:
523 | return f"{ind()}while {condition_code} do\n{execute_code}{ind()}end\n{execute_out_code}"
524 | else:
525 | inc_ind()
526 | execute_code_colored = self.attribute_code_to_execute.generate_code(color_coded=True)
527 | dec_ind()
528 |
529 | condition_code_colored = self.attribute_condition_expression.generate_code(color_coded=True)
530 | execute_out_code_colored = self.attribute_execute_out.generate_code(color_coded=True)
531 |
532 | return [
533 | [ind()],
534 | ["while ", color_keyword],
535 | ] + condition_code_colored + [
536 | [" do", color_keyword],
537 | ["\n"]
538 | ] + execute_code_colored + [
539 | [ind()],
540 | ["end", color_keyword],
541 | ["\n"]
542 | ] + execute_out_code_colored
543 |
544 | class LuaIfNode(LuaNode):
545 | def __init__(self):
546 | super().__init__()
547 | self.node_type = lua_ntIf
548 |
549 | self.node_attributes = [
550 | NodeAttributeExecuteIn(),
551 | NodeAttributeExecuteOut(),
552 | NodeAttributeExpressionIn("Condition"),
553 | NodeAttributeExecuteOut(text="Condition met"),
554 | ]
555 |
556 | self.attribute_execute_out = self.node_attributes[1]
557 | self.attribute_expression = self.node_attributes[2]
558 | self.attribute_execute_if_true = self.node_attributes[3]
559 |
560 | with dpg.stage() as self.stage:
561 | with dpg.node(label="If") as self.id:
562 | pass
563 |
564 | def generate_code(self, color_coded=False):
565 | inc_ind()
566 | execute_code = f"{self.attribute_execute_if_true.generate_code()}"
567 | dec_ind()
568 |
569 | condition_code = self.attribute_expression.generate_code()
570 | execute_out_code = self.attribute_execute_out.generate_code()
571 |
572 | execute_out_node = globals.get_to_node_from_out_node_attribute(self.attribute_execute_out.id)
573 | is_last_else_if_or_else = False
574 | if execute_out_node:
575 | is_last_else_if_or_else = isinstance(execute_out_node, LuaElseIfNode) or isinstance(execute_out_node,
576 | LuaElseNode)
577 |
578 | if not color_coded:
579 | return f"{ind()}if {condition_code} then\n{execute_code}{f'{ind()}end{bcksl()}' if not is_last_else_if_or_else else ''}{execute_out_code}"
580 | else:
581 | inc_ind()
582 | execute_code_colored = self.attribute_execute_if_true.generate_code(color_coded=True)
583 | dec_ind()
584 |
585 | condition_code_colored = self.attribute_expression.generate_code(color_coded=True)
586 | execute_out_code_colored = self.attribute_execute_out.generate_code(color_coded=True)
587 |
588 | return [
589 | [ind()],
590 | ["if ", color_keyword]
591 | ] + condition_code_colored + [
592 | [" then", color_keyword]
593 | ] + execute_code_colored + [
594 | [ind()],
595 | ["end", color_keyword],
596 | ["\n"]
597 | ] if not is_last_else_if_or_else else [] + execute_out_code_colored
598 |
599 | class LuaElseIfNode(LuaNode):
600 | def __init__(self):
601 | super().__init__()
602 | self.node_type = lua_ntElseIf
603 |
604 | self.node_attributes = [
605 | NodeAttributeExecuteIn(),
606 | NodeAttributeExecuteOut(),
607 | NodeAttributeExpressionIn("Condition"),
608 | NodeAttributeExecuteOut(text="Condition met"),
609 | ]
610 |
611 | self.attribute_execute_out = self.node_attributes[1]
612 | self.attribute_expression = self.node_attributes[2]
613 | self.attribute_execute_if_true = self.node_attributes[3]
614 |
615 | with dpg.stage() as self.stage:
616 | with dpg.node(label="Else If") as self.id:
617 | pass
618 |
619 | def generate_code(self, color_coded=False):
620 | inc_ind()
621 | execute_code = f"{self.attribute_execute_if_true.generate_code()}"
622 | dec_ind()
623 |
624 | condition_code = self.attribute_expression.generate_code()
625 | execute_out_code = self.attribute_execute_out.generate_code()
626 |
627 | execute_out_node = globals.get_to_node_from_out_node_attribute(self.attribute_execute_out.id)
628 | is_last_else_if_or_else = False
629 | if execute_out_node:
630 | is_last_else_if_or_else = isinstance(execute_out_node, LuaElseIfNode) or isinstance(execute_out_node,
631 | LuaElseNode)
632 |
633 | if not color_coded:
634 | return f"{ind()}else if {condition_code} then\n{execute_code}{f'{ind()}end{bcksl()}' if not is_last_else_if_or_else else ''}{execute_out_code}"
635 | else:
636 | inc_ind()
637 | execute_code_colored = self.attribute_execute_if_true.generate_code(color_coded=True)
638 | dec_ind()
639 |
640 | condition_code_colored = self.attribute_expression.generate_code(color_coded=True)
641 | execute_out_code_colored = self.attribute_execute_out.generate_code(color_coded=True)
642 |
643 | return [
644 | [ind()],
645 | ["else if ", color_keyword]
646 | ] + condition_code_colored + [
647 | [" then", color_keyword],
648 | ["\n"]
649 | ] + execute_code_colored + [
650 | [ind()],
651 | ["end", color_keyword],
652 | ["\n"],
653 | ] if not is_last_else_if_or_else else [] + execute_out_code_colored
654 |
655 | class LuaElseNode(LuaNode):
656 | def __init__(self):
657 | super().__init__()
658 | self.node_type = lua_ntElse
659 |
660 | self.node_attributes = [
661 | NodeAttributeExecuteIn(),
662 | NodeAttributeExecuteOut(),
663 | NodeAttributeExecuteOut(text="Execute"),
664 | ]
665 |
666 | self.attribute_execute_out = self.node_attributes[1]
667 | self.attribute_execute_if_true = self.node_attributes[2]
668 |
669 | with dpg.stage() as self.stage:
670 | with dpg.node(label="Else") as self.id:
671 | pass
672 |
673 | def generate_code(self, color_coded=False):
674 | inc_ind()
675 | execute_code = f"{self.attribute_execute_if_true.generate_code()}"
676 | dec_ind()
677 |
678 | execute_out_code = self.attribute_execute_out.generate_code()
679 |
680 | if not color_coded:
681 | return f"{ind()}else\n{execute_code}{ind()}end\n{execute_out_code}"
682 | else:
683 | inc_ind()
684 | execute_code_colored = self.attribute_execute_if_true.generate_code(color_coded=True)
685 | dec_ind()
686 | execute_out_code_colored = self.attribute_execute_out.generate_code(color_coded=True)
687 |
688 | return [
689 | [ind()],
690 | ["else", color_keyword],
691 | ["\n"]
692 | ] + execute_code_colored + [
693 | [ind()],
694 | ["end", color_keyword],
695 | ["\n"]
696 | ] + execute_out_code_colored
697 |
698 | class LuaNodeBinaryCombiner(LuaNode):
699 | def __init__(self, name, symbol):
700 | super().__init__()
701 | self.symbol = symbol
702 |
703 | self.node_attributes = [
704 | NodeAttributeExpressionIn("a"),
705 | NodeAttributeStaticText(symbol),
706 | NodeAttributeExpressionIn("b"),
707 | NodeAttributeCheckbox("Paranthesize"),
708 | NodeAttributeExpressionOut("Value")
709 | ]
710 |
711 | self.node_attribute_expression_in_a = self.node_attributes[0]
712 | self.node_attribute_expression_in_b = self.node_attributes[2]
713 | self.checkbox_attribute = self.node_attributes[3]
714 |
715 | with dpg.stage() as self.stage:
716 | with dpg.node(label=name) as self.id:
717 | pass
718 |
719 | def generate_code(self, color_coded=False):
720 | check = dpg.get_value(self.checkbox_attribute.checkbox)
721 |
722 | if not color_coded:
723 | return f"{'(' if check else ''}{self.node_attribute_expression_in_a.generate_code()}{self.symbol}{self.node_attribute_expression_in_b.generate_code()}{')' if check else ''}"
724 | else:
725 | return [
726 | ["(" if check else "", color_default]
727 | ] + self.node_attribute_expression_in_a.generate_code(color_coded=True) + [
728 | [self.symbol, color_math_operator],
729 | ] + self.node_attribute_expression_in_b.generate_code(color_coded=True) + [
730 | [")" if check else "", color_default]
731 | ]
732 | # return self.attribute_expression.generate_code()
733 |
734 |
735 | class LuaNodeAdd(LuaNodeBinaryCombiner):
736 | def __init__(self):
737 | super().__init__("Add", " + ")
738 | self.node_type = lua_ntAdd
739 |
740 |
741 | class LuaNodeSubtract(LuaNodeBinaryCombiner):
742 | def __init__(self):
743 | super().__init__("Subtract", " - ")
744 | self.node_type = lua_ntSubtract
745 |
746 |
747 | class LuaNodeMultiply(LuaNodeBinaryCombiner):
748 | def __init__(self):
749 | super().__init__("Multiply", " * ")
750 | self.node_type = lua_ntMultiply
751 |
752 |
753 | class LuaNodeDivide(LuaNodeBinaryCombiner):
754 | def __init__(self):
755 | super().__init__("Divide", " / ")
756 | self.node_type = lua_ntDivide
757 |
758 | class LuaNodeModulus(LuaNodeBinaryCombiner):
759 | def __init__(self):
760 | super().__init__("Modulus", " % ")
761 | self.node_type = lua_ntModulus
762 |
763 |
764 | class LuaNodeGreater(LuaNodeBinaryCombiner):
765 | def __init__(self):
766 | super().__init__("Greater", " > ")
767 | self.node_type = lua_ntGreater
768 |
769 |
770 | class LuaNodeGreaterOrEqual(LuaNodeBinaryCombiner):
771 | def __init__(self):
772 | super().__init__("Greater or equal", " >= ")
773 | self.node_type = lua_ntGreaterOrEqual
774 |
775 |
776 | class LuaNodeLess(LuaNodeBinaryCombiner):
777 | def __init__(self):
778 | super().__init__("Less", " < ")
779 | self.node_type = lua_ntLess
780 |
781 |
782 | class LuaNodeLessOrEqual(LuaNodeBinaryCombiner):
783 | def __init__(self):
784 | super().__init__("Less or equal", " <= ")
785 | self.node_type = lua_ntLessOrEqual
786 |
787 |
788 | class LuaNodeEqual(LuaNodeBinaryCombiner):
789 | def __init__(self):
790 | super().__init__("Equal", " == ")
791 | self.node_type = lua_ntEqual
792 |
793 |
794 | class LuaNodeNotEqual(LuaNodeBinaryCombiner):
795 | def __init__(self):
796 | super().__init__("Not equal", " ~= ")
797 | self.node_type = lua_ntNotEqual
798 |
799 |
800 | class LuaNodeNot(LuaNodeBinaryCombiner):
801 | def __init__(self):
802 | super().__init__("Not", " not ")
803 | self.node_type = lua_ntNot
804 |
805 |
806 | class LuaNodeAnd(LuaNodeBinaryCombiner):
807 | def __init__(self):
808 | super().__init__("And", " and ")
809 | self.node_type = lua_ntAnd
810 |
811 |
812 | class LuaNodeOr(LuaNodeBinaryCombiner):
813 | def __init__(self):
814 | super().__init__("Or", " or ")
815 | self.node_type = lua_ntOr
816 |
817 | class LuaNodeConcat(LuaNodeBinaryCombiner):
818 | def __init__(self):
819 | super().__init__("Concat", " .. ")
820 | self.node_type = lua_ntConcat
821 |
822 |
823 | class LuaNodeChainExpression(LuaNodeBinaryCombiner):
824 | def __init__(self):
825 | super().__init__("Chain Expression", ", ")
826 | self.node_type = lua_ntChainExpression
827 |
828 |
829 | class LuaNodeAssign(LuaNode):
830 | def __init__(self):
831 | super().__init__()
832 | self.node_type = lua_ntAssign
833 |
834 | self.node_attributes = [
835 | NodeAttributeExecuteIn(),
836 | NodeAttributeExecuteOut(),
837 | NodeAttributeExpressionIn("Variable"),
838 | NodeAttributeStaticText("="),
839 | NodeAttributeExpressionIn("Value"),
840 | ]
841 |
842 | self.attribute_execute_out = self.node_attributes[1]
843 | self.attribute_expression_variable = self.node_attributes[2]
844 | self.attribute_expression_value = self.node_attributes[4]
845 |
846 | with dpg.stage() as self.stage:
847 | with dpg.node(label="Assign") as self.id:
848 | pass
849 |
850 | def generate_code(self, color_coded=False):
851 | variable_code = self.attribute_expression_variable.generate_code()
852 | value_code = self.attribute_expression_value.generate_code()
853 |
854 | execute_out_code = self.attribute_execute_out.generate_code()
855 |
856 |
857 | if not color_coded:
858 | return f"{ind()}{variable_code} = {value_code}\n{execute_out_code}"
859 | else:
860 | variable_code_colored = self.attribute_expression_variable.generate_code(color_coded=True)
861 | value_code_colored = self.attribute_expression_value.generate_code(color_coded=True)
862 |
863 | execute_out_code_colored = self.attribute_execute_out.generate_code(color_coded=True)
864 |
865 | return [
866 | [ind()]
867 | ] + variable_code_colored + [
868 | [" = ", color_math_operator]
869 | ] + value_code_colored + [
870 | ["\n"]
871 | ] + execute_out_code_colored
872 |
873 | class LuaNodeFunction(LuaNode):
874 | def __init__(self):
875 | super().__init__()
876 | self.node_type = lua_ntFunctionDeclaration
877 |
878 | self.node_attributes = [
879 | NodeAttributeExecuteIn(),
880 | NodeAttributeExecuteOut(),
881 | NodeAttributeStaticInputText("Function name"),
882 | NodeAttributeMultipleExpressionOut("Arguments"),
883 | NodeAttributeExecuteOut("Execute"),
884 | NodeAttributeInlineDeclarationOut()
885 | ]
886 |
887 | self.attribute_execute_in = self.node_attributes[0]
888 | self.attribute_execute_out = self.node_attributes[1]
889 | self.attribute_function_name = self.node_attributes[2]
890 | self.attribute_params = self.node_attributes[3]
891 | self.attribute_execute_code = self.node_attributes[4]
892 | self.attribute_inline_decl_out = self.node_attributes[5]
893 |
894 | with dpg.stage() as self.stage:
895 | with dpg.node(label="Function Declaration") as self.id:
896 | pass
897 |
898 | def has_from_node(self):
899 | return globals.get_from_node_from_in_node_attribute(self.attribute_execute_in.id) is not None
900 |
901 | def is_inline(self):
902 | return globals.get_to_node_from_out_node_attribute(self.attribute_inline_decl_out.id) is not None
903 |
904 | def generate_code(self, inline=False, color_coded=False):
905 | name = self.attribute_function_name.generate_code()
906 |
907 | params_code = "".join([f"{arg.generate_code()}{', ' if i != len(self.attribute_params.arguments) - 1 else ''}" for
908 | i, arg in enumerate(self.attribute_params.arguments)])
909 |
910 | execute_code = ""
911 | # if inline:
912 | inc_ind()
913 | execute_code = self.attribute_execute_code.generate_code()
914 | dec_ind()
915 |
916 | execute_out_code = self.attribute_execute_out.generate_code()
917 |
918 | is_local_function = self.has_from_node()
919 | local_code = f"{ind()}local " if is_local_function else ""
920 | end_code = f"\n{execute_out_code}" if not inline else ""
921 |
922 | if not color_coded:
923 | return f"{local_code}function{f' {name}' if not inline else ''}({params_code})\n{execute_code}{ind()}end{end_code}"
924 | else:
925 | name_colored = self.attribute_function_name.generate_code(color_coded=True)
926 |
927 | params_code_colored = []
928 | for i, arg in enumerate(self.attribute_params.arguments):
929 | params_code_colored += arg.generate_code(color_coded=True) + [
930 | [", ", color_default] if (i != len(self.attribute_params.arguments) - 1) else []
931 | ]
932 |
933 | inc_ind()
934 | execute_code_colored = self.attribute_execute_code.generate_code(color_coded=True)
935 | dec_ind()
936 |
937 | execute_out_code_colored = self.attribute_execute_out.generate_code(color_coded=True)
938 |
939 | is_local_function = self.has_from_node()
940 | local_code_colored = [
941 | [ind()],
942 | ["local ", color_keyword]
943 | ] if is_local_function else []
944 | p1 = [
945 | ["\n"]
946 | ] + execute_out_code_colored
947 | end_code_colored = p1 if not inline else []
948 |
949 | xx = name_colored if not inline else []
950 |
951 | return local_code_colored + [
952 | ["function", color_keyword],
953 | ] + xx + [
954 | ["(", color_default],
955 | ] + params_code_colored + [
956 | [")", color_default],
957 | ["\n"]
958 | ] + execute_code_colored + [
959 | [ind()],
960 | ["end", color_default]
961 | ] + end_code_colored
962 |
963 |
964 | class LuaNodeFunctionCall(LuaNode):
965 |
966 | def __init__(self):
967 | super().__init__()
968 | self.node_type = lua_ntFunctionCall
969 |
970 | self.node_attributes = [
971 | NodeAttributeExecuteIn(),
972 | NodeAttributeExecuteOut(),
973 | NodeAttributeStaticInputText("Function name"),
974 | NodeAttributeExpressionIn("Call On Object"),
975 | NodeAttributeCheckbox("Call on self"),
976 | NodeAttributeMultipleExpressionIn("Arguments"),
977 | NodeAttributeExpressionOut("Out", simple=False)
978 | ]
979 |
980 | self.attribute_execute_in = self.node_attributes[0]
981 | self.attribute_execute_out = self.node_attributes[1]
982 | self.attribute_function_name = self.node_attributes[2]
983 | self.attribute_call_on_object = self.node_attributes[3]
984 | self.attribute_call_on_self = self.node_attributes[4]
985 | self.attribute_params = self.node_attributes[5]
986 |
987 | with dpg.stage() as self.stage:
988 | with dpg.node(label="Function Call") as self.id:
989 | pass
990 |
991 | def generate_code(self, color_coded=False):
992 | call_on_object_code = self.attribute_call_on_object.generate_code()
993 |
994 | function_name = self.attribute_function_name.generate_code()
995 | params_code = "".join(
996 | [f"{arg.generate_code()}{', ' if i != len(self.attribute_params.arguments) - 1 else ''}" for
997 | i, arg in enumerate(self.attribute_params.arguments)])
998 |
999 | execute_out_code = self.attribute_execute_out.generate_code()
1000 |
1001 | end_code = f"\n{execute_out_code}" if execute_out_code != "" else ""
1002 | call_on_object_code = f"{call_on_object_code}{'.' if not dpg.get_value(self.attribute_call_on_self.checkbox) else ':'}" if call_on_object_code != "" else ""
1003 | # return f"{call_on_object_code}{ind()}{function_name}({params_code}){end}"
1004 |
1005 |
1006 | if not color_coded:
1007 | return f"{call_on_object_code}{function_name}({params_code}){end_code}"
1008 | else:
1009 | call_on_object_code_colored = self.attribute_call_on_object.generate_code(color_coded=True)
1010 | function_name_colored = self.attribute_function_name.generate_code(color_coded=True)
1011 |
1012 | params_code_colored = []
1013 | for i, arg in enumerate(self.attribute_params.arguments):
1014 | params_code_colored += arg.generate_code(color_coded=True) + [
1015 | [", ", color_default] if (i != len(self.attribute_params.arguments) - 1) else []
1016 | ]
1017 |
1018 | execute_out_code_colored = self.attribute_execute_out.generate_code(color_coded=True)
1019 |
1020 | v1 = [
1021 | ["\n"]
1022 | ] + execute_out_code_colored
1023 | v2 = []
1024 | end_code_colored = v1 if execute_out_code != "" else v2
1025 |
1026 | v1 = call_on_object_code_colored + [
1027 | [".", color_default] if not dpg.get_value(self.attribute_call_on_self.checkbox) else [":", color_default]
1028 | ]
1029 | v2 = []
1030 | call_on_object_code_colored = v1 if call_on_object_code != "" else v2
1031 |
1032 | return call_on_object_code_colored + function_name_colored + [
1033 | ["(", color_default]
1034 | ] + params_code_colored + [
1035 | [")", color_default]
1036 | ] + end_code_colored
1037 |
1038 | class LuaNodeReturn(LuaNode):
1039 | def __init__(self):
1040 | super().__init__()
1041 | self.node_type = lua_ntReturn
1042 |
1043 | self.node_attributes = [
1044 | NodeAttributeExecuteIn(),
1045 | NodeAttributeExpressionIn("Value")
1046 | ]
1047 |
1048 | self.attribute_expression = self.node_attributes[1]
1049 |
1050 | with dpg.stage() as self.stage:
1051 | with dpg.node(label="Return") as self.id:
1052 | pass
1053 |
1054 | def generate_code(self, color_coded=False):
1055 | my_code = self.attribute_expression.generate_code()
1056 |
1057 | if not color_coded:
1058 | return f"{ind()}return {my_code}\n"
1059 | else:
1060 | my_code_colored = self.attribute_expression.generate_code(color_coded=True)
1061 |
1062 | return [
1063 | [ind()],
1064 | ["return ", color_keyword]
1065 | ] + my_code_colored + [
1066 | ["\n"]
1067 | ]
1068 |
1069 | class LuaNodeIndexTable(LuaNode):
1070 | def __init__(self):
1071 | super().__init__()
1072 | self.node_type = lua_ntIndexTable
1073 |
1074 | self.node_attributes = [
1075 | NodeAttributeExpressionIn("Table"),
1076 | NodeAttributeExpressionIn("Index"),
1077 | NodeAttributeExpressionOut("Output")
1078 | ]
1079 |
1080 | self.attribute_expression_table = self.node_attributes[0]
1081 | self.attribute_expression_index = self.node_attributes[1]
1082 |
1083 | with dpg.stage() as self.stage:
1084 | with dpg.node(label="Index Table") as self.id:
1085 | pass
1086 |
1087 | def generate_code(self, color_coded=False):
1088 | table_code = self.attribute_expression_table.generate_code()
1089 | index_code = self.attribute_expression_index.generate_code()
1090 |
1091 | if not color_coded:
1092 | return f"{table_code}[{index_code}]"
1093 | else:
1094 | table_code_colored = self.attribute_expression_table.generate_code(color_coded=True)
1095 | index_code_colored = self.attribute_expression_index.generate_code(color_coded=True)
1096 |
1097 | return table_code_colored + [
1098 | ["[", color_default]
1099 | ] + index_code_colored + [
1100 | ["]", color_default]
1101 | ]
1102 |
1103 | class LuaNodeIndexTableByKey(LuaNode):
1104 | def __init__(self):
1105 | super().__init__()
1106 | self.node_type = lua_ntIndexTableByKey
1107 |
1108 | self.node_attributes = [
1109 | NodeAttributeExpressionIn("Table"),
1110 | NodeAttributeExpressionIn("Key"),
1111 | NodeAttributeExpressionOut("Output")
1112 | ]
1113 |
1114 | self.attribute_expression_table = self.node_attributes[0]
1115 | self.attribute_expression_index = self.node_attributes[1]
1116 |
1117 | with dpg.stage() as self.stage:
1118 | with dpg.node(label="Index Table By Key") as self.id:
1119 | pass
1120 |
1121 | def generate_code(self, color_coded=False):
1122 | table_code = self.attribute_expression_table.generate_code()
1123 | index_code = self.attribute_expression_index.generate_code()
1124 |
1125 | if not color_coded:
1126 | return f"{table_code}.{index_code}"
1127 | else:
1128 | table_code_colored = self.attribute_expression_table.generate_code(color_coded=True)
1129 | index_code_colored = self.attribute_expression_index.generate_code(color_coded=True)
1130 |
1131 | return table_code_colored + [
1132 | [".", color_default]
1133 | ] + index_code_colored
1134 |
1135 |
1136 | class LuaNodeIteratePairs(LuaNode):
1137 | def __init__(self, it1="key", it2="value", iterate_func="ipairs", node_name="Iterate Pairs"):
1138 | super().__init__()
1139 | self.node_type = lua_ntIteratePairs
1140 | self.iterate_func = iterate_func
1141 | self.node_name = node_name
1142 |
1143 | self.node_attributes = [
1144 | NodeAttributeExecuteIn(),
1145 | NodeAttributeExecuteOut(),
1146 | NodeAttributeExpressionOut(it1, simple=True, value=it1),
1147 | NodeAttributeExpressionOut(it2, simple=True, value=it2),
1148 | NodeAttributeExpressionIn("Table"),
1149 | NodeAttributeExecuteOut("Execute"),
1150 | ]
1151 |
1152 | self.attribute_execute_out = self.node_attributes[1]
1153 | self.attribute_it1 = self.node_attributes[2]
1154 | self.attribute_it2 = self.node_attributes[3]
1155 | self.attribute_table = self.node_attributes[4]
1156 | self.attribute_code_to_execute = self.node_attributes[5]
1157 |
1158 | with dpg.stage() as self.stage:
1159 | with dpg.node(label=self.node_name) as self.id:
1160 | pass
1161 |
1162 | def generate_code(self, color_coded=False):
1163 | inc_ind()
1164 | execute_code = f"{self.attribute_code_to_execute.generate_code()}"
1165 | dec_ind()
1166 |
1167 | it1_code = self.attribute_it1.generate_code()
1168 | it2_code = self.attribute_it2.generate_code()
1169 | table_name = self.attribute_table.generate_code()
1170 |
1171 | execute_out_code = self.attribute_execute_out.generate_code()
1172 |
1173 | if not color_coded:
1174 | return f"{ind()}for {it1_code}, {it2_code} in {self.iterate_func}({table_name}) do\n{execute_code}{ind()}end\n{execute_out_code}"
1175 | else:
1176 | inc_ind()
1177 | execute_code_colored = self.attribute_code_to_execute.generate_code(color_coded=True)
1178 | dec_ind()
1179 |
1180 | it1_code_colored = self.attribute_it1.generate_code(color_coded=True)
1181 | it2_code_colored = self.attribute_it2.generate_code(color_coded=True)
1182 | table_name_colored = self.attribute_table.generate_code(color_coded=True)
1183 |
1184 | execute_out_code_colored = self.attribute_execute_out.generate_code(color_coded=True)
1185 |
1186 | return [
1187 | [ind()],
1188 | ["for ", color_keyword]
1189 | ] + it1_code_colored + [
1190 | [", ", color_default]
1191 | ] + it2_code_colored + [
1192 | [" in ", color_keyword],
1193 | [self.iterate_func, color_keyword],
1194 | ["(", color_default]
1195 | ] + table_name_colored + [
1196 | [") ", color_default],
1197 | ["do", color_keyword],
1198 | ["\n"]
1199 | ] + execute_code_colored + [
1200 | [ind()],
1201 | ["end", color_keyword],
1202 | ["\n"]
1203 | ] + execute_out_code_colored
1204 |
1205 |
1206 | class LuaNodeIterateIPairs(LuaNodeIteratePairs):
1207 | def __init__(self):
1208 | super().__init__("i", "value", "pairs", "Iterate IPairs")
1209 | self.node_type = lua_ntIterateIPairs
1210 |
--------------------------------------------------------------------------------