怎么用C或C++实现以下python 语言描述
本人不懂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)
需要用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)
...全文
相关推荐
Jinja2Cpp:Jinja2 C ++(和C ++)几乎完全符合的模板引擎实现
Jinja2Cpp:Jinja2 C ++(和C ++)几乎完全符合的模板引擎实现
Python库 | cs2cpp-0.0.9.tar.gz
python库。 资源全名:cs2cpp-0.0.9.tar.gz
libtest_python_cpp:测试如何使用python库中的cpp文件制作正确的pip安装命令
libtest_python_cpp
C_CPP_python.pdf.zip_C python_pdf_python C#_python pdf
详细讲述了使用c来扩充Python,pdf文档。
cpp-Pie为CPython的CAPI提供一个惯用的C接口
Pie 为CPython的C API提供一个惯用的C 接口


