PySciter Documentation

repository·master·Indexed 19 days ago

https://github.com/sciter-sdk/pysciter

Python bindings for the Sciter engine. Provides access to sciter::window, sciter::host, sciter::event_handler, sciter::dom, and sciter::value modules. Supports window creation, DOM manipulation, and bidirectional interoperability between Python and TIScript/JavaScript on Windows, OSX, Linux, and Raspberry Pi.

Tokens
949
Snippets
4
Records
5
Agent score
14%

What's inside PySciter

  1. Expose Python functions to Sciter script (Interoperability)

    master

    To allow TIScript or JavaScript to call Python code, define a dictionary of Python functions (or lambdas) and return it from a function that is called by the Sciter EventHandler.on_script_call.

    Python Implementation

    def GetNativeApi():
        def on_add(a, b):
            return a + b
    
        def on_sub(a, b):
            raise Exception("sub(%d,%d) raised exception" % (a, b))
    
        api = {
            'add': on_add,
            'sub': on_sub,
            'mul': lambda a, b: a * b
        }
        return api

    Accessing from TIScript

    var api = view.GetNativeApi();
    stdout.println("2 + 3 = " + api.add(2, 3));

    Accessing from JavaScript

    const api = Window.this.GetNativeApi();
    console.log("2 + 3", api.add(2, 3));
    def GetNativeApi():
      def on_add(a, b):
          return a + b
    
      def on_sub(a, b):
          raise Exception("sub(%d,%d) raised exception" % (a, b))
    
      api = { 'add': on_add,
              'sub': on_sub,
              'mul': lambda a,b: a * b }
      return api
    
    # In JS:
    const api = Window.this.GetNativeApi();
    console.log("2 + 3", api.add(2, 3));
  2. Install PySciter

    master

    To use PySciter, follow these steps to set up the Sciter engine and the Python bindings:

    1. Download the Sciter SDK: Download the Sciter.TIS or Sciter.JS SDK and extract it.
    2. Configure Environment:
      • Add the target platform binaries to your PATH (e.g., bin.win/x64, bin.osx, or bin.lnx/x64).
      • Install the Sciter shared library to your LIBRARY_PATH.
    3. Install Python Bindings: Use pip to install the package:
      pip install pysciter
    4. Verify Installation: Run the minimal sample to ensure everything is working:
      python3 examples/minimal.py
    pip install pysciter
  3. Create a minimal PySciter application

    master

    A basic Sciter application in Python involves creating a sciter.Window, loading an HTML file, and starting the application loop.

    Note: ismain=True designates the main window, and uni_theme=True enables the universal theme.

    import sciter
    
    if __name__ == '__main__':
        frame = sciter.Window(ismain=True, uni_theme=True)
        frame.load_file("minimal.htm")
        frame.expand()
        frame.run_app()
    import sciter
    
    if __name__ == '__main__':
        frame = sciter.Window(ismain=True, uni_theme=True)
        frame.load_file("minimal.htm")
        frame.expand()
        frame.run_app()
  4. Call Sciter script functions from Python

    master

    You can invoke functions defined in your HTML/JS/TIScript environment directly from Python using the call_function method on a window object. You can pass multiple arguments, including lists.

    # Inside a window/frame context
    answer = self.call_function('script_function', "hello, python!", "and", ["other", 3, "arguments"])
    answer = self.call_function('script_function', "hello, python!", "and", ["other", 3, "arguments"])
  5. Supported PySciter modules and features

    master

    The following Sciter core modules are currently supported via PySciter bindings:

    • sciter::window: Handles window creation, hosting, and event handlers.
    • sciter::host: Provides an extensible implementation for transparent script calls from Python.
    • sciter::event_handler: Provides basic event handling (e.g., attached, document_complete, on_script_call).
    • sciter::dom: Provides methods for HTML DOM access and manipulation.
    • sciter::value: A Pythonic wrapper for Sciter values, supporting sciter::script_error and sciter::native_function.

    Supported Platforms: Windows, OSX, Linux, and Raspberry Pi (Python 3.x).