From 96e6fc89b80474d7788b03d8af02ea0a6a1aef8b Mon Sep 17 00:00:00 2001 From: Garrett Bates <gbates@passcal.nmt.edu> Date: Mon, 28 Jun 2021 02:50:22 -0600 Subject: [PATCH] Fixed flake8 compliance where possible --- sohstationviewer.py | 4 +++- sohstationviewer/view/calendardialog.py | 12 +----------- sohstationviewer/view/calendarwidget.py | 18 ++++++++--------- sohstationviewer/view/filelist.py | 5 +++-- sohstationviewer/view/mainwindow.py | 26 ++++++++++--------------- 5 files changed, 25 insertions(+), 40 deletions(-) diff --git a/sohstationviewer.py b/sohstationviewer.py index 3001cf207..06924283a 100644 --- a/sohstationviewer.py +++ b/sohstationviewer.py @@ -1,12 +1,14 @@ import sys -from PySide2 import QtCore, QtGui, QtWidgets +from PySide2 import QtWidgets from sohstationviewer.view.mainwindow import MainWindow + def main(): app = QtWidgets.QApplication(sys.argv) wnd = MainWindow() wnd.show() sys.exit(app.exec_()) + if __name__ == '__main__': main() diff --git a/sohstationviewer/view/calendardialog.py b/sohstationviewer/view/calendardialog.py index 496eb1bf8..b5c839fa2 100644 --- a/sohstationviewer/view/calendardialog.py +++ b/sohstationviewer/view/calendardialog.py @@ -1,13 +1,10 @@ -import sys -import pathlib -from PySide2 import QtCore, QtGui, QtWidgets +from PySide2 import QtWidgets from sohstationviewer.view.ui.calendar_ui import Ui_CalendarDialog class CalendarDialog(QtWidgets.QDialog, Ui_CalendarDialog): def __init__(self, parent=None): - super().__init__(parent) self.setupUi(self) @@ -18,10 +15,3 @@ class CalendarDialog(QtWidgets.QDialog, Ui_CalendarDialog): # date = self.calendarWidget.selectedDate() # doy = date.dayOfYear() # self.julianDateLineEdit.setText(str(doy)) - -if __name__ == '__main__': - app = QtWidgets.QApplication(sys.argv) - wnd = CalendarDialog() - wnd.show() - sys.exit(app.exec_()) - diff --git a/sohstationviewer/view/calendarwidget.py b/sohstationviewer/view/calendarwidget.py index 06507ef7b..fea881591 100644 --- a/sohstationviewer/view/calendarwidget.py +++ b/sohstationviewer/view/calendarwidget.py @@ -4,11 +4,9 @@ from PySide2 import QtCore, QtGui, QtWidgets class CalendarWidget(QtWidgets.QCalendarWidget): def __init__(self, parent): - super().__init__(parent) self.setupUi() - self._showDayOfYear = getattr(self, 'toggleDayOfYear', None) == None - + self._showDayOfYear = getattr(self, 'toggleDayOfYear', None) is None def setupUi(self): self.setMinimumWidth(300) @@ -29,25 +27,25 @@ class CalendarWidget(QtWidgets.QCalendarWidget): self.toggleDayOfYear.show() - def showDayOfYear(self): return self._showDayOfYear - @QtCore.Slot(bool) - def setShowDayOfYear(self, value): - self._showDayOfYear = value - self.updateCells() - def paintCell(self, painter, rect, date): super().paintCell(painter, rect, date) painter.save() if self.showDayOfYear(): - color = QtGui.QColor('red') if date != self.selectedDate() else QtGui.QColor('white') + color = (QtGui.QColor('red') if date != self.selectedDate() + else QtGui.QColor('white')) font = painter.font() font.setPointSize(font.pointSize() * 0.9) painter.setFont(font) painter.setPen(color) painter.drawText(rect.bottomLeft(), str(date.dayOfYear())) painter.restore() + + @QtCore.Slot(bool) + def setShowDayOfYear(self, value): + self._showDayOfYear = value + self.updateCells() diff --git a/sohstationviewer/view/filelist.py b/sohstationviewer/view/filelist.py index c18f30dfb..9ba85790f 100644 --- a/sohstationviewer/view/filelist.py +++ b/sohstationviewer/view/filelist.py @@ -1,8 +1,9 @@ -from PySide2 import QtCore, QtGui, QtWidgets +from PySide2 import QtWidgets class FileListItem(QtWidgets.QListWidgetItem): def __init__(self, filePath, parent=None): - super().__init__(filePath.name, parent, type=QtWidgets.QListWidgetItem.UserType) + super().__init__(filePath.name, parent, + type=QtWidgets.QListWidgetItem.UserType) self.filePath = filePath diff --git a/sohstationviewer/view/mainwindow.py b/sohstationviewer/view/mainwindow.py index 592700a8b..ecb8c98f7 100755 --- a/sohstationviewer/view/mainwindow.py +++ b/sohstationviewer/view/mainwindow.py @@ -1,5 +1,3 @@ -import os -import sys import pathlib from PySide2 import QtCore, QtGui, QtWidgets from sohstationviewer.view.ui.main_ui import Ui_MainWindow @@ -7,6 +5,7 @@ from sohstationviewer.view.calendardialog import CalendarDialog from sohstationviewer.view.calendarwidget import CalendarWidget from sohstationviewer.view.filelist import FileListItem + class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): """ Implements the core logic for the Ui_MainWindow class @@ -22,7 +21,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): super().__init__(parent) self.setupUi(self) - cwd = os.path.dirname(pathlib.Path().absolute()) + cwd = str(pathlib.Path().resolve().parent) self.setCurrentDirectory(cwd) # File menu @@ -63,9 +62,12 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): # 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.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()) @@ -148,13 +150,13 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): Parameters ---------- item : FileListItem - The item contained within openFilesList which was double-clicked. + The item contained within openFilesList which was clicked. """ print(f'Opening {item.text()}') # Do something with the Path object, # i.e., path.open(), or path.iterdir() ... - path = item.filePath + # path = item.filePath @QtCore.Slot(str) def setDateFormat(self, displayFormat): @@ -204,11 +206,3 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): """ calendar = CalendarDialog(self) calendar.show() - - -if __name__ == '__main__': - app = QtWidgets.QApplication(sys.argv) - wnd = MainWindow() - wnd.show() - sys.exit(app.exec_()) - -- GitLab