Example #1
0
 def save(self,filename=""):
   if not self._excel:
     return
   
   if self._options['commas']:
     self._excel = self._excel.replace(".",",")
 
   if not filename:
     filename = ctx.type() + "-" + datetime.date.today().strftime("%Y-%m-%d")
   file = MLABFileDialog.getSaveFileName(MLABFileManager.getHomeDir() + "/" + filename + ".csv","Excel files (*.csv)","Save file")
   if file:
     MLABFileManager.writeStringToFile(file,self._excel)
Example #2
0
def _executeScript(script):
  tmp = MLABFileManager.getTmpDir()
  if not tmp[-1] == "/":
    tmp += "/"
  now = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
  
  file = MLABFileManager.getUniqueFilename(tmp,now,".scp")
  MLABFileManager.writeStringToFile(file,script)
  
  winscp = ctx.expandFilename("$(LOCAL)/winscp416.exe")
  
  cmd = "\"" + winscp + "\" /script=\"" + file + "\""
  
  proc = MLAB.newProcess()
  proc.addArgument(cmd)
  proc.setStdOutHandler(ctx,"_procStdOut")
  proc.setStdErrHandler(ctx,"_procStdErr")
  proc.setExitedHandler(ctx,"_procFinished")
  
  global _processes
  _processes[proc] = file
  
  proc.run()
Example #3
0
def _executeScript(script):
  tmp = MLABFileManager.getTmpDir()
  if not tmp[-1] == "/":
    tmp += "/"
  now = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
  
  file = MLABFileManager.getUniqueFilename(tmp,now,".scp")
  MLABFileManager.writeStringToFile(file,script)
  
  winscp = ctx.expandFilename("$(LOCAL)/winscp416.exe")
  
  cmd = "\"" + winscp + "\" /script=\"" + file + "\""
  
  proc = MLAB.newProcess()
  proc.addArgument(cmd)
  proc.setStdOutHandler(ctx,"_procStdOut")
  proc.setStdErrHandler(ctx,"_procStdErr")
  proc.setExitedHandler(ctx,"_procFinished")
  
  global _processes
  _processes[proc] = file
  
  proc.run()
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)
Example #5
0
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)