def scribusLoadSettingsHandler(self): slaFile = self.__scribusSourceFileEntryVariable.get() if(slaFile is CONST.EMPTY): tkMessageBox.showinfo( 'Choose a file', message="Set a valid scribus input file prior to loading its settings.") return dataObject = GeneratorDataObject( scribusSourceFile=slaFile ) generator = ScribusGenerator(dataObject) saved = generator.getSavedSettings() if (saved): dataObject.loadFromString(saved) # self.__scribusSourceFileEntryVariable = StringVar() #not loaded self.__dataSourceFileEntryVariable.set( dataObject.getDataSourceFile()) self.__dataSeparatorEntryVariable.set(dataObject.getCsvSeparator()) self.__outputDirectoryEntryVariable.set( dataObject.getOutputDirectory()) self.__outputFileNameEntryVariable.set( dataObject.getOutputFileName()) self.__selectedOutputFormat.set(dataObject.getOutputFormat()) self.__keepGeneratedScribusFilesCheckboxVariable.set( dataObject.getKeepGeneratedScribusFiles()) self.__mergeOutputCheckboxVariable.set( dataObject.getSingleOutput()) # self.__saveCheckboxVariable = IntVar() #not loaded self.__fromVariable.set(dataObject.getFirstRow()) self.__toVariable.set(dataObject.getLastRow()) self.__closeDialogVariable.set(dataObject.getCloseDialog()) else: tkMessageBox.showinfo( 'No Settings', message="Input scribus file contains no former saved settings.")
def buttonOkHandler(self): if (CONST.TRUE == self.allValuesSet()): dataObject = self.createGeneratorDataObject() generator = ScribusGenerator(dataObject) try: generator.run() if(dataObject.getCloseDialog()): self.__root.destroy() else: tkMessageBox.showinfo('Scribus Generator', message='Done. Generated files are in '+dataObject.getOutputDirectory()) except IOError as e: # except FileNotFoundError as e: tkMessageBox.showerror( title='File Not Found', message="Could not find some input file, please verify your Scribus and Data file settings:\n\n %s" % e) except ValueError as e: tkMessageBox.showerror( title='Variable Error', message="Could likely not replace a variable with its value,\nplease check your Data File and Data Separator settings:\n\n %s" % e) except IndexError as e: tkMessageBox.showerror( title='Variable Error', message="Could not find the value for one variable.\nplease check your Data File and Data Separator settings.\n\n %s" % e) except Exception: tkMessageBox.showerror(title='Error Scribus Generator', message="Something went wrong.\n\nRead the log file for more (in your home directory)."+traceback.format_exc()) else: tkMessageBox.showerror( title='Validation failed', message='Please check if all settings have been set correctly!')
# generate # Collect the settings made and build the Data Object dataObject = GeneratorDataObject( dataSourceFile=ife(not (args.csvFile is None), args.csvFile, CONST.EMPTY), outputDirectory=ife(not (args.outDir is None), args.outDir, CONST.EMPTY), outputFileName=args.outName, # is CONST.EMPTY by default outputFormat=ife(args.fast, CONST.FORMAT_SLA, CONST.FORMAT_PDF), keepGeneratedScribusFiles=ife(args.pdfOnly, CONST.FALSE, CONST.TRUE), # not used if outputFormat is sla. csvSeparator=args.csvDelimiter, # is CONST.CSV_SEP by default singleOutput=args.single, firstRow=args.firstRow, lastRow=args.lastRow, ) generator = ScribusGenerator(dataObject) log = generator.getLog() log.debug("ScribusGenerator is starting generation for " + str(len(args.infiles)) + " template(s).") for infile in args.infiles: dataObject.setScribusSourceFile(infile) if args.csvFile is None: # default data file is template-sla+csv dataObject.setDataSourceFile(os.path.splitext(infile)[0] + ".csv") if not (os.path.exists(dataObject.getDataSourceFile()) and os.path.isfile(dataObject.getDataSourceFile())): log.info( "found no data file for " + os.path.split(infile)[1] + ". skipped. was looking for " + dataObject.getDataSourceFile() ) continue # skip current template for lack of matching data.
# Collect the settings made and build the Data Object dataObject = GeneratorDataObject( dataSourceFile=ife(not (args.csvFile is None), args.csvFile, CONST.EMPTY), outputDirectory=ife(not (args.outDir is None), args.outDir, CONST.EMPTY), outputFileName=args.outName, # is CONST.EMPTY by default outputFormat=CONST. FORMAT_SLA, # ife(args.fast, CONST.FORMAT_SLA, CONST.FORMAT_PDF), keepGeneratedScribusFiles=CONST. TRUE, # ife(args.pdfOnly, CONST.FALSE, CONST.TRUE), # not used if outputFormat is sla. csvSeparator=args.csvDelimiter, # is CONST.CSV_SEP by default singleOutput=args.merge, firstRow=args.firstRow, lastRow=args.lastRow, saveSettings=args.save) generator = ScribusGenerator(dataObject) log = generator.getLog() log.debug("ScribusGenerator is starting generation for %s template(s)." % (str(len(args.infiles)))) for infile in args.infiles: dataObject.setScribusSourceFile(infile) if (args.load): saved = generator.getSavedSettings() if (saved): dataObject.loadFromString(saved) log.info("settings loaded from %s:" % (os.path.split(infile)[1])) else: log.warning( "could not load settings from %s. using arguments and defaults instead"