Skip to content

Commit

Permalink
Made each model modify the minimum date on the calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
tsupinie committed Jan 4, 2019
1 parent 68eb9e3 commit ceeb619
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions runsharp/full_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,16 @@ def doCrasher(*args, **kwargs):

class Calendar(QCalendarWidget):
def __init__(self, *args, **kwargs):
dt_earliest = kwargs.pop('dt_earliest', date.datetime(1946, 1, 1))
dt_avail = kwargs.pop('dt_avail', date.datetime.utcnow().replace(
minute=0, second=0, microsecond=0))

super(Calendar, self).__init__(*args, **kwargs)

min_date = QDate(1946, 1, 1)

self.setGridVisible(True)
self.setVerticalHeaderFormat(QCalendarWidget.NoVerticalHeader)
self.setHorizontalHeaderFormat(QCalendarWidget.SingleLetterDayNames)
self.setMinimumDate(min_date)
self.setEarliestAvailable(dt_earliest)
self.setLatestAvailable(dt_avail)

for day in [Qt.Sunday, Qt.Saturday]:
Expand All @@ -147,7 +146,11 @@ def setLatestAvailable(self, dt_avail):
qdate_avail = QDate(dt_avail.year, dt_avail.month, dt_avail.day)
self.setMaximumDate(qdate_avail)
self.setSelectedDate(qdate_avail)


def setEarliestAvailable(self, dt_earliest):
qdate_earliest = QDate(dt_earliest.year, dt_earliest.month, dt_earliest.day)
self.setMinimumDate(qdate_earliest)


class Picker(QWidget):
date_format = "%Y-%m-%d %HZ"
Expand Down Expand Up @@ -431,7 +434,15 @@ def update(times):
times = times[0]

if updated_model:
self.cal.setLatestAvailable(max(times))
dt_avail = max(times)
dt_earliest = min(times)
if self.model == 'observed':
dt_earliest = date.datetime(1946, 1, 1)
elif self.model.lower() in ['gfs', 'nam', 'rap', 'nam4km', 'ruc']:
dt_earliest = date.datetime(2010, 12, 30)

self.cal.setLatestAvailable(dt_avail)
self.cal.setEarliestAvailable(dt_earliest)
self.cal_date = self.cal.selectedDate()

self.run_dropdown.clear() # Clear all of the items from the dropdown
Expand Down

0 comments on commit ceeb619

Please sign in to comment.