Skip to content

Commit f142f85

Browse files
committed
restarable, standalone workers
* workers can work without the OverlayProgressWidget * workers can be restarted * documentation updates * thread(s) in OverlayProgressWidget renamed to worker(s) to avoid confusion what is really set
1 parent 57762f1 commit f142f85

File tree

4 files changed

+69
-41
lines changed

4 files changed

+69
-41
lines changed

examples/ThreadedExample.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def initUI(self):
5959
threads.append(thread)
6060
worker.finished.connect(self.debugPrint)
6161

62-
self.pgFrame = OverlayProgressWidget(self.imgContainer, threads=workers)
62+
self.pgFrame = OverlayProgressWidget(self.imgContainer, workers=workers)
6363

6464
for t in threads:
6565
t.start()

pandasqt/models/ProgressThread.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,53 @@
11
from pandasqt.compat import QtCore, QtGui, Qt, Signal, Slot
22

3-
43
class ProgressWorker(QtCore.QObject):
5-
progressChanged = Signal(int)
4+
5+
progressChanged = Signal(int) # set value of OverlayProgressView
66
finished = Signal()
77

88
def __init__(self, name):
9+
"""Worker object that will be passed to the thread.
10+
11+
Args:
12+
name (str): name shown in progress ui.
13+
14+
"""
915
super(ProgressWorker, self).__init__()
1016
self.name = name
1117

1218
@Slot()
1319
def doWork(self):
20+
"""start the thread"""
1421
self.run()
1522
# emit the result of the operation?
1623
self.finished.emit()
1724

1825
def run(self):
26+
"""Implement your job here. This is what the thread will do.
27+
28+
"""
1929
raise NotImplemented
2030

2131

2232

23-
def createThread(parent, worker):
33+
def createThread(parent, worker, deleteWorkerLater=False):
34+
"""Create a new thread for given worker.
35+
36+
Args:
37+
parent (QObject): parent of thread and worker.
38+
worker (ProgressWorker): worker to use in thread.
39+
deleteWorkerLater (bool, optional): delete the worker if thread finishes.
40+
41+
Returns:
42+
QThread
43+
44+
"""
2445
thread = QtCore.QThread(parent)
2546
thread.started.connect(worker.doWork)
26-
thread.finished.connect(worker.deleteLater)
27-
47+
worker.finished.connect(thread.quit)
48+
if deleteWorkerLater:
49+
thread.finished.connect(worker.deleteLater)
50+
2851
worker.moveToThread(thread)
52+
worker.setParent(parent)
2953
return thread

pandasqt/views/OverlayProgressView.py

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
from pandasqt.compat import QtCore, QtGui, Qt, Signal, Slot
22

33
class OverlayProgressWidget(QtGui.QFrame):
4-
def __init__(self, parent, threads=[], debug=True):
4+
def __init__(self, parent, workers=[], debug=True, margin=0):
55
super(OverlayProgressWidget, self).__init__(parent)
66
self._debug = debug
7-
self._threads = threads
7+
self._workers = workers
88
self._detailProgressBars = []
99
self._addedBars = 0
1010
self._minHeight = 50
11-
self._width = parent.width() / 3
12-
self._margin = 20
11+
self._width = parent.width() * 0.38
12+
self._margin = margin
1313
self._totalProgress = 0
1414

1515
self.initUi()
1616

17-
for thread in threads:
18-
self._addProgressBar(thread)
17+
for worker in workers:
18+
self._addProgressBar(worker)
1919

2020

2121
def initUi(self):
@@ -39,29 +39,29 @@ def initUi(self):
3939
self.glayout.addWidget(self.totalProgressBar, 0, 0, 1, 1)
4040
self.glayout.addWidget(self.toggleButton, 0, 1, 1, 1)
4141

42-
styleSheet = """.QProgressBar {
43-
border: none;
44-
border-radius: 3px;
45-
text-align: center;
46-
background-color: rgba(37, 37, 37, 50%);
47-
color: white;
48-
margin: 1px;
49-
border-bottom-left-radius:5px;
50-
border-top-left-radius:5px;
51-
}
52-
53-
.QProgressBar::chunk {
54-
background-color: #05B8CC;
55-
border-radius: 3px;
56-
}
57-
58-
.OverlayProgressWidget {
59-
background-color: white;
60-
}
61-
62-
"""
63-
# set stylesheet for all progressbars in this widget
64-
self.setStyleSheet(styleSheet)
42+
#styleSheet = """.QProgressBar {
43+
#border: none;
44+
#border-radius: 3px;
45+
#text-align: center;
46+
#background-color: rgba(37, 37, 37, 50%);
47+
#color: white;
48+
#margin: 1px;
49+
#border-bottom-left-radius:5px;
50+
#border-top-left-radius:5px;
51+
#}
52+
53+
#.QProgressBar::chunk {
54+
#background-color: #05B8CC;
55+
#border-radius: 3px;
56+
#}
57+
58+
#.OverlayProgressWidget {
59+
#background-color: white;
60+
#}
61+
62+
#"""
63+
## set stylesheet for all progressbars in this widget
64+
#self.setStyleSheet(styleSheet)
6565

6666
parent = self.parent()
6767
xAnchor = parent.width() - self._width - self._margin
@@ -91,11 +91,15 @@ def _addProgressBar(self, worker):
9191
self._detailProgressBars.append((progressBar, label))
9292
worker.progressChanged.connect(progressBar.setValue)
9393
worker.progressChanged.connect(self.calculateTotalProgress)
94-
95-
96-
def addThread(self, thread):
97-
self._threads.append(thread)
98-
self._addProgressBar(thread)
94+
95+
worker.progressChanged.connect(self.debugProgressChanged)
96+
97+
def debugProgressChanged(self, value):
98+
print "debugProgressChanged", value
99+
100+
def addWorker(self, worker):
101+
self._workers.append(worker)
102+
self._addProgressBar(worker)
99103
self.resizeFrame()
100104

101105
def resizeFrame(self):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def run_tests(self):
6565
install_requires=['pandas>=0.15.1', 'chardet', 'pytest', 'pytest-qt==1.2.2', 'pytest-cov'],
6666
cmdclass={'test': PyTest},
6767
author_email='m.Ludwig@datalyze-solutions.com',
68-
description='catches exceptions inside qt applications and writes them to a message box and into a log file',
68+
description='Utilities to use pandas (the data analysis / manipulation library for Python) with Qt.',
6969
long_description=long_description,
7070
packages=['pandasqt'],
7171
include_package_data=True,

0 commit comments

Comments
 (0)