From d1971312dba76e60de05d03f70a74a17680f3003 Mon Sep 17 00:00:00 2001 From: "Martindale, Nathan" Date: Mon, 14 Aug 2023 11:33:16 -0400 Subject: [PATCH] Add buttons for label all interesting/uninteresting Closes #21 --- CHANGELOG.md | 1 + icat/data.py | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27e17c2..de87b34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * `add_anchor` function directly to model. * Saving/loading functionality to anchors, anchor lists, and models. * Add expand/collapse all anchors in anchor list button +* Buttons for label all interesting/uninteresting to selected data tab. ### Fixed * Text fields not applying changes when user clicks away instead of hitting enter. diff --git a/icat/data.py b/icat/data.py index 00f3868..c940605 100644 --- a/icat/data.py +++ b/icat/data.py @@ -109,6 +109,25 @@ def __init__( self.filtered_df = None + self.label_all_i_btn = v.Btn( + children=["All interesting"], + small=True, + class_="blue darken-1", + style_="margin-left: 2px; margin-right: 2px;", + ) + self.label_all_u_btn = v.Btn( + children=["All uninteresting"], + small=True, + class_="orange darken-1", + style_="margin-left: 2px; margin-right: 2px;", + ) + self.label_all_i_btn.on_event("click", self._handle_ipv_label_all_i_btn_click) + self.label_all_u_btn.on_event("click", self._handle_ipv_label_all_u_btn_click) + self.label_all_row = v.Row( + children=[self.label_all_u_btn, self.label_all_i_btn], + style_="display: none; text-align: right; margin-right: 5px;", + ) + # NOTE: ipywidgets_bokeh is a bit broken right now and I'm not yet able # to get pn.ipywidget to work correctly - so panel components can only # be at the highest level right now, I can't have ipywidgets with panel @@ -121,7 +140,7 @@ def __init__( # anymore. data_layout_stack = v.Container( fluid=True, - children=[self.data_tabs, self.search_box, self.table], + children=[self.data_tabs, self.search_box, self.label_all_row, self.table], height=height, width=width, ) @@ -174,6 +193,16 @@ def __init__( # EVENT HANDLERS # ============================================================ + def _handle_ipv_label_all_i_btn_click(self, widget, event, data): + indices = self.filtered_df.index.tolist() + labels = [1] * len(indices) + self._handle_label_changed(indices, labels) + + def _handle_ipv_label_all_u_btn_click(self, widget, event, data): + indices = self.filtered_df.index.tolist() + labels = [0] * len(indices) + self._handle_label_changed(indices, labels) + # TODO: coupling: directly calling refresh data on the model view. Instead, we # could have a "sample_changed" event that view listens to. def _handle_ipv_resample_btn_click(self, widget, event, data): @@ -191,6 +220,14 @@ def _handle_ipv_tab_changed(self, widget, event, data: int): # ipyvuetify itself? # self.current_data_tab = self.data_tab_list[data] self.current_data_tab = self.data_tab_list[self.data_tabs.v_model] + if self.current_data_tab == "Selected": + self.label_all_row.style_ = ( + "display: block; text-align: right; margin-right: 5px;" + ) + else: + self.label_all_row.style_ = ( + "display: none; text-align: right; margin-right: 5px;" + ) def _handle_ipv_search_changed(self, widget, event, data): """Event handler for the vuetify search box change. This changes the search_value