Hello,
Why don't you use the FontLab-Python-Buildin-File-Dialog?
GetFileName(open_save, string extension, string filename, string filters)
opens the file dialog. open_save = 1 for file open dialog, 0 for save as.
Eigi
Because I am an idiot, Eigi. A DAU. No, in earnest: I started with Python scripting a few days ago and I miss orientation. I want to buy a book about Python. But in German.
The Buildin-File-Dialog – that sounds promising.
But first I want to document an unelegant solution, that I have found by try and error experiments a few minutes ago:
#FLM: with unencoded glyphs at the bottom
def buildNamFile():
import Tkinter,tkFileDialog
root = Tkinter.Tk()
root.withdraw()
namFileName = tkFileDialog.asksaveasfilename(parent=root, initialfile=fontName+'.nam', initialdir="/", title="Save namFile as ...")
if not namFileName == '':
namFile = open(namFileName, 'w')
print >> namFile, '%%FONTLAB NAMETABLE: '+fontName
for g in fl.font.glyphs:
a = g.unicode
if a:
a = hex(a)
while len(a) <= 5:
a = '0x0'+a[2:]
print >> namFile, a, g.name
counter=0
for g in fl.font.glyphs:
a = g.unicode
if not a:
counter += 1
a = '%0x????'
if counter == 1:
print >> namFile, '%--------------------------------------------------unencoded'
print >> namFile, a, g.name
namFile.close()
root.iconify()
root.withdraw()
if fl.font != None:
if fl.font.glyphs:
if fl.font.font_name == None:
fontName = 'Untitled'
else:
fontName = fl.font.font_name
buildNamFile()
else:
print 'Error: Font does not contain glyphs.'
else:
print 'Error: No font opened.'
I just have added the following code:
root.iconify()
root.withdraw()
The following code has the same effect:
root.deiconify()
root.withdraw()
But I don’t know, why it works, because I assume, that the tkinter window is stll active with the added code. And even, if it works with your proposal, which seems to offer an elegant solution, I would like to make out a more elegant solution with regard to the tkinter dialog additionally.
I will try to make use of the FontLab-Python-Buildin-File-Dialog. Except from that my code is not yet clean.
Thank you, Eigi! I already was afraid, that I don’t get response here, because the activity here is relatively low in comparison to a German Python forum, where I have registered today.