pygobject

How can I create a GTK ComboBox with images in Python?

故事扮演 提交于 2019-12-06 03:38:05
How can I create a ComboBox that displays a list of entries, each containing some text and an icon? I'm using Python and GTK3 with GObject introspection. Flimm Here's an example of how to do that, inspired by this answer for C . from gi.repository import Gtk from gi.repository import GdkPixbuf store = Gtk.ListStore(str, GdkPixbuf.Pixbuf) pb = GdkPixbuf.Pixbuf.new_from_file_at_size("picture.png", 32, 32) store.append(["Test", pb]) combo = Gtk.ComboBox.new_with_model(store) renderer = Gtk.CellRendererText() combo.pack_start(renderer, True) combo.add_attribute(renderer, "text", 0) renderer = Gtk

Python GTK+ Canvas

霸气de小男生 提交于 2019-12-06 02:55:45
问题 I'm currently learning GTK+ via PyGobject and need something like a canvas. I already searched the docs and found two widgets that seem likely to do the job: GtkDrawingArea and GtkLayout. I need a few basic functions like fillrect or drawline ... In fact these functions are available from c but I couldn't find directions how to use them from python. Can you recommend a tutorial or manpage that deals with their python equivalents ? If you have a better idea how to get something similar to a

Create python object from memory address (using gi.repository)

一个人想着一个人 提交于 2019-12-06 02:10:35
问题 Sometimes I need to call a gtk/gobject function that only exists in C, but returns an object that has a python wrapper. Previously I used a solution based on ctypes that worked well: http://faq.pygtk.org/index.py?req=show&file=faq23.041.htp Now that I swiched from PyGtk ("import gtk") to GObject-introspection ("from gi.repository import Gtk"), what can I use instead? 回答1: The _PyGObject_API interface has changed at some point. I needed to drop the register_sinkfunc function. The following

unresponsive drag and drop in pygobject

只谈情不闲聊 提交于 2019-12-06 01:59:19
im trying to get drag and drop working well in pygobject, but it is slow and unresponsive, 90% of the time i have to wave the item i am dragging around before i can drop it successfully, can anyone see if i am doing it incorrectly or is this a bug with pygobject? here is my code from gi.repository import Gtk, GdkPixbuf, Gdk import os def got_data_cb(windowid, context, x, y, data, info, time): # Got data. tempArray = data.get_text().splitlines() for i in tempArray: i = i.replace('file://','') print i windowid.get_model().append([i]) context.finish(True, False, time) def drop_cb(windowid,

How to write custom Gtk.CellRenderer in python and GTK 3?

匆匆过客 提交于 2019-12-06 01:33:29
问题 i must write my own cell renderer with button, i came up with this: #!/usr/bin/env python3 from gi.repository import Gtk class CellRendererButton(Gtk.CellRenderer): def __init__(self): Gtk.CellRenderer.__init__(self) def get_size(self, widget, cell_area): buttonHeight = cell_area.height buttonWidth = buttonHeight return (0, 0, buttonWidth, buttonHeight) def render(self, window, widget, background_area, cell_area, expose_area, flags): style = widget.get_style() x, y, buttonWidth, buttonHeight

How do I raise a window that is minimized or covered with PyGObject?

我的未来我决定 提交于 2019-12-05 09:26:46
I'd been using the answer provided in the PyGTK FAQ , but that doesn't seem to work with PyGObject. For your convenience, here is a test case that works with PyGTK, and then a translated version that doesn't work with PyGObject. PyGTK Version: import gtk def raise_window(widget, w2): w2.window.show() w1 = gtk.Window() w1.set_title('Main window') w2 = gtk.Window() w2.set_title('Other window') b = gtk.Button('Move something on top of the other window.\nOr, minimize the' 'other window.\nThen, click this button to raise the other' 'window to the front') b.connect('clicked', raise_window, w2) w1

Webkit threads with PyGObject on Gtk3

北慕城南 提交于 2019-12-05 07:01:00
I am trying to load a webkit view on a different thread than main thread for gtk. I see the example PyGTK, Threads and WebKit I slightly modify for support PyGObject and GTK3: from gi.repository import Gtk from gi.repository import Gdk from gi.repository import GObject from gi.repository import GLib from gi.repository import WebKit import threading import time # Use threads Gdk.threads_init() class App(object): def __init__(self): window = Gtk.Window() webView = WebKit.WebView() window.add(webView) window.show_all() #webView.load_uri('http://www.google.com') # Here it works on main thread self

Python3 + PyGobject + GTK3 and cx_freeze missing DLLs

北城以北 提交于 2019-12-05 03:43:07
问题 When I make a exe from py python3 + pygobject + gtk3 application using the setup.py from pygobject site it misses some DLL files. what files are missing? 回答1: I have manualy tried what DLLs are required. So if this will help someone: the setup.py must be edited. the missing_dlls list must be: missing_dll = ['libgtk-3-0.dll', 'libgdk-3-0.dll', 'libatk-1.0-0.dll', 'libcairo-2.dll', 'libcairo-gobject-2.dll', 'libgdk_pixbuf-2.0-0.dll', 'libjpeg-8.dll', 'libpango-1.0-0.dll', 'libpangocairo-1.0-0

Package PyGObject Python 3 program with pynsist?

喜夏-厌秋 提交于 2019-12-05 02:28:02
问题 I would like to package a Python3-PyGObject program with pynsist. The repository has an example for PyGTK and it made me think that it shouldn't be too hard to change the example. The example can be found here: https://github.com/takluyver/pynsist/tree/master/examples/pygtk In this file (https://github.com/takluyver/pynsist/blob/master/examples/pygtk/grab_files.sh) I think one just has to grab the files targeting GTK 3 (http://www.gtk.org/download/win32.php): wget -O gtkbundle.zip http:/

How to connect to a GObject signal in python, without it keeping a reference to the connecter?

佐手、 提交于 2019-12-05 01:04:24
问题 The problem is basically this, in python's gobject and gtk bindings. Assume we have a class that binds to a signal when constructed: class ClipboardMonitor (object): def __init__(self): clip = gtk.clipboard_get(gtk.gdk.SELECTION_CLIPBOARD) clip.connect("owner-change", self._clipboard_changed) The problem is now that, no instance of ClipboardMonitor will ever die . The gtk clipboard is an application-wide object, and connecting to it keeps a reference to the object, since we use the callback