Newer
Older
Garrett Bates
committed
import os
Garrett Bates
committed
import sys
Garrett Bates
committed
import pathlib
Garrett Bates
committed
from PySide2 import QtCore, QtGui, QtWidgets
Garrett Bates
committed
from sohstationviewer.view.ui.main_ui import Ui_MainWindow
from sohstationviewer.view.calendardialog import CalendarDialog

Garrett Bates
committed
from sohstationviewer.view.ui.calendarwidget import CalendarWidget
from sohstationviewer.view.ui.filelist import FileListItem
Garrett Bates
committed
class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
"""
Implements the core logic for the Ui_MainWindow class
produced by Qt Designer. Any custom slots / signals
should be implemented in this class. Any modifications to
Ui_MainWindow *will* be lost if the UI is ever updated in
Qt Designer.
"""
currentDirectoryChanged = QtCore.Signal(str)
Garrett Bates
committed
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
Garrett Bates
committed
cwd = os.path.dirname(pathlib.Path().absolute())
self.setCurrentDirectory(cwd)
Garrett Bates
committed
self.deleteSetup.triggered.connect(self.deleteSetupFile)
# Commands menu
self.openGPSPlots.triggered.connect(self.openGpsPlot)
self.searchLog.triggered.connect(self.openLogSearch)
self.plotTimeRanges.triggered.connect(self.openPlotTimeRanges)
self.plotPositions.triggered.connect(self.openPlotPositions)
# Commands/Export submenu
self.exportDeploymentFile.triggered.connect(self.exportDepLine)
self.exportDeploymentBlock.triggered.connect(self.exportDepBlock)
self.exportTSPGeometry.triggered.connect(self.exportTspGeom)
self.exportShotInfo.triggered.connect(self.exportShotInf)
# Help menu
self.openCalendar.triggered.connect(self.openCalendarWidget)
Garrett Bates
committed
# Options Menu
self.sortGroup = QtWidgets.QActionGroup(self)
self.sortGroup.addAction(self.sortFilesByType)
self.sortGroup.addAction(self.sortFilesAlphabetically)
self.sortFilesByType.setChecked(True)
self.colorGroup = QtWidgets.QActionGroup(self)
self.colorGroup.addAction(self.colorMPRegular)
self.colorGroup.addAction(self.colorMPTrillium)
self.colorMPRegular.setChecked(True)
self.dateGroup = QtWidgets.QActionGroup(self)
self.dateGroup.addAction(self.showYYYYDOYDates)
self.dateGroup.addAction(self.showYYYY_MM_DDDates)
self.dateGroup.addAction(self.showYYYYMMMDDDates)
# self.showYYYYDOYDates.setChecked(True)
self.showYYYY_MM_DDDates.setChecked(True)
# Connect slots to change the date format displayed
# by the QDateEdit widgets
# self.showYYYYDOYDates.triggered.connect(lambda: self.setDateFormat('yyyy:D'))
self.showYYYY_MM_DDDates.triggered.connect(lambda: self.setDateFormat('yyyy-MM-dd'))
self.showYYYYMMMDDDates.triggered.connect(lambda: self.setDateFormat('yyyyMMMdd'))
self.timeToDateEdit.setCalendarWidget(CalendarWidget(self))
self.timeToDateEdit.setDate(QtCore.QDate.currentDate())
self.timeFromDateEdit.setCalendarWidget(CalendarWidget(self))
self.timeFromDateEdit.setDate(QtCore.QDate.currentDate())
# self.showYYYYDOYDates.triggered.emit()
self.showYYYY_MM_DDDates.triggered.emit()
self.openFilesList.itemDoubleClicked.connect(self.openFilesListItemDoubleClicked)
pal = self.openFilesList.palette()
pal.setColor(QtGui.QPalette.Highlight, QtGui.QColor(128, 255, 128))
pal.setColor(QtGui.QPalette.HighlightedText, QtGui.QColor(0, 0, 0))
self.openFilesList.setPalette(pal)
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
@QtCore.Slot()
def deleteSetupFile(self):
print('Deleting setup file.')
@QtCore.Slot()
def openGpsPlot(self):
print('Opening GPS plot.')
@QtCore.Slot()
def openLogSearch(self):
print('Opening Log search.')
@QtCore.Slot()
def openPlotTimeRanges(self):
print('Opening Time Ranges Plot.')
@QtCore.Slot()
def openPlotPositions(self):
print('Opening Positions Plot.')
@QtCore.Slot()
def exportDepLine(self):
print('Exporting Deployment File (Line).')
@QtCore.Slot()
def exportDepBlock(self):
print('Exporting Deployment File (Block).')
@QtCore.Slot()
def exportTspGeom(self):
print('Exporting TSP Shot File / Geometry.')
@QtCore.Slot()
def exportShotInf(self):
print('Exporting Shot Info.')
Garrett Bates
committed
@QtCore.Slot()
def readSelectedFile(self):
print('Reading currently selected file.')
# TODO: Launch a separate thread, so that
# the UI doesn't hang while data is being read.
# Otherwise, the user won't be able to cancel.
Garrett Bates
committed
@QtCore.Slot()
def stopFileRead(self):
print('Abandoning file read.')
@QtCore.Slot()
def writePSFile(self):
print('Writing PS file.')
@QtCore.Slot()
def reloadFile(self):
print('Reloading last file.')
@QtCore.Slot()
def openFilesListItemDoubleClicked(self, item):
print(f'Opening {item.text()}')
# Do something with the Path object,
# i.e., path.open(), or path.iterdir() ...
path = item.filePath
@QtCore.Slot()
def setDateFormat(self, displayFormat):
self.timeToDateEdit.setDisplayFormat(displayFormat)
self.timeFromDateEdit.setDisplayFormat(displayFormat)
def setCurrentDirectory(self, path=''):
# Remove entries when cwd changes
self.openFilesList.clear()
# Signal cwd changed, and gather list of files in new cwd
self.currentDirectoryChanged.emit(path)
for dent in pathlib.Path(path).iterdir():
self.openFilesList.addItem(FileListItem(dent))
Garrett Bates
committed
@QtCore.Slot(str)
def changeCurrentDirectory(self, path=''):
fd = QtWidgets.QFileDialog(self)
fd.setFileMode(QtWidgets.QFileDialog.Directory)
fd.exec_()
new_path = fd.selectedFiles()[0]
self.setCurrentDirectory(new_path)
Garrett Bates
committed
@QtCore.Slot(str)
def openCalendarWidget(self):
calendar = CalendarDialog(self)
calendar.show()
Garrett Bates
committed
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
wnd = MainWindow()
wnd.show()
sys.exit(app.exec_())