예제 #1
0
class Save:
    def __init__(self, nodes, connections, exceptionSave=False):
        self.dlgOverwrite = None
        self.dlgOverwriteShadow = None
        self.jsonElements = JSONTools().get(nodes, connections)

        if exceptionSave:
            tmpPath = os.path.join(tempfile.gettempdir(),
                                   "NEExceptionSave.json")
            self.__executeSave(True, tmpPath)
            logging.info("Wrote crash session file to {}".format(tmpPath))
        else:
            self.browser = DirectFolderBrowser(self.save,
                                               True,
                                               defaultFilename="project.json")

    def save(self, doSave):
        if doSave:
            path = self.browser.get()
            path = os.path.expanduser(path)
            path = os.path.expandvars(path)
            if os.path.exists(path):
                self.dlgOverwrite = YesNoDialog(
                    text="File already Exist.\nOverwrite?",
                    relief=DGG.RIDGE,
                    frameColor=(1, 1, 1, 1),
                    frameSize=(-0.5, 0.5, -0.3, 0.2),
                    sortOrder=1,
                    button_relief=DGG.FLAT,
                    button_frameColor=(0.8, 0.8, 0.8, 1),
                    command=self.__executeSave,
                    extraArgs=[path],
                    scale=300,
                    pos=(base.getSize()[0] / 2, 0, -base.getSize()[1] / 2),
                    parent=base.pixel2d)
                self.dlgOverwriteShadow = DirectFrame(
                    pos=(base.getSize()[0] / 2 + 10, 0,
                         -base.getSize()[1] / 2 - 10),
                    sortOrder=0,
                    frameColor=(0, 0, 0, 0.5),
                    frameSize=self.dlgOverwrite.bounds,
                    scale=300,
                    parent=base.pixel2d)
                self.dlgOverwrite.setBin("gui-popup", 1)
            else:
                self.__executeSave(True, path)
            base.messenger.send("setLastPath", [path])
        self.browser.destroy()
        del self.browser

    def __executeSave(self, overwrite, path):
        if self.dlgOverwrite is not None: self.dlgOverwrite.destroy()
        if self.dlgOverwriteShadow is not None:
            self.dlgOverwriteShadow.destroy()
        if not overwrite: return

        with open(path, 'w') as outfile:
            json.dump(self.jsonElements, outfile, indent=2)
예제 #2
0
    def __init__(self, nodes, connections, exceptionSave=False):
        self.dlgOverwrite = None
        self.dlgOverwriteShadow = None
        self.jsonElements = JSONTools().get(nodes, connections)

        if exceptionSave:
            tmpPath = os.path.join(tempfile.gettempdir(),
                                   "NEExceptionSave.json")
            self.__executeSave(True, tmpPath)
            logging.info("Wrote crash session file to {}".format(tmpPath))
        else:
            self.browser = DirectFolderBrowser(self.save,
                                               True,
                                               defaultFilename="project.json")
예제 #3
0
def showBrowser(doLoad):
    dragFrame = DirectScrolledWindowFrame(parent=pixel2d,
                                          frameSize=(-250, 250, -200, 200),
                                          dragAreaHeight=25,
                                          pos=(260, 0, -300),
                                          closeButtonScale=20)

    def accept(ok):
        print(ok)
        dragFrame.destroy()

    DirectFolderBrowser(accept, doLoad, tooltip=tt, parent=dragFrame)
예제 #4
0
 def __init__(self, nodeMgr):
     self.nodeMgr = nodeMgr
     self.browser = DirectFolderBrowser(self.load,
                                        True,
                                        defaultFilename="project.json")
예제 #5
0
class Load:
    def __init__(self, nodeMgr):
        self.nodeMgr = nodeMgr
        self.browser = DirectFolderBrowser(self.load,
                                           True,
                                           defaultFilename="project.json")

    def load(self, doLoad):
        if doLoad:
            path = self.browser.get()
            path = os.path.expanduser(path)
            path = os.path.expandvars(path)

            self.__executeLoad(path)

        self.browser.destroy()
        del self.browser

    def __executeLoad(self, path):
        fileContent = None
        try:
            with open(path, 'r') as infile:
                fileContent = json.load(infile)
        except Exception as e:
            print("Couldn't load project file {}".format(path))
            print(e)
            return

        if fileContent is None:
            print("Problems reading file: {}".format(infile))
            return

        # 1. Create all nodes
        jsonNodes = fileContent["Nodes"]
        newNodes = []
        for jsonNode in jsonNodes:
            node = self.nodeMgr.createNode(jsonNode["type"])
            node.nodeID = UUID(jsonNode["id"])
            node.setPos(eval(jsonNode["pos"]))
            for i in range(len(jsonNode["inSockets"])):
                inSocket = jsonNode["inSockets"][i]
                node.inputList[i].socketID = UUID(inSocket["id"])
                if "value" in inSocket:
                    node.inputList[i].setValue(inSocket["value"])
            for i in range(len(jsonNode["outSockets"])):
                outSocket = jsonNode["outSockets"][i]
                node.outputList[i].socketID = UUID(outSocket["id"])
            node.show()
            newNodes.append(node)

        # 2. Connect all nodes
        jsonConnections = fileContent["Connections"]
        for jsonConnection in jsonConnections:
            # we have a connection of one of the to be copied nodes
            nodeA = None
            nodeB = None

            for node in newNodes:
                if node.nodeID == UUID(jsonConnection["nodeA_ID"]):
                    nodeA = node
                elif node.nodeID == UUID(jsonConnection["nodeB_ID"]):
                    nodeB = node

            socketA = None
            socketB = None
            for socket in nodeA.inputList + nodeA.outputList + nodeB.inputList + nodeB.outputList:
                if socket.socketID == UUID(jsonConnection["socketA_ID"]):
                    socketA = socket
                elif socket.socketID == UUID(jsonConnection["socketB_ID"]):
                    socketB = socket

            self.nodeMgr.connectPlugs(socketA, socketB)

        # 3. Run logic from all leave nodes down to the end
        self.nodeMgr.updateAllLeaveNodes()
예제 #6
0
from DirectFolderBrowser.DirectFolderBrowser import DirectFolderBrowser

from DirectFolderBrowser.DarkTheme import Theme as DarkTheme

loadPrcFileData("", "notify-level info")

app = ShowBase()


def callbackCommand(ok):
    if ok == 1:
        print("User Clicked OK")
        # print the selected file
        print(browser.get())
        browser.hide()
        browser.destroy()
        exit(ok)
    if ok == 0:
        print("User Clicked Cancel")
        browser.hide()
        browser.destroy()
        exit(ok)


# show the browser as file browser
browser = DirectFolderBrowser(callbackCommand,
                              fileBrowser=True,
                              theme=DarkTheme())

app.run()
    def __init__(self, command, headerText, actionText, affirmText, filePath,
                 tooltip):
        self.command = command
        self.darkenFrame = DirectFrame(
            relief=1,
            frameSize=(0, base.getSize()[0], -base.getSize()[1], 0),
            frameColor=(0, 0, 0, 0.45),
            state=DGG.NORMAL,
            parent=base.pixel2d,
        )
        self.mainFrame = DirectFrame(
            relief=1,
            frameSize=(-300, 300, -150, 150),
            frameColor=(1, 1, 1, 1),
            pos=LPoint3f(base.getSize()[0] / 2, 0, -base.getSize()[1] / 2),
            parent=base.pixel2d,
        )

        # Header
        headerFrame = DirectFrame(
            parent=self.mainFrame,
            relief=1,
            frameSize=(-300, 300, -20, 20),
            frameColor=(0.25, 0.25, 0.25, 1.0),
            pos=LPoint3f(0, 0, 130),
            scale=LVecBase3f(1, 0.1, 1),
        )
        DirectLabel(
            parent=headerFrame,
            frameColor=(0.8, 0.8, 0.8, 0.0),
            pos=LPoint3f(-295, 0, -5),
            text=headerText,
            text_align=0,
            text_fg=(1, 1, 1, 1),
            scale=16,
        )

        # Entry
        DirectLabel(
            parent=self.mainFrame,
            frameColor=(0.8, 0.8, 0.8, 0.0),
            pos=LPoint3f(-250, 0, 0),
            scale=12,
            text=actionText,
            text_align=0,
        )
        self.pathEntry = DirectEntry(parent=self.mainFrame,
                                     relief=DGG.SUNKEN,
                                     frameColor=(1, 1, 1, 1),
                                     pad=(0.2, 0.2),
                                     pos=LPoint3f(-250, 0, -20),
                                     scale=12,
                                     width=(500 - 90) / 12,
                                     overflow=True,
                                     command=self.entryCommandHandler,
                                     initialText=filePath)
        DirectButton(
            parent=self.mainFrame,
            relief=1,
            frameColor=(
                (0.8, 0.8, 0.8, 1),  # Normal
                (0.9, 0.9, 1, 1),  # Click
                (0.8, 0.8, 1, 1),  # Hover
                (0.5, 0.5, 0.5, 1)),  # Disabled
            frameSize=(-45, 45, -6, 14),
            pos=LPoint3f(235, 0, -20),
            text="Browse",
            text_scale=12,
            command=self.browse,
        )
        self.browser = DirectFolderBrowser(self.selectPath,
                                           True,
                                           os.path.dirname(filePath),
                                           os.path.split(filePath)[1],
                                           tooltip=tooltip)
        self.browser.hide()

        # Command Buttons
        DirectButton(
            parent=self.mainFrame,
            relief=1,
            frameColor=(
                (0.8, 0.8, 0.8, 1),  # Normal
                (0.9, 0.9, 1, 1),  # Click
                (0.8, 0.8, 1, 1),  # Hover
                (0.5, 0.5, 0.5, 1)),  # Disabled
            frameSize=(-45, 45, -6, 14),
            pos=LPoint3f(140, 0, -135),
            text=affirmText,
            text_scale=12,
            command=command,
            extraArgs=[1],
        )
        DirectButton(
            parent=self.mainFrame,
            relief=1,
            frameColor=(
                (0.8, 0.8, 0.8, 1),  # Normal
                (0.9, 0.9, 1, 1),  # Click
                (0.8, 0.8, 1, 1),  # Hover
                (0.5, 0.5, 0.5, 1)),  # Disabled
            frameSize=(-45, 45, -6, 14),
            pos=LPoint3f(245, 0, -135),
            text="Cancel",
            text_scale=12,
            command=command,
            extraArgs=[0])

        # handle window resizing
        self.prevScreenSize = base.getSize()
        self.accept("window-event", self.windowEventHandler)
        self.accept("escape", command, extraArgs=[0])
class PathSelect(DirectObject):
    def __init__(self, command, headerText, actionText, affirmText, filePath,
                 tooltip):
        self.command = command
        self.darkenFrame = DirectFrame(
            relief=1,
            frameSize=(0, base.getSize()[0], -base.getSize()[1], 0),
            frameColor=(0, 0, 0, 0.45),
            state=DGG.NORMAL,
            parent=base.pixel2d,
        )
        self.mainFrame = DirectFrame(
            relief=1,
            frameSize=(-300, 300, -150, 150),
            frameColor=(1, 1, 1, 1),
            pos=LPoint3f(base.getSize()[0] / 2, 0, -base.getSize()[1] / 2),
            parent=base.pixel2d,
        )

        # Header
        headerFrame = DirectFrame(
            parent=self.mainFrame,
            relief=1,
            frameSize=(-300, 300, -20, 20),
            frameColor=(0.25, 0.25, 0.25, 1.0),
            pos=LPoint3f(0, 0, 130),
            scale=LVecBase3f(1, 0.1, 1),
        )
        DirectLabel(
            parent=headerFrame,
            frameColor=(0.8, 0.8, 0.8, 0.0),
            pos=LPoint3f(-295, 0, -5),
            text=headerText,
            text_align=0,
            text_fg=(1, 1, 1, 1),
            scale=16,
        )

        # Entry
        DirectLabel(
            parent=self.mainFrame,
            frameColor=(0.8, 0.8, 0.8, 0.0),
            pos=LPoint3f(-250, 0, 0),
            scale=12,
            text=actionText,
            text_align=0,
        )
        self.pathEntry = DirectEntry(parent=self.mainFrame,
                                     relief=DGG.SUNKEN,
                                     frameColor=(1, 1, 1, 1),
                                     pad=(0.2, 0.2),
                                     pos=LPoint3f(-250, 0, -20),
                                     scale=12,
                                     width=(500 - 90) / 12,
                                     overflow=True,
                                     command=self.entryCommandHandler,
                                     initialText=filePath)
        DirectButton(
            parent=self.mainFrame,
            relief=1,
            frameColor=(
                (0.8, 0.8, 0.8, 1),  # Normal
                (0.9, 0.9, 1, 1),  # Click
                (0.8, 0.8, 1, 1),  # Hover
                (0.5, 0.5, 0.5, 1)),  # Disabled
            frameSize=(-45, 45, -6, 14),
            pos=LPoint3f(235, 0, -20),
            text="Browse",
            text_scale=12,
            command=self.browse,
        )
        self.browser = DirectFolderBrowser(self.selectPath,
                                           True,
                                           os.path.dirname(filePath),
                                           os.path.split(filePath)[1],
                                           tooltip=tooltip)
        self.browser.hide()

        # Command Buttons
        DirectButton(
            parent=self.mainFrame,
            relief=1,
            frameColor=(
                (0.8, 0.8, 0.8, 1),  # Normal
                (0.9, 0.9, 1, 1),  # Click
                (0.8, 0.8, 1, 1),  # Hover
                (0.5, 0.5, 0.5, 1)),  # Disabled
            frameSize=(-45, 45, -6, 14),
            pos=LPoint3f(140, 0, -135),
            text=affirmText,
            text_scale=12,
            command=command,
            extraArgs=[1],
        )
        DirectButton(
            parent=self.mainFrame,
            relief=1,
            frameColor=(
                (0.8, 0.8, 0.8, 1),  # Normal
                (0.9, 0.9, 1, 1),  # Click
                (0.8, 0.8, 1, 1),  # Hover
                (0.5, 0.5, 0.5, 1)),  # Disabled
            frameSize=(-45, 45, -6, 14),
            pos=LPoint3f(245, 0, -135),
            text="Cancel",
            text_scale=12,
            command=command,
            extraArgs=[0])

        # handle window resizing
        self.prevScreenSize = base.getSize()
        self.accept("window-event", self.windowEventHandler)
        self.accept("escape", command, extraArgs=[0])

    def browse(self):
        self.browser.show()

    def selectPath(self, confirm):
        if confirm:
            self.pathEntry.set(self.browser.get())
        self.browser.hide()

    def entryCommandHandler(self, text):
        self.command(1)

    def destroy(self):
        self.ignoreAll()
        self.browser.destroy()
        self.darkenFrame.destroy()
        self.mainFrame.destroy()

    def getPath(self):
        return self.pathEntry.get()

    def windowEventHandler(self, window=None):
        if window != base.win:
            # This event isn't about our window.
            return

        if window is not None:  # window is none if panda3d is not started
            if self.prevScreenSize == base.getSize():
                return
            self.prevScreenSize = base.getSize()
            screenWidthPx = base.getSize()[0]
            screenHeightPx = base.getSize()[1]

            self.mainFrame.setPos(screenWidthPx / 2, 0, -screenHeightPx / 2)
            self.darkenFrame["frameSize"] = (0, screenWidthPx, -screenHeightPx,
                                             0)