basic_proto

This commit is contained in:
bklronin
2024-05-09 22:07:06 +02:00
parent 36db883433
commit c11f47a2b6
4 changed files with 28 additions and 6 deletions

24
main.py
View File

@@ -1,6 +1,7 @@
from PySide6.QtWidgets import QApplication, QMainWindow, QSizePolicy
from Gui import Ui_fluencyCAD # Import the generated GUI module
from modules.gl_widget import OpenGLWidget
from sdf import *
class MainWindow(QMainWindow):
@@ -16,13 +17,34 @@ class MainWindow(QMainWindow):
# Connect the resizeEvent of the parent widget to a function
self.ui.gl_canvas.resizeEvent = self.glCanvasResized
self.ui.pb_apply_code.pressed.connect(self.generate_mesh)
def generate_mesh(self):
code_bytes = self.ui.textEdit.toPlainText().encode('utf-8')
code_text = code_bytes.decode('utf-8')
save_string = "\nf.save('out.stl', samples=2**10)"
code_text += save_string
local_vars = {}
try:
print(code_text)
exec(code_text, globals(), local_vars)
# Retrieve the result from the captured local variables
result = local_vars.get('result')
print("Result:", result)
mesh = self.openGLWidget.load_stl("out.stl")
self.openGLWidget.draw_stl(mesh)
except Exception as e:
print("Error executing code:", e)
def glCanvasResized(self, event):
# Get the size of the gl_canvas
canvas_size = self.ui.gl_canvas.size()
# Resize the OpenGL widget to match the size of the gl_canvas
self.openGLWidget.resize(canvas_size)
if __name__ == "__main__":
app = QApplication([])
window = MainWindow()