Skip to content
Snippets Groups Projects
mainwindow.py 6.04 KiB
Newer Older
from sohstationviewer.view.ui.main_ui import Ui_MainWindow
from sohstationviewer.view.calendardialog import CalendarDialog
from sohstationviewer.view.ui.calendarwidget import CalendarWidget
from sohstationviewer.view.ui.filelist import FileListItem

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)

    def __init__(self, parent=None):
        super().__init__(parent)
        self.setupUi(self)

        cwd = os.path.dirname(pathlib.Path().absolute())
        self.deleteSetup.triggered.connect(self.deleteSetupFile)
        self.openGPSPlots.triggered.connect(self.openGpsPlot)
        self.searchLog.triggered.connect(self.openLogSearch)
        self.plotTimeRanges.triggered.connect(self.openPlotTimeRanges)
        self.plotPositions.triggered.connect(self.openPlotPositions)
        self.exportDeploymentFile.triggered.connect(self.exportDepLine)
        self.exportDeploymentBlock.triggered.connect(self.exportDepBlock)
        self.exportTSPGeometry.triggered.connect(self.exportTspGeom)
        self.exportShotInfo.triggered.connect(self.exportShotInf)
        self.openCalendar.triggered.connect(self.openCalendarWidget)
        # 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)
    @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()
    @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.

    @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))
    @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)
    def openCalendarWidget(self):
        calendar = CalendarDialog(self)
        calendar.show()

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    wnd = MainWindow()
    wnd.show()
    sys.exit(app.exec_())