mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-02 04:48:27 +00:00
Python: Add support for snake case imports (#6229)
When using slint.loader.app_window.XXX look for "app_window.slint" followed by "app-window.slint". Fixes #6216
This commit is contained in:
parent
34fe6b1537
commit
844590cac8
5 changed files with 13 additions and 5 deletions
|
|
@ -129,7 +129,8 @@ options:
|
|||
Any attribute lookup in `slint.loader` is searched for in `sys.path`. If a directory with the name exists, it is returned as a loader object, and subsequent
|
||||
attribute lookups follow the same logic. If the name matches a file with the `.slint` extension, it is automatically loaded with `load_file` and the
|
||||
[namespace](https://docs.python.org/3/library/types.html#types.SimpleNamespace) is returned, which contains classes for each exported component that
|
||||
inherits `Window`.
|
||||
inherits `Window`. If the file name contains a dash, like `app-window.slint`, an attribute lookup for `app_window` will
|
||||
first try to locate `app_window.slint` and then fall back to `app-window.slint`.
|
||||
|
||||
### Accessing Properties
|
||||
|
||||
|
|
|
|||
|
|
@ -275,6 +275,13 @@ class SlintAutoLoader:
|
|||
setattr(self, name, type_namespace)
|
||||
return type_namespace
|
||||
|
||||
dir_candidate = os.path.join(path, name.replace('_', '-'))
|
||||
file_candidate = dir_candidate + ".slint"
|
||||
if os.path.isfile(file_candidate):
|
||||
type_namespace = load_file(file_candidate)
|
||||
setattr(self, name, type_namespace)
|
||||
return type_namespace
|
||||
|
||||
return None
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import os
|
|||
|
||||
def test_callback_decorators(caplog):
|
||||
module = load_file(os.path.join(os.path.dirname(
|
||||
__spec__.origin), "test_load_file.slint"), quiet=False)
|
||||
__spec__.origin), "test-load-file.slint"), quiet=False)
|
||||
|
||||
class SubClass(module.App):
|
||||
@slint.callback()
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import os
|
|||
|
||||
def test_load_file(caplog):
|
||||
module = load_file(os.path.join(os.path.dirname(
|
||||
__spec__.origin), "test_load_file.slint"), quiet=False)
|
||||
__spec__.origin), "test-load-file.slint"), quiet=False)
|
||||
|
||||
assert "The property 'color' has been deprecated. Please use 'background' instead" in caplog.text
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ def test_load_file_fail():
|
|||
|
||||
def test_load_file_wrapper():
|
||||
module = load_file(os.path.join(os.path.dirname(
|
||||
__spec__.origin), "test_load_file.slint"), quiet=False)
|
||||
__spec__.origin), "test-load-file.slint"), quiet=False)
|
||||
|
||||
instance = module.App()
|
||||
|
||||
|
|
@ -66,7 +66,7 @@ def test_load_file_wrapper():
|
|||
|
||||
def test_constructor_kwargs():
|
||||
module = load_file(os.path.join(os.path.dirname(
|
||||
__spec__.origin), "test_load_file.slint"), quiet=False)
|
||||
__spec__.origin), "test-load-file.slint"), quiet=False)
|
||||
|
||||
def early_say_hello(arg):
|
||||
return "early:" + arg
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue