class Main(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.ui.btnTakePic.clicked.connect( self.takePicClicked ) # when an object btnTakePic is clicked run function self.takePicClicked self.ui.btnAutofocus.clicked.connect(self.autofocusClicked) self.ui.btnMoveUp.clicked.connect(self.moveUpClicked) self.ui.btnMoveDown.clicked.connect(self.moveDownClicked) self.ui.btnStart.clicked.connect(self.startClicked) self.ui.btnStop.clicked.connect(self.stopClicked) self.cameraOperator = CameraOperator( "./images/") # basepath for the results (within robotchem folder) self.platform = Platform() self.backgroundThread = BackgroundThread(self.cameraOperator, self.platform, self) self.connect(self.backgroundThread, SIGNAL("displayPic"), self.displayPic) self.backgroundMode = 0 # initialisation of the backgroundMode variable def takePicClicked( self): # take picture, put it in a folder and display it if self._processRunning( ): # checks whether a background process is running return masterFolder = "master_" + str(time.time()) self.cameraOperator.newSubfolder(masterFolder) image, _ = self.cameraOperator.takePic( ) # takes a picture and puts it in the created subfolder self.displayPic(image) def displayPic(self, image): #displys a picture pixmap = QtGui.QPixmap.fromImage( ImageQt(image)) # transform an image file into pixmap # display image in labPic label that fits into its size and maintains the aspect ratio self.ui.labPic.setPixmap( pixmap.scaled(self.ui.labPic.size(), QtCore.Qt.KeepAspectRatio)) def autofocusClicked(self): # run the autofocus program if self._processRunning(): return self.backgroundMode = 1 self.backgroundThread.start( ) #start uses run (from backgroundThread class) def moveUpClicked(self): if self._processRunning(): return self.platform.moveUp( 10 ) # move the platform up by number of steps (multiplies of 0.05 mm) def moveDownClicked(self): if self._processRunning(): return self.platform.moveDown(10) # move the platform down def startClicked(self): # run the scheduler program if self._processRunning(): return self.backgroundMode = 2 # read the values of time and interval from GUI spinners and pass them to the scheduler function self.schedulerArgs = (self.ui.spinTime.value(), self.ui.spinInterval.value()) self.backgroundThread.start() def stopClicked(self): # placeholder if self._processRunning(): return def _processRunning( self ): # checks whether another process is running - if so, rejects an action (prevents from clicking buttons) if self.backgroundThread.isRunning(): print "Background process running. Rejecting requested action." return True else: return False