0

We are trying to show a calendar on a e-ink display linked to a google calendar. We can get the whole month to display, but we want just one week to display at a time and when the week ends, it will change the week that has passed to the following week.

We have tried to create loops using "if" and "else", but we have not been able to get it to run correctly with those yet.

positions = {
    # positions the code block to appear on certain columns and rows
    'a1': (col1, row1), 'a2': (col2, row1), 'a3': (col3, row1), 'a4': (col4, row1),
    'a5': (col5, row1), 'a6': (col6, row1), 'a7': (col7, row1),

    'b1': (col1, row2), 'b2': (col2, row2), 'b3': (col3, row2), 'b4': (col4, row2),
    'b5': (col5, row2), 'b6': (col6, row2), 'b7': (col7, row2),

    'c1': (col1, row3), 'c2': (col2, row3), 'c3': (col3, row3), 'c4': (col4, row3),
    'c5': (col5, row3), 'c6': (col6, row3), 'c7': (col7, row3),

    'd1': (col1, row4), 'd2': (col2, row4), 'd3': (col3, row4), 'd4': (col4, row4),
    'd5': (col5, row4), 'd6': (col6, row4), 'd7': (col7, row4),

    'e1': (col1, row5), 'e2': (col2, row5), 'e3': (col3, row5), 'e4': (col4, row5),
    'e5': (col5, row5), 'e6': (col6, row5), 'e7': (col7, row5),

    'f1': (col1, row6), 'f2': (col2, row6), 'f3': (col3, row6), 'f4': (col4, row6),
    'f5': (col5, row6), 'f6': (col6, row6), 'f7': (col7, row6)
    }

This is from another .py file that calls the positions.

"""Using the built-in calendar function, draw icons for each number of the month (1,2,3,...28,29,30)""" cal = calendar.monthcalendar(time.year, time.month)

        while True:

            if numbers in cal[0]:
                image.paste(im_open(dpath+str(numbers)+'.jpeg'), positions['a'+str(cal[0].index(numbers)+1)])
            elif numbers in cal[1]:
                image.paste(im_open(dpath+str(numbers)+'.jpeg'), positions['b'+str(cal[1].index(numbers)+1)])
            elif numbers in cal[2]:
                image.paste(im_open(dpath+str(numbers)+'.jpeg'), positions['c'+str(cal[2].index(numbers)+1)])
            elif numbers in cal[3]:
                image.paste(im_open(dpath+str(numbers)+'.jpeg'), positions['d'+str(cal[3].index(numbers)+1)])
            elif numbers in cal[4]:
                image.paste(im_open(dpath+str(numbers)+'.jpeg'), positions['e'+str(cal[4].index(numbers)+1)])
            elif len(cal) is 6:
                break
            else numbers in cal[5]:
                image.paste(im_open(dpath+str(numbers)+'.jpeg'), positions['f'+str(cal[5].index(numbers)+1)])

We expect it to show for example, Monday 2 through Sunday 8 and then change to Monday 9 through Sunday 16 when the date changes from the 8th to the 9th. Our actual results so far are either the whole month shows or a week shows, but it may show the wrong week and/or does not change when the week is up.

anglewf
  • 1
  • 1
  • you would have to use loop like `while True` which runs all time and check if it is new week and then change your calendar. – furas Oct 16 '19 at 15:49
  • We did the while true loop, but its calling from another part of the code and when we try to edit the code that is called, we are getting an invalid syntax error. "else numbers in cal[5]:" The error points to numbers as an invalid syntax. – anglewf Oct 22 '19 at 22:01
  • We start the loop with "while True:" went to "if numbers in cal[0]:" then it will paste an image at positions [ 'a'+str(cal[0].index(numbers)+1)]. Then we went to "elif numbers in cal[1]:" then paste that image at position 'b' and cal[1] using the same code above. we continued this loop with elif in cal[2] at position 'c', elif in cal[3] at position 'd', elif in cal[4] at position 'e'. Then "elif len(cal) is 6:" we entered the break command after this line and ended the loop with "else numbers in cal[5]:". Line below this pastes at position 'f' with "cal[5]". – anglewf Oct 22 '19 at 22:13
  • put code and full error message at the end of your question - it will be more readable. You shows only `positions` but you should also show code which you use to display it and which modules you use for this. – furas Oct 22 '19 at 22:31
  • Thanks we added to the question, let us know if anything else needs to be added to understand it. – anglewf Oct 24 '19 at 19:05

0 Answers0