Python: Replace import magic with an auto-loader

As discussed on Reddit, the magic import logic is not very tool friendly and a little too magic perhaps. Instead, this patch introduces an automatic loader (`slint.loader`), which can traverse `sys.path` and lazily load `.slint` files by attribute lookup.

Closes #4856
This commit is contained in:
Simon Hausmann 2024-04-18 15:51:28 +02:00 committed by Simon Hausmann
parent 93307707cd
commit f86f4993fa
6 changed files with 48 additions and 52 deletions

View file

@ -1,18 +1,15 @@
# Copyright © SixtyFPS GmbH <info@slint.dev>
# SPDX-License-Identifier: MIT
# autopep8: off
from slint import Color, ListModel, Timer, TimerMode
import slint
from datetime import timedelta, datetime
import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), "..", "ui"))
import slint
from slint import Color, ListModel, Timer, TimerMode
import printerdemo_slint
# autopep8: on
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
class MainWindow(printerdemo_slint.MainWindow):
class MainWindow(slint.loader.ui.printerdemo.MainWindow):
def __init__(self):
super().__init__()
self.ink_levels = ListModel([