Skip to content

Commit 643331f

Browse files
committed
feat: add built-in actions
1 parent d7a0082 commit 643331f

1 file changed

Lines changed: 40 additions & 7 deletions

File tree

‎src/components/App.vue‎

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template lang="pug">
2-
.app
2+
.app(:style="backdropStyle")
33
.panel.display-panel
4-
h1 Voice Kit
4+
h1 {{message}}
55
.panel.editor-panel
66
.editor-titlebar
77
.editor-window-decoration
@@ -30,7 +30,6 @@
3030
align-items: center
3131
justify-content: center
3232
min-height: 100vh
33-
background: #9b59b6
3433
width: 60%
3534
3635
h1
@@ -158,12 +157,30 @@ const cmOptions: EditorConfiguration = {
158157
viewportMargin: Infinity,
159158
}
160159
161-
const starterCode = `print("Hello, World!")`.trim()
160+
const starterCode = `
161+
print("Hello, World!")
162+
showText("Welcome to Voice Kit!")
163+
setColor("#8e44ad")
164+
`.trim()
165+
166+
function withExtras(code: string) {
167+
const extras = `
168+
from browser import window
169+
170+
def setColor(color):
171+
window.eval("setColor(\`%s\`)" % color)
172+
173+
def showText(text):
174+
window.eval("showText(\`%s\`)" % text)
175+
`.trim()
176+
177+
return extras + '\n' + code
178+
}
162179
163180
function run(code: string) {
164181
if (!window.__BRYTHON__) return
165182
166-
const js = window.__BRYTHON__.python_to_js(code)
183+
const js = window.__BRYTHON__.python_to_js(withExtras(code))
167184
168185
console.groupCollapsed('ℹ️ Translating Python to JavaScript')
169186
console.log('Python:', code)
@@ -182,10 +199,13 @@ export default Vue.extend({
182199
code: starterCode,
183200
cmOptions,
184201
logs: [],
202+
message: 'Voice Kit',
203+
color: '#9b59b6',
185204
}),
186205
187206
mounted() {
188-
window.app = this
207+
window.showText = (text: string) => (this.message = text)
208+
window.setColor = (color: string) => (this.color = color)
189209
},
190210
191211
methods: {
@@ -206,11 +226,24 @@ export default Vue.extend({
206226
if (error.$py_error) {
207227
this.logs = [
208228
...this.logs,
209-
{ text: `${error.msg} at line ${error.lineno}`, type: 'error' },
229+
{
230+
text:
231+
`${error.args[0]}` +
232+
(error.lineno ? `at line ${error.lineno}` : ''),
233+
type: 'error',
234+
},
210235
]
211236
}
212237
}
213238
},
214239
},
240+
241+
computed: {
242+
backdropStyle() {
243+
return {
244+
background: this.color,
245+
}
246+
},
247+
},
215248
})
216249
</script>

0 commit comments

Comments
 (0)