Writing gvnccapture in python
- From: Chris Lalancette <clalance redhat com>
- To: gtk-vnc-list gnome org
- Subject: Writing gvnccapture in python
- Date: Fri, 25 Mar 2011 14:19:17 -0400
Hi there,
I've been attempting to write a program that does the rough equivalent
of what gvnccapture does, except in python (my ultimate goal is to integrate
this code into a larger python program). Based on some advice from
Dan Berrange, I've started to implement a test program using gobject
introspection. However, I've run into a couple of problems (I'll paste my
full example code below).
The first problem is that I cannot seem to pass the pixel array through to
BaseFramebuffer like the constructor expects. The line of code in question is:
fb = gvnc.BaseFramebuffer().new(pixbuf.get_pixels_array(),
pixbuf.get_width(),
pixbuf.get_height(),
pixbuf.get_rowstride(),
conn.get_pixel_format(),
localFormat)
If I run that as-is, I get:
TypeError: only length-1 arrays can be converted to Python scalars
I've also tried using pixbuf.get_pixels(), which gives me:
TypeError: argument 1: Item 0: Must be number, not str
Finally, I tried just using a simple array like [1, 1] there, and I was able
to get the call to succeed. In the end, I'm not sure what I'm supposed to pass
here; does anyone have ideas?
The second problem that I am having has to do with the set_encodings() method.
The gvnccapture.c program does something like:
gint32 encodings[] = { VNC_CONNECTION_ENCODING_DESKTOP_RESIZE,
VNC_CONNECTION_ENCODING_ZRLE,
VNC_CONNECTION_ENCODING_HEXTILE,
VNC_CONNECTION_ENCODING_RRE,
VNC_CONNECTION_ENCODING_COPY_RECT,
VNC_CONNECTION_ENCODING_RAW };
gint32 *encodingsp;
encodingsp = encodings;
n_encodings = G_N_ELEMENTS(encodings);
if (!vnc_connection_set_encodings(conn, n_encodings, encodingsp))
goto error;
However, in python, if I try to call conn.set_encodings(), it only seems to
take a single parameter in, and an int parameter (not an array or dictionary)
at that. Looking at the GVnc-1.0.gir file, it looks like the second paramter
(encoding) is marked as "out", which might explain this behavior. Again,
does anyone have any ideas what I'm doing wrong here?
As mentioned, my full program (as it is so far) is attached. Any advice
is greatly appreciated.
Thanks,
--
Chris Lalancette
from gi.repository import GVnc as gvnc
import glib
import gtk
# FIXME: can we get these somewhere out of glib? Doesn't look like it
# (at least in the python bindings), but I'm not sure
G_LITTLE_ENDIAN = 1234
G_BIG_ENDIAN = 4321
def initialize(*args):
print "init called"
print args
print conn.get_width()
print conn.get_height()
desktop_resize(conn.get_width(), conn.get_height())
conn.set_encodings(6)
def disconnect(*args):
print "disconnect"
conn.shutdown()
loop.quit()
def auth_choose_type(*args):
print "auth_choose_type"
# FIXME: VNC_CONNECTION_AUTH_NONE
conn.set_auth_type(1)
def auth_choose_subtype(*args):
print "auth_choose_subtype"
def auth_credential(*args):
print "auth_credential"
def desktop_resize(*args):
print "desktop_resize"
print args
width = args[0]
height = args[1]
pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, width, height)
pixbuf.fill(0)
localFormat = gvnc.PixelFormat()
localFormat.bits_per_pixel = 32
localFormat.depth = 32
localFormat.byte_order = G_LITTLE_ENDIAN
localFormat.true_color_flag = True
localFormat.red_max = 255
localFormat.green_max = 255
localFormat.blue_max = 255
localFormat.red_shift = 0
localFormat.green_shift = 8
localFormat.blue_shift = 16
# FIXME: the first argument here needs to be pixbuf.get_pixels() or
# pixbuf.get_pixels_array()
fb = gvnc.BaseFramebuffer().new(pixbuf.get_pixels(), pixbuf.get_width(),
pixbuf.get_height(), pixbuf.get_rowstride(),
conn.get_pixel_format(), localFormat)
print conn.get_pixel_format()
conn.set_framebuffer(fb)
def framebuffer_update(*args):
print "framebuffer_update"
conn = gvnc.Connection()
conn.connect("vnc-initialized", initialize)
conn.connect("vnc-disconnected", disconnect)
conn.connect("vnc-auth-choose-type", auth_choose_type)
conn.connect("vnc-auth-choose-subtype", auth_choose_subtype)
conn.connect("vnc-auth-credential", auth_credential)
conn.connect("vnc-desktop-resize", desktop_resize)
conn.connect("vnc-framebuffer-update", framebuffer_update)
conn.open_host("127.0.0.1", "5900")
loop = glib.MainLoop()
loop.run()
[Date Prev][Date Next] [Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]