Timer Format Adjustment

I’m new to all this, but I needed a countdown timer and I found script that has worked for me, sort of.

It works exactly how I wanted it to work except that I’d like it to only show the numbers that are counting down and not the extra “0’s” that are showing. How can I make that sort of adjustment? Example: Currently is shows: 00:05:00. I want it to show: 5:00

Here is the blend file.
Time Bar.blend (505 KB)

BTW, I’m creating a status bar that correlates with the countdown.

Attachments

Time Bar.blend (507 KB)

Here you go:

import bpyimport math
from bpy.props import BoolProperty




def splittime(secs, prec=2):
        t = float(secs)
        minutes = t // 60
        t %= 60
        seconds = math.floor(t)
        t = round(t - seconds, prec)
        p = 10 ** prec
        fraction = math.floor(p * (t))
        return (minutes, seconds, fraction % p)    




def countdown_timer(scene):
    
    # look for all font objects with _timer property
    timers = [ob.data for ob in scene.objects if ob.type == 'FONT' and ob.data.is_timer]
    
    for font in timers:
        secs = font["timer"]
        prec = font["prec"]
        
        try:
            split_time = splittime(secs, prec=prec)
                
            fmt = ""
            if prec > 0:
                fmt = ".%0*d" % (prec, split_time[2])
                    
            if split_time[0] == 0:
                fmt = str(split_time[1]) + fmt
            else:
                fmt = ("%d:%02d" + fmt) % (split_time[0], split_time[1])
            font.body = fmt
        except:
            pass
        
    return None




def is_timer(self, context):
    if self.is_timer:
        if "timer" not in self.keys():
            self["timer"] = 0.0
            self["prec"] = 2
            
            countdown_timer(context.scene)
    return None








class TimerPanel(bpy.types.Panel):
    """Timer Panel"""
    bl_label = "Countdown Timer"
    bl_idname = "FONT_PT_timer"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "data"




    @classmethod
    def poll(cls, context):
        return (context.object and context.object.type in {'FONT'} and context.curve)




    def draw_header(self, context):
        font = context.object.data




        self.layout.prop(font, "is_timer", text="")




    def draw(self, context):
        font = context.object.data
        layout = self.layout
        if font.is_timer:
            row = layout.row()
            row.prop(font,'["timer"]', text="Seconds")
            row = layout.row()
            #frow.alert = False
            row.prop(font,'["prec"]', text="Prec")
            
            try:
                prec = font["prec"]
                split_time = splittime(font["timer"], prec=prec)
                
                fmt = ""
                if prec > 0:
                    fmt = ".%0*d" % (prec, split_time[2])
                    
                if split_time[0] == 0:
                    fmt = str(split_time[1]) + fmt
                else:
                    fmt = ("%d:%02d" + fmt) % (split_time[0], split_time[1])


                row.label(fmt)
            except:
                row.alert = True
                row.label("INVALID FORMAT STRING")
                        




def register():
    bpy.types.TextCurve.is_timer = BoolProperty(default=False, update=is_timer, description="Make countdown timer")




    bpy.app.handlers.frame_change_post.append(countdown_timer)    
    bpy.utils.register_class(TimerPanel)




def unregister():
    bpy.utils.unregister_class(TimerPanel)
    bpy.app.handlers.frame_change_post.pop()








if __name__ == "__main__":
    register()




print("Countdown Timer")