diff --git a/direct/src/gui/DirectEntryScroll.py b/direct/src/gui/DirectEntryScroll.py index 0cd7c3ea21..fd369b2716 100644 --- a/direct/src/gui/DirectEntryScroll.py +++ b/direct/src/gui/DirectEntryScroll.py @@ -29,19 +29,41 @@ class DirectEntryScroll(DirectFrame): # frameSize = (-0.006, 3.2, -0.015, 0.036), # if you need to scale the entry scale it's parent instead - self.entry = entry self.canvas = NodePath(self.guiItem.getCanvasNode()) - self.entry.reparentTo(self.canvas) self.canvas.setPos(0,0,0) - self.entry.bind(DGG.CURSORMOVE,self.cursorMove) + self.entry = None + if entry is not None: + self.entry = entry + self.entry.reparentTo(self.canvas) + self.entry.bind(DGG.CURSORMOVE, self.cursorMove) self.canvas.node().setBounds(OmniBoundingVolume()) self.canvas.node().setFinal(1) self.resetCanvas() + def setEntry(self, entry): + """ + Sets a DirectEntry element for this scroll frame. A DirectEntryScroll + can only hold one entry at a time, so make sure to not call this + function twice or call clearEntry before to make sure no entry + is already set. + """ + assert self.entry is None, "An entry was already set for this DirectEntryScroll element" + self.entry = entry + self.entry.reparentTo(self.canvas) + self.entry.bind(DGG.CURSORMOVE, self.cursorMove) + def clearEntry(self): + """ + detaches and unbinds the entry from the scroll frame and its + events. You'll be responsible for destroying it. + """ + if self.entry is None: return + self.entry.unbind(DGG.CURSORMOVE) + self.entry.detachNode() + self.entry = None def cursorMove(self, cursorX, cursorY): cursorX = self.entry.guiItem.getCursorX() * self.entry['text_scale'][0]