Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
labcode
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CST
labcode
Commits
2e737644
Commit
2e737644
authored
1 month ago
by
Alexandros Asonitis
Browse files
Options
Downloads
Patches
Plain Diff
QThreads Work
parent
53462426
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
hp4194/cv_qt_inteface.py
+24
-31
24 additions, 31 deletions
hp4194/cv_qt_inteface.py
with
24 additions
and
31 deletions
hp4194/cv_qt_inteface.py
+
24
−
31
View file @
2e737644
...
@@ -8,6 +8,7 @@ from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg
...
@@ -8,6 +8,7 @@ from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg
from
matplotlib.figure
import
Figure
from
matplotlib.figure
import
Figure
import
random
import
random
from
PyQt6.QtGui
import
QAction
from
PyQt6.QtGui
import
QAction
from
PyQt6.QtCore
import
*
import
time
import
time
class
MplCanvas
(
FigureCanvasQTAgg
):
class
MplCanvas
(
FigureCanvasQTAgg
):
...
@@ -16,23 +17,29 @@ class MplCanvas(FigureCanvasQTAgg):
...
@@ -16,23 +17,29 @@ class MplCanvas(FigureCanvasQTAgg):
self
.
axes
=
fig
.
subplots
(
nrows
=
2
,
ncols
=
3
)
self
.
axes
=
fig
.
subplots
(
nrows
=
2
,
ncols
=
3
)
super
().
__init__
(
fig
)
super
().
__init__
(
fig
)
class
Worker
(
Qobject
):
class
Worker
(
QRunnable
):
finished
=
pyqtSignal
()
def
__init__
(
self
,
window
):
progress
=
pyqtSignal
(
int
)
super
().
__init__
()
self
.
window
=
window
def
run
():
@pyqtSlot
()
def
run
(
self
):
self
.
window
.
widget
.
setEnabled
(
False
)
self
.
window
.
toolbar
.
setEnabled
(
False
)
for
i
in
range
(
20
):
for
i
in
range
(
20
):
self
.
xdata
=
list
(
range
(
20
))
self
.
window
.
xdata
=
list
(
range
(
20
))
for
i
in
range
(
2
):
for
i
in
range
(
2
):
for
j
in
range
(
3
):
for
j
in
range
(
3
):
self
.
sc
.
axes
[
i
,
j
].
cla
()
# Clear the canvas.
self
.
window
.
sc
.
axes
[
i
,
j
].
cla
()
# Clear the canvas.
self
.
sc
.
axes
[
i
,
j
].
plot
(
self
.
xdata
,
random
.
sample
(
range
(
50
),
20
))
self
.
window
.
sc
.
axes
[
i
,
j
].
plot
(
self
.
window
.
xdata
,
random
.
sample
(
range
(
50
),
20
))
# Trigger the canvas to update and redraw.
# Trigger the canvas to update and redraw.
self
.
sc
.
draw_idle
()
self
.
window
.
sc
.
draw_idle
()
time
.
sleep
(
1
)
time
.
sleep
(
1
)
self
.
window
.
widget
.
setEnabled
(
True
)
print
(
"
finished
"
)
self
.
window
.
toolbar
.
setEnabled
(
True
)
self
.
data
=
1
...
@@ -233,28 +240,14 @@ class MainWinow(QMainWindow):
...
@@ -233,28 +240,14 @@ class MainWinow(QMainWindow):
self
.
setCentralWidget
(
self
.
widget
)
self
.
setCentralWidget
(
self
.
widget
)
self
.
showMaximized
()
self
.
showMaximized
()
self
.
threadpool
=
QThreadPool
()
print
(
"
Multithreading with maximum %d threads
"
%
self
.
threadpool
.
maxThreadCount
())
def
toolbar_button_clicked
(
self
):
def
toolbar_button_clicked
(
self
):
self
.
widget
.
setEnabled
(
False
)
self
.
worker
=
Worker
(
self
)
self
.
toolbar
.
setEnabled
(
False
)
self
.
threadpool
.
start
(
self
.
worker
)
# Step 2: Create a QThread object
self
.
thread
=
QThread
()
# Step 3: Create a worker object
self
.
worker
=
Worker
()
# Step 4: Move worker to the thread
self
.
worker
.
moveToThread
(
self
.
thread
)
# Step 5: Connect signals and slots
self
.
thread
.
started
.
connect
(
self
.
worker
.
run
)
self
.
worker
.
finished
.
connect
(
self
.
thread
.
quit
)
self
.
worker
.
finished
.
connect
(
self
.
worker
.
deleteLater
)
self
.
thread
.
finished
.
connect
(
self
.
thread
.
deleteLater
)
self
.
worker
.
progress
.
connect
(
self
.
reportProgress
)
# Step 6: Start the thread
self
.
thread
.
start
()
self
.
widget
.
setEnabled
(
True
)
self
.
toolbar
.
setEnabled
(
True
)
app
=
QApplication
(
sys
.
argv
)
app
=
QApplication
(
sys
.
argv
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment