mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Add directory of file to run to sys path (#947)
This commit is contained in:
@@ -3,6 +3,8 @@ from textual.binding import Binding
|
||||
from textual.screen import Screen
|
||||
from textual.widgets import Static, Footer, Input
|
||||
|
||||
from some_text import TEXT
|
||||
|
||||
|
||||
class Focusable(Static, can_focus=True):
|
||||
pass
|
||||
@@ -10,11 +12,11 @@ class Focusable(Static, can_focus=True):
|
||||
|
||||
class CustomScreen(Screen):
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Focusable(f"Screen {id(self)} - two")
|
||||
yield Focusable(f"Screen {id(self)} - two {TEXT}")
|
||||
yield Focusable(f"Screen {id(self)} - three")
|
||||
yield Focusable(f"Screen {id(self)} - four")
|
||||
yield Input(placeholder="Text input")
|
||||
yield Footer()
|
||||
# yield Footer()
|
||||
|
||||
|
||||
class ScreensFocusApp(App):
|
||||
@@ -30,7 +32,7 @@ class ScreensFocusApp(App):
|
||||
yield Focusable("App - two")
|
||||
yield Focusable("App - three")
|
||||
yield Focusable("App - four")
|
||||
yield Footer()
|
||||
# yield Footer()
|
||||
|
||||
def action_push_new_screen(self):
|
||||
self.push_screen(CustomScreen())
|
||||
|
||||
1
sandbox/darren/some_text.py
Normal file
1
sandbox/darren/some_text.py
Normal file
@@ -0,0 +1 @@
|
||||
TEXT = "ABCDEFG"
|
||||
@@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
import os
|
||||
import runpy
|
||||
import shlex
|
||||
from pathlib import Path
|
||||
from typing import cast, TYPE_CHECKING
|
||||
|
||||
|
||||
@@ -38,6 +39,7 @@ def import_app(import_name: str) -> App:
|
||||
|
||||
if lib.endswith(".py"):
|
||||
path = os.path.abspath(lib)
|
||||
sys.path.append(str(Path(path).parent))
|
||||
try:
|
||||
global_vars = runpy.run_path(path, {})
|
||||
except Exception as error:
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import click
|
||||
from importlib_metadata import version
|
||||
from textual.devtools.server import _run_devtools
|
||||
from textual._import_app import import_app, AppFail
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from textual.app import App
|
||||
|
||||
|
||||
@click.group()
|
||||
@click.version_option(version("textual"))
|
||||
|
||||
Reference in New Issue
Block a user