Skip to content

Commit

Permalink
learn C3 WASM example
Browse files Browse the repository at this point in the history
  • Loading branch information
brentharts authored Nov 23, 2024
1 parent 3c087a2 commit 56036f9
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions libguizag.py
Original file line number Diff line number Diff line change
Expand Up @@ -1568,14 +1568,35 @@ def load_random(self):
btn = QPushButton('next', self.edit)
btn.clicked.connect(lambda b: self.load_random())

def load(self, tag):
tag = os.path.sep + tag
clear_layout(self.main_vbox)
ok = None
for md in self.mds:
if md.endswith(tag):
ok = md
break
if ok:
self.setWindowTitle(md)
md = open(md).read()
html = self.parse_md(md)
self.edit = edit = QTextEdit()
edit.setHtml(html)
if self.zoomout:
edit.zoomOut(self.zoomout)
self.main_vbox.addWidget(edit)

btn = QPushButton('next', self.edit)
btn.clicked.connect(lambda b: self.load_random())

def parse_md(self, md):
o = []
in_backticks = False
for ln in md.splitlines():
print(ln)
if ln.startswith('title:'):
title = ln.split('title:')[-1].strip()
o.append('<h1>Example: %s</h1>' % title)
o.append('<h2>Example: %s</h2>' % title)
continue
elif ln.strip()=='---':
o.append('<hr/>')
Expand All @@ -1589,7 +1610,7 @@ def parse_md(self, md):
o.append('<pre style="background-color:lightgray">')
continue
elif ln.startswith('- '):
o.append('<span style="font-size:20px">•%s</span>' % ln)
o.append('<span style="font-size:18px">•%s</span>' % ln)
continue
elif ln.startswith('weight:'):
continue
Expand All @@ -1607,7 +1628,7 @@ def parse_md(self, md):
code = code[1:-2]
code = code.replace('\\"', '"')
code = code.replace('<', '&lt;').replace('>', '&gt;')
o.append('<h1>C3 Code:</h1><pre>%s</pre>' % code)
o.append('<h3>C3 Code:</h3><pre>%s</pre>' % code)
continue
if in_backticks and ln.startswith('//'):
o.append('<i style="font-size:16px; background-color:gray; color:white">%s</i>' % ln)
Expand All @@ -1633,6 +1654,8 @@ def open_code_editor(self, *args):
def learn_c3(self):
w = self.blendgen("🐵")
w.editor.textCursor().insertText(choice(LEARN_C3).strip())
learn_wasm = ['wasm1.md', 'wasm2.md', 'wasm3.md']
w.learn_c3_widget.load(choice(learn_wasm))

def blendgen(self, sym):
if sys.platform=='win32':
Expand Down

0 comments on commit 56036f9

Please sign in to comment.