The Toolkit 4: Remembrance

 Ok, so I couldn't really work on the project for about 3 days due to some technical issues with my laptop, and now I have to figure out exactly what I was doing and what I was supposed to do before. Oof what a horrible feeling.

anyways after some time I got some idea of what I should do next.

on the itinerary we have:

  1. find a way to make the calendar highlight a specific date.
  2. make a method that takes the values from the specified first date and the days allotted.
  3. make calendar highlight the day that results from #2.
  4. output the result in the gray box.
  5. make the month label above the calendar change depending on the calendar(might do this first).
  6. check for errors.
  7. start the word doc program.

ok we a couple things to do this time, so lets see what we can do.
so, I went back into the QTdesigner and saw that under the calendar there that says single selection, so I might be able to do something with that.

so, to begin I changed the text box for days allotted and first day into spin boxes, so that way only numbers can be inputted.


so the next thing to do was to get a selected date which is an attribute that highlights a date on the calendar, so I made a new method(and changed the positions of days allotted and first day off) that would be called everytime the text in the days allotted box changes.

basically you would get a first day and the days allotted would added to it and then put as endDay in a date template thing I cobbled together like this: 
finalDate = str(self.monthSel.currentIndex()+1) + '/' + str(endDay) + '/' + str(self.yearBx.text())
and then put into: self.calendar.selectedDate(finalDate)
then I got an error saying there was too many arguments.....ugh. 

so after about 20 minutes I found this on geeksforgeeks.
where I found this
# date
date = QDate(2021, 1, 1)
# setting selected date
calendar.setSelectedDate(date)
and it still didn't work, apprently what I needed to do was import Qdate from PyQT, so PyQt6.QtCore import QDate, now it works!!
...
......
........ 
it works but like wrong, when I select a day it starts at 10 so here is my mistake:
def dateFinder(self):
        endDay = self.fDayOff.text() + self.dayAllot.text()
        finalDate = QDate(int(self.yearBx.text()),(self.monthSel.currentIndex()+1),int(endDay))
        print(finalDate)
        self.calendar.setSelectedDate(finalDate)

this is my method and if we select day 1 and the alloted days off is 5, instead of showing the final day off, its literally putting numbers together so instead of day 6, its day 15......Ooops

so anyways int() around both fixes it.
a new problem has been encountered and its that after day 31 the calendar doesn't change months😓

and that is when I hit the realization that I am stuck........dang it.

Several days of suffering later

finally....Finally!!!!! The function now looks like this:

a dynamically updating Qcalendar!
    def dateFinder(self):
        year = int(self.yearBx.text())
        month = self.monthSel.currentIndex() + 1
        day = self.fDayOff.value() + self.dayAllot.value()
       
        while day > QDate(year, month, 1).daysInMonth():
            day -= QDate(year, month, 1).daysInMonth()
            month += 1
           
            if month > 12:
                month = 1
                year += 1

        final_date = QDate(year, month, day)
        self.calendar.setSelectedDate(final_date)

there were things that were too complicated, so I simplified them, like the year, month and day.
then with the help of king google and our lord and saviors stack overflow and chatgpt, I managed to get this while loop when the day is greater than the days in a month that it should reset the days back to the first day of the month and then change the month.

then there is a check for when december comes as well.

after that its just setting the final date and having the calendar select it.
after that exhausting nonsense I'll end this here and go find some asprin.

~~Justin Case











Comments

Quote of the day