I'm trying to handle an exception when someone exits out of the file dialogue screen without selecting a file. I was told that when this occurs, the filepath variable would be saved as "". If that's actually the case, can anyone tell me why the is statement isn't handling that case?
PYQT documentation says this about getOpenFileName: "This is a convenience static function that returns an existing file selected by the user. If the user presses Cancel, it returns a null string."
Any ideas?
def getfile(self):
filepath = QFileDialog.getOpenFileName(self, 'Open MP3 File',
'', "MP3 (*.mp3)")
self.load_info.setText("File Location: " + filepath)
return filepath
def shred(self, filepath):
try:
filepath
except NameError:
self.load_info.setText("You Must First Load A MP3 File To Shred!")
if filepath == "":
self.load_info.setText("You Must First Load A MP3 File To Shred!")
else:
self.button_shred.setText("Shredding! Please Wait!")