Skip to content

Commit

Permalink
move function
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsumoto-ren committed Jun 5, 2024
1 parent 24a1fef commit cbedb1c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
5 changes: 5 additions & 0 deletions japanese/helpers/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ def split_list(input_list: Sequence[T], n_chunks: int) -> Iterable[Sequence[T]]:
chunk_size = math.ceil(len(input_list) / n_chunks)
for i in range(0, len(input_list), chunk_size):
yield input_list[i : i + chunk_size]


def q_emit(signal: Union[Callable, pyqtSignal, pyqtBoundSignal]) -> None:
"""Helper to work around type checking not working with signal.emit(func)."""
signal.emit() # type: ignore
11 changes: 4 additions & 7 deletions japanese/widgets/settings_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,17 +357,14 @@ def _add_widgets(self) -> None:
self._connect_widgets()

def _connect_widgets(self) -> None:
def _q_emit(signal: Union[Callable, pyqtSignal, pyqtBoundSignal]) -> None:
"""Helper to work around type checking not working with signal.emit(func)."""
signal.emit() # type: ignore

for widget in self._widgets.__dict__.values():
if isinstance(widget, QCheckBox):
qconnect(widget.checkStateChanged, lambda: _q_emit(self.opts_changed))
# checkStateChanged in pyqt 6.7+
qconnect(widget.stateChanged, lambda: q_emit(self.opts_changed))
elif isinstance(widget, QAbstractSpinBox):
qconnect(widget.valueChanged, lambda: _q_emit(self.opts_changed))
qconnect(widget.valueChanged, lambda: q_emit(self.opts_changed))
elif isinstance(widget, QLineEdit):
qconnect(widget.textChanged, lambda: _q_emit(self.opts_changed))
qconnect(widget.textChanged, lambda: q_emit(self.opts_changed))
else:
raise ValueError(f"Unhandled widget type: {type(widget)}")

Expand Down

0 comments on commit cbedb1c

Please sign in to comment.