⚡Using PySide6 Features for API Customizing
Pyloid is built on PySide6 and provides functionality for users to extend the API directly. This allows easy use of various PySide6 features in Pyloid applications.
How to Create Custom APIs
Inherit from the
PyloidAPI
class to create a new class.Define desired methods and use the
@Bridge
decorator to connect with JavaScript.Utilize PySide6 features within the methods.
Examples
Implementing File Open Dialog
Implementing Message Box
How to Use
Define custom API classes.
Pass API instances when creating a Pyloid application.
Using the API in HTML/JavaScript:
Implementing Desired Functionality Directly Using QMainWindow
You can obtain a PySide6 QMainWindow instance through the get_QMainWindow()
method from the BrowserWindow instance created by the app.create_window() function. This allows you to implement desired functionality directly.
Precautions
When using the
@Bridge
decorator, you must specify the types of input parameters and return values. For example:No input parameters and returns a string:
@Bridge(result=str)
Takes two strings as input and returns a boolean:
@Bridge(str, str, result=bool)
Takes an integer as input and returns a string:
@Bridge(int, result=str)
When returning complex objects, they must be converted to a JSON-serializable form.
UI-related tasks should be executed on the main thread.
In this way, you can integrate various PySide6 features into Pyloid applications. More complex features like QtSql
, QtBluetooth
, QtMultimedia
, QtNetwork
, etc., can also be implemented as needed.
Last updated