Panda3D - Setting date

88 views Asked by At

I am trying to make that every screenshot file end with a date. It does work, but the problem is that when i take a new screenshot, its always the same date.

Heres the code

class ScrShot(object):    
    def Screenie(self):
            file_name = Filename('WFT-ScreenShot-'+str(date)+'.jpg')
            base.win.saveScreenshot(file_name) 
            print ':debug: screenshot taken!'
            print ':debug: screenshot saved as ', file_name ,''

instance = ScrShot()

base.accept('f9', instance.Screenie)

and heres the variable used:

###########################################
#time
date = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
###########################################

Plus, something from the log:

:debug: screenshot taken!
:debug: screenshot saved as  WFT-ScreenShot-2013-12-24-18-46-04.jpg
:debug: screenshot taken!
:debug: screenshot saved as  WFT-ScreenShot-2013-12-24-18-46-04.jpg
:debug: screenshot taken!
:debug: screenshot saved as  WFT-ScreenShot-2013-12-24-18-46-04.jpg

Now, any another method to update the date?

EDIT: It did fix the problem, but i also wanted to save in a external folder. Is there a way to do it?

1

There are 1 answers

0
Timothy On

Replace your class with:

class ScrShot(object):    
    def Screenie(self):
        file_name = Filename('WFT-ScreenShot-'+str(datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S'))+'.jpg')
        base.win.saveScreenshot(file_name) 
        print ':debug: screenshot taken!'
        print ':debug: screenshot saved as ', file_name ,''

It outputs all the same date because you assigned date only once. It dosesn't update automatically when you use date. You have to call now() everytime when you want to get a new date.