Skip to content

Commit

Permalink
add Slot decorator and modified button callback
Browse files Browse the repository at this point in the history
Modify button event callback to fit buttton callback function signature.
Also, add Slot decorator, according to PySide6 official documentation
recommandation, every callback connected to signal should be indicated
by Slot decorator for good reliability and performance.
  • Loading branch information
j8xixo12 committed Nov 15, 2023
1 parent 1f72bad commit d6dd30a
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions modmesh/app/euler1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from PySide6.QtWidgets import (QApplication, QWidget, QScrollArea,
QGridLayout, QVBoxLayout, QPushButton,
QHBoxLayout, QFileDialog, QLayout, QCheckBox)
from PySide6.QtCore import Qt, QEvent, QMimeData, QTimer
from PySide6.QtCore import Qt, QEvent, QMimeData, QTimer, QObject, Slot
from PySide6.QtGui import QDrag, QPixmap

import modmesh as mm
Expand Down Expand Up @@ -145,7 +145,8 @@ def __init__(self, shocktube):

self.checkbox_select_num = 3

def save_all(self):
@Slot(bool)
def save_all(self, checked=False):
fig = QPixmap(self.figure_container.size())
self.figure_container.render(fig)

Expand Down Expand Up @@ -175,7 +176,8 @@ def _update_layout(self):
# deleteLater() and a QWidget only accept one layout at
# the same time, therefore a object delete callback is
# needed to set new layout after old layout deleted.
def del_cb():
@Slot(QObject)
def del_cb(obj=None):
if self.use_grid_layout:
self.build_lines_grid_layout()
else:
Expand All @@ -186,7 +188,8 @@ def del_cb():
self.main_layout.update()
self.main_container.update()

def switch_layout(self):
@Slot(bool)
def switch_layout(self, checked=False):
self.use_grid_layout = not self.use_grid_layout
self._update_layout()

Expand Down Expand Up @@ -448,7 +451,8 @@ def _build_checkbox(self, layout):
check_box.clicked.connect(self._checkbox_cb)
layout.addWidget(check_box)

def _checkbox_cb(self):
@Slot(bool)
def _checkbox_cb(self, checked=False):
# Under a single plot layout, that allow 3 lines on the same chart
# simultaneously to avoid it looking too crowded.
# I have chosen to use checkboxes for user to select
Expand Down Expand Up @@ -547,21 +551,29 @@ def show(self):
if self.use_sub:
self._subwin.show()

def start(self):
@Slot(bool)
def start(self, checked=False):
self.timer.start(self.interval)

def stop(self):
@Slot(bool)
def stop(self, checked=False):
self.timer.stop()

def step_button_cb(self):
@Slot(bool)
def step_button_cb(self, checked=False):
self.step()

def step(self, steps=1):
self.march_alpha2(steps=steps)
if self.max_steps and self.current_step > self.max_steps:
self.stop()

def reset(self):
@Slot()
def timer_timeout_cb(self):
self.step()

@Slot(bool)
def reset(self, checked=False):
self.stop()
self.current_step = 0
self.shocktube = euler1d.ShockTube()
Expand Down Expand Up @@ -596,7 +608,7 @@ def setup_timer(self, interval):
"""
self.interval = interval
self.timer = QTimer()
self.timer.timeout.connect(self.step)
self.timer.timeout.connect(self.timer_timeout_cb)

@staticmethod
def log(msg):
Expand Down

0 comments on commit d6dd30a

Please sign in to comment.