Skip to content

Instantly share code, notes, and snippets.

@mrdaemon
Created June 7, 2011 12:21
Show Gist options
  • Save mrdaemon/1012123 to your computer and use it in GitHub Desktop.
Save mrdaemon/1012123 to your computer and use it in GitHub Desktop.
import random
import sys
import time
from PyQt4 import QtCore, QtGui
from shitpantsui import Ui_Form
class _TimeWasterThread(QtCore.QThread):
def __init__(self):
QtCore.QThread.__init__(self)
done = QtCore.pyqtSignal(bool)
progress = QtCore.pyqtSignal(int)
def run(self):
step = 0
while step < 100:
self.progress.emit(min(step, 100))
rand = random.randint(1, 4000)
time.sleep(float(rand) / 1000.0)
step += random.randint(1, 10)
self.progress.emit(100)
self.done.emit(True)
class ShitPantsWindow(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.ui = Ui_Form()
self.ui.setupUi(self)
self._twthread = _TimeWasterThread()
self._twthread.done.connect(self.job_done)
self._twthread.progress.connect(self.draw_progress)
# derp signal autoconnect
# Apparently methods with default arguments must also
# be handled in the connect slot, else that shit is ran twice.
# It is apparently a PyQT/bindings limitation.
def on_startbutton_clicked(self, checked=None):
""" Callback slot for clicked() signal, Start button """
if checked is None: return
self.ui.startbutton.setEnabled(False)
self.ui.logpane.appendPlainText("Initiating Pooping Procedure");
self._twthread.start()
def draw_progress(self, step):
""" Callback slot that draws thread progress """
self.ui.shitprogress.setValue(step)
msg = "%s%% complete" % step
self.ui.logpane.appendPlainText(msg)
def job_done(self):
""" Callback slot on thread return """
self.ui.logpane.appendPlainText("Done shitting!")
self.ui.startbutton.setEnabled(True)
def main():
app = QtGui.QApplication(sys.argv)
window = ShitPantsWindow()
window.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment