Beispiel #1
0
 def testLoadScans(self):
     specFile = os.path.join(self.dataPath, FLUORESCENCE_FILE)
     print("SpecDataFile %s" % specFile)
     specData = SpecDataFile(specFile)
     self.scanBrowser.loadScans(specData.scans, newFile=True)
     self.assertEqual(len(self.spyLoaded), 1)
     self.assertEqual(len(self.spySelected), 0)
     self.assertEqual(self.scanBrowser.scanList.rowCount(),
                      len(specData.getScanNumbers()))
Beispiel #2
0
class ImportDialog(BaseImportDialog):
    """Dialog to import SPEC Scans"""

    def __init__(self, parent=None):

        super(ImportDialog, self).__init__(parent)

        self.accepted = False
        from nexpy.gui.consoleapp import _mainwindow

        self.default_directory = _mainwindow.default_directory
        self.import_file = None  # must set in self.get_data()
        self.spec = None

        # progress bar is updated via calls to pdate_progress()
        self.progress_bar = QtGui.QProgressBar()
        self.progress_bar.setVisible(False)

        status_layout = QtGui.QHBoxLayout()
        status_layout.addWidget(self.progress_bar)
        status_layout.addStretch()
        status_layout.addWidget(self.close_buttons())

        self.layout = QtGui.QVBoxLayout()
        self.layout.addLayout(self.filebox())
        self.layout.addLayout(self.scanbox())
        self.layout.addLayout(status_layout)
        self.setLayout(self.layout)

        self.setWindowTitle("Import " + str(filetype))

    def scanbox(self):
        """create widgets for specifying scan range to import"""
        scanminlabel = QtGui.QLabel("Min. Scan")
        self.scanmin = QtGui.QLineEdit()
        self.scanmin.setFixedWidth(100)
        self.scanmin.setAlignment(QtCore.Qt.AlignRight)
        scanmaxlabel = QtGui.QLabel("Max. Scan")
        self.scanmax = QtGui.QLineEdit()
        self.scanmax.setFixedWidth(100)
        self.scanmax.setAlignment(QtCore.Qt.AlignRight)

        scanbox = QtGui.QHBoxLayout()
        scanbox.addWidget(scanminlabel)
        scanbox.addWidget(self.scanmin)
        scanbox.addWidget(scanmaxlabel)
        scanbox.addWidget(self.scanmax)
        return scanbox

    def choose_file(self):
        """
        Opens file dialog, set file text box to the chosen path
        """
        from spec2nexus.spec import SpecDataFile

        dirname = self.get_default_directory(self.filename.text())
        filename = getOpenFileName(self, "Open file", dirname)
        if os.path.exists(filename):
            self.filename.setText(str(filename))
            self.spec = SpecDataFile(self.get_filename())
            self.set_default_directory(os.path.dirname(filename))
            scan_min = self.spec.getMinScanNumber()
            self.scanmin.setText(str(scan_min))
            scan_max = self.spec.getMaxScanNumber()
            self.scanmax.setText(str(scan_max))

    def get_data(self):
        """read the data and return either :class:`NXroot` or :class:`NXentry`"""
        self.import_file = self.get_filename()
        if not os.path.exists(self.import_file):
            return None
        if self.spec is None:
            return None
        scan_min = int(self.scanmin.text())
        scan_max = int(self.scanmax.text())
        all_scans = self.spec.getScanNumbers()
        scans = [s for s in all_scans if scan_min <= s <= scan_max]
        self.spec.progress_bar = self.progress_bar
        self.spec.update_progress = self.update_progress
        return Parser(self.spec).toTree(scans)
Beispiel #3
0
class ImportDialog(BaseImportDialog):
    """Dialog to import SPEC Scans"""
    def __init__(self, parent=None):

        super(ImportDialog, self).__init__(parent)

        self.accepted = False
        from nexpy.gui.consoleapp import _mainwindow
        self.default_directory = _mainwindow.default_directory
        self.import_file = None  # must set in self.get_data()
        self.spec = None

        # progress bar is updated via calls to pdate_progress()
        self.progress_bar = QtGui.QProgressBar()
        self.progress_bar.setVisible(False)

        status_layout = QtGui.QHBoxLayout()
        status_layout.addWidget(self.progress_bar)
        status_layout.addStretch()
        status_layout.addWidget(self.close_buttons())

        self.layout = QtGui.QVBoxLayout()
        self.layout.addLayout(self.filebox())
        self.layout.addLayout(self.scanbox())
        self.layout.addLayout(status_layout)
        self.setLayout(self.layout)

        self.setWindowTitle("Import " + str(filetype))

    def scanbox(self):
        '''create widgets for specifying scan range to import'''
        scanminlabel = QtGui.QLabel("Min. Scan")
        self.scanmin = QtGui.QLineEdit()
        self.scanmin.setFixedWidth(100)
        self.scanmin.setAlignment(QtCore.Qt.AlignRight)
        scanmaxlabel = QtGui.QLabel("Max. Scan")
        self.scanmax = QtGui.QLineEdit()
        self.scanmax.setFixedWidth(100)
        self.scanmax.setAlignment(QtCore.Qt.AlignRight)

        scanbox = QtGui.QHBoxLayout()
        scanbox.addWidget(scanminlabel)
        scanbox.addWidget(self.scanmin)
        scanbox.addWidget(scanmaxlabel)
        scanbox.addWidget(self.scanmax)
        return scanbox

    def choose_file(self):
        '''
        Opens file dialog, set file text box to the chosen path
        '''
        from spec2nexus.spec import SpecDataFile

        dirname = self.get_default_directory(self.filename.text())
        filename = getOpenFileName(self, 'Open file', dirname)
        if os.path.exists(filename):
            self.filename.setText(str(filename))
            self.spec = SpecDataFile(self.get_filename())
            self.set_default_directory(os.path.dirname(filename))
            scan_min = self.spec.getMinScanNumber()
            self.scanmin.setText(str(scan_min))
            scan_max = self.spec.getMaxScanNumber()
            self.scanmax.setText(str(scan_max))

    def get_data(self):
        '''read the data and return either :class:`NXroot` or :class:`NXentry`'''
        self.import_file = self.get_filename()
        if not os.path.exists(self.import_file):
            return None
        if self.spec is None:
            return None
        scan_min = int(self.scanmin.text())
        scan_max = int(self.scanmax.text())
        all_scans = self.spec.getScanNumbers()
        scans = [s for s in all_scans if scan_min <= s <= scan_max]
        self.spec.progress_bar = self.progress_bar
        self.spec.update_progress = self.update_progress
        return Parser(self.spec).toTree(scans)