Edit Widget size
#1271
-
How do you split a Container/Static size in half upon adding a widget inside? Similar with what tmux/iterm/vim does with panes. How do you resize Widget size at key pressed? def compose(self) -> ComposeResult:
yield Footer()
yield Container(Container(Plot(),id="plot1"), id="plots")
def action_add_signals(self) -> None:
newPlot = Container(Plot(),id="plot2"))
self.query_one("#plots").mount(newPlot)
#split in half
self.query_one(Container).size[1] = self.query_one((Container)).size[1]/2 |
Beta Was this translation helpful? Give feedback.
Answered by
davep
Nov 24, 2022
Replies: 1 comment 3 replies
-
I may be misunderstanding what you're trying to do, but I think if I was to approach a "add pane and split parent" effect I'd start out with this: from textual.app import App, ComposeResult
from textual.widgets import Header, Footer
from textual.containers import Horizontal, Vertical
class Splitter( App[ None ] ):
CSS = """
Horizontal {
border: solid #666;
}
Vertical {
border: solid #888;
width: 1fr;
}
"""
BINDINGS = [
( "n", "new_pane", "New Pane" )
]
def compose(self) -> ComposeResult:
yield Header()
yield Horizontal( id="main" )
yield Footer()
def action_new_pane( self ) -> None:
self.query_one( "#main", Horizontal ).mount( Vertical() )
if __name__ == "__main__":
Splitter().run() |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
davep
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I may be misunderstanding what you're trying to do, but I think if I was to approach a "add pane and split parent" effect I'd start out with this: