Skip to content

Commit

Permalink
Implement animation_time setting
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorDalek1963 committed Jul 4, 2022
1 parent f0d418e commit 86343c4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fully respect display settings in visual definition widget
- Support parenthesized sub-expressions as matrix identifiers
- Add proper rotation animation that rotates at constant speed
- Allow animation time to be varied

### Fixed

Expand Down
16 changes: 16 additions & 0 deletions src/lintrans/gui/dialogs/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ def __init__(self, *args, display_settings: DisplaySettings, **kwargs):
)
self.dict_checkboxes['a'] = self.checkbox_applicative_animation

self.label_animation_time = QtWidgets.QLabel(self)
self.label_animation_time.setText('Total animation length (ms)')
self.label_animation_time.setToolTip(
'How long it takes for an animation to complete'
)

self.lineedit_animation_time = QtWidgets.QLineEdit(self)
self.lineedit_animation_time.setValidator(QIntValidator(1, 9999, self))

self.label_animation_pause_length = QtWidgets.QLabel(self)
self.label_animation_pause_length.setText('Animation pause length (ms)')
self.label_animation_pause_length.setToolTip(
Expand Down Expand Up @@ -175,6 +184,10 @@ def __init__(self, *args, display_settings: DisplaySettings, **kwargs):

# Animations

self.hlay_animation_time = QHBoxLayout()
self.hlay_animation_time.addWidget(self.label_animation_time)
self.hlay_animation_time.addWidget(self.lineedit_animation_time)

self.hlay_animation_pause_length = QHBoxLayout()
self.hlay_animation_pause_length.addWidget(self.label_animation_pause_length)
self.hlay_animation_pause_length.addWidget(self.lineedit_animation_pause_length)
Expand All @@ -183,6 +196,7 @@ def __init__(self, *args, display_settings: DisplaySettings, **kwargs):
self.vlay_groupbox_animations.setSpacing(20)
self.vlay_groupbox_animations.addWidget(self.checkbox_smoothen_determinant)
self.vlay_groupbox_animations.addWidget(self.checkbox_applicative_animation)
self.vlay_groupbox_animations.addLayout(self.hlay_animation_time)
self.vlay_groupbox_animations.addLayout(self.hlay_animation_pause_length)

self.groupbox_animations = QGroupBox('Animations', self)
Expand Down Expand Up @@ -219,6 +233,7 @@ def load_settings(self) -> None:
# Animations
self.checkbox_smoothen_determinant.setChecked(self.display_settings.smoothen_determinant)
self.checkbox_applicative_animation.setChecked(self.display_settings.applicative_animation)
self.lineedit_animation_time.setText(str(self.display_settings.animation_time))
self.lineedit_animation_pause_length.setText(str(self.display_settings.animation_pause_length))

# Matrix info
Expand All @@ -237,6 +252,7 @@ def confirm_settings(self) -> None:
# Animations
self.display_settings.smoothen_determinant = self.checkbox_smoothen_determinant.isChecked()
self.display_settings.applicative_animation = self.checkbox_applicative_animation.isChecked()
self.display_settings.animation_time = int(self.lineedit_animation_time.text())
self.display_settings.animation_pause_length = int(self.lineedit_animation_pause_length.text())

# Matrix info
Expand Down
8 changes: 6 additions & 2 deletions src/lintrans/gui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,14 @@ def _get_animation_frame(self, start: MatrixType, target: MatrixType, proportion
scalar = 1 + proportion * (np.sqrt(abs(det_target / det_b)) - 1)
return scalar * matrix_b

def animate_between_matrices(self, matrix_start: MatrixType, matrix_target: MatrixType, steps: int = 100) -> None:
def animate_between_matrices(self, matrix_start: MatrixType, matrix_target: MatrixType) -> None:
"""Animate from the start matrix to the target matrix."""
self.animating = True

# Making steps depend on animation_time ensures a smooth animation without
# massive overheads for small animation times
steps = self.plot.display_settings.animation_time // 10

for i in range(0, steps + 1):
if not self.animating:
break
Expand All @@ -484,7 +488,7 @@ def animate_between_matrices(self, matrix_start: MatrixType, matrix_target: Matr
# This allows for other events to be processed while animating, like zooming in and out
self.plot.update()
QApplication.processEvents()
QThread.msleep(1000 // steps)
QThread.msleep(self.plot.display_settings.animation_time // steps)

self.animating = False

Expand Down
3 changes: 3 additions & 0 deletions src/lintrans/gui/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class DisplaySettings:
and applicative animation means that we animate from ``C`` to ``TC``, so we apply ``T`` to ``C``.
"""

animation_time: int = 1200
"""This is the number of milliseconds that an animation takes."""

animation_pause_length: int = 400
"""This is the number of milliseconds that we wait between animations when using comma syntax."""

Expand Down

0 comments on commit 86343c4

Please sign in to comment.