Exemple #1
0
 def _dlg_load_data(self):
     """ Open file-dialog to choose one or multiple files. """
     FD = QFileDialog(self, 'Open data file', '.',
                      """Raw data (*.data *.hdf5 *.mat *.npy *.txt);;
                       Images (*.jpg *.bmp *.png *.tiff);;
                       All (*)""")
     FD.setOptions(QFileDialog.DontUseNativeDialog)
     FD.setFileMode(QFileDialog.ExistingFiles)
     checkbox = QCheckBox("Put first dimension to the end", FD)
     checkbox.setChecked(self.config.getboolean('opt', 'first_to_last'))
     FD.layout().addWidget(checkbox, 4, 1, 1, 1)
     if FD.exec_():
         fnames = FD.selectedFiles()
         self.config.set('opt', 'first_to_last',
                         str(checkbox.checkState() != 0))
         # For all files
         if isinstance(fnames[0], list):
             fnames = fnames[0]
         self.load_files(fnames)
Exemple #2
0
 def saveAllCsv(self):
     """Save data for all currently plotted lines"""
     #Harsha: Plots were saved in GUI folder instead provided QFileDialog box to save to
     #user choose
     fileDialog2 = QFileDialog(self)
     fileDialog2.setFileMode(QFileDialog.Directory)
     fileDialog2.setWindowTitle('Select Directory to save plots')
     fileDialog2.setOptions(QFileDialog.ShowDirsOnly)
     fileDialog2.setLabelText(QFileDialog.Accept, self.tr("Save"))
     targetPanel = QFrame(fileDialog2)
     targetPanel.setLayout(QVBoxLayout())
     layout = fileDialog2.layout()
     layout.addWidget(targetPanel)
     if fileDialog2.exec_():
         directory = fileDialog2.directory().path()
         for line in list(self.lineToDataSource.keys()):
             self.saveCsv(line, directory)
Exemple #3
0
    def open(self):
        """
        File dialog with selections syntax and file type.
        """
        filedialog = QFileDialog(self)
        filedialog.setOption(QFileDialog.DontUseNativeDialog)
        filedialog.setDefaultSuffix("*.*")
        filedialog.setDirectory(
            self.cfg.get("TextEditor/LastPath", ".", system=True))
        layout = filedialog.layout()

        type_files = [  # type, syntax, is HTML, list of exts
            (self.tr("All files (*)"), self.tr("-- no --"), True, []),
            (self.tr("Python files (*.py *.pyw)"), "Python", False,
             ["py", "pyw"]),
            (self.tr("SQL scripts (*.sql)"), "SQL", False, ["sql"]),
            (self.tr("Text files (*.txt)"), self.tr("-- no --"), False,
             ["txt"]),
        ]
        filedialog.setNameFilters([t[0] for t in type_files])

        syntax = QComboBox()
        __in_cmb = []
        for t in type_files:
            if t[1] not in __in_cmb:
                __in_cmb.append(t[1])
                syntax.addItem(t[1])

        lbl_syntax = QLabel(self.tr("Syntax"))
        format_text = QCheckBox("HTML")
        format_text.setChecked(True)

        col, row = layout.columnCount(), layout.rowCount()
        layout.addWidget(syntax, row, col - 1)
        layout.addWidget(format_text, row, col - 1)
        layout.addWidget(lbl_syntax, row, 0)
        layout.addWidget(syntax, row, col - 2)
        layout.itemAtPosition(row, col - 1).setAlignment(Qt.AlignCenter)

        layout.update()
        layout.activate()

        def _change_syntax_and_type(idx):  # pragma: no cover
            syntax.setCurrentText(type_files[idx][1])
            format_text.setChecked(type_files[idx][2])

        def _filter_selected(name):  # pragma: no cover
            for i, (nm, _, _, _) in enumerate(type_files):
                if name == nm:
                    _change_syntax_and_type(i)

        def _current_changed(name):  # pragma: no cover
            if "." in name:
                ext = name.split(".")[-1].lower()
                for i, (_, _, _, exts) in enumerate(type_files):
                    if ext in exts:
                        _change_syntax_and_type(i)
                        return
            _change_syntax_and_type(0)

        filedialog.currentChanged.connect(_current_changed)
        filedialog.filterSelected.connect(_filter_selected)

        if filedialog.exec_():
            text_format = "html" if format_text.isChecked() else "text"
            path = filedialog.selectedFiles()[0]
            self.open_file(path=path, fmt=text_format, hl=syntax.currentText())
            self.cfg["SYSTEM", "TextEditor/LastPath"] = os.path.dirname(path)