Re: [pygtk] Restoring Window Positions
Hi, Am Do, den 29.07.2004 um 12:22 Uhr -0700 schrieb Paul Dickson: I have a PyGYK program I'm writing, and I'd like to restore the window positions that the user had the last time the program ran. I've only found the .set_uposition(x,y) but I'm getting DeprecationWarning warnings. Is there a replacement for .set_uposition() that isn't deprecated? Or failing that, another way to restore the window's position? I think gtk.Window.move(x, y) is excactly what you want. Martin ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Is a bug in gtk.Menu - Motion/Enter/Leave_Notify Event ???
Am Do, den 04.03.2004 schrieb [EMAIL PROTECTED] um 15:20: I want to make a menubar.deselect() when the mouse leave the application (i want avoid, that the popupmenu will still on top, if the user change into a other application). Problem: When the menu is popup i get only events from this menu. I can move the mousepointer around the toplevel window but i get the motion event from the menu. When i leave the toplevel window, i get a leave event from the menu. Menu windows grab the mouse pointer globally. Therefore other windows cannot receive events. I think its wrong (bug), because leave the toplevelwindow i shout get the event from the window, not from the menu. The grabbing is not a bug but intentional. That way you can safely click anywhere on the screen to close the menu without action. If it is correct - Why (and how can i solve my problem) ? If you really need to work around this, then consider implementing your own menu widget instead of using the one of GTK. Or you could run a timer that regularly checks if the mouse pointer is still within the application window (gtk.Window.get_position(), gtk.Window.get_size()) and close the menu if not. Martin Grimme ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Font manipulations
Thanks. It complained that the pango object has no SCALE attribute, but plugging in 1024 instead made it work. pango in PyGTK 2.0.0 does have the attribute. I have tested the code before I pasted it here. Maybe it's time to upgrade your PyGTK. :) Martin ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Font manipulations
Am Mo, den 09.02.2004 schrieb David G. Mackay um 00:15: Is there a set of code snippets showing how to set font characteristics (size, slant, weight, etc.) under pango? I found the section in the FAQ describing the markup capabilities, but that doesn't seem like it would apply to gtk.Entry widgets. I couldn't find anything in the examples directory that seemed generally applicable to all widgets that utilize text, either. pango.FontDescription is what you want: import gtk import pango ... fd = pango.FontDescription() fd.set_family(Serif) fd.set_style(pango.STYLE_ITALIC) fd.set_weight(pango.WEIGHT_BOLD) fd.set_size(12 * pango.SCALE) entry = gtk.Entry() entry.modify_font(fd) ... See http://www.moeraki.com/pygtkreference/pygtk2reference/class-pangofontdescription.html for more details. Martin Grimme ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Gnome Panel Applets
I would like to make a gnome panel applet. I discovered a tutorial, but it's a bit outdated: http://www.onlamp.com/pub/a/python/2000/07/25/gnome_applet.html I created the applet and fixed it so it would compile: That's totally outdated. Panel applets use bonobo in GNOME 2.x. This may help you to get started: http://www.daa.com.au/pipermail/pygtk/2002-September/003393.html Martin Grimme ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] gnome-python and gnome-session
Hi, gnome-python does not fully support session management, e.g. methods like gnome_client_set_restart_command() are missing. There has been a patch for the missing functions around since the days of 1.99.11 and Redhat and (now also) Debian patch their gnome-python with http://www.lunar-linux.com/lunar/patches/gnome-python-client-command.patch I just wonder why this patch has never been integrated into gnome-python CVS up to now; it looks very clean and since it only adds lines, doesn't break anything. Bye, Martin Grimme ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Making my own widget in Pygthon - Some more info
Hi, You have to derive your widget class from a GTK widget. That way, your widget inherits all necessary methods. If you want to look at some code to see how this is done, you could look at the projects gDeskCal and gDesklets, both on www.pycage.de. :) Basically, it works like this: class MyWidget(gtk.Foo): def __init__(self): # invoke the super constructor gtk.Foo.__init__(self) ... Bye, Martin Grimme My detailed problem: I want to write an application that uses many complex dialogs. These dialogs are recursively built up (in an XMLized way) of many smaller (but still complex) widgets. I want to build my own widgets, so I could create a nice tree of my high level widgets. I'd prefer adding my widgets in the usual PyGTK sytle: sub_widget.add(sub_sub_widget) top_widget.add(sub_widget) Instead of this plain and ugly hack (where the 'widget' member of my classes is the created PyGTK widget): sub_widget.add(sub_sub_widget.widget) top_widget.add(sub_widget.widget) I don't know whether it is possible or not. So please anyone drop me a line. Is it posibble at all from Python? ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] Question about Bonobo
Hi, I want to access the wombat of Evolution in a Python program. As I can see in the source code of Evolution, you do this by using the wombat: moniker. When I try to do this in Python, however, I only get a Bonobo.UnknownPrefix error: obj = bonobo.get_object(wombat:, Bonobo/ConfigDatabase) Traceback (most recent call last): File stdin, line 1, in ? Bonobo.UnknownPrefix Does anybody know what's going wrong here? Martin Grimme ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] problem with rh9
Hi, window = gtk.Window(gtk.WINDOW_TOPLEVEL) # create a top level window # never gets past here. Produces this message: window = gtk.Window(gtk.WINDOW_TOPLEVEL) # create a top level window AttributeError: 'module' object has no attribute 'Window' Recent version of pygtk require you to select the version of pygtk you want to use. Make this line the first program line of your program and it should work: import pygtk; pygtk.require(2.0) After this you can import gtk. Bye, Martin Grimme -- http://www.pycage.de ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] [pygnome] gnome2 applets
Hi all, I try to do a panel applet for gnome2 in python with pygnome2, but i don't find any help or tutorial on the web, have ou got any goods url ? Else i don't know how put for example a label and a button in one applet, it doesn't work, i have just the label who is displayed Take a look into the archive of this mailing list. On 9. Sep. 2002 you can find 'Re: [pygtk] PyGNOME 2 - Panel Applets' which gives a good example for a panel applet. About the button and label: are you using a container widget that can hold more than one widget? You put e.g. a HBox into the applet and put the button and label into the HBox. Bye, Martin Grimme -- http://www.pycage.de ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Draw rectangle with GDK
I would like know, if is it possble to use GDK with pygtk ? If yes, then what is the syntax to use it ? example : how to draw rectangle in window ? Maybe this example will help you: import pygtk pygtk.require(2.0) import gtk def on_expose(da, event, *args): gdkwin = da.window gc = gdkwin.new_gc() gc.foreground = gdkwin.get_colormap().alloc_color(blue) gdkwin.draw_rectangle(gc, gtk.TRUE, 10, 10, 100, 100) win = gtk.Window() win.show() win.connect(delete-event, gtk.mainquit) da = gtk.DrawingArea() da.show() win.add(da) da.connect(expose-event, on_expose) gtk.mainloop() When a window has to redraw itself, it emits the expose-event. You use the event handler to do draw into the window. You could also use an offscreen drawable and copy the pixmap into the window when necessary. You can force a window to redraw itself (emit the expose-event) by calling the window method queue_redraw(). Don't put complex drawing operations into the event handler because they will be performed each time the window has to redraw parts. Bye, Martin Grimme -- http://www.pycage.de ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] Setting Window Properties
Hello, I have a question about setting the properties of a GdkWindow with PyGTK 1.9.x. Since PyGTK does not yet support 'skip_taskbar', I want to set the property manually. How can I set this property? window.property_change(_NET_WM_STATE, ATOM, 32, gtk.gdk.PROP_MODE_APPEND, _NET_WM_STATE_SKIP_TASKBAR) does not work because PyGTK complains about the data not being a sequence of integers... How do I get the required integers from the string? Bye, Martin Grimme -- http://www.pycage.de ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] ANNOUNCE: Bonobo-Tutorial
Hi, I have written a little tutorial about using Bonobo with gnome-python for GNOME 2. Maybe this can help some people to get started with Bonobo. It is available at: http://www.pycage.de/howto_bonobo.html Have fun! Martin Grimme - http://www.pycage.de ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] PyGNOME2 panel applets
The topic of panel applets in pygnome2 has been raised before, and seemingly, answered succinctly: http://www.daa.com.au/pipermail/pygtk/2002-September/003393.html However, I'm still confused. Using the files attached to the above post, I put GNOME_HelloApplet.server in /home/btonkes/lib/oaf which is in the oaf path: $ oaf-sysconf --display-directories OAF configuration file contains: /home/btonkes/lib/oaf and python-applet in /home/btonkes/src/pyapplet, changing the PATH TO PYTHON APPLET string in GNOME_HelloApplet.server to /home/btonkes/src/pyapplet/python-applet. My question: what next? Running python-applet seems to do nothing. Am I doing something fundamentally wrong? You have to start the applet by adding it to the panel like any other applet. It should appear in the panel menu for adding applets. Btw, panel applets are Bonobo Controls now. So they are a little bit different from the applets in GNOME 1.x. Bye, Martin Grimme - http://www.pycage.de ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] Question about Bonobo
Hello, the bonobo bindings of gnome-python2 work well, so I tried to write a simple component which implements its own interface (similar to the Bonobo/Sample/Echo). As far as I have figured out of C examples, I would have to create a BonoboObject in the factory function called by GenericFactory and return it. My problem is: bonobo.Object claims to be an abstract class so I cannot instantiate it... Is it a bug in the bonobo bindings or is instantiating bonobo.Object just the wrong way for creating a simple BonoboObject (I don't want to create a Control, or similar, just a plain BonoboObject, like in the echo example of libbonobo) ? Can anyone help, please? Bye, Martin Grimme -- http://www.pycage.de ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] PyGNOME 2 - Panel Applets
Michele Campeotto wrote: Martin Grimme wrote: I would be very happy if anyone could post a short example of how to do panel applets with PyGNOME 1.9.x. Here you can find a simple example, this code is not mine, I got it from RM [EMAIL PROTECTED], I'm giving it away with his permission, and I haven't yet looked at it, so don't blame me if it doesn't work :) Thank you very much. It works well and it was exactly what I was looking for. :) Bye, Martin Grimme -- http://www.pycage.de ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] How to get the X window ID?
Hello, Is there an easy way to get the X window ID from an pygtk window? If you are working with the stable version of PyGTK, there is an easy way: 1. Your window must be realized. You can realize it by calling 'realize()' on it. If your window is already visible, you don't have to realize it. 2. Get the GdkWindow of your GtkWindow. 3. The GdkWindow has the attribute 'xid' which is what you want. Example: from gtk import * win = GtkWindow() win.show() gdkwin = win.get_window() xid = gdkwin.xid print xid Bye, Martin Grimme -- http://www.pycage.de ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
Re: [pygtk] pygtk - gtk Drawing Area - need help!
I need help on how to use a drawingarea - how to draw colored lines/circles, how to clear the area, and so on. Is there sample code somewhere, or a geek who knows all this? :-) Maybe here's a geek who knows these things... :) OK, after you created a GtkDrawingArea, you should connect the expose-event to it. This event occurs every time parts of the drawing area have to be repainted. The callback function for the event gets 2 parameters: 1. the GtkDrawingArea object 2. an event structure (which tells you useful things about the event) To actually draw on the drawing area, you need a GdkGC object. A GC is a graphics context and encapsulates settings for drawing. You would, for example, change the drawing color in the GC. You should also know that each window has its own GC (so if you have 2 drawing areas, you would usually need 2 GCs). There is a difference between GtkWindows and GdkWindows. While the GtkWindow is a GtkWidget, many widgets do have their own GdkWindows. To get the GC of the drawing area, you call the new_gc() method of its GdkWindow. Luckily, the event structure provides you with this GdkWindow (it is also possible to get the GdkWindow of a _realized_ widget by calling get_window() on that widget). OK, now that you have the GC, you want to set a drawing color. Using the colormap of the GdkDrawingArea, creating a GdkColor is as simple as this: new_color = drawingarea.get_colormap().alloc(r, g, b) where r, g, b are the RGB values of the color (ranging from 0 to 65535). You could also use X-color-names: new_color = drawingarea.get_colormap().alloc(green) Finally, we can draw on the drawing area: drawingarea.draw_line(gc, x1, y1, x2, y2) Here's tiny working example of all this stuff: -- from gtk import * def _on_expose(drawingarea, event): # get the GdkWindow window = event.window # get the GC gc = window.new_gc() # create a green color color = drawingarea.get_colormap().alloc(0x, 0x, 0x) # use this color for drawing gc.foreground = color # draw a line drawingarea.draw_line(gc, 0, 0, 200, 200) # the usual stuff win = GtkWindow() win.connect(destroy, mainquit) win.show() # create the drawing area drawingarea = GtkDrawingArea() drawingarea.connect(expose-event, _on_expose) drawingarea.show() win.add(drawingarea) # enter the mainloop mainloop() --- This example always draws the complete line whenever a part has to be redrawn. You could only redraw the parts which need to be redrawn by looking at the area variable (a rectangle) of the event structure. To clear the area, you draw a filled rectangle over it: drawingarea.draw_rectangle(gc, TRUE, 0, 0, window.width, window.height) However, if you seriously want to make use of the drawing area, then you should create an off-screen pixmap where to draw on. And the expose handler just copies this pixmap into the drawing area. If you need more description and examples, you may contact me. The Gdk-API Reference is also useful for exploring the GC and drawing primitives. Not everything is implemented in PyGTK, though :( Bye, Martin Grimme --- http://www.pycage.de ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
[pygtk] Re: [pygtk] queue draw area?
In other words, if I only update a small piece of the pixmap, is there any way to synthesize the expose event to tell it to only update the drawingarea from that small piece? Look at at the 'event' structure of the expose event. It contains the attribute 'area', which is a 4-tuple describing the rectangular area that has changed. An example (this code is not complete but only shows how to do it): def on_expose(widget, event, *args): # get the area area = event.area # redraw the area widget.draw_pixmap(gc, destination, area[1], area[2], area[0], area[1], area[2], area[3]) This is the way I handle this problem. Bye, Martin Grimme - http://www.pycage.de ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
Re: [pygtk] How to get screen width and height
I'm using : window = GtkWindow(WINDOW_TOPLEVEL) window.set_usize(800, 600) But, it would be better if I could use : window = GtkWindow(WINDOW_TOPLEVEL) window.set_usize(screen_widht, screen_height) Change this to: window = GtkWindow(WINDOW_TOPLEVEL) window.set_usize(screen_widht(), screen_height()) Bye, Martin Grimme - http://www.pycage.de ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
Re: [pygtk] Window without decors?
On 2001.03.09 02:03:24 +0100 Galen Brooks wrote: I had the same problem a few years back, and I solved it by switching window managers to FVWM2, and using the neat little Python plug-in for controlling all aspects of the windows. You can trigger certain behaviour based on the title of a window or on almost anything else. I don't know if modern window managers give you such fine control, but I wouldn't be surprised. This is not quite what I want. I want to have a fullscreen mode which works independently of the used window manager, i.e. a decorless window which uses the full screen. I somehow managed to get the size of the decor and position the window so that the decor is off-screen. However, I doubt that this works with all window managers... Bye, Martin Grimme - http://www.pycage.de ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
[pygtk] Window without decors?
Hello, can really nobody help? My questions again: I want to make a window full-screen and therefore need a way to remove the window manager decor from a window. Is there any way to achieve this in PyGTK without using 'GtkWindow(WINDOW_POPUP)' (which does not result in decorless windows on some configurations)? Maybe this is related to my question: When I get the GdkWindow of a GtkWindow widget via 'win.get_window()', it provides the methods 'property_change()', 'property_delete()' and 'property_get()'. What arguments do these methods take and how do I use them? Another question: It is possible to get the size of the WM decor the following way: gdkwin = win.get_window() winx = gdkwin.x winy = gdkwin.y x, y, nil, nil = win.get_allocation() print winx - x, winy -y However 'get_allocation()' does not return the correct position after moving the window. Is there a way to ensure that 'get_allocation()' returns the correct window position? Or is there a similar way to get the window's position (including the decor)? Please help. Martin Grimme - http://www.pycage.de ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
Re: [pygtk] Setting clip rectangles?
How do I set clip rectangles in pygtk? Am I missing something obvious? The only method I can think of is allocating a pixmap of the equivalent size and using it as the mask. Given that I'm masking an area on the order of the size of the screen, that just isn't acceptable. Can I get some help on this? This is easy, once you know it. # you have a pixmap (pix) and a clipping mask (mask) # 1. get the GC of pix gc = pix.new_gc() # 2. set the clip mask gc.clip_mask = mask # 3. if you don't want to apply the mask at (0, 0), change it gc.clip_x_origin = 100 gc.clip_y_origin = 200 # That's all to it. Bye, Martin Grimme - http://www.pycage.de ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
Re: [pygtk] Alpha channels in GtkPixmap
I'm having problems using a GtkPixmap to display the icon for an image in the Gnome panel. I have created a pixmap using Gimp which is transparent and wish to display this as the icon. The problem is that the icon never gets displayed with the proper transparency information (alpha channel). Hello, I once discovered a similar problem with GdkImlib. It simply did not want to load the alpha channel. The problem is somehow depending on the currently installed GTK-theme (weird, I know), where a certain type of entry has to be. My simple workaround is this at the beginning of the program: rcstring = """ style "trans" { engine "pixmap" {} } class "GtkWindow" style "trans" """ rc_parse_string(rcstring) It works well for me. I hope it works for you, too. Bye, Martin Grimme - http://www.pycage.de ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
Re: [pygtk] Window decorations
Is there any way using pytk to request a window manager not dress a window with decorations (like title bar, close widgets, etc). You can do this under regular x programming with playing with override_redirect or with Xt apps by specifying a -Xrm command line (or modding the x resources another way). Hello, window = GtkWindow(WINDOW_POPUP) should help (with most window managers). Bye, Martin Grimme - http://www.pycage.de ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
[pygtk] Focus of self-defined widgets
Hello, I built a widget containing a GtkLayout with a GtkDrawingArea in it. The widget class is derived from GTKLayout. Now my problem is that I need to connect "key_press_events" to this widget which doesn't seem to work as the widget cannot receive focus. Is there any way to implement this functionality by only using Python/PyGTK? The next problem is the other way round... Can I tell widgets which receive focus and thus catch key presses not to accept focus? GtkScale is the focus-taking widget of which I want that it ignores key presses (but acts on mouse clicks). Please help. Bye, Martin Grimme - http://www.pycage.de ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
Re: [pygtk] Widget/Window position and geometry like GtkWidgeyAuxInfo
Hello, if you really need to know the absolute coordinates of widget, read the properties from the widget's GdkWindow.. First you need to get the absolute position of the main window ('win' is a GtkWindow here): x, y = (win.get_window().x, win.get_window().y) You can get the positions of other widgets the same way. But you still need to add the parent window's absolute position to it. The method 'set_uposition(x, y)' sets the absolute position of a window and a GtkFixed widget can be used to place widgets at absolute positions. GtkAlignment widgets may also help. I hope, I could help. Martin Grimme - http://www.pycage.de ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
Re: [pygtk] Switching pixmaps using GtkPixmap.set()
Tessa Lau wrote: There seems to be another problem. When I do the following, I get unexpected output: img = GdkImlib.Image(filename) img.render() 1 pix = img.make_pixmap() print pix gtk.GtkPixmap instance at 80f28b8 pmap, mask = img.get_pixmap() Gdk-CRITICAL **: file gdkwindow.c: line 716 (gdk_window_ref): assertion `window != NULL' failed. Do I have to do something to the image before getting its pixmap? This apparently is a bug in PyGTK's GdkImlib module (or in Imlib itself). It should work fine if you add a "img.render()" just before the "get_pixmap"- line. Maybe "make_pixmap" does some changes to the image which shouldn't be... Also, I looked at two Imlib-based image viewers written in C, and they both set the backing pixmap using gdk_window_set_back_pixmap and gdk_window_clear. Why aren't these functions available in the Python wrapper? Yes, why? I am missing them, too! I'm trying to make a slideshow app, and using the gtk_pixmap_set method to switch images results in flickering in the display, whereas the C image viewers (electric eyes and gqview) don't have any flickering when they change images. You could use GdkPixmaps and double buffering to avoid flickering. Martin Grimme - http://www.pycage.de ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
Re: [pygtk] Switching pixmaps using GtkPixmap.set()
This looks like a bug in pygtk. You should be able to fix it by editing generate/gtkmisc.defs, and finding the following section: (define-func gtk_pixmap_set none ((GtkPixmap pixmap) (GdkPixmap val) (GdkBitmap mask))) and change it to: (define-func gtk_pixmap_set none ((GtkPixmap pixmap) (GdkPixmap val) (GdkBitmap mask (null-ok Another way without hacking into pygtk and thus making your program incompatible for the rest of the world would be to check if Imlib returns None for the mask. If this happens, you can create a mask by yourself: width, height = (img2.rgb_width, img2.rgb_height) mask = create_pixmap(None, width, height, 1) gc = mask.new_gc() gc.foreground = GdkColor(0, 0, 0, 0) draw_rectangle(mask, gc, TRUE, 0, 0, width, height) This is the way I handle this. Martin Grimme - http://www.pycage.de ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
[pygtk] Threads
Hello, as people sometimes had problems with threads in PyGTK, I'd like to share my experiences with you. First, be sure that your version of Python and your version of PyGTK support threads. If the following doesn't work, they have no thread support. From Python 2 on, Python compiles with thread support by default (and yes, Python 2 works well together with PyGTK. You just have to recompile PyGTK). To use threads in Python, you use the thread module. import thread import time # this is the function for my thread (a thread function takes 2 arguments) def my_thread(l1, l2): print "this is my thread" l1.release() # locks can be acquired and released to communicate between threads l2.release() thread.exit() lock1 = thread.allocate_lock() # create lock lock1.acquire() # lock it lock2 = thread.allocate_lock() lock2.acquire() # start the new thread and let it use both locks thread.start_new_thread(my_thread, (lock1, lock2)) # wait forever while(1): time.sleep(0.5) Now comes the part concerning PyGTK: The way described above works well as long as you don't use GTK functions. If you want to use GTK functions, you have to tell GTK that you're in a thread. Use threads_enter() and threads_leave() to do so. You place these calls into your thread function: def my_thread( ... ): ... # don't use GTK functions here threads_enter() ... # here you may use GTK functions threads_leave() ... # don't use GTK functions here If you want to use time.sleep() to delay your threads, be sure to not call it inside of a "threads_enter() / threads_leave()"-block. Because then time.sleep() would block the GTK mainloop(), too. If your thread function is a member of a class, you can use the "self"-pointer to access the class in your thread. I hope, this helps you. Have fun with threads! Martin Grimme - http://www.pycage.de ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
Re: [pygtk] making a pixmap from a bitmap or vice versa
Hi, I just started with pygtk and right now I am trying to create something like an arrow widget. In oder to get that done, I am drawing an arrow on a GtkPixmap which I create with gtk.create_pixmap and draw the pixmap on DrawingArea. This works fine and I get a black arrow on a white background. Now I want the background to be transparent instead of white. As far as I can tell, I need a bitmap for that. So the first thing I tried to do was to create a bitmap from the pixmap, but I could not find a way to do this. As you may have noticed, create_pixmap requires to know the depth of the pixmap. If you don't specify one, it will take the depth of the current display. In order to create a bitmap (pixmap with depth 1), you need to create a pixmap with a depth of 1: bitmap = create_pixmap(None, width, height, depth) The next thing I tried was to create a bitmap with PIL and from that create a GdkBitmap with create_bitmap_from_data. This worked fine as well, but now I have to create the pixmap from the bitmap, because I can not use the bitmap in gtk.draw_pixmap() to put it on the DrawingArea. I also tried toconvert the bitmap I created in PIL to an rgb and than somehow get the xpm data to create the pixmap with create_pixmap_from_xpm_d, but PIL does not support xpm format in the tostring method. I also tried to draw rgb data from the pil image on a newly created pixmap by calling gtk.draw_rgb_image(), but here I only got a segmentation fault. Does anybody know of an easier way (or any way at all). Any help would be appreciated. I am using Python2.0c1, PIL 1.1 and pygtk 0.6.6. You can copy from one pixmap to another by using the draw_pixmap command: draw_pixmap(destination, gc, source, xsrc, ysrc, xdest, ydest, width, height) You can get a 'gc' for a pixmap by calling the method new_gc(): gc = pixmap.new_gc() Thanks a lot In case you are interested in a more convenient way of creating and manipulating pixmaps and bitmaps, copying with transparency information (clipping), or reading image files, I may help you. I've written a class for PyGTK that handles all these things for pixmaps. It currently uses Imlib which is only required for loading images, though. I can mail it to you as it is not yet on my web-page (it's in an too early state). Nevertheless, it works quite well and does a great job for my programs. Ralph P.S. Since I have not subscribed to this list yet, it would be nice if you could reply to this address as well Martin Grimme - http://www.pycage.de ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
[pygtk] Pixmap transparency in a GdkDrawable?
Hello, again I've got a weird question: When I draw pixmaps onto a GdkDrawable using draw_pixmap(), transparency will be completely ignored. Is there any way around this? I want to draw pixmaps _with_ transparency onto a GdkPixmap. It seems to be possible for GdkPixmaps to have transparent areas. Consider the following piece of code: from gtk import * import _gtk win = GtkWindow() win.show() pix = win.get_window() root = _gtk.gdk_get_root_win() # _root_window() doesn't work... gc = root.new_gc() draw_pixmap(root, gc, pix, 0, 0, 0, 0, 200, 200) This puts the background of the window into the root window. But if there are parts of the window covered or otherwise out of view, those parts are not copied to the root window, thus I assume there is transparency possible for GdkPixmaps (the covered parts seem to be transparent). Please help, if you can! Thank you. Martin Grimme - http://www.pycage.de ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
[pygtk] Style and scroll bar problems
Hello I've got two questions: 1. Is it possible to change the style property bg_pixmap with widget.set_style()? When I try this, Python complains that bg_pixmap can only take a GdkPixmap as value. Is pix in the following line not a GdkPixmap? pix, mask = create_pixmap_from_xpm(win, None, "pixmap.xpm") print pix GdkPixmap at 81736f0 Python says it is one... 2. I have a code like the following: (...) hbox = GtkHBox(FALSE, 0) hbox.show() # create the iconbox as a GtkLayout self.iconbox = GtkLayout() self.iconbox.show() # create the scrollbar adj = GtkAdjustment() self.iconbox.set_vadjustment(adj) scrbar = GtkVScrollbar(adj) scrbar.show() hbox.pack_start(self.iconbox, TRUE, TRUE, 0) hbox.pack_end(scrbar, FALSE, FALSE, 0) (...) The problem is that i can use the scroll bar perfectly well to scroll the GtkLayout, but I cannot use its arrow buttons (no response), I can only drag the bar. What did I do wrong??? Martin Grimme ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk