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
13 changes: 13 additions & 0 deletions PyReconstruct/modules/gui/main/field_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import time

from PySide6.QtWidgets import (
QLabel,
QMainWindow,
QWidget,
QGestureEvent,
Expand Down Expand Up @@ -99,6 +100,18 @@ def __init__(self, series : Series, mainwindow : QMainWindow):
self.mouse_mode = POINTER
self.setCursor(QCursor(Qt.ArrowCursor))

# focus mode label, shown and placed by updateFocusHint. Its own style
# sheet so a theme's QLabel rule does not repaint it; plain text so an
# object name is never read as markup; clicks go through to the field.
self.focus_hint = QLabel(self)
self.focus_hint.setTextFormat(Qt.PlainText)
self.focus_hint.setAttribute(Qt.WA_TransparentForMouseEvents)
self.focus_hint.setStyleSheet(
"QLabel { background-color: rgba(0, 0, 0, 170); color: white;"
" border-radius: 4px; padding: 4px 8px; }"
)
self.focus_hint.hide()

self.createField(series)

self.show()
Expand Down
44 changes: 43 additions & 1 deletion PyReconstruct/modules/gui/main/field_widget_1_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
import time

from PySide6.QtWidgets import (
QLabel,
QMainWindow,
QTextEdit,
)
from PySide6.QtGui import (
QPainter,
QCursor,
QAction
QAction,
QKeySequence,
)
from PySide6.QtCore import (
QTimer,
Expand Down Expand Up @@ -48,6 +50,8 @@ def initAttrs(self, series : Series, mainwindow : QMainWindow):
self.propagate_tform : bool = False

self.focus_mode : bool = False
# label over the field naming the focused object; built by FieldWidget
self.focus_hint : QLabel = None
self.hide_trace_layer : bool = False
self.show_all_traces : bool = False
self.hide_image : bool = False
Expand Down Expand Up @@ -326,11 +330,49 @@ def generateView(self, generate_image=True, generate_traces=True, update=True) -
self.mainwindow.mouse_palette.setScale()

self.mainwindow.checkActions()
# every focus mode change and every resize ends in a redraw
self.updateFocusHint()

if update:
self.update()

if generate_image:
self.is_image_loading = False

def focusHintText(self) -> str:
"""The focus mode label's text, naming the live `focus_act` shortcut."""
act = getattr(self.mainwindow, "focus_act", None)
key = act.shortcut().toString(QKeySequence.NativeText) if act is not None else ""
if key:
how = f"Press {key} to exit."
else:
how = "Use View > Toggle focus mode in the right-click menu to exit."
return f"Focus: {self.focus_mode}. {how}"

def updateFocusHint(self) -> None:
"""Show the focus mode label while focus mode is on, centered at the top."""
hint = getattr(self, "focus_hint", None)
if hint is None:
return
if not self.focus_mode:
hint.hide()
return
text = self.focusHintText()
if hint.text() != text:
hint.setText(text)
# one line when it fits, wrapped to the field's width when it does not
hint.setWordWrap(False)
w = hint.sizeHint().width()
max_w = max(self.width() - 20, 1)
if w > max_w:
hint.setWordWrap(True)
w = max_w
hint.resize(w, hint.heightForWidth(w))
else:
hint.resize(w, hint.sizeHint().height())
hint.move((self.width() - w) // 2, 10)
hint.show()
hint.raise_()

def clearStates(self) -> None:
"""Create/clear the states for each section."""
Expand Down
5 changes: 5 additions & 0 deletions PyReconstruct/modules/gui/main/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -2706,6 +2706,11 @@ def resetShortcuts(self, shortcuts_dict : dict = None):
for act_name, kbd in shortcuts_dict.items():
getattr(self, act_name).setShortcut(kbd)
self.series.setOption(act_name, kbd)

# the focus mode label names the focus_act shortcut
field = getattr(self, "field", None)
if field is not None:
field.updateFocusHint()

def displayAbout(self):
"""Display the widget display information about the series."""
Expand Down
Loading