Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Button cb enhance #253

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 90 additions & 19 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,15 @@ def __init__(self, shocktube):

self.checkbox_select_num = 3

def save_all(self):
@Slot(bool)
def save_all(self, checked=False):
"""
This callback function don't care button's checked state,
therefore the checked state is not used in this function.

:param checked: button is checked or not
:return: nothing
"""
fig = QPixmap(self.figure_container.size())
self.figure_container.render(fig)

Expand All @@ -170,12 +178,22 @@ def _update_layout(self):
self.main_layout.deleteLater()
self.main_container.update()

# Qt objects are managed by Qt internal event loop,
# hence it will not be deleted immediately when we called
# 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):
"""
Qt objects are managed by Qt internal event loop,
hence it will not be deleted immediately when we called
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.

This callback will be called before the obj destroyed,
in this callback only update the layout, therefore the obj
is not used in this callback.

:param obj: The object about to be destroyed
:return: nothing
"""
if self.use_grid_layout:
self.build_lines_grid_layout()
else:
Expand All @@ -186,7 +204,15 @@ def del_cb():
self.main_layout.update()
self.main_container.update()

def switch_layout(self):
@Slot(bool)
def switch_layout(self, checked=False):
"""
This callback function don't care button's checked state,
therefore the checked state is not used in this function.

:param checked: button is checked or not
:return: nothing
"""
self.use_grid_layout = not self.use_grid_layout
self._update_layout()

Expand Down Expand Up @@ -448,11 +474,20 @@ def _build_checkbox(self, layout):
check_box.clicked.connect(self._checkbox_cb)
layout.addWidget(check_box)

def _checkbox_cb(self):
# 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
# the parameters they want to plot on the chart.
@Slot(bool)
def _checkbox_cb(self, checked=False):
"""
This callback function don't care button's checked state,
therefore the checked state is not used in this function.

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
the parameters they want to plot on the chart.

:param checked: button is checked or not
:return: nothing
"""
checkbox = self.sender()
if self.checkbox_select_num == 3:
if checkbox.isChecked():
Expand Down Expand Up @@ -547,21 +582,57 @@ def show(self):
if self.use_sub:
self._subwin.show()

def start(self):
@Slot(bool)
def start(self, checked=False):
"""
This callback function don't care button's checked state,
therefore the checked state is not used in this function.

:param checked: button is checked or not
:return: nothing
"""
self.timer.start(self.interval)

def stop(self):
@Slot(bool)
def stop(self, checked=False):
"""
This callback function don't care button's checked state,
therefore the checked state is not used in this function.

:param checked: button is checked or not
:return: nothing
"""
self.timer.stop()

def step_button_cb(self):
@Slot(bool)
def step_button_cb(self, checked=False):
"""
This callback function don't care button's checked state,
therefore the checked state is not used in this function.

:param checked: button is checked or not
:return: nothing
"""
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):
"""
This callback function don't care button's checked state,
therefore the checked state is not used in this function.

:param checked: button is checked or not
:return: nothing
"""
self.stop()
self.current_step = 0
self.shocktube = euler1d.ShockTube()
Expand Down Expand Up @@ -596,7 +667,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
Loading