TAGS :Viewed: 6 - Published at: a few seconds ago

[ Problems with closing and starting a Python program quickly ]

I have a small python/pyqt-program which functions fine the first time I run it. But if I close it and restart it quickly (in about 3 secs) this definition will give the wrong result. It runs fine without error but the if oktype will not return true even if its the exactly same file as first time I ran it! Has it anything to do with this code? Or is it higher up in my code, or maybe some sort of garbage-collection errors?

def fileChanged(fileIn, pubNotes, fileType):
    pubNotes.clear()
    fileType.clear()

    filename = str(fileIn.text())

    foundtype = 0
    oktype = ''
    okfiles = ('.max','.ma','.mb','.ni','.nk', '.psd','.ztl', '.tif', '.tiff')
    for ftype in okfiles:
        if filename.endswith(ftype):
            print('File: %s matches pattern %s') % (filename,ftype)
            foundtype = 1
            print 'ftype er %s' % ftype
            oktype = ftype
            break

    if foundtype:
        print('File is of type %s') % oktype
        if oktype is '.psd':
            typeopt = ['Matte Paint','Texture paint']
            for i in range(len(typeopt)):
                fileType.addItem(typeopt)
        if oktype is '.nk':
            typeopt = ['Comp', 'Precomp', 'Roto']
            for i in range(len(typeopt)):
                fileType.addItem(typeopt[i])
        if oktype is '.max':
            typeopt = ['Model']
            for i in range(len(typeopt)):
                fileType.addItem(typeopt[i])
        if oktype is '.tif':
            typeopt = ['Texture']
            for i in range(len(typeopt)):
                fileType.addItem(typeopt[i])
            #update comboBox_types here
    else:
        messageBox('File is not of known type, please drag other file')
        fileIn.clear

Answer 1


Yes! @TyrantWave and @reclosedev you are absolutely correct. I switched to using == instead of is and now it works like a charm! Thank you so much!