value tab plots complex selection; graphwindows shows last path for export; filedialog uses call not init

This commit is contained in:
dominik
2022-11-19 17:59:35 +01:00
parent a61dc40343
commit 4ca8f434aa
11 changed files with 206 additions and 157 deletions

View File

@ -18,7 +18,7 @@ class QAsciiReader(QtWidgets.QDialog, Ui_ascii_reader):
pal = QtWidgets.QApplication.instance().palette()
rgb = pal.color(pal.Base).getRgb()[:3]
rgb2 = pal.color(pal.Text).getRgb()[:3]
self.plainTextEdit_2.setStyleSheet(f'QPlainTextEdit {{ background-color: rgb{rgb} ; color: rgb{rgb2}; }}')
self.comment_textfield.setStyleSheet(f'Qdelay_textfield {{ background-color: rgb{rgb} ; color: rgb{rgb2}; }}')
self.ascii_table.horizontalHeader().setStretchLastSection(True)
self.buttonbox.button(QtWidgets.QDialogButtonBox.Apply).clicked.connect(self.apply)
@ -31,13 +31,12 @@ class QAsciiReader(QtWidgets.QDialog, Ui_ascii_reader):
self.ascii_table.horizontalHeader().customContextMenuRequested.connect(self.ctx_table)
def __call__(self, fname, *args, **kwargs):
for i in [self.stag_lineEdit, self.start_lineedit, self.end_lineedit,
self.plainTextEdit_2, self.ascii_table, self.delay_lineedit]:
self.comment_textfield, self.ascii_table, self.delay_lineedit]:
i.clear()
self.checkBox_2.setChecked(False)
self.checkBox.setChecked(False)
self.plainTextEdit_2.show()
self.staggered_checkBox.setChecked(False)
self.log_checkBox.setChecked(False)
self.comment_textfield.show()
self.reader = AsciiReader(fname)
self.set_gui()
@ -53,7 +52,7 @@ class QAsciiReader(QtWidgets.QDialog, Ui_ascii_reader):
def set_gui(self):
for text in self.reader.header:
self.plainTextEdit_2.appendPlainText(text)
self.comment_textfield.appendPlainText(text)
self.ascii_table.setRowCount(self.reader.shape[0])
self.ascii_table.setColumnCount(self.reader.shape[1])
@ -62,7 +61,7 @@ class QAsciiReader(QtWidgets.QDialog, Ui_ascii_reader):
if len(last_header_line) == self.reader.shape[1]:
self.ascii_table.setHorizontalHeaderLabels(last_header_line)
except IndexError:
self.plainTextEdit_2.hide()
self.comment_textfield.hide()
for i, line in enumerate(self.reader.data):
for j, field in enumerate(line):
@ -73,7 +72,7 @@ class QAsciiReader(QtWidgets.QDialog, Ui_ascii_reader):
if self.reader.delays is not None:
set_string = ''.join(str(d) + '\n' for d in self.reader.delays)
self.plainTextEdit.setPlainText(set_string)
self.delay_textfield.setPlainText(set_string)
self.delay_lineedit.setText(str(len(self.reader.delays)))
def ctx_table(self, _):
@ -92,7 +91,7 @@ class QAsciiReader(QtWidgets.QDialog, Ui_ascii_reader):
def set_columns(self, mode):
cols = ' '.join([str(s.column()+1) for s in self.ascii_table.selectionModel().selectedColumns()])
try:
lineedit = {'x': self.x_lineedit, 'y': self.y_lineedit, 'yerr': self.lineEdit}[mode]
lineedit = {'x': self.x_lineedit, 'y': self.y_lineedit, 'yerr': self.deltay_lineEdit}[mode]
lineedit.setText(cols)
except KeyError:
pass
@ -109,19 +108,19 @@ class QAsciiReader(QtWidgets.QDialog, Ui_ascii_reader):
@QtCore.pyqtSlot(name='on_pushButton_clicked')
def calc_delays(self):
self.reader.calc_delays(float(self.start_lineedit.text()), float(self.end_lineedit.text()),
int(self.delay_lineedit.text()), log=self.checkBox.isChecked(),
stagg=self.checkBox_2.isChecked(), stag_size=int(self.stag_lineEdit.text()))
int(self.delay_lineedit.text()), log=self.log_checkBox.isChecked(),
stagg=self.staggered_checkBox.isChecked(), stag_size=int(self.stag_lineEdit.text()))
set_string = ''.join(str(d) + '\n' for d in self.reader.delays)
self.plainTextEdit.setPlainText(set_string)
self.delay_textfield.setPlainText(set_string)
def update_header(self, text, comment='#'):
text = text.replace(comment, '').lstrip().rstrip()
self.plainTextEdit_2.appendPlainText(text)
self.comment_textfield.appendPlainText(text)
@QtCore.pyqtSlot()
def on_plainTextEdit_textChanged(self):
new_delays = str(self.plainTextEdit.toPlainText()).rstrip('\n').split('\n')
def on_delay_textfield_textChanged(self):
new_delays = str(self.delay_textfield.toPlainText()).rstrip('\n').split('\n')
self.delay_lineedit.setText(str(len(new_delays)))
if new_delays[0] == '':
new_delays = None
@ -150,7 +149,7 @@ class QAsciiReader(QtWidgets.QDialog, Ui_ascii_reader):
except ValueError:
y = None
try:
y_err = [int(t)-1 for t in str(self.lineEdit.text()).split(' ')]
y_err = [int(t)-1 for t in str(self.deltay_lineEdit.text()).split(' ')]
except ValueError:
y_err = None
@ -179,7 +178,7 @@ class QAsciiReader(QtWidgets.QDialog, Ui_ascii_reader):
if val == -2:
self.widget.show()
else:
self.lineEdit.setText('')
self.deltay_lineEdit.setText('')
self.widget.hide()
@QtCore.pyqtSlot(int, name='on_skippy_checkbox_stateChanged')

View File

@ -1,5 +1,7 @@
from __future__ import annotations
from pathlib import Path
from numpy import c_
from nmreval.io.graceeditor import GraceEditor
@ -13,7 +15,7 @@ class GraceExporter:
self.__agr = None
self.__opts = kwargs
def export(self, outfile: str, mode: int | str = 'w'):
def export(self, outfile: str | Path, mode: int | str = 'w'):
if mode == 'w':
self.__agr = GraceEditor()
else:

View File

@ -5,14 +5,17 @@ import pathlib
from ..Qt import QtWidgets, QtCore
class _FileDialog(QtWidgets.QFileDialog):
class FileDialog(QtWidgets.QFileDialog):
last_path = None
def __init__(self, directory=None, caption=None, filters='', parent=None):
super().__init__(parent=parent)
self.setOption(QtWidgets.QFileDialog.DontUseNativeDialog, True)
self.setWindowTitle(caption)
self.setDirectory(str(directory))
if directory is not None:
self.setDirectory(str(directory))
self.setNameFilters(filters.split(';;'))
file_tree = self.findChild(QtWidgets.QTreeView, 'treeView')
@ -29,8 +32,14 @@ class _FileDialog(QtWidgets.QFileDialog):
line.setFrameShadow(line.Sunken)
self.layout().addWidget(line, self.layout().rowCount(), 0, 1, self.layout().columnCount())
def save_file(self) -> pathlib.Path | None:
outfile = self.selectedFiles()
if outfile:
return pathlib.Path(outfile[0])
return
class OpenFileDialog(_FileDialog):
class OpenFileDialog(FileDialog):
def __init__(self, directory=None, caption=None, filters='', parent=None):
super().__init__(directory=directory, caption=caption, filters=filters, parent=parent)
@ -71,7 +80,7 @@ class OpenFileDialog(_FileDialog):
self.add_to_graph = self.comboBox.itemData(idx)
class SaveDirectoryDialog(_FileDialog):
class SaveDirectoryDialog(FileDialog):
def __init__(self, directory=None, filters='', parent=None):
super().__init__(directory=directory, filters=filters, parent=parent)
@ -115,8 +124,3 @@ class SaveDirectoryDialog(_FileDialog):
self.setNameFilters(['All files (*.*)', 'Session file (*.nmr)', 'Text file (*.dat)',
'HDF file (*.h5)', 'Grace files (*.agr)'])
def save_file(self) -> pathlib.Path | None:
outfile = self.selectedFiles()
if outfile:
return pathlib.Path(outfile[0])
return