def initInstruments(self): self.instrument_thread = QThread() self.acquirer = Acquirer() self.acquirer.moveToThread(self.instrument_thread) self.instrument_thread.started.connect(self.acquirer.onStarted)
class MainWindow(QMainWindow): def __init__(self): super(MainWindow, self).__init__() self.initInstruments() self.initUI() self.startThreads() def initInstruments(self): self.instrument_thread = QThread() self.acquirer = Acquirer() self.acquirer.moveToThread(self.instrument_thread) self.instrument_thread.started.connect(self.acquirer.onStarted) def initUI(self): self.setWindowTitle('pyPL - PL, R, and T acquisition') self.setWindowIcon(icons.photonacq) tabs = QTabWidget(self) self.configWidget = ConfigWidget(self.acquirer) tabs.addTab(self.configWidget, icons.configure,'Configure') self.acquireWidget = AcquireWidget(self.acquirer, self.configWidget) tabs.addTab(self.acquireWidget, icons.acquire,'Acquire') #tabs.addTab(CompareWidget(), # #QIcon(), # 'Compare') self.setCentralWidget(tabs) statusbar = self.statusBar() acquire_status = AcquireStatusWidget() statusbar.addPermanentWidget(acquire_status) self.acquirer.at_wavelength.connect(acquire_status.at_wavelength) self.acquirer.goto_started.connect(acquire_status.goto_started) #TODO: connect acquirer signals to acquire_status slots openAction = QAction(icons.fileOpen, '&Open', self) openAction.setStatusTip('Open a file') openAction.setToolTip('Open a file') openAction.setShortcut('Ctrl+O') openAction.triggered.connect(self.openFile) saveAction = QAction(icons.fileSave, '&Save', self) saveAction.setStatusTip('Save a file') saveAction.setToolTip('Save a file') saveAction.setShortcut('Ctrl+S') saveAction.triggered.connect(self.saveFile) aboutAction = QAction('&About', self) aboutAction.triggered.connect(self.about) #TODO: do we want a toolbar? #self.toolbar = self.addToolBar('Open') #self.toolbar.addAction(openAction) #self.toolbar.addAction(saveAction) menubar = self.menuBar() fileMenu = menubar.addMenu('&File') fileMenu.addAction(openAction) aboutMenu = menubar.addMenu('&About') aboutMenu.addAction(aboutAction) #statusBar = QtGui.QStatusBar() #self.setStatusBar(statusBar) #self.resize(250, 150) #self.center() self.show() def startThreads(self): self.instrument_thread.start() def openFile(self): pass #TODO def saveFile(self): pass #TODO def about(self): title = 'About PhotonAcq' text = """ Copyright (c) 2013, Scott J Maddox This file is part of PhotonAcq. PhotonAcq is free software: you can redistribute it and/or modify \ it under the terms of the GNU Affero General Public License as published by \ the Free Software Foundation, either version 3 of the License, or \ (at your option) any later version. PhotonAcq is distributed in the hope that it will be useful, \ but WITHOUT ANY WARRANTY; without even the implied warranty of \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \ GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License \ along with PhotonAcq. If not, see <http://www.gnu.org/licenses/>. \ """ QMessageBox.about(self, title, text) def center(self): qr = self.frameGeometry() cp = QDesktopWidget().availableGeometry().center() qr.moveCenter(cp) self.move(qr.topLeft()) def closeEvent(self, event): reply = QMessageBox.question(self, 'Quit?', 'Are you sure you want to quit?', QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if reply == QMessageBox.Yes: if self.acquirer.is_running: reply2 = QMessageBox.question(self, 'Abort Scan?', 'A scan is currently running. Abort it and quit?', QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if reply2 == QMessageBox.Yes: self.acquirer.abort() while self.acquirer.is_running: QThread.msleep(10) self.instrument_thread.quit() self.instrument_thread.wait() event.accept() return else: event.ignore() return self.instrument_thread.quit() self.instrument_thread.wait() event.accept() return else: event.ignore() return