This commit is contained in:
Quentin Rouland 2017-01-19 14:43:08 +01:00
parent 3e8385e7c5
commit d0b072b9c1
7 changed files with 240 additions and 9 deletions

39
LibCommon/myIvy.py Normal file
View File

@ -0,0 +1,39 @@
from ivy.std_api import *
class MyIvy:
def __init__(self, appname, bus):
self.appname = appname
self.bus = bus
sisreadymsg = '[%s is ready]' % self.appname
print('Ivy will broadcast on %s ', self.bus)
# initialising the bus
IvyInit(self.appname, # application name for Ivy
sisreadymsg, # ready message
0, # main loop is local (ie. using IvyMainloop)
self.oncxproc, # handler called on connection/disconnection
self.ondieproc) # handler called when a <die> message is received
IvyStart(self.bus)
def oncxproc(self, agent, connected):
if connected == IvyApplicationDisconnected:
print('Ivy application %r was disconnected', agent)
else:
print('Ivy application %r was connected', agent)
print('currents Ivy application are [%s]', IvyGetApplicationList())
def ondieproc(self, agent, _id):
print('received the order to die from %r with id = %d', agent, _id)
def onmsgproc(self, agent, *larg):
print('Received from %r: [%s] ', agent, larg[0])
def ontick(self):
print('%s send a tick', self.appname)
IvySendMsg('%s_tick' % self.appname)
def _createbind(self):
pass
# redefine for create some bind : IvyBindMsg(self.oncreate, '^PALETTE form=(.*) x=(.*) y=(.*) couleur=(.*)')

View File

@ -1 +0,0 @@

80
MultiModal/multiModale.py Normal file
View File

@ -0,0 +1,80 @@
from ivy.std_api import IvyBindMsg, IvySendMsg, IvyMainLoop
import myIvy
from threading import Timer
class automate:
list_color = {'rouge': 'red', 'bleu': 'blue', 'vert': 'green', 'jaune': 'yellow'}
state = 0
timer = None
def __init__(self):
self.timer = Timer(5, self.timeout)
self.form = None
self.xy = None
self.color = None
def new_geste(self, agent, *larg):
if self.state == 0:
self.__reinit_timer()
self.form = larg[0]
self.state = 1
def new_click(self, agent, *larg):
if self.state == 1:
self.__reinit_timer()
self.xy = (larg[0], larg[1])
self.state = 2
elif self.state == 3:
self.__reinit_timer()
self.xy = (larg[0], larg[1])
self.state = 1
def new_vocal_couleur(self, agent, *larg):
if self.state == 1 and larg[0] in self.list_color:
self.__reinit_timer()
self.color = self.list_color[larg[0]]
self.state = 3
elif self.state == 2:
self.__reinit_timer()
self.color = larg[0]
self.state = 1
def new_vocal_action(self, agent, *larg):
if self.state == 1 and larg[0] == "ici":
self.__reinit_timer()
self.__maybe_send_create()
self.state = 1
def timeout(self):
if self.state == 1:
self.state = 0
if self.state in [1, 2]:
self.state = 1
def __reinit_timer(self):
self.timer.cancel()
self.timer.start()
def __maybe_send_create(self):
if None not in [self.form, self.xy, self.color]:
IvySendMsg("MULTIMODAL forme={} x={} y={} couleur={}".format(self.form, self.xy[0], self.xy[1], self.color))
self.form = None
self.xy = None
self.color = None
class MyIvyMultiModale(myIvy.MyIvy):
a = automate()
def _createbind(self):
IvyBindMsg(self.a.new_geste, '^GESTE forme=(.*)')
IvyBindMsg(self.a.new_click, '^PALETTE x=(.*) y=(.*)')
IvyBindMsg(self.a.new_vocal_couleur, '^VOCAL couleur=(.*)')
IvyBindMsg(self.a.new_vocal_action, '^VOCAL action=(.*)')
MyIvyMultiModale("MultiModal", "172.31.190.255:2010")
IvyMainLoop()

View File

@ -1 +0,0 @@

121
Palette/palette.py Normal file
View File

@ -0,0 +1,121 @@
import turtle
import myIvy
from ivy.std_api import *
LIST_FORM = []
class Form:
def __init__(self, x, y):
self.x = x
self.y = y
def is_in(self, x, y):
return x == self.x and y == self.y
class Circle(Form):
def __init__(self, x, y, radius, color="red"):
super().__init__(x, y)
self.radius = radius
self.color = color
def is_in(self, x, y):
return (x - self.x) ** 2 + (y - self.y) ** 2 < self.radius ** 2
class Rectangle(Form):
def __init__(self, x, y, vert, hor, color="red"):
super().__init__(x, y)
self.vert = vert
self.hor = hor
self.color = color
def is_in(self, x, y):
return 0 <= (x - self.x) <= self.hor and 0 <= (y - self.y) <= self.vert
class MyTurtle(turtle.Turtle):
def __init__(self, color="green"):
turtle.Turtle.__init__(self, shape="turtle")
self.pensize(3)
self.my_turtle_color = color
self.color(color)
self.screen = turtle.Screen()
self.screen.bgcolor("#FFFFFF")
self.screen.title("Palette")
self.screen.setup(1000, 600, 1, -1)
self.screen.setworldcoordinates(0, 600, 1000, 0)
self.screen.listen()
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 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.vert, rectangle.x)
self.setposition(rectangle.x + rectangle.vert, rectangle.x + rectangle.hor)
self.setposition(rectangle.x, rectangle.x + rectangle.hor)
self.setposition(rectangle.x, rectangle.x)
self.__end_draw()
def delete_rectangle(self, rectangle):
self.__setup_draw(rectangle.x, rectangle.y, color="#FFFFFF")
def onclick(self, x, y):
myturtle.goto(x, y)
IvySendMsg("PALETTE x={} y={}".format(x,y))
class MyIvyPalette(myIvy.MyIvy):
def _createbind(self):
IvyBindMsg(self.create, '^MULTIMODAL forme=(.*) x=(.*) y=(.*) couleur=(.*)')
def create(self, agent, *larg):
print('create [%s]', larg)
if larg[0] == "RECTANGLE":
LIST_FORM.append(Rectangle(larg[1], larg[2], 200, 100, larg[3]))
elif larg[0] == "ROND":
LIST_FORM.append(Circle(larg[1], larg[2], larg[3]))
myturtle = MyTurtle()
myturtle.draw_circle(Circle(120, 180, 50))
myturtle.draw_rectangle(Rectangle(300, 300, 100, 200, color="blue"))
myturtle.setposition(500, 450)
myturtle.draw_circle_here()
my_ivy = MyIvyPalette("Palette", "172.31.190.255:2010")
myturtle.screen._root.mainloop()

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="NewModuleRootManager" inherit-compiler-output="false">
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -1 +0,0 @@