def save(self): """Save the current state of the application to file.""" memento = self.create_memento() import datetime f = open(str(datetime.datetime.now()).replace(' ','_')+'.saved_story','w') cPickle.dump(memento,f) f.close() zcanvas.message("Saved!")
def add(self,card): # The Add button was pressed on one of the StoryCards in self.storyCards for box in self.right_vbox: if box.contents is None: box.fill(card) # self.activate_right_frame() return zcanvas.message('The stack is full!\nDrag another card from the stack first.')
def add(self, card): # The Add button was pressed on one of the StoryCards in self.storyCards for box in self.right_vbox: if box.contents is None: box.fill(card) # self.activate_right_frame() return zcanvas.message( 'The stack is full!\nDrag another card from the stack first.')
def save(self): """Save the current state of the application to file.""" memento = self.create_memento() import datetime f = open( str(datetime.datetime.now()).replace(' ', '_') + '.saved_story', 'w') cPickle.dump(memento, f) f.close() zcanvas.message("Saved!")
def remove_row(self): """Remove the last row of boxes from this story map, _if_ all the boxes in the row are empty.""" if len(self) <= self.initial_size: return # Don't shrink below initial size for item in self.items()[-self.num_columns:]: # The last row. if item is not None: zcanvas.message('Row is not empty.') return for box in self.boxes[-self.num_columns:]: self.remove(box)
"""Demo of znode with the highlightable mixin. Mouse-over the znodes to see them highlight and unhighlight.""" import sys,os,random sys.path.append(os.path.join(sys.path[0],'../zui/')) from znode import ZNode,Highlightable from zcanvas import zcanvas from pandac.PandaModules import * import direct.directbase.DirectStart class DemoNode(ZNode,Highlightable): """A class that just mixes in highlightable with znode.""" def __init__(self): ZNode.__init__(self) Highlightable.__init__(self) for x in (-1,-.5,0,.5,1): node = DemoNode() node.reparentTo(zcanvas.home) node.set_highlightable(True) node.setPos(x,0,0) node.setScale(.7) zcanvas.message('Move the mouse cursor over the items and watch them highlight.') run()
def __init__(self): m = StoryMap(storyCardClass=FocusableChoosableStoryCard, title="Story Cards") m.fill() m.setScale(0.02) m.setPos(-.5, 0, .8) m.reparentTo(zcanvas.home) n = StoryMap(storyCardClass=FocusableEditableStoryCard, title="My Story") n.setScale(0.02) n.setPos(-.5, 0, -.1) n.reparentTo(zcanvas.home) n.title['state'] = DGG.NORMAL controller = Controller() base.accept('mouse2', zcanvas.zoomTo) base.accept('mouse3', zcanvas.zoomToParent) base.accept('mouse1', zcanvas.drag) base.accept('mouse1-up', zcanvas.drop) zcanvas.message( """Drag and drop StoryCards between StoryMaps, and zoom around.""") base.setFrameRateMeter(True) run()
def enterParent(self): """Viewport focus has changed to the lowest zoomable ancestor node of this znode.""" DemoNode.enterParent(self) self.set_zoomable(True) def exitParent(self): """Undo any changes made by enterParent.""" DemoNode.exitParent(self) self.set_zoomable(False) nodes = [] for x in (-1,-.5,0,.5,1): node = DemoNode(color=(1,1,1,1)) node.reparentTo(zcanvas.home) node.set_zoomable(True) node.setPos(x,0,0) node.setScale(.7) nodes.append(node) for node in nodes: childnode = ChildNode(color=(0,0,0,0)) childnode.reparentTo(node.np) childnode.setScale(.33) base.accept('mouse1',zcanvas.zoomTo) base.accept('mouse3',zcanvas.zoomToParent) zcanvas.message('Left click on something to focus it (zoom in on it).\nRight-click to zoom back out.\nObjects change color depending on whether you are focused on\nthem (blue), their parent element (red),\none of their sibling elements (green), or nothing (white or black).',duration=10) run()
znode = ZNode(magnification=.9) znode.reparentTo(zcanvas.home) znode.set_zoomable(True) znode.setPos(-.7, 0, 0) znode = ZNode(magnification=.7) znode.reparentTo(zcanvas.home) znode.set_zoomable(True) znode.setPos(.7, 0, 0) parent = None for i in range(4): znode = ZNode() if parent is not None: znode.reparentTo(parent.np) else: znode.reparentTo(zcanvas.home) znode.set_zoomable(True) znode.setScale(.9) znode.setColor(i / 3.0, i / 3.0, i / 3.0, 1) parent = znode base.accept('mouse1', zcanvas.zoomTo) base.accept('mouse3', zcanvas.zoomToParent) zcanvas.message( 'Left-click on a znode to zoom in on it.\n Right-click to zoom out to the parent node or back to home.\n The thing in the middle is four znodes on top of eachother.' ) run()
cm = CardMaker('cm') cm.setFrame(-.2,.2,-.2,.2) def __init__(self): ZNode.__init__(self,geomnode = DemoItem.cm.generate()) # FIXME. Currently highlightable only works when zoomable. self.set_zoomable(True) Highlightable.__init__(self) self.set_highlightable(True) Draggable.__init__(self) self.set_draggable(True) for i in range(5): b = Box(geomnode=DemoItem.cm.generate()) b.setPos(i*0.5-1,0,0.5) b.reparentTo(zcanvas.home) d = DemoItem() d.setPos(i*0.5-1,0,-0.5) d.reparentTo(zcanvas.home) base.accept('mouse1',zcanvas.drag) base.accept('mouse1-up',zcanvas.drop) zcanvas.message( """Drag the demo items (in white) and drop them onto the boxes (in black).""" ) run()
class Controller(Receiver): def __init__(self): m = StoryMap(storyCardClass=FocusableChoosableStoryCard, title="Story Cards") m.fill() m.setScale(0.02) m.setPos(-0.5, 0, 0.8) m.reparentTo(zcanvas.home) n = StoryMap(storyCardClass=FocusableEditableStoryCard, title="My Story") n.setScale(0.02) n.setPos(-0.5, 0, -0.1) n.reparentTo(zcanvas.home) n.title["state"] = DGG.NORMAL controller = Controller() base.accept("mouse2", zcanvas.zoomTo) base.accept("mouse3", zcanvas.zoomToParent) base.accept("mouse1", zcanvas.drag) base.accept("mouse1-up", zcanvas.drop) zcanvas.message("""Drag and drop StoryCards between StoryMaps, and zoom around.""") base.setFrameRateMeter(True) run()
DemoNode.enterParent(self) self.set_zoomable(True) def exitParent(self): """Undo any changes made by enterParent.""" DemoNode.exitParent(self) self.set_zoomable(False) nodes = [] for x in (-1, -.5, 0, .5, 1): node = DemoNode(color=(1, 1, 1, 1)) node.reparentTo(zcanvas.home) node.set_zoomable(True) node.setPos(x, 0, 0) node.setScale(.7) nodes.append(node) for node in nodes: childnode = ChildNode(color=(0, 0, 0, 0)) childnode.reparentTo(node.np) childnode.setScale(.33) base.accept('mouse1', zcanvas.zoomTo) base.accept('mouse3', zcanvas.zoomToParent) zcanvas.message( 'Left click on something to focus it (zoom in on it).\nRight-click to zoom back out.\nObjects change color depending on whether you are focused on\nthem (blue), their parent element (red),\none of their sibling elements (green), or nothing (white or black).', duration=10) run()
import sys,os,random sys.path.append(os.path.join(sys.path[0],'../zui/')) from box import Box from gridboxlist import GridBoxList from zcanvas import zcanvas from pandac.PandaModules import * import direct.directbase.DirectStart from direct.gui.DirectGui import * gbox = GridBoxList(columns=3,margin=0) gbox.setPos(-.3,0,.3) gbox.reparentTo(zcanvas.home) cm = CardMaker('cm') cm.setFrame(-.1,.1,-.1,.1) for i in range(9): b = Box(geomnode=cm.generate()) gbox.append(b) label = DirectButton(text="Hello.") label.setScale(0.2) b.fill(label) base.accept('mouse1',zcanvas.drag) base.accept('mouse1-up',zcanvas.drop) zcanvas.message( """You can put DirectGUI widgets in boxlists too.""" ) run()
s.setPos((i%3)*0.4-.5,0,-(i/3)*0.5+.25) s.reparentTo(zcanvas.home) self.storycards.append(s) self.acceptOnce('zoom done',zcanvas.message,'Right-click to zoom back out again.') self.accept('add',self.add) self.accept('remove',self.remove) def add(self,card): zcanvas.message('Add button was pressed on card "'+card.function.name+'"') def remove(self,card): zcanvas.message('Remove button was pressed on card "'+card.function.name+'"') controller = Controller() base.accept('mouse1',zcanvas.zoomTo) base.accept('mouse3',zcanvas.zoomToParent) base.accept('mouse2',zcanvas.drag) base.accept('mouse2-up',zcanvas.drop) zcanvas.message( """Mouse-over to highlight a StoryCard, left-click to focus (zoom in on) it, middle-click to drag it.""" ) run()
def add(self,card): zcanvas.message('Add button was pressed on card "'+card.function.name+'"')
def remove(self,card): zcanvas.message('Remove button was pressed on card "'+card.function.name+'"')
"""Demo of znode with the highlightable mixin. Mouse-over the znodes to see them highlight and unhighlight.""" import sys, os, random sys.path.append(os.path.join(sys.path[0], '../zui/')) from znode import ZNode, Highlightable from zcanvas import zcanvas from pandac.PandaModules import * import direct.directbase.DirectStart class DemoNode(ZNode, Highlightable): """A class that just mixes in highlightable with znode.""" def __init__(self): ZNode.__init__(self) Highlightable.__init__(self) for x in (-1, -.5, 0, .5, 1): node = DemoNode() node.reparentTo(zcanvas.home) node.set_highlightable(True) node.setPos(x, 0, 0) node.setScale(.7) zcanvas.message( 'Move the mouse cursor over the items and watch them highlight.') run()
from pandac.PandaModules import * import direct.directbase.DirectStart znode = ZNode(magnification=.9) znode.reparentTo(zcanvas.home) znode.set_zoomable(True) znode.setPos(-.7,0,0) znode = ZNode(magnification=.7) znode.reparentTo(zcanvas.home) znode.set_zoomable(True) znode.setPos(.7,0,0) parent = None for i in range(4): znode = ZNode() if parent is not None: znode.reparentTo(parent.np) else: znode.reparentTo(zcanvas.home) znode.set_zoomable(True) znode.setScale(.9) znode.setColor(i/3.0,i/3.0,i/3.0,1) parent = znode base.accept('mouse1',zcanvas.zoomTo) base.accept('mouse3',zcanvas.zoomToParent) zcanvas.message('Left-click on a znode to zoom in on it.\n Right-click to zoom out to the parent node or back to home.\n The thing in the middle is four znodes on top of eachother.') run()
cm = CardMaker('cm') cm.setFrame(-.2, .2, -.2, .2) def __init__(self): ZNode.__init__(self, geomnode=DemoItem.cm.generate()) # FIXME. Currently highlightable only works when zoomable. self.set_zoomable(True) Highlightable.__init__(self) self.set_highlightable(True) Draggable.__init__(self) self.set_draggable(True) for i in range(5): b = Box(geomnode=DemoItem.cm.generate()) b.setPos(i * 0.5 - 1, 0, 0.5) b.reparentTo(zcanvas.home) d = DemoItem() d.setPos(i * 0.5 - 1, 0, -0.5) d.reparentTo(zcanvas.home) base.accept('mouse1', zcanvas.drag) base.accept('mouse1-up', zcanvas.drop) zcanvas.message("""Drag the demo items (in white) and drop them onto the boxes (in black).""") run()
""" import sys, os, random sys.path.append(os.path.join(sys.path[0], '../zui/')) from box import Box from gridboxlist import GridBoxList from zcanvas import zcanvas from pandac.PandaModules import * import direct.directbase.DirectStart from direct.gui.DirectGui import * gbox = GridBoxList(columns=3, margin=0) gbox.setPos(-.3, 0, .3) gbox.reparentTo(zcanvas.home) cm = CardMaker('cm') cm.setFrame(-.1, .1, -.1, .1) for i in range(9): b = Box(geomnode=cm.generate()) gbox.append(b) label = DirectButton(text="Hello.") label.setScale(0.2) b.fill(label) base.accept('mouse1', zcanvas.drag) base.accept('mouse1-up', zcanvas.drop) zcanvas.message("""You can put DirectGUI widgets in boxlists too.""") run()