Exemple #1
0
def exec_images_open_dialog(parent, basedir='', app_name=None,
                            to_grayscale=True, dtype=None):
    """
    Executes an image*s* open dialog box (QFileDialog.getOpenFileNames)
        * parent: parent widget (None means no parent)
        * basedir: base directory ('' means current directory)
        * app_name (opt.): application name (used as a title for an eventual 
          error message box in case something goes wrong when saving image)
        * to_grayscale (default=True): convert image to grayscale
    
    Yields (filename, data) tuples if dialog is accepted, None otherwise
    """
    saved_in, saved_out, saved_err = sys.stdin, sys.stdout, sys.stderr
    sys.stdout = None
    filenames, _filter = getopenfilenames(parent, _("Open"), basedir,
                                io.iohandler.get_filters('load', dtype=dtype))
    sys.stdin, sys.stdout, sys.stderr = saved_in, saved_out, saved_err
    filenames = [to_text_string(fname) for fname in list(filenames)]
    for filename in filenames:
        try:
            data = io.imread(filename, to_grayscale=to_grayscale)
        except Exception as msg:
            import traceback
            traceback.print_exc()
            QMessageBox.critical(parent,
                 _('Error') if app_name is None else app_name,
                 (_("%s could not be opened:") % osp.basename(filename))+\
                 "\n"+str(msg))
            return
        yield filename, data
Exemple #2
0
def exec_images_open_dialog(parent,
                            basedir='',
                            app_name=None,
                            to_grayscale=True,
                            dtype=None):
    """
    Executes an image*s* open dialog box (QFileDialog.getOpenFileNames)
        * parent: parent widget (None means no parent)
        * basedir: base directory ('' means current directory)
        * app_name (opt.): application name (used as a title for an eventual 
          error message box in case something goes wrong when saving image)
        * to_grayscale (default=True): convert image to grayscale
    
    Yields (filename, data) tuples if dialog is accepted, None otherwise
    """
    saved_in, saved_out, saved_err = sys.stdin, sys.stdout, sys.stderr
    sys.stdout = None
    filenames, _filter = getopenfilenames(
        parent, _("Open"), basedir,
        io.iohandler.get_filters('load', dtype=dtype))
    sys.stdin, sys.stdout, sys.stderr = saved_in, saved_out, saved_err
    filenames = [to_text_string(fname) for fname in list(filenames)]
    for filename in filenames:
        try:
            data = io.imread(filename, to_grayscale=to_grayscale)
        except Exception as msg:
            import traceback
            traceback.print_exc()
            QMessageBox.critical(parent,
                 _('Error') if app_name is None else app_name,
                 (_("%s could not be opened:") % osp.basename(filename))+\
                 "\n"+str(msg))
            return
        yield filename, data
Exemple #3
0
    def apply_fit(self):
        msgBox = QMessageBox()
        msgBox.setText("Apply corrections?")
        msgBox.setInformativeText(
            "Select to which files will be applied the correction.")
        CancelButton = msgBox.addButton("Cancel", msgBox.RejectRole)
        SelectButton = msgBox.addButton("Select", msgBox.NoRole)
        AllButton = msgBox.addButton("All", msgBox.YesRole)
        #msgBox.setDefaultButton(QMessageBox.Cancel)
        msgBox.exec_()
        if msgBox.clickedButton() == CancelButton:
            return -1
        elif msgBox.clickedButton() == AllButton:
            filelist = None
        elif msgBox.clickedButton() == SelectButton:
            flret = getopenfilenames(self, _("Select file list"),
                                     self.data_ref.dir_name)[0]
            filelist = []
            for f in flret:
                filelist.append((basename(str(f)), dirname(str(f))))
            msgBox = QMessageBox()
            msgBox.setText("Select the correction file")
            msgBox.addButton(QMessageBox.Ok)
            msgBox.exec_()

        filename = getopenfilename(
            self, _("Correction file"),
            self.data_ref.dir_name + "/" + basename(
                normpath(self.data_ref.dir_name) + "_fit." +
                self.data_ref.files_type))
        try:
            self.data_ref.applycorr(str(filename[0]), filelist)
        except:
            msgBox = QMessageBox()
            msgBox.setText("Not a correction file!")
            msgBox.exec_()
            return -1