Compare commits

..

No commits in common. "79853af1c4e575240128b586f728b5ab6b1fe8d9" and "c8814887ad53db0ea0932284a115b7cfb0d364d7" have entirely different histories.

3 changed files with 3 additions and 51 deletions

View file

@ -10,7 +10,7 @@ pip install pyglet-cornerpin
## Usage ## Usage
Create instance for a window, and register the event handlers for dragging the pins. A `on_key_release` is also registered to handle keyboard controls to move the pins. Create instance for a window, and register the event handlers for dragging the pins.
```python ```python
@ -46,5 +46,3 @@ pins = PygletCornerPin(window, corners)
``` ```
Run [pattern.py](examples/pattern.py) in the examples folder for a demo. Run [pattern.py](examples/pattern.py) in the examples folder for a demo.
To use the keyboard, select a pin with number keys 1-4, the use the arrow keys (optionally with ctrl/shift modifier) to move the handle.

View file

@ -1,5 +1,5 @@
import pyglet import pyglet
from pyglet_cornerpin import PygletCornerPin from pyglet_corner_pin import PygletCornerPin
window = pyglet.window.Window() window = pyglet.window.Window()

View file

@ -96,7 +96,6 @@ class PygletCornerPin(pyglet.event.EventDispatcher):
self.handles = [ self.handles = [
pyglet.shapes.Arc(c[0],c[1],20, thickness=2, color=(0,0,255,255), batch=self.batch) for c in self.corners pyglet.shapes.Arc(c[0],c[1],20, thickness=2, color=(0,0,255,255), batch=self.batch) for c in self.corners
] ]
self.current_corner = None
def update_handles(self): def update_handles(self):
for i, c in enumerate(self.corners): for i, c in enumerate(self.corners):
@ -149,52 +148,7 @@ class PygletCornerPin(pyglet.event.EventDispatcher):
self.corners[self.dragging][0] = x self.corners[self.dragging][0] = x
self.corners[self.dragging][1] = y self.corners[self.dragging][1] = y
self.update_view() self.update_view()
def on_key_release(self, symbol: int, modifiers: int):
if symbol not in [
pyglet.window.key._1, pyglet.window.key._2, pyglet.window.key._3, pyglet.window.key._4,
pyglet.window.key.ESCAPE,
pyglet.window.key.UP, pyglet.window.key.DOWN, pyglet.window.key.LEFT, pyglet.window.key.RIGHT,
]:
return pyglet.event.EVENT_UNHANDLED
if symbol == pyglet.window.key._1:
self.current_corner = 2
if symbol == pyglet.window.key._2:
self.current_corner = 3
if symbol == pyglet.window.key._3:
self.current_corner = 0
if symbol == pyglet.window.key._4:
self.current_corner = 1
if symbol == pyglet.window.key.ESCAPE:
self.current_corner = None
for i, h in enumerate(self.handles):
h.color = (255,0,0,255) if i == self.current_corner else (0,0,255,255)
if self.current_corner is None:
return
if symbol not in [pyglet.window.key.UP,pyglet.window.key.DOWN, pyglet.window.key.LEFT, pyglet.window.key.RIGHT]:
return
base = 2
if modifiers & pyglet.window.key.MOD_SHIFT:
base += 10
if modifiers & pyglet.window.key.MOD_CTRL:
base *= 2
if symbol == pyglet.window.key.RIGHT:
self.corners[self.current_corner][0] += base
if symbol == pyglet.window.key.LEFT:
self.corners[self.current_corner][0] -= base
if symbol == pyglet.window.key.UP:
self.corners[self.current_corner][1] += base
if symbol == pyglet.window.key.DOWN:
self.corners[self.current_corner][1] -= base
self.update_view()
def update_view(self): def update_view(self):
self.window.view = self.transform2d_matrix(*[x for c in self.corners for x in c]) self.window.view = self.transform2d_matrix(*[x for c in self.corners for x in c])