开发者

Python Clutter: Set display?

开发者 https://www.devze.com 2023-02-03 01:29 出处:网络
How does one set the X11 display in Pyt开发者_如何学编程hon-Clutter? I am trying to set it to XSCREENSAVER_WINDOW. I have tried importing clutter.x11 and using set_display(), but this doesn\'t seem to

How does one set the X11 display in Pyt开发者_如何学编程hon-Clutter? I am trying to set it to XSCREENSAVER_WINDOW. I have tried importing clutter.x11 and using set_display(), but this doesn't seem to be the correct command. Does anyone know the right way of doing this?


While searching around I found this thread, and by looking at the avatar picture, I assume it's your thread ;) I'll re post the code given by LemursDontExist so you have it all in one.


Short explanation: to make a program a screensaver in X Windows, the program checks if it is running as a screensaver, that means if it was invoked by the windowing system as such. This is done by checking if the environment variable DISPLAY is set to XSCREENSAVER_WINDOW.

In that case, the program needs to go full screen and react to certain events. This is exactly what the code below does. Setting this variable is done through the xscreensaver application, you don't do it yourself.

The bit you're missing is the clutter-gtk python binding. In current Ubuntu, the package name is gir1.2-clutter-gtk-0.10. With that, you can use the custom window class together with the clutter API.


class GsThemeWindow(gtk.Window):
    __gtype_name__ = 'GsThemeWindow'

def __init__(self):
    super(GsThemeWindow, self).__init__()
    self.connect("destroy", gtk.main_quit)

def do_realize(self):
    ident = os.environ.get('XSCREENSAVER_WINDOW')
    if not ident is None:
        self.window = gtk.gdk.window_foreign_new(int(ident, 16))
        self.window.set_events(gtk.gdk.EXPOSURE_MASK |
                               gtk.gdk.STRUCTURE_MASK)
        x, y, w, h, depth = self.window.get_geometry()
        self.size_allocate(gtk.gdk.Rectangle(x, y, w, h))
        self.set_default_size(w, h)
        self.set_decorated(False)
    else:
        self.window = gtk.gdk.Window(
            self.get_parent_window(),
            width=self.allocation.width,
            height=self.allocation.height,
            window_type=gtk.gdk.WINDOW_TOPLEVEL,
            wclass=gtk.gdk.INPUT_OUTPUT,
            event_mask=self.get_events() | gtk.gdk.EXPOSURE_MASK)
    self.window.set_user_data(self)
    self.style.attach(self.window)
    self.set_flags(self.flags() | gtk.REALIZED)

For a short overview on how to use clutter with python (it has changed a lot), see this example

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号