dataviews
sleap.gui.dataviews
¶
Data table widgets and view models used in GUI app.
Typically you'll need to subclass class:
GenericTableModel for your data
(unless your data is already a list of dictionaries with keys matching
the columns of the table you want), but you can use class:
GenericTableView
as is. For example::
videos_table = GenericTableView(
state=self.state,
row_name="video",
is_activatable=True,
model=VideosTableModel(items=self.labels.videos, context=self.commands),
)
Classes:
| Name | Description |
|---|---|
GenericTableModel |
Generic Qt table model to show a list of properties for some items. |
GenericTableView |
Qt table view for use with |
InstancesTableView |
Instances table with shift/ctrl multi-select for Merge Instance. |
LabeledFrameTableModel |
Table model for listing instances in labeled frame. |
SkeletonEdgesTableModel |
Table model for skeleton edges. |
SkeletonNodeModel |
String list model for source/destination nodes of edges. |
SkeletonNodesTableModel |
|
SuggestionsTableModel |
|
VideosTableModel |
|
GenericTableModel
¶
Bases: QAbstractTableModel
Generic Qt table model to show a list of properties for some items.
Typically this will be used as base class. Subclasses can implement methods:
object_to_items: allows conversion from a single object to a list of
items which correspond to rows of table. for example, a table
which shows skeleton nodes could implement this method and return
the list of nodes for skeleton.
item_to_data: if each item isn't already a dictionary with keys for
columns of table (i.e., properties attribute) and values to show
in table, then use this method to convert each item to such a dict.
Note that if you need to convert a single object to a list of dictionaries,
you can implement both steps in object_to_items (and use the default
implementation of item_to_data which doesn't do any conversion), or you
can implement this in two steps using the two methods. It doesn't make
much difference which you do.
For editable table, you must implement can_set and set_item methods.
Usually it's simplest to override properties in the subclass, rather
than passing as an init arg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
properties
|
Optional[List[str]]
|
The list of property names (table columns). |
None
|
items
|
Optional[list]
|
The list of items with said properties (rows). |
None
|
context
|
Optional[CommandContext]
|
A command context (required for editable items). |
None
|
Methods:
| Name | Description |
|---|---|
can_set |
Virtual method, returns whether table cell is editable. |
columnCount |
Overrides Qt method, returns number of columns (attributes). |
data |
Overrides Qt method, returns data to show in table. |
flags |
Overrides Qt method, returns whether item is selectable etc. |
get_from_idx |
Gets item from QModelIndex. |
get_item_color |
Virtual method, returns color for given item. |
headerData |
Overrides Qt method, returns column (attribute) names. |
object_to_items |
Virtual method, convert object to list of items to show in rows. |
rowCount |
Overrides Qt method, returns number of rows (items). |
setData |
Overrides Qt method, dispatch for settable properties. |
set_item |
Virtual method, used to set value for item in table cell. |
sort |
Sorts table by given column and order. |
Attributes:
| Name | Type | Description |
|---|---|---|
items |
Gets or sets list of items to show in table. |
|
original_items |
Gets the original items (rather than the dictionary we build from it). |
Source code in sleap/gui/dataviews.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
items
property
writable
¶
Gets or sets list of items to show in table.
original_items
property
¶
Gets the original items (rather than the dictionary we build from it).
can_set(item, key)
¶
columnCount(parent=None)
¶
data(index, role=QtCore.Qt.DisplayRole)
¶
Overrides Qt method, returns data to show in table.
Source code in sleap/gui/dataviews.py
flags(index)
¶
Overrides Qt method, returns whether item is selectable etc.
Source code in sleap/gui/dataviews.py
get_from_idx(index)
¶
Gets item from QModelIndex.
get_item_color(item, key)
¶
headerData(idx, orientation, role=QtCore.Qt.DisplayRole)
¶
Overrides Qt method, returns column (attribute) names.
Source code in sleap/gui/dataviews.py
object_to_items(item_list)
¶
rowCount(parent=None)
¶
setData(index, value, role=QtCore.Qt.EditRole)
¶
Overrides Qt method, dispatch for settable properties.
Source code in sleap/gui/dataviews.py
set_item(item, key, value)
¶
sort(column_idx, order=QtCore.Qt.SortOrder.AscendingOrder)
¶
Sorts table by given column and order.
Correctly sorts numeric string (i.e., "123.45") numerically rather than alphabetically. Has logic for correctly sorting video frames by video then frame index.
Source code in sleap/gui/dataviews.py
GenericTableView
¶
Bases: QTableView
Qt table view for use with GenericTableModel (and subclasses).
Uses the class:
GuiState object to keep track of which row/item is
selected. If the row_name attribute is "foo", then a "foo_selected"
state will be item corresponding to the currently selected row in table
(and the table will select the row if this state is updated by something
else). When is_activatable is True, then a "foo" state will also be
set to the item when a row is activated--typically by being double-clicked.
This state can then be used to trigger something else outside the table.
Note that by default "selected_" is used for the state key, e.g.,
"selected_foo", but you can set the name_prefix attribute/init arg if
for some reason you need this to be different. For instance, the table
of instances in the GUI sets this to "" so that the row for an instance
is automatically selected when state["instance"] is set outside the table.
"ellipsis_left" can be used to make the TableView truncate cell content on the left instead of the right side. By default, the argument is set to False, i.e. truncation on the right side, which is also the default for QTableView.
Methods:
| Name | Description |
|---|---|
activateSelected |
Activate item currently selected in table. |
getSelectedRowItem |
Return item corresponding to currently selected row. |
selectRow |
Select row corresponding to index. |
selectRowItem |
Select row corresponding to item. |
selectionChanged |
Custom event handler. |
Source code in sleap/gui/dataviews.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | |
activateSelected(*args)
¶
Activate item currently selected in table.
"Activate" means that the relevant class:
GuiState state variable
is set to the currently selected item.
Source code in sleap/gui/dataviews.py
getSelectedRowItem()
¶
Return item corresponding to currently selected row.
Note that if the table model converts items to dictionaries (using
item_to_data method), then returned item will be the original item,
not the converted dict.
Source code in sleap/gui/dataviews.py
selectRow(idx)
¶
selectRowItem(item)
¶
Select row corresponding to item.
If the table model converts items to dictionaries (using item_to_data
method), then item argument should be the original item, not the
converted dict.
Source code in sleap/gui/dataviews.py
selectionChanged(new, old)
¶
Custom event handler.
InstancesTableView
¶
Bases: GenericTableView
Instances table with shift/ctrl multi-select for Merge Instance.
Selecting a second instance (shift- or ctrl-click) marks it as the merge
donor: the first-selected instance is the survivor (state["instance"],
kept) and the second is the donor (state["merge_partner"], merged in and
removed). Single selection behaves exactly like the base view. Selection
order is tracked explicitly because Qt's "current" index follows the last
click, which would otherwise make the donor (2nd) the survivor.
Methods:
| Name | Description |
|---|---|
selectRowItem |
Skip while syncing so our own state set doesn't clear the selection. |
selectionChanged |
Set survivor/donor GuiState from the click-ordered selection. |
Source code in sleap/gui/dataviews.py
selectRowItem(item)
¶
Skip while syncing so our own state set doesn't clear the selection.
selectionChanged(new, old)
¶
Set survivor/donor GuiState from the click-ordered selection.
Source code in sleap/gui/dataviews.py
LabeledFrameTableModel
¶
Bases: GenericTableModel
Table model for listing instances in labeled frame.
Allows editing track names.
In addition to the informational columns, three checkbox columns control
per-instance rendering on the video canvas (transient, session-only state;
see sleap.gui.state.instance_visible /
sleap.gui.state.instance_shows_non_visible):
- "visibility": checked by default; unchecking hides that instance on the canvas while keeping its row in the table.
- "view only": unchecked by default; checking exactly one row makes only that instance visible and disables the whole visibility column. Checking another row's "view only" auto-unchecks the previous (radio-like). Toggling any "visibility" box exits view-only mode.
- "invisible nodes": per-instance override of the global "Show Non-Visible Nodes" flag; defaults to the effective value (override if present, else the global flag). Because non-visible nodes are baked into the canvas instance at creation time, toggling this forces a full replot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labeled_frame
|
|
required | |
labels
|
|
required |
Methods:
| Name | Description |
|---|---|
data |
Overrides Qt method to add checkbox state for the new columns. |
flags |
Overrides Qt method to make the new columns user-checkable. |
is_show_nonvisible_checked |
Whether the "invisible nodes" box is checked (effective value). |
is_view_only_checked |
Whether the "view only" box is checked for the given instance. |
is_visibility_checked |
Whether the "visibility" box is checked for the given instance. |
setData |
Overrides Qt method to toggle the per-instance visibility state. |
Source code in sleap/gui/dataviews.py
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 | |
data(index, role=QtCore.Qt.DisplayRole)
¶
Overrides Qt method to add checkbox state for the new columns.
Source code in sleap/gui/dataviews.py
flags(index)
¶
Overrides Qt method to make the new columns user-checkable.
Both checkbox columns stay enabled and user-checkable at all times.
During view-only mode the "visibility" column is rendered greyed (see
data) to signal it is overridden, but it remains clickable so that
toggling any visibility box exits view-only mode (per the feature spec).
Source code in sleap/gui/dataviews.py
is_show_nonvisible_checked(instance)
¶
Whether the "invisible nodes" box is checked (effective value).
Source code in sleap/gui/dataviews.py
is_view_only_checked(instance)
¶
Whether the "view only" box is checked for the given instance.
Source code in sleap/gui/dataviews.py
is_visibility_checked(instance)
¶
Whether the "visibility" box is checked for the given instance.
setData(index, value, role=QtCore.Qt.EditRole)
¶
Overrides Qt method to toggle the per-instance visibility state.
Source code in sleap/gui/dataviews.py
SkeletonEdgesTableModel
¶
Bases: GenericTableModel
Table model for skeleton edges.
Source code in sleap/gui/dataviews.py
SkeletonNodeModel
¶
Bases: QStringListModel
String list model for source/destination nodes of edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skeleton
|
Skeleton
|
The skeleton for which to list nodes. |
required |
src_node
|
Callable
|
If given, then we assume that this model is being used for edge destination node. Otherwise, we assume that this model is being used for an edge source node. If given, then this should be function that will return the selected edge source node. |
None
|
Methods:
| Name | Description |
|---|---|
columnCount |
Overrides Qt method, returns number of columns (1). |
data |
Overrides Qt method, returns data for given row. |
flags |
Overrides Qt method, returns flags (editable etc). |
rowCount |
Overrides Qt method, returns number of rows. |
Attributes:
| Name | Type | Description |
|---|---|---|
skeleton |
Gets or sets current skeleton. |
Source code in sleap/gui/dataviews.py
979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 | |
SkeletonNodesTableModel
¶
Bases: GenericTableModel
Methods:
| Name | Description |
|---|---|
object_to_items |
Converts given skeleton to list of nodes to show in table. |
Source code in sleap/gui/dataviews.py
object_to_items(skeleton)
¶
SuggestionsTableModel
¶
Bases: GenericTableModel
Methods:
| Name | Description |
|---|---|
sort |
Sorts table by given column and order. |
Source code in sleap/gui/dataviews.py
895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 | |
sort(column_idx, order)
¶
Sorts table by given column and order.
Source code in sleap/gui/dataviews.py
VideosTableModel
¶
Bases: GenericTableModel
Source code in sleap/gui/dataviews.py
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 | |