mirror of
				https://github.com/slint-ui/slint.git
				synced 2025-11-03 21:24:17 +00:00 
			
		
		
		
	doc: Add Python language tabs for various sections in the docs
cc #4139
This commit is contained in:
		
							parent
							
								
									9d5984dfa8
								
							
						
					
					
						commit
						95aaf73653
					
				
					 4 changed files with 67 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -145,6 +145,31 @@ for each accessible callback in `Recipe`. In this case we will have `get_counter
 | 
			
		|||
`set_counter` to access the `counter` property and `on_button_pressed` to
 | 
			
		||||
set up the callback.
 | 
			
		||||
 | 
			
		||||
</TabItem>
 | 
			
		||||
 | 
			
		||||
<TabItem label="Python">
 | 
			
		||||
 | 
			
		||||
In Python, you can write:
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
```python
 | 
			
		||||
import slint
 | 
			
		||||
 | 
			
		||||
class App(slint.loader.recipe.Recipe):
 | 
			
		||||
    @slint.callback
 | 
			
		||||
    def button_pressed(self):
 | 
			
		||||
        value = self.counter
 | 
			
		||||
        value = value + 1
 | 
			
		||||
        self.counter = value
 | 
			
		||||
 | 
			
		||||
app = App()
 | 
			
		||||
app.run()
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
The Slint auto-loader provides a `Recipe` class originating from `recipe.slint`, which is subclassed.
 | 
			
		||||
The `Recipe` class provides the `counter` property, and the `@slint.callback` decorator connects the
 | 
			
		||||
`button_pressed` method with the `button-pressed` callback.
 | 
			
		||||
 | 
			
		||||
</TabItem>
 | 
			
		||||
</Tabs>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -487,6 +512,21 @@ recipe.Logic.to_upper_case = (str) => {
 | 
			
		|||
// ...
 | 
			
		||||
```
 | 
			
		||||
</TabItem>
 | 
			
		||||
<TabItem label="Python">
 | 
			
		||||
 | 
			
		||||
In Python, the callback is assocated with the `global_name` parameter of the `@slint.callback` decorator:
 | 
			
		||||
 | 
			
		||||
```python
 | 
			
		||||
import slint
 | 
			
		||||
 | 
			
		||||
class App(slint.loader.recipe.Recipe):
 | 
			
		||||
    @slint.callback(global_name="Logic")
 | 
			
		||||
    def to_upper_case(&self, value: str) -> str:
 | 
			
		||||
        return value.upper()
 | 
			
		||||
 | 
			
		||||
# ...
 | 
			
		||||
```
 | 
			
		||||
</TabItem>
 | 
			
		||||
</Tabs>
 | 
			
		||||
 | 
			
		||||
# Custom Widgets
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -90,6 +90,22 @@ app.Logic.the_value = 42;
 | 
			
		|||
// ...
 | 
			
		||||
```
 | 
			
		||||
</TabItem>
 | 
			
		||||
<TabItem label="Python">
 | 
			
		||||
 | 
			
		||||
```python
 | 
			
		||||
import slint
 | 
			
		||||
 | 
			
		||||
class App(slint.loader.app.App):
 | 
			
		||||
    @slint.callback(global_name="Logic")
 | 
			
		||||
    def magic_operation(self, value: int) -> int:
 | 
			
		||||
        return value * 2
 | 
			
		||||
 | 
			
		||||
app = new App()
 | 
			
		||||
app.Logic.the_value = 42
 | 
			
		||||
 | 
			
		||||
# ...
 | 
			
		||||
```
 | 
			
		||||
</TabItem>
 | 
			
		||||
</Tabs>
 | 
			
		||||
 | 
			
		||||
It's possible to re-expose a callback or properties from a global using the two way binding syntax.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -55,6 +55,13 @@ set_property(TARGET my_program APPEND PROPERTY WIN32_EXECUTABLE TRUE)
 | 
			
		|||
```
 | 
			
		||||
 | 
			
		||||
</TabItem>
 | 
			
		||||
 | 
			
		||||
<TabItem label="Python">
 | 
			
		||||
Change the extension of your Python script from `.py` to `.pyw`, the default Python interpreter associated with
 | 
			
		||||
Python files will launch without a console window. Alternatively, use `pythonw.exe` instead of `python.exe` to launch
 | 
			
		||||
your Python script.
 | 
			
		||||
</TabItem>
 | 
			
		||||
 | 
			
		||||
</Tabs>
 | 
			
		||||
</TabItem>
 | 
			
		||||
<TabItem label="macOS" icon="apple">
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -176,6 +176,10 @@ Some image formats can be disabled using cargo features to reduce binary size an
 | 
			
		|||
In JavaScript properties or struct fields of the image type are mapped an object that implement the <LangRefLink lang="nodejs" relpath="interfaces/ImageData.html">ImageData interface</LangRefLink>.
 | 
			
		||||
</TabItem>
 | 
			
		||||
 | 
			
		||||
<TabItem label="Python" >
 | 
			
		||||
In Python, properties or struct fields of the image type are mapped to <LangRefLink lang="python" relpath="slint.html#Image">`Image`</LangRefLink>.
 | 
			
		||||
</TabItem>
 | 
			
		||||
 | 
			
		||||
</Tabs>
 | 
			
		||||
 | 
			
		||||
Access an `image`'s dimension using its `width` and `height` properties.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue