怎么用C或C++实现以下python 语言描述
听海拉拉 2010-08-26 10:40:27 本人不懂python
需要用c++/c写一个客户端软件,像以下代码描述的一样。不知道怎么入手
#!/usr/bin/env python
import httplib #httplib modules for the HTTP interactions
from Tkinter import * #Tkinter modules for Windowing
from PIL import Image, ImageTk #Python Image Libraries, required for displaying jpegs
from time import sleep
import StringIO #For converting Stream from the server to IO for Image (PIL)
from StreamViewer import StreamViewer
'''Gets the file from the specified
host, port and location/query'''
def get(host,port,query):
h = httplib.HTTP(host, port)
h.putrequest('GET', query)
h.putheader('Host', host)
h.putheader('User-agent', 'python-httplib')
h.putheader('Content-type', 'image/jpeg')
h.endheaders()
(returncode, returnmsg, headers) = h.getreply()
print "return code:",returncode
print "return message:",returnmsg
print "headers:",headers
if returncode != 200:
print returncode, returnmsg
sys.exit()
f = h.getfile()
return f.read()
'''This is where we show the file on our StreamViewer'''
def streamfile(tbk, root):
f = get('127.0.0.1',80,'/?action=snapshot')
img=Image.open(StringIO.StringIO(f)) #convert to jpeg object from the stream
imagetk = ImageTk.PhotoImage(img) #Get a PhotoImage to pass to our Frame
tbk.addImage(imagetk) #Image added
root.update()
root = Tk()
tbk = StreamViewer(root)
#As much space as we need, no more, no less
#we change the root geometry to the size of the streaming jpg #As much space as we need, no more, no less
root.geometry("%dx%d+0+0" % (640, 480))
root.resizable(False,False)
'''It's our overrated slideshow viewer .. hehe'''
while(1):
streamfile(tbk,root)
from Tkinter import *
#########
class StreamViewer(Frame):
def __init__(self, root):
root.title("Test Application")
self.addFrame(root)
def addFrame(self,root):
frame = Frame(root, background="#FFFFFF")
self.addCanvas(frame)
frame.pack(fill=BOTH, expand=YES)
def addCanvas(self, frame):
self.canvas = Canvas(frame, background='#000000')
self.canvas.pack(fill=BOTH, expand=YES)
self.canvas.pack()
def addImage(self, photoimage):
self.canvas.create_image(640,480, image=photoimage,anchor=SE)