From ac6da5008f1dcdbd49e4836c9acf976b35a445f2 Mon Sep 17 00:00:00 2001 From: 7174Andy Date: Mon, 16 Dec 2024 12:51:14 -0800 Subject: [PATCH 01/17] add option to show video names with filepath --- sleap/gui/dataviews.py | 82 +++++++++++++++++++++++++++++++++++++- sleap/gui/widgets/docks.py | 3 ++ sleap/io/video.py | 10 +++++ 3 files changed, 93 insertions(+), 2 deletions(-) diff --git a/sleap/gui/dataviews.py b/sleap/gui/dataviews.py index f68dc0180..a0b31e0b5 100644 --- a/sleap/gui/dataviews.py +++ b/sleap/gui/dataviews.py @@ -291,6 +291,7 @@ class GenericTableView(QtWidgets.QTableView): name_prefix: str = "selected_" is_activatable: bool = False is_sortable: bool = False + show_video_name: bool = False def __init__( self, @@ -305,12 +306,17 @@ def __init__( ): super(GenericTableView, self).__init__() + model.show_video_name = self.show_video_name + self.state = state or GuiState() self.row_name = row_name or self.row_name self.name_prefix = name_prefix if name_prefix is not None else self.name_prefix self.is_sortable = is_sortable or self.is_sortable self.is_activatable = is_activatable or self.is_activatable self.multiple_selection = multiple_selection + self.options = { + "Show Video Name": self.show_video_name, + } self.setModel(model) @@ -384,12 +390,84 @@ def getSelectedRowItem(self) -> Any: return None return self.model().original_items[idx.row()] + def mousePressEvent(self, event) -> None: + """Only for right-click on VideosTableView. + + Args: + event (QMouseEvent): The mouse event. + """ + if event.button() == QtCore.Qt.RightButton and isinstance( + self.model(), VideosTableModel + ): + self.show_context_menu(event) + super().mousePressEvent(event) + + def show_context_menu(self, event): + menu = QtWidgets.QMenu(self) + + # Add actions to the menu + for option, is_checked in self.options.items(): + action = QtWidgets.QAction(option, self) + action.setCheckable(True) + action.setChecked(is_checked) + action.triggered.connect(self.create_checked_lambda(option)) + menu.addAction(action) + + # Show the context menu + menu.exec_(event.globalPos()) + + def create_checked_lambda(self, option): + """Callback for context menu actions. + + Args: + option (dict): The option to toggle. + + Returns: + function: The callback function. + """ + return lambda checked: self.toggle_option(option, checked) + + def toggle_option(self, option, checked): + """Toggle the option in the context menu. + + Args: + option (str): The option to toggle. + checked (bool): The new value for the option. + """ + self.options[option] = checked + model = self.model() + if isinstance(model, VideosTableModel): + model.set_show_video_name(self.options["Show Video Name"]) + class VideosTableModel(GenericTableModel): - properties = ("filename", "frames", "height", "width", "channels") + def __init__(self, show_video_name: bool = False, *args, **kwargs): + super().__init__(*args, **kwargs) + self.show_video_name = show_video_name + self.update_properties() + + def update_properties(self): + if self.show_video_name: + self.properties = ( + "filename", + "name", + "frames", + "height", + "width", + "channels", + ) + else: + self.properties = ("filename", "frames", "height", "width", "channels") + + def set_show_video_name(self, show_video_name: bool): + if self.show_video_name == show_video_name: + return + self.show_video_name = show_video_name + self.update_properties() + self.layoutChanged.emit() def item_to_data(self, obj, item): - return {key: getattr(item, key) for key in self.properties} + return {key: getattr(item, key, None) for key in self.properties} class SkeletonNodesTableModel(GenericTableModel): diff --git a/sleap/gui/widgets/docks.py b/sleap/gui/widgets/docks.py index bd20bf79a..40b59a4db 100644 --- a/sleap/gui/widgets/docks.py +++ b/sleap/gui/widgets/docks.py @@ -183,6 +183,9 @@ def create_tables(self) -> GenericTableView: return self.table + def create_context_menu(self) -> None: + """Create the context menu for the dock.""" + def create_video_edit_and_nav_buttons(self) -> QWidget: """Create the buttons for editing and navigating videos in table.""" main_window = self.main_window diff --git a/sleap/io/video.py b/sleap/io/video.py index c8272cfbd..c6e371707 100644 --- a/sleap/io/video.py +++ b/sleap/io/video.py @@ -465,6 +465,11 @@ def dtype(self): """See :class:`Video`.""" return self.test_frame.dtype + @property + def name(self): + """Return the name of the video.""" + return os.path.basename(self.filename) + def reset(self, filename: str = None, grayscale: bool = None, bgr: bool = None): """Reloads the video.""" if filename is not None: @@ -944,6 +949,11 @@ def dtype(self): """See :class:`Video`.""" return self.cache_.dtype + @property + def name(self): + """Name of the video.""" + return os.path.basename(self.filename) + def reset( self, filename: str = None, From 788e8bcbfdc4f073f3d095d1c02b9ee809bd30bc Mon Sep 17 00:00:00 2001 From: 7174Andy Date: Mon, 16 Dec 2024 13:06:54 -0800 Subject: [PATCH 02/17] add doc --- sleap/gui/dataviews.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sleap/gui/dataviews.py b/sleap/gui/dataviews.py index a0b31e0b5..838fdb54f 100644 --- a/sleap/gui/dataviews.py +++ b/sleap/gui/dataviews.py @@ -403,6 +403,11 @@ def mousePressEvent(self, event) -> None: super().mousePressEvent(event) def show_context_menu(self, event): + """Show context menu for VideosTableView. + + Args: + event (QMouseEvent): The mouse event. + """ menu = QtWidgets.QMenu(self) # Add actions to the menu @@ -447,6 +452,7 @@ def __init__(self, show_video_name: bool = False, *args, **kwargs): self.update_properties() def update_properties(self): + """Update properties based on show_video_name attribute.""" if self.show_video_name: self.properties = ( "filename", @@ -460,6 +466,7 @@ def update_properties(self): self.properties = ("filename", "frames", "height", "width", "channels") def set_show_video_name(self, show_video_name: bool): + """Set whether to show video name in table.""" if self.show_video_name == show_video_name: return self.show_video_name = show_video_name From a92fc2d879b49d9a827c9bf745db26d1acbcc3de Mon Sep 17 00:00:00 2001 From: 7174Andy Date: Mon, 16 Dec 2024 17:11:48 -0800 Subject: [PATCH 03/17] new feature added successfully --- sleap/gui/dataviews.py | 54 ++++++++++++++++++++++++++---------------- sleap/io/video.py | 51 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 82 insertions(+), 23 deletions(-) diff --git a/sleap/gui/dataviews.py b/sleap/gui/dataviews.py index 838fdb54f..8433ab2a1 100644 --- a/sleap/gui/dataviews.py +++ b/sleap/gui/dataviews.py @@ -442,39 +442,53 @@ def toggle_option(self, option, checked): self.options[option] = checked model = self.model() if isinstance(model, VideosTableModel): - model.set_show_video_name(self.options["Show Video Name"]) + if option == "Show Video Name": + model.set_show_video_name(self.options["Show Video Name"]) class VideosTableModel(GenericTableModel): - def __init__(self, show_video_name: bool = False, *args, **kwargs): - super().__init__(*args, **kwargs) + def __init__(self, items, show_video_name=False, **kwargs): + super().__init__(**kwargs) + self.items = items self.show_video_name = show_video_name - self.update_properties() + self.properties = self._get_properties() + self.all_properties = ( + "filename", + "filepath", + "name", + "frames", + "height", + "width", + "channels", + ) - def update_properties(self): - """Update properties based on show_video_name attribute.""" + def headerData(self, section, orientation, role=QtCore.Qt.DisplayRole): + if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole: + return self.properties[section].title() + return super().headerData(section, orientation, role) + + def _get_properties(self): + """Return properties based on the show_video_name flag.""" if self.show_video_name: - self.properties = ( - "filename", - "name", - "frames", - "height", - "width", - "channels", - ) - else: - self.properties = ("filename", "frames", "height", "width", "channels") + return ["filepath", "name", "frames", "height", "width", "channels"] + return ["filename", "frames", "height", "width", "channels"] def set_show_video_name(self, show_video_name: bool): """Set whether to show video name in table.""" if self.show_video_name == show_video_name: return + + # Reset the table so that new columns are added self.show_video_name = show_video_name - self.update_properties() - self.layoutChanged.emit() + self.properties = self._get_properties() + self.beginResetModel() + self.endResetModel() - def item_to_data(self, obj, item): - return {key: getattr(item, key, None) for key in self.properties} + def item_to_data(self, obj, item: "Video"): + data = {} + for property in self.all_properties: + data[property] = getattr(item, property) + return data class SkeletonNodesTableModel(GenericTableModel): diff --git a/sleap/io/video.py b/sleap/io/video.py index c6e371707..36beab565 100644 --- a/sleap/io/video.py +++ b/sleap/io/video.py @@ -271,6 +271,17 @@ def height(self): return int(self.__dataset_h5.attrs["height"]) return self.__dataset_h5.shape[self.__height_idx] + @property + def name(self): + """Name of the video.""" + return self.filename.split("/")[-1] + + @property + def filepath(self): + """Path to the video file.""" + splitted = self.filename.split("/")[:-1] + return "/".join(splitted) + @property def dtype(self): """See :class:`Video`.""" @@ -467,8 +478,14 @@ def dtype(self): @property def name(self): - """Return the name of the video.""" - return os.path.basename(self.filename) + """Name of the video.""" + return self.filename.split("/")[-1] + + @property + def filepath(self): + """Path to the video file.""" + splitted = self.filename.split("/")[:-1] + return "/".join(splitted) def reset(self, filename: str = None, grayscale: bool = None, bgr: bool = None): """Reloads the video.""" @@ -595,6 +612,17 @@ def dtype(self): """See :class:`Video`.""" return self.__data.dtype + @property + def name(self): + """Name of the video.""" + return self.filename.split("/")[-1] + + @property + def filepath(self): + """Path to the video file.""" + splitted = self.filename.split("/")[:-1] + return "/".join(splitted) + def reset(self): """Reload the video.""" # TODO @@ -711,6 +739,17 @@ def height(self): """See :class:`Video`.""" return self.__img.shape[0] + @property + def name(self): + """Name of the video.""" + return self.filename.split("/")[-1] + + @property + def filepath(self): + """Path to the video file.""" + splitted = self.filename.split("/")[:-1] + return "/".join(splitted) + @property def dtype(self): """See :class:`Video`.""" @@ -952,7 +991,13 @@ def dtype(self): @property def name(self): """Name of the video.""" - return os.path.basename(self.filename) + return self.filename.split("/")[-1] + + @property + def filepath(self): + """Path to the video file.""" + splitted = self.filename.split("/")[:-1] + return "/".join(splitted) def reset( self, From 2ea89bbf0a1b7bbdc5e9c8f031d8989fa5f49801 Mon Sep 17 00:00:00 2001 From: 7174Andy Date: Mon, 16 Dec 2024 17:14:01 -0800 Subject: [PATCH 04/17] delete unnecessary code --- sleap/gui/widgets/docks.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/sleap/gui/widgets/docks.py b/sleap/gui/widgets/docks.py index 40b59a4db..bd20bf79a 100644 --- a/sleap/gui/widgets/docks.py +++ b/sleap/gui/widgets/docks.py @@ -183,9 +183,6 @@ def create_tables(self) -> GenericTableView: return self.table - def create_context_menu(self) -> None: - """Create the context menu for the dock.""" - def create_video_edit_and_nav_buttons(self) -> QWidget: """Create the buttons for editing and navigating videos in table.""" main_window = self.main_window From e03be7e29d358ef543d26a059e4230338578b20f Mon Sep 17 00:00:00 2001 From: 7174Andy Date: Mon, 16 Dec 2024 23:26:14 -0800 Subject: [PATCH 05/17] remove attributes from video object --- sleap/gui/dataviews.py | 19 +++++++++++++-- sleap/io/video.py | 55 ------------------------------------------ 2 files changed, 17 insertions(+), 57 deletions(-) diff --git a/sleap/gui/dataviews.py b/sleap/gui/dataviews.py index 8433ab2a1..aab6e543b 100644 --- a/sleap/gui/dataviews.py +++ b/sleap/gui/dataviews.py @@ -446,12 +446,21 @@ def toggle_option(self, option, checked): model.set_show_video_name(self.options["Show Video Name"]) +# TODO: Fix the error in the Pytest. class VideosTableModel(GenericTableModel): def __init__(self, items, show_video_name=False, **kwargs): super().__init__(**kwargs) self.items = items self.show_video_name = show_video_name - self.properties = self._get_properties() + self.properties = ( + "filepath", + "name", + "frames", + "height", + "width", + "channels", + ) + # TODO: Always with filepath and name (no filename) self.all_properties = ( "filename", "filepath", @@ -487,7 +496,13 @@ def set_show_video_name(self, show_video_name: bool): def item_to_data(self, obj, item: "Video"): data = {} for property in self.all_properties: - data[property] = getattr(item, property) + if property == "name": + data[property] = getattr(item, "filename").split("/")[-1] + elif property == "filepath": + splitted = getattr(item, "filename").split("/")[:-1] + data[property] = "/".join(splitted) + else: + data[property] = getattr(item, property) return data diff --git a/sleap/io/video.py b/sleap/io/video.py index 36beab565..c8272cfbd 100644 --- a/sleap/io/video.py +++ b/sleap/io/video.py @@ -271,17 +271,6 @@ def height(self): return int(self.__dataset_h5.attrs["height"]) return self.__dataset_h5.shape[self.__height_idx] - @property - def name(self): - """Name of the video.""" - return self.filename.split("/")[-1] - - @property - def filepath(self): - """Path to the video file.""" - splitted = self.filename.split("/")[:-1] - return "/".join(splitted) - @property def dtype(self): """See :class:`Video`.""" @@ -476,17 +465,6 @@ def dtype(self): """See :class:`Video`.""" return self.test_frame.dtype - @property - def name(self): - """Name of the video.""" - return self.filename.split("/")[-1] - - @property - def filepath(self): - """Path to the video file.""" - splitted = self.filename.split("/")[:-1] - return "/".join(splitted) - def reset(self, filename: str = None, grayscale: bool = None, bgr: bool = None): """Reloads the video.""" if filename is not None: @@ -612,17 +590,6 @@ def dtype(self): """See :class:`Video`.""" return self.__data.dtype - @property - def name(self): - """Name of the video.""" - return self.filename.split("/")[-1] - - @property - def filepath(self): - """Path to the video file.""" - splitted = self.filename.split("/")[:-1] - return "/".join(splitted) - def reset(self): """Reload the video.""" # TODO @@ -739,17 +706,6 @@ def height(self): """See :class:`Video`.""" return self.__img.shape[0] - @property - def name(self): - """Name of the video.""" - return self.filename.split("/")[-1] - - @property - def filepath(self): - """Path to the video file.""" - splitted = self.filename.split("/")[:-1] - return "/".join(splitted) - @property def dtype(self): """See :class:`Video`.""" @@ -988,17 +944,6 @@ def dtype(self): """See :class:`Video`.""" return self.cache_.dtype - @property - def name(self): - """Name of the video.""" - return self.filename.split("/")[-1] - - @property - def filepath(self): - """Path to the video file.""" - splitted = self.filename.split("/")[:-1] - return "/".join(splitted) - def reset( self, filename: str = None, From 8cac64c77fd37c21b71ef818e8c086eaa1684047 Mon Sep 17 00:00:00 2001 From: 7174Andy Date: Mon, 16 Dec 2024 23:27:55 -0800 Subject: [PATCH 06/17] Update dataviews.py --- sleap/gui/dataviews.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sleap/gui/dataviews.py b/sleap/gui/dataviews.py index aab6e543b..4bf53dd91 100644 --- a/sleap/gui/dataviews.py +++ b/sleap/gui/dataviews.py @@ -495,7 +495,7 @@ def set_show_video_name(self, show_video_name: bool): def item_to_data(self, obj, item: "Video"): data = {} - for property in self.all_properties: + for property in self.properties: if property == "name": data[property] = getattr(item, "filename").split("/")[-1] elif property == "filepath": From 1fa5f02e03a2394f763daf6ad2bebe6a06652817 Mon Sep 17 00:00:00 2001 From: 7174Andy Date: Mon, 16 Dec 2024 23:28:38 -0800 Subject: [PATCH 07/17] remove all properties --- sleap/gui/dataviews.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/sleap/gui/dataviews.py b/sleap/gui/dataviews.py index 4bf53dd91..9aaf23819 100644 --- a/sleap/gui/dataviews.py +++ b/sleap/gui/dataviews.py @@ -461,15 +461,6 @@ def __init__(self, items, show_video_name=False, **kwargs): "channels", ) # TODO: Always with filepath and name (no filename) - self.all_properties = ( - "filename", - "filepath", - "name", - "frames", - "height", - "width", - "channels", - ) def headerData(self, section, orientation, role=QtCore.Qt.DisplayRole): if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole: From 8e6b947ace2aeb487eef6b61f373110c605a4a06 Mon Sep 17 00:00:00 2001 From: 7174Andy Date: Tue, 17 Dec 2024 09:38:59 -0800 Subject: [PATCH 08/17] delete toggle option --- sleap/gui/dataviews.py | 99 ++++-------------------------------------- 1 file changed, 8 insertions(+), 91 deletions(-) diff --git a/sleap/gui/dataviews.py b/sleap/gui/dataviews.py index 9aaf23819..df0927262 100644 --- a/sleap/gui/dataviews.py +++ b/sleap/gui/dataviews.py @@ -390,99 +390,16 @@ def getSelectedRowItem(self) -> Any: return None return self.model().original_items[idx.row()] - def mousePressEvent(self, event) -> None: - """Only for right-click on VideosTableView. - Args: - event (QMouseEvent): The mouse event. - """ - if event.button() == QtCore.Qt.RightButton and isinstance( - self.model(), VideosTableModel - ): - self.show_context_menu(event) - super().mousePressEvent(event) - - def show_context_menu(self, event): - """Show context menu for VideosTableView. - - Args: - event (QMouseEvent): The mouse event. - """ - menu = QtWidgets.QMenu(self) - - # Add actions to the menu - for option, is_checked in self.options.items(): - action = QtWidgets.QAction(option, self) - action.setCheckable(True) - action.setChecked(is_checked) - action.triggered.connect(self.create_checked_lambda(option)) - menu.addAction(action) - - # Show the context menu - menu.exec_(event.globalPos()) - - def create_checked_lambda(self, option): - """Callback for context menu actions. - - Args: - option (dict): The option to toggle. - - Returns: - function: The callback function. - """ - return lambda checked: self.toggle_option(option, checked) - - def toggle_option(self, option, checked): - """Toggle the option in the context menu. - - Args: - option (str): The option to toggle. - checked (bool): The new value for the option. - """ - self.options[option] = checked - model = self.model() - if isinstance(model, VideosTableModel): - if option == "Show Video Name": - model.set_show_video_name(self.options["Show Video Name"]) - - -# TODO: Fix the error in the Pytest. class VideosTableModel(GenericTableModel): - def __init__(self, items, show_video_name=False, **kwargs): - super().__init__(**kwargs) - self.items = items - self.show_video_name = show_video_name - self.properties = ( - "filepath", - "name", - "frames", - "height", - "width", - "channels", - ) - # TODO: Always with filepath and name (no filename) - - def headerData(self, section, orientation, role=QtCore.Qt.DisplayRole): - if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole: - return self.properties[section].title() - return super().headerData(section, orientation, role) - - def _get_properties(self): - """Return properties based on the show_video_name flag.""" - if self.show_video_name: - return ["filepath", "name", "frames", "height", "width", "channels"] - return ["filename", "frames", "height", "width", "channels"] - - def set_show_video_name(self, show_video_name: bool): - """Set whether to show video name in table.""" - if self.show_video_name == show_video_name: - return - - # Reset the table so that new columns are added - self.show_video_name = show_video_name - self.properties = self._get_properties() - self.beginResetModel() - self.endResetModel() + properties = ( + "filepath", + "name", + "frames", + "height", + "width", + "channels", + ) def item_to_data(self, obj, item: "Video"): data = {} From 22dd69efdd0bc75a7855a47c463c79a1fffb8770 Mon Sep 17 00:00:00 2001 From: 7174Andy Date: Tue, 17 Dec 2024 10:26:54 -0800 Subject: [PATCH 09/17] remove video show --- sleap/gui/dataviews.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/sleap/gui/dataviews.py b/sleap/gui/dataviews.py index df0927262..a36f46f8d 100644 --- a/sleap/gui/dataviews.py +++ b/sleap/gui/dataviews.py @@ -291,7 +291,6 @@ class GenericTableView(QtWidgets.QTableView): name_prefix: str = "selected_" is_activatable: bool = False is_sortable: bool = False - show_video_name: bool = False def __init__( self, @@ -306,8 +305,6 @@ def __init__( ): super(GenericTableView, self).__init__() - model.show_video_name = self.show_video_name - self.state = state or GuiState() self.row_name = row_name or self.row_name self.name_prefix = name_prefix if name_prefix is not None else self.name_prefix From 8db81a9c14a96e806b8b4707cf869c72a03d44b9 Mon Sep 17 00:00:00 2001 From: 7174Andy Date: Tue, 17 Dec 2024 10:28:12 -0800 Subject: [PATCH 10/17] fix the order of the columns --- sleap/gui/dataviews.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sleap/gui/dataviews.py b/sleap/gui/dataviews.py index a36f46f8d..470ad889f 100644 --- a/sleap/gui/dataviews.py +++ b/sleap/gui/dataviews.py @@ -390,8 +390,8 @@ def getSelectedRowItem(self) -> Any: class VideosTableModel(GenericTableModel): properties = ( - "filepath", "name", + "filepath", "frames", "height", "width", From 7529acc013364ee7b051471ef752562de15a9ef6 Mon Sep 17 00:00:00 2001 From: 7174Andy Date: Tue, 17 Dec 2024 10:28:47 -0800 Subject: [PATCH 11/17] remove options --- sleap/gui/dataviews.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/sleap/gui/dataviews.py b/sleap/gui/dataviews.py index 470ad889f..009403916 100644 --- a/sleap/gui/dataviews.py +++ b/sleap/gui/dataviews.py @@ -311,9 +311,6 @@ def __init__( self.is_sortable = is_sortable or self.is_sortable self.is_activatable = is_activatable or self.is_activatable self.multiple_selection = multiple_selection - self.options = { - "Show Video Name": self.show_video_name, - } self.setModel(model) From 9d747cb1161f32a8e14ec94bdd0d4268100916fb Mon Sep 17 00:00:00 2001 From: Andrew Park Date: Tue, 17 Dec 2024 14:14:38 -0800 Subject: [PATCH 12/17] Update sleap/gui/dataviews.py Co-authored-by: Liezl Maree <38435167+roomrys@users.noreply.github.com> --- sleap/gui/dataviews.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sleap/gui/dataviews.py b/sleap/gui/dataviews.py index 009403916..cb467dbcb 100644 --- a/sleap/gui/dataviews.py +++ b/sleap/gui/dataviews.py @@ -399,7 +399,8 @@ def item_to_data(self, obj, item: "Video"): data = {} for property in self.properties: if property == "name": - data[property] = getattr(item, "filename").split("/")[-1] + filename = getattr(item, "filename") + name = Path(filename).name elif property == "filepath": splitted = getattr(item, "filename").split("/")[:-1] data[property] = "/".join(splitted) From d38c0c49f7e0ed02f93e4d65999739e516fd6acc Mon Sep 17 00:00:00 2001 From: Andrew Park Date: Tue, 17 Dec 2024 14:14:44 -0800 Subject: [PATCH 13/17] Update sleap/gui/dataviews.py Co-authored-by: Liezl Maree <38435167+roomrys@users.noreply.github.com> --- sleap/gui/dataviews.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sleap/gui/dataviews.py b/sleap/gui/dataviews.py index cb467dbcb..76cb44976 100644 --- a/sleap/gui/dataviews.py +++ b/sleap/gui/dataviews.py @@ -402,7 +402,8 @@ def item_to_data(self, obj, item: "Video"): filename = getattr(item, "filename") name = Path(filename).name elif property == "filepath": - splitted = getattr(item, "filename").split("/")[:-1] + filename = getattr(item, "filename") + parent = Path(filename).parent data[property] = "/".join(splitted) else: data[property] = getattr(item, property) From 946082d651c0d4c3374c64278505c8cdffc4da37 Mon Sep 17 00:00:00 2001 From: 7174Andy Date: Tue, 17 Dec 2024 14:21:14 -0800 Subject: [PATCH 14/17] use pathlib instead of substrings --- sleap/gui/dataviews.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sleap/gui/dataviews.py b/sleap/gui/dataviews.py index 76cb44976..6a6653713 100644 --- a/sleap/gui/dataviews.py +++ b/sleap/gui/dataviews.py @@ -19,6 +19,7 @@ import numpy as np import os +import pathlib from operator import itemgetter @@ -400,11 +401,11 @@ def item_to_data(self, obj, item: "Video"): for property in self.properties: if property == "name": filename = getattr(item, "filename") - name = Path(filename).name + data[property] = pathlib.Path(filename).name elif property == "filepath": filename = getattr(item, "filename") - parent = Path(filename).parent - data[property] = "/".join(splitted) + data[property] = str(pathlib.Path(filename).parent) + print(data[property]) else: data[property] = getattr(item, property) return data From d1586331cd76e37353f857ceff4c9ebf0e822526 Mon Sep 17 00:00:00 2001 From: Andrew Park Date: Tue, 17 Dec 2024 17:10:33 -0800 Subject: [PATCH 15/17] Update dataviews.py Co-authored-by: Liezl Maree <38435167+roomrys@users.noreply.github.com> --- sleap/gui/dataviews.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sleap/gui/dataviews.py b/sleap/gui/dataviews.py index 6a6653713..dfbaad496 100644 --- a/sleap/gui/dataviews.py +++ b/sleap/gui/dataviews.py @@ -405,7 +405,6 @@ def item_to_data(self, obj, item: "Video"): elif property == "filepath": filename = getattr(item, "filename") data[property] = str(pathlib.Path(filename).parent) - print(data[property]) else: data[property] = getattr(item, property) return data From 69b627358db6ed24c0e43b5439ee977b815e084c Mon Sep 17 00:00:00 2001 From: roomrys <38435167+roomrys@users.noreply.github.com> Date: Tue, 17 Dec 2024 17:22:55 -0800 Subject: [PATCH 16/17] Use Path instead of pathlib.Path and sort imports and remove unused imports --- sleap/gui/dataviews.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/sleap/gui/dataviews.py b/sleap/gui/dataviews.py index dfbaad496..bd99d1ecf 100644 --- a/sleap/gui/dataviews.py +++ b/sleap/gui/dataviews.py @@ -15,21 +15,17 @@ """ -from qtpy import QtCore, QtWidgets, QtGui - -import numpy as np import os -import pathlib - from operator import itemgetter +from pathlib import Path +from typing import Any, Callable, List, Optional -from typing import Any, Callable, Dict, List, Optional, Type +import numpy as np +from qtpy import QtCore, QtGui, QtWidgets -from sleap.gui.state import GuiState from sleap.gui.commands import CommandContext -from sleap.gui.color import ColorManager -from sleap.io.dataset import Labels -from sleap.instance import LabeledFrame, Instance +from sleap.gui.state import GuiState +from sleap.instance import LabeledFrame from sleap.skeleton import Skeleton @@ -401,10 +397,10 @@ def item_to_data(self, obj, item: "Video"): for property in self.properties: if property == "name": filename = getattr(item, "filename") - data[property] = pathlib.Path(filename).name + data[property] = Path(filename).name elif property == "filepath": filename = getattr(item, "filename") - data[property] = str(pathlib.Path(filename).parent) + data[property] = str(Path(filename).parent) else: data[property] = getattr(item, property) return data From 5b1b7e9d24d7b9935cad3b886b2c5f682b2a98c3 Mon Sep 17 00:00:00 2001 From: roomrys <38435167+roomrys@users.noreply.github.com> Date: Tue, 17 Dec 2024 17:24:58 -0800 Subject: [PATCH 17/17] Use item.filename instead of getattr --- sleap/gui/dataviews.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sleap/gui/dataviews.py b/sleap/gui/dataviews.py index bd99d1ecf..721bdc321 100644 --- a/sleap/gui/dataviews.py +++ b/sleap/gui/dataviews.py @@ -396,11 +396,9 @@ def item_to_data(self, obj, item: "Video"): data = {} for property in self.properties: if property == "name": - filename = getattr(item, "filename") - data[property] = Path(filename).name + data[property] = Path(item.filename).name elif property == "filepath": - filename = getattr(item, "filename") - data[property] = str(Path(filename).parent) + data[property] = str(Path(item.filename).parent) else: data[property] = getattr(item, property) return data