You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
.~/virtualenv/Textualize/bin/activate
textual run --dev $PWD/command01.py
The script
I made some modifications to print out where it was getting stuck, but it is mostly the same script as shown here:
#!/usr/bin/env python3from __future__ importannotationsfromfunctoolsimportpartialfrompathlibimportPathfromtypingimportAnyfromrich.styleimportStylefromrich.syntaximportSyntaxfromtextual.appimportApp, ComposeResultfromtextual.commandimportHit, Hits, Providerfromtextual.containersimportVerticalScrollfromtextual.screenimportScreenfromtextual.widgetsimportStaticclassPythonFileCommands(Provider):
"""A command provider to open a Python file in the current working directory."""def__init__(self, screen: Screen[Any], match_style: Style|None=None):
super().__init__(screen, match_style)
self.python_paths=Noneself.app.log(f"Done with Provider init")
defread_files(self) ->list[Path]:
"""Get a list of Python files in the current working directory."""files=list(Path("../").glob("*.py"))
self.app.log.info(f"Got files: {files}")
returnfilesasyncdefstartup(self) ->None:
"""Called once when the command palette is opened, prior to searching."""worker=self.app.run_worker(self.read_files, thread=True)
self.python_paths=awaitworker.wait()
self.app.log.info(f"Done startup, paths = {self.python_paths}")
asyncdefsearch(self, query: str) ->Hits:
"""Search for Python files."""matcher=self.matcher(query)
my_app=self.appassertisinstance(my_app, ViewerApp)
forpathinself.python_paths:
command=f"open {str(path)}"score=matcher.match(command)
ifscore>0:
yieldHit(
score,
matcher.highlight(command),
partial(my_app.open_file, path),
help="Open this file in the viewer",
)
classViewerApp(App):
"""Demonstrate a command source."""COMMANDS=App.COMMANDS| {PythonFileCommands}
defcompose(self) ->ComposeResult:
withVerticalScroll():
yieldStatic(id="code", expand=True)
self.log.info("Done with compose")
defopen_file(self, path: Path) ->None:
"""Open and display a file with syntax highlighting."""syntax=Syntax.from_path(
str(path),
line_numbers=True,
word_wrap=False,
indent_guides=True,
theme="github-dark",
)
self.query_one("#code", Static).update(syntax)
self.log.info(f"Done reading file {path}")
if__name__=="__main__":
app=ViewerApp()
app.run()
User error. I was using the wrong keys to make the command pallete to show up.
How to troubleshoot?
Run 'textual keys' and make sure you are pressing the right key combination. Ctrl + \, it will show up on the screen
Call the demo and then you will see the command pallete show up after you press 'Ctrl + '. It won't show up by default (why it should, it is called on demand).
Hello,
The example app showcased on 'command01.py' freezes and displays nothing but an blank screen.
Ctrl+
Doesn't do anything.This is how I call the script. One one terminal:
And on a different terminal, same machine:
The script
I made some modifications to print out where it was getting stuck, but it is mostly the same script as shown here:
Environment
Here is my environment information
Textual Diagnostics
Versions
Python
Operating System
Terminal
Rich Console options
Output of 'textual console`
The text was updated successfully, but these errors were encountered: