def __init__(self, parent): import resources.logo_packed self.parent = parent self.settings = self.loadConfiguration() self.frame = Frame(parent) self.frame.pack(padx=10, pady=10, fill=X, expand=1) # Menu self.menu = Menu(parent) mainmenu = Menu(self.menu, tearoff=False) mainmenu.add_command(label='Opties / Standaardthesauri', command=self.showOptions) mainmenu.add_command(label='Over erfgoedstats', command=self.showAbout) mainmenu.add_separator() mainmenu.add_command(label='Afsluiten', command=self.quit) self.menu.add_cascade(label='Bestand', menu=mainmenu) parent.config(menu=self.menu) self.parent.protocol("WM_DELETE_WINDOW", self.quit) # Kies museum naam self.museumnaamFrame = Frame(self.frame) self.museumnaamFrame.pack(pady=5, fill=X, expand=1) font = tkFont.Font(weight="bold") museumnaamLabel = Label(self.museumnaamFrame, text="Naam collectie: ", font=font, anchor=W) museumnaamLabel.pack(side=LEFT, pady=15) self.museumnaamField = Entry(self.museumnaamFrame) self.museumnaamField.pack(side=LEFT, fill=X, expand=1) ## Input files ## font = tkFont.Font(weight="bold") inputsLabel = Label(self.frame, text="Input bestanden: ", anchor=W, font=font) inputsLabel.pack(pady=5, fill=X, expand=1) self.inputFilesTable = InputFileTable(self.frame, nameColumn=False,settings=self.settings, tabletype="objects") self.inputFilesTable.setAvailableTypes( settings.inputfile_types ) # Set default input rows self.inputFilesTable.addRow(name="Objecten", filetype='Adlib XML Objecten') self.inputFilesTable.addRow(name="Thesaurus", filetype='Adlib XML Thesaurus') self.inputFilesTable.addRow(name="Personen", filetype='Adlib XML Personen') # Input file toevoegen knop img = PhotoImage(master=parent, data=resources.ButtonIcons_base64.add,format="gif89") self.addimg = img self.addRowButton = Button(self.frame, image=img, text="Bestand toevoegen", compound=LEFT, command=self.addInputRow) self.addRowButton.pack(pady=5) # Kies output file self.outputFrame = Frame(self.frame) self.outputFrame.pack(pady=5, fill=X, expand=1) font = tkFont.Font(weight="bold") outputLabel = Label(self.outputFrame, text="Output: ", anchor=W, font=font) outputLabel.pack(side=LEFT) self.outputField = Entry(self.outputFrame) self.outputButton = Button(self.outputFrame, text="Bladeren", command=self.browseOutputFile) self.outputField.pack(side=LEFT, fill=X, expand=1) self.outputButton.pack(side=RIGHT, padx=5) # Vergelijk met thesauri optie self.frame4 = Frame(self.frame) self.frame4.pack(pady=10, fill=X, expand=1) self.checkThesaurus = IntVar() self.checkb = Checkbutton(self.frame4, variable=self.checkThesaurus) self.updateThesauriCheckbox() self.checkb.pack(side=LEFT, padx=5) ## Start button ## self.startButton = Button(self.frame, text="Start", command=self.start) self.startButton.pack(side=BOTTOM) utils.centerWindow(self.parent)
def __init__(self, mainWindow): Toplevel.__init__(self, mainWindow.parent, takefocus=True) self.transient(mainWindow.parent) self.mainWindow = mainWindow self.protocol("WM_DELETE_WINDOW", self.cancelPressed) #self.window.wm_attributes("-topmost", True) # This option does not play well with ttk comboboxes self.title('Instellingen') self.grab_set() self.frame = Frame(self) self.frame.pack(fill=BOTH, expand=1, padx=10, pady=10) font = tkFont.Font(weight="bold") label = Label(self.frame, text='Standaard (referentie) thesauri: ', anchor=W, font=font) label.pack(pady=5, fill=X, expand=1) # Create an input file table for specifying the thesauri and add configured thesauri to it self.thesauriTable = InputFileTable(self.frame,settings=mainWindow.settings) self.thesauriTable.setAvailableTypes(thesaurus_types) settings = mainWindow.settings settings.validate() self.thesauriTable.addRows(settings.thesauri) if settings.thesauri.size() == 0: # Add an empty row to GUI if no thesauri are configured, as a visual cue of what the purpose of this menu is self.thesauriTable.addRow() # Input file toevoegen knop self.addimg = PhotoImage(data=resources.ButtonIcons_base64.add, format="gif89") self.addRowButton = Button(self.frame, text="Thesaurus toevoegen", image=self.addimg, compound=LEFT, command=self.thesauriTable.addRow) self.addRowButton.pack(pady=5) # Description label descrLabel = Label(self.frame, text="De volgorde van de thesauri in deze tabel bepaalt hun belangrijkheid.\nDe bovenste thesaurus is het meest belangrijk.", anchor=W) descrLabel.config(justify=LEFT) descrLabel.pack(pady=5, fill=X, expand=1) # Detail self.detailFrame = Frame(self.frame) self.detailFrame.pack(pady=5, fill=X, expand=1) font = tkFont.Font(weight="bold") detailLabel = Label(self.detailFrame, text="Maximum aantal unieke waardes voor detail: ", anchor=W, font=font) detailLabel.pack(side=LEFT) self.detailField = Entry(self.detailFrame) self.detailField.pack(side=LEFT, fill=X, expand=1) try: self.detailField.insert(0, str(settings.maxUniqueValues)) except: self.detailField.insert(0, str(DEFAULT_MAX_DETAIL)) detaildescrLabel = Label(self.frame, text="Indien er meer unieke waardes voor een bepaald veld zijn dan het getal hierboven, wordt geen detail meer getoond.\nEen hoger maximum geeft een gedetailleerder (maar groter) rapport.\nVoor het genereren/bekijken van een groot rapport is een krachtige computer nodig.", anchor=W) detaildescrLabel.config(justify=LEFT) detaildescrLabel.pack(pady=5, fill=X, expand=1) # Add Ok and Cancel buttons buttonsFrame = Frame(self.frame) buttonsFrame.pack() buttonsFrame.pack(fill=X, expand=1) okButton = Button(buttonsFrame, text="Ok", command=self.okPressed) okButton.pack(side=RIGHT) cancelButton = Button(buttonsFrame, text="Annuleren", command=self.cancelPressed) cancelButton.pack(side=RIGHT, padx=5) self.bind("<Escape>", self.cancelPressed) # Focus and center utils.centerWindow(self) self.focus_set()
class MainWindow: def __init__(self, parent): import resources.logo_packed self.parent = parent self.settings = self.loadConfiguration() self.frame = Frame(parent) self.frame.pack(padx=10, pady=10, fill=X, expand=1) # Menu self.menu = Menu(parent) mainmenu = Menu(self.menu, tearoff=False) mainmenu.add_command(label='Opties / Standaardthesauri', command=self.showOptions) mainmenu.add_command(label='Over erfgoedstats', command=self.showAbout) mainmenu.add_separator() mainmenu.add_command(label='Afsluiten', command=self.quit) self.menu.add_cascade(label='Bestand', menu=mainmenu) parent.config(menu=self.menu) self.parent.protocol("WM_DELETE_WINDOW", self.quit) # Kies museum naam self.museumnaamFrame = Frame(self.frame) self.museumnaamFrame.pack(pady=5, fill=X, expand=1) font = tkFont.Font(weight="bold") museumnaamLabel = Label(self.museumnaamFrame, text="Naam collectie: ", font=font, anchor=W) museumnaamLabel.pack(side=LEFT, pady=15) self.museumnaamField = Entry(self.museumnaamFrame) self.museumnaamField.pack(side=LEFT, fill=X, expand=1) ## Input files ## font = tkFont.Font(weight="bold") inputsLabel = Label(self.frame, text="Input bestanden: ", anchor=W, font=font) inputsLabel.pack(pady=5, fill=X, expand=1) self.inputFilesTable = InputFileTable(self.frame, nameColumn=False,settings=self.settings, tabletype="objects") self.inputFilesTable.setAvailableTypes( settings.inputfile_types ) # Set default input rows self.inputFilesTable.addRow(name="Objecten", filetype='Adlib XML Objecten') self.inputFilesTable.addRow(name="Thesaurus", filetype='Adlib XML Thesaurus') self.inputFilesTable.addRow(name="Personen", filetype='Adlib XML Personen') # Input file toevoegen knop img = PhotoImage(master=parent, data=resources.ButtonIcons_base64.add,format="gif89") self.addimg = img self.addRowButton = Button(self.frame, image=img, text="Bestand toevoegen", compound=LEFT, command=self.addInputRow) self.addRowButton.pack(pady=5) # Kies output file self.outputFrame = Frame(self.frame) self.outputFrame.pack(pady=5, fill=X, expand=1) font = tkFont.Font(weight="bold") outputLabel = Label(self.outputFrame, text="Output: ", anchor=W, font=font) outputLabel.pack(side=LEFT) self.outputField = Entry(self.outputFrame) self.outputButton = Button(self.outputFrame, text="Bladeren", command=self.browseOutputFile) self.outputField.pack(side=LEFT, fill=X, expand=1) self.outputButton.pack(side=RIGHT, padx=5) # Vergelijk met thesauri optie self.frame4 = Frame(self.frame) self.frame4.pack(pady=10, fill=X, expand=1) self.checkThesaurus = IntVar() self.checkb = Checkbutton(self.frame4, variable=self.checkThesaurus) self.updateThesauriCheckbox() self.checkb.pack(side=LEFT, padx=5) ## Start button ## self.startButton = Button(self.frame, text="Start", command=self.start) self.startButton.pack(side=BOTTOM) utils.centerWindow(self.parent) def addInputRow(self): self.inputFilesTable.addRow() def browseOutputFile(self): defaultDir = self.settings.getPath("output") filename = tkFileDialog.asksaveasfilename(title="Waar wilt u het resultaat opslaan?", filetypes=[("HTML bestand", "*.html")], defaultextension=".html", initialdir=defaultDir) # Remove current text and replace with selected filename self.outputField.delete(0, END) self.outputField.insert(0, filename) self.settings.setPath("output",os.path.dirname(filename)) def showOptions(self): s = SettingsDialog(self) s.show() def showAbout(self): import aboutdialog a = aboutdialog.AboutDialog(self) a.show() def start(self): museumName = self.museumnaamField.get() museumName = utils.ensureUnicode(museumName) if not museumName.strip(): tkMessageBox.showerror('Geen naam voor de collectie opgegeven', 'Vul de naam van de collectie in, aub.'); return outputFile = self.outputField.get() if not isValidOutputFile(outputFile): tkMessageBox.showerror('Fout bij het starten', 'Kon niet starten omdat er geen correct "Output" bestand is opgegeven.'); return if os.path.exists(outputFile): doOverwrite = tkMessageBox.askyesno('Bestand overschrijven?', 'Het gekozen "Output" bestand bestaat reeds. Wilt u verder gaan en het overschrijven?') if not doOverwrite: return try: waitDialog = WaitDialog(self.parent) utils.setMaxDetail(self.settings.maxUniqueValues) # Will only return input files with valid files and names filled in inputFiles = self.inputFilesTable.getValues() if inputFiles.size() == 0: waitDialog.close() tkMessageBox.showerror('Fout bij het starten', u'Kon niet starten omdat er geen geldige "Input" bestanden zijn opgegeven.\nEr is minstens één input bestand met ingevulde naam, type en bestandslocatie vereist.'); return if self.checkb["state"] != DISABLED and self.checkThesaurus.get(): checkThesaurus = True else: checkThesaurus = False # Set configured reference thesauri err = None if (checkThesaurus): referenceThesauri = self.settings.thesauri err = setCustomThesauri(referenceThesauri) else: err = setCustomThesauri(TEntries()) if (not (err is None)): waitDialog.close() tkMessageBox.showerror('Fout bij het starten', err); return # Set specified input files to analyse objects = [] thesauri = [] fieldstats = [] csvfieldstats = [] inputFiles.sort() for entry in inputFiles.values: utils.s("%s - %s - %s\n" % (entry.name, entry.type, entry.path)) if entry.type == 'Adlib XML Objecten': objects.append(entry.path) elif entry.type == 'XML Fieldstats' or entry.type == "Adlib XML Personen": fieldstats.append(entry.path) elif entry.type == 'CSV Fieldstats': csvfieldstats.append(entry.path) elif entry.type == 'Adlib XML Thesaurus': thesauri.append(entry.path) else: print "ERROR: Input bestand %s met type %s kan niet gebruikt worden" % (entry.name, entry.type) generateReport(museumName, objects, thesauri, fieldstats, csvfieldstats, outputFile, False) except Exception, e: waitDialog.close() stacktrace = traceback.format_exc() print "exception ..." print stacktrace print "done" ExceptionDialog(self.parent, e, stacktrace) return waitDialog.close() showHtml = tkMessageBox.askyesno('Verwerking voltooid', 'De verwerking van de gegevens is gelukt. Wilt u het resultaat bekijken?') if showHtml: webbrowser.open(outputFile) return