dataviews
sleap.gui.dataviews
¶
Data table widgets and view models used in GUI app.
Typically you'll need to subclass :py: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 :py: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 |
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 |
|
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
37 38 39 40 41 42 43 44 45 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 | |
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)
¶
Virtual method, returns whether table cell is editable.
Source code in sleap/gui/dataviews.py
250 251 252 | |
columnCount(parent=None)
¶
Overrides Qt method, returns number of columns (attributes).
Source code in sleap/gui/dataviews.py
185 186 187 | |
data(index, role=QtCore.Qt.DisplayRole)
¶
Overrides Qt method, returns data to show in table.
Source code in sleap/gui/dataviews.py
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 | |
flags(index)
¶
Overrides Qt method, returns whether item is selectable etc.
Source code in sleap/gui/dataviews.py
258 259 260 261 262 263 264 265 | |
get_from_idx(index)
¶
Gets item from QModelIndex.
Source code in sleap/gui/dataviews.py
242 243 244 245 246 247 248 | |
get_item_color(item, key)
¶
Virtual method, returns color for given item.
Source code in sleap/gui/dataviews.py
122 123 124 | |
headerData(idx, orientation, role=QtCore.Qt.DisplayRole)
¶
Overrides Qt method, returns column (attribute) names.
Source code in sleap/gui/dataviews.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
object_to_items(item_list)
¶
Virtual method, convert object to list of items to show in rows.
Source code in sleap/gui/dataviews.py
81 82 83 | |
rowCount(parent=None)
¶
Overrides Qt method, returns number of rows (items).
Source code in sleap/gui/dataviews.py
181 182 183 | |
setData(index, value, role=QtCore.Qt.EditRole)
¶
Overrides Qt method, dispatch for settable properties.
Source code in sleap/gui/dataviews.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
set_item(item, key, value)
¶
Virtual method, used to set value for item in table cell.
Source code in sleap/gui/dataviews.py
254 255 256 | |
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
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 | |
GenericTableView
¶
Bases: QTableView
Qt table view for use with GenericTableModel (and subclasses).
Uses the :py: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
268 269 270 271 272 273 274 275 276 277 278 279 280 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 | |
activateSelected(*args)
¶
Activate item currently selected in table.
"Activate" means that the relevant :py:class:GuiState state variable
is set to the currently selected item.
Source code in sleap/gui/dataviews.py
342 343 344 345 346 347 348 349 | |
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
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 | |
selectRow(idx)
¶
Select row corresponding to index.
Source code in sleap/gui/dataviews.py
368 369 370 | |
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
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | |
selectionChanged(new, old)
¶
Custom event handler.
Source code in sleap/gui/dataviews.py
334 335 336 337 338 339 340 | |
LabeledFrameTableModel
¶
Bases: GenericTableModel
Table model for listing instances in labeled frame.
Allows editing track names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labeled_frame
|
|
required | |
labels
|
|
required |
Source code in sleap/gui/dataviews.py
467 468 469 470 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 | |
SkeletonEdgesTableModel
¶
Bases: GenericTableModel
Table model for skeleton edges.
Source code in sleap/gui/dataviews.py
451 452 453 454 455 456 457 458 459 460 461 462 463 464 | |
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
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 | |
skeleton
property
writable
¶
Gets or sets current skeleton.
columnCount(parent)
¶
Overrides Qt method, returns number of columns (1).
Source code in sleap/gui/dataviews.py
668 669 670 | |
data(index, role=QtCore.Qt.DisplayRole)
¶
Overrides Qt method, returns data for given row.
Source code in sleap/gui/dataviews.py
656 657 658 659 660 661 662 | |
flags(index)
¶
Overrides Qt method, returns flags (editable etc).
Source code in sleap/gui/dataviews.py
672 673 674 | |
rowCount(parent)
¶
Overrides Qt method, returns number of rows.
Source code in sleap/gui/dataviews.py
664 665 666 | |
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
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 | |
object_to_items(skeleton)
¶
Converts given skeleton to list of nodes to show in table.
Source code in sleap/gui/dataviews.py
432 433 434 435 436 | |
SuggestionsTableModel
¶
Bases: GenericTableModel
Methods:
| Name | Description |
|---|---|
sort |
Sorts table by given column and order. |
Source code in sleap/gui/dataviews.py
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 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 | |
sort(column_idx, order)
¶
Sorts table by given column and order.
Source code in sleap/gui/dataviews.py
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 | |