def update_image_queue(self, img_dict): #hardware_mode do this # QApplication.processEvents() plot_win = self.img_queue.plot_wins.get() plot_win.img_plot(img_dict) img_name2 = (plot_win.img_label)[0:24].replace(' ', '_').replace( ':', '').replace('-', '').replace('.', '_') self.img_queue.plot_wins.put(plot_win) print("update image queue") if settings.widget_params["Analyse Data Setting"][ "autoStatus"] == True: QApplication.processEvents() fpath = IOHelper.get_config_setting('DATA_PATH') fpath = Path(fpath) dir_path = fpath # dir_path = fpath.joinpath(str(datetime.datetime.now())[2:].split('.')[0].replace(' ', '').replace(':', '_')) if settings.m_path != []: dir_path = settings.m_path if not dir_path.exists(): dir_path.mkdir() img_data = np.array(img_dict['img_data']) # load image name by path # img_name2 = (self.img_label)[0:20].replace(' ', '~').replace(':', '').replace('-', '') img_name = str(img_name2) img_data = img_data[::-1] from numpy import savetxt savetxt(r"{}\{}.data".format(dir_path, img_name), img_data, fmt='%.2e', delimiter=' ', newline='\n', header='', footer='', comments=' ', encoding=None) print("save images to {}".format(dir_path))
def Mainwindowfile_save_imgs(self): # try: if self.plot_main_window.img.image is None: print("have no image in Mainwindow") return fpath = IOHelper.get_config_setting('DATA_PATH') fpath = Path(fpath) dir_path = fpath # dir_path = fpath.joinpath(str(datetime.datetime.now())[2:].split('.')[0].replace(' ', '-').replace(':', '_')) # print("save images to {}".format(dir_path)) if settings.m_path != []: dir_path = settings.m_path if not dir_path.exists(): dir_path.mkdir() img_data = np.array(self.plot_main_window.img.image) # load image name by path img_name2 = (self.plot_main_window.img_label.text())[0:24].replace( ' ', '_').replace(':', '').replace('-', '').replace('.', '_') img_name = str(img_name2) img_data = img_data[::-1] # img_data = Image.fromarray(img_data) # img_data.save(r"{}\{}.png".format(dir_path, img_name)) import numpy numpy.savetxt(r"{}\{}.data".format(dir_path, img_name), img_data, fmt='%.2e', delimiter=' ', newline='\n', header='', footer='', comments=' ', encoding=None) print("save images to {}".format(dir_path))
def save_image(self): try: if self.video.image is None: print("have no image in window") return fpath = IOHelper.get_config_setting('DATA_PATH') fpath = Path(fpath) dir_path = fpath.joinpath( str(datetime.datetime.now()).split('.')[0].replace( ' ', '-').replace(':', '_')) # print("save images to {}".format(dir_path)) if not dir_path.exists(): dir_path.mkdir() img_data = np.array(self.video.image) # load image name by path img_name1 = settings.widget_params["Analyse Data Setting"][ "Prefix"] img_name2 = (self.img_label.text())[0:20].replace( ' ', '~').replace(':', '').replace('-', '') img_name = str(img_name1) + str(img_name2) img_data = img_data[::-1] img_data = Image.fromarray(img_data) img_data.save(r"{}\{}.png".format(dir_path, img_name)) print("save images to {}".format(dir_path)) # print("images have saved.") except OSError: print('Only new version files can be saved.')
def mousePressEvent(self, event): if event.button() == Qt.LeftButton: try: fpath = IOHelper.get_config_setting('DATA_PATH') img_fpath = QFileDialog.getOpenFileName( self, "Open File", fpath) # name path strimg_fpath = str(img_fpath) img_file = strimg_fpath[2:len(strimg_fpath) - 19] img_path = Path(img_file) file = open(img_path) linescontent = file.readlines( ) # Read the file as a behavior unit rows = len(linescontent) # get the numbers fo line lines = len(linescontent[0].strip().split(' ')) img_data = np.zeros((rows, lines)) # Initialization matrix row = 0 for line in linescontent: line = line.strip().split(' ') img_data[row, :] = line[:] row += 1 file.close() img_data = img_data[::-1] img_name = img_path.stem img = {'img_name': img_name, 'img_data': img_data} settings.absimgDatas[self.myserial] = img_data self.img_plot(img) except TypeError: return except PermissionError: return
def push2_state(self): fpath = IOHelper.get_config_setting('DATA_PATH') fpath = Path(fpath) dir_path = fpath.joinpath( str(datetime.datetime.now())[2:].split('.')[0].replace( ' ', '-').replace(':', '_')) # print("save images to {}".format(dir_path)) if settings.m_path != []: dir_path = settings.m_path if not dir_path.exists(): dir_path.mkdir() img_data = np.array(self.img.image) # load image name by path img_name = (self.img_labelt1.text())[0:20].replace(' ', '~').replace( ':', '_').replace('-', '') img_data = img_data[::-1] import numpy numpy.savetxt(r"{}\{}.ndata".format(dir_path, img_name), img_data, fmt='%.2e', delimiter=' ', newline='\n', header='', footer='', comments=' ', encoding=None) print("save images to {}".format(dir_path))
def load_img2stack(self): """ load images to image queue, with image name and data """ settings.widget_params["Image Display Setting"]["imgSource"] = "disk" fpath = IOHelper.get_config_setting('DATA_PATH') img_fpath = QFileDialog.getExistingDirectory(self, "Open File", fpath) img_file = Path(img_fpath) img_paths = list(img_file.glob('*.png')) for win_index in range(settings.widget_params["Image Display Setting"]["img_stack_num"]): if win_index == len(img_paths): break plot_win = self.img_queue.plot_wins.get() plot_win.img_plot(self.load_img_dict(img_paths[win_index])) self.img_queue.plot_wins.put(plot_win)
def save_image(self): if self.video.image is None: print("have no image in window") return fpath = IOHelper.get_config_setting('DATA_PATH') fpath = Path(fpath) dir_path = fpath.joinpath( str(datetime.datetime.now()).split('.')[0].replace(' ', '-').replace( ':', '_')) print("save images to {}".format(dir_path)) if not dir_path.exists(): dir_path.mkdir() img_data = np.array(self.video.image) # load image name by path img_name = (self.img_label.text()).split('.')[0].replace( ' ', '-').replace(':', '_') img_data = Image.fromarray(img_data) img_data.save(r"{}\{}.png".format(dir_path, img_name)) print("images have saved.")
def file_save_imgs(self): """ save image stack's images to disk :return: """ fpath = IOHelper.get_config_setting('DATA_PATH') fpath = Path(fpath) dir_path = fpath.joinpath(str(datetime.datetime.now()).split('.')[0].replace(' ', '-').replace(':', '_')) print("save images to {}".format(dir_path)) if not dir_path.exists(): dir_path.mkdir() for i in range(settings.widget_params["Image Display Setting"]["img_stack_num"]): plot_win = self.img_queue.plot_wins.get() if plot_win.video.image is not None: img_data = np.array(plot_win.video.image) # load image name by path img_name = (plot_win.img_label.text()).split('.')[0].replace(' ', '-').replace(':', '_') img_data = Image.fromarray(img_data) img_data.save(r"{}\{}.png".format(dir_path, img_name)) self.img_queue.plot_wins.put(plot_win) print("images have saved.")
def file_save_imgs(self): """ save image stack's images to disk :return: """ # try: fpath = IOHelper.get_config_setting('DATA_PATH') fpath = Path(fpath) dir_path = fpath # dir_path = fpath.joinpath(str(datetime.datetime.now()).split('.')[0].replace(' ', '-').replace(':', '_')) # print("save images to {}".format(dir_path)) if settings.m_path != []: dir_path = settings.m_path if not dir_path.exists(): dir_path.mkdir() for i in range(settings.widget_params["Image Display Setting"] ["img_stack_num"]): plot_win = self.img_queue.plot_wins.get() if plot_win.video.image is not None: img_data = np.array(plot_win.video.image) # load image name by path img_name2 = (plot_win.img_label)[0:24].replace( ' ', '_').replace(':', '').replace('-', '').replace('.', '_') img_name = str(img_name2) img_data = img_data[::-1] # img_data = Image.fromarray(img_data) # img_data.save(r"{}\{}.png".format(dir_path, img_name)) import numpy numpy.savetxt(r"{}\{}.data".format(dir_path, img_name), img_data, fmt='%.2e', delimiter=' ', newline='\n', header='', footer='', comments=' ', encoding=None) self.img_queue.plot_wins.put(plot_win) print("save images to {}".format(dir_path))
def create_action(parent, text, slot=None, shortcut=None, icon=None, tip=None, checkable=False): action = QAction(text, parent) if icon is not None: icpath = IOHelper.get_configt_setting('DATA_PATH') # icpath = Path(icpath) icpath = str(icpath).replace('\\', '/') action.setIcon(QIcon(icpath + "/%s.png" % icon)) if shortcut is not None: action.setShortcut(shortcut) if tip is not None: action.setToolTip(tip) action.setStatusTip(tip) if slot is not None: action.triggered.connect(slot) if checkable: action.setCheckable(True) return action
def file_load_imgs(self): """ Load previous image to stack. :return: """ settings.widget_params["Image Display Setting"]["imgSource"] = "disk" fpath = IOHelper.get_config_setting('DATA_PATH') img_fpath = QFileDialog.getOpenFileName(self, "Open File", fpath) # name path strimg_fpath = str(img_fpath) img_file = strimg_fpath[2:len(strimg_fpath) - 19] img_file = Path(img_file) img_paths = img_file if img_fpath[0] != '': plot_win = self.img_queue.plot_wins.get() try: plot_win.img_plot(self.load_img_dict(img_paths)) self.img_queue.plot_wins.put(plot_win) except TypeError: return except PermissionError: return
def __init__(self): super(TestMainWindow, self).__init__() self.move(82, 0) ### MENUS AND TOOLBARS ### self.fileMenu = self.menuBar().addMenu("File") self.windowMenu = self.menuBar().addMenu("Window") self.optionMenu = self.menuBar().addMenu("Options") self.path = self.menuBar().addMenu("") self.path.setEnabled(False) self.plotToolbar = self.addToolBar("Plot") self.expToolbar = self.addToolBar("Experiment") self.testToolbar = self.addToolBar("test") # experiment start/stop buttons self.start_exp_action = Helper.create_action( self, "Start Experiment", slot=self.start_exp, icon="start") #name and action and image self.stop_exp_action = Helper.create_action(self, "Stop Experiment", slot=self.stop_exp, icon="stop") self.stop_exp_action.setEnabled(False) # plot buttons self.clear_img_stack_action = Helper.create_action( self, "clear image stack", slot=self.clear_img_stack, icon="clear_img_stack") self.clear_main_win_action = Helper.create_action( self, "clear main window", slot=self.clear_main_win, icon="clear_main_win") ### CREATE WIDGET ### # global parameters settings.inintParams() self.plot_main_window = PlotMainWindow() self.setCentralWidget(self.plot_main_window) # set central # image queue dock self.img_queue = ImgQueueWidget() # create a QDockWidget imgQueueDockWidget = QDockWidget("Image Stack", self) imgQueueDockWidget.setObjectName("imgStackDockWidget") imgQueueDockWidget.setAllowedAreas(Qt.LeftDockWidgetArea) imgQueueDockWidget.setWidget(self.img_queue) self.addDockWidget(Qt.LeftDockWidgetArea, imgQueueDockWidget) self.windowMenu.addAction(imgQueueDockWidget.toggleViewAction()) # # image display setting dock # self.img_display_setting = ImgDisplaySetting() # self.img_display_setting.img_sub.connect(self.plot_main_window.img_plot2) # self.img_display_setting.img_sub2.connect(self.plot_main_window.img_plot3) # # # create a QDockWidget # displaySettingDockWidget = QDockWidget("Display Setting", self) # displaySettingDockWidget.setObjectName("displaySettingDockWidget") # displaySettingDockWidget.setAllowedAreas(Qt.RightDockWidgetArea) # displaySettingDockWidget.setWidget(self.img_display_setting) # self.addDockWidget(Qt.RightDockWidgetArea, displaySettingDockWidget) # # enable the toggle view action # self.windowMenu.addAction(displaySettingDockWidget.toggleViewAction()) # image analyse setting dock self.img_analyse_setting = ImgAnalysisSetting() analyseDataDockWidget = QDockWidget("Analyse Data", self) analyseDataDockWidget.setObjectName("analyseDataDockWidget") analyseDataDockWidget.setAllowedAreas(Qt.RightDockWidgetArea) analyseDataDockWidget.setWidget(self.img_analyse_setting) self.addDockWidget(Qt.RightDockWidgetArea, analyseDataDockWidget) self.windowMenu.addAction(analyseDataDockWidget.toggleViewAction()) self.img_analyse_setting.prefix_text.editingFinished.connect( self.editFinished) # camera setting dock self.camera_setting = CameraOption() cameraSettingDockWidget = QDockWidget("Setting", self) cameraSettingDockWidget.setObjectName("cameraSettingDockWidget") cameraSettingDockWidget.setAllowedAreas(Qt.BottomDockWidgetArea) cameraSettingDockWidget.setWidget(self.camera_setting) self.addDockWidget(Qt.BottomDockWidgetArea, cameraSettingDockWidget) self.windowMenu.addAction(cameraSettingDockWidget.toggleViewAction()) self.camera_setting.img_sub.connect(self.plot_main_window.img_plot2) self.camera_setting.img_sub2.connect(self.plot_main_window.img_plot3) # output dock # self.prompt_dock = PromptWidget() # promptDockWidget = QDockWidget("Output Console", self) # promptDockWidget.setObjectName("consoleDockWidget") # # promptDockWidget.setAllowedAreas(Qt.RightDockWidgetArea) # promptDockWidget.setWidget(self.prompt_dock) # self.addDockWidget(Qt.RightDockWidgetArea, promptDockWidget) # # redirect print statements to show a copy on "console" sys.stdout = Helper.print_redirect() sys.stdout.print_signal.connect(self.update_console) # # sys.stdout.print_signal.connect(self.update_pro) # self.windowMenu.addAction(promptDockWidget.toggleViewAction()) # Fitting dock self.Fitting_dock = FittingdataWidget() fittingDockWidget = QDockWidget("Fitting Console", self) fittingDockWidget.setObjectName("FittingDockWidget") fittingDockWidget.setAllowedAreas(Qt.BottomDockWidgetArea) fittingDockWidget.setWidget(self.Fitting_dock) self.addDockWidget(Qt.BottomDockWidgetArea, fittingDockWidget) self.windowMenu.addAction(fittingDockWidget.toggleViewAction()) # result dock self.result_dock = ResultWidget() resultDockWidget = QDockWidget("Result Console", self) resultDockWidget.setObjectName("resultDockWidget") resultDockWidget.setAllowedAreas(Qt.RightDockWidgetArea) resultDockWidget.setWidget(self.result_dock) self.addDockWidget(Qt.RightDockWidgetArea, resultDockWidget) self.windowMenu.addAction(resultDockWidget.toggleViewAction()) ### TOOLBAR MENU ### self.expToolbar.setObjectName("ExperimentToolbar") self.expToolbar.addAction(self.start_exp_action) self.expToolbar.addAction(self.stop_exp_action) self.plotToolbar.setObjectName("PlotToolbar") self.plotToolbar.addAction(self.clear_img_stack_action) self.plotToolbar.addAction(self.clear_main_win_action) self.LoadfolderAction = Helper.create_action( self, "Load folder", slot=self.load_img2stack, shortcut=None, icon=None, tip="Load previous images to image stack from file") self.LoadImgAction = Helper.create_action( self, "Load Images", slot=self.file_load_imgs, shortcut=None, icon=None, tip="Load previous images to image stack") self.SaveImgAction = Helper.create_action( self, "Save all stack images", slot=self.file_save_imgs, shortcut=None, icon=None, tip="Save image stack's images") self.SaveMainImgAction = Helper.create_action( self, "Save MainWindow's images", slot=self.Mainwindowfile_save_imgs, shortcut=None, icon=None, tip="Save MainWidnow's images") self.SetpathAction = Helper.create_action( self, "Set the default save path", slot=self.Setpath, shortcut=None, icon=None, tip="Set the default save path") self.AbsorbImageAction = Helper.create_action( self, "Absorb Image", slot=self.img_analyse_setting.absorb_setting, shortcut=None, icon=None, tip="Processing absorption imaging") self.PrefixsettingAction = Helper.create_action( self, "Prefix setting", slot=self.img_analyse_setting.prefix_setting, shortcut=None, icon=None, tip="Prefix setting") self.setcolorAction = Helper.create_action(self, "colour setting", slot=self.setcolour, shortcut=None, icon=None, tip="colour setting") self.fileMenu.addAction(self.LoadImgAction) self.fileMenu.addAction(self.LoadfolderAction) self.fileMenu.addAction(self.SaveMainImgAction) self.fileMenu.addAction(self.SaveImgAction) self.optionMenu.addAction(self.SetpathAction) self.optionMenu.addAction(self.AbsorbImageAction) self.optionMenu.addAction(self.setcolorAction) self.optionMenu.addAction(self.PrefixsettingAction) # queue for update main window when camera is in video mode self.acquiring = False # thread for acquiring image from camera to queue self.thread = None self.worker = None self.connect_slot2signal() icpath = IOHelper.get_configt_setting('DATA_PATH') # icpath = Path(icpath) icpath = str(icpath).replace('\\', '/') icpath = icpath + '/icon/UALab.png' # print(icpath) self.setWindowIcon(QIcon(icpath)) self.show()