diff --git a/gui/v2/ui/pages/location_page.py b/gui/v2/ui/pages/location_page.py index 977c33c..84d7364 100755 --- a/gui/v2/ui/pages/location_page.py +++ b/gui/v2/ui/pages/location_page.py @@ -1,6 +1,6 @@ import os -from PyQt6.QtWidgets import QApplication, QLabel, QPushButton, QButtonGroup +from PyQt6.QtWidgets import QApplication, QLabel, QPushButton, QButtonGroup, QScrollArea, QWidget from PyQt6.QtGui import QPixmap, QIcon, QPainter, QColor, QFont, QTransform from PyQt6.QtCore import Qt from PyQt6 import QtCore @@ -20,6 +20,7 @@ class LocationPage(Page): self.display.setGeometry(QtCore.QRect(5, 10, 390, 520)) self.title.setGeometry(395, 40, 380, 40) self.title.setText("Pick a location") + self._setup_scroll_area() self.initial_display = QLabel(self) self.initial_display.setGeometry(5, 22, 355, 485) @@ -70,13 +71,24 @@ class LocationPage(Page): self.refresh_protocol_location_visibility() def create_interface_elements(self, available_locations): + old_button_widget = self.scroll_area.takeWidget() + if old_button_widget is not None: + old_button_widget.deleteLater() + button_widget = QWidget() + button_widget.setStyleSheet("background: transparent;") + self._button_widget = button_widget self.buttonGroup = QButtonGroup(self) self.buttons = [] for j, (object_type, icon_name, geometry) in enumerate(available_locations): - boton = object_type(self) - boton.setGeometry(*geometry) + boton = object_type(button_widget) + boton.setGeometry( + 0, + 0, + geometry[2], + geometry[3], + ) boton.setIconSize(boton.size()) boton.setCheckable(True) @@ -123,11 +135,61 @@ class LocationPage(Page): boton.clicked.connect( lambda checked, loc=icon_name: self.show_location(loc)) + content_height = max( + (geometry[3] for _, _, geometry in available_locations), + default=0, + ) + button_widget.setFixedSize(380, max(1, content_height)) + self.scroll_area.setWidget(button_widget) + self._layout_visible_buttons() + + def _setup_scroll_area(self): + self.scroll_area = QScrollArea(self) + self.scroll_area.setGeometry(405, 90, 385, 400) + self.scroll_area.setWidgetResizable(False) + self.scroll_area.setHorizontalScrollBarPolicy( + Qt.ScrollBarPolicy.ScrollBarAlwaysOff) + self.scroll_area.setStyleSheet(""" + QScrollArea { + background: transparent; + border: none; + } + QScrollBar:vertical { + background: transparent; + border: none; + width: 10px; + margin: 0px 0px 0px 4px; + } + QScrollBar::handle:vertical { + background: #00ffff; + border-radius: 5px; + min-height: 20px; + margin: 1px 0px; + } + QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical { + height: 0px; + } + """) + def refresh_protocol_location_visibility(self): for button in self.buttons: location_key = getattr(button, 'location_icon_name', None) locations = self.connection_manager.get_location_info(location_key) button.setVisible(not locations or self._location_supports_selected_protocol(locations)) + self._layout_visible_buttons() + + def _layout_visible_buttons(self): + visible_buttons = [button for button in self.buttons if not button.isHidden()] + for index, button in enumerate(visible_buttons): + button.move((index % 2) * 195, (index // 2) * 105) + + if hasattr(self, '_button_widget'): + button_height = self.buttons[0].height() if self.buttons else 0 + row_count = (len(visible_buttons) + 1) // 2 + self._button_widget.setFixedSize( + 380, + max(1, row_count * 105 - 30 + button_height), + ) def _current_protocol(self): profile_data = self.update_status.read_data()