-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
87 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# LTK - Copyright 2023 - All Rights Reserved - chrislaffra.com - See LICENSE | ||
|
||
import ltk | ||
|
||
source = """ | ||
ltk.VBox( | ||
# edit this text and see what happens | ||
ltk.HBox( | ||
ltk.Span("Edit the text").css("margin", 12), | ||
ltk.Span("In the editor below"), | ||
) | ||
.css("height", 40) | ||
.css("background", "lightblue") | ||
.css("border", "1px solid gray"), | ||
ltk.HBox( | ||
ltk.Span("This UI will update live").css("margin", 12), | ||
ltk.Span("With every character you type!").css("margin-top", 24), | ||
) | ||
.css("height", 80) | ||
.css("background", "lightyellow") | ||
.css("border", "1px solid gray"), | ||
) | ||
""".strip() | ||
|
||
def create(): | ||
editor = Editor(source) | ||
|
||
def show_output(): | ||
print(editor.text()) | ||
eval(editor.text()).appendTo( | ||
ltk.find("#editor-output") | ||
.empty() | ||
) | ||
|
||
ltk.schedule(ltk.proxy(lambda: show_output()), "show output", 0.1) | ||
|
||
return( | ||
ltk.VerticalSplitPane( | ||
ltk.Div() | ||
.css("border", "1px solid gray") | ||
.attr("id", "editor-output"), | ||
editor | ||
.on("keyup", ltk.proxy(lambda event: show_output())) | ||
.css("border", "1px solid gray") | ||
.attr("id", "editor"), | ||
"interactive editor" | ||
) | ||
.css("height", 805) | ||
.css("width", 400) | ||
.css("font-size", 14) | ||
.attr("name", "Editor") | ||
) | ||
|
||
class Editor(ltk.Div): | ||
classes = [ "editor" ] | ||
|
||
def __init__(self, value): | ||
ltk.Div.__init__(self) | ||
ltk.schedule(ltk.proxy(lambda: self.create(value)), "refresh editor", 0.1) | ||
|
||
def create(self, value): | ||
config = ltk.to_js({ | ||
"mode": { | ||
"name": "python", | ||
"version": 3, | ||
"singleLineStringErrors": False | ||
}, | ||
"lineNumbers": True, | ||
"indentUnit": 4, | ||
"matchBrackets": True, | ||
}) | ||
self.editor = ltk.window.CodeMirror(self.element[0], config) | ||
self.editor.setSize("100%", "100%") | ||
self.text(value) | ||
|
||
def text(self, text=None): | ||
return self.editor.setValue(text) if text is not None else self.editor.getValue() |
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