예제 #1
0
def OpenRoboFontProject(path):
    root = os.path.dirname(path)
    project = readPlist(path)

    documentController = NSDocumentController.sharedDocumentController()
    delegate = NSApp().delegate()

    openFileNames = [window.representedFilename() for window in NSApp().windows()]

    for fileName, data in project["documents"].items():

        isUntitled = fileName == "untitled"

        if not isUntitled:
            if not os.path.exists(fileName):
                fileName = os.path.abspath(os.path.join(root, fileName))

            if not os.path.exists(fileName):
                continue

            if fileName in openFileNames:
                continue

        data.sort(key=lambda item: item.get("name") != "FontWindow")

        for windowData in data:
            name = windowData["windowName"]
            x, y, w, h = windowData["frame"]

            if isUntitled:
                if name == "FontWindow":
                    RFont()
                elif name == "ScriptingWindow":
                    delegate.scriptingWindow_(None)
                elif name == "FeatureWindow":
                    delegate.newFeature_(None)

            else:
                url = NSURL.fileURLWithPath_(fileName)
                doc, error = documentController.openDocumentWithContentsOfURL_display_error_(url, True, None)
                if error:
                    delegate.application_openFile_(NSApp(), fileName)

            window = NSApp().mainWindow()

            vanillaWrapper = None
            if hasattr(window.delegate(), "vanillaWrapper"):
                vanillaWrapper = window.delegate().vanillaWrapper()

            if vanillaWrapper:
                font = CurrentFont()
                if name == "GlyphWindow":
                    window = OpenGlyphWindow(font[windowData["glyphName"]], newWindow=True)
                    window.w.getNSWindow().setFrame_display_animate_(((x, y), (w, h)), True, False)
                    continue

                elif name == "SpaceCenter":
                    spaceCenter = OpenSpaceCenter(font)
                    spaceCenter.setPointSize(windowData["pointSize"])
                    spaceCenter.setPre(windowData["pre"])
                    spaceCenter.setAfter(windowData["after"])
                    spaceCenter.set(windowData["input"])

                    window = CurrentSpaceCenterWindow()
                    window.w.getNSWindow().setFrame_display_animate_(((x, y), (w, h)), True, False)
                    continue

            window.setFrame_display_animate_(((x, y), (w, h)), True, False)

    for windowData in project["toolWindows"]:
        name = windowData["windowName"]
        x, y, w, h = windowData["frame"]

        if name == "DebugWindow":
            window = OutputWindow()
            window.show()
            window.w.getNSWindow().setFrame_display_animate_(((x, y), (w, h)), True, False)

        elif name == "InspectorWindow":
            try:
                # a little bit hacky
                # will move to mojo.UI in the upcoming releases
                window = delegate._inspectorWindow.w.getNSWindow()
            except:
                window = None
            if window is None:
                delegate.openInspector_(None)
                window = delegate._inspectorWindow.w.getNSWindow()
            window.setFrame_display_animate_(((x, y), (w, h)), True, False)

    if "execute" in project:
        try:
            ScriptRunner(text=project["execute"])
        except:
            import traceback
            print traceback.format_exc(5)