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
53462426
Commit
53462426
authored
2 months ago
by
Alexandros Asonitis
Browse files
Options
Downloads
Patches
Plain Diff
Threads for preventing freezing
parent
7936f21a
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
+38
-13
38 additions, 13 deletions
hp4194/cv_qt_inteface.py
with
38 additions
and
13 deletions
hp4194/cv_qt_inteface.py
+
38
−
13
View file @
53462426
...
@@ -16,6 +16,26 @@ class MplCanvas(FigureCanvasQTAgg):
...
@@ -16,6 +16,26 @@ 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
):
finished
=
pyqtSignal
()
progress
=
pyqtSignal
(
int
)
def
run
():
for
i
in
range
(
20
):
self
.
xdata
=
list
(
range
(
20
))
for
i
in
range
(
2
):
for
j
in
range
(
3
):
self
.
sc
.
axes
[
i
,
j
].
cla
()
# Clear the canvas.
self
.
sc
.
axes
[
i
,
j
].
plot
(
self
.
xdata
,
random
.
sample
(
range
(
50
),
20
))
# Trigger the canvas to update and redraw.
self
.
sc
.
draw_idle
()
time
.
sleep
(
1
)
print
(
"
finished
"
)
class
MainWinow
(
QMainWindow
):
class
MainWinow
(
QMainWindow
):
def
__init__
(
self
):
def
__init__
(
self
):
super
().
__init__
()
super
().
__init__
()
...
@@ -217,19 +237,24 @@ class MainWinow(QMainWindow):
...
@@ -217,19 +237,24 @@ class MainWinow(QMainWindow):
self
.
widget
.
setEnabled
(
False
)
self
.
widget
.
setEnabled
(
False
)
self
.
toolbar
.
setEnabled
(
False
)
self
.
toolbar
.
setEnabled
(
False
)
# Step 2: Create a QThread object
self
.
xdata
=
list
(
range
(
20
))
self
.
thread
=
QThread
()
for
i
in
range
(
2
):
# Step 3: Create a worker object
for
j
in
range
(
3
):
self
.
worker
=
Worker
()
self
.
sc
.
axes
[
i
,
j
].
cla
()
# Clear the canvas.
# Step 4: Move worker to the thread
self
.
sc
.
axes
[
i
,
j
].
plot
(
self
.
xdata
,
random
.
sample
(
range
(
50
),
20
))
self
.
worker
.
moveToThread
(
self
.
thread
)
# Step 5: Connect signals and slots
# Trigger the canvas to update and redraw.
self
.
thread
.
started
.
connect
(
self
.
worker
.
run
)
self
.
sc
.
draw_idle
()
self
.
worker
.
finished
.
connect
(
self
.
thread
.
quit
)
self
.
worker
.
finished
.
connect
(
self
.
worker
.
deleteLater
)
print
(
"
finished
"
)
self
.
thread
.
finished
.
connect
(
self
.
thread
.
deleteLater
)
#self.widget.setEnabled(True)
self
.
worker
.
progress
.
connect
(
self
.
reportProgress
)
#self.toolbar.setEnabled(True)
# 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