Re: Reuse saved file name
You need two separate methods: one to get the file name the first time, and another that you use with the QTimer to autosave. When you start the program, the "save file" name is blank. You start the timer, the timeout slot looks at the name and see that it is empty, so it calls the method to get the file name from the user. It then saves the name in a member variable. Then, each time the timeout occurs, it sees that the filename is not blank and uses that name to save instead of asking for a new one.
Re: Reuse saved file name
Hi there! Thanks for the response. However, since I'm at a beginner level in programming, could you direct me to a resource where I can get this in detail with an example?
I am using the function as:
Code:
def sampleSave(self):
filename
= QtWidgets.
QFileDialog.
getSaveFileName(caption
="Choose pkl to save configuration")
Now, how do I recall this filename?
Code:
timer = threading.Timer(300, self.sampleSave, filename)
timer.start()
is this correct?
Re: Reuse saved file name
I am not a Python expert, but your code should look something like this:
Code:
def __init__( self ) :
self.filename = ""
def getAutosaveName(self):
self.
filename = QtWidgets.
QFileDialog.
getSaveFileName(caption
="Choose pkl to save configuration")
def onTimeout( self ) :
if self.filename.isEmpty() :
getAutosaveName()
# use self.filename to save the file
timer = threading.Timer( 300, self.onTimeout )
timer.start()
What units are the first argument in threading.Timer()? Seconds or milliseconds? You certainly don't want to be autosaving a file every 300 ms - if you did, your program wouldn't have time to do anything else. Saving every 300 seconds (300000 ms) would be more reasonable.
Re: Reuse saved file name
It is in seconds. Looking at the code you mentioned, it is more understandable to me now. Thank you!