def create_dock_windows(self): self.dock_view_list = ViewList() self.dock_view_list.select_item_index.connect(self.select_item_change) # self.view_dock_widget.setWidget(self.view_list) self.addDockWidget(Qt.RightDockWidgetArea, self.dock_view_list) self.dock_slice_info = InfoWidget() self.addDockWidget(Qt.LeftDockWidgetArea, self.dock_slice_info) self.dock_slice_info.setMinimumWidth(self.width * 0.5) self.dock_slice_info.setMinimumHeight(self.height * 0.4) self.dock_slice_tif = TifWidget() self.addDockWidget(Qt.LeftDockWidgetArea, self.dock_slice_tif) self.dock_slice_tif.setMinimumWidth(self.width * 0.5) self.dock_slice_tif.setFixedHeight(self.height * 0.5) self.dock_debug_info = DebugInfo() self.addDockWidget(Qt.LeftDockWidgetArea, self.dock_debug_info) self.dock_debug_info.setMinimumWidth(self.width * 0.5) self.dock_debug_info.setFixedHeight(self.height * 0.4) self.dock_debug_info.set_text_browser('') version_file = QFile("Version.txt") version_file.open(QIODevice.ReadOnly) ver_info = str(version_file.readAll(), encoding='utf-8') version_file.close() self.dock_debug_info.set_head_info(ver_info)
def initComponent(self): self.drawPanel = GLWidget(self) self.infoPanel = InfoWidget(self) self.controlPanel = ControlWidget(self) self.splitterPanel = SplitWidget(self) self.globalPanel = mylable(self) controlLayout = QVBoxLayout() controlLayout.addWidget(self.infoPanel) controlLayout.addWidget(self.controlPanel) # controlLayout.addWidget(self.globalPanel) controlLayout.addWidget(self.splitterPanel) subLayout = QVBoxLayout() subLayout.addWidget(self.globalPanel) mainLayout = QHBoxLayout() mainLayout.addWidget(self.drawPanel) mainLayout.addLayout(controlLayout) mainLayout.addWidget(self.globalPanel) mainWidget = QWidget() mainWidget.setLayout(mainLayout) # mainWidget.setLayout(subLayout) return mainWidget
def __init__(self, obsdate, imdir, prodir, server='smtp.saao.ac.za', readme='readme.fast.template', \ sdbhost='sdb.salt', sdbname='sdb', sdbuser='', \ password='', hmin=350, wmin=400, cmap='gray', \ sexfile='/home/ccd/tools/qred.sex', update=True, scale='zscale', contrast=0.1, imreduce=True, clobber=False, log=None, verbose=True): #set up the variables self.obsdate=obsdate self.imdir=imdir self.prodir=prodir self.imreduce=imreduce self.clobber=clobber self.scamwatch=True self.rsswatch=True self.hrswatch=True self.hrbwatch=True self.objsection=None self.sdbhost=sdbhost self.sdbname=sdbname self.sdbuser=sdbuser self.password=password self.server=server self.readme=readme self.sexfile=sexfile self.update=update self.headfiles=[] self.pickle_file='%s_obslog.p' % self.obsdate # Setup widget QtGui.QMainWindow.__init__(self) # Set main widget self.main = QtGui.QWidget(self) # Set window title self.setWindowTitle("SALTFIRST") #set up observation log from database self.create_obslog() #look for any initial data self.checkfordata(self.obsdate, self.imdir) #example data #image='../salt/scam/data/2006/1016/raw/S200610160009.fits' #self.hdu=saltio.openfits(image) #name=getbasename(self.hdu) #imlist=getimagedetails(self.hdu) #obsdict={} #obsdict[name]=imlist #set up each of the tabs if len(self.obsdict)>0: name=self.obsdict.order()[-1] imlist=self.obsdict[name] else: name='' imlist=[] self.hdu=None self.infoTab=InfoWidget(name, imlist) self.dqTab=DQWidget(name, imlist) #self.imageTab=ImageWidget(self.hdu, hmin=hmin, wmin=wmin, cmap=cmap, scale=scale, contrast=contrast) self.specTab=SpectraViewWidget(None, None, None, hmin=hmin, wmin=wmin) self.obsTab=ObsLogWidget(self.obsdict, obsdate=self.obsdate) #create the tabs self.tabWidget=QtGui.QTabWidget() self.tabWidget.addTab(self.infoTab, 'Info') self.tabWidget.addTab(self.dqTab, 'DQ') #self.tabWidget.addTab(self.imageTab, 'Image') self.tabWidget.addTab(self.specTab, 'Spectra') self.tabWidget.addTab(self.obsTab, 'Log') #create button to reset the filewatcher self.checkButton = QtGui.QPushButton("Check for Data") self.checkButton.clicked.connect(self.clickfordata) #layout the widgets mainLayout = QtGui.QVBoxLayout(self.main) mainLayout.addWidget(self.tabWidget) mainLayout.addWidget(self.checkButton) #set up thrading self.threadlist=[] self.thread=QtCore.QThread() self.nothread=False #add the file watching capability self.addwatcher() #add a timer to check on data and update obslog in database self.ctimer=QtCore.QTimer() ctime=5*60*1000 self.ctimer.start(ctime) self.connect(self.ctimer, QtCore.SIGNAL("timeout()"), self.updatetime) #add signal catches self.connect(self, QtCore.SIGNAL('updatespec(QString)'), self.updatespecview) self.connect(self.thread, QtCore.SIGNAL('finishedthread(QString)'), self.updatetabs) self.connect(self.obsTab, QtCore.SIGNAL('cellclicked(QString)'), self.updatetabs) self.connect(self.obsTab, QtCore.SIGNAL('updateobslogdb(QString)'), self.updateobslogdb) self.connect(self.obsTab, QtCore.SIGNAL('updatecals(QString)'), self.updatecals) self.connect(self.specTab, QtCore.SIGNAL('updateextract(int,int)'), self.updateextract) # Set the main widget as the central widget self.setCentralWidget(self.main) # Destroy widget on close self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
class FirstWindow(QtGui.QMainWindow): def __init__(self, obsdate, imdir, prodir, server='smtp.saao.ac.za', readme='readme.fast.template', \ sdbhost='sdb.salt', sdbname='sdb', sdbuser='', \ password='', hmin=350, wmin=400, cmap='gray', \ sexfile='/home/ccd/tools/qred.sex', update=True, scale='zscale', contrast=0.1, imreduce=True, clobber=False, log=None, verbose=True): #set up the variables self.obsdate=obsdate self.imdir=imdir self.prodir=prodir self.imreduce=imreduce self.clobber=clobber self.scamwatch=True self.rsswatch=True self.hrswatch=True self.hrbwatch=True self.objsection=None self.sdbhost=sdbhost self.sdbname=sdbname self.sdbuser=sdbuser self.password=password self.server=server self.readme=readme self.sexfile=sexfile self.update=update self.headfiles=[] self.pickle_file='%s_obslog.p' % self.obsdate # Setup widget QtGui.QMainWindow.__init__(self) # Set main widget self.main = QtGui.QWidget(self) # Set window title self.setWindowTitle("SALTFIRST") #set up observation log from database self.create_obslog() #look for any initial data self.checkfordata(self.obsdate, self.imdir) #example data #image='../salt/scam/data/2006/1016/raw/S200610160009.fits' #self.hdu=saltio.openfits(image) #name=getbasename(self.hdu) #imlist=getimagedetails(self.hdu) #obsdict={} #obsdict[name]=imlist #set up each of the tabs if len(self.obsdict)>0: name=self.obsdict.order()[-1] imlist=self.obsdict[name] else: name='' imlist=[] self.hdu=None self.infoTab=InfoWidget(name, imlist) self.dqTab=DQWidget(name, imlist) #self.imageTab=ImageWidget(self.hdu, hmin=hmin, wmin=wmin, cmap=cmap, scale=scale, contrast=contrast) self.specTab=SpectraViewWidget(None, None, None, hmin=hmin, wmin=wmin) self.obsTab=ObsLogWidget(self.obsdict, obsdate=self.obsdate) #create the tabs self.tabWidget=QtGui.QTabWidget() self.tabWidget.addTab(self.infoTab, 'Info') self.tabWidget.addTab(self.dqTab, 'DQ') #self.tabWidget.addTab(self.imageTab, 'Image') self.tabWidget.addTab(self.specTab, 'Spectra') self.tabWidget.addTab(self.obsTab, 'Log') #create button to reset the filewatcher self.checkButton = QtGui.QPushButton("Check for Data") self.checkButton.clicked.connect(self.clickfordata) #layout the widgets mainLayout = QtGui.QVBoxLayout(self.main) mainLayout.addWidget(self.tabWidget) mainLayout.addWidget(self.checkButton) #set up thrading self.threadlist=[] self.thread=QtCore.QThread() self.nothread=False #add the file watching capability self.addwatcher() #add a timer to check on data and update obslog in database self.ctimer=QtCore.QTimer() ctime=5*60*1000 self.ctimer.start(ctime) self.connect(self.ctimer, QtCore.SIGNAL("timeout()"), self.updatetime) #add signal catches self.connect(self, QtCore.SIGNAL('updatespec(QString)'), self.updatespecview) self.connect(self.thread, QtCore.SIGNAL('finishedthread(QString)'), self.updatetabs) self.connect(self.obsTab, QtCore.SIGNAL('cellclicked(QString)'), self.updatetabs) self.connect(self.obsTab, QtCore.SIGNAL('updateobslogdb(QString)'), self.updateobslogdb) self.connect(self.obsTab, QtCore.SIGNAL('updatecals(QString)'), self.updatecals) self.connect(self.specTab, QtCore.SIGNAL('updateextract(int,int)'), self.updateextract) # Set the main widget as the central widget self.setCentralWidget(self.main) # Destroy widget on close self.setAttribute(QtCore.Qt.WA_DeleteOnClose) def create_obslog(self): """Check to see if there are any files in the database, and if so, create the observing log""" if os.path.isfile(self.pickle_file) and 0: self.obsdict = pickle.load( open( self.pickle_file, "rb" ) ) else: self.obsdict = OrderedDict() def updateextract(self, y1, y2): print y1, y2 name=self.specTab.name iminfo=self.obsdict[name] lampid=iminfo[headerList.index('LAMPID')].strip().upper() objsection='[%i:%i]' % (y1, y2) if self.specTab.defaultBox.checkState(): print "Updating Object Section" self.objsection=objsection else: self.objsection=None outpath='./' outfile=outpath+'smbxp'+name logfile='saltclean.log' verbose=True y1, y2=quickap(outfile, objsection=objsection, clobber=True, logfile=logfile, verbose=verbose) #quickspec(outfile, lampid, findobj=False, objsection=objsection, clobber=True, logfile=logfile, verbose=verbose) self.specTab.updaterange(y1,y2) self.updatespecview(name) def updatetime(self): """Check to see if the data or logs need updating""" print "Checking for updates at %s" % time.asctime() #check for any new data self.clickfordata('') #update the obstab to the sdb self.obsTab.printfornightlog() self.updatecals() def updateobslogdb(self, logstr): #print logstr print "Updating Obslog for ", self.obsdate sdbloadobslog(logstr, self.obsdate, self.sdbhost, self.sdbname, self.sdbuser, self.password) pickle.dump(self.obsdict, open(self.pickle_file, 'wb')) def updatecals(self): print "Loading Calibration Data" findcal(self.obsdate, self.sdbhost, self.sdbname, self.sdbuser, self.password) def updateimlist(self, name, key, value): print "UPDATE:", name, key, value def updatespecview(self, name): name = str(name) print "UPDATING SPECVIEW with %s" % name specfile='./smbxp'+name.split('.fits')[0]+'.txt' warr, farr, snarr=np.loadtxt(specfile, usecols=(0,1,2), unpack=True) self.specTab.loaddata(warr, farr, snarr, name) self.specTab.redraw_canvas() def converttoname(self, infile): """Given a file name, find the raw salt file name""" def updatetabs(self, infile): name=str(infile) imlist=self.obsdict[name] detmode=imlist[headerList.index('DETMODE')].strip().upper() obsmode=imlist[headerList.index('OBSMODE')].strip().upper() #update the information panel try: self.infoTab.update(name, self.obsdict[name]) print "UPDATING tabs with %s" % name except Exception, e: print e return if self.thread.isRunning() and self.nothread: self.nothread=False #update the DQ tab try: self.dqTab.updatetab(name, self.obsdict[name]) #self.dqTab=DQWidget(name, self.obsdict[name]) #self.tabWidget.removeTab(1) #self.tabWidget.insertTab(1, self.dqTab, 'DQ') except Exception, e: print e return
class DetectionWindow(QMainWindow): def __init__(self): super(DetectionWindow, self).__init__() self.slice_image_list = [] # 放置tif文件路径 self.setWindowTitle('胃癌组织病理辅助诊断系统') self.setGeometry(400, 200, 800, 600) self.showMaximized() self.width = self.width() self.height = self.height() # 菜单栏 self.menu_bar = self.menuBar() # 文件选项 self.menufile = QMenu("文件", self) self.menufile.setObjectName("menufile") self.menu_bar.addMenu(self.menufile) #导入 self.action_open_file = QAction('导入', self.menufile) self.action_open_file.setStatusTip('导入.') self.action_open_file.triggered.connect(self.open_file) self.menufile.addAction(self.action_open_file) #批量导入 self.action_batch_open = QAction('批量导入', self.menufile) self.action_batch_open.setStatusTip('批量导入') self.action_batch_open.triggered.connect(self.batch_open) self.menufile.addAction(self.action_batch_open) # 编辑 self.action_clear_info = QAction('分析', self) self.action_clear_info.setStatusTip('分析.') self.action_clear_info.triggered.connect(self.analysis) self.menu_bar.addAction(self.action_clear_info) # 可视化 self.action_visual = QAction('可视化', self) self.action_visual.setStatusTip('可视化.') self.action_visual.triggered.connect(self.visualize) self.menu_bar.addAction(self.action_visual) # 日志 self.dialog = QAction('日志', self) self.dialog.setStatusTip('日志.') self.dialog.triggered.connect(self.dialog_info) self.menu_bar.addAction(self.dialog) self.target_view = TargetView() self.setCentralWidget(self.target_view) self.target_view.setBackgroundBrush( QBrush(QColor(214, 214, 214), Qt.SolidPattern)) self.create_dock_windows() def create_dock_windows(self): self.dock_view_list = ViewList() self.dock_view_list.select_item_index.connect(self.select_item_change) # self.view_dock_widget.setWidget(self.view_list) self.addDockWidget(Qt.RightDockWidgetArea, self.dock_view_list) self.dock_slice_info = InfoWidget() self.addDockWidget(Qt.LeftDockWidgetArea, self.dock_slice_info) self.dock_slice_info.setMinimumWidth(self.width * 0.5) self.dock_slice_info.setMinimumHeight(self.height * 0.4) self.dock_slice_tif = TifWidget() self.addDockWidget(Qt.LeftDockWidgetArea, self.dock_slice_tif) self.dock_slice_tif.setMinimumWidth(self.width * 0.5) self.dock_slice_tif.setFixedHeight(self.height * 0.5) self.dock_debug_info = DebugInfo() self.addDockWidget(Qt.LeftDockWidgetArea, self.dock_debug_info) self.dock_debug_info.setMinimumWidth(self.width * 0.5) self.dock_debug_info.setFixedHeight(self.height * 0.4) self.dock_debug_info.set_text_browser('') version_file = QFile("Version.txt") version_file.open(QIODevice.ReadOnly) ver_info = str(version_file.readAll(), encoding='utf-8') version_file.close() self.dock_debug_info.set_head_info(ver_info) def open_file(self): try: file_path = QFileDialog.getOpenFileName( self, '选择图像文件', '.', # "All Files (*.*);; " "Tiff Image (*.tif;*.tiff);; " "General Image (*.bmp;*.jpg;*.png);;") # txt_path = QFileDialog.getOpenFileName(self, '选择检测结果', './images', # # "All Files (*.*);; " # "TXT (*.txt);;") # print(file_path) tif_list = [] image_path = file_path[0] image_name = image_path.split('.')[0].split('/')[-1] tif_list.append(image_name + "." + image_path.split('.')[-1]) self.dock_slice_tif.set_slice_view(tif_list) except: QMessageBox.critical(self, "错误", "导入失败", QMessageBox.Yes, QMessageBox.Yes) def batch_open(self): startDirectory = "C://" os.startfile(startDirectory) def analysis(self): self.target_view.clear_target_view() self.dock_view_list.clear_view_list() # self.dock_slice_info.clear_info() self.boxes_info.clear() self.slice_image_list.clear() def visualize(self): self.target_view.show_boxes() self.dock_view_list.set_slice_view(self.slice_image_list) def dialog_info(self): print(self) def select_item_change(self, connect): self.target_view.focus_box(int(connect)) box_info = self.boxes_info[connect] info_dict = {} info_dict['index'] = connect + 1 info_dict['position'] = '({}, {})'.format(box_info[0], box_info[1]) info_dict['width'] = box_info[2] - box_info[0] info_dict['height'] = box_info[3] - box_info[1] info_dict['score'] = box_info[4] self.dock_slice_info.set_info(info_dict)
class BVHPlayerPy(QMainWindow): def __init__(self, pathCD): super().__init__() self.setMaximumSize(800, 500) self.pathCurrentDir = pathCD self.pathMotionFileDir = pathCD.rstrip(os.path.basename(pathCD)) self.setCentralWidget(self.initComponent()) menuBar = self.menuBar() menuBar.setNativeMenuBar(False) fileMenu = menuBar.addMenu("&File") loadAction = QAction("&Open...", self) loadAction.triggered.connect(self.loadFile) loadAction.setShortcut("Ctrl+l") fileMenu.addAction(loadAction) quitAction = QAction("&Quit...", self) quitAction.triggered.connect(self.quit) quitAction.setShortcut("Ctrl+q") fileMenu.addAction(quitAction) self.setMenuBar(menuBar) self.setWindowTitle("BVH Player") def initComponent(self): self.drawPanel = GLWidget(self) self.infoPanel = InfoWidget(self) self.controlPanel = ControlWidget(self) self.splitterPanel = SplitWidget(self) controlLayout = QVBoxLayout() controlLayout.addWidget(self.infoPanel) controlLayout.addWidget(self.controlPanel) controlLayout.addWidget(self.splitterPanel) mainLayout = QHBoxLayout() mainLayout.addWidget(self.drawPanel) mainLayout.addLayout(controlLayout) mainWidget = QWidget() mainWidget.setLayout(mainLayout) return mainWidget def quit(self): sys.exit() def loadFile(self): filePath = QFileDialog.getOpenFileName(self, "Choose Motion File...", self.pathMotionFileDir, "Biovision Hierarchy (*.bvh)") if filePath[0] == "": # print("Error: Motion file is not given") pass else: root, motion, frames, frameTime = BVH.readBVH(filePath[0]) self.pathMotionFileDir = os.path.dirname(filePath[0]) self.drawPanel.setMotion(root, motion, frames, frameTime) self.infoPanel.initInfo(os.path.basename(filePath[0]), frameTime, frames) self.controlPanel.setPlayMode(True) self.splitterPanel.setActive() self.splitterPanel.initMotionData(os.path.basename(filePath[0]), root, motion, frameTime) def keyPressEvent(self, event:QKeyEvent): if event.key() == Qt.Key_Escape: self.quit() elif event.key() == Qt.Key_S: if self.drawPanel.motion is not None: self.drawPanel.isPlaying = not self.drawPanel.isPlaying self.controlPanel.setPlayMode(self.drawPanel.isPlaying) elif event.key() == Qt.Key_F: self.drawPanel.fastRatio *= 2.0 elif event.key() == Qt.Key_D: self.drawPanel.fastRatio /= 2.0 elif event.key() == Qt.Key_Right: if self.drawPanel.frames is not None: self.drawPanel.frameCount += 1 if self.drawPanel.frameCount >= self.drawPanel.frames: self.drawPanel.frameCount = 0 elif event.key() == Qt.Key_Left: if self.drawPanel.frames is not None: self.drawPanel.frameCount -= 1 if self.drawPanel.frameCount < 0: self.drawPanel.frameCount = self.drawPanel.frames - 1 else: pass