Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions rkdeveloptool-gui/rkdevtoolgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,19 +672,20 @@ def create_right_panel(self):
return panel

def _resize_tabs_to_current(self, index):
"""Make the tab widget take the height of the current tab only.
"""Make the tab widget take the size of the current tab only.

Non-current pages get an Ignored vertical size policy so they don't
inflate the tab widget's size hint; the current page uses its natural
height. This keeps short tabs compact and lets the log panel fill the
rest of the column.
Non-current pages get Ignored size policies so they don't inflate
the tab widget: in height, short tabs stay compact and the log panel
fills the rest of the column; in width, the two-column Settings page
no longer makes every tab wider than the panel at the default
window size.
"""
for i in range(self.tab_widget.count()):
page = self.tab_widget.widget(i)
if page is None:
continue
vpol = QSizePolicy.Policy.Preferred if i == index else QSizePolicy.Policy.Ignored
page.setSizePolicy(QSizePolicy.Policy.Preferred, vpol)
policy = QSizePolicy.Policy.Preferred if i == index else QSizePolicy.Policy.Ignored
page.setSizePolicy(policy, policy)
# CurrentPageTabWidget sizes itself from the current page; let the
# layout re-ask. (No adjustSize() on the page: that shrank it to its
# size hint for a frame before the layout stretched it back, which
Expand Down Expand Up @@ -819,7 +820,7 @@ def on_theme_changed(self):
# Enable automatic theme detection
if hasattr(self, 'theme_auto_manager'):
self.theme_auto_manager.enable_auto = True
self.theme_auto_manager.apply_system_theme()
self.theme_auto_manager.apply_system_theme(force=True)
elif selected_theme:
# Disable auto and apply selected theme
if hasattr(self, 'theme_auto_manager'):
Expand Down
12 changes: 10 additions & 2 deletions rkdeveloptool-gui/themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,9 @@ def _get_windows_theme(self):
except Exception:
return "light"

def apply_system_theme(self):
"""Apply system theme to the application"""
def apply_system_theme(self, force=False):
"""Apply the system theme when it has changed (or when forced: on
start-up, and when the user picks Auto)."""
if not self.enable_auto:
return

Expand All @@ -392,6 +393,13 @@ def apply_system_theme(self):
return

theme = self.get_system_theme()
# The poll runs every 2 s. Applying a theme restyles and relays out
# every widget in the app, so doing it each time kept the window
# busy for nothing, and on a slow machine (CI's macOS runner) the
# next poll came before the last one finished and it never idled.
if theme == getattr(self, "_applied", None) and not force:
return
self._applied = theme

# Leave the picker on "Auto". Moving it to Dark/Light hid that auto
# mode was on, and picking that same theme afterwards changed nothing,
Expand Down
14 changes: 0 additions & 14 deletions rkdeveloptool-gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,6 @@ def sizeHint(self):
return hint
return QSize(hint.width(), page.sizeHint().height() + self._chrome(page)[1])

def minimumSizeHint(self):
# Likewise the width: the widest page (Settings, two columns) made
# every tab that wide, and the right panel scrolled sideways at the
# default window size.
hint = super().minimumSizeHint()
page = self.currentWidget()
if page is None:
return hint
# The frame's share: the stock minimum less its widest page's.
widest = max(self.widget(i).minimumSizeHint().width() for i in range(self.count()))
frame = max(hint.width() - widest, 0)
width = max(page.minimumSizeHint().width() + frame, self.tabBar().minimumSizeHint().width())
return QSize(width, hint.height())

def heightForWidth(self, width):
# Pages with word-wrapped labels make the whole column height-for-
# width, and then the scroll area sizes it from this - which Qt also
Expand Down
48 changes: 48 additions & 0 deletions tests/smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

pip install . && python tests/smoke.py
"""
import faulthandler
import os
import stat
import sys
Expand Down Expand Up @@ -3115,6 +3116,33 @@ def yes_text():
errors.append(f"Qt's Yes button in Chinese reads {zh!r} (English {en!r})")


def check_theme_poll(app):
"""The 2-second system-theme poll restyles the app only when the
system's theme changed; doing it every time kept slow machines busy."""
window = RKDevToolGUI(TranslationManager(lang="en", settings=AppSettings()),
settings=AppSettings())
window.stop_device_detection()
auto = window.theme_auto_manager
applied, system = [], ["dark"]
real = (window.theme_manager.apply_theme, auto.get_system_theme)
window.theme_manager.apply_theme = lambda theme=None, style=None: applied.append(theme)
auto.get_system_theme = lambda: system[0]
auto.enable_auto = True
try:
auto.apply_system_theme(force=True)
auto.apply_system_theme()
auto.apply_system_theme()
system[0] = "light"
auto.apply_system_theme()
if applied != ["dark", "light"]:
errors.append(f"theme poll applied {applied}")
finally:
window.theme_manager.apply_theme, auto.get_system_theme = real
window.cleanup()
window.deleteLater()
app.processEvents()


def run_window(app, lang):
settings = AppSettings()
manager = TranslationManager(lang=lang, settings=settings)
Expand All @@ -3128,7 +3156,26 @@ def run_window(app, lang):
app.processEvents()


def _timed(check):
"""Log each check and how long it took to stderr, which CI shows as it
happens (stdout is buffered until the end)."""
def run(*args):
start = time.monotonic()
try:
return check(*args)
finally:
print(f"[smoke] {check.__name__} {time.monotonic() - start:.1f}s", file=sys.stderr, flush=True)
run.__name__ = check.__name__
return run


def main():
# CI stops the job at 15 minutes with no clue where it hung: dump every
# thread's stack before that and exit.
faulthandler.dump_traceback_later(13 * 60, exit=True)
for name, value in list(globals().items()):
if name.startswith("check_") and callable(value):
globals()[name] = _timed(value)
app = QApplication(sys.argv)
app.setOrganizationName(app_settings.ORGANIZATION)
app.setApplicationName(app_settings.APPLICATION)
Expand All @@ -3142,6 +3189,7 @@ def main():

check_translations()
check_qt_translation(app)
check_theme_poll(app)
check_partition_backup(app)
check_first_run_wizard(app)
check_maskrom_help(app)
Expand Down
Loading