Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default styling of TabbedContent widget incompatible with DataTable #2109

Closed
scapeg0at opened this issue Mar 22, 2023 · 3 comments
Closed

Default styling of TabbedContent widget incompatible with DataTable #2109

scapeg0at opened this issue Mar 22, 2023 · 3 comments
Labels
bug Something isn't working Task

Comments

@scapeg0at
Copy link

I've been trying to write an app with the new TabbedContent widget however, I cannot seem to get a DataTable to display anything. Here is the setup code:

def compose(self) -> ComposeResult:
  with TabbedContent():
    with TabPane("Data", id='data'):
      yield DataTale(id = 'table')
    with TabPane("stat", id='stat')
      yield Static('test', id='test')

def on_mount(self):
  table = self.query_one(DataTable)
  rows = iter(ROWS)
  table.add_columns(*next(rows))
  table.add_rows(rows)

where ROWS is from the DataTable example page.

When I run the app the Static page displays properly, showing "test", but the DataTable will not render in the corresponding tabs container. I've tried to activate the tab via clicking and via an action. The tab become active, but no datatable is displayed.

I've also looked into the console and the rows/columns seem to be added to the DataTable widget, the widget will just not render.

@Textualize Textualize deleted a comment from github-actions bot Mar 22, 2023
@davep
Copy link
Contributor

davep commented Mar 22, 2023

Given the use of DataTale rather than DataTable in the above, I take it this isn't from running code? Just for future reference it's generally a good idea to try and recreate the issue in a small stand-alone example, so everyone can be working with the same problem.

I think the following should serve the purpose here:

from textual.app     import App, ComposeResult
from textual.widgets import DataTable, Header, Footer, TabbedContent, TabPane

class TabsAndDataTable( App[ None ] ):

    CSS = """
    TabbedContent {
        border: round red;
    }

    TabPane {
        border: round green;
    }

    ContentSwitcher {
        border: round blue;
    }

    DataTable {
        border: round yellow;
    }
    """

    def compose( self ) -> ComposeResult:
        yield Header()
        with TabbedContent():
            with TabPane("DataTable"):
                yield DataTable()
        yield Footer()

    def on_mount( self ) -> None:
        dt = self.query_one(DataTable)
        dt.add_columns( "N", "N*10", "N*100", "N*1000" )
        for n in range( 20 ):
            dt.add_row( str( n ), str( n * 10 ), str( n * 100 ), str( n * 1000 ) )

if __name__ == "__main__":
    TabsAndDataTable().run()

Note that to help really see what could be going on, I've added borders to everything involved (under the hood ContentSwitcher also gets used so I've included that too):

Screenshot 2023-03-22 at 19 56 07

If I get a bit heavy-handed and throw some hight styling at everything, it all pops out:

from textual.app     import App, ComposeResult
from textual.widgets import DataTable, Header, Footer, TabbedContent, TabPane

class TabsAndDataTable( App[ None ] ):

    CSS = """
    TabbedContent {
        border: round red;
        height: 1fr;
    }

    TabPane {
        border: round green;
        height: 1fr;
    }

    ContentSwitcher {
        border: round blue;
        height: 1fr;
    }

    DataTable {
        border: round yellow;
        height: 1fr;
    }
    """

    def compose( self ) -> ComposeResult:
        yield Header()
        with TabbedContent():
            with TabPane("DataTable"):
                yield DataTable()
        yield Footer()

    def on_mount( self ) -> None:
        dt = self.query_one(DataTable)
        dt.add_columns( "N", "N*10", "N*100", "N*1000" )
        for n in range( 20 ):
            dt.add_row( str( n ), str( n * 10 ), str( n * 100 ), str( n * 1000 ) )

if __name__ == "__main__":
    TabsAndDataTable().run()

Screenshot 2023-03-22 at 19 59 27

I've not dived into it deeply, but I would suspect some unfortunate combination of default styles somewhere between DataTable, ContentSwitcher, TabPage and TabbedContent. Meanwhile you should be able to get your table to show with some styling along the lines of the above.

@scapeg0at
Copy link
Author

I tried out the styling you recommended and it worked, tank you! I generally set up styling after the app is completed so I didn't even think to check if that was the issue.

Next time I encounter an issue I'll be sure to include a stand alone example.

@scapeg0at scapeg0at changed the title Cannot display DataTable within TabbedContent Default styling of TabbedContent widget incompatible with DataTable Mar 22, 2023
@davep davep added bug Something isn't working Task labels Mar 22, 2023
@github-actions
Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Task
Projects
None yet
Development

No branches or pull requests

3 participants