-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Brython + improve signals, do not use Set
- Loading branch information
1 parent
a9980a0
commit 664ea00
Showing
14 changed files
with
217 additions
and
118 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from browser import self | ||
|
||
WebC = self.wrapjs(self.LISS()) | ||
|
||
class DefaultExport(WebC): | ||
def __init__(this): | ||
this.content.replaceChildren("Hello!") | ||
|
||
def foo(this): | ||
print( self.document.querySelector("test-bry").faa() ) | ||
|
||
def faa(this): | ||
print(2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// @ts-ignore | ||
/* | ||
import {test} from "TEST_HELPER"; | ||
await test("cstr-params", | ||
`<cstr-params></cstr-params>`, | ||
async () => { | ||
// @ts-ignore | ||
await assertElemEquals('cstr-params', { | ||
shadow_html: "HTML" | ||
}); | ||
} | ||
)*/ |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import executeJS from "./js"; | ||
|
||
// @ts-ignore | ||
globalThis.getProp = function(target, name) { | ||
return target[name]; | ||
} | ||
|
||
// can't use WebPack require() if we want to use it directly... | ||
const bry_wrapper = `from browser import self | ||
def wrapjs(js_klass): | ||
class Wrapper: | ||
_js_klass = js_klass # TODO: replace ? | ||
_js = None | ||
def __new__(cls): | ||
this = super().__new__(cls) | ||
if "brython_wrapper_js" in self: | ||
this._js = self.brython_wrapper_js | ||
else: | ||
# TODO: set it during define... | ||
this._js = this._js_klass.new() # no args | ||
return this | ||
def __getattr__(this, name: str): | ||
print( name in this._js, var(this._js) ) | ||
return self.getProp(this._js, name) | ||
#return this._js[name] | ||
def __setattr__(this, name: str, value): | ||
if name == "_js": | ||
super().__setattr__(name, value) | ||
return | ||
this._js[name] = value | ||
return Wrapper | ||
self.wrapjs = wrapjs`; | ||
|
||
let wrapper_loaded = false; | ||
|
||
export default async function executeBry<T>(code: string, origin: string): Promise<T> { | ||
|
||
if( ! wrapper_loaded ) { | ||
await executeJS(`globalThis.__BRYTHON__.runPythonSource(\`${bry_wrapper}\`, "_")`); | ||
wrapper_loaded = true; | ||
} | ||
|
||
// Brython library needs to have been loaded. | ||
const jscode = `const $B = globalThis.__BRYTHON__; | ||
$B.runPythonSource(\`${code}\`, "_"); | ||
const module = $B.imported["_"]; | ||
export default module.DefaultExport;`; | ||
|
||
return await executeJS(jscode, origin); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
import executeBry from "./bry"; | ||
import executeJS from "./js"; | ||
|
||
export default async function execute<T>(code: string, type: "js", origin: string): Promise<T> { | ||
const EXEC = { | ||
js : executeJS, | ||
bry: executeBry | ||
} | ||
|
||
if( type === "js" ) | ||
return await executeJS<T>(code, origin); | ||
export default async function execute<T>(code: string, type: "js"|"bry", origin: string): Promise<T> { | ||
|
||
throw new Error(''); | ||
return await EXEC[type]<T>(code, origin); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.