Skip to content

Commit

Permalink
new feature added successfully
Browse files Browse the repository at this point in the history
  • Loading branch information
7174Andy committed Dec 17, 2024
1 parent 788e8bc commit a92fc2d
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 23 deletions.
54 changes: 34 additions & 20 deletions sleap/gui/dataviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
51 changes: 48 additions & 3 deletions sleap/io/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`."""
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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`."""
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a92fc2d

Please sign in to comment.