Periodically update panel background

Question about custom panels:

I LOVE the custom panel option and I use my BigTemperature panel and my whole family loves to see it.

One of the things I do in my panel is that I have a custom background in that single panel. It’s an animated GIF generated by another Raspberry Pi with a camera. It’s effectively showing a 15min GIF of the most recent weather outside my house.

The issue I have, is that I can’t get the panel to reload it self any more, since the new updates, so, even though the GIF is updated every 15 mins or so, it’s stale, in the panel.

I’m not a Python expert, but you gave me some code awhile back to set a Clock.schedule_interval to update reload/refresh the panel. I’ve tried to incorporate that into my custom one but just can’t get it right without crashing the display at the time interval, or causing the whole thing not to load.

Any possibility you could share the code I would need to use in the customPanels.py to allow the panel to reload every XX seconds?

Thanks!
Steve

Can you share the code I gave you last time? Hopefully a jog to my memory will save me having to work out how to do this all again :joy:

Sure. This is the original class I used before you created the custom ones. This allowed for a refresh/reload every 600 secs.

###From main.py

==============================================================================

BigTemp Panel RELATIVE LAYOUT CLASS

==============================================================================

class BigTempPanel(RelativeLayout):

# Initialise 'BigTempPanel' relative layout class
def __init__(self,**kwargs):
    super(BigTempPanel,self).__init__(**kwargs)
    App.get_running_app().BigTempPanel = self
    Clock.schedule_interval(self.updateImage,600.0)

def updateImage(self,dt):
    self.ids.BigTempBackground.reload()

class BigTempButton(RelativeLayout):
pass

#From wfpiconsole.kv

=============================================================================

BIGTEMP FORECAST PANEL AND BUTTON

=============================================================================

:
Image:
id: BigTempBackground
source: ‘background/BigTempBackground.png’
size_hint: (1,1)
keep_ratio: 0
allow_stretch: 1

Outdoor temperature

ExtraLargeText

if app.Obs[‘outTemp’][0] > ‘90.1’: font_size: ‘80sp’

    text: '[color=ff0404ff]' +  app.Obs['outTemp'][0]
    pos_hint: {'x': 18/262, 'y': 50/202}
    size_hint: (250/262, 100/202)

:
Button:
id: ‘BigTempButton’
background_normal: ‘buttons/BigTemp.png’
background_down: ‘buttons/BigTempPressed.png’
on_release: app.CurrentConditions.SwitchPanel(self)

@peter
Update on my reloading panel. I used ChatGpt to help fix the code I was trying to use and it actually gave me working code and helped fix my errors. lol. I had a couple of errors in what I was trying to use and it analysed the Python Traceback and told me what to fix. :slight_smile:

You can ignore my request and work on more important things.

For anyone that’s interested, I created a wfpiconsole/backgrounds directory and I put an animated GIF in it. The GIF happens to be a timelapse of the sky in my backyard.

I use this code in customPanels.kv

<BigTemperaturePanel>:
    PanelBackground:
        _panelTitle: 'Big Temperature'
    Image:
        id: BigTempBackground
        source: 'background/BigTempBackground.gif'
        size_hint: (1,1)
        keep_ratio: 0
        allow_stretch: 1
    Label:
        text: app.CurrentConditions.Obs['outTemp'][0] ## + app.CurrentConditions.Obs['outTemp'][1]
        pos_hint: {'x': 0, 'y': 0}
        size_hint: (1, 1)
        font_name: 'fonts/Inter-Bold.ttf'
        font_size: dp(100*app.scaleFactor)
        color: utils.rgba('#ff0404ff')
        valign: 'center'
        halign: 'center'
        markup: 1

<BigTemperatureButton>:
    PanelButton:
        text: 'BigTemp'
        on_release: app.CurrentConditions.switchPanel(self)

Then, in customPanels.py

# Load App to support panel reload
from kivy.clock       import Clock

# ===================
# BigTemperature CUSTOM PANEL
# ===================
class BigTemperaturePanel(panelTemplate):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        Clock.schedule_interval(self.updateImage, 600)

    def updateImage(self,dt):
        self.ids.BigTempBackground.reload()

class BigTemperatureButton(RelativeLayout):
    pass
2 Likes

Wow - that is scary! I had sketched out some code for you but hadn’t had a chance to test it, and it is literally identical to what ChatGPT suggested. Glad you managed to get it working :smiley:

2 Likes