pygtk

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

higher level Python GUI toolkit, e.g. pass dict for TreeView/Grid

孤人 提交于 2019-12-05 00:11:54
问题 Started my first Python pet project using PyGTK. Though it is a really powerful GUI toolkit and looks excellent, I have some pet peeves. So I thought about transitioning to something else, as it's not yet too extensive. Had a look around on SO and python documentation, but didn't get a good overview. What's nice about PyGTK: Glade files self.signal_autoconnect({...}) self.get_widget() as __getattr__ This is bugging me however: manual gobject.idle_add(lambda: ... and False) no standard

How does one add an item to GTK's “recently used” file list from Python?

别等时光非礼了梦想. 提交于 2019-12-04 22:48:23
I'm trying to add to the "recently used" files list from Python 3 on Ubuntu. I am able to successfully read the recently used file list like this: from gi.repository import Gtk recent_mgr = Gtk.RecentManager.get_default() for item in recent_mgr.get_items(): print(item.get_uri()) This prints out the same list of files I see when I look at "Recent" in Nautilus, or look at the "Recently Used" place in the file dialog of apps like GIMP. However, when I tried adding an item like this (where /home/laurence/foo/bar.txt is an existing text file)... recent_mgr.add_item('file:///home/laurence/foo/bar

PyGtk3 how to change application theme?

流过昼夜 提交于 2019-12-04 21:38:39
i tried rc_parse method using Gtk.rc_parse("path/to/Hooli/gtk-3/gtk.css") code but it is not working. this question is simlpy but solution of question not easy. how can i change the my gtk apllication theme ? or how can i use custom theme on my gtk application ? Thanks. import gi gi.require_version("Gtk", "3.0") from gi.repository import Gtk as gtk settings = gtk.Settings.get_default() settings.set_property("gtk-theme-name", "Numix") settings.set_property("gtk-application-prefer-dark-theme", False) # if you want use dark theme, set second arg to True # getting all existing properties # for i

PyGTK, Threads and WebKit

大城市里の小女人 提交于 2019-12-04 17:06:26
In my PyGTK app, on button click I need to: Fetch some html (can take some time) Show it in new window While fetching html, I want to keep GUI responsive, so I decided to do it in separate thread. I use WebKit to render html. The problem is I get empty page in WebView when it is in separated thread. This works: import gtk import webkit webView = webkit.WebView() webView.load_html_string('<h1>Hello Mars</h1>', 'file:///') window = gtk.Window() window.add(webView) window.show_all() gtk.mainloop() This does not work, produces empty window: import gtk import webkit import threading def show_html()

How to save webkit page image resources from memory?

别来无恙 提交于 2019-12-04 16:51:43
I open page with python, gtk, and webkit. Now - how to save image from that page without downloading it again from the internet? Here is a python program that will save a rendered web page to an image: http://pastie.org/4572412 This should be the section of primary interest to you: size = self.browser.mainFrame().contentsSize() if width > 0: size.setWidth(width) self.browser.setViewportSize(size) # Render the virtual browsers viewport to an image. image = QImage(self.browser.viewportSize(), QImage.Format_ARGB32) paint = QPainter(image) #Have the painters target be our image object self.browser

Is there a way to change the current PyGTK theme on Windows?

柔情痞子 提交于 2019-12-04 15:52:09
I've written a Python app that uses PyGTK. It runs fine on Linux and looks great. It also runs fine on Windows, but it looks absolutely awful. The default GTK theme looks absolutely nothing like the native Windows GUI elements. Is there anything I can do to make my Python app look a little better? Perhaps some function I can call to change to theme to something a little nicer? Edit: using the rc_parse() function suggested in the answer below, I now have: import pygtk,gtk gtk.rc_parse("C:\\Program Files\\Common Files\\GTK\\2.0\\share\\themes\\Bluecurve\\gtk-2.0\\gtkrc") window = gtk.Window(gtk

Editing GtkWidget attributes/properties

左心房为你撑大大i 提交于 2019-12-04 14:01:18
In most pygtk widget pages, they contain sections called 'Attributes', 'Properties', and 'Style Properties'. How can I change these properties and attributes? There are three ways to change properties: As in zheoffec's answer, use the set_property() function (or set_style_property() for style properties.) This function is actually not necessary in Python, but it is there for completeness because it is part of the C API. Use the props attribute. Any property that you find in the documentation can be accessed through this attribute. For example, btn1.props.label = 'StackOverflow' and btn1.props

pygtk: Draw lines onto a gtk.gdk.Pixbuf

不羁的心 提交于 2019-12-04 12:58:40
I'm using pygtk with PIL. I've already figured out a way to convert PIL Image s to gtk.gdk.Pixbuf s. What I do to display the pixbuf is I create a gtk.gdk.Image , and then use img.set_from_pixbuf . I now want to draw a few lines onto this image. Apparently I need a Drawable to do that. I've started looking through the docs but already I have 8-10 windows open and it is not being straightforward at all. So - what magic do I need to type to get a Drawable representing my picture, draw some things on to it, and then turn it into a gdk.Image so I can display it on my app? I was doing something

How do I create a new signal in pygtk

时光毁灭记忆、已成空白 提交于 2019-12-04 11:28:17
问题 I've created a python object, but I want to send signals on it. I made it inherit from gobject.GObject, but there doesn't seem to be any way to create a new signal on my object. 回答1: You can also define signals inside the class definition: class MyGObjectClass(gobject.GObject): __gsignals__ = { "some-signal": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (object, )), } The contents of the tuple are the the same as the three last arguments to gobject.signal_new . 回答2: Here is how: import