Skip to content

Commit

Permalink
Implement #22
Browse files Browse the repository at this point in the history
* The main table has now a rightclick menu to open the respective structure folder
* Also double-click opens the files directory
  • Loading branch information
dkratzert committed Jan 29, 2024
1 parent 6e1d832 commit 557e321
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/changes.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
StructureFinder Changelog
-------------------------
* v80 A missing directory doesn't let the program crash anymore on file open actions. A double click or
right click can open the directory of the current structure (Only works on the same computer).

* v79 Improved program executable which can now be pinned to the taskbar. Updated updater executable.
* v78 Improved threshold of volume prefilter to be suitable for inaccurate unit cells.
* v77 The distribution architecture of the application was changed so that
Expand Down
18 changes: 16 additions & 2 deletions src/structurefinder/gui/table_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,38 @@
from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtGui import QCursor

from structurefinder.gui.table_model import Column


class StructuresListTableView(QtWidgets.QTableView):
save_excel_triggered = pyqtSignal()
open_save_path = pyqtSignal(str)

def __init__(self, parent):
super().__init__(parent)
self.setContextMenuPolicy(Qt.DefaultContextMenu)
self.doubleClicked.connect(self._on_open_file_path)

def contextMenuEvent(self, event: QtGui.QContextMenuEvent) -> None:
context_menu = QtWidgets.QMenu(self)
save_excel = context_menu.addAction("Save as Excel File")
save_excel.triggered.connect(lambda: self._on_save_excel(event))
context_menu.addAction(save_excel)
open_path = context_menu.addAction("Open file path")
context_menu.addAction(open_path)
save_excel.triggered.connect(self._on_save_excel)
open_path.triggered.connect(self._on_open_file_path)
context_menu.popup(QCursor.pos())

def _on_save_excel(self, event: QtGui.QContextMenuEvent):
def _on_save_excel(self):
self.save_excel_triggered.emit()

def _on_open_file_path(self) -> None:
try:
path_data = self.model()._data[self.currentIndex().row()][Column.PATH]
except IndexError:
path_data = b''
self.open_save_path.emit(path_data.decode(errors='ignore'))

def mousePressEvent(self, e: QtGui.QMouseEvent) -> None:
if e.button() == Qt.RightButton:
pass
Expand Down
10 changes: 10 additions & 0 deletions src/structurefinder/strf.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def connect_signals_and_slots(self):
self.ui.actionSave_Database.triggered.connect(self.save_database)
self.ui.actionCopy_Unit_Cell.triggered.connect(self.copyUnitCell)
self.ui.cifList_tableView.save_excel_triggered.connect(self.on_save_as_excel)
self.ui.cifList_tableView.open_save_path.connect(self.on_browse_path_from_row)
# Other fields:
self.ui.txtSearchEdit.textChanged.connect(self.search_text)
self.ui.searchCellLineEDit.textChanged.connect(self.search_cell)
Expand Down Expand Up @@ -325,6 +326,15 @@ def write_excel_file_from_selection(self, filename, selection):
worksheet.write(row, col, item.decode('utf-8') if isinstance(item, bytes) else item)
workbook.close()

def on_browse_path_from_row(self, curdir: str):
import subprocess
if sys.platform == "win" or sys.platform == "win32":
subprocess.Popen(['explorer', str(curdir)], shell=True)
if sys.platform == 'darwin':
subprocess.call(['open', curdir])
if sys.platform == 'linux':
subprocess.call(['xdg-open', curdir])

def show_csdentry(self, item: QModelIndex):
import webbrowser
sel = self.ui.CSDtreeWidget.selectionModel().selection()
Expand Down

0 comments on commit 557e321

Please sign in to comment.