I am creating a data import module and I need to restrict users to uploading only Excel workbooks. I'm using AppJar for the GUI
app = gui('File Selection', '600x600')
app.addImage("Company", "appJar/company.gif")
app.zoomImage("Company", -10)
app.addLabel('title', 'PowerPoint Data Import')
app.setFont(18)
app.addFileEntry('Data File')
def press(button):
if button == "Cancel":
app.stop
else:
entry = app.getEntry('Data File')
print 'Data File:', entry
wb = load_workbook(filename = entry, data_only = True)
DataImport(wb)
pptxname = entry[:-5] + '.pptx'
prs.save(pptxname)
print "Import Complete"
app.addButtons(['Import', 'Cancel'], press)
app.go()
No error messages, but the system will allow any filetype to be selected, and I haven't been able to find a way to restrict it.
To make this work, I had to create a separate button that set the value, rather than using the feature that added multiple buttons. A bit roundabout, I'm afraid.
def xlsxselect():
xslxfile = app.openBox(title="Choose Import Data", dirName=None, fileTypes=[('excel worksheets', '*.xlsx')],
parent=None, multiple=False, mode='r')
app.setEntry('xlsxfile', xslxfile, callFunction=False)