def showSplash(pth = "splash"): path = common_paths() # Create and display the splash screen splash_pix = QtGui.QPixmap(path[pth]) splash = QtWidgets.QSplashScreen(splash_pix, QtCore.Qt.WindowStaysOnTopHint) splash.setMask(splash_pix.mask()) progressBar = QtWidgets.QProgressBar(splash) progressBar.setStyleSheet(''' QProgressBar { border: 2px solid grey; border-radius: 5px; border: 2px solid grey; border-radius: 5px; text-align: center; } QProgressBar::chunk { background-color: #012748; width: 10px; margin: 0.5px; } ''') progressBar.setMaximum(10) progressBar.setGeometry(0, splash_pix.height() - 50, splash_pix.width(), 20) progressBar.setRange(0,8) splash.show() splash.pbar = progressBar splash.show() return splash
def __init__(self,parent=None): super(AppWindow.portSelectionDialog, self).__init__(parent) self.button_layout = QtGui.QVBoxLayout() self.setLayout(self.button_layout) self.btns=[] self.doneButton = QtWidgets.QPushButton("Done") self.button_layout.addWidget(self.doneButton) self.doneButton.clicked.connect(self.finished)
def newRegister(self): reg = dio.REGEDIT(self.commandQ) #self.registerLayout.addWidget(reg) #self.registers.append(reg) #TODO: Convert layout to listwidget to enable re-ordering regItem = QtWidgets.QListWidgetItem() regItem.setSizeHint(QtCore.QSize(200, 40)) self.registerList.addItem(regItem) self.registerList.setItemWidget(regItem, reg) self.registers.append(regItem)
def addPins(self): ''' This function adds pins in the right order. this should be moved to a configuration file! ''' self.btns['C'] = dio.REGVALS('C') self.leftlayout.addWidget(self.btns['C']) s = QtWidgets.QSpacerItem(20, 250, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.leftlayout.addItem(s) for name in ['PC0', 'PC1', 'PC2', 'PC3', 'PC4', 'PC5']: #left dock checkbox = dio.widget(name, self.commandQ, extra=self.SPECIALS.get(name, '')) self.leftlayout.addWidget(checkbox) self.btns[name] = checkbox self.btns['B'] = dio.REGVALS('B') self.rightlayout.addWidget(self.btns['B']) for name in ['PB5', 'PB4', 'PB3', 'PB2', 'PB1', 'PB0']: #right dock checkbox = dio.widget(name, self.commandQ, extra=self.SPECIALS.get(name, '')) self.rightlayout.addWidget(checkbox) self.btns[name] = checkbox s = QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.rightlayout.addItem(s) self.btns['D'] = dio.REGVALS('D') self.rightlayout.addWidget(self.btns['D']) for name in ['PD7', 'PD6', 'PD5', 'PD4', 'PD3', 'PD2', 'PD1', 'PD0']: #right dock checkbox = dio.widget(name, self.commandQ, extra=self.SPECIALS.get(name, '')) self.rightlayout.addWidget(checkbox) self.btns[name] = checkbox
def I2CScan(self): if self.p.connected: x = self.p.I2CScan() print('Responses from: ', x) for a in self.sensorList: a[0].setParent(None) a[1].setParent(None) self.sensorList = [] for a in self.controllerList: a[0].setParent(None) a[1].setParent(None) self.controllerList = [] for a in x: s = self.p.sensors.get(a, None) if s is not None: btn = QtWidgets.QPushButton(s['name'] + ':' + hex(a)) dialog = dio.DIOSENSOR(self, s) btn.clicked.connect(dialog.launch) self.sensorLayout.addWidget(btn) self.sensorList.append([dialog, btn]) continue s = self.p.controllers.get(a, None) if s is not None: btn = QtWidgets.QPushButton(s['name'] + ':' + hex(a)) dialog = dio.DIOCONTROL(self, s) btn.clicked.connect(dialog.launch) self.sensorLayout.addWidget(btn) self.controllerList.append([dialog, btn]) continue s = self.p.special.get(a, None) if s is not None: btn = QtWidgets.QPushButton(s['name'] + ':' + hex(a)) dialog = dio.DIOROBOT(self, s) btn.clicked.connect(dialog.launch) self.sensorLayout.addWidget(btn) self.controllerList.append([dialog, btn]) continue
def setList(self,L,handler): for a in self.btns: a.setParent(None) del a self.btns=[] self.button_group = QtWidgets.QButtonGroup() #moods[0].setChecked(True) pos=0 for i in L: # Add each radio button to the button layout btn = QtWidgets.QRadioButton(i) self.button_layout.addWidget(btn) self.btns.append(btn) if handler: if handler.connected: if handler.portname == i: btn.setStyleSheet("color:green;") if not L[i]: #Port in use btn.setEnabled(False) self.button_group.addButton(btn, pos) pos+=1
def run(): global path, app, myapp path = common_paths() app = QtWidgets.QApplication(sys.argv) myapp = AppWindow(app=app, path=path) myapp.show() r = app.exec_() ''' if myapp.p.connected: myapp.p.fd.write(b'j') #myapp.p.fd.setRTS(0) #time.sleep(0.01) #myapp.p.fd.setRTS(1) ''' app.deleteLater() sys.exit(r)
def makeBottomMenu(self): try: self.pushbutton.setParent(None) except: pass self.pushbutton = QtWidgets.QPushButton('Menu') self.pushbutton.setStyleSheet( "height: 13px;padding:3px;color: #FFFFFF;") menu = QtWidgets.QMenu() menu.addAction('Save Window as Svg', self.exportSvg) menu.addAction('Open Stepper Controller', self.newStepperController) #Theme self.themeAction = QtWidgets.QWidgetAction(menu) themes = [ a.split('.qss')[0] for a in os.listdir(path["themes"]) if '.qss' in a ] self.themeBox = QtWidgets.QComboBox() self.themeBox.addItems(themes) self.themeBox.currentIndexChanged['QString'].connect(self.setTheme) self.themeAction.setDefaultWidget(self.themeBox) menu.addAction(self.themeAction) self.pushbutton.setMenu(menu) self.userApplication = QtWidgets.QCheckBox("User App") self.userApplication.toggled['bool'].connect(self.jumpToApplication) self.statusBar.addPermanentWidget(self.userApplication) self.hexUploadButton = QtWidgets.QPushButton("Upload Hex") self.hexUploadButton.clicked.connect(self.uploadHex) self.statusBar.addPermanentWidget(self.hexUploadButton) self.speedbutton = QtWidgets.QComboBox() self.speedbutton.addItems(['Slow', 'Fast', 'Ultra']) self.speedbutton.setCurrentIndex(1) self.speedbutton.currentIndexChanged['int'].connect(self.setSpeed) self.statusBar.addPermanentWidget(self.speedbutton) self.statusBar.addPermanentWidget(self.pushbutton)
def __init__(self, parent=None,**kwargs): super(AppWindow, self).__init__(parent) self.setupUi(self) self.setTheme("default") #self.setTheme("material2") self.statusBar = self.statusBar() self.splash = kwargs.get('splash',None) global app self.fileBrowser = fileBrowser(thumbnail_directory = 'MCA_thumbnails',app=app, clickCallback = self.loadPlot,recordToHistory = self.recordToHistory, loadList = self.loadList) self.saveLayout.addWidget(self.fileBrowser) #Calibration Menu & storage self.calibrationEnabled = False self.calPoly = np.poly1d([1,0]) self.calPolyInv = np.poly1d([1,0]) self.calibrationMenu = QtWidgets.QMenu() self.y=[]; self.y2=[]; self.spectrumTime = time.time() self.offlineData = True self._browserPath = '.' self.saved={} self.thumbList={} self.markers=[] # PLOT creation self.createMainPlot() #self.createMainPlot('w','k') #Region Widget #self.regionLayout.setAlignment(QtCore.Qt.AlignTop) self.regionWindow = regionPopup.AppWindow(self,insertRegion=self.insertRegion,getData = self.getData,hltime = self.halflifeTime,changeDirectory = self.changeDirectory,enablePeriodicSpectrumSaving = self.enablePeriodicSpectrumSaving ) self.regionWindow.widgetLayout.setAlignment(QtCore.Qt.AlignTop) self.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.regionWindow) #self.regionWindow.setFloating(True) self.regionWindow.close() #Spectrum History Widget self.historyWindow = historyPopup.AppWindow(self,regions = self.regionWindow.regions) self.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.historyWindow) self.historyWindow.setFloating(True) #self.historyWindow.close() #Define some keyboard shortcuts for ease of use self.shortcutActions={} self.shortcuts={"+":self.summation,"s":self.start,"f":self.fit,"u":self.load,"r":self.insertRegion,"g":self.fitWithTail,"t":self.fitWithTail,"h":self.historyWindow.show,"Ctrl+S":self.save,"o":self.selectDevice} for a in self.shortcuts: shortcut = QtWidgets.QShortcut(QtGui.QKeySequence(a), self) shortcut.activated.connect(self.shortcuts[a]) self.shortcutActions[a] = shortcut # exporter self.exporter = PQG_ImageExporter(self.plot.plotItem)# pg.exporters.ImageExporter(self.plot.plotItem) #Auto-Update Menu self.autoUpdateMenu = QtGui.QMenu() #self.autoUpdateMenu.addAction("Interval",self.setAutoUpdateTime) self.autoUpdateTimerAction = QtWidgets.QWidgetAction(self.autoUpdateMenu) self.autoUpdateTimerInterval = QtWidgets.QSpinBox() self.autoUpdateTimerInterval.setMinimum(5);self.autoUpdateTimerInterval.setMaximum(3600);self.autoUpdateTimerInterval.setValue(constants.AUTOUPDATE_INTERVAL); self.autoUpdateTimerInterval.setSuffix(' S'); self.autoUpdateTimerInterval.valueChanged['int'].connect(self.setAutoUpdateInterval) self.autoUpdateTimerAction.setDefaultWidget(self.autoUpdateTimerInterval) self.autoUpdateMenu.addAction(self.autoUpdateTimerAction) self.autoUpdateSettings.setMenu(self.autoUpdateMenu) self.calibWindow = calPopup.AppWindow(self,application=self.setCalibration) self.splash.showMessage("<h2><font color='Black'>Connecting...</font></h2>", QtCore.Qt.AlignLeft, QtCore.Qt.black) self.splash.pbar.setValue(7) self.initializeCommunications() self.pending = { 'status':myTimer(constants.STATUS_UPDATE_INTERVAL), 'update':myTimer(constants.AUTOUPDATE_INTERVAL), 'current':myTimer(constants.CURRENT_UPDATE_INTERVAL), 'temperature':myTimer(constants.TEMPERATURE_UPDATE_INTERVAL), 'halflife':myTimer(self.regionWindow.decayInterval.value()), 'datadump':myTimer(self.regionWindow.saveAllInterval.value()*60) #convert minutes to seconds } self.temperature = decayTools.temperatureHandler() self.startTime = time.time() self.timer = QtCore.QTimer() self.timer.timeout.connect(self.updateEverything) self.timer.start(200) #Auto-Detector self.shortlist=MCALib.getFreePorts(None) self.deviceSelector.setList(self.shortlist,self.p) #self.loadPlot('DATA/212Bi.csv') #self.showGammaMarkers('137Cs') #self.loadPlot('DATA/eu152.dat') #self.loadList('DATA/list_sample.csv') self.splash.showMessage("<h2><font color='Black'>Ready!</font></h2>", QtCore.Qt.AlignLeft, QtCore.Qt.black) self.splash.pbar.setValue(8)
def makeBottomMenu(self): try:self.pushbutton.setParent(None) except:pass self.pushbutton = QtWidgets.QPushButton('Menu') menu = QtWidgets.QMenu() menu.addAction(self.controlDock.toggleViewAction()) menu.addAction(self.historyWindow.toggleViewAction()) menu.addAction('Set Square Wave', self.sqr1) if self.version_number>=2.0: menu.addAction('Set Threshold', self.set_threshold) menu.addSeparator() self.plotColorAction = QtWidgets.QAction('Light Theme', menu, checkable=True) self.plotColorAction.triggered.connect(self.setPlotColor) menu.addAction(self.plotColorAction) self.removeCalBox = QtWidgets.QAction('File Load: Remove Calibration', menu, checkable=True) self.removeCalBox.triggered.connect(menu.show) menu.addAction(self.removeCalBox) #self.pileUpAction = QtWidgets.QAction('PileUp Reject', menu, checkable=True) #self.pileUpAction.triggered.connect(self.pileUpRejection) #self.pileUpAction.triggered.connect(menu.show) #menu.addAction(self.pileUpAction) self.coincidencegate = QtWidgets.QAction('External Gate', menu, checkable=True) self.coincidencegate.triggered.connect(self.externalGate) self.coincidencegate.triggered.connect(menu.show) menu.addAction(self.coincidencegate) menu.addAction('Set Window Opacity', self.setOpacity) menu.addAction('Save Window as Svg', self.exportSvg) #Theme self.themeAction = QtWidgets.QWidgetAction(menu) themes = [a.split('.qss')[0] for a in os.listdir(path["themes"]) if '.qss' in a] self.themeBox = QtWidgets.QComboBox(); self.themeBox.addItems(themes) self.themeBox.currentIndexChanged['QString'].connect(self.setTheme) self.themeAction.setDefaultWidget(self.themeBox) menu.addAction(self.themeAction) #Alpha Markers self.markerAction = QtWidgets.QWidgetAction(menu) self.markerBox = QtWidgets.QComboBox(); self.markerBox.addItems(['Add Alpha Energy Guides']+list(constants.ALPHAS.keys())) self.markerBox.currentIndexChanged['QString'].connect(self.showAlphaMarkers) self.markerAction.setDefaultWidget(self.markerBox) menu.addAction(self.markerAction) #Gamma Markers self.markerActionG = QtWidgets.QWidgetAction(menu) self.markerBoxG = QtWidgets.QComboBox(); self.markerBoxG.addItems(['Add Gamma Energy Guides']+list(constants.GAMMAS.keys())) self.markerBoxG.currentIndexChanged['QString'].connect(self.showGammaMarkers) self.markerActionG.setDefaultWidget(self.markerBoxG) menu.addAction(self.markerActionG) #Graph Colour self.traceRow = traceRowWidget(self.curve) self.colAction = QtWidgets.QWidgetAction(menu) self.colAction.setDefaultWidget(self.traceRow) menu.addAction(self.colAction) #TRACE2 self.traceRow2 = traceRowWidget(self.curve2) self.colAction2 = QtWidgets.QWidgetAction(menu) self.colAction2.setDefaultWidget(self.traceRow2) menu.addAction(self.colAction2) # Quit menu.addAction('Exit', self.askBeforeQuit) self.pushbutton.setMenu(menu) self.extraLayout.addWidget(self.pushbutton) #self.statusBar.addPermanentWidget(self.pushbutton) self.deviceSelector = self.portSelectionDialog()
} ''') progressBar.setMaximum(10) progressBar.setGeometry(0, splash_pix.height() - 50, splash_pix.width(), 20) progressBar.setRange(0,8) splash.show() splash.pbar = progressBar splash.show() return splash if __name__ == "__main__": path = common_paths() from utilities.animTools import traceRowWidget app = QtWidgets.QApplication(sys.argv) #for t in translators(path["translation"]): # app.installTranslator(t) # Create and display the splash screen splash = showSplash() splash.showMessage("<h2><font color='Black'>Initializing...</font></h2>", QtCore.Qt.AlignLeft, QtCore.Qt.black) for a in range(5): app.processEvents() time.sleep(0.01) #IMPORT LIBRARIES splash.showMessage("<h2><font color='Black'>Importing libraries...</font></h2>", QtCore.Qt.AlignLeft, QtCore.Qt.black) splash.pbar.setValue(1) import string,glob,functools
def __init__(self, parent=None, **kwargs): super(AppWindow, self).__init__(parent) self.setupUi(self) self.VERSION = REGISTERS.VERSION_ATMEGA32 #This needs to be dynamically changed when hardware is connected self.SPECIALS = REGISTERS.VERSIONS[self.VERSION]['SPECIALS'] self.REGISTERS = REGISTERS.VERSIONS[self.VERSION]['REGISTERS'] self.EXAMPLES_DIR = REGISTERS.VERSIONS[ self.VERSION]['examples directory'] self.docks = [self.padock, self.pbdock, self.pcdock, self.pddock] self.sensorList = [] self.controllerList = [] self.monitoring = True self.logRegisters = True self.userHexRunning = False self.uploadingHex = False self.autoUpdateUserRegisters = False self.CFile = None #'~/kuttyPy.c' self.ipy = None self.setTheme("material") examples = [ a for a in os.listdir( os.path.join(path["examples"], self.EXAMPLES_DIR)) if ('.py' in a) and a is not 'kuttyPy.py' ] #.py files except the library self.exampleList.addItems(examples) blinkindex = self.exampleList.findText('blink.py') if blinkindex != -1: #default example. blink.py present in examples directory self.exampleList.setCurrentIndex(blinkindex) #Define some keyboard shortcuts for ease of use self.shortcutActions = {} self.shortcuts = { "f": partial(self.setLanguage, 'fr_FR'), "e": partial(self.setLanguage, 'en_IN'), "m": partial(self.setLanguage, 'ml_IN') } for a in self.shortcuts: shortcut = QtWidgets.QShortcut(QtGui.QKeySequence(a), self) shortcut.activated.connect(self.shortcuts[a]) self.shortcutActions[a] = shortcut ######## PYTHON CODE self.codeThread = QtCore.QThread() self.codeEval = self.codeObject(self.REGISTERS) self.codeEval.moveToThread(self.codeThread) self.codeEval.finished.connect(self.codeThread.quit) self.codeEval.logThis.connect( self.appendLog) #Connect to the log window self.logThis.connect(self.appendLog) #Connect to the log window self.logThisPlain.connect( self.appendLogPlain) #Connect to the log window self.serialGaugeSignal.connect(self.setSerialgauge) self.codeThread.started.connect(self.codeEval.execute) self.codeThread.finished.connect(self.codeFinished) ######### C CODE UPLOADER self.uploadThread = QtCore.QThread() self.UploadObject = self.uploadObject() self.UploadObject.moveToThread(self.uploadThread) self.UploadObject.finished.connect(self.uploadThread.quit) self.UploadObject.logThis.connect( self.appendLog) #Connect to the log window self.UploadObject.logThisPlain.connect( self.appendLogPlain) #Connect to the log window. add plain text self.logThis.connect(self.appendLog) #Connect to the log window self.uploadThread.started.connect(self.UploadObject.execute) self.uploadThread.finished.connect(self.codeFinished) self.commandQ = [] self.btns = {} self.registers = [] self.addPins() self.statusBar = self.statusBar() self.makeBottomMenu() global app self.initializeCommunications() self.pending = { 'status': myTimer(constants.STATUS_UPDATE_INTERVAL), 'update': myTimer(constants.AUTOUPDATE_INTERVAL), } serialgaugeoptions = { 'name': 'Serial Monitor', 'init': print, 'read': None, 'fields': ['Value'], 'min': [0], 'max': [1000], 'config': [{ 'name': 'Data Type', 'options': ['byte', 'ASCII'], 'function': self.configSerialGauge }] } self.serialGauge = dio.DIOSENSOR(self, serialgaugeoptions) self.startTime = time.time() self.timer = QtCore.QTimer() self.timer.timeout.connect(self.updateEverything) self.timer.start(20) #Auto-Detector self.shortlist = KuttyPyLib.getFreePorts()