[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [OT] Python Einstieg



Thomas Kuster schrieb:
Hallo zusammen

Ich suche eine freie, lesbare Einführung in Python. Ich habe auf die schnelle "Non-Programmers Tutorial For Python" gefunden, aber ich brauche wohl eher etwas ohne das Non am Anfang. Das gibts auch noch:
http://docs.python.org/tutorial/
und dort noch viele weitere. Mein Ziel ist es zu verstehen wieso das unten angehängte Python Programm sich nicht beendet, sondern hängen bleibt. Wenn ich auf meinem Openmoko (daher OT da dort ein SHR drauf läuft) auf «schliessen» klicke. Konkret geht es um die letzten Zeilen:
	if string.find(str(tmp), "12-Quit {}")!=-1:
		os.system("echo \"0\" > /sys/class/leds/neo1973\:vibrator/brightness")
		pygame.quit()
		exit()

Das Programm hängt bei pygame.quit(). Kommentier ich das aus hängt es trotzdem, schmeisse ich pygame.quit() und exit() raus und schreibe ein break hin kann ich dann zwar so was machen:
	if string.find(str(tmp), "12-Quit {}")!=-1:
		os.system("echo \"0\" > /sys/class/leds/neo1973\:vibrator/brightness")
		break

print "Ich werde ausgegeben beim Aufruf von beenden"

Und genau das verstehe ich überhaupt nicht ich dache dann kommt EOF und das Programm wird so oder so beendet.

Gruss
Thomas

#!/usr/bin/python
#
#       openmiaocat.py
# # Copyright 2009 Pietro Isotti <isottipietro@gmail.com> # # This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation; either version 2 of the License, or
#       (at your option) any later version.
# # This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
# # You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.

import time, os, string, pygame
from time import sleep

def draw_cat(screen):
		global img_cat
		#screen.fill((0,0,0))
		screen.blit(img_cat,(0, -32))
		pygame.display.update()

def purr(cmd):
	global pet, started
	if cmd:
		os.system("echo \"25\" > /sys/class/leds/neo1973\:vibrator/brightness")
		started = True
	if cmd and started:
		os.system("echo \"50\" > /sys/class/leds/neo1973\:vibrator/brightness")
	elif not cmd:
		started = False
		pet = 0
		os.system("echo \"40\" > /sys/class/leds/neo1973\:vibrator/brightness")
		sleep(0.5)
		os.system("echo \"30\" > /sys/class/leds/neo1973\:vibrator/brightness")
		sleep(0.5)
		os.system("echo \"20\" > /sys/class/leds/neo1973\:vibrator/brightness")
		sleep(0.5)
		os.system("echo \"0\" > /sys/class/leds/neo1973\:vibrator/brightness")
		
pygame.init()
SCREEN_SIZE = (480,640)
pet = 0
state = "up"
started = False
img_cat = pygame.image.load('/usr/share/pixmaps/openmiaocat/cat.png')
screen = pygame.display.set_mode(SCREEN_SIZE,0,32)
pygame.display.set_caption("MiaoCat")
#pygame.display.toggle_fullscreen()
pygame.mouse.set_visible(False)
draw_cat(screen)
t = time.time()
while 1:
	tmp=pygame.event.get()
	for i in tmp:
			print str(i)
			if string.find(str(i), "MouseButtonDown")!=-1:
				state="down"
			if string.find(str(i), "MouseButtonUp")!=-1:
				state="up"
				pet+=1
				t = time.time()
	if pet==2: purr(True)
	if pet==3: purr(True)
	if time.time()-t>3 and started: purr(False)
	if string.find(str(tmp), "12-Quit {}")!=-1:
		os.system("echo \"0\" > /sys/class/leds/neo1973\:vibrator/brightness")
		pygame.quit()
		exit()


Die Schleife sammelt alle Events in tmp auf. Das Event "12-Quit {}" führt zum Beenden.

Ich kann nichts Falsches finden.

Das klappt hier mit einem anderen Bild und Debian gut.
Warum es im OpenMoko nicht beendet ... ?

M.







Reply to: