本文整理汇总了Python中Timer.Timer.connect方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.connect方法的具体用法?Python Timer.connect怎么用?Python Timer.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timer.Timer
的用法示例。
在下文中一共展示了Timer.connect方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Muerta
# 需要导入模块: from Timer import Timer [as 别名]
# 或者: from Timer.Timer import connect [as 别名]
class Muerta(Sprite):
def __init__(self, pos, escala, TIME):
Sprite.__init__(self)
path = os.path.join(BASE_PATH, "Imagenes", "muerta.png")
imagen = pygame.image.load(path)
imagen_escalada = pygame.transform.scale(imagen, escala)
self.image = imagen_escalada.convert_alpha()
self.rect = self.image.get_rect()
self.image = pygame.transform.rotate(self.image, -pos[0])
self.rect.centerx = pos[1]
self.rect.centery = pos[2]
self.timer = Timer(TIME)
self.edad = {
"Años": 0,
"Dias": 0,
"Horas": 0}
self.timer.connect("new-time", self.__update_time)
def __update_time(self, widget, _dict):
self.edad = dict(_dict)
if self.edad["Dias"] >= 3:
self.morir()
def morir(self):
self.timer.salir()
self.kill()
示例2: Huevo
# 需要导入模块: from Timer import Timer [as 别名]
# 或者: from Timer.Timer import connect [as 别名]
class Huevo(Sprite, GObject.GObject):
__gsignals__ = {
"nacer": (GObject.SignalFlags.RUN_LAST,
None, (GObject.TYPE_PYOBJECT,
GObject.TYPE_PYOBJECT))}
def __init__(self, pos, TIME):
Sprite.__init__(self)
GObject.GObject.__init__(self)
path = os.path.join(BASE_PATH, "Imagenes", "huevos.png")
self.imagen = pygame.image.load(path)
self.imagen_original = self.imagen.convert_alpha()
self.image = self.imagen_original.copy()
self.image = pygame.transform.rotate(
self.imagen_original, -pos[0])
self.rect = self.image.get_bounding_rect()
self.rect.centerx = pos[1]
self.rect.centery = pos[2]
self.timer = Timer(TIME)
self.edad = {
"Años": 0,
"Dias": 0,
"Horas": 0}
self.timer.connect("new-time", self.__update_time)
def __update_time(self, widget, _dict):
self.edad = dict(_dict)
if self.edad["Dias"] >= 9:
random.seed()
huevos = random.randrange(10, 41, 1)
hembras = random.randrange(0, huevos, 1)
machos = huevos - hembras
self.emit("nacer", (hembras, machos),
(self.rect.centerx, self.rect.centery))
self.morir()
def morir(self):
self.timer.salir()
self.kill()
示例3: Cucaracha
# 需要导入模块: from Timer import Timer [as 别名]
# 或者: from Timer.Timer import connect [as 别名]
class Cucaracha(Sprite, GObject.GObject):
__gsignals__ = {
#"new-edad": (GObject.SignalFlags.RUN_LAST,
# None, (GObject.TYPE_PYOBJECT, )),
"muere": (GObject.SignalFlags.RUN_LAST,
None, (GObject.TYPE_PYOBJECT,
GObject.TYPE_PYOBJECT)),
"muda": (GObject.SignalFlags.RUN_LAST,
None, []),
"reproduce": (GObject.SignalFlags.RUN_LAST,
None, (GObject.TYPE_PYOBJECT, ))}
def __init__(self, sexo, ancho, alto, TIME):
Sprite.__init__(self)
GObject.GObject.__init__(self)
self.acciones = ["camina", "gira", "quieto"]
self.sexo = sexo
self.alimento = 0.0
self.agua = 0.0
self.accion = "camina"
self.contador = 0
random.seed()
self.sentido = random.choice(["+", "-"])
random.seed()
path = ""
if self.sexo == "macho":
self.imagen = random.choice(["cucaracha1.png", "cucaracha2.png"])
path = os.path.join(BASE_PATH, "Imagenes", self.imagen)
self.imagen = pygame.image.load(path)
elif self.sexo == "hembra":
self.imagen = random.choice(["cucaracha3.png", "cucaracha4.png"])
path = os.path.join(BASE_PATH, "Imagenes", self.imagen)
self.imagen = pygame.image.load(path)
self.escala = (53, 40)
imagen_escalada = pygame.transform.scale(self.imagen, self.escala)
self.imagen_original = imagen_escalada.convert_alpha()
self.dx = 0
self.dy = 0
self.angulo = 0
self.velocidad = 8
self.escena = pygame.Rect(35, 35, ancho - 70, alto - 70)
self.image = self.imagen_original.copy()
self.rect = self.image.get_bounding_rect()
self.rect.centerx = self.escena.w / 2
self.rect.centery = self.escena.h / 2
random.seed()
self.muerte = random.randrange(340, 365, 1) # morirá este dia
self.mudas = {
10: (63, 50),
50: (73, 60),
60: (83, 70),
90: (103, 90)}
self.repro = range(91, 330, random.randrange(15, 30, 1))
self.timer = Timer(TIME)
self.edad = {
"Años": 0,
"Dias": 0,
"Horas": 0}
self.timer.connect("new-time", self.__update_time)
def __update_time(self, widget, _dict):
self.edad = dict(_dict)
if self.edad["Dias"] in self.mudas.keys() and self.edad["Horas"] == 0:
self.__set_muda(escala=self.mudas[self.edad["Dias"]])
self.emit("muda")
elif self.edad["Dias"] in self.repro and self.edad["Horas"] == 0:
if self.sexo == "hembra":
grupo = self.groups()
cucas = grupo[0].sprites()
for cuca in cucas:
if cuca != self and cuca.sexo == "macho" and \
cuca.edad["Dias"] >= 190:
self.emit("reproduce", (self.angulo,
self.rect.centerx, self.rect.centery))
break
elif self.edad["Dias"] >= self.muerte:
self.emit("muere", (self.angulo,
self.rect.centerx, self.rect.centery), self.escala)
self.morir()
self.agua -= 1.0
self.alimento -= 1.0
if self.agua < -180.0 or self.alimento < -300.0:
self.morir()
def __actualizar_posicion(self):
x = self.rect.centerx + self.dx
y = self.rect.centery + self.dy
# FIXME: Sin límite en el habitat
if self.escena.collidepoint(x, y):
#.........这里部分代码省略.........
示例4: CucaraSims
# 需要导入模块: from Timer import Timer [as 别名]
# 或者: from Timer.Timer import connect [as 别名]
class CucaraSims(GObject.GObject):
__gsignals__ = {
"exit": (GObject.SignalFlags.RUN_LAST,
None, []),
"lectura": (GObject.SignalFlags.RUN_LAST,
None, (GObject.TYPE_STRING, )),
"clear-cursor-gtk": (GObject.SignalFlags.RUN_LAST,
None, []),
"update": (GObject.SignalFlags.RUN_LAST,
None, (GObject.TYPE_PYOBJECT, )),
"puntos": (GObject.SignalFlags.RUN_LAST,
None, (GObject.TYPE_INT, ))}
def __init__(self):
GObject.GObject.__init__(self)
self.RESOLUCION_INICIAL = RESOLUCION_INICIAL
self.resolucionreal = RESOLUCION_INICIAL
self.ventana_real = False
self.escenario = False
self.ventana = False
self.reloj = False
self.estado = 0
self.timer = False
self.edad = {
"Años": 0,
"Dias": 0,
"Horas": 0}
self.musica = False
self.cucas = pygame.sprite.RenderUpdates()
self.huevos = pygame.sprite.RenderUpdates()
self.muertas = pygame.sprite.RenderUpdates()
self.mouse = pygame.sprite.GroupSingle()
self.alimentos = pygame.sprite.RenderUpdates()
self.cursor_agua = False
self.cursor_pan = False
def __handle_event(self):
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
self.emit("exit")
return
elif event.type == pygame.MOUSEMOTION:
cursor = self.mouse.sprites()
if cursor:
cursor[0].pos(event.pos)
elif event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
cursor = self.mouse.sprites()
alimentos = self.alimentos.sprites()
if cursor:
tipo = cursor[0].tipo
self.set_cursor(False, False)
for alimento in alimentos:
if alimento.tipo == tipo:
self.alimentos.remove(alimento)
alimento.kill()
self.alimentos.add(Alimento(tipo, (event.pos)))
self.emit("clear-cursor-gtk")
else:
# Fixme: Casos a Considerar:
# Click sobre Cuca
for alimento in alimentos:
if alimento.rect.collidepoint(event.pos):
self.alimentos.remove(alimento)
alimento.kill()
self.emit("clear-cursor-gtk")
# Click sobre ooteca
# Click sobre muerta
# Click sobre el fondo
pygame.event.clear()
def __stop_timer(self, objeto):
try:
objeto.disconnect_by_func(self.__event_muerte)
except:
pass
try:
objeto.disconnect_by_func(self.__event_muda)
except:
pass
try:
objeto.disconnect_by_func(self.__event_repro)
except:
pass
objeto.morir()
def __connect_signals(self, objeto):
objeto.connect("muere", self.__event_muerte)
objeto.connect("muda", self.__event_muda)
objeto.connect("reproduce", self.__event_repro)
def __update_time(self, widget, _dict):
"""
#.........这里部分代码省略.........