diff --git a/dashport/dash.py b/dashport/dash.py index b2d28bf..9006819 100644 --- a/dashport/dash.py +++ b/dashport/dash.py @@ -285,63 +285,5 @@ def background(self, color): for i in range(0, self.cols): self.screen.insstr(j, i, " ", cpi(self.color_default, color)) - def single_panel(self, **kwargs): - """ - Creates one single panel that takes up the screen - """ - self.panels["layout"] = layout.single_panel( - self, border=kwargs.get("border", False), - border_styles=kwargs.get("border_styles", [0]), - scroll=kwargs.get("scroll", False), - height=kwargs.get("height", self.rows), - width=kwargs.get("width", self.cols)) - - def split_screen_columns(self, **kwargs): - """ - Splits the screen into two vertical panels - """ - self.panels["layout"] = layout.split_screen_columns( - self, border=kwargs.get("border", False), - border_styles=kwargs.get("border_styles", [0, 0]), - scroll=kwargs.get("scroll", False)) - - def split_screen_rows(self, **kwargs): - """ - Splits the screen into two horizontal panels - """ - self.panels["layout"] = layout.split_screen_rows( - self, border=kwargs.get("border", False), - border_styles=kwargs.get("border_styles", [0, 0]), - scroll=kwargs.get("scroll", False), - center_divide_y=kwargs.get("center_divide_y")) - - def split_screen_quad(self, **kwargs): - """ - Splits the screen into four quadrant panels - """ - self.panels["layout"] = layout.quadrants( - self, border=kwargs.get("border", False), - border_styles=kwargs.get("border_styles", [0, 0, 0, 0]), - scroll=kwargs.get("scroll", False)) - - def split_screen_three_vert(self, **kwargs): - """ - Splits the screen into three panels - """ - self.panels["layout"] = layout.three_panels_vert( - self, border=kwargs.get("border", False), - border_styles=kwargs.get("border_styles", [0, 0, 0]), - long_side=kwargs.get("long_side", "right"), - long_side_width=kwargs.get("long_side_width"), - scroll=kwargs.get("scroll", False)) - - def split_screen_three_horizontal(self, **kwargs): - """ - Splits the screen into three panels - """ - self.panels["layout"] = layout.three_panels_horizontal( - self, border=kwargs.get("border", False), - border_styles=kwargs.get("border_styles", [0, 0, 0]), - long_side=kwargs.get("long_side", "top"), - long_side_height=kwargs.get("long_side_height"), - scroll=kwargs.get("scroll", False)) + def layout(self, layout_name, **kwargs): + self.panels["layout"] = getattr(layout, layout_name)(self, **kwargs) diff --git a/dashport/layout.py b/dashport/layout.py index bea7dd5..5bfa9a7 100644 --- a/dashport/layout.py +++ b/dashport/layout.py @@ -5,7 +5,7 @@ def single_panel(app, **kwargs): border = kwargs.get("border", False) border_styles = kwargs.get("border_styles", [0]) - height = kwargs.get("height", app.rows) + height = kwargs.get("height", app.rows - app.title_offset) width = kwargs.get("width", app.cols) if isinstance(border, bool): border = [border] @@ -29,11 +29,13 @@ def split_screen_columns(app, **kwargs): border_styles = kwargs.get("border_styles", [0, 0]) if isinstance(border, bool): border = [border] * 2 - win1, panel1 = app.panel(height=app.rows, length=split_cols, y=0, x=0, + win1, panel1 = app.panel(height=app.rows - app.title_offset, + length=split_cols, y=0, x=0, scroll=kwargs.get("scroll", False), border=border[0], border_style=border_styles[0]) - win2, panel2 = app.panel(height=app.rows, length=split_cols, + win2, panel2 = app.panel(height=app.rows - app.title_offset, + length=split_cols, y=0, x=split_cols, scroll=kwargs.get("scroll", False), @@ -48,7 +50,7 @@ def split_screen_columns(app, **kwargs): def split_screen_rows(app, **kwargs): if not kwargs.get("center_divide_y"): - split_rows = [int(app.rows / 2), int(app.rows / 2)] + split_rows = [int(app.rows / 2) - app.title_offset, int(app.rows / 2)] else: split_rows = [int(kwargs.get("center_divide_y")), app.rows - int(kwargs.get("center_divide_y"))] @@ -74,7 +76,7 @@ def split_screen_rows(app, **kwargs): def quadrants(app, **kwargs): - split_rows = int(app.rows / 2) + split_rows = int(app.rows / 2) - app.title_offset split_cols = int(app.cols / 2) border = kwargs.get("border", False) border_styles = kwargs.get("border_styles", [0, 0, 0, 0]) @@ -109,7 +111,7 @@ def quadrants(app, **kwargs): def three_panels_vert(app, **kwargs): - split_rows = int(app.rows / 2) + split_rows = int(app.rows / 2) - app.title_offset split_cols = int(app.cols / 2) long_side = kwargs.get("long_side", "right") border = kwargs.get("border", False) @@ -164,7 +166,7 @@ def three_panels_vert(app, **kwargs): def three_panels_horizontal(app, **kwargs): - split_rows = int(app.rows / 2) + split_rows = int(app.rows / 2) - app.title_offset split_cols = int(app.cols / 2) long_side = kwargs.get("long_side", "top") border = kwargs.get("border", False) diff --git a/examples/layouts/split_screen_columns.py b/examples/layouts/split_screen_columns.py index 02e9582..f4d90e0 100755 --- a/examples/layouts/split_screen_columns.py +++ b/examples/layouts/split_screen_columns.py @@ -14,7 +14,7 @@ def quit(app): def dashport(stdscr): app = Dashport(stdscr, color_default=17) app.add_control("q", quit, case_sensitive=False) - app.split_screen_columns(border=True) + app.layout("split_screen_columns", border=True) app.print("hello", x=1, y=1, panel="layout.1") app.print("world", x=1, y=2, panel="layout.1") while True: diff --git a/examples/layouts/split_screen_quad.py b/examples/layouts/split_screen_quad.py index a462cd6..c07edb8 100755 --- a/examples/layouts/split_screen_quad.py +++ b/examples/layouts/split_screen_quad.py @@ -14,8 +14,9 @@ def quit(app): def dashport(stdscr): app = Dashport(stdscr, color_default=176) app.add_control("q", quit, case_sensitive=False) - app.split_screen_quad(border=[True, False, True, True], - border_styles=[0, 1, 1, None]) + app.layout("quadrants", + border=[True, False, True, True], + border_styles=[0, 1, 1, None]) app.panels["layout"][3].border('M', 'M', '=', '=', ' ', ' ', ' ', ' ') app.print("panel 0", x=1, y=1, panel="layout.0", A_BOLD=True, A_ITALIC=True) diff --git a/examples/layouts/split_screen_rows.py b/examples/layouts/split_screen_rows.py index 247f2c5..39e853e 100755 --- a/examples/layouts/split_screen_rows.py +++ b/examples/layouts/split_screen_rows.py @@ -14,7 +14,7 @@ def quit(app): def dashport(stdscr): app = Dashport(stdscr, color_default=17) app.add_control("q", quit, case_sensitive=False) - app.split_screen_rows(border=True) + app.layout("split_screen_rows", border=True) app.print("hello", x=1, y=1, panel="layout.0") app.print("world", x=1, y=1, panel="layout.1") while True: diff --git a/examples/layouts/split_screen_three_horizontal.py b/examples/layouts/split_screen_three_horizontal.py index 796a8ca..f566794 100755 --- a/examples/layouts/split_screen_three_horizontal.py +++ b/examples/layouts/split_screen_three_horizontal.py @@ -14,8 +14,9 @@ def quit(app): def dashport(stdscr): app = Dashport(stdscr, color_default=176) app.add_control("q", quit, case_sensitive=False) - app.split_screen_three_horizontal( - border=[False, False, True], long_side="bottom", long_side_height=10) + app.layout("three_panels_horizontal", + border=[False, False, True], long_side="bottom", + long_side_height=10) app.print("panel 0", panel="layout.0") app.print(f"Rows: {app.panel_dimensions[0][0]}", x=5, y=2, panel="layout.0") diff --git a/examples/layouts/split_screen_three_vert.py b/examples/layouts/split_screen_three_vert.py index 85ab215..5b1d0f3 100755 --- a/examples/layouts/split_screen_three_vert.py +++ b/examples/layouts/split_screen_three_vert.py @@ -14,8 +14,9 @@ def quit(app): def dashport(stdscr): app = Dashport(stdscr, color_default=176) app.add_control("q", quit, case_sensitive=False) - app.split_screen_three_vert(border=True, long_side="right", - long_side_width=20) + app.layout("three_panels_vert", + border=True, long_side="right", + long_side_width=20) app.print("panel 0", x=1, y=1, panel="layout.0") app.print(f"Rows: {app.panel_dimensions[0][0]}", x=5, y=2, panel="layout.0") diff --git a/examples/util/all_box_drawing.py b/examples/util/all_box_drawing.py index a1bb599..d00d667 100755 --- a/examples/util/all_box_drawing.py +++ b/examples/util/all_box_drawing.py @@ -126,7 +126,7 @@ def dashport(stdscr): app = Dashport(stdscr) height = app.rows - 2 app.title_bar(text="Q = quit, B = Next page", align="bottom", color=121) - app.single_panel(scroll=True, height=height) + app.layout("single_panel", scroll=True, height=height) app.add_control("q", quit) app.add_control("KEY_UP", move_up) app.add_control("KEY_DOWN", move_down) diff --git a/examples/views/interactive_prompt.py b/examples/views/interactive_prompt.py index 84d4f71..164667e 100755 --- a/examples/views/interactive_prompt.py +++ b/examples/views/interactive_prompt.py @@ -10,7 +10,7 @@ def quit(): def dashport(stdscr): app = Dashport(stdscr, color_default=8) - app.single_panel(border=False, scroll=True, height=app.rows - 1) + app.layout("single_panel", border=False, scroll=True, height=app.rows - 1) app.commands = [] while True: while True: diff --git a/examples/views/multiple_views.py b/examples/views/multiple_views.py index ba59a0e..d482c53 100755 --- a/examples/views/multiple_views.py +++ b/examples/views/multiple_views.py @@ -12,7 +12,7 @@ def quit(app): def four_way_split(app): - app.split_screen_quad(border=True) + app.layout("quadrants", border=True, height=app.rows - 2) app.print("panel 0", panel="layout.0") app.print(f"Rows: {app.panel_dimensions[0][0]}", x=5, y=2, panel="layout.0") @@ -36,8 +36,8 @@ def four_way_split(app): def three_way_split(app): - app.split_screen_three_vert(border=True, long_side="right", - long_side_width=100) + app.layout("three_panels_vert", border=True, long_side="right", + long_side_width=100) app.print("panel 0", panel="layout.0") app.print(f"Rows: {app.panel_dimensions[0][0]}", x=5, y=2, panel="layout.0") diff --git a/examples/views/scroll_panels.py b/examples/views/scroll_panels.py index f974d90..1b710ce 100755 --- a/examples/views/scroll_panels.py +++ b/examples/views/scroll_panels.py @@ -19,7 +19,7 @@ def dashport(stdscr): app = Dashport(stdscr, scroll=True) app.add_control("q", quit) rows, cols = app.screen.getmaxyx() - app.split_screen_three_vert(border=True, scroll=True) + app.layout("three_panels_vert", border=True, scroll=True) app.title_bar(text=f"Title {app.cursor_x},{app.cursor_y}", align="top", color=256) for i in range(0, 1000):