def selectPresentation(field=None): presentation = ctx.field("presentation").stringValue() header = "" footer = "" module = "" style = "" if presentation: config = MLABFileManager.readStringFromFile(_presentations[presentation] + "config").split("\n") for line in config: parts = line.split("=") if not len(parts) == 2: continue tag = parts[0].strip() value = parts[1].strip() if tag == "HEADER": header = value elif tag == "FOOTER": footer = value elif tag == "STYLE": if _styles.has_key(value): style = value elif tag == "MODULE": module = value ctx.field("header").setStringValue(header) ctx.field("footer").setStringValue(footer) ctx.field("module").setStringValue(module) ctx.field("style").setStringValue(style) selectStyle()
def selectPresentation(field=None): presentation = ctx.field("presentation").stringValue() header = "" footer = "" module = "" style = "" if presentation: config = MLABFileManager.readStringFromFile( _presentations[presentation] + "config").split("\n") for line in config: parts = line.split("=") if not len(parts) == 2: continue tag = parts[0].strip() value = parts[1].strip() if tag == "HEADER": header = value elif tag == "FOOTER": footer = value elif tag == "STYLE": if _styles.has_key(value): style = value elif tag == "MODULE": module = value ctx.field("header").setStringValue(header) ctx.field("footer").setStringValue(footer) ctx.field("module").setStringValue(module) ctx.field("style").setStringValue(style) selectStyle()
def buildPresentation(): #set style style = ctx.field("style").stringValue() # check/delete module path localPath = ctx.localPath() + "/" stylePath = localPath + "Styles/" + style contentPath = localPath + "Presentations/" + ctx.field("presentation").stringValue() moduleName = ctx.field("module").stringValue() modulePath = localPath + "/Generated/" + moduleName # create directories MLABFileManager.mkdir(modulePath) MLABFileManager.mkdir(modulePath + "/style") MLABFileManager.mkdir(modulePath + "/data") MLABFileManager.mkdir(modulePath + "/macros") MLABFileManager.mkdir(modulePath + "/scripts") slashRe = re.compile('(.*?)[\/]{3,}',re.DOTALL) #parse style.script global _styleTags _styleTags = {} if MLABFileManager.exists(stylePath + "/tags"): tagRe = re.compile('\[(.*?)\]\s*=\s*(.*)',re.DOTALL) content = MLABFileManager.readStringFromFile(stylePath + "/tags") matches = slashRe.findall(content) for styleTag in matches: if styleTag == "": continue tagMatches = tagRe.findall(styleTag) _styleTags[tagMatches[0][0]] = tagMatches[0][1] # generate content: slides global _slideBullets _slideBullets = {} global _slideNames _slideNames = [] global _slideModules _slideModules = {} slides = "" if MLABFileManager.exists(contentPath + "/slides"): content = MLABFileManager.readStringFromFile(contentPath + "/slides") matches = slashRe.findall(content) count = 0 for slide in matches: if slide == "": continue result = parseSlide(slide,count+1) if not result == "": count += 1 slides += result # generate content: menu menu = "" if MLABFileManager.exists(contentPath + "/menu"): content = MLABFileManager.readStringFromFile(contentPath + "/menu") menuRe = re.compile('(.*?)[\/]+',re.DOTALL) matches = menuRe.findall(content) for menuItem in matches: if menuItem == "": continue menu += parseMenuItem(menuItem) # generate def file defFile = "MacroModule " + moduleName + " { externalDefinition = $(LOCAL)/" + moduleName + ".script }" MLABFileManager.writeStringToFile(modulePath + "/" + moduleName + ".def",defFile) # copy py file MLABFileManager.copy(localPath + "template_py",modulePath + "/" + moduleName + ".py") # load styles styleFile = MLABFileManager.readStringFromFile(stylePath + "/style") styleRe = re.compile('DefineStyle\s*(.*?)\s*\{(.*?)[\/]{3,}',re.DOTALL) styles = styleRe.findall(styleFile) # process slideBullets for i in range(len(styles)): styleName = styles[i][0].strip() styleDef = styles[i][1].strip() for k,v in _slideBullets.iteritems(): for i in range(len(v)): _slideBullets[k][i] = _slideBullets[k][i].replace("style = " + styleName,"style { " + styleDef) _slideBullets[k][i] = _slideBullets[k][i].replace("\n"," ") sources = "" # write slideBullets file if len(_slideBullets): bulletFile = "_bullets = {\n" num = 0 for k,v in _slideBullets.iteritems(): if num > 0: bulletFile += "," bulletFile += "'" + `k` + "':['" + "','".join(v) + "']\n" num = num + 1 bulletFile += "}" sources += "source = $(LOCAL)/scripts/bullets.py\n" MLABFileManager.writeStringToFile(modulePath + "/scripts/bullets.py",bulletFile) # process script file -> replace content tags scriptFile = MLABFileManager.readStringFromFile(stylePath + "/template") scriptFile = scriptFile.replace("template.py",moduleName + ".py") files = MLABFileManager.recursiveContentOfDirectory(contentPath + "/scripts") for file in files: if not file == "": sources += "source = $(LOCAL)/scripts/" + file.strip() + "\n" # print sources if not sources == "": scriptFile = scriptFile.replace("Commands {","Commands {\n" + sources) scriptFile = scriptFile.replace("[HEADER]","\"" + ctx.field("header").stringValue() + "\"") scriptFile = scriptFile.replace("[FOOTER]","\"" + ctx.field("footer").stringValue() + "\"") scriptFile = scriptFile.replace("[MENU]",menu) scriptFile = scriptFile.replace("[SLIDES]",slides) # process script file -> replace style tags for i in range(len(styles)): styleName = styles[i][0].strip() style = styles[i][1].strip() scriptFile = scriptFile.replace("style = " + styleName,"style { " + style) # write script file MLABFileManager.writeStringToFile(modulePath + "/" + moduleName + ".script",scriptFile) # copy style data from stylePath styleDataPath = stylePath + "/data/" if MLABFileManager.exists(styleDataPath): files = MLABFileManager.recursiveContentOfDirectory(styleDataPath) for file in files: if MLABFileManager.isDir(styleDataPath + file): MLABFileManager.mkdir(modulePath + "/style/" + file) else: MLABFileManager.copy(styleDataPath + file,modulePath + "/style/" + file) else: print(styleDataPath) # write .mlab file for module # write .def and .script files for used modules mlabFile = "//MDL v1 utf8\n network {\n watchlist = \"\"\n}\n" for k,v in _slideModules.iteritems(): macro = k.strip() mlabFile += "module " + macro + " {\n fields {\n instanceName = " + macro + "\n }\n internalFields = \"\"\n}\n" defFile = "MacroModule " + macro + " { externalDefinition = $(LOCAL)/" + macro + ".script }" scriptFile = "Interface { Inputs {} Outputs {} Parameters {} } Commands { }" MLABFileManager.writeStringToFile(modulePath + "/macros/" + macro + ".def",defFile) MLABFileManager.writeStringToFile(modulePath + "/macros/" + macro + ".script",scriptFile) mlabFile += "connections = \"\"\n" MLABFileManager.writeStringToFile(modulePath + "/" + moduleName + ".mlab",mlabFile) # copy data, macros, networks, scripts, etc from contentPath files = MLABFileManager.recursiveContentOfDirectory(contentPath) extRE = re.compile('(\.dcm|\.tiff|\.tif|\.avi)') for file in files: if file == "slides": continue if file == "menu": continue if file == "config": continue if MLABFileManager.isDir(contentPath + "/" + file): if not MLABFileManager.exists(modulePath + "/" + file): MLABFileManager.mkdir(modulePath + "/" + file) else: if not MLABFileManager.exists(modulePath + "/" + file): MLABFileManager.copy(contentPath + "/" + file,modulePath + "/" + file) else: if not len(extRE.findall(file)): MLABFileManager.copy(contentPath + "/" + file,modulePath + "/" + file)
def buildPresentation(): #set style style = ctx.field("style").stringValue() # check/delete module path localPath = ctx.localPath() + "/" stylePath = localPath + "Styles/" + style contentPath = localPath + "Presentations/" + ctx.field( "presentation").stringValue() moduleName = ctx.field("module").stringValue() modulePath = localPath + "/Generated/" + moduleName # create directories MLABFileManager.mkdir(modulePath) MLABFileManager.mkdir(modulePath + "/style") MLABFileManager.mkdir(modulePath + "/data") MLABFileManager.mkdir(modulePath + "/macros") MLABFileManager.mkdir(modulePath + "/scripts") slashRe = re.compile('(.*?)[\/]{3,}', re.DOTALL) #parse style.script global _styleTags _styleTags = {} if MLABFileManager.exists(stylePath + "/tags"): tagRe = re.compile('\[(.*?)\]\s*=\s*(.*)', re.DOTALL) content = MLABFileManager.readStringFromFile(stylePath + "/tags") matches = slashRe.findall(content) for styleTag in matches: if styleTag == "": continue tagMatches = tagRe.findall(styleTag) _styleTags[tagMatches[0][0]] = tagMatches[0][1] # generate content: slides global _slideBullets _slideBullets = {} global _slideNames _slideNames = [] global _slideModules _slideModules = {} slides = "" if MLABFileManager.exists(contentPath + "/slides"): content = MLABFileManager.readStringFromFile(contentPath + "/slides") matches = slashRe.findall(content) count = 0 for slide in matches: if slide == "": continue result = parseSlide(slide, count + 1) if not result == "": count += 1 slides += result # generate content: menu menu = "" if MLABFileManager.exists(contentPath + "/menu"): content = MLABFileManager.readStringFromFile(contentPath + "/menu") menuRe = re.compile('(.*?)[\/]+', re.DOTALL) matches = menuRe.findall(content) for menuItem in matches: if menuItem == "": continue menu += parseMenuItem(menuItem) # generate def file defFile = "MacroModule " + moduleName + " { externalDefinition = $(LOCAL)/" + moduleName + ".script }" MLABFileManager.writeStringToFile(modulePath + "/" + moduleName + ".def", defFile) # copy py file MLABFileManager.copy(localPath + "template_py", modulePath + "/" + moduleName + ".py") # load styles styleFile = MLABFileManager.readStringFromFile(stylePath + "/style") styleRe = re.compile('DefineStyle\s*(.*?)\s*\{(.*?)[\/]{3,}', re.DOTALL) styles = styleRe.findall(styleFile) # process slideBullets for i in range(len(styles)): styleName = styles[i][0].strip() styleDef = styles[i][1].strip() for k, v in _slideBullets.iteritems(): for i in range(len(v)): _slideBullets[k][i] = _slideBullets[k][i].replace( "style = " + styleName, "style { " + styleDef) _slideBullets[k][i] = _slideBullets[k][i].replace("\n", " ") sources = "" # write slideBullets file if len(_slideBullets): bulletFile = "_bullets = {\n" num = 0 for k, v in _slideBullets.iteritems(): if num > 0: bulletFile += "," bulletFile += "'" + ` k ` + "':['" + "','".join(v) + "']\n" num = num + 1 bulletFile += "}" sources += "source = $(LOCAL)/scripts/bullets.py\n" MLABFileManager.writeStringToFile(modulePath + "/scripts/bullets.py", bulletFile) # process script file -> replace content tags scriptFile = MLABFileManager.readStringFromFile(stylePath + "/template") scriptFile = scriptFile.replace("template.py", moduleName + ".py") files = MLABFileManager.recursiveContentOfDirectory(contentPath + "/scripts") for file in files: if not file == "": sources += "source = $(LOCAL)/scripts/" + file.strip() + "\n" # print sources if not sources == "": scriptFile = scriptFile.replace("Commands {", "Commands {\n" + sources) scriptFile = scriptFile.replace( "[HEADER]", "\"" + ctx.field("header").stringValue() + "\"") scriptFile = scriptFile.replace( "[FOOTER]", "\"" + ctx.field("footer").stringValue() + "\"") scriptFile = scriptFile.replace("[MENU]", menu) scriptFile = scriptFile.replace("[SLIDES]", slides) # process script file -> replace style tags for i in range(len(styles)): styleName = styles[i][0].strip() style = styles[i][1].strip() scriptFile = scriptFile.replace("style = " + styleName, "style { " + style) # write script file MLABFileManager.writeStringToFile( modulePath + "/" + moduleName + ".script", scriptFile) # copy style data from stylePath styleDataPath = stylePath + "/data/" if MLABFileManager.exists(styleDataPath): files = MLABFileManager.recursiveContentOfDirectory(styleDataPath) for file in files: if MLABFileManager.isDir(styleDataPath + file): MLABFileManager.mkdir(modulePath + "/style/" + file) else: MLABFileManager.copy(styleDataPath + file, modulePath + "/style/" + file) else: print(styleDataPath) # write .mlab file for module # write .def and .script files for used modules mlabFile = "//MDL v1 utf8\n network {\n watchlist = \"\"\n}\n" for k, v in _slideModules.iteritems(): macro = k.strip() mlabFile += "module " + macro + " {\n fields {\n instanceName = " + macro + "\n }\n internalFields = \"\"\n}\n" defFile = "MacroModule " + macro + " { externalDefinition = $(LOCAL)/" + macro + ".script }" scriptFile = "Interface { Inputs {} Outputs {} Parameters {} } Commands { }" MLABFileManager.writeStringToFile( modulePath + "/macros/" + macro + ".def", defFile) MLABFileManager.writeStringToFile( modulePath + "/macros/" + macro + ".script", scriptFile) mlabFile += "connections = \"\"\n" MLABFileManager.writeStringToFile(modulePath + "/" + moduleName + ".mlab", mlabFile) # copy data, macros, networks, scripts, etc from contentPath files = MLABFileManager.recursiveContentOfDirectory(contentPath) extRE = re.compile('(\.dcm|\.tiff|\.tif|\.avi)') for file in files: if file == "slides": continue if file == "menu": continue if file == "config": continue if MLABFileManager.isDir(contentPath + "/" + file): if not MLABFileManager.exists(modulePath + "/" + file): MLABFileManager.mkdir(modulePath + "/" + file) else: if not MLABFileManager.exists(modulePath + "/" + file): MLABFileManager.copy(contentPath + "/" + file, modulePath + "/" + file) else: if not len(extRE.findall(file)): MLABFileManager.copy(contentPath + "/" + file, modulePath + "/" + file)