diff --git a/src/structurefinder/gui/table_view.py b/src/structurefinder/gui/table_view.py index 3418f59..7ffacea 100644 --- a/src/structurefinder/gui/table_view.py +++ b/src/structurefinder/gui/table_view.py @@ -1,3 +1,5 @@ +from typing import Union + from PyQt5 import QtWidgets, QtGui from PyQt5.QtCore import Qt, pyqtSignal from PyQt5.QtGui import QCursor @@ -27,12 +29,18 @@ def contextMenuEvent(self, event: QtGui.QContextMenuEvent) -> None: def _on_save_excel(self): self.save_excel_triggered.emit() + def get_field_content(self, row: int, col: int) -> Union[str, int]: + model = self.model() + source_index = model.index(row, col) + content = model.data(source_index) + return content + def _on_open_file_path(self) -> None: try: - path_data = self.model()._data[self.currentIndex().row()][Column.PATH] + path_data = self.get_field_content(self.currentIndex().row(), Column.PATH) except IndexError: - path_data = b'' - self.open_save_path.emit(path_data.decode(errors='ignore')) + path_data = '' + self.open_save_path.emit(path_data) def mousePressEvent(self, e: QtGui.QMouseEvent) -> None: if e.button() == Qt.RightButton: diff --git a/src/structurefinder/strf.py b/src/structurefinder/strf.py index 7267254..a186b96 100644 --- a/src/structurefinder/strf.py +++ b/src/structurefinder/strf.py @@ -37,7 +37,7 @@ from structurefinder.ccdc.query import search_csd, parse_results from structurefinder.displaymol.sdm import SDM from structurefinder.gui.strf_main import Ui_stdbMainwindow -from structurefinder.gui.table_model import TableModel, CustomProxyModel +from structurefinder.gui.table_model import TableModel, CustomProxyModel, Column from structurefinder.misc.dialogs import bug_found_warning, do_update_program from structurefinder.misc.download import MyDownloader from structurefinder.misc.exporter import export_to_cif_file @@ -332,9 +332,14 @@ def write_excel_file_from_selection(self, filename, selection): workbook = xlsxwriter.Workbook(filename) worksheet = workbook.add_worksheet() for row, index in enumerate(selection): - row_data = self.ui.cifList_tableView.model()._data[index.row()] - for col, item in enumerate(row_data): - worksheet.write(row, col, item.decode('utf-8') if isinstance(item, bytes) else item) + row_1_data = self.ui.cifList_tableView.get_field_content(index.row(), Column.DATA) + row_2_data = self.ui.cifList_tableView.get_field_content(index.row(), Column.FILENAME) + row_3_data = self.ui.cifList_tableView.get_field_content(index.row(), Column.MODIFIED) + row_4_data = self.ui.cifList_tableView.get_field_content(index.row(), Column.PATH) + worksheet.write(row, Column.DATA, row_1_data) + worksheet.write(row, Column.FILENAME, row_2_data) + worksheet.write(row, Column.MODIFIED, row_3_data) + worksheet.write(row, Column.PATH, row_4_data) workbook.close() def on_browse_path_from_row(self, curdir: str):