Skip to content

Commit

Permalink
C3 example hello world js_eval
Browse files Browse the repository at this point in the history
  • Loading branch information
brentharts authored Nov 23, 2024
1 parent 7d57d8e commit 3c087a2
Showing 1 changed file with 41 additions and 26 deletions.
67 changes: 41 additions & 26 deletions libguizag.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,12 @@ class ZigZagEditor( MegasolidCodeEditor ):
CYRILLIC = tuple('Ѐ Ё Ђ Ѓ Є Ї Љ Њ Ћ Ќ Ѝ Ў Џ Б Д Ж И Й Л Ф Ц Ш Щ Ъ Э Ю Я'.split())

def close(self):
print('closing...')
self._parent.show()
super().close()

def update_title(self):
self.setWindowTitle("%s - ZigZag" % (os.path.basename(self.path) if self.path else "Untitled"))

def debug_chat(self, msg):
if not self._debug_chat:
self._debug_chat_bubble = lab = ClickLabel('🗨', self.glview)
Expand Down Expand Up @@ -261,6 +263,10 @@ def reset(self, parent=None):
act.triggered.connect( self.export_html )
self.format_toolbar.addAction(act)

spacer = QWidget()
spacer.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum)
self.format_toolbar.addWidget(spacer)

self._is_fs = False ## this is only required on Linux/Wayland?
self.setFullscreen = QAction("❖", self)
self.setFullscreen.setShortcut("F11")
Expand All @@ -269,9 +275,6 @@ def reset(self, parent=None):
self.setFullscreen.triggered.connect(self.toggle_fs)
self.format_toolbar.addAction(self.setFullscreen)

spacer = QWidget()
spacer.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum)
self.format_toolbar.addWidget(spacer)

self.exit_button = QPushButton("✖")
self.exit_button.setToolTip('close window')
Expand Down Expand Up @@ -765,9 +768,9 @@ def update_active_materials(self):
if not self.active_blend: return
blend = self.active_blend
info = self.active_object
rthresh = 4
rthresh = 5
if self._is_fs:
rthresh = 8
rthresh = 13

#print(dir(self.materials_layout))
clear_layout(self.materials_layout)
Expand All @@ -779,39 +782,49 @@ def update_active_materials(self):
sub.setContentsMargins(1,1,1,1)
container.setLayout(sub)
#sub = self.materials_layout
container.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
container.setSizePolicy(QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Minimum)

row = []
for mat in info['materials']:
self.shared_materials[mat['name']] = mat

box = QVBoxLayout()
if self._is_fs:
box = QVBoxLayout()
else:
box = QHBoxLayout()
con = QWidget()
#con.setFixedHeight(70)
if self._is_fs:
con.setFixedHeight(60)
else:
box.setContentsMargins(1,1,1,1)
con.setFixedHeight(30)
con.setLayout(box)
mat['WIDGET'] = con
row.append(con)

lab = QLabel(mat['name'])
if self._is_fs:
lab.setStyleSheet('font-size:14px')
else:
lab.setStyleSheet('font-size:10px')
box.addWidget(lab)

if 'class' in mat:
btn = QPushButton(mat['class'])
btn.setFixedHeight(16)
btn.setFixedWidth(60)
btn.setStyleSheet('font-size:8px')
box.addWidget(btn)
if False:
lab = QLabel(mat['name'])
if self._is_fs:
lab.setStyleSheet('font-size:14px')
else:
lab.setStyleSheet('font-size:10px')
box.addWidget(lab)

if 'class' in mat and self._is_fs:
btn = QPushButton(mat['class'])
btn.setFixedHeight(16)
btn.setFixedWidth(60)
btn.setStyleSheet('font-size:8px')
box.addWidget(btn)

msym = self.material_sym(mat['name'], blend)
btn = QPushButton( msym )
btn.setToolTip(mat['name'])
if self._is_fs:
btn.setStyleSheet('font-size:32px')
btn.setFixedWidth(50)
#btn.setStyleSheet('font-size:22px')
btn.setFixedWidth(32)
else:
#btn.setStyleSheet('font-size:14px')
btn.setFixedWidth(32)
box.addWidget(btn)
btn.clicked.connect(lambda a,s=msym: self.insert_material(s))
Expand Down Expand Up @@ -1503,8 +1516,10 @@ def add(self, ob):
"""
.c3.script = '''
fn void onclick( int x, int y ) {
fn void onclick( int x, int y ) @extern("onclick") @wasm {
js_eval(`
window.alert("hello click")
`);
}
'''
Expand Down

0 comments on commit 3c087a2

Please sign in to comment.