def mouseReleaseEvent(self, event): btn = event.button() if btn == QtCore.Qt.LeftButton: self.inputDevice.buttonUp(MouseButton.one()) elif btn == QtCore.Qt.MiddleButton: self.inputDevice.buttonUp(MouseButton.two()) elif btn == QtCore.Qt.RightButton: self.inputDevice.buttonUp(MouseButton.three()) QtWidgets.QWidget.mouseReleaseEvent(self, event)
def wheelEvent(self, event): ang = event.angleDelta().y() if ang > 0: self.inputDevice.buttonDown(MouseButton.wheelUp()) self.inputDevice.buttonUp(MouseButton.wheelUp()) else: self.inputDevice.buttonDown(MouseButton.wheelDown()) self.inputDevice.buttonUp(MouseButton.wheelDown()) QtWidgets.QWidget.wheelEvent(self, event)
def mousePressed(self, event): print 'got mouse pressed event from', event.sender if (not self.enabled or event.modifiers.isDown(KeyboardButton.control())): print 'short circuiting' return shiftDown = event.modifiers.isDown(KeyboardButton.shift()) if event.sender == self.engine: if not shiftDown: self.deselectAll() else: self._setEditMode(event.modifiers.isDown(MouseButton.three())) node = event.sender if shiftDown: # Shift-clicking a node toggles its selected state. if node.isSelected(): self.selection.remove(node) node.setSelected(False) else: self.selection.append(node) node.setSelected(True) elif len(self.selection) == 1 and node.isSelected(): # This is already the only node selected. return else: print 'selecting', node self.deselectAll() node.setSelected(True) self.selection.append(node) if self.editMode: self.handle.setClients([NodePath(n) for n in self.selection], self.getSelectionCenter()) else: self.handle.setClients([])
def task_mouse_press_check(self,task): if base.mouseWatcherNode.isButtonDown(MouseButton.one()): #if self.multi_select == True: self.anchor_x,self.anchor_y = self.model.getX(),self.model.getY() taskMgr.add(self.task_mouse_place, "multibox") return task.done return task.again
def mouseTask (self, task): mw = base.mouseWatcherNode wp = WindowProperties() hasMouse = mw.hasMouse() if hasMouse and mw.is_button_down(MouseButton.one()): x, y = mw.getMouseX(), mw.getMouseY() if not self.scrolling : self.lastMouseX, self.lastMouseY = x, y self.scrolling = True if self.lastMouseX is not None: dx, dy = x - self.lastMouseX, y - self.lastMouseY else: dx, dy = 0, 0 self.lastMouseX, self.lastMouseY = x, y else: x, y, dx, dy, self.lastMouseX, self.lastMouseY = 0, 0, 0, 0, 0, 0 self.scrolling = False if self.scrolling : self.rotateX += dx * 10 * self.mouseMagnitude self.rotateY -= dy * 10 * self.mouseMagnitude self.camera.setH(self.rotateX) self.camera.setP(self.rotateY) return Task.cont
def task_select_check(self, task): if base.mouseWatcherNode.isButtonDown(MouseButton.one()): #if self.multi_select == True: self.box_x, self.box_y = self.model.getX(), self.model.getY() taskMgr.add(self.draw_multiselect_box, "multibox") return task.done return task.cont
def draw_multiselect_box(self, task): if base.mouseWatcherNode.isButtonDown(MouseButton.one()): self.multi_select = True self.select_box.remove() ls = LineSegs() ls.move_to(self.box_x, self.box_y, 1) ls.draw_to(self.model.getX(), self.box_y, 1) ls.draw_to(self.model.getX(), self.model.getY(), 1) ls.draw_to(self.box_x, self.model.getY(), 1) ls.draw_to(self.box_x, self.box_y, 1) node = ls.create() #text = TextNode('text') #text.setText(str(self.box_x)+","+str(self.box_y)+"\n"+str(self.model.getX())+","+str(self.model.getY())) #textnp = NodePath(text) #textnp.setPos(self.box_x,self.box_y,1) #textnp.setHpr(0,-90,0) #textnp.setScale(20.0) self.select_box = NodePath(node) #textnp.reparentTo(self.select_box) self.select_box.reparentTo(render) return task.cont else: self.select_box.hide() taskMgr.add(self.task_select_check, "updatePicker") return task.done
def task_mouse_press_check(self, task): if base.mouseWatcherNode.isButtonDown(MouseButton.one()): #if self.multi_select == True: self.anchor_x, self.anchor_y = self.model.getX(), self.model.getY() taskMgr.add(self.task_mouse_place, "multibox") return task.done return task.again
def render(task): if base.mouseWatcherNode.hasMouse(): # (-1, -1) would be bottom left, (1, 1) for top-right # convert scale x = base.mouseWatcherNode.getMouseX() x = hw + (x * hw) y = base.mouseWatcherNode.getMouseY() y = hh + (y * hh) z = 0.1 if base.mouseWatcherNode.isButtonDown( MouseButton.one()) else 0.0 rt1.mesh.setShaderInput('smokeSource', (x, y, z)) rt1.buffer.clearRenderTextures() rt1.buffer.addRenderTexture(rt1.B, GraphicsOutput.RTMCopyTexture) rt1.mesh.setShaderInput('bufferTexture', rt1.B) Mesh2.setTexture(rt1.A) base.graphicsEngine.renderFrame() rt1.buffer.addRenderTexture(rt1.A, GraphicsOutput.RTMCopyTexture) rt1.mesh.setShaderInput('bufferTexture', rt1.A) Mesh2.setTexture(rt1.B) return task.cont
def mouseDragTask(self, task): mw = self.mouseWatcherNode if mw.hasMouse(): x = mw.getMouseX() y = mw.getMouseY() if mw.isButtonDown(MouseButton.one()): self.OnMouseMotion(x, y) return Task.cont
def __init__(self): ShowBase.__init__(self) # Initialise the keyboard task. self.disableMouse() self.mouse_anchor = None self.accept("escape", sys.exit) m = self.win.getKeyboardMap() self.key = { "forward": m.getMappedButton("w"), "backward": m.getMappedButton("s"), "left": m.getMappedButton("a"), "right": m.getMappedButton("d"), "mouse1": MouseButton.one(), "mouse3": MouseButton.three() } self.taskMgr.add(self.move, "moveTask") self.reset_acceleration()
def update_camera(self, task): if base.mouseWatcherNode.is_button_down(MouseButton.three()): new_x = base.mouseWatcherNode.getMouseX() new_y = base.mouseWatcherNode.getMouseY() x = self.last_mouse[0] - new_x y = self.last_mouse[1] - new_y self.last_mouse = [new_x, new_y] pivot = self.cam_pivot pivot.set_z(pivot.get_z() + (y * self.move_speed)) pivot.set_h(pivot.get_h() + (x * (self.move_speed * 640))) else: self.last_mouse = [0, 0] return task.cont
def updateStateTask(self, task): if base.mouseWatcherNode.hasMouse(): if base.mouseWatcherNode.isButtonDown(MouseButton.three()): if not self.wasClicked: self.wasClicked = True else: if self.wasClicked: self.wasClicked = False X, Y, Z = self.positions["drone"] new_position = (X, Y, Z+0.05) self.positions["drone"] = new_position self.drone.setPos(*new_position) if base.mouseWatcherNode.isButtonDown(MouseButton.one()): if not self.wasClicked: self.wasClicked = True else: if self.wasClicked: self.wasClicked = False X, Y, Z = self.positions["drone"] new_position = (X, Y, Z-0.05) self.positions["drone"] = new_position self.drone.setPos(*new_position) return Task.cont
def moveCamera( self, task ): is_down = base.mouseWatcherNode.is_button_down if base.mouseWatcherNode.hasMouse(): x = base.mouseWatcherNode.getMouseX() y = base.mouseWatcherNode.getMouseY() if is_down( MouseButton.two() ): dx = self.lastMousePos[0] - x self.ang -= dx #self.ang = max( 0, min( self.ang, math.pi*0.49 ) ) dy = self.lastMousePos[1] - y self.angY -= dy self.angY = max( 0.01, min( self.angY, math.pi ) ) self.lastMousePos = (x,y) speed = self.speed if is_down( self.bSpeed ): speed = speed*3 if self.attachmentNode and self.attached: self.focusPoint = self.attachmentNode.getPos() else: sideways = (is_down(self.bRight)-is_down(self.bLeft))*speed forward = (is_down(self.bForward)-is_down(self.bBackward))*speed quat = Quat() quat.setFromAxisAngle( -180*self.ang/math.pi, LVector3f.unitZ()) rotated = quat.xform( LVector3f( -forward, sideways, 0 )) self.focusPoint += rotated self.focusNode.setPos( self.focusPoint ) radius = self.zoom self.angY = max( 0, min( math.pi*0.4, self.angY ) ) rY = math.sin( self.angY ) self.nodePos = self.focusPoint + LVector3f( rY*math.cos(self.ang)*radius, -rY*math.sin(self.ang)*radius, radius*math.cos( self.angY) ) self.node.setPos( self.nodePos ) self.node.lookAt( self.focusNode, LVector3f.unitZ() ) return Task.cont
def moveCamera(self, task): is_down = base.mouseWatcherNode.is_button_down if base.mouseWatcherNode.hasMouse(): x = base.mouseWatcherNode.getMouseX() y = base.mouseWatcherNode.getMouseY() if is_down(MouseButton.two()): dx = self.lastMousePos[0] - x self.heading += dx * 25 #self.ang = max( 0, min( self.ang, math.pi*0.49 ) ) dy = self.lastMousePos[1] - y self.pitch -= dy * 25 self.pitch = max(self.pitch, -80) self.pitch = min(self.pitch, 80) #self.angY = max( 0.01, min( self.angY, math.pi ) ) self.lastMousePos = (x, y) speed = self.speed if is_down(self.bSpeed): speed = speed * 3 if not self.attached: forward = (is_down(self.bRight) - is_down(self.bLeft)) * speed sideways = -(is_down(self.bForward) - is_down(self.bBackward)) * speed quat = Quat() quat.setFromAxisAngle(self.heading, LVector3f.unitZ()) rotated = quat.xform(LVector3f(-forward, sideways, 0)) self.headingNode.setPos(self.headingNode.getPos() - rotated) #self.angY = max( 0, min( math.pi*0.4, self.angY ) ) #rY = math.sin( self.angY ) #self.nodePos = self.focusPoint + LVector3f( math.sin(self.angY)*math.cos(self.ang)*radius, -math.sin(self.ang)*radius, radius*math.cos( self.angY) ) self.node.lookAt(self.headingNode) self.node.setPos(0, -self.zoom, 0) self.pitchNode.setHpr(0, self.pitch, 0) self.headingNode.setHpr(self.heading, 0, 0) return Task.cont
def task_mouse_place(self,task): if base.mouseWatcherNode.isButtonDown(MouseButton.one()): self.placing_object = True self.place_pos = (self.anchor_x,self.anchor_y) self.line_dir.remove() ls = LineSegs() ls.move_to(self.anchor_x,self.anchor_y,1) ls.draw_to(self.model.getX(),self.model.getY(),1) node = ls.create() angle1 = math.atan2(self.anchor_y - self.anchor_y,self.anchor_x - self.anchor_x+50) angle2 = math.atan2(self.anchor_y - self.model.getY(),self.anchor_x - self.model.getY()); final_angle = angle1-angle2; self.model.setHpr(final_angle,0,0) self.line_dir = NodePath(node) self.line_dir.reparentTo(render) return task.again else: self.line_dir.hide() taskMgr.add(self.task_mouse_press_check, "checkMousePress") return task.done
def updateMousePosition(task): global prevMouseX, prevMouseY if base.mouseWatcherNode.hasMouse(): # (-1, -1) would be bottom left, (1, 1) for top-right x = base.mouseWatcherNode.getMouseX() x = hw + (x * hw) y = base.mouseWatcherNode.getMouseY() y = hh - (y * hh) if x and y: mouseX = x / w mouseY = (h - y) / h if base.mouseWatcherNode.isButtonDown(MouseButton.one()): addDensity(mouseX, mouseY) addVelocity(mouseX, mouseY, mouseX - prevMouseX, mouseY - prevMouseY) prevMouseX = mouseX prevMouseY = mouseY return task.cont
def task_mouse_place(self, task): if base.mouseWatcherNode.isButtonDown(MouseButton.one()): self.placing_object = True self.place_pos = (self.anchor_x, self.anchor_y) self.line_dir.remove() ls = LineSegs() ls.move_to(self.anchor_x, self.anchor_y, 1) ls.draw_to(self.model.getX(), self.model.getY(), 1) node = ls.create() angle1 = math.atan2(self.anchor_y - self.anchor_y, self.anchor_x - self.anchor_x + 50) angle2 = math.atan2(self.anchor_y - self.model.getY(), self.anchor_x - self.model.getY()) final_angle = angle1 - angle2 self.model.setHpr(final_angle, 0, 0) self.line_dir = NodePath(node) self.line_dir.reparentTo(render) return task.again else: self.line_dir.hide() taskMgr.add(self.task_mouse_press_check, "checkMousePress") return task.done
class _beastGlobals(DirectObject): enter = PGButton.getEnterPrefix() exit = PGButton.getExitPrefix() within = PGButton.getWithinPrefix() without = PGButton.getWithoutPrefix() leftPress = PGButton.getPressPrefix() + MouseButton.one().getName() + '-' centerPress = PGButton.getPressPrefix() + MouseButton.two().getName() + '-' rightPress = PGButton.getPressPrefix() + MouseButton.three().getName( ) + '-' leftClick = PGButton.getClickPrefix() + MouseButton.one().getName() + '-' centerClick = PGButton.getClickPrefix() + MouseButton.two().getName() + '-' rightClick = PGButton.getClickPrefix() + MouseButton.three().getName( ) + '-' leftRelease = PGButton.getReleasePrefix() + MouseButton.one().getName( ) + '-' centerRelease = PGButton.getReleasePrefix() + MouseButton.two().getName( ) + '-' rightRelease = PGButton.getReleasePrefix() + MouseButton.three().getName( ) + '-' wheelUp = PGButton.getPressPrefix() + MouseButton.wheelUp().getName() + '-' wheelDown = PGButton.getPressPrefix() + MouseButton.wheelDown().getName( ) + '-' def __init__(self, taskMgr, base): DirectObject.__init__(self) self.taskMgr = taskMgr self.base = base self.setupPoint2d() self.beastPointSize = ConfigVariableDouble('beast-point-size', 1.0).getValue() self.beastPointSizeAuto = ConfigVariableBool('beast-point-size-auto', False).getValue() self.beastRenderBruteForce = ConfigVariableBool( 'beast-render-brute-force', False).getValue() self.beastRenderDebug = ConfigVariableBool('beast-render-debug', False).getValue() self.setPointSize(self.beastPointSize, update=False) self.setPointSizeAuto(self.beastPointSizeAuto, update=False) self.accept('window-event', self.windowEvent) self.originalResolution = (float(self.base.win.getXSize()), float(self.base.win.getYSize())) self.buffer = None #- If bruteForce == False then we will setup beast frame rendering system if self.beastRenderBruteForce == False: self._setupTextureBuffer() taskMgr.add(self.renderTask, 'beastRender', sort=-100000000) self.windowEvent() def _setupTextureBuffer(self): if self.buffer: self.card.remove() self.camera2d.remove() self.base.graphicsEngine.removeWindow(self.buffer) self.buffer = self.base.win.makeTextureBuffer("beastBuffer", self.base.win.getXSize(), self.base.win.getYSize()) self.buffer.setActive(True) self.buffer.getTexture().setOrigFileSize(self.base.win.getXSize(), self.base.win.getYSize()) self.camera2d = self.base.makeCamera2d(self.buffer) self.camera2d.reparentTo(self.point2d.getParent()) cm = CardMaker('beastDisplay') cm.setFrame(-1, 1, -1, 1) cm.setUvRange(self.buffer.getTexture()) self.card = self.base.render2d.attachNewNode(cm.generate()) self.card.setTransparency(TransparencyAttrib.MAlpha) self.card.setTexture(self.buffer.getTexture()) def renderTask(self, task): if self.point2d.getRequiresUpdate(): debug = self.beastRenderBruteForce == False and self.beastRenderDebug == True if debug: print ':beast::render' self.buffer.setActive(True) self.point2d.setRequiresUpdate(False) else: self.buffer.setActive(False) return task.cont def setupPoint2d(self): fakeRender2d = NodePath('render2d') fakeRender2d.setDepthTest(False) fakeRender2d.setDepthWrite(False) fakeRender2d.setMaterialOff(True) fakeRender2d.setTwoSided(True) self.point2d = beastNodePath(PGTop('point2d')) self.point2d.reparentTo(fakeRender2d) self.point2d.node().setMouseWatcher(self.base.mouseWatcherNode) self.p2dTopLeft = self.point2d.attachNewNode('p2dTopLeft') self.p2dTopRight = self.point2d.attachNewNode('p2dTopRight') self.p2dTopCenter = self.point2d.attachNewNode('p2dTopCenter') self.p2dCenterLeft = self.point2d.attachNewNode('p2dCenterLeft') self.p2dCenterRight = self.point2d.attachNewNode('p2dCenterRight') self.p2dBottomLeft = self.point2d.attachNewNode('p2dBottomLeft') self.p2dBottomRight = self.point2d.attachNewNode('p2dBottomRight') self.p2dBottomCenter = self.point2d.attachNewNode('p2dBottomCenter') def getMousePos(self): md = self.win.getPointer(0) x = md.getX() y = md.getY() p = self.point2d.getRelativePoint(self.pixel2d, (x, 0, -y)) return p.getX(), p.getZ() def hasMouse(self): return self.mouseWatcherNode.hasMouse() def getAbsolutePointSize(self): fakePointSize = None if self.getPointSizeAuto(): oldX, oldY = self.originalResolution newX, newY = float(self.win.getXSize()), float(self.win.getYSize()) ratio = newY / oldY fakePointSize = ratio if self.getPointSizeAuto(): ps = fakePointSize else: ps = self.getPointSize() return ps def windowEvent(self, win=None): ps = self.getAbsolutePointSize() x = self.base.win.getXSize() y = self.base.win.getYSize() xActual = (x / ps) yActual = (y / ps) self.point2d.setScale(2.0 / xActual, 1.0, 2.0 / yActual) #- Finish actuals self.p2dTopLeft.setPos(-xActual / 2.0, 1.0, yActual / 2.0) self.p2dTopRight.setPos(xActual / 2.0, 1.0, yActual / 2.0) self.p2dTopCenter.setPos(0, 1.0, yActual / 2.0) self.p2dCenterLeft.setPos(-xActual / 2.0, 1.0, 0.0) self.p2dCenterRight.setPos(xActual / 2.0, 1.0, 0.0) self.p2dBottomLeft.setPos(-xActual / 2.0, 1.0, -yActual / 2.0) self.p2dBottomRight.setPos(xActual / 2.0, 1.0, -yActual / 2.0) self.p2dBottomCenter.setPos(0, 1.0, -yActual / 2.0) if self.beastRenderBruteForce == False: debug = self.beastRenderBruteForce == False and self.beastRenderDebug == True bx = self.buffer.getTexture().getOrigFileXSize() by = self.buffer.getTexture().getOrigFileYSize() cx = self.base.win.getXSize() cy = self.base.win.getYSize() if bx != cx or by != by: if debug: print ':beast::render::resolutionChanged from(%s, %s) to(%s, %s)' % ( bx, by, cx, cy) self._setupTextureBuffer() messenger.send('beast.windowEvent') ''' Point size ''' def getPointSize(self): return self.pointSize def setPointSize(self, value, update=True): self.pointSize = float(value) if update: self.update() ''' Point size auto resolution ''' def setPSAutoResolution(self, x, y): self.originalResolution = (float(base.win.getXSize()), float(base.win.getYSize())) def getPSAutoResolution(self): return self.originalResolution ''' Point size auto ''' def setPointSizeAuto(self, value, update=True): self.pointSizeAuto = bool(value) if update: self.update() def getPointSizeAuto(self): return self.pointSizeAuto def togglePointSizeAuto(self): if self.getPointSizeAuto(): self.setPointSizeAuto(False) else: self.setPointSizeAuto(True) ''' Data folder ''' def getDataFolder(self): if sys.platform.startswith('win'): slash = '\\' else: slash = '/' point = __file__.rindex(slash) f = __file__[:point] + slash + 'data' + slash return Filename().fromOsSpecific(f).getFullpath() ''' Destroy beast now ''' def destroy(self): self.ignoreAll()
def __init__(self, mainWin=base.win, mainCam=base.cam, scene=render): self.lastMousePos = Vec2(-2, -2) self.lastId = 0 self.pressedNode = None self.mDownId = 0 self.idStack = range(1, 256) self.idTable = {} self.aspectRatio = 1 self.checkCursorTask = Task(self.checkCursor, 'checkCursorTask') self.enabled = True self.mouseListeners = [] self.mainCam = mainCam mainCam.node().setCameraMask(BitMask32(1)) tempnode = NodePath(PandaNode('temp node')) tempnode.setShaderAuto() tempnode.setShaderInput('hi_id', Vec4(0, 0, 0, 0), 2) mainCam.node().setInitialState(tempnode.getState()) # Set up a node with the silhouetteGen shader. We'll apply this node's # state to custom cameras below. tempnode.setShader(loader.loadShader('silhouetteGen.sha'), 100) tempnode.setShaderInput('hi_id', Vec4(0, 0, 0, 0), 0) tempnode.setAntialias(AntialiasAttrib.MNone, 100) tempnode.setBin('inactive', 0, 1) initialState = tempnode.getState() tempnode.setBin('opaque', 0, 1) selnodeState = tempnode.getState() # We'll be using this a few times, so make an easy name for it. mainLens = mainCam.node().getLens() # Set up a buffer to which we draw a silhouette of any geometry that # we want to outline. We draw the outline by applying a Sobel edge # detection shader to the contents of this buffer. silhouetteBuffer = mainWin.makeTextureBuffer('silhouetteBuffer', 0, 0) silhouetteBuffer.setClearColor(Vec4(0, 0, 0, 1)) self.silhouetteBuffer = silhouetteBuffer silhouetteCamera = base.makeCamera(silhouetteBuffer, lens=mainLens) silhouetteCamera.node().setScene(scene) silhouetteCamera.node().setInitialState(initialState) silhouetteCamera.node().setTagState('sel', selnodeState) silhouetteCamera.node().setTagStateKey('sel') silhouetteCamera.node().setCameraMask(BitMask32(8)) tempnode.setShader(loader.loadShader('mousePicker.sha'), 100) selnodeState = tempnode.getState() tempnode.setBin('inactive', 0, 1) initialState = tempnode.getState() # Set up a 1-by-1 buffer to which we'll just render the pixel under # the mouse. selectBuffer = mainWin.makeTextureBuffer('selectBuffer', 1, 1) selectBuffer.setClearColor(Vec4(0, 0, 0, 1)) self.selectBuffer = selectBuffer selectLens = PerspectiveLens() selectLens.setNearFar(mainLens.getNear(), mainLens.getFar()) selectLens.setFocalLength(mainLens.getFocalLength()) selectCamera = base.makeCamera(selectBuffer, lens=selectLens) selectCamera.node().setScene(scene) selectCamera.node().setInitialState(initialState) selectCamera.node().setTagState('sel', selnodeState) selectCamera.node().setTagStateKey('sel') selectCamera.node().setCameraMask(BitMask32(16)) self.selectLens = selectLens self.selectTex = selectBuffer.getTexture() self.selectTex.makeRamImage() self.gsg = mainWin.getGsg() # Set up a texture card to render the silhouette texture with the # Sobel shader, which will draw the edges of the silhouettes. silhouetteCard = silhouetteBuffer.getTextureCard() silhouetteCard.setTransparency(1) inkGen = loader.loadShader('sobel.sha') silhouetteCard.setShader(inkGen) silhouetteCard.setShaderInput('separation', 0.001, 0) silhouetteCard.reparentTo(render2d) self.silhouetteCard = silhouetteCard self.accept(mainWin.getWindowEvent(), self.windowEventHandler) self.accept('mouse1', self.mouseDownHandler, ['l']) self.accept('mouse1-up', self.mouseUpHandler, ['l']) self.accept('mouse3', self.mouseDownHandler, ['r']) self.accept('mouse3-up', self.mouseUpHandler, ['r']) self.buttonWatcher = ButtonWatcher([ KeyboardButton.shift(), KeyboardButton.control(), MouseButton.one(), MouseButton.three(), ]) CameraController.getInstance().addEventHandler(EVT_CAMERA_MODE, self._cameraModeHandler) self.enable(False)
from direct.gui.DirectFrame import DirectFrame from direct.gui.DirectEntry import DirectEntry from direct.gui.DirectScrolledFrame import DirectScrolledFrame from direct.gui.DirectButton import DirectButton from direct.gui.DirectLabel import DirectLabel from panda3d.core import ( LPoint3f, LVecBase3f, LVecBase4f, TransparencyAttrib, TextNode ) from panda3d.core import PGButton, MouseButton DGG.MWUP = PGButton.getPressPrefix() + MouseButton.wheel_up().getName() + '-' DGG.MWDOWN = PGButton.getPressPrefix() + MouseButton.wheel_down().getName() + '-' class DirectFolderBrowser(DirectObject): def __init__(self, command, fileBrowser=False, defaultPath="~", defaultFilename="unnamed.txt", fileExtensions=[], tooltip=None): """ A simple file and folder browser command: The command that will be called on closing the browser fileBrowser: If set to True the browser will show files, otherwise it will only show folders defaultPath: The initial path the browser will be set to show defaultFilename: The filename that will be set by default, only usefull if fileBrowser is True fileExtensions: A list of extensions. Only files with those extensions will be shown. Only usefull if fileBrowser is True tooltip: An instance of the Tooltip class to display tooltips for certain parts of the editor """ self.tt = tooltip
from direct.stdpy.file import open, exists from direct.stdpy import pickle import direct.gui.DirectGuiGlobals as DGG from direct.gui.OnscreenText import OnscreenText from direct.gui.DirectFrame import DirectFrame from direct.gui.DirectButton import DirectButton from direct.gui.DirectScrolledFrame import DirectScrolledFrame from runtime_data import game_settings from sogal_form import SogalForm, SogalDialog from gui.layout import HLayout, VLayout import gui.color_themes as color_themes from sogal_form import ConfirmDialog import runtime_data WHEELUP = PGButton.getReleasePrefix() + MouseButton.wheelUp().getName() + '-' WHEELDOWN = PGButton.getReleasePrefix() + MouseButton.wheelDown().getName( ) + '-' WHEELLEFT = PGButton.getReleasePrefix() + MouseButton.wheelLeft().getName( ) + '-' WHEELRIGHT = PGButton.getReleasePrefix() + MouseButton.wheelRight().getName( ) + '-' #pos = (-0.57,0,0.67) MAX_SAVE = 200 hspacing = 1.33 vspacing = 0.4 FRAMESIZE = (-1.35, 1.35, -0.95, 0.95) LOAD_CANVAS_SIZE = ( -0.05, 2.55, math.ceil(
def __init__(self, name): NodePath.__init__(self, name) DirectObject.__init__(self) self.setPythonTag('Sprite', self) global SpriteCounter SpriteCounter += 1 self.__id = int(SpriteCounter) #- Use PGItem to detect mouse and keyboard input via PGTop (eg, aspect2d, pixel2d, etc) self.__pgItem = PGItem(name) self.__pgItem.setActive(True) self.__pgItemNp = self.attachNewNode(self.__pgItem) #- Use TextNode to generate both text and cards for displaying background images self.__textNode = TextNode(name) self.__textNodeNp = None #self.__textNodeNp = self.attachNewNode(self.__textNode) #self.__textNode.setCardDecal(True) #- This is what we would do, should Sprite support being non-under PGTop self.accept(self.__pgItem.getPressEvent(MouseButton.one()), self.__onMouse, [Sprite.MouseLeftDown]) self.accept(self.__pgItem.getPressEvent(MouseButton.two()), self.__onMouse, [Sprite.MouseCenterDown]) self.accept(self.__pgItem.getPressEvent(MouseButton.three()), self.__onMouse, [Sprite.MouseRightDown]) self.accept(self.__pgItem.getPressEvent(MouseButton.four()), self.__onMouse, [Sprite.MouseFourDown]) self.accept(self.__pgItem.getPressEvent(MouseButton.five()), self.__onMouse, [Sprite.MouseFiveDown]) self.accept(self.__pgItem.getReleaseEvent(MouseButton.one()), self.__onMouse, [Sprite.MouseLeftUp]) self.accept(self.__pgItem.getReleaseEvent(MouseButton.two()), self.__onMouse, [Sprite.MouseCenterUp]) self.accept(self.__pgItem.getReleaseEvent(MouseButton.three()), self.__onMouse, [Sprite.MouseRightUp]) self.accept(self.__pgItem.getReleaseEvent(MouseButton.four()), self.__onMouse, [Sprite.MouseFourUp]) self.accept(self.__pgItem.getReleaseEvent(MouseButton.five()), self.__onMouse, [Sprite.MouseFiveUp]) self.accept(self.__pgItem.getPressEvent(MouseButton.wheelDown()), self.__onMouse, [Sprite.MouseScrollDown]) self.accept(self.__pgItem.getPressEvent(MouseButton.wheelUp()), self.__onMouse, [Sprite.MouseScrollUp]) self.accept(self.__pgItem.getEnterEvent(), self.__onMouse, [Sprite.MouseEnter]) self.accept(self.__pgItem.getExitEvent(), self.__onMouse, [Sprite.MouseExit]) self.accept(self.__pgItem.getWithinEvent(), self.__onMouse, [Sprite.MouseWithin]) self.accept(self.__pgItem.getWithoutEvent(), self.__onMouse, [Sprite.MouseWithout]) self.__beastDebug = ConfigVariableBool('beast-debug', False).getValue() self.__mouseInside = False self.__disabled = False #- Setup state configuration self.__lastStateOptions = None self.__state = None self.__states = { 'default': SpriteOptions(), 'hover': SpriteOptions(), 'click': SpriteOptions(), 'focus': SpriteOptions(), 'disabled': SpriteOptions(), } self.updateToState('default')
class DialogMask(DirectButton): '''used to generate a full-screen mask to prevent button-clicking below the focused window/dialog Added some tricks to make panda3d mouse events still available ''' B1PRESS = PGButton.getPressPrefix() + MouseButton.one().getName() + '-' B2PRESS = PGButton.getPressPrefix() + MouseButton.two().getName() + '-' B3PRESS = PGButton.getPressPrefix() + MouseButton.three().getName() + '-' B4PRESS = PGButton.getPressPrefix() + MouseButton.four().getName() + '-' B5PRESS = PGButton.getPressPrefix() + MouseButton.five().getName() + '-' WHEELUP = PGButton.getReleasePrefix() + MouseButton.wheelUp().getName( ) + '-' WHEELDOWN = PGButton.getReleasePrefix() + MouseButton.wheelDown().getName( ) + '-' WHEELLEFT = PGButton.getReleasePrefix() + MouseButton.wheelLeft().getName( ) + '-' WHEELRIGHT = PGButton.getReleasePrefix() + MouseButton.wheelRight( ).getName() + '-' B1RELEASE = PGButton.getReleasePrefix() + MouseButton.one().getName() + '-' B2RELEASE = PGButton.getReleasePrefix() + MouseButton.two().getName() + '-' B3RELEASE = PGButton.getReleasePrefix() + MouseButton.three().getName( ) + '-' B4RELEASE = PGButton.getReleasePrefix() + MouseButton.four().getName( ) + '-' B5RELEASE = PGButton.getReleasePrefix() + MouseButton.five().getName( ) + '-' def __init__(self): DirectButton.__init__(self, parent=aspect2d, frameColor=(1, 1, 1, 0), relief=DGG.FLAT, commandButtons=[]) self.accept('window-event', self.windowResize) self.windowResize(None) #trick: make this re-throw mouse events self.bind(self.B1PRESS, self.rethrowEvent, ['mouse1']) self.bind(self.B2PRESS, self.rethrowEvent, ['mouse2']) self.bind(self.B3PRESS, self.rethrowEvent, ['mouse3']) self.bind(self.B4PRESS, self.rethrowEvent, ['mouse4']) self.bind(self.B5PRESS, self.rethrowEvent, ['mouse5']) self.bind(self.WHEELUP, self.rethrowEvent, ['wheel_up']) self.bind(self.WHEELDOWN, self.rethrowEvent, ['wheel_down']) self.bind(self.WHEELLEFT, self.rethrowEvent, ['wheel_left']) self.bind(self.WHEELRIGHT, self.rethrowEvent, ['wheel_right']) self.bind(self.B1RELEASE, self.rethrowEvent, ['mouse1-up']) self.bind(self.B2RELEASE, self.rethrowEvent, ['mouse2-up']) self.bind(self.B3RELEASE, self.rethrowEvent, ['mouse3-up']) self.bind(self.B4RELEASE, self.rethrowEvent, ['mouse4-up']) self.bind(self.B5RELEASE, self.rethrowEvent, ['mouse5-up']) def windowResize(self, arg): #fill the screen aspect = base.getAspectRatio() if aspect > 1: self['frameSize'] = (-aspect, aspect, -1, 1) elif aspect: hh = 1.0 / aspect self['frameSize'] = (-1, 1, -hh, hh) def setCommandButtons(self, *args, **kwargs): #inherited pass def rethrowEvent(self, sevent, event): messenger.send(sevent) def destroy(self): self.ignoreAll() DirectButton.destroy(self)
from direct.stdpy import pickle import direct.gui.DirectGuiGlobals as DGG from direct.gui.OnscreenText import OnscreenText from direct.gui.DirectFrame import DirectFrame from direct.gui.DirectButton import DirectButton from direct.gui.DirectScrolledFrame import DirectScrolledFrame from runtime_data import game_settings from sogal_form import SogalForm,SogalDialog from gui.layout import HLayout,VLayout import gui.color_themes as color_themes from sogal_form import ConfirmDialog import runtime_data WHEELUP = PGButton.getReleasePrefix() + MouseButton.wheelUp().getName() + '-' WHEELDOWN = PGButton.getReleasePrefix() + MouseButton.wheelDown().getName() + '-' WHEELLEFT = PGButton.getReleasePrefix() + MouseButton.wheelLeft().getName() + '-' WHEELRIGHT = PGButton.getReleasePrefix() + MouseButton.wheelRight().getName() + '-' #pos = (-0.57,0,0.67) MAX_SAVE = 200 hspacing = 1.33 vspacing = 0.4 FRAMESIZE = (-1.35,1.35,-0.95,0.95) LOAD_CANVAS_SIZE = (-0.05,2.55,math.ceil( -vspacing*(MAX_SAVE +runtime_data.MAX_AUTOSAVE + runtime_data.MAX_QUICKSAVE)/2.0 ) ,vspacing/2) SAVE_CANVAS_SIZE = (-0.05,2.55,math.ceil(-vspacing*MAX_SAVE/2.0) ,vspacing/2) LOAD_ROLL_SPEED = -LOAD_CANVAS_SIZE[2]/5100.0 SAVE_ROLL_SPEED = -SAVE_CANVAS_SIZE[2]/5100.0 AUTO_HIDE_SCROLLBARS = True
def test_mousebutton(): btns = [ MouseButton.one(), MouseButton.two(), MouseButton.three(), MouseButton.four(), MouseButton.five() ] for i, btn in enumerate(btns): assert MouseButton.button(i) == btn assert MouseButton.is_mouse_button(btn) assert MouseButton.button(5) == ButtonHandle.none() assert MouseButton.is_mouse_button(MouseButton.wheel_up()) assert MouseButton.is_mouse_button(MouseButton.wheel_down()) assert MouseButton.is_mouse_button(MouseButton.wheel_left()) assert MouseButton.is_mouse_button(MouseButton.wheel_right())