I came up with a working logic to parse the createImageFormats.mel file to fill it in the QComboBox lists for my current project, this may not be the best solution however it works perfectly.
1: def readImageFormats(self):
2: phile = "scripts/others/createImageFormats.mel"
3: imageFormatIndex={}
4: try:
5: read_phile=open(phile,"r")
6: text =str(read_phile.read())
7: except Exception as e:
8: print e
9: finally:
10: read_phile.close()
11:
12: lst = text.split("$i =")
13: for each in lst:
14: if each.split()[0].split(";")[0].isdigit() :
15: if (each.split()[-1].split(";")[0].replace('"',"")).isalnum():
16: imageFormatIndex[each.split()[0].split(";")[0]]=each.split()[-1].split(";")[0].replace('"',"").upper()
17:
18: imageFormatIndex.update({'12':'YUV'})
19: imageFormatIndex.update({'13':'SGI16'})
20: imageFormatIndex.update({'4':'TIF16'})
21: imageFormatIndex.update({'10':'MAYA16 IFF'})
22: imageFormatIndex.update({'7':'MAYA IFF'})
23: return imageFormatIndex
Basically it looks for a pattern like "$i = " and creates a list and then I split the list based on the index and retrieve the text from the selected indexes. I would guess it it would take less lines in regex but i do not have much experience with regex.