qt: add WizardComponent.initialFocus() which specifies the control to focus. If undefined, the Next button is focused by default
This commit is contained in:
@@ -376,6 +376,9 @@ class WCWalletName(WalletWizardComponent, Logger):
|
||||
self.name_e.textChanged.connect(on_filename)
|
||||
self.name_e.setText(relative_path(path))
|
||||
|
||||
def initialFocus(self) -> Optional[QWidget]:
|
||||
return self.pw_e
|
||||
|
||||
def apply(self):
|
||||
if self.wallet_exists:
|
||||
# use full path
|
||||
@@ -986,6 +989,9 @@ class WCWalletPassword(WalletWizardComponent):
|
||||
self.layout().addLayout(self.pw_layout.layout())
|
||||
self.layout().addStretch(1)
|
||||
|
||||
def initialFocus(self) -> Optional[QWidget]:
|
||||
return self.pw_layout.new_pw
|
||||
|
||||
def apply(self):
|
||||
self.wizard_data['password'] = self.pw_layout.new_password()
|
||||
self.wizard_data['encrypt'] = self.pw_layout.encrypt_cb.isChecked()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import copy
|
||||
import threading
|
||||
from abc import abstractmethod
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from PyQt6.QtCore import Qt, QTimer, pyqtSignal, pyqtSlot, QSize, QMetaObject
|
||||
from PyQt6.QtGui import QPixmap
|
||||
@@ -129,7 +129,8 @@ class QEAbstractWizard(QDialog, MessageBoxMixin):
|
||||
else:
|
||||
viewstate = self.start_wizard()
|
||||
self.load_next_component(viewstate.view, viewstate.wizard_data, viewstate.params)
|
||||
self.next_button.setFocus()
|
||||
self.set_default_focus()
|
||||
|
||||
# TODO: re-test if needed on macOS
|
||||
self.refresh_gui() # Need for QT on MacOSX. Lame.
|
||||
|
||||
@@ -174,6 +175,14 @@ class QEAbstractWizard(QDialog, MessageBoxMixin):
|
||||
.scaledToWidth(60, mode=Qt.TransformationMode.SmoothTransformation))
|
||||
return prior_filename
|
||||
|
||||
def set_default_focus(self):
|
||||
page = self.main_widget.currentWidget()
|
||||
control = page.initialFocus()
|
||||
if control and control.isVisible() and control.isEnabled():
|
||||
control.setFocus()
|
||||
else:
|
||||
self.next_button.setFocus()
|
||||
|
||||
def can_go_back(self) -> bool:
|
||||
return len(self._stack) > 0
|
||||
|
||||
@@ -222,6 +231,7 @@ class QEAbstractWizard(QDialog, MessageBoxMixin):
|
||||
view = self.submit(wd)
|
||||
try:
|
||||
self.load_next_component(view.view, view.wizard_data, view.params)
|
||||
self.set_default_focus()
|
||||
except Exception as e:
|
||||
self.prev() # rollback the submit above
|
||||
raise e
|
||||
@@ -311,3 +321,7 @@ class WizardComponent(AbstractQWidget):
|
||||
self.updated.emit(self)
|
||||
except RuntimeError:
|
||||
pass
|
||||
|
||||
def initialFocus(self) -> Optional[QWidget]:
|
||||
"""Override to specify a control that should receive initial focus"""
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user