11 |
|
|
12 |
def importPDF_select(fen, treetime): |
def importPDF_select(fen, treetime): |
13 |
"""Show a file selection dialog and import a file. |
"""Show a file selection dialog and import a file. |
14 |
|
|
15 |
|
Returns a sequence of ScrollBlock objects imported. |
16 |
""" |
""" |
17 |
|
|
18 |
file = selectFile("Select PS/PDF file to import, or directory for all files in it") |
file = selectFile("Select PS/PDF file to import, or directory for all files in it") |
21 |
|
|
22 |
lastFile = None |
lastFile = None |
23 |
if file.isDirectory(): |
if file.isDirectory(): |
24 |
|
blocks = [] |
25 |
for f in file.listFiles(): |
for f in file.listFiles(): |
26 |
try: |
try: |
27 |
if f.isDirectory(): continue |
if f.isDirectory(): continue |
28 |
importPDF(fen, treetime, f) |
blocks.append( |
29 |
|
importPDF(fen, treetime, f) |
30 |
|
) |
31 |
except exception: |
except exception: |
32 |
print "EXCEPTION LOADING",f,":",sys.exc_info() |
print "EXCEPTION LOADING",f,":",sys.exc_info() |
33 |
|
blocks = [b for b in blocks if b != None ] |
34 |
|
return blocks |
35 |
else: |
else: |
36 |
return importPDF(fen, treetime, file) |
return [importPDF(fen, treetime, file)] |
37 |
|
|
38 |
def selectFile(string): |
def selectFile(string): |
39 |
"""Select a file using an AWT dialog, with the given prompt. |
"""Select a file using an AWT dialog, with the given prompt. |
71 |
# XXX JPEG?!? |
# XXX JPEG?!? |
72 |
elif type.startswith('\xff\xd8\xff\xe0'): p('JPEG not yet supported!'); scrollBlock = None |
elif type.startswith('\xff\xd8\xff\xe0'): p('JPEG not yet supported!'); scrollBlock = None |
73 |
|
|
74 |
|
if scrollBlock == None: return |
75 |
|
|
76 |
if treetime != None: |
if treetime != None: |
77 |
try: |
try: |
78 |
treetime.addLatest(fen.graph, |
treetime.addLatest(fen.graph, |