Re: [pygtk] gtk.gdk.Event.get_coords does not exist.
On Mon, Feb 24, 2003 at 06:10:26PM -0500, Rob Landley wrote: > I'm getting an attribute error trying to call anything on the Event object > passed to me. I tried dumping a __dict__ and that isn't there either. > > The wrapper doesn't make SENSE, in any case. The logic of get_coords would be > that a python method call was modifying its (integer) arguments, which is > remarkably un-pythonic. (Pass it a mutable list, sure. But that's not what > it claims should be happening.) Maybe the C bindings can do this, but ouch. How do you know the wrapper doesn't make sense if you couldn't get it to work? Most of the C idioms used in GTK are mapped to their Python equivalent idiom. Overall, PyGTK has a pretty good setup. > > Here's some sample code showing things I've tried, which didn't work. In the future, if you have a short code snippet just append it to the body of your message. Attachments are a pain and not easily quotable. You must create a mainloop, by calling gtk.mainloop(). Your iteration loop has two major problems. The first one is that you haven't properly initialized the GTK+ mainloop which is causing you all kinds of grief. GTK+ will complain about this only when you call certain functions, notably gtk.mainquit() (which usually exists somewhere in every program). The second problem is that your while loop never sleeps and imposes 100% CPU load. This is unacceptable because it will suck the life very quickly out of any battery powered device (laptop users will hate you). It also is unnecessarily unfair to lower priority processes. In otherwords, your example has no need for gtk.mainiteration(). gtk.mainiteration() is generally used when you are performing some long process and want to periodically flush the gtk event queue. You can use something like this: while gtk.events_pending(): gtk.mainiteration() Rarely does one use gtk.mainiteration by itself in a loop, and never in an unconditional loop. Getting that taken care of you should find that the GdkEvent object (that you name b in your signal handler) has a get_coords function. The get_coords function returns the coordinates as a tuple, which seems to be as Pythonic as one could ask for. --jkl ___ 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] color of draw_lines changes
On Mon, 24 Feb 2003, Dan Christian wrote: > The color changes happens after you try to draw outside the drawing > areas (off by 1 issue). Still, sort of a odd symptom. FWIW, I have seen this bug too. I just have been too occupied running down other bugs in my programs to hunt this one down. The best way to test this is to write a small gtk program in C to check if the problem still exists. If so, then write an XLib program and see if the problem still exists. These kinds of bugs are a real pain to track down. :( The last time I saw something similar was with stippled filled rectangles which would turn black when clipped. It was an XFree86 bug (Radeon specific, last time I checked, it was still there). BTW, what's your graphics hardware and XFree86 version? -a ___ 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] Tutorial translations.
I converted most of these as well for the PyGTK tutorial at http://www.moeraki.com/pygtktutorial/index.html John Rob Landley wrote: By the way, I'm going through http://www.gtk.org/tutorial and translating the examples from C to python, and sending them in to the maintainer. Here's the ones I've done so far. ___ 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] Tutorial translations.
By the way, I'm going through http://www.gtk.org/tutorial and translating the examples from C to python, and sending them in to the maintainer. Here's the ones I've done so far. Chapter 3: base.py, hello.py chapter 4: hello2.py chapter 5: packbox.py Still working on the second (table based) example in chapter 5... Rob -- penguicon.sf.net - A combination Linux Expo and Science Fiction Convention, May 2-4 2003 in Warren, Michigan. Tutorials, installfest, filk, masquerade...#!/usr/bin/python import gtk win=gtk.Window() win.show() gtk.mainloop() #!/usr/bin/python import gtk class hello: # The "hello" signal is sent when you click the button. def hello(self, obj): print "Hello World" # The "delete_event" signal is sent when they try to close the window. def delete_event(self, obj, event): # Return TRUE and nothing happens, return FALSE and a destroy_event gets # sent to the main window, which actually makes it go away. This is # intended to allow you to stick in an "Are you sure?" type pop-up dialog. print "delete event occurred" return gtk.TRUE # The "kill -9" type callback. Quit without a confirmation pop-up. def destroy(self, obj): gtk.mainquit() # The constructor function for the class def __init__(self): # We don't have to call an equivalent of gtk_init manually. Importing # the gtk module did that for us as part of its setup. # Create a window. self.window=gtk.Window() # Let it know how to go away. self.window.connect("delete_event",self.delete_event) self.window.connect("destroy",self.destroy) # Give it a little padding around the edges. self.window.set_border_width(10) # Create a button. self.button=gtk.Button("Hello World!") # Install signal handlers on the button to provide appropriate behavior. self.button.connect("clicked",self.hello) self.button.connect("clicked",lambda a: self.window.destroy()) # Put the button in the window. self.window.add(self.button) # make everything visible. self.button.show() self.window.show() # If this module is being called directly rather than imported by another # module... if __name__ == "__main__": # Instantiate our dialog and loop dispatching events for it. hello() gtk.mainloop() #!/usr/bin/python import gtk # Python specific note: I tried to make this example match the C example # as closely as possible, but there were a couple of judgement calls: # This is a class, and that means local variables and instance variables # are different. I made all the references to GTK widgets instance variables # (so you can reach out and twiddle GUI elements easily long after # instantiating them), but "button" was re-used for both buttons in the C # example. I changed it to "button1" and "button2". (I could have just made # everything locals, or simply ignored the overwrite, but it bugged me. At # the very least, window should be an instance variable, and having it be # different from the other widgets was gratuitously ugly. The difference # between instance variables and local variables has nothing to do with the # GTK anyway, and python itself already has a nice tutorial up on python.org. # Another judgement call is that "pack_button" takes four arguments, but # the last three have default values, and the C example is passing in what # their default values are. So I kept the code smaller, and more than made # up for it with this big long comment. :) class hello2: # Our new improved callback. The data passed to this function # is printed to stdout. def callback(self, obj, data): print "Hello again - %s was pressed" % data # The "delete_event" signal is sent when they try to close the window. def delete_event(self, obj, event): gtk.mainquit() # The constructor function for the class def __init__(self): # We still don't have to call an equivalent of gtk_init manually. # Importing the gtk module did that for us as part of its setup. # Create a new window. self.window=gtk.Window() # This is a new call, which just sets the title of our # new window to "Hello Buttons!" self.window.set_title("Hello Buttons!") # Here we just set a handler for delete_event that immediately # exits GTK. self.window.connect("delete_event",self.delete_event) # Sets the border width of the window. self.window.set_border_width(10) # We create a box to pack widgets into. This is described in detail # in the "packing" section. The box is not really visible, it # is just used as a tool to arrange widgets. self.box1=gtk.HBox() # Put the box into the main window. self.window.add(self.box1) # Creates a button with the label "Button 1". self.button1=gtk.Button("Button 1") # Now when the button is clicked, we call the "callback" function # with a pointer to "Button 1" as its argument. self.button1.con
[pygtk] gtk.gdk.Event.get_coords does not exist.
I'm getting an attribute error trying to call anything on the Event object passed to me. I tried dumping a __dict__ and that isn't there either. The wrapper doesn't make SENSE, in any case. The logic of get_coords would be that a python method call was modifying its (integer) arguments, which is remarkably un-pythonic. (Pass it a mutable list, sure. But that's not what it claims should be happening.) Maybe the C bindings can do this, but ouch. Here's some sample code showing things I've tried, which didn't work. Rob -- penguicon.sf.net - A combination Linux Expo and Science Fiction Convention, May 2-4 2003 in Warren, Michigan. Tutorials, installfest, filk, masquerade...#!/usr/bin/python import gtk,gtk.gdk, sys class blah: def button_press_event(self, a, b): print a,b w=x=y=0 print b.get_state print b.get_state(w) print b.get_coords print b.coords print gtk.gdk.get_coords(b,x,y) def __init__(self): self.window=gtk.Window() self.window.connect("delete_event",lambda a: sys.exit(0)) self.window.set_border_width(10) self.event_box=gtk.EventBox() self.window.add(self.event_box) self.event_box.show() self.label=gtk.Label("Click here to quit, quit, quit, quit") self.event_box.add(self.label) self.label.show() self.label.set_size_request(110,20) self.event_box.set_events(gtk.gdk.BUTTON_PRESS_MASK) self.event_box.connect("button_press_event",self.button_press_event) self.event_box.realize() #self.event_box.set_cursor(gtk.cursor_new(gtk.gdk.HAND1)) self.window.show() if __name__=="__main__": blah() while gtk.mainiteration(): pass
Re: [pygtk] Constants
On Mon, Feb 24, 2003 at 01:54:01PM -0600, Lars Clausen wrote: > I'm having some trouble finding GTK constants in PyGTK. For instance, > where is GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID? I think -1 should work in a pinch. You may want to file a bug report on this one: http://bugzilla.gnome.org Dave Cook ___ 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] Constants
I'm having some trouble finding GTK constants in PyGTK. For instance, where is GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID? And more importantly, how would I found out where it is? I didn't see it in the online help for gtk or gtk.TreeSortable. -Lars -- Lars Clausen (http://shasta.cs.uiuc.edu/~lrclause)| HÃ¥rdgrim of Numenor "I do not agree with a word that you say, but I | will defend to the death your right to say it." | Where are we going, and --Evelyn Beatrice Hall paraphrasing Voltaire | what's with the handbasket? ___ 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] color of draw_lines changes
On Monday 24 February 2003 09:29, Dan Christian wrote: > When I do drawingArea.draw_lines() with a GC set to a specific > foreground color, the first part of the line sequence will draw in > the right color, but then the rest reverts to black. Never mind, my bug. The color changes happens after you try to draw outside the drawing areas (off by 1 issue). Still, sort of a odd symptom. -Dan ___ 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] color of draw_lines changes
I'm running pygtk2-1.99.13 with RedHat 7.3. When I do drawingArea.draw_lines() with a GC set to a specific foreground color, the first part of the line sequence will draw in the right color, but then the rest reverts to black. The number of segments before the color change occurs is consistent across refreshes, but seems to change as the code changes (ranging from all the right color, to only the first segment being right). If I draw multiple lines, then they all change colors after the same number of segments. Am I doing something wrong? Has this been fixed already? -Dan ___ 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] Fastest way of caching data?
>> cache[track][note][(tick/250)*250][tick] >> >> I hope you can follow me and would be most gratefull for a reply. > > I'm not sure about the (tick/250)*250 part, since it seems to be > redundant with indexing by tick. It is used since the tick is a dictionary and not a list, so I have to home in on what notes are displayed on screen by 250, and then iterate through them checking if they exist in the dictionary (by using try: [...] except KeyError: pass). This apears smarter (in my head) that getting the midi-tick of the start of the display, and then iterating through all midi-tick that are displayable on screen, checking if there's a note with cache.index(tick), because since the program can zoom, thousands of midi-ticks can be displayed on screen. > Apart from that, no, I don't see a > better way to optimize that off the top of my head. Are you having a > performance problem? Well, not with the program on its on, but since it's a sequencer it has to run at the same time as the sound-client, in this case iiwusynth, and then every CPU-cycle counts. I can do what I just descriped on my Celeron 500MHz, but not while moving the mouse fast (which is, of course, the ultimate test ;) ), then sound skips, so I was just wondering if I could speed up this function somehow. Thanks for your answer. Cheers ...Christian ___ 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] Fastest way of caching data?
On Mon, Feb 24, 2003 at 11:38:29AM +0100, [EMAIL PROTECTED] wrote: > I was wondering what the fastest way of caching data was in Python? Python Lists and Dictionaries are very fast, being 100% coded in C and avoiding all of Python's function call overhead. > so I can find stuff by getting: > (tick is position in midi-ticks, note is, well, note, like E5, just in > numbers) > > cache[track][note][(tick/250)*250][tick] > > I hope you can follow me and would be most gratefull for a reply. I'm not sure about the (tick/250)*250 part, since it seems to be redundant with indexing by tick. Apart from that, no, I don't see a better way to optimize that off the top of my head. Are you having a performance problem? Take care, -- Christian Reis, Senior Engineer, Async Open Source, Brazil. http://async.com.br/~kiko/ | [+55 16] 261 2331 | NMFL ___ 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] Strange change in event behavior in PyGTK2
James Henstridge <[EMAIL PROTECTED]> writes: > Christian Reis wrote: > > >Would it be correct, according to Python semantics, to pre-copy of > >the object then? And if so, what are the drawbacks of implementing > >things that way? > > > The drawback is that a number of GTK APIs simply don't work if you copy > the boxed arguments. We used to copy boxed arguments (which has the > benefit that it is safe to keep references to boxed objects passed as > arguments to signals), but we changed it for this reason. Would it be worthwhile to mark the python object as invalid somehow when the signal handler finished? E.g. set a flag that it's invalid or simply set the pointer to the boxed object to NULL and all attempts to access attributes later on will raise an exception? This would have saved me some time when I tried to figure out why some things in Sketch didn't work anymore after switching to gtk2. Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ MapIt! http://www.mapit.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] Fastest way of caching data?
I know this is not specifically PyGTK, but it's used in a PyGTK program so... I was wondering what the fastest way of caching data was in Python? It's for my MIDI-sequencer project. I have been using a combination of lists and dictinarys for caching notes on tracks like this cache = [[[{}]]] so I can find stuff by getting: (tick is position in midi-ticks, note is, well, note, like E5, just in numbers) cache[track][note][(tick/250)*250][tick] I hope you can follow me and would be most gratefull for a reply. Cheers ...Christian ___ 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] Adjusting a TreeView padding to the other elements of an HBox
Hi. I have a VBox which contains a few buttons and a TreeView. For the buttons I call set_border_width(), but this doesn't have any effect on the TreeView. I understand that I should wrap TreeView inside another container. What's the usual 'neutral' container I should use to give TreeView a padding border? Here's a code extract: self.button2 = gtk.Button("title") self.box1.pack_start(self.button2, 1, 1, 0) self.button2.connect("clicked", self.clicked_button2, "hello", "world") self.button2.set_border_width(5) self.button2.show() self.list = gtk.TreeView(create_model()) self.box1.pack_start(self.list) self.list.set_border_width(50) self.list.set_rules_hint(1) self.list.set_headers_visible(0) Another thing I would like to do is have the TreeView always have the height of five rows. When I store five rows, this is ok, but when I introduce 3, the TreeView height decreases accordingly. One solution I found is to insert empty rows. However, these rows are selectable by the user. Is it possible to have void spacing rows? ___ 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] can not import gnome.ui
hi! i compiled gnome-python 1.99.15 yesterday and for some reason i cannot import gnome.ui anymore.. Python 2.2.2 (#1, Jan 18 2003, 10:38:15) [GCC 3.2.2 20030109 (Debian prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import pygtk >>> pygtk.require("2.0") >>> import gnome >>> import gnome.ui Traceback (most recent call last): File "", line 1, in ? ImportError: No module named ui when i go to /usr/lib/python2.2/site-packages/gtk-2.0/gnome though the uimodule.so and uimodule.la file is there though. also configure told me that it will compile gnome-python with gnome.ui included. any ideas what could go wrong? thanks! ciao! florian ___ 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] treeview drag and drop
I'm trying to use a class I derived from treestore as the model for a tree view. How do I implment the drag and drop interfaces? I know I can use the standard gtk dnd interface, but I'd rather try and use the treeview\treemodel dnd interface as it already does some of the work like highlighting the row over which you drag and automatically expanding nodes when you drag over them. Also, the gtk docs for treeview have an enable_drag_model() method which does not seem to be present in the pygtk version of treeview. Is this a bug? If you know of any good source code or docs (with any language) on doing treeview drag and drop, please let me know. Thanks ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/