Skip to content

Commit

Permalink
Handle MicroPython and support worker access to window
Browse files Browse the repository at this point in the history
  • Loading branch information
laffra committed Nov 19, 2023
1 parent 71bcdcf commit 5419c14
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 41 deletions.
8 changes: 4 additions & 4 deletions ltk/jquery.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# LTK - Copyrights Reserved 2023 - chrislaffra.com - See LICENSE

import js # type: ignore
import json
import os
import pyodide # type: ignore

import pyscript # type: ignore

timers = {}

js = pyscript.window

jQuery = js.jQuery
console = js.console
window = jQuery(js.window)
Expand Down Expand Up @@ -62,7 +62,7 @@ def delete(route, handler):
return js.ajax(route, "DELETE", wrapper)

def time():
return js.time()
return js.time() / 1000

def post(route, data, handler):
payload = js.encodeURIComponent(json.dumps(data))
Expand Down
80 changes: 44 additions & 36 deletions ltk/ltk.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,54 @@
/* LTK - Copyrights Reserved 2023 - chrislaffra.com - See LICENSE */

function table() {
return $("<table>").addClass("ltk-table");
}
(function ltk() {
const start = new Date().getTime();

function tableTitle(table, column, title) {
var header = table.find("tr");
if (!header.length) {
header = $("<tr>")
.addClass("ltk-table-header")
.appendTo(table);
window.time = () => {
return (new Date().getTime() - start)
}
for (var n=header.find(".ltk-table-title").length; n<=column; n++) {
$("<th>")
.addClass("ltk-table-title")
.appendTo(header);

window.table = () => {
return $("<table>").addClass("ltk-table");
}
header.find(".ltk-table-title").eq(column).text(title)
}

function tableCell(table, column, row) {
for (var n=table.find(".ltk-table-row").length; n<=row; n++) {
$("<tr>")
.addClass("ltk-table-row")
.addClass(`ltk-row-${n}`)
.appendTo(table);
window.tableTitle = (table, column, title) => {
var header = table.find("tr");
if (!header.length) {
header = $("<tr>")
.addClass("ltk-table-header")
.appendTo(table);
}
for (var n=header.find(".ltk-table-title").length; n<=column; n++) {
$("<th>")
.addClass("ltk-table-title")
.appendTo(header);
}
header.find(".ltk-table-title").eq(column).text(title)
}
const rowElement = table.find(".ltk-table-row").eq(row)
for (var n=rowElement.find(".ltk-table-cell").length; n<=column; n++) {
$("<td>")
.addClass("ltk-table-cell")
.addClass(`ltk-row-${row}`)
.addClass(`ltk-col-${n}`)
.appendTo(rowElement);

window.tableCell = (table, column, row) => {
for (var n=table.find(".ltk-table-row").length; n<=row; n++) {
$("<tr>")
.addClass("ltk-table-row")
.addClass(`ltk-row-${n}`)
.appendTo(table);
}
const rowElement = table.find(".ltk-table-row").eq(row)
for (var n=rowElement.find(".ltk-table-cell").length; n<=column; n++) {
$("<td>")
.addClass("ltk-table-cell")
.addClass(`ltk-row-${row}`)
.addClass(`ltk-col-${n}`)
.appendTo(rowElement);
}
return rowElement.find(".ltk-table-cell").eq(column)
}
return rowElement.find(".ltk-table-cell").eq(column)
}

function tableGet(table, column, row) {
return tableCell(table, column, row).text()
}
window.tableGet = (table, column, row) => {
return tableCell(table, column, row).text()
}

function tableSet(table, column, row, value) {
tableCell(table, column, row).text(value)
}
window.tableSet = (table, column, row, value) => {
tableCell(table, column, row).text(value)
}
})()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pyscript-ltk"
version = "0.1.5"
version = "0.1.7"
description = "A little toolkit for writing UIs in PyScript"
readme = "README.md"
authors = [{ name = "Chris Laffra", email = "chris@chrislaffra.com" }]
Expand Down

0 comments on commit 5419c14

Please sign in to comment.