#!/usr/bin/env python # -*- coding: utf-8 -*- import sys import os try: import scribus except ImportError: print("This Python script is written for the Scribus scripting interface.") print("It can only be run from within Scribus.") sys.exit(1) from scribus_calendar.config_parser import ConfigParser from scribus_calendar.calendars import MonthlyCalendar from scribus_calendar.monthly_objects import * from scribus_calendar.base_objects import UserDefinedObjects from feiertage_api import FeiertageApi from ferien_api import FerienApi def class_from_name(className): return globals()[className] def main(argv): objects = [] #compute config file path thisDir = os.getcwd() defaultConfigFile = scribus.fileDialog("calender config :: open file", "*.json") try: configParser = ConfigParser(defaultConfigFile) except Exception as e: raise Exception(defaultConfigFile) feiertageApi = FeiertageApi(configParser.settings["year"], configParser.settings["bundesland"]) ferienApi = FerienApi(configParser.settings["year"], configParser.settings["bundesland"]) configParser.addEvents(feiertageApi.get()) configParser.addEvents(ferienApi.get()) #create objects from config file strListModuleObjects = configParser.modules.keys() for module in strListModuleObjects: obj = class_from_name(module)() obj.configure(configParser) noglobal = getattr(obj, "noGlobal", False) if noglobal == False: objects.append(obj) #create calendar object from defined class in config calendar = class_from_name(configParser.settings["calendarClass"])(objects, configParser.settings["year"], configParser.settings["numMonths"]) calendar.createStyles() calendar.createLayers() if calendar.plotStubs(): scribus.messageBox('created objects','created objects. Please adjust its position and re-run script.' ,scribus.ICON_NONE, scribus.BUTTON_OK) return calendar.readFromStubs() calendar.plotObjects() def main_wrapper(argv): """The main_wrapper() function disables redrawing, sets a sensible generic status bar message, and optionally sets up the progress bar. It then runs the main() function. Once everything finishes it cleans up after the main() function, making sure everything is sane before the script terminates.""" try: scribus.statusMessage("Running script...") scribus.progressReset() main(argv) finally: # Exit neatly even if the script terminated with an exception, # so we leave the progress bar and status bar blank and make sure # drawing is enabled. if scribus.haveDoc(): scribus.setRedraw(True) scribus.statusMessage("") scribus.progressReset() # This code detects if the script is being run as a script, or imported as a module. # It only runs main() if being run as a script. This permits you to import your script # and control it manually for debugging. if __name__ == '__main__': main_wrapper(sys.argv)