def __init__(self, parent, getEditorRootCanvas, elementDict,
                 selectedElement):
        height = DGH.getRealHeight(parent)
        self.collapsedElements = []

        self.parent = parent

        self.box = DirectBoxSizer(frameColor=(0.25, 0.25, 0.25, 1),
                                  autoUpdateFrameSize=False,
                                  orientation=DGG.VERTICAL)
        self.sizer = DirectAutoSizer(parent=parent,
                                     child=self.box,
                                     childUpdateSizeFunc=self.box.refresh)

        self.lblHeader = DirectLabel(
            text="Structure",
            text_scale=16,
            text_align=TextNode.ALeft,
            text_fg=(1, 1, 1, 1),
            frameColor=VBase4(0, 0, 0, 0),
        )
        self.box.addItem(self.lblHeader)

        color = (
            (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
        self.structureFrame = DirectScrolledFrame(
            # make the frame fit into our background frame
            frameSize=VBase4(
                self.parent["frameSize"][0], self.parent["frameSize"][1],
                self.parent["frameSize"][2] +
                DGH.getRealHeight(self.lblHeader),
                self.parent["frameSize"][3]),
            #canvasSize=VBase4(parent["frameSize"][0], parent["frameSize"][1]-20, height+30, 0),
            # set the frames color to transparent
            frameColor=VBase4(1, 1, 1, 1),
            scrollBarWidth=20,
            verticalScroll_scrollSize=20,
            verticalScroll_thumb_relief=DGG.FLAT,
            verticalScroll_incButton_relief=DGG.FLAT,
            verticalScroll_decButton_relief=DGG.FLAT,
            verticalScroll_thumb_frameColor=color,
            verticalScroll_incButton_frameColor=color,
            verticalScroll_decButton_frameColor=color,
            horizontalScroll_thumb_relief=DGG.FLAT,
            horizontalScroll_incButton_relief=DGG.FLAT,
            horizontalScroll_decButton_relief=DGG.FLAT,
            horizontalScroll_thumb_frameColor=color,
            horizontalScroll_incButton_frameColor=color,
            horizontalScroll_decButton_frameColor=color,
            state=DGG.NORMAL)
        self.box.addItem(self.structureFrame)
        self.structureFrame.bind(DGG.MWDOWN, self.scroll, [0.01])
        self.structureFrame.bind(DGG.MWUP, self.scroll, [-0.01])
        self.maxWidth = parent["frameSize"][1] - 20
        self.getEditorRootCanvas = getEditorRootCanvas
        self.refreshStructureTree(elementDict, selectedElement)
Пример #2
0
class MainView():
    def __init__(self, parent, customNodeMap, customExporterMap):
        logging.debug("Setup GUI")

        self.menuBarHeight = 24

        #
        # LAYOUT SETUP
        #

        # the box everything get's added to
        self.main_box = DirectBoxSizer(frameColor=(0, 0, 0, 0),
                                       state=DGG.DISABLED,
                                       orientation=DGG.VERTICAL,
                                       autoUpdateFrameSize=False)
        # our root element for the main box
        self.main_sizer = DirectAutoSizer(
            frameColor=(0, 0, 0, 0),
            parent=parent,
            child=self.main_box,
            childUpdateSizeFunc=self.main_box.refresh)

        # our menu bar
        self.menu_bar_sizer = DirectAutoSizer(updateOnWindowResize=False,
                                              frameColor=(0, 0, 0, 0),
                                              parent=self.main_box,
                                              extendVertical=False)

        # CONNECT THE UI ELEMENTS
        self.main_box.addItem(self.menu_bar_sizer,
                              updateFunc=self.menu_bar_sizer.refresh,
                              skipRefresh=True)

        #
        # CONTENT SETUP
        #
        self.menu_bar = MenuBar(customNodeMap, customExporterMap)
        self.menu_bar_sizer.setChild(self.menu_bar.menu_bar)
        self.menu_bar_sizer[
            "childUpdateSizeFunc"] = self.menu_bar.menu_bar.refresh

        self.main_box.refresh()
Пример #3
0
    def __init__(self, customNodeMap, customExporterMap):
        screenWidthPx = base.getSize()[0]

        #
        # Menubar
        #
        self.menu_bar = DirectBoxSizer(frameColor=(0.25, 0.25, 0.25, 1),
                                       frameSize=(0, screenWidthPx, -12, 12),
                                       autoUpdateFrameSize=False,
                                       pos=(0, 0, 0),
                                       itemMargin=(2, 2, 2, 2),
                                       parent=base.pixel2d)

        customExporters = []
        if len(customExporterMap) > 0:
            for entry, action in customExporterMap.items():
                customExporters.append(
                    DirectMenuItemEntry(entry, base.messenger.send,
                                        ["NodeEditor_customSave", [action]]))
            customExporters.append(DirectMenuSeparator())

        self.file_entries = [
            DirectMenuItemEntry("New", base.messenger.send,
                                ["NodeEditor_new"]),
            DirectMenuSeparator(),
            DirectMenuItemEntry("Open", base.messenger.send,
                                ["NodeEditor_load"]),
            DirectMenuItemEntry("Save", base.messenger.send,
                                ["NodeEditor_save"]),
            DirectMenuSeparator(),
            *customExporters,
            DirectMenuItemEntry("Quit", base.messenger.send, ["quit_app"]),
        ]
        self.file = self.__create_menu_item("File", self.file_entries)

        self.view_entries = [
            DirectMenuItemEntry("Zoom In", base.messenger.send,
                                ["NodeEditor_zoom", [True]]),
            DirectMenuItemEntry("Zoom Out", base.messenger.send,
                                ["NodeEditor_zoom", [False]]),
            DirectMenuSeparator(),
            DirectMenuItemEntry("Reset Zoom", base.messenger.send,
                                ["NodeEditor_zoom_reset"]),
        ]
        self.view = self.__create_menu_item("View", self.view_entries)

        self.tool_entries = [
            DirectMenuItemEntry("Refresh", base.messenger.send,
                                ["NodeEditor_refreshNodes"]),
            DirectMenuSeparator(),
            DirectMenuItemEntry("Copy Nodes", taskMgr.doMethodLater, [
                0.2, base.messenger.send, "delayedCopyFromMenu",
                ["NodeEditor_copyNodes"]
            ]),
            DirectMenuItemEntry("Delete Nodes", base.messenger.send,
                                ["NodeEditor_removeNode"]),
        ]
        self.tool = self.__create_menu_item("Tools", self.tool_entries)

        self.node_map = {
            "Math Nodes >": {
                "Numeric Input": "NumericNode",
                "Addition": "AddNode",
                "Divide": "DivideNode",
                "Multiply": "MultiplyNode"
            },
            "Boolean Nodes >": {
                "Boolean Value": "BoolNode",
                "Boolean And": "BoolAnd",
                "Boolean Or": "BoolOr"
            },
            "Simple Output": "TestOutNode"
        }
        self.node_map.update(customNodeMap)

        self.nodes_entries = []
        for node_name, node in self.node_map.items():
            if type(node) == str:
                self.nodes_entries.append(
                    DirectMenuItemEntry(node_name, base.messenger.send,
                                        ["addNode", [node]]))
            elif type(node) == list:
                self.nodes_entries.append(
                    DirectMenuItemEntry(node_name, base.messenger.send,
                                        ["addNode", [node[1]]]))
            elif type(node) == dict:
                sub_entries = []
                for sub_node_name, sub_node in node.items():
                    if type(sub_node) == list:
                        sub_entries.append(
                            DirectMenuItemEntry(sub_node_name,
                                                base.messenger.send,
                                                ["addNode", [sub_node[1]]]))
                    else:
                        sub_entries.append(
                            DirectMenuItemEntry(sub_node_name,
                                                base.messenger.send,
                                                ["addNode", [sub_node]]))
                self.nodes_entries.append(
                    DirectMenuItemSubMenu(node_name, sub_entries))

        self.nodes = self.__create_menu_item("Nodes", self.nodes_entries)

        self.menu_bar.addItem(self.file, skipRefresh=True)
        self.menu_bar.addItem(self.view, skipRefresh=True)
        self.menu_bar.addItem(self.tool, skipRefresh=True)
        self.menu_bar.addItem(self.nodes)
Пример #4
0
    def __init__(self, grid):
        self.grid = grid
        screenWidthPx = base.getSize()[0]
        left = screenWidthPx * 0.25
        barWidth = screenWidthPx * 0.75

        color = (
            (0.25, 0.25, 0.25, 1),  # Normal
            (0.35, 0.35, 1, 1),  # Click
            (0.25, 0.25, 1, 1),  # Hover
            (0.1, 0.1, 0.1, 1))  # Disabled

        sepColor = (0.7, 0.7, 0.7, 1)

        #
        # Menubar
        #
        self.menuBar = DirectBoxSizer(frameColor=(0.25, 0.25, 0.25, 1),
                                      frameSize=(0, screenWidthPx, -12, 12),
                                      autoUpdateFrameSize=False,
                                      pos=(0, 0, 0),
                                      itemMargin=(2, 2, 2, 2),
                                      parent=base.pixel2d)

        fileEntries = [
            DirectMenuItemEntry("New", base.messenger.send, ["newProject"]),
            DirectMenuSeparator(),
            DirectMenuItemEntry("Open", base.messenger.send, ["loadProject"]),
            DirectMenuItemEntry("Save", base.messenger.send, ["saveProject"]),
            DirectMenuItemEntry("Export", base.messenger.send,
                                ["exportProject"]),
            DirectMenuSeparator(),
            DirectMenuItemEntry("Quit", base.messenger.send, ["quitApp"]),
        ]
        self.file = DirectMenuItem(text="File",
                                   text_fg=(1, 1, 1, 1),
                                   text_scale=0.8,
                                   items=fileEntries,
                                   frameSize=(0, 65 / 21, -7 / 21, 17 / 21),
                                   frameColor=color,
                                   scale=21,
                                   relief=DGG.FLAT,
                                   item_text_fg=(1, 1, 1, 1),
                                   item_text_scale=0.8,
                                   item_relief=DGG.FLAT,
                                   item_pad=(0.2, 0.2),
                                   itemFrameColor=color,
                                   separatorFrameColor=sepColor,
                                   popupMenu_itemMargin=(0, 0, -.1, -.1),
                                   popupMenu_frameColor=color,
                                   highlightColor=color[2])

        viewEntries = [
            DirectMenuItemEntry("Toggle Grid", base.messenger.send,
                                ["toggleGrid", [not self.grid.isHidden()]]),
            DirectMenuItemEntry("Toggle Scale", base.messenger.send,
                                ["toggleVisualEditorParent"]),
            DirectMenuSeparator(),
            DirectMenuItemEntry("Zoom-in", base.messenger.send, ["zoom-in"]),
            DirectMenuItemEntry("Zoom-out", base.messenger.send, ["zoom-out"]),
            DirectMenuItemEntry("reset Zoom", base.messenger.send,
                                ["zoom-reset"]),
        ]
        self.view = DirectMenuItem(text="View",
                                   text_fg=(1, 1, 1, 1),
                                   text_scale=0.8,
                                   items=viewEntries,
                                   frameSize=(0, 65 / 21, -7 / 21, 17 / 21),
                                   frameColor=color,
                                   scale=21,
                                   relief=DGG.FLAT,
                                   item_text_fg=(1, 1, 1, 1),
                                   item_text_scale=0.8,
                                   item_relief=DGG.FLAT,
                                   item_pad=(0.2, 0.2),
                                   itemFrameColor=color,
                                   separatorFrameColor=sepColor,
                                   popupMenu_itemMargin=(0, 0, -.1, -.1),
                                   popupMenu_frameColor=color,
                                   highlightColor=color[2])

        toolsEntries = [
            DirectMenuItemEntry("Undo", base.messenger.send, ["undo"]),
            DirectMenuItemEntry("Redo", base.messenger.send, ["redo"]),
            DirectMenuItemEntry("Cycle redos", base.messenger.send,
                                ["cycleRedo"]),
            DirectMenuSeparator(),
            DirectMenuItemEntry("Delete Element", base.messenger.send,
                                ["removeElement"]),
            DirectMenuItemEntry("Copy", base.messenger.send, ["copyElement"]),
            DirectMenuItemEntry("Paste", base.messenger.send,
                                ["pasteElement"]),
            DirectMenuItemEntry("Copy options", base.messenger.send,
                                ["copyOptions"]),
            DirectMenuItemEntry("Paste options", base.messenger.send,
                                ["pasteOptions"]),
            DirectMenuSeparator(),
            DirectMenuItemEntry("Options", base.messenger.send,
                                ["showSettings"]),
            DirectMenuItemEntry("Help", base.messenger.send, ["showHelp"]),
        ]
        self.tools = DirectMenuItem(text="Tools",
                                    text_fg=(1, 1, 1, 1),
                                    text_scale=0.8,
                                    items=toolsEntries,
                                    frameSize=(0, 65 / 21, -7 / 21, 17 / 21),
                                    frameColor=color,
                                    scale=21,
                                    relief=DGG.FLAT,
                                    item_text_fg=(1, 1, 1, 1),
                                    item_text_scale=0.8,
                                    item_relief=DGG.FLAT,
                                    item_pad=(0.2, 0.2),
                                    itemFrameColor=color,
                                    separatorFrameColor=sepColor,
                                    popupMenu_itemMargin=(0, 0, -.1, -.1),
                                    popupMenu_frameColor=color,
                                    highlightColor=color[2])

        self.menuBar.addItem(self.file)
        self.menuBar.addItem(self.view)
        self.menuBar.addItem(self.tools)
class StructurePanel():
    def __init__(self, parent, getEditorRootCanvas, elementDict,
                 selectedElement):
        height = DGH.getRealHeight(parent)
        self.collapsedElements = []

        self.parent = parent

        self.box = DirectBoxSizer(frameColor=(0.25, 0.25, 0.25, 1),
                                  autoUpdateFrameSize=False,
                                  orientation=DGG.VERTICAL)
        self.sizer = DirectAutoSizer(parent=parent,
                                     child=self.box,
                                     childUpdateSizeFunc=self.box.refresh)

        self.lblHeader = DirectLabel(
            text="Structure",
            text_scale=16,
            text_align=TextNode.ALeft,
            text_fg=(1, 1, 1, 1),
            frameColor=VBase4(0, 0, 0, 0),
        )
        self.box.addItem(self.lblHeader)

        color = (
            (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
        self.structureFrame = DirectScrolledFrame(
            # make the frame fit into our background frame
            frameSize=VBase4(
                self.parent["frameSize"][0], self.parent["frameSize"][1],
                self.parent["frameSize"][2] +
                DGH.getRealHeight(self.lblHeader),
                self.parent["frameSize"][3]),
            #canvasSize=VBase4(parent["frameSize"][0], parent["frameSize"][1]-20, height+30, 0),
            # set the frames color to transparent
            frameColor=VBase4(1, 1, 1, 1),
            scrollBarWidth=20,
            verticalScroll_scrollSize=20,
            verticalScroll_thumb_relief=DGG.FLAT,
            verticalScroll_incButton_relief=DGG.FLAT,
            verticalScroll_decButton_relief=DGG.FLAT,
            verticalScroll_thumb_frameColor=color,
            verticalScroll_incButton_frameColor=color,
            verticalScroll_decButton_frameColor=color,
            horizontalScroll_thumb_relief=DGG.FLAT,
            horizontalScroll_incButton_relief=DGG.FLAT,
            horizontalScroll_decButton_relief=DGG.FLAT,
            horizontalScroll_thumb_frameColor=color,
            horizontalScroll_incButton_frameColor=color,
            horizontalScroll_decButton_frameColor=color,
            state=DGG.NORMAL)
        self.box.addItem(self.structureFrame)
        self.structureFrame.bind(DGG.MWDOWN, self.scroll, [0.01])
        self.structureFrame.bind(DGG.MWUP, self.scroll, [-0.01])
        self.maxWidth = parent["frameSize"][1] - 20
        self.getEditorRootCanvas = getEditorRootCanvas
        self.refreshStructureTree(elementDict, selectedElement)

    def scroll(self, scrollStep, event):
        self.structureFrame.verticalScroll.scrollStep(scrollStep)

    def resizeFrame(self):
        self.sizer.refresh()
        self.structureFrame["frameSize"] = (self.parent["frameSize"][0],
                                            self.parent["frameSize"][1],
                                            self.parent["frameSize"][2] +
                                            DGH.getRealHeight(self.lblHeader),
                                            self.parent["frameSize"][3])

        #posZ = 0
        #height = DGH.getRealHeight(parent)
        #self.lblHeader["frameSize"] = (self.parent["frameSize"][0], self.parent["frameSize"][1], -10, 20)
        #self.lblHeader["text_pos"] = (self.parent["frameSize"][0], 0)
        #self.lblHeader.setPos(0,0,posZ-20)
        #posZ -= 30
        #self.structureFrame["frameSize"] = (self.parent["frameSize"][0], self.parent["frameSize"][1], height+30, 0)
        #self.structureFrame.setPos(0,0,posZ)

    def refreshStructureTree(self, elementDict, selectedElement):
        self.elementDict = elementDict
        self.selectedElement = selectedElement
        for element in self.structureFrame.getCanvas().getChildren():
            element.removeNode()

        self.maxWidth = self.parent["frameSize"][1] - 20
        self.itemCounter = 0
        self.__fillStructureTree(self.getEditorRootCanvas(), 0, 0)

        self.structureFrame["canvasSize"] = (
            self.structureFrame["frameSize"][0], self.maxWidth,
            self.itemCounter * -16, 0)
        self.structureFrame.setCanvasSize()

    def __fillStructureTree(self, root, level, z):
        if "DirectGrid" in root.getName(): return
        self.itemCounter += 1

        elementInfo = None
        if root.getName() in self.elementDict.keys():
            elementInfo = self.elementDict[root.getName()]
        elif len(root.getName().split("-")) > 1 and root.getName().split(
                "-")[1] in self.elementDict.keys():
            elementInfo = self.elementDict[root.getName().split("-")[1]]

        if level > 0:
            self.__makeStructureFrameTreeItem(root, elementInfo, level, z)
        if hasattr(root, "getChildren") \
        and elementInfo not in self.collapsedElements:
            for child in root.getChildren():
                z = -16 * self.itemCounter
                self.__fillStructureTree(child, level + 1, z)

    def __makeStructureFrameTreeItem(self, elementNP, elementInfo,
                                     parentsLevel, z):
        if elementInfo is None:
            lbl = DirectLabel(text=elementNP.getName(),
                              text_align=TextNode.ALeft,
                              frameColor=(0, 0, 0, 0),
                              relief=DGG.FLAT,
                              pos=(self.structureFrame["frameSize"][0] +
                                   20 * parentsLevel, 0, z),
                              scale=16,
                              parent=self.structureFrame.getCanvas())
            self.maxWidth = max(
                self.maxWidth,
                lbl.getX() + lbl.getWidth() * lbl.getScale()[0])
        else:
            margin = 5
            shift = 6

            if hasattr(elementNP, "getChildren"):
                if len(elementNP.getChildren()) > 0:
                    # Collapse Button
                    btnC = DirectCheckBox(
                        relief=DGG.FLAT,
                        pos=(self.structureFrame["frameSize"][0] +
                             20 * parentsLevel - 16 + margin, 0, z + shift),
                        frameSize=(-8, 8, -8, 8),
                        frameColor=(0, 0, 0, 0),
                        command=self.__collapseElement,
                        extraArgs=[elementInfo],
                        image="icons/Collapsed.png" if elementInfo
                        in self.collapsedElements else "icons/Collapse.png",
                        uncheckedImage="icons/Collapse.png",
                        checkedImage="icons/Collapsed.png",
                        image_scale=8,
                        isChecked=elementInfo in self.collapsedElements,
                        parent=self.structureFrame.getCanvas())
                    btnC.setTransparency(TransparencyAttrib.M_alpha)
                    btnC.bind(DGG.MWDOWN, self.scroll, [0.01])
                    btnC.bind(DGG.MWUP, self.scroll, [-0.01])

            # Element Name
            btn = DirectButton(
                frameColor=(
                    VBase4(1, 1, 1, 1),  #normal
                    VBase4(0.9, 0.9, 0.9, 1),  #click
                    VBase4(0.8, 0.8, 0.8, 1),  #hover
                    VBase4(0.5, 0.5, 0.5, 1)),  #disabled
                text=elementInfo.name,
                text_align=TextNode.ALeft,
                relief=DGG.FLAT,
                pos=(self.structureFrame["frameSize"][0] + 20 * parentsLevel,
                     0, z),
                scale=16,
                command=self.__selectElement,
                extraArgs=[elementInfo],
                parent=self.structureFrame.getCanvas())
            btn.bind(DGG.MWDOWN, self.scroll, [0.01])
            btn.bind(DGG.MWUP, self.scroll, [-0.01])
            if self.selectedElement is not None and self.selectedElement == elementInfo:
                btn.setColorScale(1, 1, 0, 1)

            # Delete Button
            btnX = DirectButton(
                relief=DGG.FLAT,
                pos=(self.structureFrame["frameSize"][0] + 8 + margin +
                     20 * parentsLevel + btn.getWidth() * btn.getScale()[0], 0,
                     z + shift),
                frameSize=(-8, 8, -8, 8),
                frameColor=(0, 0, 0, 0),
                command=self.__removeElement,
                extraArgs=[elementInfo],
                image="icons/DeleteSmall.png",
                image_scale=8,
                parent=self.structureFrame.getCanvas())
            btnX.setTransparency(TransparencyAttrib.M_multisample)
            btnX.bind(DGG.MWDOWN, self.scroll, [0.01])
            btnX.bind(DGG.MWUP, self.scroll, [-0.01])

            # Visibility Button
            btnV = DirectCheckBox(
                relief=DGG.FLAT,
                pos=(self.structureFrame["frameSize"][0] + 8 + margin * 2 +
                     20 * parentsLevel + btn.getWidth() * btn.getScale()[0] +
                     btnX.getWidth(), 0, z + shift),
                frameSize=(-8, 8, -8, 8),
                frameColor=(0, 0, 0, 0),
                command=self.__toggleElementVisibility,
                extraArgs=[elementInfo],
                image="icons/VisibilityOffSmall.png"
                if elementInfo.element.isHidden() else
                "icons/VisibilityOnSmall.png",
                uncheckedImage="icons/VisibilityOffSmall.png",
                checkedImage="icons/VisibilityOnSmall.png",
                image_scale=8,
                isChecked=not elementInfo.element.isHidden(),
                parent=self.structureFrame.getCanvas())
            btnV.setTransparency(TransparencyAttrib.M_multisample)
            btnV.bind(DGG.MWDOWN, self.scroll, [0.01])
            btnV.bind(DGG.MWUP, self.scroll, [-0.01])
            self.maxWidth = max(self.maxWidth, btnV.getX() + 8)

    def __selectElement(self, elementInfo, args=None):
        if elementInfo is not None:
            base.messenger.send("selectElement", [elementInfo, args])

    def __removeElement(self, elementInfo):
        if elementInfo is not None:
            base.messenger.send("removeElement", [elementInfo.element])

    def __toggleElementVisibility(self, toggle, elementInfo):
        if elementInfo is not None:
            base.messenger.send("toggleElementVisibility",
                                [elementInfo.element])

    def __collapseElement(self, collapse, elementInfo):
        if elementInfo is not None:
            if collapse:
                self.collapsedElements.append(elementInfo)
            else:
                self.collapsedElements.remove(elementInfo)
            base.messenger.send("refreshStructureTree")
Пример #6
0
from DirectGuiExtension.DirectAutoSizer import DirectAutoSizer
from DirectGuiExtension.DirectSplitFrame import DirectSplitFrame
from DirectGuiExtension import DirectGuiHelper as DGH

from DirectFolderBrowser.DirectFolderBrowser import DirectFolderBrowser

loadPrcFileData(
    "", """
    window-title DirectGUI Extensions Demo
    show-frame-rate-meter #t
    """)

app = ShowBase()

# MAIN LAYOUT
mainBox = DirectBoxSizer(orientation=DGG.VERTICAL, autoUpdateFrameSize=False)
DirectAutoSizer(child=mainBox, childUpdateSizeFunc=mainBox.refresh)


# CALENDAR EXAMPLE
# in a function to be called by a menu item
def showCalendar():
    dp = DirectDatePicker()
    calendarDragFrame = DirectScrolledWindowFrame(frameSize=dp["frameSize"])
    dp.reparentTo(calendarDragFrame)
    dp.refreshPicker()
    calendarDragFrame.setPos(-calendarDragFrame.getWidth() * 0.5, 0,
                             calendarDragFrame.getHeight() * 0.5)


# BROWSER EXAMPLE
Пример #7
0
    def __init__(self, tooltip, grid):
        self.tt = tooltip
        self.grid = grid
        screenWidthPx = base.getSize()[0]
        left = screenWidthPx * 0.25
        barWidth = screenWidthPx * 0.75

        color = (
            (0.25, 0.25, 0.25, 1),  # Normal
            (0.35, 0.35, 1, 1),  # Click
            (0.25, 0.25, 1, 1),  # Hover
            (0.1, 0.1, 0.1, 1))  # Disabled

        #
        # Toolbar
        #
        self.toolBar = DirectBoxSizer(frameColor=(0.25, 0.25, 0.25, 1),
                                      frameSize=(0, barWidth, -24, 24),
                                      autoUpdateFrameSize=False,
                                      pos=(0, 0, 0),
                                      parent=base.pixel2d)

        buttonColor = (
            (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
        btn = DirectButton(frameSize=(-24, 24, -24, 24),
                           frameColor=buttonColor,
                           relief=DGG.FLAT,
                           command=base.messenger.send,
                           extraArgs=["newProject"],
                           image="icons/New.png",
                           image_scale=24)
        btn.setTransparency(TransparencyAttrib.M_multisample)
        btn.bind(DGG.ENTER, self.tt.show, ["Create New GUI (Ctrl-N)"])
        btn.bind(DGG.EXIT, self.tt.hide)
        self.toolBar.addItem(btn)

        btn = DirectButton(frameSize=(-24, 24, -24, 24),
                           frameColor=buttonColor,
                           relief=DGG.FLAT,
                           command=base.messenger.send,
                           extraArgs=["saveProject"],
                           image="icons/Save.png",
                           image_scale=24)
        btn.setTransparency(TransparencyAttrib.M_multisample)
        btn.bind(DGG.ENTER, self.tt.show, ["Save GUI as gui Project (Ctrl-S)"])
        btn.bind(DGG.EXIT, self.tt.hide)
        self.toolBar.addItem(btn)

        btn = DirectButton(frameSize=(-24, 24, -24, 24),
                           frameColor=buttonColor,
                           text_scale=0.33,
                           relief=DGG.FLAT,
                           command=base.messenger.send,
                           extraArgs=["exportProject"],
                           image="icons/Export.png",
                           image_scale=24)
        btn.setTransparency(TransparencyAttrib.M_multisample)
        btn.bind(DGG.ENTER, self.tt.show,
                 ["Export GUI as python script (Ctrl-E)"])
        btn.bind(DGG.EXIT, self.tt.hide)
        self.toolBar.addItem(btn)

        btn = DirectButton(frameSize=(-24, 24, -24, 24),
                           frameColor=buttonColor,
                           relief=DGG.FLAT,
                           text_scale=0.33,
                           command=base.messenger.send,
                           extraArgs=["loadProject"],
                           image="icons/Load.png",
                           image_scale=24)
        btn.setTransparency(TransparencyAttrib.M_multisample)
        btn.bind(DGG.ENTER, self.tt.show, ["Load GUI project (Ctrl-O)"])
        btn.bind(DGG.EXIT, self.tt.hide)
        self.toolBar.addItem(btn)

        placeholder = DirectFrame(text="|",
                                  frameSize=(-1, 1, -24, 24),
                                  pad=(4, 0),
                                  frameColor=(0, 0, 0, 1))
        self.toolBar.addItem(placeholder)

        btn = DirectButton(frameSize=(-24, 24, -24, 24),
                           frameColor=buttonColor,
                           relief=DGG.FLAT,
                           text_scale=0.33,
                           command=base.messenger.send,
                           extraArgs=["undo"],
                           image="icons/Undo.png",
                           image_scale=24)
        btn.setTransparency(TransparencyAttrib.M_multisample)
        btn.bind(DGG.ENTER, self.tt.show, ["Undo last action (Ctrl-Z)"])
        btn.bind(DGG.EXIT, self.tt.hide)
        self.toolBar.addItem(btn)

        btn = DirectButton(frameSize=(-24, 24, -24, 24),
                           frameColor=buttonColor,
                           relief=DGG.FLAT,
                           text_scale=0.33,
                           command=base.messenger.send,
                           extraArgs=["redo"],
                           image="icons/Redo.png",
                           image_scale=24)
        btn.setTransparency(TransparencyAttrib.M_multisample)
        btn.bind(DGG.ENTER, self.tt.show, ["Redo last action (Ctrl-Y)"])
        btn.bind(DGG.EXIT, self.tt.hide)
        self.toolBar.addItem(btn)

        btn = DirectButton(frameSize=(-24, 24, -24, 24),
                           frameColor=buttonColor,
                           relief=DGG.FLAT,
                           text_scale=0.33,
                           command=base.messenger.send,
                           extraArgs=["cycleRedo"],
                           image="icons/CycleRedo.png",
                           image_scale=24)
        btn.setTransparency(TransparencyAttrib.M_multisample)
        btn.bind(DGG.ENTER, self.tt.show,
                 ["Cycle through redo branches (Ctrl-Shift-Y)"])
        btn.bind(DGG.EXIT, self.tt.hide)
        self.toolBar.addItem(btn)

        placeholder = DirectFrame(text="|",
                                  frameSize=(-1, 1, -24, 24),
                                  pad=(4, 0),
                                  frameColor=(0, 0, 0, 1))
        self.toolBar.addItem(placeholder)

        btn = DirectButton(frameSize=(-24, 24, -24, 24),
                           frameColor=buttonColor,
                           relief=DGG.FLAT,
                           text_scale=0.33,
                           command=base.messenger.send,
                           extraArgs=["removeElement"],
                           image="icons/Delete.png",
                           image_scale=24)
        btn.setTransparency(TransparencyAttrib.M_multisample)
        btn.bind(DGG.ENTER, self.tt.show, ["Delete selected element (Del)"])
        btn.bind(DGG.EXIT, self.tt.hide)
        self.toolBar.addItem(btn)

        placeholder = DirectFrame(text="|",
                                  frameSize=(-1, 1, -24, 24),
                                  pad=(4, 0),
                                  frameColor=(0, 0, 0, 1))
        self.toolBar.addItem(placeholder)

        self.cb_grid = DirectCheckBox(
            frameSize=(-24, 24, -24, 24),
            frameColor=buttonColor,
            relief=DGG.FLAT,
            text_scale=12,
            image="icons/GridOff.png"
            if self.grid.isHidden() else "icons/GridOn.png",
            uncheckedImage="icons/GridOff.png",
            checkedImage="icons/GridOn.png",
            image_scale=24,
            isChecked=not self.grid.isHidden(),
            command=self.toggleGrid)
        self.cb_grid.setTransparency(TransparencyAttrib.M_multisample)
        self.cb_grid.bind(DGG.ENTER, self.tt.show, ["Toggle Grid (Ctrl-G)"])
        self.cb_grid.bind(DGG.EXIT, self.tt.hide)
        self.toolBar.addItem(self.cb_grid)

        self.cb_scale = DirectCheckBox(frameSize=(-24, 24, -24, 24),
                                       frameColor=buttonColor,
                                       relief=DGG.FLAT,
                                       text_scale=12,
                                       image="icons/Scale1.png",
                                       uncheckedImage="icons/Scale2.png",
                                       checkedImage="icons/Scale1.png",
                                       image_scale=24,
                                       isChecked=True,
                                       command=self.toggleVisualEditorParent)
        self.cb_scale.setTransparency(TransparencyAttrib.M_alpha)
        self.cb_scale.bind(DGG.ENTER, self.tt.show,
                           ["Toggle editor scale (Aspect/Pixel)"])
        self.cb_scale.bind(DGG.EXIT, self.tt.hide)
        self.toolBar.addItem(self.cb_scale)

        placeholder = DirectFrame(text="|",
                                  frameSize=(-1, 1, -24, 24),
                                  pad=(4, 0),
                                  frameColor=(0, 0, 0, 1))
        self.toolBar.addItem(placeholder)

        zoomHolder = DirectFrame(
            frameSize=(-48, 48, -24, 24),
            #pad=(4, 0),
            frameColor=(0, 0, 0, 0))
        self.toolBar.addItem(zoomHolder)
        self.zoomSlider = DirectSlider(zoomHolder,
                                       scale=(48, 1, 96),
                                       pos=(0, 0, 0),
                                       range=(0.1, 1.5),
                                       command=self.zoomSliderChanged)
        self.zoomSlider.bind(DGG.ENTER, self.tt.show, ["Zoom"])
        self.zoomSlider.bind(DGG.EXIT, self.tt.hide)
        #self.toolBar.addItem(self.zoomSlider)

        placeholder = DirectFrame(text="|",
                                  frameSize=(-1, 1, -24, 24),
                                  pad=(4, 0),
                                  frameColor=(0, 0, 0, 1))
        self.toolBar.addItem(placeholder)

        btn = DirectButton(frameSize=(-24, 24, -24, 24),
                           frameColor=buttonColor,
                           relief=DGG.FLAT,
                           text_scale=0.33,
                           command=base.messenger.send,
                           extraArgs=["quitApp"],
                           image="icons/Quit.png",
                           image_scale=24)
        btn.setTransparency(TransparencyAttrib.M_alpha)
        btn.bind(DGG.ENTER, self.tt.show,
                 ["Quit Direct GUI Designer (Ctrl-Q)"])
        btn.bind(DGG.EXIT, self.tt.hide)
        self.toolBar.addItem(btn)

        placeholder = DirectFrame(text="|",
                                  frameSize=(-1, 1, -24, 24),
                                  pad=(4, 0),
                                  frameColor=(0, 0, 0, 1))
        self.toolBar.addItem(placeholder)

        btn = DirectButton(frameSize=(-24, 24, -24, 24),
                           frameColor=buttonColor,
                           relief=DGG.FLAT,
                           text_scale=0.33,
                           command=base.messenger.send,
                           extraArgs=["showHelp"],
                           image="icons/Help.png",
                           image_scale=24)
        btn.setTransparency(TransparencyAttrib.M_multisample)
        btn.bind(DGG.ENTER, self.tt.show, ["Show a help Dialog (F1)"])
        btn.bind(DGG.EXIT, self.tt.hide)
        self.toolBar.addItem(btn)

        btn = DirectButton(frameSize=(-24, 24, -24, 24),
                           frameColor=buttonColor,
                           relief=DGG.FLAT,
                           text_scale=0.33,
                           command=base.messenger.send,
                           extraArgs=["showSettings"],
                           image="icons/Settings.png",
                           image_scale=24)
        btn.setTransparency(TransparencyAttrib.M_multisample)
        btn.bind(DGG.ENTER, self.tt.show, ["Show Designer Settings"])
        btn.bind(DGG.EXIT, self.tt.hide)
        self.toolBar.addItem(btn)

        if not ConfigVariableBool("show-toolbar", True).getValue():
            self.toolBar.hide()

        self.accept("setVisualEditorParent", self.setVisualEditorParent)
        self.accept("toggleGrid", self.setGrid)
Пример #8
0
    def __init__(self, parent):
        height = DGH.getRealHeight(parent)
        self.parent = parent

        self.box = DirectBoxSizer(frameColor=(0.25, 0.25, 0.25, 1),
                                  autoUpdateFrameSize=False,
                                  orientation=DGG.VERTICAL)
        self.sizer = DirectAutoSizer(parent=parent,
                                     child=self.box,
                                     childUpdateSizeFunc=self.box.refresh)

        self.lblHeader = DirectLabel(
            text="Toolbox",
            text_scale=16,
            text_align=TextNode.ALeft,
            text_fg=(1, 1, 1, 1),
            frameColor=VBase4(0, 0, 0, 0),
        )
        self.box.addItem(self.lblHeader)

        color = (
            (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
        self.toolboxFrame = DirectScrolledFrame(
            # make the frame fit into our background frame
            frameSize=VBase4(
                self.parent["frameSize"][0], self.parent["frameSize"][1],
                self.parent["frameSize"][2] +
                DGH.getRealHeight(self.lblHeader),
                self.parent["frameSize"][3]),
            scrollBarWidth=20,
            verticalScroll_scrollSize=20,
            verticalScroll_thumb_relief=DGG.FLAT,
            verticalScroll_incButton_relief=DGG.FLAT,
            verticalScroll_decButton_relief=DGG.FLAT,
            verticalScroll_thumb_frameColor=color,
            verticalScroll_incButton_frameColor=color,
            verticalScroll_decButton_frameColor=color,
            horizontalScroll_thumb_relief=DGG.FLAT,
            horizontalScroll_incButton_relief=DGG.FLAT,
            horizontalScroll_decButton_relief=DGG.FLAT,
            horizontalScroll_thumb_frameColor=color,
            horizontalScroll_incButton_frameColor=color,
            horizontalScroll_decButton_frameColor=color,
            state=DGG.NORMAL)
        self.box.addItem(self.toolboxFrame)
        self.toolboxFrame.bind(DGG.MWDOWN, self.scroll, [0.01])
        self.toolboxFrame.bind(DGG.MWUP, self.scroll, [-0.01])
        self.toolboxEntries = [
            ["~Interactive Elements~"],
            ["Button", "DirectButton"],
            ["Entry", "DirectEntry"],
            ["Scrolled Entry", "DirectEntryScroll"],
            ["Check Box", "DirectCheckBox"],
            ["Check Button", "DirectCheckButton"],
            ["Option Menu", "DirectOptionMenu"],
            ["Radio Button", "DirectRadioButton"],
            ["Slider", "DirectSlider"],
            ["Scroll Bar", "DirectScrollBar"],
            ["Scrolled List Item", "DirectScrolledListItem"],
            ["~Display Elements~"],
            ["Label", "DirectLabel"],
            ["Wait Bar", "DirectWaitBar"],
            ["~Container~"],
            ["Frame", "DirectFrame"],
            ["Scrolled Frame", "DirectScrolledFrame"],
            ["Scrolled List", "DirectScrolledList"],
            ["~Dialogs~"],
            ["OK Dialog", "OkDialog"],
            ["OK Cancel Dialog", "OkCancelDialog"],
            ["Yes No Dialog", "YesNoDialog"],
            ["Yes No Cancel Dialog", "YesNoCancelDialog"],
            ["Retry Cancel Dialog", "RetryCancelDialog"],
        ]
        self.createEntries()
Пример #9
0
class ToolboxPanel:
    def __init__(self, parent):
        height = DGH.getRealHeight(parent)
        self.parent = parent

        self.box = DirectBoxSizer(frameColor=(0.25, 0.25, 0.25, 1),
                                  autoUpdateFrameSize=False,
                                  orientation=DGG.VERTICAL)
        self.sizer = DirectAutoSizer(parent=parent,
                                     child=self.box,
                                     childUpdateSizeFunc=self.box.refresh)

        self.lblHeader = DirectLabel(
            text="Toolbox",
            text_scale=16,
            text_align=TextNode.ALeft,
            text_fg=(1, 1, 1, 1),
            frameColor=VBase4(0, 0, 0, 0),
        )
        self.box.addItem(self.lblHeader)

        color = (
            (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
        self.toolboxFrame = DirectScrolledFrame(
            # make the frame fit into our background frame
            frameSize=VBase4(
                self.parent["frameSize"][0], self.parent["frameSize"][1],
                self.parent["frameSize"][2] +
                DGH.getRealHeight(self.lblHeader),
                self.parent["frameSize"][3]),
            scrollBarWidth=20,
            verticalScroll_scrollSize=20,
            verticalScroll_thumb_relief=DGG.FLAT,
            verticalScroll_incButton_relief=DGG.FLAT,
            verticalScroll_decButton_relief=DGG.FLAT,
            verticalScroll_thumb_frameColor=color,
            verticalScroll_incButton_frameColor=color,
            verticalScroll_decButton_frameColor=color,
            horizontalScroll_thumb_relief=DGG.FLAT,
            horizontalScroll_incButton_relief=DGG.FLAT,
            horizontalScroll_decButton_relief=DGG.FLAT,
            horizontalScroll_thumb_frameColor=color,
            horizontalScroll_incButton_frameColor=color,
            horizontalScroll_decButton_frameColor=color,
            state=DGG.NORMAL)
        self.box.addItem(self.toolboxFrame)
        self.toolboxFrame.bind(DGG.MWDOWN, self.scroll, [0.01])
        self.toolboxFrame.bind(DGG.MWUP, self.scroll, [-0.01])
        self.toolboxEntries = [
            ["~Interactive Elements~"],
            ["Button", "DirectButton"],
            ["Entry", "DirectEntry"],
            ["Scrolled Entry", "DirectEntryScroll"],
            ["Check Box", "DirectCheckBox"],
            ["Check Button", "DirectCheckButton"],
            ["Option Menu", "DirectOptionMenu"],
            ["Radio Button", "DirectRadioButton"],
            ["Slider", "DirectSlider"],
            ["Scroll Bar", "DirectScrollBar"],
            ["Scrolled List Item", "DirectScrolledListItem"],
            ["~Display Elements~"],
            ["Label", "DirectLabel"],
            ["Wait Bar", "DirectWaitBar"],
            ["~Container~"],
            ["Frame", "DirectFrame"],
            ["Scrolled Frame", "DirectScrolledFrame"],
            ["Scrolled List", "DirectScrolledList"],
            ["~Dialogs~"],
            ["OK Dialog", "OkDialog"],
            ["OK Cancel Dialog", "OkCancelDialog"],
            ["Yes No Dialog", "YesNoDialog"],
            ["Yes No Cancel Dialog", "YesNoCancelDialog"],
            ["Retry Cancel Dialog", "RetryCancelDialog"],
        ]
        self.createEntries()

    def scroll(self, scrollStep, event):
        self.toolboxFrame.verticalScroll.scrollStep(scrollStep)

    def createEntries(self):
        # Empty the toolbox if there were any elements
        for child in self.toolboxFrame.getCanvas().getChildren():
            child.removeNode()
        idx = 1
        for entry in self.toolboxEntries:
            if len(entry) == 2:
                item = self.__makeToolboxListItem(entry[0], entry[1], idx)
                item.reparentTo(self.toolboxFrame.getCanvas())
            else:
                item = self.__makeToolboxCenteredListItem(entry[0], idx)
                item.reparentTo(self.toolboxFrame.getCanvas())
            item.bind(DGG.MWDOWN, self.scroll, [0.01])
            item.bind(DGG.MWUP, self.scroll, [-0.01])
            idx += 1
        self.toolboxFrame["canvasSize"] = (self.parent["frameSize"][0],
                                           self.parent["frameSize"][1] - 20,
                                           -(len(self.toolboxEntries) * 30), 0)
        self.toolboxFrame.setCanvasSize()

    def resizeFrame(self):
        self.sizer.refresh()
        self.toolboxFrame["frameSize"] = (self.parent["frameSize"][0],
                                          self.parent["frameSize"][1],
                                          self.parent["frameSize"][2] +
                                          DGH.getRealHeight(self.lblHeader),
                                          self.parent["frameSize"][3])

        self.createEntries()

    def __createControl(self, name):
        base.messenger.send("createControl", [name])

    def __makeToolboxListItem(self, displayName, name, index):
        item = DirectButton(
            text=displayName,
            frameSize=VBase4(self.parent["frameSize"][0],
                             self.parent["frameSize"][1] - 20, -10, 20),
            frameColor=(
                VBase4(1, 1, 1, 1),  #normal
                VBase4(0.9, 0.9, 0.9, 1),  #click
                VBase4(0.8, 0.8, 0.8, 1),  #hover
                VBase4(0.5, 0.5, 0.5, 1)),  #disabled
            text_align=TextNode.ALeft,
            text_scale=12,
            text_pos=(self.parent["frameSize"][0], 0),
            pos=(0, 0, -30 * index + 10),
            relief=DGG.FLAT,
            command=self.__createControl,
            extraArgs=[name],
            #suppressMouse=0
        )
        return item

    def __makeToolboxCenteredListItem(self, displayName, index):
        item = DirectFrame(
            text=displayName,
            frameSize=VBase4(-self.parent["frameSize"][1],
                             self.parent["frameSize"][1], -10, 20),
            frameColor=VBase4(0.85, 0.85, 0.85, 1),
            text_align=TextNode.ACenter,
            text_scale=16,
            text_pos=(-10, 0),
            pos=(0, 0, -30 * index + 10),  #self.parent["frameSize"][1]/2-10
            state=DGG.NORMAL,
            #suppressMouse=0
        )
        return item