Pyhon Qcake Comicviewer

From Wiki

Jump to: navigation, search

Contents

English

This is the wiki page for Lexi's Video Qcake Comic Viewer

The comic viewer is written in Python, but to re-do the example from the video, you need several other files:

  • Open Office Calc or any other program to manipulate csv-files. (Can be a simple text editor if you really know what you are doing)
  • The text-to-speech software espeak. If you are running Ubuntu espeak is maybe already installed.
  • A csv-list with the names of the graphics to watch, the name of the soundeffect-files to hear and the text to read out loud. The list ist called liste5.csv and you can find it in the zip-archive (see below).
  • Two graphic files for the Comicviewer (pfeil_rechts.png and pfeil_links.png). Those are the two blue arrows from the video. You can find those files in the zip-archive (see below).
  • The pictures and soudfiles namend in the csv-file. You can find them all in the zip-archive (complete with all other files and the sourcecode)


source code: comic-en.py

# -*- coding: utf-8 -*-
import Tkinter as t
import PIL.Image
import PIL.ImageTk
import csv
import subprocess


class App:
    def __init__(self, master):

        inputfile=file("liste5.csv", "rb")
        self.pictures = []
        
        for row in csv.reader(inputfile):
        	self.pictures.append(row) 
        inputfile.close()
    	
        frame = t.Frame(master)
        frame.pack(side=t.TOP, ancho=t.W)
        self.bildnummer = 0
        self.fxnummer = 0
        self.max_fxnummer = 0

        self.button = t.Button(frame, text="Quit",
                               fg="red", command=frame.quit)
        self.button.pack(side=t.LEFT)

        self.pfeilobjeklinks = PIL.Image.open("pfeil_links.png")
        self.pfeillinks = PIL.ImageTk.PhotoImage(self.pfeilobjeklinks)
        self.retour = t.Button(frame, image=self.pfeillinks, command=self.bild_retour)
        self.retour.pack(side=t.LEFT)
        
        self.pfeilobjektrechts = PIL.Image.open("pfeil_rechts.png")
        self.pfeilrechts = PIL.ImageTk.PhotoImage(self.pfeilobjektrechts)
        self.bildwechsel = t.Button(frame,  image=self.pfeilrechts, command=self.bild_weiter)
        self.bildwechsel.pack(side=t.LEFT)

        #self.hi_there=t.Button(frame, text="hello", command=self.say_hi)
        #self.hi_there.pack(side=t.LEFT)

        self.sprich=t.Button(frame, text="vorlesen", command=self.vorlesen)
        self.sprich.pack(side=t.LEFT)
        
        self.fx=t.Button(frame)
        self.fx.pack(side=t.LEFT)
        
        self.bildname=t.Label(frame)
        self.bildname.pack(side=t.LEFT)

        frame2 = t.Frame(master)
        frame2.pack(side=t.TOP)
        self.schriftplatz=t.Label(frame2)
        self.schriftplatz.pack(side=t.TOP)

        self.bildplatz=t.Label(frame2)
        self.bildplatz.pack(side=t.TOP)

        

        self.zeichne_Bild()

    #def say_hi(self):
    #    print "hallo zusammen"
        
    def vorlesen(self):
    	retcode = subprocess.call(["espeak",self.pictures[self.bildnummer][1]])
    	
    def play_fx(self):
    	retcode = subprocess.call(["play",self.pictures[self.bildnummer][self.fxnummer+1]])
    	if self.fxnummer == self.max_fxnummer:
    		self.fxnummer = 1
    	else:
    		self.fxnummer += 1
    	self.zeichne_Bild()
    	
    def get_fx(self):
    	self.fxnummer=0
    	self.max_fxnummer=0
        if len(self.pictures[self.bildnummer])> 2:
        	if len(self.pictures[self.bildnummer][2]) > 0:
        	    self.fxnummer = 1
        	    self.max_fxnummer=1
        	    for soundfile in self.pictures[self.bildnummer][3:]:
        	        if soundfile <> "":
        	        	self.max_fxnummer +=1
        
    def bild_weiter(self):
    	self.bildnummer += 1
    	if self.bildnummer > len(self.pictures)-1:
    		self.bildnummer = 0
    	self.get_fx()
    	self.zeichne_Bild()
    	
    def bild_retour(self):
    	self.bildnummer -= 1
    	if self.bildnummer < 0:
    		self.bildnummer = len(self.pictures)-1
    	self.get_fx()
    	self.zeichne_Bild()
    	
    def zeichne_Bild(self):
    	self.bildobjekt = PIL.Image.open(self.pictures[self.bildnummer][0])
    	self.photo = PIL.ImageTk.PhotoImage(self.bildobjekt)
    	self.bildname.config(text="Bild Nr %i  von %i : %s" % (self.bildnummer +1 , len(self.pictures), self.pictures[self.bildnummer][0]))
    	self.bildplatz.config(image=self.photo)
    	self.schriftplatz.config(text=self.pictures[self.bildnummer][1]) 
    	if self.fxnummer > 0:
    		self.fx.config(text="Soundeffekt %i von %i"%(self.fxnummer, self.max_fxnummer), command=self.play_fx)
    	else:
    		self.fx.config(text="kein Soundeffekt", command="")

root = t.Tk()
app = App(root)

root.mainloop()
root.destroy()



the csv-file: liste5.csv


"1.png","It was a tiny little town.",
"2.png","If out in the wild there is any monster,i will eat some rats.","lachen.wav"
"3.png","Suddenly a  big monster was on the top of a skyscraper.","panik.wav"

German version

more specific details for the German Version of the Comic-Betrachter can be found in the German Wiki page to Benni's Comicbetrachter-Video. The whole German Archiv for Benni's Video Tutorial can be downloaded from here.

Personal tools