basic_proto
This commit is contained in:
24
main.py
24
main.py
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user