用于clutter-gtk和clutter-gsk的Python绑定

时间:2011-11-07 08:13:27

标签: python gtk clutter

我正在使用python并希望在杂乱阶段嵌入gtk3小部件。但是,似乎pyclutter-gtkpyclutter-gsk已停止了一段时间。我们可以在python中使用任何替代绑定吗? 我试过谷歌但没有运气。只有一个项目(http://code.google.com/p/pyclutter-widgets/)看起来很有趣,但它已停用了一年......

2 个答案:

答案 0 :(得分:2)

gtk3和clutter的所有python绑定都已移至基于内省的 pygobject ;你应该能够通过简单的方式使用pygobject> = 2.30中的Clutter-Gtk和Clutter-Gst:

from gi.repository import GtkClutter

您可以按照Gnome wiki entry for IntrospectionPorting上的说明进行操作。

答案 1 :(得分:0)

以下是使用Clutter-gtk 1.2.x和python-3.x

将GtkClutter阶段和scrollActor添加到Gtk.HBox的方法
from gi.repository import Gtk, Gdk, GtkClutter, Clutter   

class EmbeddedGtkClutterStageWithScrollActor(Gtk.Window): 

    def __init__(self):
        super(EmbeddedGtkClutterStage, self).__init__()

        # Initialise GtkClutter
        GtkClutter.init(sys.argv)


        self.connect('destroy', lambda w: Gtk.main_quit())

        self.set_default_size(1024, 768)
        self.override_background_color(Gtk.StateFlags.NORMAL, Gdk.RGBA(0, 0, 0, 1))

        display = Gdk.Display.get_default()
        screen = display.get_default_screen()
        css_provider = Gtk.CssProvider()

        css_provider.load_from_path('style.css')
        context = Gtk.StyleContext()
        context.add_provider_for_screen(screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) 


        hbox = Gtk.HBox(False, 2)
        vbox.add(hbox)

        # Create Clutter Stage 
        embed = GtkClutter.Embed()    

        hbox.add(embed)
        embed.set_size_request(900, 500)

        stage = embed.get_stage()
        # set stage color to black
        stage.set_color(Clutter.Color.new(0, 0, 0, 255))

        # Create a Scrollable Actor and add to the Stage
        scrollActor = Clutter.ScrollActor()

        scrollActor.set_scroll_mode(Clutter.ScrollMode.HORIZONTALLY)
        stage.add_actor(scrollActor)

        # scroll the scrollActor to x/y coords 
        point = Clutter.Point()
        point.x = 50
        point.y = 100
        scrollActor.scroll_to_point(point) 

        hbox.show_all()


EmbeddedGtkClutterStageWithScrollActor()
Gtk.main()