def __init__(self, window: Window.Window, profile: Profile.Profile): content_widget = window.ui.create_column_widget() super().__init__(content_widget) ui = window.ui self._tree_model = TreeModel(profile) def closed_items_changed(closed_items: typing.Set[str]) -> None: profile.closed_items = list(closed_items) self._tree_model.on_closed_items_changed = closed_items_changed self._tree_selection = Selection.IndexedSelection( Selection.Style.multiple) projects_list_widget = Widgets.ListWidget( ui, ProjectTreeCanvasItemDelegate(window, self._tree_model), selection=self._tree_selection, v_scroll_enabled=False, v_auto_resize=True) projects_list_widget.wants_drag_events = True projects_list_widget.bind_items( Binding.PropertyBinding(self._tree_model, "value")) projects_section = Widgets.SectionWidget(ui, _("Projects"), projects_list_widget) projects_section.expanded = True content_widget.add(projects_section) # configure an observer for watching for project references changes. # this serves as the master updater for changes. move to document controller? def project_references_changed(item: Observer.ItemValue) -> None: # update the tree model. project_references = typing.cast( typing.Sequence[Profile.ProjectReference], item) self._tree_model.update_project_references(project_references) oo = Observer.ObserverBuilder() oo.source(profile).ordered_sequence_from_array( "project_references").collect_list().action_fn( project_references_changed) self.__projects_model_observer = typing.cast( Observer.AbstractItemSource, oo.make_observable())
def __init__( self, ui: UserInterface.UserInterface, document_controller: DocumentController.DocumentController ) -> None: content_widget = ui.create_column_widget() super().__init__(content_widget) document_model = document_controller.document_model all_items_controller = CollectionDisplayItemCounter( _("All"), None, "all", document_controller) persistent_items_controller = CollectionDisplayItemCounter( _("Persistent"), None, "persistent", document_controller) live_items_controller = CollectionDisplayItemCounter( _("Live"), None, "temporary", document_controller) latest_items_controller = CollectionDisplayItemCounter( _("Latest Session"), None, "latest-session", document_controller) self.__item_controllers = [ all_items_controller, persistent_items_controller, live_items_controller, latest_items_controller ] self.__data_group_controllers: typing.List[ CollectionDisplayItemCounter] = list() collection_selection = Selection.IndexedSelection( Selection.Style.single_or_none) collections_list_widget = Widgets.ListWidget( ui, CollectionListCanvasItemDelegate(collection_selection), selection=collection_selection, v_scroll_enabled=False, v_auto_resize=True) collections_list_widget.wants_drag_events = True def filter_changed(data_group: typing.Optional[DataGroup.DataGroup], filter_id: typing.Optional[str]) -> None: if data_group: for index, controller in enumerate( collections_list_widget.items): if data_group == controller.data_group: collection_selection.set(index) break else: if filter_id == "latest-session": collection_selection.set(3) elif filter_id == "temporary": collection_selection.set(2) elif filter_id == "persistent": collection_selection.set(1) else: collection_selection.set(0) self.__filter_changed_event_listener = document_controller.filter_changed_event.listen( filter_changed) def collections_changed(t: str) -> None: collections_list_widget.items = [ all_items_controller, persistent_items_controller, live_items_controller, latest_items_controller, ] + self.__data_group_controllers all_items_controller.on_title_changed = collections_changed persistent_items_controller.on_title_changed = collections_changed live_items_controller.on_title_changed = collections_changed latest_items_controller.on_title_changed = collections_changed def document_model_item_inserted(key: str, value: typing.Any, before_index: int) -> None: if key == "data_groups": data_group = value controller = CollectionDisplayItemCounter( data_group.title, data_group, None, document_controller) self.__data_group_controllers.insert(before_index, controller) controller.on_title_changed = collections_changed collections_changed(str()) def document_model_item_removed(key: str, value: typing.Any, index: int) -> None: if key == "data_groups": controller = self.__data_group_controllers.pop(index) controller.close() collections_changed(str()) self.__document_model_item_inserted_listener = document_model.item_inserted_event.listen( document_model_item_inserted) self.__document_model_item_removed_listener = document_model.item_removed_event.listen( document_model_item_removed) data_group, filter_id = document_controller.get_data_group_and_filter_id( ) filter_changed(data_group, filter_id) for index, data_group in enumerate(document_model.data_groups): document_model_item_inserted("data_groups", data_group, index) collections_changed(str()) def collections_selection_changed( indexes: typing.AbstractSet[int]) -> None: if len(indexes) == 0: controller = collections_list_widget.items[0] document_controller.set_filter(controller.filter_id) elif len(indexes) == 1: controller = collections_list_widget.items[list(indexes)[0]] if controller.is_smart_collection: document_controller.set_filter(controller.filter_id) document_controller.set_data_group(None) else: document_controller.set_filter(None) document_controller.set_data_group(controller.data_group) collections_list_widget.on_selection_changed = collections_selection_changed collections_column = ui.create_column_widget() collections_column.add(collections_list_widget) collections_section = Widgets.SectionWidget(ui, _("Collections"), collections_column) collections_section.expanded = True content_widget.add(collections_section) content_widget.add_stretch() # for testing self._collection_selection = collection_selection