pygtk

PyGTK, Threads and WebKit

眉间皱痕 提交于 2019-12-06 09:15:21
问题 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

pygtk: Draw lines onto a gtk.gdk.Pixbuf

▼魔方 西西 提交于 2019-12-06 06:54:29
问题 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

Python: Fastest way to take and save screenshots

我们两清 提交于 2019-12-06 06:13:10
I've been struggling to come up with a script that allows me to take screenshots of my desktop more than once per every second. I'm using Win10. PIL: from PIL import ImageGrab import time while True: im = ImageGrab.grab() fname = "dropfolder/%s.png" %int(time.time()) im.save(fname,'PNG') Results 1.01 seconds per image. PyScreeze ( https://github.com/asweigart/pyscreeze ): import pyscreeze import time while True: fname = "dropfolder/%s.png" %int(time.time()) x = pyscreeze.screenshot(fname) Results 1.00 seconds per image. Win32: import win32gui import win32ui import win32con import time w=1920

GtkWindow can only contain one widget at a time

▼魔方 西西 提交于 2019-12-06 06:00:06
I am using this code to retrieve and display an image from the web: class Display(object): def __init__(self): self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.connect('destroy', self.destroy) self.window.set_border_width(10) self.image = gtk.Image() response = urllib2.urlopen('http://image.url/image.jpg').read() pbuf = gtk.gdk.PixbufLoader() pbuf.write(response) pbuf.close() self.image.set_from_pixbuf(pbuf.get_pixbuf()) self.window.add(self.image) self.image.show() self.window.show() def main(self): gtk.main() def destroy(self, widget, data=None): gtk.main_quit() It works, however I

gtk: set active window

馋奶兔 提交于 2019-12-06 05:22:50
I have a gtk.Window . How do I set it to be the active window? I can call is_active() to see whether it already is, but I don't see where to make it active. Bonus points: given a gtk.Widget , how do I make the window it is a part of the active window? Ah thanks to this thread , the answer is to call gtk.Window.present() . if W is a gtk.Window : import wnck wnck.window_get(W.window.xid).activate() Here's what worked for me (thanks Dan D for pointing out wnck) def activate(window): screen = wnck.screen_get_default() screen.force_update() wnckwin = [win for win in screen.get_windows() if win.get

drawing a pixbuf onto a drawing area using pygtk and glade

偶尔善良 提交于 2019-12-06 04:54:02
i'm trying to make a GTK application in python where I can just draw a loaded image onto the screen where I click on it. The way I am trying to do this is by loading the image into a pixbuf file, and then drawing that pixbuf onto a drawing area. the main line of code is here: def drawing_refresh(self, widget, event): #clear the screen widget.window.draw_rectangle(widget.get_style().white_gc, True, 0, 0, 400, 400) for n in self.nodes: widget.window.draw_pixbuf(widget.get_style().fg_gc[gtk.STATE_NORMAL], self.node_image, 0, 0, 0, 0) This should just draw the pixbuf onto the image in the top left

How to install PyGI (Python Gobject Introspection) on Windows?

帅比萌擦擦* 提交于 2019-12-06 04:23:03
问题 Installing the python interpreter: http://python.org/ftp/python/2.7.2/python-2.7.2.msi and: http://ftp.gnome.org/pub/GNOME/binaries/win32/pygtk/2.24/pygtk-all-in-one-2.24.0.win32-py2.7.msi run: python import gtk ...works Is there a PyGI all in one installer? run: python import gi Error: Unable to import module gi ...how to make it work on Windows? On Ubuntu 11.04 runs without installing anything. 回答1: I think you run into two problems here. First of all, I'm not sure that the PyGObject

PyGTK+3 (PyGObject) to create screenshot?

本小妞迷上赌 提交于 2019-12-06 03:40:29
I've spend past 3 days searching in google, how can I create a screenshot with PyGTK+3 ? There are gallizion tutorials about pyqt,pygtk+2,wx and PIL. By the way, I don't need external programs like scrot, imlib2, imagemagick and so on. Since nobody else posted the translation to GTK3, here you go: from gi.repository import Gdk win = Gdk.get_default_root_window() h = win.get_height() w = win.get_width() print ("The size of the window is %d x %d" % (w, h)) pb = Gdk.pixbuf_get_from_window(win, 0, 0, w, h) if (pb != None): pb.savev("screenshot.png","png", (), ()) print("Screenshot saved to

Cairo context and persistence?

拥有回忆 提交于 2019-12-06 02:22:15
I am just getting started using pycairo, and I ran into the following interesting error. The program I write creates a simple gtk window, draws a rectangle on it, and then has a callback to draw a random line on any kind of keyboard input. However, it seems that with each keyboard input, I have to create a new context, or I get an error at the moment the program receives first keyboard input (specifically, on the .stroke() line). Error is as follows, if it matters. 'BadDrawable (invalid Pixmap or Window parameter)'. (Details: serial 230 error_code 9 request_code 53 minor_code 0) #! /usr/bin

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