gallery_widget
anomaly_match_ui.widgets.gallery_widget
¶
Paginated thumbnail gallery with sort controls.
GalleryWidget(on_magnify=None, on_star=None, cell_factory=None, setup_mode=False)
¶
Paginated thumbnail grid with sort controls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
on_magnify
|
Callable[[str], None] | None
|
Callback invoked with filename when a thumbnail's magnify button is clicked. |
None
|
on_star
|
Callable[[str], None] | None
|
Callback invoked with filename when a thumbnail's star button is clicked. |
None
|
cell_factory
|
Callable[..., object] | None
|
Optional callable to create custom cell widgets. Called
with |
None
|
setup_mode
|
bool
|
When |
False
|
Source code in anomaly_match_ui/widgets/gallery_widget.py
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 | |
effective_page_size
property
¶
Cells shown per page at the current column count.
Equal to _ROWS * columns — the grid shows exactly this many
cells, so pagination consumers (gallery_screen_base,
training_setup_screen) slice their data with this rather than the
static :data:PAGE_SIZE and every cell stays reachable by paging.
set_pagination(page, total_pages, total_count)
¶
Update only the pagination label and button states.
Cheap enough to call on the UI thread — touches no cells and issues no DB query — so a background poll refresh can keep the page counter current without disturbing (or re-spinning) the visible thumbnails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
page
|
int
|
Current zero-based page index. |
required |
total_pages
|
int
|
Total number of pages. |
required |
total_count
|
int
|
Total number of results. |
required |
Source code in anomaly_match_ui/widgets/gallery_widget.py
begin_page(page, total_pages, total_count, n_loading)
¶
Flip to page instantly, showing spinners while images load.
Called on the UI thread the moment the user navigates so the page
turns without waiting on the DB query or image decode: the first
n_loading cells show a loading spinner and the rest are cleared.
Filenames, scores, and images are filled in afterwards from a
background thread. This is what makes Next/Previous
non-blocking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
page
|
int
|
Current zero-based page index. |
required |
total_pages
|
int
|
Total number of pages. |
required |
total_count
|
int
|
Total number of results. |
required |
n_loading
|
int
|
Number of leading cells to put in the loading state. |
required |
Source code in anomaly_match_ui/widgets/gallery_widget.py
update_page(results, page, total_pages, total_count, image_loader=None)
¶
Fill the grid cells from a page of DB results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
list[dict]
|
List of dicts with keys |
required |
page
|
int
|
Current zero-based page index. |
required |
total_pages
|
int
|
Total number of pages. |
required |
total_count
|
int
|
Total number of results. |
required |
image_loader
|
Callable[[str], bytes | None] | None
|
Callable that returns PNG bytes for a filename, or None if unavailable. |
None
|
Source code in anomaly_match_ui/widgets/gallery_widget.py
get_sort_mode()
¶
Return the current sort key.
Returns:
| Type | Description |
|---|---|
str
|
Sort key string (e.g. |
set_on_sort_change(callback)
¶
Register a callback for sort mode changes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callback
|
Callable[[], None]
|
Called when the user clicks a different sort button. |
required |
Source code in anomaly_match_ui/widgets/gallery_widget.py
set_on_page_change(callback)
¶
Register a callback for page changes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callback
|
Callable[[int], None]
|
Called with the new page index. |
required |
set_on_scale_change(callback)
¶
Register a callback for slider changes.
The consumer should re-render the current page using the new
:attr:effective_page_size so paging tracks what's visible.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callback
|
Callable[[], None]
|
Zero-arg callable invoked after the slider's CSS update has been applied. |
required |
Source code in anomaly_match_ui/widgets/gallery_widget.py
page_size_for_columns(n_columns)
¶
Return the page size for a grid n_columns wide.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_columns
|
int
|
Number of thumbnail columns the user selected. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Cells per page — exactly |
int
|
visible rows are always full and pagination never skips a cell. |