camper/.ipynb_checkpoints/snippets_panel-checkpoint.py

56 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from IPython.display import display
from IPython import get_ipython
import ipywidgets as widgets
def show_snippet_panel():
snippets = {
"📥 Start": '''
from build123d import *
from jupyter_cadquery import show, show_all,open_viewer, show_clear
from IPython.display import display
import ipywidgets as widgets''',
"🧲 Import STEP": '''from build123d import *
model = import_step("element.step")
show_object(model)''',
"🖥️ view": '''
cv = None # viewer globalny
def open_bottom(b):
global cv
print("Otwieram viewer (split-bottom)")
cv = open_viewer("Build123d", anchor="split-bottom")
def open_right(b):
global cv
print("Otwieram viewer (right)")
cv = open_viewer("Build123d", anchor="right")
# Przycisk 1 bottom
btn_bottom = widgets.Button(description="Viewer dół")
btn_bottom.on_click(open_bottom)
# Przycisk 2 right
btn_right = widgets.Button(description="Viewer prawo")
btn_right.on_click(open_right)
# Wyświetl przyciski
display(widgets.HBox([btn_bottom, btn_right]))
'''
}
dropdown = widgets.Dropdown(
options=["-- wybierz snippet --"] + list(snippets.keys()),
description="Snippet:"
)
def on_select(change):
key = change["new"]
if key != "-- wybierz snippet --":
get_ipython().set_next_input(snippets[key], replace=False)
dropdown.value = "-- wybierz snippet --"
dropdown.observe(on_select, names="value")
display(dropdown)