Package: pyscript-ltk
ltkLTK is a little toolkit for writing UIs in PyScript. For an explanation of PyScript and LTK, seeYouTube.For examples see:TheLTK kitchensinkfor a live demo of all the widgets.Why use LTK? See thepitch, written with LTK, of course.Thedocs rendered using LTK.A personal website,chrislaffra.com, which uses a number of animations, svg, styling, and timers to render a visual resume.An animatedHoliday cardwhere PyScript logo tree ornaments are animated using Python code in the browser using LTK.LTK is implemented as a declarative Python library and leveragesjQueryfor DOM operations.Installing LTKInstall LTK from pypi:python3 -m pip install pyscript-ltkHello Worldimportltkltk.Text("Hello World").appendTo(ltk.body)Getting StartedTo get started with LTK, we recommend you try it out on pyscript.com:Minimal LTK with MicroPythonMinimal LTK with PyOdideWidget SpecificationNew widget types are created by subclassingltk.Widget:classHBox(Widget):classes=["ltk-hbox"]By default, widgets are created asdivDOM elements. You can choose a different tag:classPreformatted(Widget):classes=["ltk-pre"]tag="pre"Creating a UITo create a UI, elements are constructed declaratively:ltk.Table(ltk.TableRow(ltk.TableHeader("header1")ltk.TableHeader("header2")),[ltk.TableRow(ltk.TableData(value1),ltk.TableData(value2),)forvalue1,value2indata],)Widgets are added to others by usingjQuery'sappendandappendTocalls:ltk.body.append(ltk.Table(...).element)container=ltk.VBox(...)ltk.H1("This is a header").appendTo(container)When an LTK widget is created, a corresponding jQuery element is attached to it in
theltk.Widget.__init__constructor. It uses thetagvalue defined by the
declaring class and the constructed element is referred to aselement.
As theappendcall is a JavaScript function, implemented by jQuery, we do not
pass the LTK widget directly, but pass itselementto append to the DOM.StylingWidgets can be styled using using three different approaches:Styling with element styles usingjQuery'scssfunction:ltk.Text("Error: Flux capacitor low!").css("background-color","red").css("color","white").css("padding",8)Styling using adictto make it easier to share styles:error={"background-color":"red","color":"white","padding":8,}ltk.Text("Error: Flux capacitor low!",error)Styling using CSS classes and an external stylesheet, usingjQuery'saddClassfunction:ltk.Text("Some text").addClass("my-special-text)The external style sheet should have these rules:.ltk-text{font-family:Arial;}.my-special-text{font-family:Courier;background-color:red;color:white;padding:8px;}External stylesheets can be included in the originalindex.htmlor injected at runtime from Python using:ltk.inject_style("https://example.org/awesome_styles.css")EventsEvent handlers are attached usingjQuerymechanisms.defbuy(event):purchase(...)ltk.Card("Buy Now").on("click",ltk.proxy(buy))You can also use the more declarative decorator:@ltk.callbackdefbuy(event):purchase(...)ltk.Card("Buy Now").on("click",buy)ExamplesSee theLTK kitchensinkor explore theexamplesfolderApplications built using LTKPySheets (more details soon)LicenseLTK is covered under the Apache License:The Apache license is a permissive open source software license.It allows users to freely use, modify, and distribute the software (including for commercial purposes).Modified versions can be distributed without having to release the source code. Though source code changes should be documented.The license requires modified versions to retain the Apache license and copyright notice.The software is provided by the authors "as is" with no warranties.Users are not granted patent rights by contributors, but contributors cannot revoke patent grants for previous contributions.The license does not require derived works to adopt the Apache license. Though this is encouraged for consistency.Upload new version to PyPiFirst build the package into a source distribution and a Python wheel:python3 -m pip install --user --upgrade setuptools wheel twine buildpython3 -m buildThen verify whether the build works for pypi:twine check dist/*Then upload to the pypi test environment:twine upload --repository pypitest dist/*Finally, if the pypi test upload appears to work fine, run:twine upload dist/*