Tester c'est douter !
This commit is contained in:
parent
4761053142
commit
78ce3a0890
18
.gitignore
vendored
18
.gitignore
vendored
@ -29,3 +29,21 @@
|
|||||||
|
|
||||||
# mpeltonen/sbt-idea plugin
|
# mpeltonen/sbt-idea plugin
|
||||||
.idea_modules/
|
.idea_modules/
|
||||||
|
|
||||||
|
|
||||||
|
# Python cache
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
|
||||||
|
# VirtualEnv
|
||||||
|
.Python
|
||||||
|
[Bb]in
|
||||||
|
[Ii]nclude
|
||||||
|
[Ll]ib
|
||||||
|
[Ll]ib64
|
||||||
|
[Ll]ocal
|
||||||
|
[Ss]cripts
|
||||||
|
pyvenv.cfg
|
||||||
|
.venv
|
||||||
|
*.egg
|
||||||
|
pip-selfcheck.json
|
@ -13,6 +13,8 @@ class automate:
|
|||||||
self.timer = None
|
self.timer = None
|
||||||
self.form = None
|
self.form = None
|
||||||
self.xy = None
|
self.xy = None
|
||||||
|
self.la_xy = None
|
||||||
|
self.ca_xy = None
|
||||||
self.color = None
|
self.color = None
|
||||||
|
|
||||||
def new_geste(self, agent, *larg):
|
def new_geste(self, agent, *larg):
|
||||||
@ -20,10 +22,20 @@ class automate:
|
|||||||
print("state = " + str(self.state))
|
print("state = " + str(self.state))
|
||||||
|
|
||||||
if self.state == 0:
|
if self.state == 0:
|
||||||
|
if larg[0] == "Rectangle" or larg[0] == "Cercle":
|
||||||
self.__reinit_timer()
|
self.__reinit_timer()
|
||||||
self.form = larg[0]
|
self.form = larg[0]
|
||||||
self.state = 1
|
self.state = 1
|
||||||
|
|
||||||
|
elif larg[0] == "Deplacer":
|
||||||
|
self.__reinit_timer()
|
||||||
|
self.state = 4
|
||||||
|
|
||||||
|
elif larg[0] == "Supprimer":
|
||||||
|
self.__reinit_timer()
|
||||||
|
self.state = 7
|
||||||
|
|
||||||
|
|
||||||
print("endstate = " + str(self.state))
|
print("endstate = " + str(self.state))
|
||||||
|
|
||||||
def new_click(self, agent, *larg):
|
def new_click(self, agent, *larg):
|
||||||
@ -40,6 +52,16 @@ class automate:
|
|||||||
self.xy = (larg[0], larg[1])
|
self.xy = (larg[0], larg[1])
|
||||||
self.state = 1
|
self.state = 1
|
||||||
|
|
||||||
|
elif self.state in [4, 5, 6]:
|
||||||
|
self.__reinit_timer()
|
||||||
|
self.xy = (larg[0], larg[1])
|
||||||
|
|
||||||
|
elif self.state == 8:
|
||||||
|
self.__reinit_timer()
|
||||||
|
self.xy = (larg[0], larg[1])
|
||||||
|
self.__maybe_send_delete()
|
||||||
|
self.state = 1
|
||||||
|
|
||||||
print("endstate = " + str(self.state))
|
print("endstate = " + str(self.state))
|
||||||
|
|
||||||
def new_vocal_couleur(self, agent, *larg):
|
def new_vocal_couleur(self, agent, *larg):
|
||||||
@ -52,10 +74,30 @@ class automate:
|
|||||||
self.color = self.list_color[larg[0].split(" ")[0]]
|
self.color = self.list_color[larg[0].split(" ")[0]]
|
||||||
self.state = 3
|
self.state = 3
|
||||||
|
|
||||||
elif self.state == 2:
|
elif self.state == 2 and larg[0].split(" ")[0] in self.list_color and int(larg[0].split(",")[1][0:2]) > 85:
|
||||||
|
print(larg[0].split(" ")[0])
|
||||||
self.__reinit_timer()
|
self.__reinit_timer()
|
||||||
self.color = larg[0]
|
self.color = self.list_color[larg[0].split(" ")[0]]
|
||||||
self.state = 1
|
self.state = 1
|
||||||
|
|
||||||
|
elif self.state == 5 and larg[0].split(" ")[0] in self.list_color and int(larg[0].split(",")[1][0:2]) > 85:
|
||||||
|
print(larg[0].split(" ")[0])
|
||||||
|
self.__reinit_timer()
|
||||||
|
self.color = self.list_color[larg[0].split(" ")[0]]
|
||||||
|
self.state = 5
|
||||||
|
|
||||||
|
elif self.state == 6 and larg[0].split(" ")[0] in self.list_color and int(larg[0].split(",")[1][0:2]) > 85:
|
||||||
|
print(larg[0].split(" ")[0])
|
||||||
|
self.__reinit_timer()
|
||||||
|
self.color = self.list_color[larg[0].split(" ")[0]]
|
||||||
|
self.state = 6
|
||||||
|
|
||||||
|
elif self.state == 7 and larg[0].split(" ")[0] in self.list_color and int(larg[0].split(",")[1][0:2]) > 85:
|
||||||
|
print(larg[0].split(" ")[0])
|
||||||
|
self.__reinit_timer()
|
||||||
|
self.color = self.list_color[larg[0].split(" ")[0]]
|
||||||
|
self.state = 7
|
||||||
|
|
||||||
print("endstate = " + str(self.state))
|
print("endstate = " + str(self.state))
|
||||||
|
|
||||||
def new_vocal_action(self, agent, *larg):
|
def new_vocal_action(self, agent, *larg):
|
||||||
@ -65,28 +107,84 @@ class automate:
|
|||||||
self.__reinit_timer()
|
self.__reinit_timer()
|
||||||
self.__maybe_send_create()
|
self.__maybe_send_create()
|
||||||
self.state = 1
|
self.state = 1
|
||||||
|
|
||||||
|
if self.state == 4 and larg[0].split(" ")[0] == "la":
|
||||||
|
self.__reinit_timer()
|
||||||
|
self.la_xy = self.xy
|
||||||
|
self.state = 6
|
||||||
|
|
||||||
|
if self.state == 4 and larg[0].split(" ")[0] == "ça":
|
||||||
|
self.__reinit_timer()
|
||||||
|
self.ca_xy = self.xy
|
||||||
|
self.state = 5
|
||||||
|
|
||||||
|
if self.state == 5 and larg[0].split(" ")[0] == "la":
|
||||||
|
self.__reinit_timer()
|
||||||
|
self.la_xy = self.xy
|
||||||
|
self.__maybe_send_deplacer()
|
||||||
|
self.state = 4
|
||||||
|
|
||||||
|
if self.state == 7 and larg[0].split(" ")[0] in ("Ce retangle", "Cette ellipse"):
|
||||||
|
self.__reinit_timer()
|
||||||
|
if larg[0].split(" ")[0] == "Ce rectangle":
|
||||||
|
self.form = "RECTANGLE"
|
||||||
|
elif larg[0].split(" ")[0] == "Cette ellipse":
|
||||||
|
self.form = "ELLIPSE"
|
||||||
|
self.__maybe_send_deplacer()
|
||||||
|
self.state = 8
|
||||||
|
|
||||||
print("endstate = " + str(self.state))
|
print("endstate = " + str(self.state))
|
||||||
|
|
||||||
def all(self, agent, *larg):
|
def all(self, agent, *larg):
|
||||||
print("all " + str(larg))
|
print("all " + str(larg))
|
||||||
|
|
||||||
def timeout(self):
|
def __timeout(self):
|
||||||
if self.state == 1:
|
if self.state in [1, 4]:
|
||||||
|
self.form = None
|
||||||
self.state = 0
|
self.state = 0
|
||||||
if self.state in [1, 2]:
|
elif self.state in [2, 3]:
|
||||||
|
self.xy = None
|
||||||
|
self.color = None
|
||||||
self.state = 1
|
self.state = 1
|
||||||
|
|
||||||
|
elif self.state in [5, 6]:
|
||||||
|
self.ca_xy = None
|
||||||
|
self.la_xy = None
|
||||||
|
self.xy = None
|
||||||
|
self.color = None
|
||||||
|
self.state = 4
|
||||||
|
|
||||||
def __reinit_timer(self):
|
def __reinit_timer(self):
|
||||||
pass
|
pass
|
||||||
"""if self.timer:
|
if self.timer:
|
||||||
self.timer.cancel()
|
self.timer.cancel()
|
||||||
self.timer = Timer(5, self.timeout)
|
self.timer = Timer(5, self.__timeout)
|
||||||
self.timer.start()"""
|
self.timer.start()
|
||||||
|
|
||||||
def __maybe_send_create(self):
|
def __maybe_send_create(self):
|
||||||
if None not in [self.form, self.xy, self.color]:
|
if None not in (self.form, self.xy, self.color):
|
||||||
print("Send Forme")
|
print("Send Forme")
|
||||||
IvySendMsg("MULTIMODAL forme={} x={} y={} couleur={}".format(self.form, self.xy[0], self.xy[1], self.color))
|
IvySendMsg("MULTIMODAL:creer forme={} x={} y={} couleur={}".format(self.form, self.xy[0], self.xy[1], self.color))
|
||||||
|
self.xy = None
|
||||||
|
self.color = None
|
||||||
|
|
||||||
|
def __maybe_send_deplacer(self):
|
||||||
|
if None not in (self.la_xy, self.ca_xy):
|
||||||
|
print("Send Forme")
|
||||||
|
IvySendMsg("MULTIMODAL:deplacer ca_x={} ca_y={} la_x={} la_y={} couleur={}"
|
||||||
|
.format(self.ca_xy[0], self.ca_xy[1], self.la_xy[0], self.la_xy[1],
|
||||||
|
self.color if not None else ""))
|
||||||
|
self.ca_xy = None
|
||||||
|
self.la_xy = None
|
||||||
|
self.xy = None
|
||||||
|
self.color = None
|
||||||
|
|
||||||
|
def __maybe_send_delete(self):
|
||||||
|
if None not in (self.form, self.xy):
|
||||||
|
print("Send Forme")
|
||||||
|
IvySendMsg("MULTIMODAL:supprimer forme={} x={} y={} couleur={}"
|
||||||
|
.format(self.form, self.xy[0], self.xy[1],
|
||||||
|
self.color if not None else ""))
|
||||||
self.xy = None
|
self.xy = None
|
||||||
self.color = None
|
self.color = None
|
||||||
|
|
||||||
|
@ -2,31 +2,87 @@ import turtle
|
|||||||
from LibCommon import myIvy
|
from LibCommon import myIvy
|
||||||
from ivy.std_api import *
|
from ivy.std_api import *
|
||||||
|
|
||||||
LIST_FORM = []
|
|
||||||
|
|
||||||
|
|
||||||
class Form:
|
class Form:
|
||||||
def __init__(self, x, y):
|
def __init__(self, t, x, y, color):
|
||||||
|
self.t = t
|
||||||
self.x = x
|
self.x = x
|
||||||
self.y = y
|
self.y = y
|
||||||
|
self.color = color
|
||||||
|
self.color_default = color
|
||||||
|
|
||||||
|
def _setup_draw(self, x, y, color):
|
||||||
|
self.t.penup()
|
||||||
|
self.t.setposition(x, y)
|
||||||
|
self.t.pendown()
|
||||||
|
self.t.color(color, color)
|
||||||
|
self.t.begin_fill()
|
||||||
|
|
||||||
|
def _end_draw(self):
|
||||||
|
self.t.end_fill()
|
||||||
|
self.t.color(self.t.my_turtle_color)
|
||||||
|
self.t.penup()
|
||||||
|
self.t.home()
|
||||||
|
|
||||||
def is_in(self, x, y):
|
def is_in(self, x, y):
|
||||||
return x == self.x and y == self.y
|
return x == self.x and y == self.y
|
||||||
|
|
||||||
|
def draw(self):
|
||||||
|
self._setup_draw(self.x, self.y, self.color)
|
||||||
|
self.t.dot()
|
||||||
|
self._end_draw()
|
||||||
|
|
||||||
class Circle(Form):
|
def delete(self):
|
||||||
def __init__(self, x, y, radius=50, color="red"):
|
self.color = self.t.bgcolor
|
||||||
super().__init__(x, y)
|
self.draw()
|
||||||
|
self.color = self.color_default
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def aim_delete(l_form, type_form, x, y, color=""):
|
||||||
|
for form in l_form:
|
||||||
|
if form.__class__.__name__.upper() == type_form and form.is_in(x, y) \
|
||||||
|
and color in ("", form.color):
|
||||||
|
form.delete()
|
||||||
|
l_form.remove(form)
|
||||||
|
break
|
||||||
|
|
||||||
|
for form in l_form:
|
||||||
|
if form.is_in(x, y):
|
||||||
|
form.draw()
|
||||||
|
return l_form
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def aim_move(l_form, x, y, tx, ty, color=""):
|
||||||
|
for form in l_form:
|
||||||
|
if form.is_in(x, y)\
|
||||||
|
and color in ("", form.color):
|
||||||
|
form.delete()
|
||||||
|
form.x = tx
|
||||||
|
form.y = ty
|
||||||
|
form.draw()
|
||||||
|
break
|
||||||
|
return l_form
|
||||||
|
|
||||||
|
|
||||||
|
class Ellipse(Form):
|
||||||
|
def __init__(self, t, x, y, radius=50, color="red"):
|
||||||
|
super().__init__(t, x, y, color)
|
||||||
self.radius = radius
|
self.radius = radius
|
||||||
self.color = color
|
|
||||||
|
|
||||||
def is_in(self, x, y):
|
def is_in(self, x, y):
|
||||||
return (x - self.x) ** 2 + (y - self.y) ** 2 < self.radius ** 2
|
return (x - self.x) ** 2 + (y - self.y) ** 2 < self.radius ** 2
|
||||||
|
|
||||||
|
def draw(self):
|
||||||
|
self._setup_draw(self.x, self.y, self.color)
|
||||||
|
self.t.circle(self.radius)
|
||||||
|
self._end_draw()
|
||||||
|
|
||||||
|
|
||||||
class Rectangle(Form):
|
class Rectangle(Form):
|
||||||
def __init__(self, x, y, vert=50, hor=80, color="red"):
|
def __init__(self, t, x, y, vert=50, hor=80, color="red"):
|
||||||
super().__init__(x, y)
|
super().__init__(t, x, y, color)
|
||||||
self.vert = vert
|
self.vert = vert
|
||||||
self.hor = hor
|
self.hor = hor
|
||||||
self.color = color
|
self.color = color
|
||||||
@ -34,6 +90,14 @@ class Rectangle(Form):
|
|||||||
def is_in(self, x, y):
|
def is_in(self, x, y):
|
||||||
return 0 <= (x - self.x) <= self.hor and 0 <= (y - self.y) <= self.vert
|
return 0 <= (x - self.x) <= self.hor and 0 <= (y - self.y) <= self.vert
|
||||||
|
|
||||||
|
def draw(self):
|
||||||
|
self._setup_draw(self.x, self.y, self.color)
|
||||||
|
self.t.setposition(self.x + self.hor, self.y)
|
||||||
|
self.t.setposition(self.x + self.hor, self.y + self.vert)
|
||||||
|
self.t.setposition(self.x, self.y + self.vert)
|
||||||
|
self.t.setposition(self.x, self.y)
|
||||||
|
self._end_draw()
|
||||||
|
|
||||||
|
|
||||||
class MyTurtle(turtle.Turtle):
|
class MyTurtle(turtle.Turtle):
|
||||||
def __init__(self, color="green", bgcolor="#FFFFFF"):
|
def __init__(self, color="green", bgcolor="#FFFFFF"):
|
||||||
@ -54,67 +118,35 @@ class MyTurtle(turtle.Turtle):
|
|||||||
self.screen.listen()
|
self.screen.listen()
|
||||||
self.screen.onclick(self.onclick)
|
self.screen.onclick(self.onclick)
|
||||||
|
|
||||||
def __setup_draw(self, x, y, color):
|
|
||||||
self.penup()
|
|
||||||
self.setposition(x, y)
|
|
||||||
self.pendown()
|
|
||||||
self.color("black", color)
|
|
||||||
self.begin_fill()
|
|
||||||
|
|
||||||
def __end_draw(self):
|
|
||||||
self.end_fill()
|
|
||||||
self.color(self.my_turtle_color)
|
|
||||||
self.penup()
|
|
||||||
self.home()
|
|
||||||
|
|
||||||
def draw_circle_here(self, color="red", radius=50):
|
|
||||||
self.draw_circle(Circle(self.xcor(), self.ycor(), radius, color))
|
|
||||||
|
|
||||||
def draw_circle(self, circle):
|
|
||||||
self.__setup_draw(circle.x, circle.y, circle.color)
|
|
||||||
self.circle(circle.radius)
|
|
||||||
self.__end_draw()
|
|
||||||
|
|
||||||
def delete_circle(self, circle):
|
|
||||||
circle.color = self.bgcolor
|
|
||||||
self.draw_rectangle(circle)
|
|
||||||
|
|
||||||
def draw_rectangle_here(self, vert, hor, color="red"):
|
|
||||||
self.draw_rectangle(Rectangle(self.xcor(), self.ycor(), vert, hor, color))
|
|
||||||
|
|
||||||
def draw_rectangle(self, rectangle):
|
|
||||||
self.__setup_draw(rectangle.x, rectangle.y, rectangle.color)
|
|
||||||
self.setposition(rectangle.x + rectangle.hor, rectangle.y)
|
|
||||||
self.setposition(rectangle.x + rectangle.hor, rectangle.y + rectangle.vert)
|
|
||||||
self.setposition(rectangle.x, rectangle.y + rectangle.vert)
|
|
||||||
self.setposition(rectangle.x, rectangle.y)
|
|
||||||
self.__end_draw()
|
|
||||||
|
|
||||||
def delete_rectangle(self, rectangle):
|
|
||||||
rectangle.color = self.bgcolor
|
|
||||||
self.draw_rectangle(rectangle)
|
|
||||||
|
|
||||||
def onclick(self, x, y, **kwargs):
|
def onclick(self, x, y, **kwargs):
|
||||||
myturtle.goto(x, y)
|
myturtle.goto(x, y)
|
||||||
IvySendMsg("PALETTE x={} y={}".format(x, y))
|
IvySendMsg("PALETTE x={} y={}".format(x, y))
|
||||||
|
|
||||||
|
|
||||||
class MyIvyPalette(myIvy.MyIvy):
|
class MyIvyPalette(myIvy.MyIvy):
|
||||||
|
LIST_FORM = []
|
||||||
def _createbind(self):
|
def _createbind(self):
|
||||||
IvyBindMsg(self.create, '^MULTIMODAL forme=(.*) x=(.*) y=(.*) couleur=(.*)')
|
IvyBindMsg(self.create, '^MULTIMODAL:creer forme=(.*) x=(.*) y=(.*) couleur=(.*)')
|
||||||
|
IvyBindMsg(self.move, '^MULTIMODAL:deplacer ca_x=(.*) ca_y=(.*) la_x=(.*) la_y=(.*) couleur=(.*)')
|
||||||
|
IvyBindMsg(self.delete, '^MULTIMODAL:supprimer forme=(.*) x=(.*) y=(.*) couleur=(.*)')
|
||||||
|
|
||||||
def create(self, agent, *larg):
|
def create(self, agent, *larg):
|
||||||
if larg[0] == "RECTANGLE":
|
if larg[0] == "RECTANGLE":
|
||||||
r = Rectangle(self.__my_int(larg[1]), self.__my_int(larg[2]), 200, 100, larg[3])
|
r = Rectangle(myturtle, self.__my_int(larg[1]), self.__my_int(larg[2]), color=larg[3])
|
||||||
myturtle.draw_rectangle(r)
|
r.draw()
|
||||||
LIST_FORM.append(r)
|
self.LIST_FORM.append(r)
|
||||||
elif larg[0] == "ROND":
|
elif larg[0] == "ELLIPSE":
|
||||||
c = Circle(self.__my_int(larg[1]), self.__my_int(larg[2]), 50, larg[3])
|
c = Ellipse(myturtle, self.__my_int(larg[1]), self.__my_int(larg[2]), color=larg[3])
|
||||||
myturtle.draw_circle(c)
|
c.draw()
|
||||||
LIST_FORM.append(Circle(self.__my_int(larg[1]), self.__my_int(larg[2]), larg[3]))
|
self.LIST_FORM.append(c)
|
||||||
|
|
||||||
|
def move(self, agent, *larg):
|
||||||
|
self.LIST_FORM = Form.aim_move(self.LIST_FORM, larg[0], larg[1], larg[2], larg[3], larg[4])
|
||||||
|
|
||||||
|
def delete(self, agent, *larg):
|
||||||
|
self.LIST_FORM = Form.aim_delete(self.LIST_FORM, larg[0], larg[1], larg[2], larg[3])
|
||||||
|
|
||||||
def __my_int(self, str):
|
def __my_int(self, str):
|
||||||
print(int(str.split(".")[0]))
|
|
||||||
return int(str.split(".")[0])
|
return int(str.split(".")[0])
|
||||||
|
|
||||||
|
|
||||||
@ -124,4 +156,15 @@ myturtle.color("green")
|
|||||||
|
|
||||||
my_ivy = MyIvyPalette("Palette", "127.255.255.255:2010")
|
my_ivy = MyIvyPalette("Palette", "127.255.255.255:2010")
|
||||||
|
|
||||||
|
|
||||||
|
r = Rectangle(myturtle, 500, 400, color="red")
|
||||||
|
r.draw()
|
||||||
|
|
||||||
|
e = Ellipse(myturtle, 100, 200, color="green")
|
||||||
|
e.draw()
|
||||||
|
|
||||||
|
|
||||||
|
Form.aim_delete(my_ivy.LIST_FORM, "RECTANGLE", 522, 403)
|
||||||
|
|
||||||
myturtle.screen._root.mainloop()
|
myturtle.screen._root.mainloop()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user