Skip to content

Commit

Permalink
Add resize/scroll to training GUI (#1565)
Browse files Browse the repository at this point in the history
* Make resizable training GUI and add adaptive scroll bar

* Set a maximum window size

---------

Co-authored-by: Liezl Maree <[email protected]>
  • Loading branch information
KevinZ0217 and roomrys authored Jan 5, 2024
1 parent 2d24296 commit 16241e0
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions sleap/gui/learning/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
from sleap.gui.dialogs.formbuilder import YamlFormWidget
from sleap.gui.learning import runners, scopedkeydict, configs, datagen, receptivefield

from typing import Dict, List, Optional, Text, Optional, cast
from typing import Dict, List, Text, Optional, cast

from qtpy import QtWidgets, QtCore

import json

# List of fields which should show list of skeleton nodes
Expand Down Expand Up @@ -128,12 +127,25 @@ def __init__(
self.message_widget = QtWidgets.QLabel("")

# Layout for entire dialog
layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.tab_widget)
layout.addWidget(self.message_widget)
layout.addWidget(buttons_layout_widget)
content_widget = QtWidgets.QWidget()
content_layout = QtWidgets.QVBoxLayout(content_widget)

self.setLayout(layout)
content_layout.addWidget(self.tab_widget)
content_layout.addWidget(self.message_widget)
content_layout.addWidget(buttons_layout_widget)

# Create the QScrollArea.
scroll_area = QtWidgets.QScrollArea()
scroll_area.setWidgetResizable(True)
scroll_area.setWidget(content_widget)

scroll_area.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
scroll_area.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)

layout = QtWidgets.QVBoxLayout(self)
layout.addWidget(scroll_area)

self.adjust_initial_size()

# Default to most recently trained pipeline (if there is one)
self.set_default_pipeline_tab()
Expand All @@ -157,6 +169,20 @@ def __init__(
self.view_datagen
)

def adjust_initial_size(self):
# Get screen size
screen = QtWidgets.QDesktopWidget().screenGeometry()

max_width = 1860
max_height = 1150
margin = 0.10

# Calculate target width and height
target_width = min(screen.width() - screen.width() * margin, max_width)
target_height = min(screen.height() - screen.height() * margin, max_height)
# Set the dialog's dimensions
self.resize(target_width, target_height)

def update_file_lists(self):
self._cfg_getter.update()
for tab in self.tabs.values():
Expand Down

0 comments on commit 16241e0

Please sign in to comment.