bottom_toolbar
¶
This module begins the section of the repository that entails more advanced customization of prompt_toolkit.
Lower level constructs like widgets, toolbars and eventually the Layout classes are utilized quite heavily.
The InteractiveShell
.`pt_app.bottom_toolbar` type is expected to be some kind of
FormattedText
. Unfortunately, feeding it an already populated control like a
FormattedTextToolbar
will break the application.
Don’t run.:
bottom_toolbar = FormattedTextToolbar(bottom_text)
shell.pt_app.bottom_toolbar = bottom_toolbar
Note that a similar expression is used to assign the BottomToolbar
to the shell’s pt_app.bottom_toolbar attribute.:
from prompt_toolkit.formatted_text import FormattedText
from IPython import get_ipython
bottom_text = BottomToolbar()
bottom_toolbar = FormattedText(bottom_text.rerender())
However, the FormattedText
in and of itself doesn’t provide any functionality.
A FormattedText
object is simply a subclass of list
. The value is provided
in defining a method __pt_formatted_text__
.
As a result, BottomToolbar
also defines this method and as a result an
instance of the class can be passed directly as an assignment to the
_ip.pt_app.bottom_toolbar
.
Examples¶
>>> import time
>>> from pathlib import Path
>>> from default_profile.startup import bottom_toolbar_mod
>>> if bottom_toolbar_mod is not None:
>>> from default_profile.startup.bottom_toolbar_mod
>>> bt = BottomToolbar(get_app())
>>> print(bt)
<BottomToolbar:>
>>> bt()
f" [F4] Vi: {current_vi_mode!r} \n cwd: {Path.cwd().stem!r}\n Clock: {time.ctime()!r}"
Toolbar API¶
TODO: currently initialize a titlebar, an exit button and a few other things that aren’t utilized at all.
-
get_app
(shell=None) → prompt_toolkit.application.application.Application[source][source]¶ A patch to cover up the fact that get_app() returns a DummyApplication.
-
init_style
() → prompt_toolkit.styles.style.Style[source][source]¶ Merges the styles from default_pygments_style and the previously imported
pygments_style
.
-
show_header
(header_text: Optional[AnyStr] = None) → prompt_toolkit.widgets.base.Frame[source][source]¶
-
class
LineCounter
[source][source]¶ Bases:
object
Simple counter inspired by Doug Hellman. Could set it to sys.displayhook.
-
class
BottomToolbar
(_style: Optional[prompt_toolkit.styles.style.Style] = None, *args: List, **kwargs: Dict)[source][source]¶ Bases:
object
Display the current input mode.
As the bottom_toolbar property exists in both a prompt_toolkit PromptSession and Application, both are accessible from the
session
andpt_app
attributes.Defines a method
rerender()
and calls it whenever the instance is called via__call__
.-
__init__
(_style: Optional[prompt_toolkit.styles.style.Style] = None, *args: List, **kwargs: Dict)[source][source]¶ Require an ‘app’ for initialization.
This will eliminate all IPython code out of this class and make things a little more modular for the tests.
-