Skip to content

Commit

Permalink
Fix writing of excel file
Browse files Browse the repository at this point in the history
  • Loading branch information
dkratzert committed Feb 1, 2024
1 parent 0c24aaa commit 352b36e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
14 changes: 11 additions & 3 deletions src/structurefinder/gui/table_view.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Union

from PyQt5 import QtWidgets, QtGui
from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtGui import QCursor
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 9 additions & 4 deletions src/structurefinder/strf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 352b36e

Please sign in to comment.