from textual import on from textual.app import ComposeResult from textual.widgets import Select import portfolio from tui.record_pane import RecordListPane IMAGE_FOLDERS = {"hackathons": "hacks", "organizations": "organizations", "opensource": "projects"} class ProjectsPane(RecordListPane): def __init__(self, **kwargs): super().__init__(portfolio.PROJECT_COLLECTIONS[0], **kwargs) def compose_header(self) -> ComposeResult: options = [(collection.title, collection.id) for collection in portfolio.PROJECT_COLLECTIONS] yield Select(options, value=self.collection.id, allow_blank=False, id="category-select") @on(Select.Changed, "#category-select") def category_changed(self, event: Select.Changed): if event.value == self.collection.id: return self.collection = portfolio.find_collection(str(event.value)) self.set_content_file(self.collection.file) self.build_columns() self.reload() self.table().focus() def image_folder(self) -> str: return IMAGE_FOLDERS.get(self.collection.id, "")