import pyglet
from pyglet import shapes
from pyglet.shapes import BorderedRectangle
from pyglet.window import key
def init():
display = pyglet.canvas.get_display()
# for screen in display.get_screens():
# print(screen)
screen = display.get_screens()[0]
config = pyglet.gl.Config(double_buffer=True)
return pyglet.window.Window(screen = screen, config=config, resizable=True)
window = init()
batch = pyglet.graphics.Batch()
box_list = []
drawing_box = False
rectangle = None
box_position = [0,0,0,0]
X = 0
Y = 1
W = 2
H = 3
def getSelected(x, y):
pass
@window.event
def on_draw():
window.clear()
batch.draw()
pyglet.gl.glFlush()
@window.event
def on_resize(width, height):
print(f"window resized width: {width} and height: {height}")
@window.event
def on_key_press(symbol, modifiers):
print(f"key: {chr(symbol)} pressed with modifier: {modifiers}")
return True
@window.event
def on_key_release(symbol, modifiers):
global drawing_box
global rectangle
#print(f"this keys: {chr(symbol)} and modifiers: {modifiers} are no longer pressed")
if (drawing_box == True):
drawing_box = False
if box_position[W] < 0:
box_position[X] = box_position[X] + box_position[W]
box_position[W] = -box_position[W]
if box_position[H] < 0:
box_position[Y] = box_position[Y] + box_position[H]
box_position[H] = -box_position[H]
rectangle = shapes.BorderedRectangle(box_position[0], box_position[1], box_position[2], box_position[3],
border=3, color=(200, 200, 200),
border_color=(255, 255, 255), batch=batch)
rectangle.opacity = 100
box_list.append(rectangle)
rectangle = None
@window.event
def on_mouse_press(x, y, button, modifiers):
#print(f"button : {button} at ({x},{y}) modifiers: {modifiers}")
global drawing_box
global box_position
if(modifiers == key.MOD_SHIFT):
drawing_box = True
box_position[0] = x
box_position[1] = y
else:
selected = getSelected(x, y)
import inspect
@window.event
def on_mouse_drag(x, y, dx, dy, buttons, modifiers):
#print(f"mouse dragging at x: {x}, y: {y} button: {buttons} and modifier: {modifiers} are pressed")
global drawing_box
global box_position
global rectangle
if drawing_box == True:
box_position[2] = x-box_position[0]
box_position[3] = y -box_position[1]
rectangle = shapes.BorderedRectangle(box_position[0], box_position[1], box_position[2], box_position[3],
border=3,color=(200,200,200),border_color=(255, 255, 255), batch=batch)
rectangle.opacity = 100
if __name__ == "__main__":
pyglet.app.run()
#attrs = vars(rectangle)
# {'kids': 0, 'name': 'Dog', 'color': 'Spotted', 'age': 10, 'legs': 2, 'smell': 'Alot'}
# now dump this in some way or another
#print(', '.join("%s: %s" % item for item in attrs.items()))
#print(inspect.getmembers(BorderedRectangle, predicate=inspect.isfunction))