Пример #1
0
 def onMouseWheel(self, event):
     if event.type in self.event.events:
         r = self.canvas.getBoundingClientRect()
         x = event.clientX - round(r.left)
         y = event.clientY - round(r.top)
         self.event._updateQueue(self.evt[event.type](event, x, y))
     DOM.eventPreventDefault(event)
Пример #2
0
 def onKeyDown(self, sender, keycode, mods):
     event = DOM.eventGetCurrentEvent()
     if event.key in self.modKey:
         self.event.keyPress[self.modKey[event.key]] = True
     if event.type in self.event.events:
         if not self._isPaused(event.key):
             self.event._updateQueue(self.evt[event.type](event))
     DOM.eventPreventDefault(event)
Пример #3
0
 def set_visible(self, visible):
     """
     Set visibility of mouse cursor. Return bool of previous state.
     """
     visible_pre = self._cursorVisible
     if visible:
         DOM.setStyleAttribute(env.canvas.getElement(), 'cursor', self._cursor)
         self._cursorVisible = True
     else:
         DOM.setStyleAttribute(env.canvas.getElement(), 'cursor', 'none')
         self._cursorVisible = False
     return visible_pre
Пример #4
0
 def set_visible(self, visible):
     """
     Set visibility of mouse cursor. Return bool of previous state.
     """
     visible_pre = self._cursorVisible
     if visible:
         DOM.setStyleAttribute(env.canvas.getElement(), 'cursor',
                               self._cursor)
         self._cursorVisible = True
     else:
         DOM.setStyleAttribute(env.canvas.getElement(), 'cursor', 'none')
         self._cursorVisible = False
     return visible_pre
Пример #5
0
 def _onKeyDown(self, sender, keycode, mods):
     event = DOM.eventGetCurrentEvent()
     if keycode in self.modKeyCode:
         self.event.keyPress[keycode] = True
     if event.type in self.event.events:
         if not self._isPaused(keycode):
             self.event.keyCode = keycode
             if keycode in self.specialKeyCode:
                 self.event._updateQueue(self.evt[event.type](event,
                                                              keycode))
                 DOM.eventPreventDefault(event)
         else:
             DOM.eventPreventDefault(event)
Пример #6
0
 def _onKeyUp(self, sender, keycode, mods):
     event = DOM.eventGetCurrentEvent()
     if keycode in self.modKeyCode:
         self.event.keyPress[keycode] = False
     if keycode in self.keyHeld:
         self.keyHeld[keycode]['pressed'] = False
     if event.type in self.event.events:
         self.event._updateQueue(self.evt[event.type](event, keycode))
Пример #7
0
 def onKeyUp(self, sender, keycode, mods):
     event = DOM.eventGetCurrentEvent()
     if event.key in self.modKey:
         self.event.keyPress[self.modKey[event.key]] = False
     if event.key in self.keyHeld:
         self.keyHeld[event.key]['pressed'] = False
     if event.type in self.event.events:
         self.event._updateQueue(self.evt[event.type](event))
Пример #8
0
 def set_cursor(self, *cursor):
     """
     Set mouse cursor.
     Alternative arguments:
     * system cursor or cursor object
     * image url or surface, hotspot (x,y), and optional fallback
     * size, hotspot, data, mask, and optional fallback
     Refer to pyjsdl.cursors for details.
     """
     args = len(cursor)
     if args == 1:
         self._cursor = cursor[0]
     elif args in (2, 3):
         if isinstance(cursor[0], str):
             url = cursor[0]
         else:
             url = cursor[0].toDataURL()
         hotspot = cursor[1]
         if args == 2:
             fallback = 'default'
         else:
             fallback = cursor[2]
         self._cursor = 'url({}) {} {}, {}'.format(url, hotspot[0],
                                                   hotspot[1], fallback)
     elif args in (4, 5):
         size = cursor[0]
         hotspot = cursor[1]
         data = cursor[2]
         mask = cursor[3]
         if args == 4:
             fallback = 'default'
         else:
             fallback = cursor[4]
         surface = cursors.create_cursor(size, data, mask)
         url = surface.toDataURL()
         self._cursor = 'url({}) {} {}, {}'.format(url, hotspot[0],
                                                   hotspot[1], fallback)
     else:
         self._cursor = 'default'
     if self._cursorVisible:
         DOM.setStyleAttribute(env.canvas.getElement(), 'cursor',
                               self._cursor)
Пример #9
0
 def _onMouseWheelY(self, sender, velocity):
     event = DOM.eventGetCurrentEvent()
     if velocity < 0:
         button = 4
         events = velocity / -3
     else:
         button = 5
         events = velocity / 3
     event.btn = button
     event.pos = (self.event.mouseMove['x'], self.event.mouseMove['y'])
     for evt in range(events):
         self.event._updateQueue(event)
Пример #10
0
 def _onMouseWheelY(self, sender, velocity):
     event = DOM.eventGetCurrentEvent()
     if velocity < 0:
         button = 4
         events = velocity / -3
     else:
         button = 5
         events = velocity / 3
     event.btn = button
     event.pos = (self.event.mouseMove['x'], self.event.mouseMove['y'])
     for evt in range(events):
         self.event._updateQueue(event)
Пример #11
0
 def set_cursor(self, *cursor):
     """
     Set mouse cursor.
     Alternative arguments:
     * system cursor or cursor object
     * image url or surface, hotspot (x,y), and optional fallback
     * size, hotspot, data, mask, and optional fallback
     Refer to pyjsdl.cursors for details.
     """
     args = len(cursor)
     if args == 1:
         self._cursor = cursor[0]
     elif args in (2,3):
         if isinstance(cursor[0], str):
             url = cursor[0]
         else:
             url = cursor[0].toDataURL()
         hotspot = cursor[1]
         if args == 2:
             fallback = 'default'
         else:
             fallback = cursor[2]
         self._cursor = 'url("%s") %d %d, %s' % (url, hotspot[0], hotspot[1], fallback)
     elif args in (4,5):
         size = cursor[0]
         hotspot = cursor[1]
         data = cursor[2]
         mask = cursor[3]
         if args == 4:
             fallback = 'default'
         else:
             fallback = cursor[4]
         surface = cursors.create_cursor(size, data, mask)
         url = surface.toDataURL()
         self._cursor = 'url("%s") %d %d, %s' % (url, hotspot[0], hotspot[1], fallback)
     else:
         self._cursor = 'default'
     if self._cursorVisible:
         DOM.setStyleAttribute(env.canvas.getElement(), 'cursor', self._cursor)
Пример #12
0
 def onMouseMove(self, sender, x, y):
     event = DOM.eventGetCurrentEvent()
     if event.type in self.event.events:
         if not self.mouse_entered:
             self.event.mouseMovePre['x'] = self.event.mouseMove['x']
             self.event.mouseMovePre['y'] = self.event.mouseMove['y']
         else:
             self.event.mouseMovePre['x'] = x
             self.event.mouseMovePre['y'] = y
             self.mouse_entered = False
         self.event._updateQueue(self.evt[event.type](event, x, y))
     self.event.mouseMove['x'] = x
     self.event.mouseMove['y'] = y
Пример #13
0
 def onMouseWheel(self, sender, velocity):
     event = DOM.eventGetCurrentEvent()
     if event.type == 'mousewheel':
         #TODO: update for changes in mousewheel implementation
         if hasattr(event, 'wheelDeltaX'):
             self.onMouseWheel = self._onMouseWheel
             self._onMouseWheel(sender, velocity)
         else:
             self.onMouseWheel = self._onMouseWheelY
             DOM.eventGetMouseWheelVelocityY = eventGetMouseWheelVelocityY
             self._onMouseWheelY(sender, eventGetMouseWheelVelocityY(event))
     else:  #DOMMouseScroll
         self.onMouseWheel = self._onMouseScroll
         self._onMouseScroll(sender, velocity)
Пример #14
0
 def onMouseWheel(self, sender, velocity):
     event = DOM.eventGetCurrentEvent()
     if event.type == 'mousewheel':
         #TODO: update for changes in mousewheel implementation
         if hasattr(event, 'wheelDeltaX'):
             self.onMouseWheel = self._onMouseWheel
             self._onMouseWheel(sender, velocity)
         else:
             self.onMouseWheel = self._onMouseWheelY
             DOM.eventGetMouseWheelVelocityY = eventGetMouseWheelVelocityY
             self._onMouseWheelY(sender, eventGetMouseWheelVelocityY(event))
     else:       #DOMMouseScroll
         self.onMouseWheel = self._onMouseScroll
         self._onMouseScroll(sender, velocity)
Пример #15
0
 def _onMouseScroll(self, sender, velocity):
     event = DOM.eventGetCurrentEvent()
     if velocity > 1 or velocity < -1:
         if velocity < 0:
             button = 4
         else:
             button = 5
     else:
         if velocity < 0:
             button = 6
         else:
             button = 7
     event.btn = button
     event.pos = (self.event.mouseMove['x'], self.event.mouseMove['y'])
     self.event._updateQueue(event)
Пример #16
0
 def _onMouseScroll(self, sender, velocity):
     event = DOM.eventGetCurrentEvent()
     if velocity > 1 or velocity < -1:
         if velocity < 0:
             button = 4
         else:
             button = 5
     else:
         if velocity < 0:
             button = 6
         else:
             button = 7
     event.btn = button
     event.pos = (self.event.mouseMove['x'], self.event.mouseMove['y'])
     self.event._updateQueue(event)
Пример #17
0
 def onKeyDown(self, sender, keycode, modifiers):
     if keycode in self.modKey:
         event = DOM.eventGetCurrentEvent()
         self.event.keyPress[keycode] = True
         self.event._updateQueue(event)
         DOM.eventPreventDefault(event)
     elif keycode in self.specialKey:
         event = DOM.eventGetCurrentEvent()
         self.event._updateQueue(event)
         DOM.eventPreventDefault(event)
Пример #18
0
 def onKeyDown(self, sender, keycode, modifiers):
     if keycode in self.modKey:
         event = DOM.eventGetCurrentEvent()
         self.event.keyPress[keycode] = True
         self.event._updateQueue(event)
         DOM.eventPreventDefault(event)
     elif keycode in self.specialKey:
         event = DOM.eventGetCurrentEvent()
         self.event._updateQueue(event)
         DOM.eventPreventDefault(event)
Пример #19
0
 def onMouseUp(self, sender, x, y):
     event = DOM.eventGetCurrentEvent()
     event.pos = (x, y)
     self.event.mousePress[event.button] = False
     self.event._updateQueue(event)
Пример #20
0
 def onMouseMove(self, sender, x, y):
     event = DOM.eventGetCurrentEvent()
     event.pos = (x, y)
     self.event.mouseMove['x'], self.event.mouseMove['y'] = x, y
     self.event._updateQueue(event)
Пример #21
0
 def onKeyUp(self, sender, keycode, modifiers):
     event = DOM.eventGetCurrentEvent()
     if keycode in self.modKey:
         self.event.keyPress[keycode] = False
     self.event._updateQueue(event)
Пример #22
0
 def onKeyPress(self, sender, keycode, modifiers):
     event = DOM.eventGetCurrentEvent()
     if not (event.keyCode and event.keyCode in self.specialKey):
         self.event._updateQueue(event)
     DOM.eventPreventDefault(event)
Пример #23
0
 def _onKeyPress(self, sender, keycode, mods):
     event = DOM.eventGetCurrentEvent()
     if event.type in self.event.events:
         self.event.keyPressCode[self.event.keyCode] = keycode
         self.event._updateQueue(self.evt[event.type](event, keycode))
     event.preventDefault()
Пример #24
0
 def onMouseUp(self, sender, x, y):
     event = DOM.eventGetCurrentEvent()
     event.pos = (x, y)
     self.event.mousePress[event.button] = False
     self.event._updateQueue(event)
Пример #25
0
 def onMouseMove(self, sender, x, y):
     event = DOM.eventGetCurrentEvent()
     event.pos = (x, y)
     self.event.mouseMove['x'], self.event.mouseMove['y'] = x, y
     self.event._updateQueue(event)
Пример #26
0
 def onKeyPress(self, sender, keycode, modifiers):
     event = DOM.eventGetCurrentEvent()
     if not (event.keyCode and event.keyCode in self.specialKey):
         self.event._updateQueue(event)
     DOM.eventPreventDefault(event)
Пример #27
0
 def onKeyUp(self, sender, keycode, modifiers):
     event = DOM.eventGetCurrentEvent()
     if keycode in self.modKey:
         self.event.keyPress[keycode] = False
     self.event._updateQueue(event)
Пример #28
0
 def onMouseUp(self, sender, x, y):
     event = DOM.eventGetCurrentEvent()
     if event.type in self.event.events:
         self.event._updateQueue(self.evt[event.type](event, x, y))
     self.event.mousePress[event.button] = False