Version avec librairie déportée..
|
@ -0,0 +1,466 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
'''
|
||||||
|
------------------------------------------
|
||||||
|
|
||||||
|
Microlinux
|
||||||
|
|
||||||
|
Classes OpenGl
|
||||||
|
|
||||||
|
(C) Copyright 2013-2014 Nicolas Hordé
|
||||||
|
|
||||||
|
------------------------------------------
|
||||||
|
'''
|
||||||
|
import datetime
|
||||||
|
import math
|
||||||
|
import copy
|
||||||
|
import random
|
||||||
|
import time
|
||||||
|
import operator
|
||||||
|
|
||||||
|
import pyglet
|
||||||
|
from GLclass import *
|
||||||
|
from pyglet.gl import *
|
||||||
|
from pyglet.window import mouse
|
||||||
|
from pyglet.window import key
|
||||||
|
from pyglet import clock
|
||||||
|
from pyglet import image
|
||||||
|
|
||||||
|
''' *********************************************************************************************** '''
|
||||||
|
''' Classes graphiques '''
|
||||||
|
|
||||||
|
#Classe comme un label avec l'attribut visible
|
||||||
|
class alabel(pyglet.text.Label):
|
||||||
|
def __init__(self, window, xx, yy, visible=True, text="", font="Deja vu sans", size=16, group=None):
|
||||||
|
self.window = window
|
||||||
|
self.font=font
|
||||||
|
self.size=size
|
||||||
|
self.visible = visible
|
||||||
|
super(alabel, self).__init__(text,x=xx,y=yy,font_name=self.font,font_size=self.size,group=group,batch=self.window.batch)
|
||||||
|
self.update(0)
|
||||||
|
|
||||||
|
def update(self,dt):
|
||||||
|
if not self.visible:
|
||||||
|
if self.x!=10000:
|
||||||
|
self.xx=self.x
|
||||||
|
self.x=10000
|
||||||
|
else:
|
||||||
|
if self.x==10000:
|
||||||
|
self.x=self.xx
|
||||||
|
self.font_size=self.size
|
||||||
|
self.font_name=self.font
|
||||||
|
|
||||||
|
# Classe d'un rectangle
|
||||||
|
class arect(object):
|
||||||
|
def __init__(self, window, x, y, width, height, visible=True, typeof=0, color=(180, 180, 180, 255), group=None):
|
||||||
|
self.window = window
|
||||||
|
self.x = x
|
||||||
|
self.y = y
|
||||||
|
self.width = width
|
||||||
|
self.height = height
|
||||||
|
self.typeof = typeof
|
||||||
|
self.color = color
|
||||||
|
self.group = group
|
||||||
|
self.visible = visible
|
||||||
|
self.update(0)
|
||||||
|
|
||||||
|
def update(self,dt):
|
||||||
|
try:
|
||||||
|
self.vertex_list.delete()
|
||||||
|
except:
|
||||||
|
foo = 0
|
||||||
|
try:
|
||||||
|
self.vertex_list2.delete()
|
||||||
|
except:
|
||||||
|
foo = 0
|
||||||
|
if self.visible and (self.typeof == "face" or self.typeof == "both"):
|
||||||
|
self.vertex_list = self.window.batch.add(4, pyglet.gl.GL_QUADS, self.group, (
|
||||||
|
'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.color * 4))
|
||||||
|
if self.visible and self.typeof == "line" or self.typeof == "both":
|
||||||
|
self.vertex_list2 = self.window.batch.add(4, pyglet.gl.GL_LINE_LOOP, self.group,
|
||||||
|
('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]),
|
||||||
|
('c3B', [self.color[0], self.color[1], self.color[2]] * 4))
|
||||||
|
|
||||||
|
#Classe d'un texte editable
|
||||||
|
class atext(object):
|
||||||
|
def __init__(self, window, x, y, width, height, visible=True, text="", font="Deja vu sans", size=10, align="center", color=(180, 180, 180, 255)):
|
||||||
|
self.evalx = x
|
||||||
|
self.evaly = y
|
||||||
|
self.x = x
|
||||||
|
self.y = y
|
||||||
|
self.window = window
|
||||||
|
if type(self.evalx) is str:
|
||||||
|
self.x = eval(self.evalx)
|
||||||
|
if type(self.evaly) is str:
|
||||||
|
self.y = eval(self.evaly)
|
||||||
|
self.loaded = ''
|
||||||
|
self.align = align
|
||||||
|
self.font = font
|
||||||
|
self.size = size
|
||||||
|
self.text = text
|
||||||
|
self.color = color
|
||||||
|
self.height = height
|
||||||
|
self.visible = visible
|
||||||
|
self.document = pyglet.text.document.FormattedDocument(text.decode("utf8"))
|
||||||
|
self.document.set_style(0, len(self.document.text),dict(font_name=self.font, font_size=self.size, color=self.color, align=self.align,
|
||||||
|
background_color=(200, 200, 200, 0)))
|
||||||
|
if height == 0:
|
||||||
|
font = self.document.get_font(0)
|
||||||
|
height = font.ascent - font.descent
|
||||||
|
self.layout = pyglet.text.layout.IncrementalTextLayout(self.document, width, height, multiline=True,
|
||||||
|
batch=self.window.batch, group=self.window.p3)
|
||||||
|
self.layout.document.register_event_type('self.on_insert_text')
|
||||||
|
self.layout.on_layout_update = self.on_layout_update
|
||||||
|
self.caret = pyglet.text.caret.Caret(self.layout)
|
||||||
|
self.caret.visible = False
|
||||||
|
self.update(0)
|
||||||
|
|
||||||
|
def update(self,dt):
|
||||||
|
self.layout.begin_update()
|
||||||
|
if type(self.evalx) is str:
|
||||||
|
self.x = eval(self.evalx)
|
||||||
|
if type(self.evaly) is str:
|
||||||
|
self.y = eval(self.evaly)
|
||||||
|
if self.visible:
|
||||||
|
self.layout.x = self.x
|
||||||
|
else:
|
||||||
|
self.layout.x = 10000
|
||||||
|
self.layout.y = self.y
|
||||||
|
#self.layout.document.text = self.text.decode('utf8')
|
||||||
|
if len(self.layout.document.text) > 0:
|
||||||
|
self.layout.document.set_style(0, len(self.layout.document.text),
|
||||||
|
dict(font_name=self.font, font_size=self.size, color=self.color, align=self.align,
|
||||||
|
background_color=(200, 200, 200, 0)))
|
||||||
|
self.layout.end_update()
|
||||||
|
|
||||||
|
def on_layout_update(self):
|
||||||
|
if self.loaded != '':
|
||||||
|
#exec (self.loaded + '="' + self.layout.document.text + '"')
|
||||||
|
self.text = self.layout.document.text
|
||||||
|
|
||||||
|
def hit_test(self, x, y):
|
||||||
|
return (0 < x - self.layout.x < self.layout.width and 0 < y - self.layout.y < self.layout.height)
|
||||||
|
|
||||||
|
|
||||||
|
#Bouton sensible a plusieurs évènements, types: function, multicon, icon, color,
|
||||||
|
# et text in,left,top,bottom,right
|
||||||
|
class abutton(object):
|
||||||
|
def update(self, dt):
|
||||||
|
if not self.hilite and dt>0:
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
self.vertex_list.delete()
|
||||||
|
except:
|
||||||
|
foo = 0
|
||||||
|
try:
|
||||||
|
self.vertex_list2.delete()
|
||||||
|
except:
|
||||||
|
foo = 0
|
||||||
|
try:
|
||||||
|
self.vertex_list3.delete()
|
||||||
|
except:
|
||||||
|
foo = 0
|
||||||
|
if type(self.evalx) is str:
|
||||||
|
self.x = eval(self.evalx)
|
||||||
|
if type(self.evaly) is str:
|
||||||
|
self.y = eval(self.evaly)
|
||||||
|
|
||||||
|
if self.typeof == 'color':
|
||||||
|
if self.isvisible():
|
||||||
|
if not self.isactive():
|
||||||
|
color = (self.content[0], self.content[1], self.content[2], 127)
|
||||||
|
else:
|
||||||
|
color = (self.content[0], self.content[1], self.content[2], 255)
|
||||||
|
self.vertex_list = self.window.batch.add(4, pyglet.gl.GL_QUADS, self.window.p1,
|
||||||
|
('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', color * 4))
|
||||||
|
elif self.typeof == 'function':
|
||||||
|
self.vertex_list = eval(self.content)
|
||||||
|
else:
|
||||||
|
if self.typeof == 'multicon':
|
||||||
|
self.sprite.image = self.content[self.index]
|
||||||
|
else:
|
||||||
|
self.sprite.image = self.content
|
||||||
|
self.sprite.visible=self.isvisible()
|
||||||
|
if self.width == 0:
|
||||||
|
self.width = self.sprite.image.width
|
||||||
|
if self.height == 0:
|
||||||
|
self.height = self.sprite.image.height
|
||||||
|
if self.text!='':
|
||||||
|
self.layout.begin_update()
|
||||||
|
self.layout.document.text=self.text
|
||||||
|
self.layout.document.set_style(0, len(self.layout.document.text),dict(font_name=self.font, font_size=self.size))
|
||||||
|
self.layout.end_update()
|
||||||
|
if self.align=="top" or self.align=="bottom":
|
||||||
|
font = self.layout.document.get_font(0)
|
||||||
|
self.height+= font.ascent - font.descent
|
||||||
|
elif self.align=="left" or self.align=="right":
|
||||||
|
self.width+=self.layout.content_width
|
||||||
|
if self.width / float(self.height) < self.sprite.image.width / float(self.sprite.image.height):
|
||||||
|
self.sprite.scale = float(self.width) / self.sprite.image.width
|
||||||
|
else:
|
||||||
|
self.sprite.scale = float(self.height) / self.sprite.image.height
|
||||||
|
self.sprite.x=self.x
|
||||||
|
self.sprite.y=self.y
|
||||||
|
if not self.isactive():
|
||||||
|
self.sprite.color = (60, 60, 60)
|
||||||
|
else:
|
||||||
|
self.sprite.color = (255, 255, 255)
|
||||||
|
if self.text != '':
|
||||||
|
self.layout.begin_update()
|
||||||
|
if not self.scale:
|
||||||
|
self.sprite.scale=1
|
||||||
|
picalign="center"
|
||||||
|
if not self.isvisible():
|
||||||
|
self.layout.x=10000
|
||||||
|
elif self.align=="right":
|
||||||
|
self.sprite.x=self.x
|
||||||
|
self.sprite.y=self.y+(self.height-self.sprite.height)/2
|
||||||
|
self.layout.x=self.sprite.x+self.sprite.width
|
||||||
|
self.layout.width=self.width-self.sprite.width
|
||||||
|
self.layout.y=self.y
|
||||||
|
self.layout.height=self.height
|
||||||
|
self.layout.content_valign='center'
|
||||||
|
picalign="left"
|
||||||
|
elif self.align=="left":
|
||||||
|
self.sprite.x=self.x+self.width-self.sprite.width
|
||||||
|
self.sprite.y=self.y+(self.height-self.sprite.height)/2
|
||||||
|
self.layout.x=self.x
|
||||||
|
self.layout.width=self.width-self.sprite.width
|
||||||
|
self.layout.y=self.y
|
||||||
|
self.layout.height=self.height
|
||||||
|
self.layout.content_valign='center'
|
||||||
|
picalign="right"
|
||||||
|
elif self.align=="bottom":
|
||||||
|
self.sprite.x=self.x+(self.width-self.sprite.width)/2
|
||||||
|
self.sprite.y=self.y+self.height-self.sprite.height
|
||||||
|
self.layout.x=self.x
|
||||||
|
self.layout.width=self.width
|
||||||
|
self.layout.y=self.y
|
||||||
|
self.layout.height=self.height-self.sprite.height
|
||||||
|
self.layout.content_valign='top'
|
||||||
|
elif self.align=="in":
|
||||||
|
self.sprite.x=self.x+(self.width-self.sprite.width)/2
|
||||||
|
self.sprite.y=self.y+(self.height-self.sprite.height)/2
|
||||||
|
self.layout.x=self.x
|
||||||
|
self.layout.y=self.y
|
||||||
|
self.layout.width=self.width
|
||||||
|
self.layout.height=self.height
|
||||||
|
self.layout.content_valign='center'
|
||||||
|
else:
|
||||||
|
self.sprite.x=self.x+(self.width-self.sprite.width)/2
|
||||||
|
self.sprite.y=self.y
|
||||||
|
self.layout.x=self.x
|
||||||
|
self.layout.width=self.width
|
||||||
|
self.layout.y=self.y+self.sprite.height
|
||||||
|
self.layout.height=self.height-self.sprite.height
|
||||||
|
self.layout.content_valign='bottom'
|
||||||
|
if len(self.layout.document.text)>0:
|
||||||
|
if type(self.selected) is not list:
|
||||||
|
if self.active:
|
||||||
|
piccolor=(90, 90, 90,255)
|
||||||
|
else:
|
||||||
|
piccolor=(180, 180, 180,255)
|
||||||
|
else:
|
||||||
|
piccolor=(self.selected[0], self.selected[1], self.selected[2], 255)
|
||||||
|
self.layout.document.set_style(0, len(self.layout.document.text),
|
||||||
|
dict(font_name=self.font, font_size=self.size, color=piccolor, align=picalign,
|
||||||
|
background_color=(200, 200, 200, 0)))
|
||||||
|
self.layout.end_update()
|
||||||
|
if type(self.selected) is tuple:
|
||||||
|
color = (self.selected[0], self.selected[1], self.selected[2], 255)
|
||||||
|
self.vertex_list2 = self.window.batch.add(4, pyglet.gl.GL_LINE_LOOP, self.window.p2,
|
||||||
|
('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', color * 4))
|
||||||
|
elif type(self.selected) is list and self.isactive():
|
||||||
|
self.sprite.color = (self.selected[0], self.selected[1], self.selected[2])
|
||||||
|
if self.hilite and int(time.time()) % 2 == 0:
|
||||||
|
color = (255, 0, 0, 128)
|
||||||
|
self.vertex_list3 = self.window.batch.add(4, pyglet.gl.GL_QUADS, self.window.p2,
|
||||||
|
('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', color * 4))
|
||||||
|
|
||||||
|
def __init__(self, window, x, y, width, height, name, active=True, hilite=False, visible=True, selected=False, content=None, hint="", typeof="icon",
|
||||||
|
text="", align="left", font="Deja vu sans", size=16, scale=False):
|
||||||
|
self.name = name
|
||||||
|
self.time = 0
|
||||||
|
self.index = 0
|
||||||
|
self.enter = 0
|
||||||
|
self.window = window
|
||||||
|
self.evalx = x
|
||||||
|
self.evaly = y
|
||||||
|
self.x = x
|
||||||
|
self.y = y
|
||||||
|
self.scale=scale
|
||||||
|
self.align=align
|
||||||
|
self.font=font
|
||||||
|
self.size=size
|
||||||
|
self.width = width
|
||||||
|
self.height = height
|
||||||
|
self.active = active
|
||||||
|
self.hilite = hilite
|
||||||
|
self.visible = visible
|
||||||
|
self.content = content
|
||||||
|
self.typeof = typeof
|
||||||
|
self.hint = hint
|
||||||
|
self.text = text
|
||||||
|
self.selected = selected
|
||||||
|
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.updateclock = clock.schedule_interval(self.update, 1)
|
||||||
|
if self.typeof=='multicon' or self.typeof=='icon':
|
||||||
|
self.sprite = pyglet.sprite.Sprite(pyglet.image.Texture.create(1,1),x=-300,y=-300, batch=self.window.batch, group=self.window.p1)
|
||||||
|
if self.text!='' or self.typeof=="text":
|
||||||
|
self.layout = pyglet.text.layout.IncrementalTextLayout(pyglet.text.document.FormattedDocument(text), 10, 10, multiline=True, batch=self.window.batch, group=self.window.p2)
|
||||||
|
self.update(0)
|
||||||
|
|
||||||
|
def delete(self):
|
||||||
|
try:
|
||||||
|
self.vertex_list.delete()
|
||||||
|
except:
|
||||||
|
foo = 0
|
||||||
|
try:
|
||||||
|
self.vertex_list2.delete()
|
||||||
|
except:
|
||||||
|
foo = 0
|
||||||
|
try:
|
||||||
|
self.vertex_list3.delete()
|
||||||
|
except:
|
||||||
|
foo = 0
|
||||||
|
try:
|
||||||
|
self.sprite.delete()
|
||||||
|
except:
|
||||||
|
foo = 0
|
||||||
|
|
||||||
|
def launch(self, state):
|
||||||
|
name = self.name.split('_')
|
||||||
|
if len(name) > 1 and hasattr(self.window, "on_mouse_" + state['event'] + "_" + name[0]) and callable(
|
||||||
|
eval("self.window.on_mouse_" + state['event'] + "_" + name[0])):
|
||||||
|
eval("self.window.on_mouse_" + state['event'] + "_" + name[0] + "(" + str(name[1]) + "," + str(state) + ")")
|
||||||
|
#print state,self.name
|
||||||
|
if hasattr(self.window, "on_mouse_" + state['event'] + "_" + self.name) and callable(
|
||||||
|
eval("self.window.on_mouse_" + state['event'] + "_" + self.name)):
|
||||||
|
if self.typeof == 'multicon':
|
||||||
|
self.index += 1
|
||||||
|
if self.index >= len(self.content):
|
||||||
|
self.index = 0
|
||||||
|
self.update(0)
|
||||||
|
eval("self.window.on_mouse_" + state['event'] + "_" + self.name + "(" + str(state) + ")")
|
||||||
|
#print state,self.name
|
||||||
|
|
||||||
|
def on_mouse_press(self, x, y, button, modifiers):
|
||||||
|
if x > self.x and y > self.y and x < self.x + self.width and y < self.y + self.height and self.isactive() and self.isvisible():
|
||||||
|
if time.time() - self.time < 0.30:
|
||||||
|
state = {'x': x, 'y': y, 'dx': 0, 'dy': 0, 'buttons': button, 'modifiers': modifiers, 'event': 'double'}
|
||||||
|
self.launch(state)
|
||||||
|
self.time = time.time()
|
||||||
|
state = {'x': x, 'y': y, 'dx': 0, 'dy': 0, 'buttons': button, 'modifiers': modifiers, 'event': 'press'}
|
||||||
|
self.launch(state)
|
||||||
|
|
||||||
|
def on_mouse_release(self, x, y, button, modifiers):
|
||||||
|
if x > self.x and y > self.y and x < self.x + self.width and y < self.y + self.height and self.isactive() and self.isvisible():
|
||||||
|
state = {'x': x, 'y': y, 'dx': 0, 'dy': 0, 'buttons': button, 'modifiers': modifiers, 'event': 'release'}
|
||||||
|
self.launch(state)
|
||||||
|
|
||||||
|
def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
|
||||||
|
if x > self.x and y > self.y and x < self.x + self.width and y < self.y + self.height and self.isactive() and self.isvisible():
|
||||||
|
state = {'x': x, 'y': y, 'dx': dx, 'dy': dy, 'buttons': buttons, 'modifiers': modifiers, 'event': 'drag'}
|
||||||
|
self.launch(state)
|
||||||
|
|
||||||
|
def on_mouse_scroll(self, x, y, scroll_x, scroll_y):
|
||||||
|
if x > self.x and y > self.y and x < self.x + self.width and y < self.y + self.height and self.isactive() and self.isvisible():
|
||||||
|
state = {'x': x, 'y': y, 'dx': scroll_x, 'dy': scroll_y, 'buttons': 0, 'modifiers': 0, 'event': 'scroll'}
|
||||||
|
self.launch(state)
|
||||||
|
|
||||||
|
def on_mouse_motion(self, x, y, dx, dy):
|
||||||
|
if x > self.x and y > self.y and x < self.x + self.width and y < self.y + self.height:
|
||||||
|
if self.isvisible() and self.isactive():
|
||||||
|
if self.enter == 0:
|
||||||
|
self.enter = 1
|
||||||
|
state = {'x': x, 'y': y, 'dx': dx, 'dy': dy, 'buttons': 0, 'modifiers': 0, 'event': 'enter'}
|
||||||
|
self.launch(state)
|
||||||
|
state = {'x': x, 'y': y, 'dx': dx, 'dy': dy, 'buttons': 0, 'modifiers': 0, 'event': 'motion'}
|
||||||
|
self.launch(state)
|
||||||
|
else:
|
||||||
|
if self.enter == 1:
|
||||||
|
self.enter = 0
|
||||||
|
state = {'x': x, 'y': y, 'dx': dx, 'dy': dy, 'buttons': 0, 'modifiers': 0, 'event': 'leave'}
|
||||||
|
self.launch(state)
|
||||||
|
|
||||||
|
def setselected(self, select):
|
||||||
|
self.selected = select
|
||||||
|
self.update(0)
|
||||||
|
|
||||||
|
def isvisible(self):
|
||||||
|
if type(self.visible) is bool:
|
||||||
|
return self.visible
|
||||||
|
else:
|
||||||
|
return eval(self.visible)
|
||||||
|
|
||||||
|
def isactive(self):
|
||||||
|
if type(self.active) is bool:
|
||||||
|
return self.active
|
||||||
|
else:
|
||||||
|
return eval(self.active)
|
||||||
|
|
||||||
|
def ishilite(self):
|
||||||
|
if type(self.hilite) is bool:
|
||||||
|
return self.hilite
|
||||||
|
else:
|
||||||
|
return eval(self.hilite)
|
||||||
|
|
||||||
|
def hide(self):
|
||||||
|
if type(self.visible) is bool:
|
||||||
|
self.visible = False
|
||||||
|
self.update(0)
|
||||||
|
|
||||||
|
def show(self):
|
||||||
|
if type(self.visible) is bool:
|
||||||
|
self.visible = True
|
||||||
|
self.update(0)
|
||||||
|
|
||||||
|
def activate(self):
|
||||||
|
if type(self.active) is bool:
|
||||||
|
self.active = True
|
||||||
|
self.update(0)
|
||||||
|
|
||||||
|
def unactivate(self):
|
||||||
|
if type(self.active) is bool:
|
||||||
|
self.active = False
|
||||||
|
self.update(0)
|
||||||
|
|
||||||
|
def hilitate(self):
|
||||||
|
if type(self.hilite) is bool:
|
||||||
|
self.hilite = True
|
||||||
|
self.update(0)
|
||||||
|
|
||||||
|
def unhilitate(self):
|
||||||
|
if type(self.hilite) is bool:
|
||||||
|
self.hilite = False
|
||||||
|
self.update(0)
|
||||||
|
|
||||||
|
# Classe interface
|
||||||
|
class ainter(abutton):
|
||||||
|
def __init__(self, window, x, y, icon, comment="", text="", cmd="", font="Deja vu"):
|
||||||
|
if window.width>1800:
|
||||||
|
super(ainter,self).__init__(window, x, y, 0, 0, "item_"+str(window.count), content=icon, hint=comment, typeof="icon", text=text, align="bottom", size=16, font=font, scale=False)
|
||||||
|
elif window.width>1600:
|
||||||
|
super(ainter,self).__init__(window, x, y, 96, 0, "item_"+str(window.count), content=icon, hint=comment, typeof="icon", text=text, align="bottom", size=14, font=font, scale=True)
|
||||||
|
elif window.width>1280:
|
||||||
|
super(ainter,self).__init__(window, x, y, 64, 0, "item_"+str(window.count), content=icon, hint=comment, typeof="icon", text=text, align="bottom", size=12, font=font, scale=True)
|
||||||
|
else:
|
||||||
|
super(ainter,self).__init__(window, x, y, 48, 0, "item_"+str(window.count), content=icon, hint=comment, typeof="icon", text=text, align="bottom", size=10, font=font, scale=True)
|
||||||
|
self.cmd=cmd
|
||||||
|
window.count+=1
|
400
WireChem.py
|
@ -26,6 +26,7 @@ import sys
|
||||||
from os.path import expanduser
|
from os.path import expanduser
|
||||||
|
|
||||||
import pyglet
|
import pyglet
|
||||||
|
from GLclass import *
|
||||||
from pyglet.gl import *
|
from pyglet.gl import *
|
||||||
from pyglet.window import mouse
|
from pyglet.window import mouse
|
||||||
from pyglet.window import key
|
from pyglet.window import key
|
||||||
|
@ -178,357 +179,6 @@ else:
|
||||||
debug = 0
|
debug = 0
|
||||||
inc=1
|
inc=1
|
||||||
|
|
||||||
''' *********************************************************************************************** '''
|
|
||||||
''' Classes graphiques '''
|
|
||||||
|
|
||||||
#Classe d'un rectangle
|
|
||||||
class arect(object):
|
|
||||||
def __init__(self, window, x1, y1, x2, y2, atype, color, level):
|
|
||||||
self.window = window
|
|
||||||
if atype==1 or atype==2:
|
|
||||||
self.vertex_list = window.batch.add(4, pyglet.gl.GL_QUADS, level, ('v2i', [x1, y1, x2, y1, x2, y2, x1, y2]),
|
|
||||||
('c4B', color * 4))
|
|
||||||
if atype==0 or atype==2:
|
|
||||||
self.vertex_list2 = window.batch.add(4, pyglet.gl.GL_LINE_LOOP, level, ('v2i', [x1, y1, x2, y1, x2, y2, x1, y2]),
|
|
||||||
('c3B', [color[0],color[1],color[2]] * 4))
|
|
||||||
|
|
||||||
|
|
||||||
#Classe d'un texte editable
|
|
||||||
class atext(object):
|
|
||||||
def __init__(self, window, text, x, y, width, height, font, size):
|
|
||||||
self.x = x
|
|
||||||
self.y = y
|
|
||||||
self.loaded = ''
|
|
||||||
self.text = text
|
|
||||||
self.color = (180, 180, 180, 255)
|
|
||||||
self.height=height
|
|
||||||
self.document = pyglet.text.document.FormattedDocument(text)
|
|
||||||
self.document.set_style(0, len(self.document.text),
|
|
||||||
dict(font_name=font, font_size=size, color=self.color, align="center",
|
|
||||||
background_color=(200, 200, 200, 0)))
|
|
||||||
if height==0:
|
|
||||||
font = self.document.get_font(0)
|
|
||||||
height = font.ascent - font.descent
|
|
||||||
self.window = window
|
|
||||||
self.layout = pyglet.text.layout.IncrementalTextLayout(self.document, width, height, multiline=True,
|
|
||||||
batch=self.window.batch, group=self.window.p3)
|
|
||||||
self.layout.document.register_event_type('self.on_insert_text')
|
|
||||||
self.layout.on_layout_update=self.on_layout_update
|
|
||||||
self.caret = pyglet.text.caret.Caret(self.layout)
|
|
||||||
self.caret.visible = False
|
|
||||||
self.layout.x = self.x
|
|
||||||
self.layout.y = self.y
|
|
||||||
|
|
||||||
def update(self):
|
|
||||||
self.layout.begin_update()
|
|
||||||
self.layout.x = self.x
|
|
||||||
self.layout.y = self.y
|
|
||||||
self.layout.document.text = self.text
|
|
||||||
if len(self.layout.document.text)>0:
|
|
||||||
self.layout.document.set_style(0, len(self.layout.document.text), dict(color=self.color))
|
|
||||||
self.layout.end_update()
|
|
||||||
|
|
||||||
def on_layout_update(self):
|
|
||||||
if self.loaded != '':
|
|
||||||
exec (self.loaded + '="' + self.layout.document.text + '"')
|
|
||||||
self.text=self.layout.document.text
|
|
||||||
|
|
||||||
def hit_test(self, x, y):
|
|
||||||
return (0 < x - self.layout.x < self.layout.width and 0 < y - self.layout.y < self.layout.height)
|
|
||||||
|
|
||||||
|
|
||||||
#Bouton sensible a plusieurs évènements, types: function, multicon, icon, color,
|
|
||||||
# et text in,left,top,bottom,right
|
|
||||||
class abutton(object):
|
|
||||||
def update(self, dt):
|
|
||||||
if not self.hilite and dt>0:
|
|
||||||
return
|
|
||||||
try:
|
|
||||||
self.vertex_list.delete()
|
|
||||||
except:
|
|
||||||
foo = 0
|
|
||||||
try:
|
|
||||||
self.vertex_list2.delete()
|
|
||||||
except:
|
|
||||||
foo = 0
|
|
||||||
try:
|
|
||||||
self.vertex_list3.delete()
|
|
||||||
except:
|
|
||||||
foo = 0
|
|
||||||
if type(self.evalx) is str:
|
|
||||||
self.x = eval(self.evalx)
|
|
||||||
if type(self.evaly) is str:
|
|
||||||
self.y = eval(self.evaly)
|
|
||||||
|
|
||||||
if self.typeof.split("_")[0] == 'color':
|
|
||||||
if self.isvisible():
|
|
||||||
if not self.isactive():
|
|
||||||
color = (self.content[0], self.content[1], self.content[2], 127)
|
|
||||||
else:
|
|
||||||
color = (self.content[0], self.content[1], self.content[2], 255)
|
|
||||||
self.vertex_list = self.window.batch.add(4, pyglet.gl.GL_QUADS, self.window.p1,
|
|
||||||
('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', color * 4))
|
|
||||||
elif self.typeof.split("_")[0] == 'function':
|
|
||||||
self.vertex_list = eval(self.content)
|
|
||||||
else:
|
|
||||||
if self.typeof.split("_")[0] == 'multicon':
|
|
||||||
self.sprite.image = self.content[self.index]
|
|
||||||
else:
|
|
||||||
self.sprite.image = self.content
|
|
||||||
self.sprite.visible=self.isvisible()
|
|
||||||
if self.width == 0:
|
|
||||||
self.width = self.sprite.image.width
|
|
||||||
if self.height == 0:
|
|
||||||
self.height = self.sprite.image.height
|
|
||||||
if self.width / float(self.height) < self.sprite.image.width / float(self.sprite.image.height):
|
|
||||||
self.sprite.scale = float(self.width) / self.sprite.image.width
|
|
||||||
else:
|
|
||||||
self.sprite.scale = float(self.height) / self.sprite.image.height
|
|
||||||
self.sprite.x=self.x
|
|
||||||
self.sprite.y=self.y
|
|
||||||
if not self.isactive():
|
|
||||||
self.sprite.color = (60, 60, 60)
|
|
||||||
else:
|
|
||||||
self.sprite.color = (255, 255, 255)
|
|
||||||
if self.text != '':
|
|
||||||
if len(self.typeof.split("_"))<3 and hasattr(self,"sprite"):
|
|
||||||
self.sprite.scale=1
|
|
||||||
align="center"
|
|
||||||
self.layout.begin_update()
|
|
||||||
if not self.isvisible():
|
|
||||||
self.layout.x=-300
|
|
||||||
elif len(self.typeof.split("_"))==1 or self.typeof.split("_")[1]=="in" or self.typeof.split("_")[0][-4:] != 'icon':
|
|
||||||
if hasattr(self,"sprite"):
|
|
||||||
self.sprite.x=self.x+(self.width-self.sprite.width)/2
|
|
||||||
self.sprite.y=self.y+(self.height-self.sprite.height)/2
|
|
||||||
self.layout.x=self.x
|
|
||||||
self.layout.y=self.y
|
|
||||||
self.layout.width=self.width
|
|
||||||
self.layout.height=self.height
|
|
||||||
self.layout.content_valign='center'
|
|
||||||
elif self.typeof.split("_")[1]=="left":
|
|
||||||
self.sprite.x=self.x+self.width-self.sprite.width
|
|
||||||
self.sprite.y=self.y+(self.height-self.sprite.height)/2
|
|
||||||
self.layout.x=self.x
|
|
||||||
self.layout.width=self.width-self.sprite.width
|
|
||||||
self.layout.y=self.y
|
|
||||||
self.layout.height=self.height
|
|
||||||
self.layout.content_valign='center'
|
|
||||||
align="right"
|
|
||||||
elif self.typeof.split("_")[1]=="bottom":
|
|
||||||
self.sprite.x=self.x+(self.width-self.sprite.width)/2
|
|
||||||
self.sprite.y=self.y+self.height-self.sprite.height
|
|
||||||
self.layout.x=self.x
|
|
||||||
self.layout.width=self.width
|
|
||||||
self.layout.y=self.y
|
|
||||||
self.layout.height=self.height-self.sprite.height
|
|
||||||
self.layout.content_valign='top'
|
|
||||||
elif self.typeof.split("_")[1]=="right":
|
|
||||||
self.sprite.x=self.x
|
|
||||||
self.sprite.y=self.y+(self.height-self.sprite.height)/2
|
|
||||||
self.layout.x=self.sprite.x+self.sprite.width
|
|
||||||
self.layout.width=self.width-self.sprite.width
|
|
||||||
self.layout.y=self.y
|
|
||||||
self.layout.height=self.height
|
|
||||||
self.layout.content_valign='center'
|
|
||||||
align="left"
|
|
||||||
else:
|
|
||||||
self.sprite.x=self.x+(self.width-self.sprite.width)/2
|
|
||||||
self.sprite.y=self.y
|
|
||||||
self.layout.x=self.x
|
|
||||||
self.layout.width=self.width
|
|
||||||
self.layout.y=self.y+self.sprite.height
|
|
||||||
self.layout.height=self.height-self.sprite.height
|
|
||||||
self.layout.content_valign='bottom'
|
|
||||||
if len(self.text)>0:
|
|
||||||
self.layout.document.text=self.text
|
|
||||||
if len(self.layout.document.text)>0:
|
|
||||||
if type(self.selected) is not list:
|
|
||||||
color=(180, 180, 180,255)
|
|
||||||
else:
|
|
||||||
color=(self.selected[0], self.selected[1], self.selected[2], 255)
|
|
||||||
self.layout.document.set_style(0, len(self.layout.document.text),
|
|
||||||
dict(font_name="Mechanihan", font_size=20, color=color, align=align,
|
|
||||||
background_color=(200, 200, 200, 0)))
|
|
||||||
self.layout.end_update()
|
|
||||||
if type(self.selected) is tuple:
|
|
||||||
color = (self.selected[0], self.selected[1], self.selected[2], 255)
|
|
||||||
self.vertex_list2 = self.window.batch.add(4, pyglet.gl.GL_LINE_LOOP, self.window.p2,
|
|
||||||
('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', color * 4))
|
|
||||||
elif type(self.selected) is list and self.isactive():
|
|
||||||
self.sprite.color = (self.selected[0], self.selected[1], self.selected[2])
|
|
||||||
if self.hilite and int(time.time()) % 2 == 0:
|
|
||||||
color = (255, 0, 0, 128)
|
|
||||||
self.vertex_list3 = self.window.batch.add(4, pyglet.gl.GL_QUADS, self.window.p2,
|
|
||||||
('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', color * 4))
|
|
||||||
|
|
||||||
def __init__(self, window, name, x, y, width, height, active, hilite, visible, selected, content, hint, typeof, text):
|
|
||||||
self.name = name
|
|
||||||
self.time = 0
|
|
||||||
self.index = 0
|
|
||||||
self.enter = 0
|
|
||||||
self.window = window
|
|
||||||
self.evalx = x
|
|
||||||
self.evaly = y
|
|
||||||
self.x = x
|
|
||||||
self.y = y
|
|
||||||
self.width = width
|
|
||||||
self.height = height
|
|
||||||
self.active = active
|
|
||||||
self.hilite = hilite
|
|
||||||
self.visible = visible
|
|
||||||
self.content = content
|
|
||||||
self.typeof = typeof
|
|
||||||
self.hint = hint
|
|
||||||
self.text = text
|
|
||||||
self.selected = selected
|
|
||||||
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.updateclock = clock.schedule_interval(self.update, 1)
|
|
||||||
if self.typeof.split("_")[0]=='multicon' or self.typeof.split("_")[0]=='icon':
|
|
||||||
self.sprite = pyglet.sprite.Sprite(pyglet.image.Texture.create(1,1),x=-300,y=-300, batch=self.window.batch, group=self.window.p1)
|
|
||||||
if self.text!='':
|
|
||||||
self.layout = pyglet.text.layout.IncrementalTextLayout(pyglet.text.document.FormattedDocument(text), 10, 10, multiline=True, batch=self.window.batch, group=self.window.p2)
|
|
||||||
self.update(0)
|
|
||||||
|
|
||||||
def delete(self):
|
|
||||||
try:
|
|
||||||
self.vertex_list.delete()
|
|
||||||
except:
|
|
||||||
foo = 0
|
|
||||||
try:
|
|
||||||
self.vertex_list2.delete()
|
|
||||||
except:
|
|
||||||
foo = 0
|
|
||||||
try:
|
|
||||||
self.vertex_list3.delete()
|
|
||||||
except:
|
|
||||||
foo = 0
|
|
||||||
try:
|
|
||||||
self.sprite.delete()
|
|
||||||
except:
|
|
||||||
foo = 0
|
|
||||||
|
|
||||||
def launch(self, state):
|
|
||||||
global debug
|
|
||||||
name = self.name.split('_')
|
|
||||||
if len(name) > 1 and hasattr(self.window, "on_mouse_" + state['event'] + "_" + name[0]) and callable(
|
|
||||||
eval("self.window.on_mouse_" + state['event'] + "_" + name[0])):
|
|
||||||
eval("self.window.on_mouse_" + state['event'] + "_" + name[0] + "(" + str(name[1]) + "," + str(state) + ")")
|
|
||||||
if debug==1: print state,self.name
|
|
||||||
if hasattr(self.window, "on_mouse_" + state['event'] + "_" + self.name) and callable(
|
|
||||||
eval("self.window.on_mouse_" + state['event'] + "_" + self.name)):
|
|
||||||
if self.typeof == 'multicon':
|
|
||||||
self.index += 1
|
|
||||||
if self.index >= len(self.content):
|
|
||||||
self.index = 0
|
|
||||||
self.update(0)
|
|
||||||
eval("self.window.on_mouse_" + state['event'] + "_" + self.name + "(" + str(state) + ")")
|
|
||||||
if debug==1: print state,self.name
|
|
||||||
|
|
||||||
def on_mouse_press(self, x, y, button, modifiers):
|
|
||||||
if x > self.x and y > self.y and x < self.x + self.width and y < self.y + self.height and self.isactive() and self.isvisible():
|
|
||||||
if time.time() - self.time < 0.30:
|
|
||||||
state = {'x': x, 'y': y, 'dx': 0, 'dy': 0, 'buttons': button, 'modifiers': modifiers, 'event': 'double'}
|
|
||||||
self.launch(state)
|
|
||||||
self.time = time.time()
|
|
||||||
state = {'x': x, 'y': y, 'dx': 0, 'dy': 0, 'buttons': button, 'modifiers': modifiers, 'event': 'press'}
|
|
||||||
self.launch(state)
|
|
||||||
|
|
||||||
def on_mouse_release(self, x, y, button, modifiers):
|
|
||||||
if x > self.x and y > self.y and x < self.x + self.width and y < self.y + self.height and self.isactive() and self.isvisible():
|
|
||||||
state = {'x': x, 'y': y, 'dx': 0, 'dy': 0, 'buttons': button, 'modifiers': modifiers, 'event': 'release'}
|
|
||||||
self.launch(state)
|
|
||||||
|
|
||||||
def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
|
|
||||||
if x > self.x and y > self.y and x < self.x + self.width and y < self.y + self.height and self.isactive() and self.isvisible():
|
|
||||||
state = {'x': x, 'y': y, 'dx': dx, 'dy': dy, 'buttons': buttons, 'modifiers': modifiers, 'event': 'drag'}
|
|
||||||
self.launch(state)
|
|
||||||
|
|
||||||
def on_mouse_scroll(self, x, y, scroll_x, scroll_y):
|
|
||||||
if x > self.x and y > self.y and x < self.x + self.width and y < self.y + self.height and self.isactive() and self.isvisible():
|
|
||||||
state = {'x': x, 'y': y, 'dx': scroll_x, 'dy': scroll_y, 'buttons': 0, 'modifiers': 0, 'event': 'scroll'}
|
|
||||||
self.launch(state)
|
|
||||||
|
|
||||||
def on_mouse_motion(self, x, y, dx, dy):
|
|
||||||
if x > self.x and y > self.y and x < self.x + self.width and y < self.y + self.height:
|
|
||||||
if self.isvisible() and self.isactive():
|
|
||||||
if self.enter == 0:
|
|
||||||
self.enter = 1
|
|
||||||
state = {'x': x, 'y': y, 'dx': dx, 'dy': dy, 'buttons': 0, 'modifiers': 0, 'event': 'enter'}
|
|
||||||
self.launch(state)
|
|
||||||
state = {'x': x, 'y': y, 'dx': dx, 'dy': dy, 'buttons': 0, 'modifiers': 0, 'event': 'motion'}
|
|
||||||
self.launch(state)
|
|
||||||
else:
|
|
||||||
if self.enter == 1:
|
|
||||||
self.enter = 0
|
|
||||||
state = {'x': x, 'y': y, 'dx': dx, 'dy': dy, 'buttons': 0, 'modifiers': 0, 'event': 'leave'}
|
|
||||||
self.launch(state)
|
|
||||||
|
|
||||||
def setselected(self, select):
|
|
||||||
self.selected = select
|
|
||||||
self.update(0)
|
|
||||||
|
|
||||||
def isvisible(self):
|
|
||||||
if type(self.visible) is bool:
|
|
||||||
return self.visible
|
|
||||||
else:
|
|
||||||
return eval(self.visible)
|
|
||||||
|
|
||||||
def isactive(self):
|
|
||||||
if type(self.active) is bool:
|
|
||||||
return self.active
|
|
||||||
else:
|
|
||||||
return eval(self.active)
|
|
||||||
|
|
||||||
def ishilite(self):
|
|
||||||
if type(self.hilite) is bool:
|
|
||||||
return self.hilite
|
|
||||||
else:
|
|
||||||
return eval(self.hilite)
|
|
||||||
|
|
||||||
def hide(self):
|
|
||||||
if type(self.visible) is bool:
|
|
||||||
self.visible = False
|
|
||||||
self.update(0)
|
|
||||||
|
|
||||||
def show(self):
|
|
||||||
if type(self.visible) is bool:
|
|
||||||
self.visible = True
|
|
||||||
self.update(0)
|
|
||||||
|
|
||||||
def activate(self):
|
|
||||||
if type(self.active) is bool:
|
|
||||||
self.active = True
|
|
||||||
self.update(0)
|
|
||||||
|
|
||||||
def unactivate(self):
|
|
||||||
if type(self.active) is bool:
|
|
||||||
self.active = False
|
|
||||||
self.update(0)
|
|
||||||
|
|
||||||
def hilitate(self):
|
|
||||||
if type(self.hilite) is bool:
|
|
||||||
self.hilite = True
|
|
||||||
self.update(0)
|
|
||||||
|
|
||||||
def unhilitate(self):
|
|
||||||
if type(self.hilite) is bool:
|
|
||||||
self.hilite = False
|
|
||||||
self.update(0)
|
|
||||||
|
|
||||||
|
|
||||||
''' *********************************************************************************************** '''
|
''' *********************************************************************************************** '''
|
||||||
''' Gestion du plateau de jeu '''
|
''' Gestion du plateau de jeu '''
|
||||||
|
@ -592,12 +242,12 @@ class menu(pyglet.window.Window):
|
||||||
self.clocks = [clock.schedule(self.draw), clock.schedule_interval(self.movefond, 0.03)]
|
self.clocks = [clock.schedule(self.draw), clock.schedule_interval(self.movefond, 0.03)]
|
||||||
self.loc = [0, 0, 1, 1]
|
self.loc = [0, 0, 1, 1]
|
||||||
self.selected = -1
|
self.selected = -1
|
||||||
self.icons=[abutton(self, 'icon_0', 740, 110, 120, 0, True, False, False, False,pyglet.image.load('picture/cout.png'), 'test', 'icon_right', ' '),
|
self.icons=[abutton(self, 740, 110, 120, 0, 'icon_0', active=True, hilite=False, visible=False, selected=False, content=pyglet.image.load('picture/cout.png'), text='test', typeof='icon',align='right', hint=' '),
|
||||||
abutton(self, 'icon_1', 740, 65, 120, 0, True, False, False, False,pyglet.image.load('picture/cycle.png'), 'test', 'icon_right', ' '),
|
abutton(self, 740, 65, 120, 0, 'icon_1', active=True, hilite=False, visible=False, selected=False, content=pyglet.image.load('picture/cycle.png'), text='test', typeof='icon',align='right', hint=' '),
|
||||||
abutton(self, 'icon_2', 940, 110, 70, 0, True, False, False, False,pyglet.image.load('picture/tech.png'), 'test', 'icon_right', ' '),
|
abutton(self, 940, 110, 70, 0, 'icon_2', active=True, hilite=False,visible=False, selected=False, content=pyglet.image.load('picture/tech.png'), text='test', typeof='icon',align='right', hint=' '),
|
||||||
abutton(self, 'icon_3', 940, 65, 70, 0, True, False, False, False,pyglet.image.load('picture/rayon.png'), 'test', 'icon_right', ' '),
|
abutton(self, 940, 65, 70, 0, 'icon_3', active=True, hilite=False, visible=False, selected=False, content=pyglet.image.load('picture/rayon.png'), text='test', typeof='icon',align='right', hint=' '),
|
||||||
abutton(self, 'icon_4', 850, 110, 70, 0, True, False, False, False,pyglet.image.load('picture/temp.png'), 'test', 'icon_right', ' '),
|
abutton(self, 850, 110, 70, 0, 'icon_4', active=True, hilite=False, visible=False, selected=False, content=pyglet.image.load('picture/temp.png'), text='test', typeof='icon',align='right', hint=' '),
|
||||||
abutton(self, 'icon_5', 850, 65, 70, 0, True, False, False, False,pyglet.image.load('picture/nrj.png'), 'test', 'icon_right', ' ')]
|
abutton(self, 850, 65, 70, 0, 'icon_5', active=True, hilite=False, visible=False, selected=False, content=pyglet.image.load('picture/nrj.png'), text='test', typeof='icon',align='right', hint=' ')]
|
||||||
self.images = [pyglet.image.load('picture/leveler0.png'), pyglet.image.load('picture/leveler1.png'),
|
self.images = [pyglet.image.load('picture/leveler0.png'), pyglet.image.load('picture/leveler1.png'),
|
||||||
pyglet.image.load('picture/leveler2.png'), pyglet.image.load('picture/leveler3.png'),
|
pyglet.image.load('picture/leveler2.png'), pyglet.image.load('picture/leveler3.png'),
|
||||||
pyglet.image.load('picture/leveler4.png')]
|
pyglet.image.load('picture/leveler4.png')]
|
||||||
|
@ -613,30 +263,30 @@ class menu(pyglet.window.Window):
|
||||||
self.rects = [arect(self,740,148,1016,8,1,[40,40,40,255],self.p1),
|
self.rects = [arect(self,740,148,1016,8,1,[40,40,40,255],self.p1),
|
||||||
arect(self,8,8,1017,149,2,[90,90,90,170],self.p0)]
|
arect(self,8,8,1017,149,2,[90,90,90,170],self.p0)]
|
||||||
self.buttons = [
|
self.buttons = [
|
||||||
abutton(self, 'logo', 185, 'self.window.height-200', 0, 0, True, False, True, False,pyglet.image.load('picture/logo.png'), 'test', 'icon', ''),
|
abutton(self, 185, 'self.window.height-200', 0, 0, 'logo', active=True, hilite=False, visible=True, selected=False, content=pyglet.image.load('picture/logo.png'), text='', typeof='icon', hint=''),
|
||||||
abutton(self, 'logo2', 45, 'self.window.height-150', 0, 0, True, False, True, False,pyglet.image.load('picture/logo2.png'), 'test', 'icon', ''),
|
abutton(self, 45, 'self.window.height-150', 0, 0, 'logo2', active=True, hilite=False, visible=True, selected=False, content=pyglet.image.load('picture/logo2.png'), text='', typeof='icon', hint=''),
|
||||||
abutton(self, 'menu_0', 840, 150, 0, 0, True, False, True, False, pyglet.image.load('picture/arrows.png'),'test', 'icon', ''),
|
abutton(self, 840, 150, 0, 0, 'menu_0', active=True, hilite=False, visible=True, selected=False, content=pyglet.image.load('picture/arrows.png'),text='', typeof='icon', hint=''),
|
||||||
abutton(self, 'menu_1', 920, 150, 0, 0, True, False, True, False, pyglet.image.load('picture/arrows2.png'),'test', 'icon', ''),
|
abutton(self, 920, 150, 0, 0, 'menu_1', active=True, hilite=False, visible=True, selected=False, content=pyglet.image.load('picture/arrows2.png'),text='', typeof='icon', hint=''),
|
||||||
abutton(self, 'menu_2', 940, 'self.window.height-100', 0, 0, True, False, True, False,pyglet.image.load('picture/exit2.png'), 'test', 'icon', '')
|
abutton(self, 940, 'self.window.height-100', 0, 0, 'menu_2', active=True, hilite=False, visible=True, selected=False, content=pyglet.image.load('picture/exit2.png'), text='', typeof='icon', hint='')
|
||||||
]
|
]
|
||||||
self.infos = [atext(self, "c un test", 12, 8, 730, 140, 'OpenDyslexicAlta', 15)]
|
self.infos = [atext(self, 12, 8, 730, 140, text="c un test", font='OpenDyslexicAlta', size=15)]
|
||||||
self.infos[0].layout.begin_update()
|
self.infos[0].layout.begin_update()
|
||||||
self.infos[0].color=(255,255,255,255)
|
self.infos[0].color=(255,255,255,255)
|
||||||
self.infos[0].layout.document.set_style(0, len(self.infos[0].layout.document.text), dict(align="left"))
|
self.infos[0].layout.document.set_style(0, len(self.infos[0].layout.document.text), dict(align="left"))
|
||||||
self.infos[0].layout.end_update()
|
self.infos[0].layout.end_update()
|
||||||
self.infos[0].text=" "
|
self.infos[0].text=" "
|
||||||
self.infos[0].update()
|
self.infos[0].update(0)
|
||||||
self.victorys = [abutton(self, 'victory_'+str(i), 740+21*i, 12, 21, 38, True, False, True, False, self.thecolors[i], 'test', 'color', self.names[i]+"\n0") for i in range(len(self.names))]
|
self.victorys = [abutton(self, 740+21*i, 12, 21, 38, 'victory_'+str(i), active=True, hilite=False, visible=True, selected=False, content=self.thecolors[i], text='test', typeof='color', hint=self.names[i]+"\n0") for i in range(len(self.names))]
|
||||||
for i in range(len(self.names)):
|
for i in range(len(self.names)):
|
||||||
self.victorys[i].layout.document.set_style(0,2,dict(font_name="Mechanihan", font_size=10, color=(180,180,180,255), align="left"))
|
self.victorys[i].layout.document.set_style(0,2,dict(font_name="Mechanihan", font_size=10, color=(180,180,180,255), align="left"))
|
||||||
self.victorys[i].layout.document.set_style(1,1,dict(font_name="Mechanihan", font_size=14, bold=True ,color=(180,180,180,255), align="left"))
|
self.victorys[i].layout.document.set_style(1,1,dict(font_name="Mechanihan", font_size=14, bold=True ,color=(180,180,180,255), align="left"))
|
||||||
self.victorys[i].layout.content_valign="top"
|
self.victorys[i].layout.content_valign="top"
|
||||||
self.levels = [abutton(self, 'level_'+str(i), -250, 0, 0, 0, True, False, True, False, self.images[level], 'test', 'icon', '') for i in range(10)]
|
self.levels = [abutton(self, -250, 0, 0, 0, 'level_'+str(i), active=True, hilite=False, visible=True, selected=False, content=self.images[level], text='test', typeof='icon', hint='') for i in range(10)]
|
||||||
self.untitled2 = [atext(self, "text", -300, -300, 300, 0, 'Fluoxetine', 18) for i in range(10)]
|
self.untitled2 = [atext(self, -300, -300, 300, 0, text="", font='Fluoxetine', size=18) for i in range(10)]
|
||||||
self.untitled = [atext(self, "text", -300, -300, 60, 0, 'Vademecum', 23) for i in range(10)]
|
self.untitled = [atext(self, -300, -300, 60, 0, text="", font='Vademecum', size=23) for i in range(10)]
|
||||||
self.special = pyglet.sprite.Sprite(pyglet.image.load('picture/boss.png'), batch=self.batch, group=self.p4,x=-300, y=-300)
|
self.special = pyglet.sprite.Sprite(pyglet.image.load('picture/boss.png'), batch=self.batch, group=self.p4,x=-300, y=-300)
|
||||||
self.lock = [pyglet.sprite.Sprite(pyglet.image.load('picture/locked.png'), batch=self.batch, group=self.p4, x=-300, y=-300) for i in range(10)]
|
self.lock = [pyglet.sprite.Sprite(pyglet.image.load('picture/locked.png'), batch=self.batch, group=self.p4, x=-300, y=-300) for i in range(10)]
|
||||||
self.update(0)
|
self.update(0)
|
||||||
|
|
||||||
def on_resize(self, width, height):
|
def on_resize(self, width, height):
|
||||||
super(menu, self).on_resize(width, height)
|
super(menu, self).on_resize(width, height)
|
||||||
|
@ -682,8 +332,8 @@ class menu(pyglet.window.Window):
|
||||||
self.untitled2[l].x = -300
|
self.untitled2[l].x = -300
|
||||||
self.lock[l].x = -300
|
self.lock[l].x = -300
|
||||||
self.levels[l].update(0)
|
self.levels[l].update(0)
|
||||||
self.untitled2[l].update()
|
self.untitled2[l].update(0)
|
||||||
self.untitled[l].update()
|
self.untitled[l].update(0)
|
||||||
continue
|
continue
|
||||||
ele = worlds[world][l]
|
ele = worlds[world][l]
|
||||||
self.levels[l].active = (world, l) in finished or debug == 2
|
self.levels[l].active = (world, l) in finished or debug == 2
|
||||||
|
@ -699,7 +349,7 @@ class menu(pyglet.window.Window):
|
||||||
self.untitled[l].loaded = 'worlds[' + str(world) + '][' + str(l) + ']["element"]'
|
self.untitled[l].loaded = 'worlds[' + str(world) + '][' + str(l) + ']["element"]'
|
||||||
self.untitled[l].color = (
|
self.untitled[l].color = (
|
||||||
int(ele['_xx'] / 1024.0 * 150), int(ele['_xx'] / 1024.0 * 150), int(ele['_xx'] / 1024.0 * 150), 255)
|
int(ele['_xx'] / 1024.0 * 150), int(ele['_xx'] / 1024.0 * 150), int(ele['_xx'] / 1024.0 * 150), 255)
|
||||||
self.untitled[l].update()
|
self.untitled[l].update(0)
|
||||||
self.untitled2[l].text = ele['nom'].decode('utf-8')
|
self.untitled2[l].text = ele['nom'].decode('utf-8')
|
||||||
self.untitled2[l].x = ele['_xx'] + (self.images[world].width - 300) / 2
|
self.untitled2[l].x = ele['_xx'] + (self.images[world].width - 300) / 2
|
||||||
self.untitled2[l].y = ele['_yy'] / 768.0 * self.height - 25
|
self.untitled2[l].y = ele['_yy'] / 768.0 * self.height - 25
|
||||||
|
@ -708,7 +358,7 @@ class menu(pyglet.window.Window):
|
||||||
self.untitled2[l].color = (255, 255, 255, 255)
|
self.untitled2[l].color = (255, 255, 255, 255)
|
||||||
else:
|
else:
|
||||||
self.untitled2[l].color = (90, 90, 90, 255)
|
self.untitled2[l].color = (90, 90, 90, 255)
|
||||||
self.untitled2[l].update()
|
self.untitled2[l].update(0)
|
||||||
self.lock[l].visible = (world, l) not in finished and not debug == 2
|
self.lock[l].visible = (world, l) not in finished and not debug == 2
|
||||||
self.lock[l].x = ele['_xx'] + 10
|
self.lock[l].x = ele['_xx'] + 10
|
||||||
self.lock[l].y = ele['_yy'] / 768.0 * self.height + 50
|
self.lock[l].y = ele['_yy'] / 768.0 * self.height + 50
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<b>Version de Wirechem: V0.2a</b>
|
||||||
|
|
||||||
|
Version de développement alpha.
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/bash
|
||||||
|
export DISPLAY=":0"
|
||||||
|
su -c "startx" wirechem &
|
||||||
|
while true
|
||||||
|
do
|
||||||
|
launch=`ps ax|grep init.py|grep python`
|
||||||
|
if [ "$launch" == "" ]; then
|
||||||
|
su -c "python /srv/init.py" wirechem
|
||||||
|
fi
|
||||||
|
done
|
|
@ -0,0 +1,345 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
'''
|
||||||
|
------------------------------------------
|
||||||
|
|
||||||
|
Microlinux
|
||||||
|
|
||||||
|
Programme principal
|
||||||
|
|
||||||
|
(C) Copyright 2013-2014 Nicolas Hordé
|
||||||
|
|
||||||
|
------------------------------------------
|
||||||
|
'''
|
||||||
|
import subprocess
|
||||||
|
import datetime
|
||||||
|
import math
|
||||||
|
import copy
|
||||||
|
import random
|
||||||
|
import time
|
||||||
|
import operator
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import socket
|
||||||
|
import httplib
|
||||||
|
import urllib
|
||||||
|
|
||||||
|
import pyglet
|
||||||
|
from GLclass import *
|
||||||
|
from pyglet.gl import *
|
||||||
|
from pyglet.window import mouse
|
||||||
|
from pyglet.window import key
|
||||||
|
from pyglet import clock
|
||||||
|
from pyglet import image
|
||||||
|
from git import Git
|
||||||
|
|
||||||
|
''' *********************************************************************************************** '''
|
||||||
|
''' initialisation '''
|
||||||
|
|
||||||
|
global debug,user,hostname
|
||||||
|
hostname=socket.getfqdn()
|
||||||
|
user=""
|
||||||
|
debug = 1
|
||||||
|
animate = 0
|
||||||
|
|
||||||
|
''' *********************************************************************************************** '''
|
||||||
|
''' Gestion du menu principal '''
|
||||||
|
|
||||||
|
#Classe du menu principal
|
||||||
|
class menu(pyglet.window.Window):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
global debug, worlds, world
|
||||||
|
super(menu, self).__init__(resizable=True, fullscreen=True, visible=True,
|
||||||
|
caption="Microlinux - Lancement")
|
||||||
|
|
||||||
|
self.set_mouse_cursor(cursors['cross'])
|
||||||
|
self.batch = pyglet.graphics.Batch()
|
||||||
|
self.p0 = pyglet.graphics.OrderedGroup(0)
|
||||||
|
self.p1 = pyglet.graphics.OrderedGroup(1)
|
||||||
|
self.p2 = pyglet.graphics.OrderedGroup(2)
|
||||||
|
self.p3 = pyglet.graphics.OrderedGroup(3)
|
||||||
|
self.p4 = pyglet.graphics.OrderedGroup(4)
|
||||||
|
self.clocks = [clock.schedule(self.draw)]
|
||||||
|
self.count=0
|
||||||
|
self.focus = None
|
||||||
|
self.icons = [ainter(self, 20, self.height-185, pyglet.resource.image('picture/restart.png'), 'Redemarre la machine instantanement.', 'Redemarrer', 'sudo reboot',font="Mechanihan")]
|
||||||
|
self.icons.extend([ainter(self, 20+self.icons[0].width*1.4, self.height-185, pyglet.resource.image('picture/eteindre.png'), "Eteindre votre ordinateur.", 'Eteindre', 'sudo halt',font="Mechanihan"),
|
||||||
|
ainter(self, 20+2*self.icons[0].width*1.4, self.height-185, pyglet.resource.image('picture/terminal.png'), "Lancement d'un terminal.", 'Terminal', 'xterm',font="Mechanihan"),
|
||||||
|
ainter(self, self.width-20-self.icons[0].width*1.4, 60+self.icons[0].width*0.6, pyglet.resource.image('picture/web.png'), 'Site internet de WireChem...', 'Site WWW', 'netsurf http://evolving.fr',font="Mechanihan"),
|
||||||
|
ainter(self, self.width-20-2*self.icons[0].width*1.4, 60+self.icons[0].width*0.6, pyglet.resource.image('picture/bug.png'), 'Soumettre un bogue ou un rapport de bêta testeur.', 'Beta-test', 'netsurf http://evolving.fr/ecrire/special.php?login=pinon&pass=poppop&where=14',font="Mechanihan"),
|
||||||
|
ainter(self, self.width-20-3*self.icons[0].width*1.4, 60+self.icons[0].width*0.6, pyglet.resource.image('picture/compte.png'), 'Votre compte...', 'Mon compte', 'netsurf http://evolving.fr',font="Mechanihan"),
|
||||||
|
ainter(self, 20, 60+self.icons[0].width*0.6, pyglet.resource.image('picture/wirechem.png'), "Lancer le jeu WireChem", 'WireChem', '/srv/launch',font="Mechanihan"),
|
||||||
|
ainter(self, self.width-400-self.icons[0].width*1.4, self.height-185, pyglet.resource.image('picture/musique.png'), "Réglage du son.", 'Son...', 'gnome-alsamixer',font="Mechanihan"),
|
||||||
|
ainter(self, self.width-400-2*self.icons[0].width*1.4, self.height-185, pyglet.resource.image('picture/net.png'), "Réglage du Réseau.", 'Reseau...', '/srv/network',font="Mechanihan"),
|
||||||
|
ainter(self, self.width-400-3*self.icons[0].width*1.4, self.height-185, pyglet.resource.image('picture/ecran.png'), "Configuration des options vidéo.", 'Video...', 'arandr',font="Mechanihan"),
|
||||||
|
ainter(self, 20, self.height/2-40, pyglet.resource.image('picture/info.png'), "Information sur la version du logiciel WireChem.", 'Informations', 'netsurf file:///srv/infos.html',font="Mechanihan")])
|
||||||
|
self.rects=[arect(self,10, 10, self.width-20,125, typeof="both", color=(100,100,100,200), group=self.p3)]
|
||||||
|
self.hostname=alabel(self,10,self.height-15,text=hostname,font='Deja vu',size=12,group=self.p4)
|
||||||
|
self.dialog=[alabel(self,self.width-380,self.height-60,text='identifiant :',font='Deja vu',size=16,group=self.p4,visible=False),
|
||||||
|
alabel(self,self.width-380,self.height-120,text='mot de passe :',font='Deja vu',size=16,group=self.p4,visible=False),
|
||||||
|
atext(self,self.width-215,self.height-65,170,0,text="",font='Deja vu',align="left",size=16,visible=False),
|
||||||
|
atext(self,self.width-215,self.height-125,170,0,text="",font='password',align="left",size=16,visible=False),
|
||||||
|
abutton(self,self.width-190, self.height-195,0,0,"connect",content=pyglet.resource.image('picture/connexion.png'),typeof="icon",visible=False),
|
||||||
|
arect(self,self.width-400,self.height-230,390,220,typeof="face", color=(100,100,100,200), group=self.p3,visible=False),
|
||||||
|
arect(self,self.width-218,self.height-65,175,25,typeof="face", color=(150,150,150,255), group=self.p2,visible=False),
|
||||||
|
arect(self,self.width-218,self.height-125,175,25,typeof="face", color=(150,150,150,255), group=self.p2,visible=False)]
|
||||||
|
self.dialog[4].sprite.group=self.p4
|
||||||
|
self.dialog2=[alabel(self,0,0,text='',font='Deja vu',size=16,group=self.p4,visible=False),
|
||||||
|
abutton(self, 0, 0,0,0,"deconnect",content=pyglet.resource.image('picture/deconnexion.png'),typeof="icon",visible=False),
|
||||||
|
arect(self,0,0,290,90,typeof="face", color=(100,100,100,200), group=self.p2,visible=False)]
|
||||||
|
self.dialog2[1].sprite.group=self.p4
|
||||||
|
self.infos=[atext(self, 10, 10, self.width-10, 125, font="Mechanihan", size=18, align="left")]
|
||||||
|
self.fond = abutton(self, "(self.window.width-800)/2", "(self.window.height-175+125)/2", 0, 0,"fond",content=pyglet.resource.image('picture/logo3.png'),typeof='icon')
|
||||||
|
self.fond.sprite.group=self.p0
|
||||||
|
self.setfocus(self.dialog[2])
|
||||||
|
self.icons[4].visible=False
|
||||||
|
self.icons[5].visible=False
|
||||||
|
self.icons[4].update(0)
|
||||||
|
self.icons[5].update(0)
|
||||||
|
self.update(0)
|
||||||
|
|
||||||
|
|
||||||
|
self.geticons()
|
||||||
|
|
||||||
|
def geticons(self):
|
||||||
|
global user
|
||||||
|
ui = Git(".")
|
||||||
|
try:
|
||||||
|
version_temp=ui.ls_remote("git://github.com/dahut87/WireChem.git")
|
||||||
|
version=version_temp.replace('\n','\t').split('\t')
|
||||||
|
add=0
|
||||||
|
for i in range(len(version)):
|
||||||
|
if i%2==1 and version[i]!="HEAD" and '^' not in version[i]:
|
||||||
|
add+=1
|
||||||
|
self.icons.append(ainter(self, 20+add*(self.icons[0].width*1.4), 60+self.icons[0].width*0.6, pyglet.resource.image('picture/git.png'), "Lancer le jeu WireChem dans une version particulière de développement.", os.path.basename(version[i]), 'xterm -e /srv/launch '+os.path.basename(version[i]),font="Mechanihan"))
|
||||||
|
self.icons.append(ainter(self, self.width-20-self.icons[0].width*1.4, self.height/2-40, pyglet.resource.image('picture/connect.png'), "Le système est connecté au réseau et opérationnel, double cliquez pour rafraichir !", "Connecte", 'killall python',font="Mechanihan"))
|
||||||
|
except:
|
||||||
|
self.icons.append(ainter(self, self.width-20-self.icons[0].width*1.4, self.height/2-40, pyglet.resource.image('picture/disconnect.png'), "Le système n'est pas convenablement connecté au réseau, double cliquez pour réessayer !", "Deconnecte", 'killall python',font="Mechanihan"))
|
||||||
|
|
||||||
|
def update(self, what):
|
||||||
|
global user
|
||||||
|
if user!="":
|
||||||
|
self.hidemdp()
|
||||||
|
self.showlog()
|
||||||
|
else:
|
||||||
|
self.hidelog()
|
||||||
|
self.showmdp()
|
||||||
|
|
||||||
|
def connectsite(self, user, password):
|
||||||
|
print user,password
|
||||||
|
params = urllib.urlencode({'login': user, 'pass': password})
|
||||||
|
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
|
||||||
|
conn = httplib.HTTPConnection("wirechem.dahut.fr:80")
|
||||||
|
conn.request("POST", "/ecrire/special.php", params, headers)
|
||||||
|
response = conn.getresponse()
|
||||||
|
state=''
|
||||||
|
if response.status==200:
|
||||||
|
state = response.read()
|
||||||
|
conn.close()
|
||||||
|
if state=="1":
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def draw(self, dt):
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT)
|
||||||
|
self.batch.draw()
|
||||||
|
|
||||||
|
def hidemdp(self):
|
||||||
|
for i in range(len(self.dialog)):
|
||||||
|
self.dialog[i].visible=False
|
||||||
|
self.dialog[i].update(0)
|
||||||
|
|
||||||
|
def showmdp(self):
|
||||||
|
for i in range(len(self.dialog)):
|
||||||
|
self.dialog[i].visible=True
|
||||||
|
self.dialog[i].update(0)
|
||||||
|
self.setfocus(self.dialog[2])
|
||||||
|
|
||||||
|
def showlog(self):
|
||||||
|
global user
|
||||||
|
self.dialog2[0].visible=True
|
||||||
|
self.dialog2[0].text=user
|
||||||
|
self.dialog2[0].x=self.width+(self.dialog2[0].content_width-300)/2-self.dialog2[0].content_width
|
||||||
|
self.dialog2[0].y=self.height-35
|
||||||
|
self.dialog2[1].visible=True
|
||||||
|
self.dialog2[1].x=self.width-self.dialog2[1].width-62
|
||||||
|
self.dialog2[1].y=self.height-85
|
||||||
|
self.dialog2[1].update(0)
|
||||||
|
self.dialog2[2].visible=True
|
||||||
|
self.dialog2[2].x=self.width-300
|
||||||
|
self.dialog2[2].y=self.height-100
|
||||||
|
self.dialog2[2].update(0)
|
||||||
|
|
||||||
|
def hidelog(self):
|
||||||
|
for i in range(len(self.dialog2)):
|
||||||
|
self.dialog2[i].visible=False
|
||||||
|
self.dialog2[i].update(0)
|
||||||
|
|
||||||
|
def anime(self,dt):
|
||||||
|
global animate
|
||||||
|
if animate==0:
|
||||||
|
self.infos[0].text="Mot de passe incorrect !! Veuillez retaper votre mot de passe s'il vous plait."
|
||||||
|
self.infos[0].update(0)
|
||||||
|
animate=16*math.pi
|
||||||
|
animate-=math.pi/4
|
||||||
|
if animate>0:
|
||||||
|
clock.schedule_once(self.anime,0.02)
|
||||||
|
else:
|
||||||
|
animate=0
|
||||||
|
self.infos[0].text=" "
|
||||||
|
self.infos[0].update(0)
|
||||||
|
for i in range(len(self.dialog)):
|
||||||
|
self.dialog[i].x+=int(5*math.sin(animate))
|
||||||
|
if hasattr(self.dialog[i],"update"):
|
||||||
|
self.dialog[i].update(0)
|
||||||
|
|
||||||
|
### Evenements ###
|
||||||
|
|
||||||
|
def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
|
||||||
|
if self.focus:
|
||||||
|
self.focus.caret.on_mouse_drag(x, y, dx, dy, buttons, modifiers)
|
||||||
|
|
||||||
|
def on_mouse_press(self, x, y, button, modifiers):
|
||||||
|
for widget in [self.dialog[2],self.dialog[3]]:
|
||||||
|
if widget.hit_test(x, y):
|
||||||
|
self.setfocus(widget)
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
self.setfocus(None)
|
||||||
|
|
||||||
|
if self.focus:
|
||||||
|
self.focus.caret.on_mouse_press(x, y, button, modifiers)
|
||||||
|
|
||||||
|
def on_mouse_motion(self, x, y, dx, dy):
|
||||||
|
for widget in [self.dialog[2],self.dialog[3]]:
|
||||||
|
if widget.hit_test(x, y):
|
||||||
|
self.set_mouse_cursor(cursors["text"])
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
self.set_mouse_cursor(cursors["cross"])
|
||||||
|
|
||||||
|
def on_text(self, text):
|
||||||
|
if self.focus:
|
||||||
|
self.focus.caret.on_text(text)
|
||||||
|
|
||||||
|
def on_text_motion(self, motion):
|
||||||
|
if self.focus:
|
||||||
|
self.focus.caret.on_text_motion(motion)
|
||||||
|
|
||||||
|
def on_text_motion_select(self, motion):
|
||||||
|
if self.focus:
|
||||||
|
self.focus.caret.on_text_motion_select(motion)
|
||||||
|
|
||||||
|
def on_key_press(self, symbol, modifiers):
|
||||||
|
global user
|
||||||
|
if symbol == pyglet.window.key.TAB:
|
||||||
|
if modifiers & pyglet.window.key.MOD_SHIFT:
|
||||||
|
dir = -1
|
||||||
|
else:
|
||||||
|
dir = 1
|
||||||
|
all=(self.dialog[2],self.dialog[3])
|
||||||
|
if self.focus in all:
|
||||||
|
i = all.index(self.focus)
|
||||||
|
else:
|
||||||
|
i = 0
|
||||||
|
dir = 0
|
||||||
|
self.setfocus(all[(i + dir) % len(all)])
|
||||||
|
elif symbol == key.ESCAPE:
|
||||||
|
if debug==0:
|
||||||
|
return pyglet.event.EVENT_HANDLED
|
||||||
|
else:
|
||||||
|
pyglet.app.exit()
|
||||||
|
elif symbol == key.F5:
|
||||||
|
self.close()
|
||||||
|
launch()
|
||||||
|
elif symbol == key.ENTER:
|
||||||
|
if user=="":
|
||||||
|
self.on_mouse_press_connect([])
|
||||||
|
|
||||||
|
def setfocus(self, focus):
|
||||||
|
if self.focus:
|
||||||
|
self.focus.caret.visible = False
|
||||||
|
self.focus.caret.mark = self.focus.caret.position = 0
|
||||||
|
self.focus = focus
|
||||||
|
if self.focus:
|
||||||
|
self.focus.caret.visible = True
|
||||||
|
self.focus.caret.mark = 0
|
||||||
|
self.focus.caret.position = len(self.focus.document.text)
|
||||||
|
|
||||||
|
### Evenement générer par classe abutton ###
|
||||||
|
|
||||||
|
def on_mouse_press_deconnect(self, state):
|
||||||
|
global user
|
||||||
|
user=""
|
||||||
|
self.icons[len(self.icons)-1].content=pyglet.resource.image('picture/connect2.png')
|
||||||
|
self.icons[len(self.icons)-1].update(0)
|
||||||
|
self.update(0)
|
||||||
|
|
||||||
|
def on_mouse_press_connect(self, state):
|
||||||
|
global user
|
||||||
|
if animate>0:
|
||||||
|
return
|
||||||
|
if self.connectsite(self.dialog[2].layout.document.text,self.dialog[3].layout.document.text):
|
||||||
|
user=self.dialog[2].layout.document.text
|
||||||
|
self.icons[len(self.icons)-1].content=pyglet.resource.image('picture/connect2.png')
|
||||||
|
self.icons[len(self.icons)-1].update(0)
|
||||||
|
self.update(0)
|
||||||
|
else:
|
||||||
|
user=''
|
||||||
|
self.anime(0.02)
|
||||||
|
|
||||||
|
def on_mouse_enter_item(self, n, state):
|
||||||
|
self.infos[0].text=self.icons[n].hint
|
||||||
|
self.infos[0].update(0)
|
||||||
|
self.set_mouse_cursor(cursors['pointer'])
|
||||||
|
self.icons[n].setselected([255, 120, 120])
|
||||||
|
|
||||||
|
def on_mouse_leave_item(self, n, state):
|
||||||
|
self.infos[0].text=" "
|
||||||
|
self.infos[0].update(0)
|
||||||
|
self.set_mouse_cursor(cursors['cross'])
|
||||||
|
self.icons[n].setselected(False)
|
||||||
|
|
||||||
|
def on_mouse_release_item(self, n, state):
|
||||||
|
self.set_mouse_cursor(cursors['cross'])
|
||||||
|
|
||||||
|
def on_mouse_double_item(self, n, state):
|
||||||
|
process = subprocess.Popen(self.icons[n].cmd.split(" "))
|
||||||
|
self.close()
|
||||||
|
process.wait()
|
||||||
|
launch()
|
||||||
|
|
||||||
|
def on_mouse_drag_item(self, n, state):
|
||||||
|
self.set_mouse_cursor(cursors['move'])
|
||||||
|
self.icons[n].x += state['dx']
|
||||||
|
self.icons[n].y += state['dy']
|
||||||
|
if state['dx']<0 and self.icons[n].x<20 : self.icons[n].x=0
|
||||||
|
if state['dx']>0 and self.icons[n].x>self.width-self.icons[n].width-20 : self.icons[n].x=self.width-self.icons[n].width
|
||||||
|
if state['dy']<0 and self.icons[n].y<20-self.icons[n].height : self.icons[n].y=0
|
||||||
|
if state['dy']>0 and self.icons[n].y>self.height-self.icons[n].height-20 : self.icons[n].y=self.height-self.icons[n].height
|
||||||
|
print str(self.icons[n].y)+","+str(self.icons[n].x)
|
||||||
|
self.icons[n].update(0)
|
||||||
|
|
||||||
|
def launch():
|
||||||
|
menu_principal = menu()
|
||||||
|
menu_principal.set_minimum_size(1024, 768)
|
||||||
|
glEnable(GL_BLEND)
|
||||||
|
#glEnable(GL_LINE_SMOOTH)
|
||||||
|
#glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST)
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
|
||||||
|
pyglet.app.run()
|
||||||
|
|
||||||
|
''' *********************************************************************************************** '''
|
||||||
|
''' Lancement du menu principal
|
||||||
|
'''
|
||||||
|
pyglet.resource.add_font('font/Mecanihan.ttf')
|
||||||
|
pyglet.resource.add_font('font/password.ttf')
|
||||||
|
cursors = {'pointer':pyglet.window.ImageMouseCursor(pyglet.resource.image('cursor/pointer.png'), 15, 46),
|
||||||
|
'text':pyglet.window.ImageMouseCursor(pyglet.resource.image('cursor/text.png'), 24, 30),
|
||||||
|
'move':pyglet.window.ImageMouseCursor(pyglet.resource.image('cursor/move.png'), 24, 24),
|
||||||
|
'create':pyglet.window.ImageMouseCursor(pyglet.resource.image('cursor/create.png'), 12, 17),
|
||||||
|
'cross':pyglet.window.ImageMouseCursor(pyglet.resource.image('cursor/cross.png'), 24, 33),
|
||||||
|
'delete':pyglet.window.ImageMouseCursor(pyglet.resource.image('cursor/delete.png'), 24, 32)}
|
||||||
|
launch()
|
|
@ -0,0 +1,9 @@
|
||||||
|
#!/bin/bash
|
||||||
|
if [ "$1" == "" ]; then
|
||||||
|
cd /srv/WireChem
|
||||||
|
python WireChem.py
|
||||||
|
else
|
||||||
|
git clone -b $1 git://github.com/dahut87/WireChem.git /srv/_version_$1
|
||||||
|
cd /srv/_version_$1
|
||||||
|
python WireChem.py
|
||||||
|
fi
|
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
export XAUTHORITY="/home/wirechem/.Xauthority"
|
||||||
|
export DISPLAY=":0"
|
||||||
|
sudo network-config
|
After Width: | Height: | Size: 29 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 3.0 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 7.8 KiB |
After Width: | Height: | Size: 79 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 21 KiB |
After Width: | Height: | Size: 7.2 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 9.0 KiB |
After Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 6.0 KiB |