From cd70c0f2363817330d4729555fdbd5eda9cd7614 Mon Sep 17 00:00:00 2001 From: Le_dahut Date: Wed, 4 Jun 2014 17:02:25 +0200 Subject: [PATCH] =?UTF-8?q?-Ajout=20de=20la=20classe=20abutton=20qui=20per?= =?UTF-8?q?met=20de=20g=C3=A9n=C3=A9rer=20un=20=C3=A9l=C3=A9ment=20de=20me?= =?UTF-8?q?nu=20depuis=20une=20image,=20une=20couleur=20ou=20une=20fonctio?= =?UTF-8?q?n.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WireChem.py | 160 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 158 insertions(+), 2 deletions(-) diff --git a/WireChem.py b/WireChem.py index ecc3d09..6a0197e 100644 --- a/WireChem.py +++ b/WireChem.py @@ -82,6 +82,140 @@ def reference(var,noms): def duplicateref(d): for k in d.keys(): d[d[k]['nom']]=d[k] + +class abutton(object): + def update(self): + if not self.isvisible(): + try: + self.vertex_list.delete() + except: + print "destroyed" + else: + if self.typeof=='icon': + self.content.width=self.width + self.content.height=self.height + self.vertex_list = pyglet.sprite.Sprite(self.content, x=self.x, y=self.y, batch=self.batch) + elif self.typeof=='color': + self.vertex_list = self.batch.add(4,pyglet.gl.GL_QUADS, None, + ('v2i', (self.x, self.y, self.x+self.width, self.y, self.x+self.width, self.y+self.height, self.x, self.y+self.height)), + ('c4B', self.content * 4)) + elif self.typeof=='function': + self.vertex_list = eval(self.content) + elif self.typeof=='multicon': + self.content[self.index].width=self.width + self.content[self.index].height=self.height + self.vertex_list = pyglet.sprite.Sprite(self.content[self.index], x=self.x, y=self.y, batch=self.batch) + + def __init__(self, window, name, x, y, width, height , active, hilite, visible, seleted, separe, content, hint, typeof, text, text2, batch): + self.name=name + self.index=0 + self.x=x + self.y=y + self.batch=batch + self.width=width + self.height=height + self.active=active + self.hilite=hilite + self.visible=visible + self.separe=separe + self.content=content + self.typeof=typeof + self.hint=hint + self.seleted=seleted + self.window=window + self.window.push_handlers(self.on_mouse_press) + self.window.push_handlers(self.on_mouse_motion) + self.window.push_handlers(self.on_mouse_drag) + self.window.push_handlers(self.on_mouse_release) + self.window.push_handlers(self.on_mouse_scroll) + self.update() + + def delete(self): + self.vertex_list.delete() + + def on_mouse_press(self, x, y, button, modifiers): + if x>self.x and y>self.y and x=len(self.content): + self.index=0 + self.update() + eval("self.window.on_mouse_press_"+self.name+"("+str(state)+")") + + def on_mouse_release(self, x, y, button, modifiers): + if x>self.x and y>self.y and xself.x and y>self.y and xself.x and y>self.y and xself.x and y>self.y and x