Merge pull request #9290 from accumulator/qt_wizard_initial_focus
qt: add WizardComponent.initialFocus()
This commit is contained in:
@@ -376,6 +376,9 @@ class WCWalletName(WalletWizardComponent, Logger):
|
|||||||
self.name_e.textChanged.connect(on_filename)
|
self.name_e.textChanged.connect(on_filename)
|
||||||
self.name_e.setText(relative_path(path))
|
self.name_e.setText(relative_path(path))
|
||||||
|
|
||||||
|
def initialFocus(self) -> Optional[QWidget]:
|
||||||
|
return self.pw_e
|
||||||
|
|
||||||
def apply(self):
|
def apply(self):
|
||||||
if self.wallet_exists:
|
if self.wallet_exists:
|
||||||
# use full path
|
# use full path
|
||||||
@@ -986,6 +989,9 @@ class WCWalletPassword(WalletWizardComponent):
|
|||||||
self.layout().addLayout(self.pw_layout.layout())
|
self.layout().addLayout(self.pw_layout.layout())
|
||||||
self.layout().addStretch(1)
|
self.layout().addStretch(1)
|
||||||
|
|
||||||
|
def initialFocus(self) -> Optional[QWidget]:
|
||||||
|
return self.pw_layout.new_pw
|
||||||
|
|
||||||
def apply(self):
|
def apply(self):
|
||||||
self.wizard_data['password'] = self.pw_layout.new_password()
|
self.wizard_data['password'] = self.pw_layout.new_password()
|
||||||
self.wizard_data['encrypt'] = self.pw_layout.encrypt_cb.isChecked()
|
self.wizard_data['encrypt'] = self.pw_layout.encrypt_cb.isChecked()
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import copy
|
import copy
|
||||||
import threading
|
import threading
|
||||||
from abc import abstractmethod
|
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.QtCore import Qt, QTimer, pyqtSignal, pyqtSlot, QSize, QMetaObject
|
||||||
from PyQt6.QtGui import QPixmap
|
from PyQt6.QtGui import QPixmap
|
||||||
@@ -129,7 +129,8 @@ class QEAbstractWizard(QDialog, MessageBoxMixin):
|
|||||||
else:
|
else:
|
||||||
viewstate = self.start_wizard()
|
viewstate = self.start_wizard()
|
||||||
self.load_next_component(viewstate.view, viewstate.wizard_data, viewstate.params)
|
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
|
# TODO: re-test if needed on macOS
|
||||||
self.refresh_gui() # Need for QT on MacOSX. Lame.
|
self.refresh_gui() # Need for QT on MacOSX. Lame.
|
||||||
|
|
||||||
@@ -174,6 +175,14 @@ class QEAbstractWizard(QDialog, MessageBoxMixin):
|
|||||||
.scaledToWidth(60, mode=Qt.TransformationMode.SmoothTransformation))
|
.scaledToWidth(60, mode=Qt.TransformationMode.SmoothTransformation))
|
||||||
return prior_filename
|
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:
|
def can_go_back(self) -> bool:
|
||||||
return len(self._stack) > 0
|
return len(self._stack) > 0
|
||||||
|
|
||||||
@@ -222,6 +231,7 @@ class QEAbstractWizard(QDialog, MessageBoxMixin):
|
|||||||
view = self.submit(wd)
|
view = self.submit(wd)
|
||||||
try:
|
try:
|
||||||
self.load_next_component(view.view, view.wizard_data, view.params)
|
self.load_next_component(view.view, view.wizard_data, view.params)
|
||||||
|
self.set_default_focus()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.prev() # rollback the submit above
|
self.prev() # rollback the submit above
|
||||||
raise e
|
raise e
|
||||||
@@ -311,3 +321,7 @@ class WizardComponent(AbstractQWidget):
|
|||||||
self.updated.emit(self)
|
self.updated.emit(self)
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
pass
|
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