Re: [pygtk] ANN: PyGUI 2.1.1
I'm disappointed that I appear to be the only one on this list that finds these announcements objectionable. And contrary to speculation I find them all objectionable (yes that means yours as well Roberto). So far it's been lucky that not all of the hundreds of projects based on pygtk have felt it necessary to send announcements to the list and I thank them for their restraint. I would suggest that an announcement only maillist be setup for those who wish to send and receive these announcements but I fear that many would continue to spam this list anyway. John Greg Ewing wrote: PyGUI 2.1.1 is available: http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ This is an emergency bugfix release to repair some major breakage in the gtk version. Also corrects some other problems. What is PyGUI? -- PyGUI is a cross-platform GUI toolkit designed to be lightweight and have a highly Pythonic API. ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] ANN: PyGUI 2.1
Pietro Battiston wrote: Il giorno mar, 17/11/2009 alle 11.19 +1300, Greg Ewing ha scritto: Pietro Battiston wrote: And I promise I won't come there just saying that PyGUI API sucks Okay, that particular remark was a bit rude, and I apologise for it. Let me rephrase: One of the reasons I created PyGUI is that none of the existing cross-platform GUI APIs, including pygtk, are entirely to my taste. So making PyGUI emulate pygtk wouldn't make sense from my point of view. I certainly don't mean to dissuade anyone from using pygtk. If you like it, by all means continue to use it. OK, that's more diplomatic. My opinion is that if you create a mailing list for PyGUI (and I suggest Mailman [0], the software running this mailing list, for it), a message if anybody is interested in a different approach to pygtk, a PyGUI mailing list has been created at this address on this mailing list will cause no complaints (notice your first email didn't mention pygtk at all). I have to disagree. I consider attempts to build a competing community by spamming maillists with announcements to be annoying and rude. The criterion should be does this post add value to the community. I believe that Greg's posts do not add value to the pygtk community and he should refrain from posting his announcement to the pygtk list. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] ANN: PyGUI 2.1
Greg Ewing wrote: Luis A. Bastiao Silva wrote: But it just works for application wroted from stratch, otherwise application wroted in pygtk need to be ported to work cross-platform. It's already possible to run pygtk programs on all three platforms, if you're willing to install the required libraries. API compatibility with pygtk (or any other gui library) is not one of PyGUI's goals. What are you wrapping in Win32? Windows API directly? Currently it uses the MFC layer of pywin32. I hope eventually to replace that with raw win32 via ctypes. Anyway seems a good project, although it will be better have a pygtk cross platform :) That's a matter of opinion. One of the major goals of PyGUI is to provide an API that doesn't suck. The pygtk API doesn't meet that requirement, IMO. Greg, Why do you post to mailing lists that are unrelated to your project? I would appreciate it if in future you didn't post a message about your project ot the PyGTK mailing list. I think you are rude to post your off-topic messages to the PyGTK mailing list mo to mention the other lists. Please don't post your project adverts here in future. Thanks John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] ANN: PyGUI 2.1
Greg Ewing wrote: John Finlay wrote: Greg, Why do you post to mailing lists that are unrelated to your project? I would appreciate it if in future you didn't post a message about your project ot the PyGTK mailing list. I posted the announcement to the pyobjc, pygtk and pywin32 lists because PyGUI uses all of those libraries, and because I don't know of any single mailing list where people interested in Python GUIs in general can be found. However, if the consensus is that PyGUI announcements are not welcome on those lists, I will be happy to cease posting them there. What is the general feeling out there? Should I stop posting PyGUI messages to these lists? Is there another GUI-related list that would be more appropriate? Start your own list for the community that is interested in your project. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Saving and reading images from database
Timo List wrote: My program uses the SQLite database. The database holds some information about persons and I want to add a picture for each person. Not the path to the file, but the actual image so that the image also works if the file is deleted on the harddisk. I can save the image in a BLOB column as: imgfile = open('/path/to/image.png') db.save_image(imgfile.read()) Works fine as far as I see. (Maybe any comments on this?) Retrieving also works, but I see no possibility to show this image in a gtk.Image widget. I can't seem to find anything related to this on the net, maybe someone reading this has done this before? One possibility is to save the image as a compressed in-line image in the db and create a pixbuf from the in-line data after it's retrieved and decompressed. Here's some code to create an in-line image and compress it: import struct, bz2 ... # pb is a pixbuf containing the image to be in-lined pix = pb.get_pixels() inline_img = 'GdkP'+struct.pack('!iBBHiii',len(pix)+24,1,1,pb.get_has_alpha()+1, pb.get_rowstride(),pb.get_width(),pb.get_height())+pix bz2_inline_img = bz2.compress(inline_img) # save bz2_inline_ob in the db To use the compressed in-line image use something like: # the compressed in-line image is in bz2_inline_img inline_img = bz2.decompress(bz2_inline_img) pb = gtk.gdk.pixbuf_new_from_inline(-1, inline_img, False) Copy the pixels if you are going to delete the inline_img string. Then you can use the pixbuf to create your image. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] pyGtk segfault comparing gtk.Image with 0
Pietro Battiston wrote: Il giorno sab, 17/10/2009 alle 20.49 +0300, Paul Pogonyshev ha scritto: Pietro Battiston wrote: Il giorno sab, 17/10/2009 alle 17.30 +0100, Tomeu Vizoso ha scritto: On Sat, Oct 17, 2009 at 17:12, René 'Necoro' Neumann li...@necoro.eu wrote: Well -- you are not initializing gtk.Image. So it's your very own mistake. I don't see a pygtk issue here. This is Python, any crash is a bug. Wait, wait. Read http://bugzilla.gnome.org/show_bug.cgi?id=561130 , then come back here and let's talk :-) Pietro (P.S: as you can desume from the page, I _would like_ to agree with you) You can still rightfully agree with him that it _is_ a bug. Whether it gets fixed is another point. What I mean is: where is it written that every crash is a bug, if Pygtk developers themselves are not so clear on that (and I'm possibly too ignorant)? this question has come around a couple of times before and I recall that each time it's deemed too impractical to catch every possible error to prevent a segfault. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] How to add 'clicked' event to treeview cell?
Taras wrote: Hello, all! There is a table with some rows. For example, it has 3 columns. The first one is icon column 'Add/Remove to favorites' with star icon. I read about pixbuf renderer but I can't find how can I connect 'clicked' event to this column :( I also research how it made in Exaile (music player written in Python/GTK). There is workaround with: ... self.list.connect('button-release-event', self.update_rating) ... and ... (x, y) = e.get_coords() #check if the click is within rating column and on a list entry if self.list.get_path_at_pos(int(x), int(y)) \ and left_edge x left_edge + rating_col_width: ... But it looks like unbeautiful workaround. Is there more beautiful solution to connect 'clicked' event to icon cell? I don't think there is a built-in way to connect to a clicked event on a TreeView cell. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Styling a text view across the visible line
Scott Ferguson wrote: Hi, I'm trying to build an integrated diff tool for an app that I'm writing, and I am styling the text to make certain parts of the diff more visible (adds are green, removes are red, etc). Typical look and feel of a diff viewer. The styling includes a background and foreground color. Currently I'm iterating over each line of the gtk.TextBuffer, creating an ending iterator at the next line, and styling everything between the line start, and the start of the following line. My issue is that I would like the background color to carry straight across the gtk.TextView, not end where the line ends (on the '\n' character). A single line should have a highlight from left to right. Is this possible with a stock gtk.TextView? My current formatting function can be found here: http://gist.github.com/206387 Try setting the 'paragraph-background' property of the tag. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] gtk.entry copy and paste via ctrl-c ctrl-v
Kim Adil wrote: I have an entry and want to use the keyboard shortcuts for cut/copy/paste. Without any coding by me, popup menu works fine, but keyboard shortcuts don't work. the tutorial suggests it should be working by default: 15.1.2. Using Clipboards with Entry, Spinbutton and TextView Entry, SpinButton and TextView widgets have popup menus that provide the ability to cut and copy the selected text to and paste from the CLIPBOARD clipboard. In addition key bindings are set to allow keyboard accelerators to cut, copy and paste. Cut is activated by *Control*+*X*; copy, by *Control*+*C*; and, paste, by *Control*+*V*. Am I missing something obvious? BTW using ubuntu jaunty standard packages. works for me on: Python 2.6.2, PyGTK 2.14.1 (Gtk+ 2.16.1) on jaunty John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] image on a Button
Gorse Emmanuel wrote: Thanks for the answer. I'm checking the imgFullFile with os.path.exists() before loading it, so the absolute path of the image is correct. As img.set_from_file() doesn't raise an exception when it can't load the file, i've tried with this: img = gtk.Image() pixBuf = gtk.gdk.pixbuf_new_from_file(imgFullFile) img.set_from_pixbuf(pixBuf) button.set_image(img) and gtk.gdk.pixbuf_new_from_file() didn't raise an exception, but the image is still not displayed. Furthermore, i'm also using an IconView to display the images, and they are displayed just fine. The code is: store = gtk.ListStore(str, gtk.gdk.Pixbuf) for name in xxx: pixbuf = gtk.gdk.pixbuf_new_from_file(imgFullFile) store.append([name, pixbuf]) So the image loading seems fine but images don't get displayed on the buttons... 2009/9/30, sandbox_mail sandbox_m...@yahoo.de: I did not try it out but my first guess is: the image is not found in Windows due to the different path syntax. In linux you will have a path like /home/user/picture.jpg but in windows 1.) there is no /, instead \ is used 2.) absolute paths start at the drive letter like C:\Users\picure.jpg I believe python's os module will help you build the correct paths depending on which system the code is running. Gorse Emmanuel wrote: Hye, I'm using this code to display an image on a button: img = gtk.Image() img.set_from_file(imgFullFile) button.set_image(img) with imgFullFile beeing the absolute path of the image. The code works fine under Linux, but the image is not displayed under Windows. Do you have any idea why ? Try adding: img.show() John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Image Resize
Pete Stapley wrote: I have a menu bar, an image and a status bar in a vbox. Is there a way to find out the new size of the image widget when the window is resized? I can get the size of the complete window with configure-event signal, but I want just the size of the image widget. Thanks! http://www.daa.com.au/pipermail/pygtk/2009-September/017635.html ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Drawing a PNG on a gtk.DrawingArea
Fabrice DELENTE wrote: Hello. I'm still struggling with displaying a PNG image on a gtk.DrawingArea. I designed a glade interface that is basically a toplevel window with an hbox in it. I then add() a gtk.DrawingArea in the hbox. I'm trying to display the image this way: fichier = /home/fab/tex/courante/TES/partie1/equations_et_inequations_du_second_degre.png self.imageOriginelle = gtk.gdk.pixbuf_new_from_file(fichier) self.imageReduite = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 500, 700) self.imageOriginelle.scale(self.imageReduite, 0, 0, 500, 700, 0, 0, self.imageOriginelle.get_width()/500.0, self.imageOriginelle.get_height()/700.0, gtk.gdk.INTERP_HYPER) I do this because I need to rescale the image so that it fits in my interface. The 500 and 700 values are arbitrary and for tests purposes only. I then try to display it: self.GC = gtk.gdk.GC(self.zoneDeDessin.window) self.zoneDeDessin.window.draw_pixbuf(self.GC, self.imageReduite, 0, 0, 0, 0) where self.zoneDeDessin is the gtk.DrawingArea object I add()ed to the hbox. I can see a white rectangle, but no image in it. What did I miss? What happens if you try drawing the original pixbuf? John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Resizing an hbox
Fabrice DELENTE wrote: Hello. I have an interface which is a simple toplevel window containing an hbox which contains a gtk.DrawingArea, designed in glade. How can I catch the fact that the hbox or the DrawingArea are resized when the toplevel is resized in the window manager? I thought that connecting the check-resize event of the hbox would be enough, but it doesn't work. Is there a flag to set somewhere? Thanks! Try the size-allocate signal. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Multiple Gtk.DrawingArea
Antoine Cailliau wrote: Dear, don't use this since it returns the allocation within the Window not within the DA. Use self.window.get_size() to get the width and height and use 0, 0 for the x and y in the following. Thanks you a lot for your answer. I've on other small problem (but I do not think it is useful to start a new thread): I would like to set the size of the bottom DA. Using da2.size(X, Y) it seems that the application become greedy when I resize the window. Therefore, I guess it is not the right way to set the size. Spend some time reading the PyGTK Tutorial and reviewing the appropriate Reference Manual pages and the FAQ at pygtk.org John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Problems with button.
Hidura wrote: I'm trying to make a button just with the icon, I want to give the relief of the button to the icon for have more stetic in my project On Tue, Sep 8, 2009 at 1:24 PM, John Finlay fin...@moeraki.com mailto:fin...@moeraki.com wrote: Hidura wrote: Hello, List i have this sub-class of a Button and make me the icon what i pass in the button but lose the releif when the icon replace the button how could i change that and give the relief back again. Thanks. ##CODE class Button(gtk.Button): This is the constructor of the Vertical Scale. def __init__(self): gtk.Button.__init__(self) self.gc = None # initialized in realize-event handler self.width = 0 # updated in size-allocate handler self.height = 0 # idem self.connect('size-allocate', self.on_size_allocate) self.icon = '/usr/local/lib/python2.5/HidalgoP/.Logos/Buttons/add.png' def do_expose_event(self, event): self.window.draw_pixbuf(self.gc, gtk.gdk.pixbuf_new_from_file_at_size(self.icon, 60, 60), 0, 0, -1, -1, -1, -1, gtk.gdk.RGB_DITHER_NORMAL, 0, 0) self.set_relief(gtk.RELIEF_NORMAL) def on_size_allocate(self, widget, allocation): self.width = allocation.width self.height = allocation.height Are you trying to put the Pixbuf inside the Button or undeneath the button? I'm having trouble understanding what you are trying to do. John Try putting the pixbuf inside an Image and then put the Image inside a Button. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Multiple Gtk.DrawingArea
Antoine Cailliau wrote: Dear all, First of all, a short presentation since I'm new on the ML. I'm student in Belgium (UCLouvain) in Computer Science (especially computer langages and software engineering). I just started a small project (a game for gnome) to get familiar with Cairo and Pango libs. I need two distinct drawing area in a gtk window. I tried a naive way but I only get one working area (the first is accordingly filled with a black rectangle, the other seems to be not displayed). I presume this is not the right way to do it. Here is the code: #!/usr/bin/env python # import gtk, cairo class DA(gtk.DrawingArea): def __init__(self): gtk.DrawingArea.__init__(self) self.connect(expose_event, self.expose) def expose(self, widget, event): self.context = widget.window.cairo_create() # set a clip region for the expose event self.context.rectangle(event.area.x, event.area.y, event.area.width, event.area.height) self.context.clip() self.draw(self.context) return False def draw(self, context): rect = self.get_allocation() don't use this since it returns the allocation within the Window not within the DA. Use self.window.get_size() to get the width and height and use 0, 0 for the x and y in the following. context.rectangle(rect.x, rect.y, rect.width, rect.height) context.fill() return False def main(): window = gtk.Window() da1 = DA() da2 = DA() vbox = gtk.VBox() vbox.add(da1) vbox.add(da2) window.add(vbox) window.connect(destroy, gtk.main_quit) window.show_all() gtk.main() if __name__ == __main__: main() ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Disable signals and events to use a button as a container, not as a button?
Ryan Martin wrote: Hey John, Thanks for the response. Yes, technically that would work, except that you can't stretch the background of an event box. It only tiles. As the style is applied to other sized event boxes, the background texture would not stretch and resize. If anybody knows a way to make the background pixmap for an event box stretch, I'd be all set. Any ideas? Thanks Ryan What do you mean by stretch and resize? An example would help to visualize how this would work. John Finlay wrote: Have you tried using an eventbox inside the frame to hold the vbox that holds the other stuff? I believe that the purpose of the eventbox is to do just the kind of thing you want i.e. set the bg_pixmap for the eventbox to some custom pixmap that represents your style. John Ryan Martin wrote: That's a good question. I didn't explain why I needed to do this because I thought I'd confuse more. In the software I'm writing, I'm combining theme elements with some widget tricks to accomplish a visual task that I don't know is possible by any other means. I need to have a container than I can 'skin' that can contain other widgets. My initial thought was to theme gtk.Frame to have borders and a background (like a button), and I can pack all of my widgets into that. Unfortunately, to my knowledge, you can't have a background on a frame widget. So I started cycling through other gtk widgets to see if there was some sort of container that I could theme, but was unable to find something that worked. (http://www.ensomniac.com/pygtk/button_example2.jpg) That led me to my latest theory, that if I were able to use a button as a container, I could theme gtk.Button to get the visual style I wanted, but also the functionality of having the widgets inside. I would need to disable the core button (container) from receiving and processing signals, but somehow pass them on to any of the widgets inside the button: (http://www.ensomniac.com/pygtk/button_example.jpg) And that leaves me where I'm at now. The following code will disable my base button from working: *print* self.widgets.main_container_button.get_property(above-child) *False** print* self.widgets.main_container_button.set_property(above-child, True) *print* self.widgets.main_container_button.get_property(above-child) *True* But I have no idea how to pass the events to the widgets that are children of the button (the 'button_2' widget and the entry widget in the image above). If there is some other way to accomplish my task, I'm all ears. Currently, I'm struggling trying to get my events passed to the child widgets. Thanks for the help! Ryan John Finlay wrote: Ryan Martin wrote: Hey Guys, I have a strange situation that I'm having trouble finding a solution for. In the application I'm building, I would like to use a button as a container and not necessarily a button. Currently, I have a text field and another button inside my main button in question. What I would like is to disable all of the innate callbacks (prelight/hover, clicked, etc.) on that main button and just have it sit there while still being able to click the child button inside the main button or enter text into the text field. One thing to consider is that I need to disable callbacks on the main button but not on any of the widgets that are added to the main button as a child. Is this possible? Did that make sense? Any help would be greatly appreciated. I have scoured through old threads looking for clues. Why do you need to use a button as a container when you don't want to use any of the button's features? Are there no GTK containers that work? John -- Ryan Martin *Industrial Light + Magic *Assistant Technical Director cell: 973-632-1417 / desk: 415-746-2117 * * -- Ryan Martin *Industrial Light + Magic *Assistant Technical Director cell: 973-632-1417 / desk: 415-746-2117 * * ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/ ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Problems with button.
Hidura wrote: Hello, List i have this sub-class of a Button and make me the icon what i pass in the button but lose the releif when the icon replace the button how could i change that and give the relief back again. Thanks. ##CODE class Button(gtk.Button): This is the constructor of the Vertical Scale. def __init__(self): gtk.Button.__init__(self) self.gc = None # initialized in realize-event handler self.width = 0 # updated in size-allocate handler self.height = 0 # idem self.connect('size-allocate', self.on_size_allocate) self.icon = '/usr/local/lib/python2.5/HidalgoP/.Logos/Buttons/add.png' def do_expose_event(self, event): self.window.draw_pixbuf(self.gc, gtk.gdk.pixbuf_new_from_file_at_size(self.icon, 60, 60), 0, 0, -1, -1, -1, -1, gtk.gdk.RGB_DITHER_NORMAL, 0, 0) self.set_relief(gtk.RELIEF_NORMAL) def on_size_allocate(self, widget, allocation): self.width = allocation.width self.height = allocation.height Are you trying to put the Pixbuf inside the Button or undeneath the button? I'm having trouble understanding what you are trying to do. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Disable signals and events to use a button as a container, not as a button?
Ryan Martin wrote: Hey Guys For all intensive purposes, an eventBox can have widgets packed into it as I need and it can also have the background set as a style property ala bg_pixmap[NORMAL] = 'something.png'. My problem is that the background needs to stretch, not tile. Like this: http://www.ensomniac.com/pygtk/button_example3.jpg When looking at the image above, please consider that I need to pack widgets inside the blue graphic area. That is why I need to use some form of container. I can't use an image widget, I can't use anything that won't let me pack widgets inside the graphic area. The reason I initially decided to go with a button was because I knew I could skin it (it has advanced skinning functionality allowing you to stretch the pixmap while leaving the borders of the graphic intact) and it could act as a container for other widgets. The problem with using a button is that each time you hover over the main container button, it steals all of the events that I want to go to the child widgets. My initial post was looking for ideas on how I could disable the main button from events and just use it as a graphic container for my child widgets which would still need to work as expected. This has proven to be impossible? snip What is the advanced skinning functionality of a Button? This is something I'm not aware of. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Disable signals and events to use a button as a container, not as a button?
Ryan Martin wrote: When you skin a button (and certain other widgets), you can control the amount of pixels on top, left right and bottom to remain intact. Those pixels do not scale when the widget is resized. The rest of the pixels inside the widget scale as normal. This is what keeps button borders from scaling horizontally or vertically and distorting, creating ugly edges. This example should show you what I mean: http://www.ensomniac.com/pygtk/button_example8.jpg That's nice. What's the API to control that? John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Color a ToggleButton
E.R. Uber wrote: I agree, it works fine on my Fedora 11 box as well, but not under Windows XP SP3. So do you think this is impossible under XP or that more effort is required?? Thanks E.R. Uber On Sun, Sep 6, 2009 at 8:26 AM, John Finlay fin...@moeraki.com mailto:fin...@moeraki.com wrote: E.R. Uber wrote: As in? widget.modify_bg(gtk.STATE_NORMAL, color_off) andwidget.modify_bg(gtk.STATE_ACTIVE, color_on) That doesn't work either. On Sat, Sep 5, 2009 at 7:41 PM, John Finlay fin...@moeraki.com mailto:fin...@moeraki.com mailto:fin...@moeraki.com mailto:fin...@moeraki.com wrote: E.R. Uber wrote: After reading PyGTK FAQ 4.6 at http://faq.pygtk.org/index.py?req=showfile=faq04.006.htp http://faq.pygtk.org/index.py?req=showfile=faq04.006.htp http://faq.pygtk.org/index.py?req=showfile=faq04.006.htp http://faq.pygtk.org/index.py?req=showfile=faq04.006.htp http://faq.pygtk.org/index.py?req=showfile=faq04.006.htp http://faq.pygtk.org/index.py?req=showfile=faq04.006.htp http://faq.pygtk.org/index.py?req=showfile=faq04.006.htp http://faq.pygtk.org/index.py?req=showfile=faq04.006.htp I thought perhaps I could change the color of a ToggleButton by copying its style, updating the style, and setting the style. This did not work. Then reading PyGTK FAQ 4.16 at http://faq.pygtk.org/index.py?req=showfile=faq04.016.htp http://faq.pygtk.org/index.py?req=showfile=faq04.016.htp http://faq.pygtk.org/index.py?req=showfile=faq04.016.htp http://faq.pygtk.org/index.py?req=showfile=faq04.016.htp http://faq.pygtk.org/index.py?req=showfile=faq04.016.htp http://faq.pygtk.org/index.py?req=showfile=faq04.016.htp http://faq.pygtk.org/index.py?req=showfile=faq04.016.htp http://faq.pygtk.org/index.py?req=showfile=faq04.016.htp it mentions that gtk.Button (and I assume gtk.ToggleButton) are windowless widgets that do not allow changing their background and base color unless you insert them into an EventBox. Using a parent EventBox succeeds in changing the color of the event box, but not the child ToggleButton, the button just appears to be surrounded by the color change of the event box. I tried the same with a Button and it works the same way. I am using pygtk 2.12.1, gtk 2.16.4, glade 3.6.7, and python 2.6 on both windows and fedora core 9. I have only tried this to date on windows though. You don't need the EventBox just use toggle.modify_bg() with the appropriate state and color. Note in your example you need to set STATE_NORMAL and STATE_ACTIVE to have different colors for the active and inactive states. John Works fine on ubuntu 9.04 (Python 2.6.2, PyGTK 2.14.1 (Gtk+ 2.16.1)) and Fedora 10.21 (Python 2.5.2, PyGTK 2.13.0 (Gtk+ 2.14.7)). Maybe Windows overrides the change. Note the color change isn't visible when the cursor is over the button because it is in the prelight state. John Try asking your question on one of the gtk mail lists (see: http://www.gtk.org/mailing-lists.html) John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Color a ToggleButton
E.R. Uber wrote: As in? widget.modify_bg(gtk.STATE_NORMAL, color_off) and widget.modify_bg(gtk.STATE_ACTIVE, color_on) That doesn't work either. On Sat, Sep 5, 2009 at 7:41 PM, John Finlay fin...@moeraki.com mailto:fin...@moeraki.com wrote: E.R. Uber wrote: After reading PyGTK FAQ 4.6 at http://faq.pygtk.org/index.py?req=showfile=faq04.006.htp http://faq.pygtk.org/index.py?req=showfile=faq04.006.htp http://faq.pygtk.org/index.py?req=showfile=faq04.006.htp http://faq.pygtk.org/index.py?req=showfile=faq04.006.htp I thought perhaps I could change the color of a ToggleButton by copying its style, updating the style, and setting the style. This did not work. Then reading PyGTK FAQ 4.16 at http://faq.pygtk.org/index.py?req=showfile=faq04.016.htp http://faq.pygtk.org/index.py?req=showfile=faq04.016.htp http://faq.pygtk.org/index.py?req=showfile=faq04.016.htp http://faq.pygtk.org/index.py?req=showfile=faq04.016.htp it mentions that gtk.Button (and I assume gtk.ToggleButton) are windowless widgets that do not allow changing their background and base color unless you insert them into an EventBox. Using a parent EventBox succeeds in changing the color of the event box, but not the child ToggleButton, the button just appears to be surrounded by the color change of the event box. I tried the same with a Button and it works the same way. I am using pygtk 2.12.1, gtk 2.16.4, glade 3.6.7, and python 2.6 on both windows and fedora core 9. I have only tried this to date on windows though. You don't need the EventBox just use toggle.modify_bg() with the appropriate state and color. Note in your example you need to set STATE_NORMAL and STATE_ACTIVE to have different colors for the active and inactive states. John Works fine on ubuntu 9.04 (Python 2.6.2, PyGTK 2.14.1 (Gtk+ 2.16.1)) and Fedora 10.21 (Python 2.5.2, PyGTK 2.13.0 (Gtk+ 2.14.7)). Maybe Windows overrides the change. Note the color change isn't visible when the cursor is over the button because it is in the prelight state. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Color a ToggleButton
E.R. Uber wrote: After reading PyGTK FAQ 4.6 at http://faq.pygtk.org/index.py?req=showfile=faq04.006.htp http://faq.pygtk.org/index.py?req=showfile=faq04.006.htp I thought perhaps I could change the color of a ToggleButton by copying its style, updating the style, and setting the style. This did not work. Then reading PyGTK FAQ 4.16 at http://faq.pygtk.org/index.py?req=showfile=faq04.016.htp http://faq.pygtk.org/index.py?req=showfile=faq04.016.htp it mentions that gtk.Button (and I assume gtk.ToggleButton) are windowless widgets that do not allow changing their background and base color unless you insert them into an EventBox. Using a parent EventBox succeeds in changing the color of the event box, but not the child ToggleButton, the button just appears to be surrounded by the color change of the event box. I tried the same with a Button and it works the same way. I am using pygtk 2.12.1, gtk 2.16.4, glade 3.6.7, and python 2.6 on both windows and fedora core 9. I have only tried this to date on windows though. You don't need the EventBox just use toggle.modify_bg() with the appropriate state and color. Note in your example you need to set STATE_NORMAL and STATE_ACTIVE to have different colors for the active and inactive states. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] PyGTK problem
nipun batra wrote: I need from this code that var1,var2,var3,var4 should be continuosly read from file(or serial port) and there value be updated continuosly.Also i wish to use these 4 variables for plotting in pygame/matplotlib/VPython .How can i do that.Moreover for every read cycle there has to be a write cycle on to a file(or serial port) and the user must be able to set this value via an entry.have not been able to figure out all this.Moreover with my code i am able to presently display updated information on a button click(where as i wanna use button just to start things of) have attached program and source file 1.txt IO to a disk file has quite different characteristics than IO to a serial port or network connection. You probably have to code these separately because of the different needs. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Updating widgets within threads
Bottiger, Maxwell - AES wrote: Hi, I have an implementation methodology question. I'm putting together an app which runs a bunch of external devices. All my devices are on different serial ports and run at different frequencies. I'd like to use one thread to monitor each device, then have the thread update it's relevant section of the GUI. I've been playing with updating a progress bar with a thread this morning and I've found once I start the thread the main window freezes until the thread completely exits. Obviously this isn't working. What is the best way to go about this? I don't want to freeze my main window by putting sleep calls in the main loop, but I do need to update the display when new data becomes available. Have you considered using using gobject.io_add_watch() instead of using threads? Unless there is some really long calculation this would seem like an ideal event driven program. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Existing C/GTK application
Rick Hightower wrote: I have an existing C/GTK application. I would like to write all new features in Python using PyGTK. Is there any way to write widgets in PyGTK and use them easily in a C/GTK based application? Are there examples of this somewhere? Essentially I want to add a Widget to a parent where the Widget is managed by PyGTK and the parent is in the C/GTK application. It might be easier to rewrite the C/GTK app in Python if possible. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Disable signals and events to use a button as a container, not as a button?
Ryan Martin wrote: Hey Guys, I have a strange situation that I'm having trouble finding a solution for. In the application I'm building, I would like to use a button as a container and not necessarily a button. Currently, I have a text field and another button inside my main button in question. What I would like is to disable all of the innate callbacks (prelight/hover, clicked, etc.) on that main button and just have it sit there while still being able to click the child button inside the main button or enter text into the text field. One thing to consider is that I need to disable callbacks on the main button but not on any of the widgets that are added to the main button as a child. Is this possible? Did that make sense? Any help would be greatly appreciated. I have scoured through old threads looking for clues. Why do you need to use a button as a container when you don't want to use any of the button's features? Are there no GTK containers that work? John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Disable signals and events to use a button as a container, not as a button?
Have you tried using an eventbox inside the frame to hold the vbox that holds the other stuff? I believe that the purpose of the eventbox is to do just the kind of thing you want i.e. set the bg_pixmap for the eventbox to some custom pixmap that represents your style. John Ryan Martin wrote: That's a good question. I didn't explain why I needed to do this because I thought I'd confuse more. In the software I'm writing, I'm combining theme elements with some widget tricks to accomplish a visual task that I don't know is possible by any other means. I need to have a container than I can 'skin' that can contain other widgets. My initial thought was to theme gtk.Frame to have borders and a background (like a button), and I can pack all of my widgets into that. Unfortunately, to my knowledge, you can't have a background on a frame widget. So I started cycling through other gtk widgets to see if there was some sort of container that I could theme, but was unable to find something that worked. (http://www.ensomniac.com/pygtk/button_example2.jpg) That led me to my latest theory, that if I were able to use a button as a container, I could theme gtk.Button to get the visual style I wanted, but also the functionality of having the widgets inside. I would need to disable the core button (container) from receiving and processing signals, but somehow pass them on to any of the widgets inside the button: (http://www.ensomniac.com/pygtk/button_example.jpg) And that leaves me where I'm at now. The following code will disable my base button from working: *print* self.widgets.main_container_button.get_property(above-child) *False** print* self.widgets.main_container_button.set_property(above-child, True) *print* self.widgets.main_container_button.get_property(above-child) *True* But I have no idea how to pass the events to the widgets that are children of the button (the 'button_2' widget and the entry widget in the image above). If there is some other way to accomplish my task, I'm all ears. Currently, I'm struggling trying to get my events passed to the child widgets. Thanks for the help! Ryan John Finlay wrote: Ryan Martin wrote: Hey Guys, I have a strange situation that I'm having trouble finding a solution for. In the application I'm building, I would like to use a button as a container and not necessarily a button. Currently, I have a text field and another button inside my main button in question. What I would like is to disable all of the innate callbacks (prelight/hover, clicked, etc.) on that main button and just have it sit there while still being able to click the child button inside the main button or enter text into the text field. One thing to consider is that I need to disable callbacks on the main button but not on any of the widgets that are added to the main button as a child. Is this possible? Did that make sense? Any help would be greatly appreciated. I have scoured through old threads looking for clues. Why do you need to use a button as a container when you don't want to use any of the button's features? Are there no GTK containers that work? John -- Ryan Martin *Industrial Light + Magic *Assistant Technical Director cell: 973-632-1417 / desk: 415-746-2117 * * ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Animation performance - limitation or my code?
Kim Adil wrote: I once wrote a gtk program in C that displayed about 30 animations on a drawing area and they moved around the screen, and performance was excellent. The drawingarea size was 1600x1200 and the animations were very smooth. I have started to write a similar app using pygtk in a more object oriented way, and the drawing area size really seems to have a large impact on performance. When the drawing area is 100x100, anims are smooth. If the drawing area is dragged to 1000x1000 the frame rate drops very quickly. Is this to be expected with the python being interpreted, or is it just that my code is inefficient. See sample below (requires 2 animated gif files a.gif and a2.gif, just substitute any from the web for demonstartion, and a glade file attached): #!/usr/bin/env python import sys import pygtk import glib import gtk import gtk.glade # main window to display objects in motion i=1 class MainWin: def __init__(self): self.gladefile = hv.glade self.wTree = gtk.glade.XML(self.gladefile, main_win) dic = {on_drawingarea1_expose_event : self.expose, on_drawingarea1_configure_event: self.configure, } self.wTree.signal_autoconnect(dic) self.window = self.wTree.get_widget(main_win) self.da = self.wTree.get_widget(drawingarea1) self.window.show_all() x, y, width, height = self.da.get_allocation() self.pixmap = gtk.gdk.Pixmap(self.da.window, width, height) self.machlist = [] self.setup_objects() glib.timeout_add(30, self.draw_objects) def setup_objects(self): self.machlist.append(Object('t1','v','stopped',10,10,'a.gif')) self.machlist.append(Object('t2','v','travelling',300,10,'a2.gif')) self.machlist.append(Object('t3','v','stopped',100,300,'a.gif')) self.machlist.append(Object('t4','v','stopped',600,600,'a2.gif')) self.machlist.append(Object('t5','v','stopped',100,60,'a.gif')) self.machlist.append(Object('t6','f','stopped',60,100,'a.gif')) self.machlist.append(Object('t7','f','travelling',100,100,'a.gif')) def draw_objects(self): x, y, width, height = self.da.get_allocation() self.pixmap = gtk.gdk.Pixmap(self.da.window, width, height) self.pixmap.draw_rectangle(self.da.get_style().white_gc,True, 0, 0, width, height) for object in self.machlist: self.pixmap.draw_pixbuf(self.da.get_style().fg_gc[gtk.STATE_NORMAL],object.pb, 0, 0, object.x,object.y) Add this line: self.da.queue_draw_area(x, y, width, height) return True def expose(self,a,b): x, y, width, height = self.da.get_allocation() self.da.window.draw_drawable(self.da.get_style().fg_gc[gtk.STATE_NORMAL],self.pixmap, x, y, x, y, width, height) self.da.queue_draw_area(x, y, width, height) Remove the above line. return False def configure(self,a,b): x, y, width, height = self.da.get_allocation() self.da.window.draw_drawable(self.da.get_style().fg_gc[gtk.STATE_NORMAL],self.pixmap, x, y, x, y, width, height) return False def cleanup(self): for object in self.machlist: glib.source_remove(object.timeout) def list_objects(self): self.draw_objects() for object in self.machlist: self.pixmap.draw_pixbuf(self.da.get_style().fg_gc[gtk.STATE_NORMAL],object.pb, 0, 0, 0, 0) #self.da.queue_draw() class Object: def __init__(self,name,model,state,x,y,anim): self.name=name self.model=model self.state=state self.x=x self.y=y self.anim=anim self.image='l' self.frame=0 self.imagef = gtk.Image() self.pixbufanim = gtk.gdk.PixbufAnimation(anim) print 'width %d - height %d'%(self.pixbufanim.get_width(),self.pixbufanim.get_height()) self.pbiter = self.pixbufanim.get_iter() print 'delay time %d'%(self.pbiter.get_delay_time()) self.pb=self.pbiter.get_pixbuf() self.t=glib.timeout_add(self.pbiter.get_delay_time(), self.update_pb) def update_pb(self): self.pbiter.advance() self.pb=self.pbiter.get_pixbuf() self.t=glib.timeout_add(self.pbiter.get_delay_time(), self.update_pb) return False print 'create mainwin' m=MainWin() gtk.main() I think the program is generating too many expose events and too many draw_pixbuf calls are slowing down the animations when a large pixbuf draw is needed. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Trying to change the pen color just before I draw a line
Rick Hightower wrote: snip Here is the full program. It changes the background color and redraws. I need to be able to draw different color lines. import pygtk pygtk.require(2.0) import gtk from gtk import Window, Button class Base: def handle_color_change(self, widget, data) : self.color = data if self.color == Red: gdk_color = gtk.gdk.color_parse(Red) elif self.color == Green: gdk_color = gtk.gdk.color_parse(Green) else: gdk_color = gtk.gdk.color_parse(Blue) style = self.area.get_style().copy() style.bg http://style.bg[gtk.STATE_NORMAL] = gdk_color self.area.set_style(style) self.area.queue_draw() def __init__(self): self.color = None self.window = Window(gtk.WINDOW_TOPLEVEL) self.window.connect(destroy, lambda w: gtk.main_quit()) self.mainPane = gtk.VBox(False, 0) self.window.add(self.mainPane) # create the toolbar self.toolbar = gtk.HBox(False, 0) self.green = Button('Green') self.red = Button ('Red') self.toolbar.pack_start(self.green, True, True, 0) self.toolbar.pack_start(self.red, True, True, 0) self.mainPane.pack_start(self.toolbar, True, True, 0) self.red.connect(clicked, self.handle_color_change, Red) self.green.connect(clicked, self.handle_color_change, Green) #Create the drawing area self.area = gtk.DrawingArea() self.area.set_size_request(400, 300) self.area.connect(expose-event, self.area_expose) self.mainPane.pack_start(self.area, True, True, 0) self.window.show_all() def area_expose(self, area, event): print (area exposed) v delete vv gc = self.area.get_style().fg_gc[gtk.STATE_NORMAL] gdk_color = gtk.gdk.color_parse(Blue) gc.get_colormap().alloc_color(gdk_color) ^^ delete ^^^ v add v gc=self.area.window.new_gc() gdk_color = gc.get_colormap().alloc_color(Blue) ^^ add ^^ gc.set_foreground(gdk_color) self.area.window.draw_line(gc, 0, 0, 80, 70) return False def main(self): gtk.main() if __name__ == __main__: base = Base() base.main() You could create the GC and color up front and reuse it in the expose event handler to simplify. john ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Non-blocking subprocess.Popen stop GUI
Bou Baris wrote: I think this is due to mkvextract not flushing its output because it's not connected to a tty. Try using a pty in between to fool mkvextract. Something like: from_mkve, to me = pty.openpty() to_me = os.fdopen(to_me, 'r') file_flags = fcntl.fcntl(to_me, fcntl.F_GETFL) fcntl.fcntl(to_me, fcntl.F_SETFL, file_flags|os.O_NDELAY) proc = subprocess.Popen(command, stdout=from_mkve) gobject.io_add_watch(to_me, gobject.IO_IN|gobject.IO_HUP, self.test_io_watch) Thanks for your suggestion. This evening when I come back @home I'll try it. BTW if 'mkvextract' doesn't flush its output, I should have the same problem running my original code that use 'select'. Using 'select' is fine, there is no block to the flow due to lack of stdout flush, BUT the problem is GUI that is stopped. One hour ago I've also tried with thread (using module thread and thread.start_new_thread() function). The same behaviour.. GUI is stopped until subprocess.Popen() end. I'm guessing that you are printing a buffer full of output at a time but the progressbar isn't getting updated because the program is stuck in the select() loop and can't run the gtk event processing loop until it exits the loop i.e. when the mkvextract program ends. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Non-blocking subprocess.Popen stop GUI
Bou Baris wrote: Instead of using select() use gobject.io_add_watch() on proc.stdout to register a callback function that is used to read the % and set the progress bar. I've modified my code to test gobject.io_add_watch() I expect that test_io_watch() print in console line readed from proc.stdout But i see nothing: look like a blocking behaviour (as when use Popen without use select) If I stop program with CTRL-C, now I see the output to console/terminal def test_io_watch(self, file, condition): print str(file.readline()) return True def mkv_dts_extraction(self,dtstrack,pgbar=None): command=['mkvextract', \ 'tracks', \ self.INPUTFILE, \ dtstrack + ':' + self.TEMP_DTSFILENAME] proc=subprocess.Popen(command,stdout=subprocess.PIPE) outfile=proc.stdout outfd=outfile.fileno() file_flags = fcntl.fcntl(outfd, fcntl.F_GETFL) fcntl.fcntl(outfd, fcntl.F_SETFL, file_flags | os.O_NDELAY) gobject.io_add_watch(proc.stdout,gobject.IO_IN | gobject.IO_HUP,self.test_io_watch) err = proc.wait() return True I was surprised at your result so I looked back at this message and realized that the reason it didn't work is because you are waiting for the process to complete before returning from the mkv_dts_extraction() method. The above code should work if you remove the line: err = proc.wait() John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Non-blocking subprocess.Popen stop GUI
Bou Baris wrote: Instead of using select() use gobject.io_add_watch() on proc.stdout to register a callback function that is used to read the % and set the progress bar. I've modified my code to test gobject.io_add_watch() I expect that test_io_watch() print in console line readed from proc.stdout But i see nothing: look like a blocking behaviour (as when use Popen without use select) If I stop program with CTRL-C, now I see the output to console/terminal def test_io_watch(self, file, condition): print str(file.readline()) return True def mkv_dts_extraction(self,dtstrack,pgbar=None): command=['mkvextract', \ 'tracks', \ self.INPUTFILE, \ dtstrack + ':' + self.TEMP_DTSFILENAME] proc=subprocess.Popen(command,stdout=subprocess.PIPE) outfile=proc.stdout outfd=outfile.fileno() file_flags = fcntl.fcntl(outfd, fcntl.F_GETFL) fcntl.fcntl(outfd, fcntl.F_SETFL, file_flags | os.O_NDELAY) gobject.io_add_watch(proc.stdout,gobject.IO_IN | gobject.IO_HUP,self.test_io_watch) err = proc.wait() return True ___ Also I forgot you must use file.read() instead of file.readline() in your callback since you need to read all the available input in the callback. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Non-blocking subprocess.Popen stop GUI
Bou Baris wrote: I'm a new user of PyGTK. I'm writing with Python and PyGTK a little software for decoding MKV video files using external tool MKV TOOL UNIX. It's a simple graphical front-end to ffmpeg and MKVTOOLNIX. I use Ubuntu 9.04 shipped with Python 2.6.2 and PyGTK 2.x I've a problem (obviously). I've made a non blocking function (using subprocess.Popen and select) for calling the external program MKVEXTRACT. When works, 'mkvextract' reports its progress state as a percentage: Progress: 0% Progress: 1% Progress: 2% I want read 'mkvextract' stdout in a real-time (non-blocking) fashion, decode progress number from string 'Progress: xx%' and control a PyGTK ProgressBar. This is the code and non-blocking is working (printing the progress to console it's ok). The problem is that when code run, I see in terminal the percentage number decoded correctly (printed from my code, not by 'mkvextract', see code below) but progress bar isn't moving. Really ALL GUI is blocked. It's look that Popen block GUI job until 'mkvextraxt' end. When Popen/mkvextract ends its job, GUI restart to normal behaviour and I see the progress bar to 100% def mkv_dts_extraction(self,dtstrack,pgbar=None): command=[ 'mkvextract', \ 'tracks', \ self.INPUTFILE, \ dtstrack + ':' + self.DTSFILENAME ] # start subprocess proc = subprocess.Popen(command,stdout=subprocess.PIPE) # set non-blocking mode outfile = proc.stdout outfd = outfile.fileno() file_flags = fcntl.fcntl(outfd, fcntl.F_GETFL) fcntl.fcntl(outfd, fcntl.F_SETFL, file_flags | os.O_NDELAY) # use 'select' for reading while True: ready = select.select([outfd],[],[]) # wait for input if outfd in ready[0]: outchunk = outfile.read() if outchunk == '' : break select.select([],[],[],.1) # give a little time for buffers to fill perc = re.compile(Progress:\s+(\d+),re.IGNORECASE).findall(outchunk) if len(perc) 0: completed = int(perc[len(perc)-1]) / 100.00 # take last 'Progress' number print completed # this print WORKS: in terminal I can see the percentage growing # progress bar DON'T WORK : GUI is blocked pgbar.set_fraction(completed) pgbar.show() err = proc.wait() return True Instead of using select() use gobject.io_add_watch() on proc.stdout to register a callback function that is used to read the % and set the progress bar. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Non-blocking subprocess.Popen stop GUI
Bou Baris wrote: Instead of using select() use gobject.io_add_watch() on proc.stdout to register a callback function that is used to read the % and set the progress bar. I've modified my code to test gobject.io_add_watch() I expect that test_io_watch() print in console line readed from proc.stdout But i see nothing: look like a blocking behaviour (as when use Popen without use select) If I stop program with CTRL-C, now I see the output to console/terminal def test_io_watch(self, file, condition): print str(file.readline()) return True def mkv_dts_extraction(self,dtstrack,pgbar=None): command=['mkvextract', \ 'tracks', \ self.INPUTFILE, \ dtstrack + ':' + self.TEMP_DTSFILENAME] proc=subprocess.Popen(command,stdout=subprocess.PIPE) outfile=proc.stdout outfd=outfile.fileno() file_flags = fcntl.fcntl(outfd, fcntl.F_GETFL) fcntl.fcntl(outfd, fcntl.F_SETFL, file_flags | os.O_NDELAY) gobject.io_add_watch(proc.stdout,gobject.IO_IN | gobject.IO_HUP,self.test_io_watch) err = proc.wait() return True I think this is due to mkvextract not flushing its output because it's not connected to a tty. Try using a pty in between to fool mkvextract. Something like: from_mkve, to me = pty.openpty() to_me = os.fdopen(to_me, 'r') file_flags = fcntl.fcntl(to_me, fcntl.F_GETFL) fcntl.fcntl(to_me, fcntl.F_SETFL, file_flags|os.O_NDELAY) proc = subprocess.Popen(command, stdout=from_mkve) gobject.io_add_watch(to_me, gobject.IO_IN|gobject.IO_HUP, self.test_io_watch) John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Glade interface and Dialog: buttons don't work
Fabrice DELENTE wrote: Hello. I designed an interface with Glade, and I want to use it with PyGtk. In this interface, there is a Window and a Dialog. The Dialog is popped up when I click a button in the Window. I have a reference to the Dialog: dialog = gtk.glade.XML(gladeFile, dialog1).get_widget(dialog1) and references to the two button that are in the action area: okButton = gtk.glade.XML(gladeFile, dialog1).get_widget(okButton) cancelButton = gtk.glade.XML(gladeFile, dialog1).get_widget(cancelButton) These buttons are connected to handlers in Glade: okButton's activate and clicked signals are connected to handleOkButton, and cancelButton's activate and clicked signals to handleCancelButton. I have defined these handlesr: def handleOkButton(widget): print ok button pressed def handleCancelButton(widget): print cancel button pressed but nothing happens when I pop up my Dialog with dialog.show_all() and I click either Ok or Cancel... I tried with dialog.run(), and it didn't worked either. Any hint? Thanks! Did you connect the handlers to the signals using autoconnect? John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Glade interface and Dialog: buttons don't work
Fabrice DELENTE wrote: Look at: http://library.gnome.org/devel/pygtk/stable/class-gladexml.html#method-gladexml--signal-autoconnect I think I don't need this method if I define the callbacks directly in the glade file. You need to call this method to connect the callbacks named in the glade file to the callbacks in the python program. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Sorting every row of a tree regardless of its hierarchy
Jiri Bajer wrote: On Wed, 2009-08-26 at 01:47 +0200, John Finlay wrote: If I store the data in a TreeModel, wrap a TreeModelSort over it and display the result via TreeView, the sorting mechanism is not able to put Task 2 before Task 1.2 even if Task 2 has higher priority. It is caused by respecting the hierarchy - sorting won't break a child from its parent (but I need to do so). Is there any way how to achieve such sorting without maintaining two copies of all data - one in TreeStore and one in ListStore and sorting/displaying the ListStore instead? Look at the TreeModelFilter. With the right set_modify_func() function you may be able to massage the look for your purposes. Thanks for a hint! I've managed to create a 1:1 mapping between filtered and original model - but I don't see how to change the row hierarchy in the filtered model. It seems to me it is not possible to do anything else than setting a value for filtered model's cell and thus using PyGTK's native tree sorting mechanism over the filtered model won't work. Did you mean I can reorder the filtered tree rows as if they were sorted by a given column (with original model's hierarchy that doesn't respect my re-ordering) and then hide the expanders? That would also mean I have to maintain a path-to-path/row-to-row mapping for every tree row and every column I want to sort-by. Mapping example for sort by Priority: tree - sorted flat list (0,) - (0,) (0,0) - (1,) (0,1) - (3,) (1,) - (2,) Do you have any tips for the mapping? If I use something like the example before I have to go through most of the tree and re-number the paths with every row insert/delete (but finding the right path is easy). Or I could store pointers like iterators or row references for every row and every sortable column - they wouldn't need any additional care in case of row insert/delete. But the iterators are not guaranteed to be persistent and large number of row references would slow down the tree to crawl... That looks like having two copies of all data (a tree and a list) doesn't help either because I would have to maintain the path-to-path mapping anyway (or compute it on a fly by walking through all tree rows, counting the rows traversed and searching for a particular hierarchy number - which is too slow, O(N) for N=number of tree rows). I can also imagine a hybrid solution where every parent tree node keeps a number of nodes in his subtree which would speed up the tree traversing to something like O(log N) but would also add O(log N) operation of re-calculating the counts in a part of subtree on every row add/delete. From what I've thought about so far it seems the easiest way would be to hack into the TreeModelSort and add a property that would control if the rows compared during the sort operation will respect the hierarchy or if every row in the model gets compared. Can it be done directly from Python or will I have to roll up the sleeves and dive into the C code? Are there any tutorials available? Thanks for any further ideas! I think that you have to use a ListStore instead of a TreeStore and then work out some way to simulate a hierarchy with hiding children which I imagine is the major benefit of using a TreeStore. I was thinking a TreeModelFilter could do this. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Sorting every row of a tree regardless of its hierarchy
Jiri Bajer wrote: Hi, I am writing an editor for multi-columned hierarchical data (for example project tasks or software requirements) and would like to allow the user to sort the rows as if the data had a flat structure. Example TreeView: Hierarchy | Task name | Priority | Man-days --+---++- 1 | Task 1| High | 5 1.1 | Subtask 1 | High | 3 1.2 | Subtask 2 | Low| 2 2 | Task 2| High | 1 Now I would like to sort all the project tasks and subtasks by priority. If I store the data in a TreeModel, wrap a TreeModelSort over it and display the result via TreeView, the sorting mechanism is not able to put Task 2 before Task 1.2 even if Task 2 has higher priority. It is caused by respecting the hierarchy - sorting won't break a child from its parent (but I need to do so). Required result: Hierarchy | Task name | Priority v | Man-days --+---++- 1 | Task 1| High | 5 1.1 | Subtask 1 | High | 3 2 | Task 2| High | 1 1.2 | Subtask 2 | Low| 2 --- breaks the hierarchy Is there any way how to achieve such sorting without maintaining two copies of all data - one in TreeStore and one in ListStore and sorting/displaying the ListStore instead? I was able to hide the expanders via setting the expander column to a hidden one so the view part seems to be OK. I don't think TreeSortable.set_sort_func() would help here as the comparison works but the rows to be compared are chosen only from one parent and within the same tree depth (i.e. 1.1 is compared only with 1.2 but not with 1 or 2). Maybe I could write a wrapper providing a ListStore-like behavior while having no own data but taking them from a TreeStore + put this ListStore in its own TreeView? Or inheriting from a plain ListStore and implement child collapse/expand on my own? Any ideas are welcome, thanks! Look at the TreeModelFilter. With the right set_modify_func() function you may be able to massage the look for your purposes. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] set_use_markup and gtk.Button
Art Hunkins wrote: I have been happily using the set_use_markup property of gtk.Label and gtk.Frame with XML markup, to create bolded, italic and various sized text. I need to do this with gtk.Button as well - to do the same with (callback) button labels. However, I've not been able. I've employed the two general approaches below (with results immediately below them): #1: def cbbutton(self,box,callback,title=): Creates a callbackbutton box: parent box callback: click callback title: if given, the button name returns the widget instance self.cbbutts = self.cbbutts + 1 label = gtk.Label(title) label.set_use_markup(True) butt = gtk.Button( %s % label) box.pack_start(butt, False, False, 5) self.cbbuttons.append([butt,label,0]) butt.connect(clicked, callback) butt.show() return butt The above version runs fine, but gives unwanted button labels, of this variety: gtk.Label object a 0x[] (GtkLabel at 0x[different]) #2: def cbbutton(self,box,callback,title=): Creates a callbackbutton box: parent box callback: click callback title: if given, the button name returns the widget instance self.cbbutts = self.cbbutts + 1 label = gtk.Label() label.set_markup(title) butt = gtk.Button() butt.child = label label.show() box.pack_start(butt, False, False, 5) self.cbbuttons.append([butt,label,0]) butt.connect(clicked, callback) butt.show() return butt The above version crashes, with the following error log: /usr/lib/python2.6/site-packages/sugar/activity/main.py:35: GtkWarning: gtk_widget_realize: assertion `GTK_WIDGET_ANCHORED (widget) || GTK_IS_INVISIBLE (widget)' failed activity.show() Gtk:ERROR:gtkwidget.c:7967:gtk_widget_real_map: assertion failed: (GTK_WIDGET_REALIZED (widget)) Can someone please suggest what changes might give me a proper label? FWIW, including XML tags in title makes no difference whatever in the above results. How about: butt = gtk.Button(title) butt.child.set_use_markup(True) John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Help with set_cursor() ---- Invisible cursor option
On 08/03/2009 09:23 PM, John Finlay wrote: DINESHBABU DINAKARABABU wrote: Hi everyone, I am pretty new to Python and Pygtk. I would be grateful if someone could help me out with this issue. I am trying to get a full screen display of an image from some raw data using the pixbuf_new_from_data() method. I want to do away with the default cursor option and implement an invisible cursor so that we don't see the cursor during the full screen display. To implement the invisible cursor, I am doing the following: pixmap = gtk.gdk.Pixmap(None, 1, 1, 1) color = gtk.gdk.Color() cursor = gtk.gdk.Cursor(pixmap, pixmap, color, color, 0, 0) gtk.gdk.Window.set_cursor(cursor) However, I am getting this error: TypeError: descriptor 'set_cursor' requires a 'gtk.gdk.Window' object but receives a 'gtk.gdk.Cursor'. Try using: win.set_cursor(cursor) The error message is indicating that you have passed the wrong object to the function gtk.gdk.Window.set_cursor() which requires a Window object and a Cursor object as args. You should invoke the method of the Window object win instead. My mistake it should be: win.window.set_cursor(cursor) since it's the gtk.gdk.Window object not the gtk.Window object. john ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Help with set_cursor() ---- Invisible cursor option
On 08/03/2009 03:05 PM, DINESHBABU DINAKARABABU wrote: Hi, Now, it throws: AttributeError: 'NoneType' object has no attribute 'set_cursor' I agree to the fact that it is a gtk.gdk.Window object. Does win.window invoke a gtk.gdk.Window object? Correct me if am wrong as I am still learning the details and tricks associated with python and gtk. This means that there is no gtk.gdk.Window associated with the gtk.Window (win in this case). This is usually because the gtk.Window has not been realized (have a look at the tutorial which has an description of the widget display methods). You can call the widget realize() or show() methods before setting the cursor, or connect to the realize signal of win and set the cursor in the callback. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] size request in scrolled windows + viewport
On 08/03/2009 01:27 PM, Alessandro Dentella wrote: Hi I have a table with many widgets inside, so that total dimenstions are bigger that the screen so that I put it in a ScrolledWindow + ViewPort. So far so good. ow I have a Window with all widgets in a pane that scrolls fine... but starts very little indeed. I'd like to know how to propagate the dimentions that the table would have requested to set dimentions of the Viewport. I'm a little lost between size_request/get_child_requisition and similar methds. If the table is larger than the screen then I would assume you want the window to be smaller than the table. I usually set the default size of the Window so it starts up bigger than the minimum size. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Problem in fetching Unicode from URL and displaying it in PyGTK widget
Bertrand Kintanar wrote: On 7/17/09 1:12 PM, John Finlay wrote: Maybe you could gzip it and base64 encode it before stuffing it into the DB? John is gzipping it necessary for this to work? No but it'll make it a lot smaller than just base64 alone. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] gtk.ToggleButton not working.
Neil Dugan wrote: With pygtk version 2.12.9 this works button = gtk.ToggleButton('test',False) but on pygtk version 2.16.1 it no longer works :) I get the error message RuntimeError: more argument specifiers than keyword list entries (remaining format:'):GtkToggleButton.__init__') what do I need to do for it to work on both versions? It's a bug. The workaround is: button = gtk.ToggleButton('test') button.props.use_underline = False John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Problem in fetching Unicode from URL and displaying it in PyGTK widget
Bertrand Kintanar wrote: On 7/17/09 6:39 PM, John Finlay wrote: Bertrand Kintanar wrote: On 7/17/09 1:12 PM, John Finlay wrote: Maybe you could gzip it and base64 encode it before stuffing it into the DB? John is gzipping it necessary for this to work? No but it'll make it a lot smaller than just base64 alone. John I'm really not concerned with database size here. What I'm really concerned, which I'm having trouble implementing is how to convert the unicode to display the right character text rather than the coded form. ___ I misunderstood what you wanted. I thought you just wanted to save the html file contents into the DB and were having a problem with the text encoding between the html and the DB but it sounds like you want to do something different. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Problem in fetching Unicode from URL and displaying it in PyGTK widget
Bertrand Kintanar wrote: Hi list I've been working on a personal project and for some reason I need to read a html file and then store what I've read into database. And since there is huge possibility that the html file contains some unicode in it (e.g. `#xF1;' ) I'm having a hard time converting/displaying the right ascii equivalent to it (e.g. letter `ñ'). I don't care what format to store it to database, may it be in coded form or the ascii form. I can just make a function to convert it later. My problem is how to convert it. Maybe you could gzip it and base64 encode it before stuffing it into the DB? John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] warnings from dialog.run in pygtk2-2.14.1
On 07/15/2009 01:09 AM, Chris Rouch wrote: Hi, I recently upgraded to Fedora 11. Since then every pygtk program I have has started to produce a warning when dialog.run() is called: ./tmp.py:12: GtkWarning: gdk_x11_atom_to_xatom_for_display: assertion `atom != GDK_NONE' failed response=dialog.run() A very simple example is: #!/usr/bin/python import gtk,gobject window = gtk.Window(gtk.WINDOW_TOPLEVEL) dialog = gtk.Dialog(title,window) renametable=gtk.Table(2, 2, False) dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK) dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) dialog.set_position(gtk.WIN_POS_MOUSE) dialog.set_default_response(gtk.RESPONSE_OK) dialog.show_all() response=dialog.run() dialog.destroy() Is this a problem with my code, or a bug in pygtk? Neither. It's the result of a change in gtk 16.2. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Disappearing pango attributes
Krzysztof Kotlenga wrote: Hi, I have a program which, I believe, should do the same thing in both Python and C - set pango attributes on a label. The C version works as expected. In PyGTK version attributes get applied only on the first character. Any ideas why does this happen? I attach both test cases. The pygtk pango docs say that the end_index is 1 by default. You need to specify the end_index=-1 to get the same behavior as the C code. Pango C code started to set the attribute end_index to a default value in version 1.20 and the default value used was end of string. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] gtk.TreeModel.iter_children() method, how often should it be called?
Try asking this question on the gtk list gtk-l...@gnome.org. It's more likely someone there would have the answer. John Gerald Britton wrote: I don't think that makes sense. For example, it does stop calling iter_children at some point and display the tree. In my case, the first time the tree is build, it makes two calls to iter_children and then displays the tree and waits for something to happen (I still think that two is one too many, but I can live with it). The next time, it calls iter_children over 2000 times before it displays the tree. That can't be right! So, the question remains, When does the TreeModel stop calling iter_children and display the tree? It obviously does stop calling iter_children at some point, I can show that. But, what are the circumstances? What is it looking for? On Mon, Jun 22, 2009 at 6:28 AM, Chris Camachochris_cama...@yahoo.com wrote: As far as I could tell that's just the way it works *if* you could suspend the calls to iter_children it would stop working... --- On Sat, 20/6/09, Gerald Britton gerald.brit...@gmail.com wrote: From: Gerald Britton gerald.brit...@gmail.com Subject: Re: [pygtk] gtk.TreeModel.iter_children() method, how often should it be called? To: Chris Camacho chris_cama...@yahoo.com Cc: pygtk@daa.com.au Date: Saturday, 20 June, 2009, 11:11 PM I hear you, but I still need a direct answer to the question, What makes the TreeModel stop calling iter_children? I can't find a clear explanation and I can't figure it out by looking at the calls that come into my method either. On Thu, Jun 18, 2009 at 11:18 AM, Chris Camachochris_cama...@yahoo.com wrote: jeeze not being able to just reply is a pain anyhow I looked into using treemodels connecting to databases from what I could tell it seems to initially iterate all items and either copies them or creates meta data about the items (I didnt look into the implementation) Depending on how things were added it would also seem to iterate the whole set again! I think the standard treemodel is ok for small numbers (sub 200) but I had to end up paging 1,000's of items 100 at a time (interestingly this is what the gnome db widgets do...) I've been tempted to weld together my own data grid with a viewport and moving entry widgets but this would at a guess need C and I haven't had the time to look into it --- On Thu, 18/6/09, Gerald Britton gerald.brit...@gmail.com wrote: From: Gerald Britton gerald.brit...@gmail.com Subject: [pygtk] gtk.TreeModel.iter_children() method, how often should it be called? To: pygtk@daa.com.au Date: Thursday, 18 June, 2009, 2:50 PM Hi -- I think I have a problem but I'm not sure since I'm relatively new to the TreeModel and how it works. Here's the scenario: I use TreeModel to display rows of data from a database. Upon startup, the TreeModel is built and I notice two calls to the gtk.TreeModel.iter_children() method. Later, I change some data in one of the rows. The next time the TreeModel is built, gtk.TreeModel.iter_children() is called thousands of times before the display is refreshed. Oh, the database has less than 50 rows of data in it! So, two questions: 1. Is this normal (I hope not!) behavior? 2. What tells the TreeModel to stop calling gtk.TreeModel.iter_children()? How does the TM know that it has done everything it needs to do? -- Gerald Britton ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/ -- Gerald Britton ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] button-press-event on a TreeViewColumn Header?
Alessandro Dentella wrote: On Wed, Jun 17, 2009 at 08:16:37PM +0430, saeed wrote: I even tried to use a custom class: class MyTreeviewColumn(gtk.TreeViewColumn, gtk.EventBox): def __init__(self, *args): gtk.TreeViewColumn.__init__(self, *args) gtk.EventBox.__init__(self) self.connect('button-press-event', self.buttonPress) But it doesn't detect 'button-press-event'. Would be the header of treeview was accessible as a separate widget, or the TreeViewColums was a gtk.Widget not only a gtk.Object! :-D The only way that I found is that: if you don't need to resize columns, no, I definitely *need* to resize columns... sandro *:-) Could you use a MenuToolButton instead of a Button for the header using TreeViewColumn.set_widget()? John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Difficulty with rich text in gtk.TextView
Dennis Honeyman wrote: Hi everyone. I've been working on a simple rich text component for a project I've been working on using a gtk.TextView, and while I have something that's usable (in a very loose sense of the word =), there are a couple of problems I'm having that I can't figure out how to solve. This is what I have so far... http://pastebin.com/m6d3eb0b9 (The toggle buttons and text view are part of a glade file) For one, if there isn't text selected and the bold, italic, or underline button is pressed, I tried to apply the tag (buffer.apply_tag_by_name) by using the cursor's position as the start and end gtk.TextIter, although it seems to do nothing, as any text I type after I apply the tag is still in the same font as before. Also, when I have the cursor at the last character of a section of text with an applied style and I type more text, it doesn't keep the formatting like word processors do. (If text in underscores is bold) _This is bold te_ (But if I keep typing, the formatting isn't kept) _This is bold te_xt (It should be like this) _This is bold text_ I found a rich text demo application in Pygtk while I was searching for a solution (http://www.mail-archive.com/pygtk@daa.com.au/msg10283.html), but that one has the same limitation as mine. (Tags are not applied to text added directly after a section with the tag applied) And lastly, when the cursor is at the beginning of a block of text with an applied style, the gtk.TextIter at the cursor position says that the tag for the style is applied, but when I type it shows up in the default font ( '|' is the cursor) |_ere is bold text_ (iter.get_tags() has the bold tag, but when I type something...) h_ere is bold text_ (The tag is not applied) Why does it say that the bold tag is applied at the cursor if it doesn't apply the tag to text typed at that location? I think I might be missing something fundamental about how tags work... _ I'm sorry if any of this was unclear. If anyone could point me in the right direction I would be grateful. =) Your application will have to handle the bookkeeping required to manage the tags in the TextBuffer. When text is inserted at the cursor your app has to catch a signal indicating the text is being inserted and then apply the required tags to the inserted text. I think this can be done by catching theTextBuffer insert-text signal (using connect_after() to make sure the text has already been inserted) and then applying the tags to the text in the callback. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Getting string with in pixels
vlad...@atlas.cz wrote: Walter Leibbrandt wal...@translate.org.za napsal(a) : Hi, Vladimír Jícha wrote: Hello, I'm trying to get width of a text string. I found a FAQ 4.15 (http://faq.pygtk.org/index.py?req=showfile=faq04.015.htp) which has a solution for this. But unfortunately it doesn't work. If I use font = widget.get_style().font, I get following error message: AttributeError: 'gtk.Style' has no attribute 'font'. Is the FAQ outdated? What syntax should I use? Thank yo Try widget.get_style().get_font(). Thanks for your answer. Unfortunately it doens't work correctly for me. I have following 2 problems: 1) I get a DeprecationWarning for the line. 2) No matter what fond and size I use, I get the same width. Sample code: label = gtk.Label() name_font = pango.FontDescription(Times 10) label.modify_font(name_font) font = label.get_style().get_font() label2 = gtk.Label() name_font2 = pango.FontDescription(Sans Bold 12) label2.modify_font(name_font2) font2 = label2.get_style().get_font() print font.width(string), font2.width(string) I always get the same numbers. Is something wrong in my code? You should use the PangoLayout to retrieve the pixel size of the text. Use: label.get_layout().get_pixel_size() to get the width and height of the label string in pixels. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Fwd: Question
Johan Dahlin wrote: -- Forwarded message -- From: Rodrigo Almeida rodrigoal...@gmail.com Date: Tue, Feb 10, 2009 at 6:37 PM Subject: Question To: pygtk-...@async.com.br Hello Friends, I'm a programmer from Brasil, and i am doing an application using pygtk. I would like to know if you can help me. My question is: is there a way to use an image as a cursor? something like this: self.image.set_from_file(myimage.png) self.Tela.window.set_cursor(self.image) I hope you can help me. Greetings. Rodrigo Almeida. pb = gtk.gdk.pixbuf_new_from_file(myimage.png) c = gtk.gdk.Cursor(gtk.gdk.display_get_default(), pb, 0, 0) widget.window.set_cursor(c) John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Simple question on reusing stock item
Alessandro Dentella wrote: Hi, i'd like to use stock item in menu entries with modified labels to better suit context. * MenuItem doesn't allow to use images (reasonable) * ImageMenuItem doesn't appearently allow to change label (really???) I think I could go with IconFactory but it seems to me it's more complex than what is should be and I wandered if there is a simple way I was not able to work out. Thanks sandro *:-) A MenuItem is a Container so you can add anything to it. In your case create an empty MenuItem and add an HBox containing an Image and a Label. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] synchronizing HPaned widgets
Stephen Langer wrote: Hi -- I'm hoping that someone can tell me if this is a bug or if I'm doing something wrong. I have two HPaned widgets whose separators I'd like to keep synchronized. Both Paneds are in the same VBox, so they have the same width. As described at http://faq.pygtk.org/index.py?req=showfile=faq19.013.htp , I connect to the 'notify' signal for each pane to find out when the separator has been moved. The callback function blocks the signal for the other pane, changes its position to match the first pane, and then unblocks the signal. The problem is that the signal doesn't seem to be blocked sometimes, so the program goes into an infinite loop. There are easy workarounds for this, but they're ugly and unsatisfying. In particular, the program loops when the panes are first shown if the contents of two diagonally opposite subpanes are larger than the contents of the other two. I've appended short program that illustrates the problem. Just starting the program will put it into an infinite loop. If you replace paneMoved by paneMoved_workaround, the problem goes away. Why doesn't blocking the signal work? Am I doing something wrong? I've run this test on OS X with python 2.5, gtk 2.14.7, and pygtk 2.12.1, and on Linux with python 2.4, gtk 2.8.20, and pygtk 2.8.6. Thanks, Steve import gtk def setPos(pane, signal, pos): Set a Paned position without propagating signals pane.handler_block(signal) pane.set_position(pos) pane.handler_unblock(signal) def paneMoved(pane, gparamspec): Callback for synchronizing Paned position changes if gparamspec.name == 'position': pos = pane.get_position() if pane is topPane: print top setPos(botPane, botSignal, pos) else: print bottom setPos(topPane, topSignal, pos) count = 0 def paneMoved_workaround(pane, gparamspec): Callback for synchronizing Paned position changes global count if gparamspec.name == 'position': count += 1 pos = pane.get_position() if count == 1: if pane is topPane: print top setPos(botPane, botSignal, pos) else: print bottom setPos(topPane, topSignal, pos) elif count 1: count = 0 window = gtk.Window() box = gtk.VBox() window.add(box) window.connect(delete-event, gtk.main_quit) # Create two panes, one on top of the other topPane = gtk.HPaned() box.pack_start(topPane, expand=1, fill=1) botPane = gtk.HPaned() box.pack_start(botPane, expand=1, fill=1) # Synchronize the pane positions topSignal = topPane.connect('notify', paneMoved) botSignal = botPane.connect('notify', paneMoved) # If the displayed sizes of shortstring and longstring are different, # the program will enter an infinite loop after show_all(). If the # strings are identical, the program behaves correctly (no infinite # loop, the panes can be resized and stay synchronized). shortstring = string longstring = long string # Try String too. # Put each string into two diagonally opposite labels in the panes. topPane.pack1(gtk.Label(longstring), resize=1, shrink=0) topPane.pack2(gtk.Label(shortstring), resize=1, shrink=0) botPane.pack1(gtk.Label(shortstring), resize=1, shrink=0) botPane.pack2(gtk.Label(longstring), resize=1, shrink=0) window.show_all() gtk.main() You have to allow the widgets to shrink - remove the shrink=0 args from the pack1() and pack2() calls. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] synchronizing HPaned widgets
Stephen Langer wrote: On Feb 5, 2009, at 3:15 PM, John Finlay wrote: Stephen Langer wrote: Hi -- I'm hoping that someone can tell me if this is a bug or if I'm doing something wrong. I have two HPaned widgets whose separators I'd like to keep synchronized. Both Paneds are in the same VBox, so they have the same width. As described at http://faq.pygtk.org/index.py?req=showfile=faq19.013.htp , I connect to the 'notify' signal for each pane to find out when the separator has been moved. The callback function blocks the signal for the other pane, changes its position to match the first pane, and then unblocks the signal. The problem is that the signal doesn't seem to be blocked sometimes, so the program goes into an infinite loop. There are easy workarounds for this, but they're ugly and unsatisfying. In particular, the program loops when the panes are first shown if the contents of two diagonally opposite subpanes are larger than the contents of the other two. I've appended short program that illustrates the problem. Just starting the program will put it into an infinite loop. If you replace paneMoved by paneMoved_workaround, the problem goes away. Why doesn't blocking the signal work? Am I doing something wrong? I've run this test on OS X with python 2.5, gtk 2.14.7, and pygtk 2.12.1, and on Linux with python 2.4, gtk 2.8.20, and pygtk 2.8.6. [ code deleted ] You have to allow the widgets to shrink - remove the shrink=0 args from the pack1() and pack2() calls. John Thanks for the response, but what if I don't want the widgets to be able to shrink? Is that possible? Why isn't calling handler_block before calling set_position sufficient? -- Steve Yes but you have to set the default size of the window as large or larger than the required size of the largest pane. Your code doesn't set the window size so it starts up with the minimum required size to fit the paned widgets. Since the two separators can't line up because the panes are different sizes and because the panes can't shrink the set_position() calls fail and apparently trigger a resize calculation which trys to set the position and so on. Your choices are allow something to shrink or set a window size that will allow the separators to line up initially. Also you can add a detail to the notify signal connection that only signals when the position is changed - use notify::position and you can remove the gparamspec.name check in paneMoved(). John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Treeview: How to set Font Size in Column Titles?
darethehair wrote: Hello all! From the PyGTK docs, I know the various ways to change the font size in 'treeview' columns/cells, but they appear to only work on the column *data*, and not the column *titles*. The effect of this is that I can make my fonts (for example) smaller and get more rows in the screen, but the title font sizes do not change, and so it looks silly. Any tips? Try using a custom widget for the header using TreeViewColumn.set_widget() JOhn ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] TreeView selection issue
A minor nit. The cursor is not the same as the selection. To see the difference press Control-n. The cursor is identified by the outlined box. Of course it's usually the same as the selection. John Alan F wrote: Is there some reason why you are not using the TreeSelection changed signal to track the selction changes and update your display? In your case I assume that only one selection at a time is allowed so the changed signal would seem to be ideal. John Thanks John. Finally got it working. If anybodys interested, I've just created a program that displays the tags of mp3 files in a selected folder. It's quite basic as you have to enter path into script file. # # Start of File #!/usr/bin/env python # tag-tree.py import pygtk pygtk.require('2.0') import gtk import os import glob from mutagen.id3 import ID3, TPE2, TIT2, TPE1, TALB, TCOM, TDRC, TCON, TRCK, TPOS MUSIC_DIR = ENTER MUSIC FOLDER PATH HERE class tag_tree: # close the window and quit def delete_event(self, widget, event, data=None): gtk.main_quit() return False def add_data(self): os.chdir(MUSIC_DIR) file_list = glob.glob('*.mp3') first_time = True if len(file_list) == 0: print No mp3 files in folder else: file_list.sort() for x in file_list: curr_iter = self.liststore.append([x,x] ) if first_time == True: first_iter = curr_iter first_time = False return first_iter def change_details(self, widget, txt_area): #get data from highlighted selection treeselection = self.treeview.get_selection() (model, iter) = treeselection.get_selected() if iter != None : # Add audio data txt_buffer = gtk.TextBuffer() file_name = self.liststore.get_value(iter, 0) audio = ID3(file_name) if audio.has_key('TIT2'): txt_buffer.insert_at_cursor(Title: + unicode(audio[TIT2]) + '\n') if audio.has_key('TPE1'): txt_buffer.insert_at_cursor( Artist: + unicode(audio[TPE1]) + '\n') if audio.has_key('TCOM'): txt_buffer.insert_at_cursor(Composer: + unicode(audio[TCOM]) + '\n') if audio.has_key('TPE2'): txt_buffer.insert_at_cursor(AlbumArtist: + unicode(audio[TPE2]) + '\n') if audio.has_key('TALB'): txt_buffer.insert_at_cursor(Album: + unicode(audio[TALB]) + '\n') if audio.has_key('TCON'): txt_buffer.insert_at_cursor(Genre: + unicode(audio[TCON]) + '\n') if audio.has_key('TDRC'): txt_buffer.insert_at_cursor(Year: + unicode(audio[TDRC]) + '\n') if audio.has_key('TRCK'): txt_buffer.insert_at_cursor(Track num: + unicode(audio[TRCK]) + '\n') if audio.has_key('TPOS'): txt_buffer.insert_at_cursor(Disc num: + unicode(audio[TPOS]) + '\n') txt_area.set_buffer(txt_buffer) def __init__(self): # Create a new window self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.set_title(Tag Display) self.window.set_size_request(500, 200) self.window.connect(delete_event, self.delete_event) table1 = gtk.Table(1, 2, False) table1.set_row_spacings( 5) table1.set_col_spacings(5) self.window.add(table1) # create a ListStore with one string column to use as the model self.liststore = gtk.ListStore(str, str) first_iter = self.add_data() # create the TreeView using liststore self.treeview = gtk.TreeView(self.liststore) self.treeview.set_headers_visible(False) # create the TreeViewColumn to display the data self.tvcolumn = gtk.TreeViewColumn() # add tvcolumn to treeview self.treeview.append_column(self.tvcolumn) # create a CellRendererText to render the data self.cell = gtk.CellRendererText() # add the cell to the tvcolumn and allow it to expand self.tvcolumn.pack_start(self.cell, True) # set the cell text attribute to column 0 - retrieve text # from that column in treestore self.tvcolumn.add_attribute(self.cell, 'text', 0) # make it searchable self.treeview.set_search_column(0) # Allow drag and drop reordering of rows self.treeview.set_reorderable(False) # values colx, coly, roxx, rowy table1.attach(self.treeview, 0, 1, 0, 1) txt_area = gtk.TextView() txt_area.set_editable(False) table1.attach(txt_area, 1,2, 0, 1)
Re: [pygtk] Treeview/model: Problems with Expanding and Selecting Rows
darethehair wrote: Hello Folks! The PyGTK tutorial example named 'basictreeview.py' works fine for me. When I click on the 'expander' arrow for a row, it instantly expands to show the child rows under it. In my case, I am using a 'lazy treeview' to only populate the child rows as I need to do so -- mostly because of time, but also because I want to allow unlimited 'nesting'. My problem is two-fold: 1) When I use a 'row-expanded' signal detector, I have to click two or three times on the 'expander' arrow in order for the child rows to actually show up. In fact, out of desperation I have even added the following to my routine to 'force' the issue: self.treeview.expand_to_path(path) self.treeview.expand_row(path, True) 2) When I add a selection 'changed' signal, it works, but it 'gets in the way' of my 'row-expanded' detector i.e. even if I am very careful to click just the 'expand arrow' on a row, it triggers my 'changed' selection routine the first time I touch a row. I would appreciate any tips to produce the desired behavior! :) Connect to the test-expand-row signal and add the rows in the callback. You have to put a dummy child row to get the expander to show and replace it with the real children in the callback. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Treeview/model: Problems with Expanding and Selecting Rows
darethehair wrote: snip: I do not understand why my mouse clicks on the 'expansion' arrow is interpreted as an entire 'row selection' instead :( Bug in your program? On my system clicking the expander does not change the seslection. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] TreeView selection issue
Alan F wrote: Hi I am new to GTK programming. I want to create a program that displays the sub-folders of a main folder in a tree view format. Once I find the particular sub-folder , I want to be able to click on it to display the contents of that folder. When the contents of that folder is displayed, I want to click on any file to display the mp3 tags of that file. I have managed to get a program working that displays all the sub-folders of the main folder as a treeview. The problem is I am having trouble trying to get it to do the next step i.e. when I click on a sub-folder I want to display the contents of that folder. After googling around, I found a post that used a solution of adding a button event to the treeview. I put it in an example code below and it works but with a problem. Firstly, to describe the actions of the example code, I've created a treeeview that has 3 parents and 3 childs, when I click on a selection (either parent or child), the value of that selection is printed in the console. The problem is that when I click on any selection, nothing happens. When I click on it again, the value of that selection is displayed. When I click on another selection, the value of the previous selection is displayed. When I click on that selection again, the values are displayed. On clicking on any selection, the value of the previous one is displayed. I've put console print statements throughout the code and the contents are definately being displayed when I single click on selection. I can only think it is something to do with the lines treeselection = self.treeview.get_selection(), (model, iter) = treeselection.get_selected(). I've checked the API and in TreeSelection there is text that may have something to do my issue: One of the important things to remember when monitoring the selection of a view is that the changed signal is mostly a hint. That is, it may only emit one signal when a range of rows is selected. Additionally, it may on occasion emit a changed signal when nothing has happened (mostly as a result of programmers calling the |select_path|() file:///home/theman/documents/python/pygtkdoc/www.pygtk.org/docs/pygtk/class-gtktreeselection.html#method-gtktreeselection--select-path or |select_iter|() file:///home/theman/documents/python/pygtkdoc/www.pygtk.org/docs/pygtk/class-gtktreeselection.html#method-gtktreeselection--select-iter methods on an already selected row). I don't really know enough about GTK programming to understand where to start to look to fix this. Can someone please point me in the right direction? # ###Start of file #!/usr/bin/env python import pygtk pygtk.require('2.0') import gtk import os class BasicTreeViewExample: # close the window and quit def delete_event(self, widget, event, data=None): gtk.main_quit() return False def add_data(self): # we'll add some data now - 4 rows with 3 child rows each for parent in range(4): piter = self.treestore.append(None, ['parent %i' % parent, 'value %i' %parent]) #print this is path of parent + str(parent) #print self.treestore.get_path(piter) for child in range(3): citr = self.treestore.append(piter, ['parent %i child %i' % (parent, child, ), 'value %i' %parent]) #print this is path of parent + str(parent) + child + str(child) #print self.treestore.get_path(citr) def selectTest(self, widget, event): print This is event button print event.button # Mouse press confirmed ok if event.button == 1: #get data from highlighted selection treeselection = self.treeview.get_selection() (model, iter) = treeselection.get_selected() if iter != None : print this is path of selected print self.treestore.get_path(iter) print value or select store print self.treestore.get_value(iter, 0) print model.get_value(iter, 0) else: print no selection made def __init__(self): # Create a new window self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.set_title(Music Collection) self.window.set_size_request(300, 200) self.window.connect(delete_event, self.delete_event) # create a new scrolled window. scrolled_window = gtk.ScrolledWindow() scrolled_window.set_border_width(10) # the policy is one of POLICY AUTOMATIC, or POLICY_ALWAYS. # POLICY_AUTOMATIC will automatically decide whether you need # scrollbars, whereas POLICY_ALWAYS will always leave the
Re: [pygtk] TreeView/cell/signals
Alessandro Dentella wrote: ... the same problem, a different point of view... If I enter a CellRendererText in editing mode I can press return and the mode switched and signal 'edited'is emitted. Who is responsable for that? I guess is the editable as I can't imagine anything else... but how can I be sure? I mean is there a way to listen all signals and who is emitting them? Which is the signal emitted? What can I do from within the 'edited' callback to stop switching from editing mode? sandro The signals are described in the Reference Manual but sometimes can be hard to find. The devhelp application can help find them because it provides a search mode. If I understand your question I don't think that you can prevent the Entry that is used as the CellEditable for the CellRendererText from closing when activated. You can only prevent the edits from being applied which is the default. John John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Updating a TextBuffer line by line
Daniel Roesler wrote: Howdy again, I am running into a problem displaying stdout from a subprocess command. I have a loop that checks to see if the subprocess is still active, then reads a line in from stdout and sends it to the text buffer. However, I can't seem to get my text buffer to print except when the command ends. Obviously, I'm missing some logic behind how loops work with pygtk. Here's my code: --- command = subprocess.Popen(cmd, stdout=subprocess.PIPE) while command.poll() is None: line = command.stdout.readline() self.txtbuffer.insert_at_cursor(line) --- Any ideas on how to read stdout line by line with subprocesses? Don't use command.poll() rather use gobject.io_add_watch to register a callback when data is available on the stdout pipe or the pipe is closed. Something like: gobject.io_add_watch(command.stdout, gobject.IO-IN | gobject.IO_HUP, read_output) def read_output(source, condition): if condition == gobject.IO_IN: line = source.readline() if condition == gobject.IO_HUP: return False return True John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Updating a TextBuffer line by line
Daniel Roesler wrote: Ok, I tried that, but it's giving an error about the number of arguments sent to read_output. TypeError: display_details() takes exactly 2 arguments (3 given) Here's my code: -- gobject.io_add_watch(command.stdout, gobject.IO_IN | gobject.IO_HUP, self.read_output) def read_output(source, condition): if condition == gobject.IO_IN: line = source.readline() self.txtbuffer.insert_at_cursor(line) if condition == gobject.IO_HUP: self.txtbuffer.insert_at_cursor(Command finished.) return False return True -- Any ideas on why this is occurring? You passed io_add_watch a class method as the callback - the first arg of the classmethod must be self so prepend self to the method definition params: def read_output(self, source, condition): John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] TreeViewColumn sizing
The expand property of a TreeViewColumn is False by default. You have to set_expand(True) the first two columns in your TreeView. John Daniel Hernández Bahr wrote: this is the thing: def init_files(): for column in self.updates_view.get_columns(): self.updates_view.remove_column(column) headers = [_(New File),_(Old File), _(Revision)] index = 0 for header in headers[:3]: index += 1 column = gtk.TreeViewColumn(header) self.updates_view.append_column(column) cell = gtk.CellRendererText() column.pack_start(cell, True) column.add_attribute(cell, 'text', index) column.set_sort_column_id(index) column = gtk.TreeViewColumn(_(Edit)) self.updates_view.append_column(column) cell = gtk.CellRendererPixbuf() column.pack_start(cell) column.add_attribute(cell, 'stock_id', 4) column.set_name('edit_column') column.set_expand(False) selection = self.updates_view.get_selection() selection.set_mode(gtk.SELECTION_MULTIPLE) selection.connect('changed', self.on_files_selection_changed) - Original Message - From: John Stowers john.stowers.li...@gmail.com To: Daniel Hernández Bahr db...@estudiantes.uci.cu Cc: pygtk pygtk@daa.com.au Sent: Wednesday, January 14, 2009 4:29:07 PM (GMT-0500) Auto-Detected Subject: Re: [pygtk] TreeViewColumn sizing On Wed, 2009-01-14 at 16:34 -0500, Daniel Hernández Bahr wrote: Should, but won't .. Please provide your code so we may take a look Regards, John best regards .. - Original Message - From: Pietro Battiston too...@email.it To: pygtk pygtk@daa.com.au Sent: Wednesday, January 14, 2009 2:10:43 PM (GMT-0500) Auto-Detected Subject: Re: [pygtk] TreeViewColumn sizing Il giorno mer, 14/01/2009 alle 15.50 -0500, Daniel Hernández Bahr ha scritto: Hullo, everyone! my issue is, I have a TreeView with 4 Columns, and it is my interest that the last 2 should have the minimal size required (as the last one is a small pixbuf and the one before that a 4 digit number), and let the first two to get all the size they need (as they represent file paths). I have tried two set fixed sizes already for the small ones, but it doesn't work. column.set_expand(False) for the two small should do the job Pietro ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/ -- Daniel Hernández Bahr Universidad de las Ciencias Informáticas. ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/ ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Entry.connect_after('changed', ...) doesn't see updated cursor position
Yang Zhang wrote: Hi, I have a signal handler connected to an Entry's 'changed' signal, but it never sees the updated cursor position, only the previous cursor position. E.g., if I start with an empty Entry and then type 'a', Entry.get_text() returns 'a', but Entry.get_position() returns 0, not 1. I tried both .connect() and .connect_after(), but there doesn't seem to be any difference. How can I get the updated cursor position? Connect to the notify::cursor-position signal. This should work for your app. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Problem with Notebook
Frédéric wrote: On mercredi 24 décembre 2008, John Finlay wrote: I don't see how that would happen. I guess a small self-contained example would illustrate the problem. Here is a little example... I block switching to the Page 2, with your trick. The first time you select that page, the callback is called, but the page is not displayed. Good. But then, if you click again on that page, the callback is not called anymore, until you switch to another page first (or just click on the current selected one). It acts like if this page was selected, but not displayed. Also note that if you click the currnt page again, the callback is not called neither. But is change internal stuff, as it calls the callback when clicking on Page 2! The current page number hasn't changed so it seems that it remembers the last clicked tab. Sounds like a bug to me... Maybe. Might be a good idea to ask about this on the gtk mailing list. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Problem with Notebook - stop-emission doubts
Alessandro Dentella wrote: On Wed, Dec 24, 2008 at 01:22:49PM +0100, Gian Mario Tagliaretti wrote: On Wed, Dec 24, 2008 at 9:57 AM, Frédéric frederic.mantega...@gbiloba.org wrote: PS: BTW, where did you find the stop_emission() method? I can't retreive it in the doc... it a gobject method: http://library.gnome.org/devel/pygobject/stable/class-gobject.html#method-gobject--stop-emission following the docs I have several questions? 1. the explanation is exactly the same as for emit_stop_by_name: which is the difference? They are the same. The stop_emission() method stops the current emission of the signal specified by detailed_signal 2. current emission means the emission of the signal that is now handled? if this is the case, what's the need for specifying the name? A signal could be emitted within a signal emission. 3. How is it different from returning True? I tested it with:: b = gtk.Button(Press me) e = gtk.Entry() b.connect('clicked', self.on_clicked1) b.connect('clicked', self.on_clicked2) e.connect('key-press-event', self.on_key_press_event1) e.connect('key-press-event', self.on_key_press_event2) on_clicked2 cannot be inhibited returning True from on_clicked1 while on_key_press_event1 *can* be inhibited simply returning True. Both can be inhibited using stop_emission. Some signals provide an explicit means of stopping the signal emission using a return value from a handler. The clicked handler is not supposed to provide a return value so returning True does nothing. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Problem with Notebook
Frédéric wrote: On mercredi 24 décembre 2008, John Finlay wrote: Since you just want to stay on the same page (assuming you mean the currently displayed page) then you should be able to stop the emission of the 'switch-page' signal using: self.notebook.stop_emission('switch-page') which will prevent the page change. Ok, it works, thanks :) There is just a strange behaviour: once I have clicked on the blocked page and showed the warning, then if I click again on the same page, the 'switch-page' is not emitted anymore. I have to click on the current page, and then click again on the other one. It seems that the internal page_num var. is set to the new page. Blocking the event just prevents to visualy switch to that page, but internally, PyGTK thinks that he is on that page... I tried to use set_current_page(), but it does not change anything. I don't see how that would happen. I guess a small self-contained example would illustrate the problem. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Problem with Notebook
Frédéric wrote: Hello, I use a Notebook widget. I added the following callback to the 'switch-page' signal: def __onNoteBookSwitchedPage(self, widget, page, page_num): if page_num == 0 and self._model.camera.lens.type_ == 'fisheye': controller = WarningMessageController(_(Warning), _(Can't set shooting mode)) controller.run() self.notebook.set_current_page(1) # Does not work!!! else: if page_num == 0: self._model.mode = 'mosaic' else: self._model.mode = 'preset' As you can see, depending of a config. parameter (self._model.camera.lens.type_), I show a warning saying that the selected TAB can't be used. I would like to stay on the current tab, but as soon as the warning is closed, the selected tab is shown; the self.notebook.set_current_page(1) call does not seem to work. Why ? If I change some widgets, here, it works; why not the Notebook? Thanks, Since you just want to stay on the same page (assuming you mean the currently displayed page) then you should be able to stop the emission of the 'switch-page' signal using: self.notebook.stop_emission('switch-page') which will prevent the page change. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] hide on delete_event()
Frédéric wrote: Le 5/12/2008, Christian Becke christianbe...@web.de a écrit: Peyman schrieb: I have tried every variation, but I will try it once again...Nope, still doesn't work. I tried returning: True, False, 0, 1, gtk.TRUE, and gtk.FALSE This works for me (python 2.5.2, pygtk 2.13.0, gtk 2.14.4): I'm trying to block the delete event when hitting the X box of a dialog. It seems that all documentation related to that point refer to gtk.Window widgets, and it works fine. But if the main window opens a gtk.Dialog, then, it is impossible to avoid this dialog to be destroyed when hitting its X box: even if event-delete callback returns True, the signal is propagated, and the destroy signal is emited. Why? Is there a way to avoid that? Frederic, Could you create a small, self-contained program to illustrate the problem you are having? John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] hide on delete_event()
Frédéric wrote: Le 19/12/2008, John Finlay fin...@moeraki.com a écrit: Frédéric wrote: It seems that all documentation related to that point refer to gtk.Window widgets, and it works fine. But if the main window opens a gtk.Dialog, then, it is impossible to avoid this dialog to be destroyed when hitting its X box: even if event-delete callback returns True, the signal is propagated, and the destroy signal is emited. Could you create a small, self-contained program to illustrate the problem you are having? Sure: import gtk def delete(widget, event): print delete() return True # Should not propagate delete-event def destroy(widget): print destroy() return True def clicked(widget): print clicked() dialog = gtk.Dialog(My dialog, win, gtk.DIALOG_MODAL, (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) dialog.set_size_request(200, 50) dialog.show() dialog.connect(delete-event, delete) dialog.connect(destroy, destroy) You probably mean to connect to the destroy-event signal in the above though it's not likely that you need to handle it. dialog.run() dialog.destroy() The above line is what is destroying your dialog - remove it. win = gtk.Window() win.set_size_request(200, 50) button = gtk.Button(Open dialog...) button.connect(clicked, clicked) win.add(button) win.connect(delete-event, gtk.main_quit) win.show_all() gtk.main() You are mixing the two ways of using a dialog - show() and run(). You should only use one of these ways. If you use the show() method then add a call in delete() to hide() the dialog when you are finished the delete processing. If you use the run() method then you don't need to handle the delete-event and you should retrieve the return response from the run() method to figure out what to do (you also don't need to make the dialog modal since run() blocks the UI until it returns). John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] hide on delete_event()
Frédéric wrote: On vendredi 19 décembre 2008, John Finlay wrote: dialog.connect(destroy, destroy) You probably mean to connect to the destroy-event signal in the above though it's not likely that you need to handle it. The event is called 'delete', and not 'delete-event'... Check the docs for the gtk.Widget to see the signals: http://pygtk.org/docs/pygtk/class-gtkwidget.html#signal-prototypes-gtkwidget Both delete-event and destroy-event are Widget signals. destroy is a gtk.Object signal. dialog.destroy() The above line is what is destroying your dialog - remove it. Yes, but I need to destroy it once I leave it (but only using a special close button, not shown here)... You are mixing the two ways of using a dialog - show() and run(). You should only use one of these ways. If you use the show() method then add a call in delete() to hide() the dialog when you are finished the delete processing. If you use the run() method then you don't need to handle the delete-event and you should retrieve the return response from the run() method to figure out what to do (you also don't need to make the dialog modal since run() blocks the UI until it returns). I forgot to remove the show() call from my previous tests. But it does not work neither. As soon as I click on the X dialog, the run() returns. This is not what I want. I really want to avoid the dialog to be ended; I want to stay in its loop... Then don't use run(), connect a callback to the response signal and put all the dialog processing in that. You still need to handle the delete-event signal to prevent the dialog closing and put the destroy() in the response signal handler assuming the close button is part of the dialog; if not then put it in the button's clicked handler. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] hide on delete_event()
Frédéric wrote: On vendredi 19 décembre 2008, Frédéric wrote: Then don't use run(), connect a callback to the response signal and put all the dialog processing in that. You still need to handle the delete-event signal to prevent the dialog closing and put the destroy() in the response signal handler assuming the close button is part of the dialog; if not then put it in the button's clicked handler. Ok, I got it! Things work fine without the run() call... A last question: is it possible to simulate the run() call, to get a response id, as I need to make different things depending which button closed the dialog? That's what connecting a callback to the response signal allows you to do. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Unable to run your tutorial examples
A.K.Karthikeyan wrote: Hello PyGTK people, I have tried to run *pygtkconsole.py* http://www.pygtk.org/pygtk2tutorial/examples/pygtkconsole.py and *gpython.py* http://www.pygtk.org/pygtk2tutorial/examples/gpython.py found in http://www.pygtk.org/pygtk2tutorial/ch-Introduction.html on my Ubuntu 8.04, but I got the following error message http://www.pygtk.org/pygtk2tutorial/examples/gpython.py Traceback (most recent call last): File pygtkconsole.py, line 14, in module import gtk File /media/sda7/python/py/gtk.py, line 2 SyntaxError: Non-ASCII character '\xe2' in file /media/sda7/python/py/gtk.py on line 2, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details and Traceback (most recent call last): File gpython.py, line 16, in module import gtk, gobject File /media/sda7/python/py/gtk.py, line 2 SyntaxError: Non-ASCII character '\xe2' in file /media/sda7/python/py/gtk.py on line 2, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details I am clueless what to even after visiting http://www.python.org/peps/pep-0263.html as there are no non-ASCII characters in program. Can any one help me? The problem is the file /media/sda7/python/py/gtk.py that interferes with the importing of the gtk module. If possible you should rename this file or make sure it isn't in the import path of python. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] TreeView - Making whole row colored, Again
Kevin wrote: Greetings, I came across an old message in the archives at http://www.mail-archive.com/pygtk@daa.com.au/msg15480.html , which sounds a lot like I want to do (though I want to work with background colors rather than foreground colors). But I was thinking: couldn't I just add a column to my model containing the color values I want for each row, and use values of #ff for all the rows I wanted to leave white? The problem is that without a column of booleans, I can't seem to set the background-set property of the columns. Specifically, I'm using: leftjust = gtk.CellRendererText() column = gtk.TreeViewColumn('Filename', leftjust, text=COLUMN_FILENAME) column.set_sort_column_id(COLUMN_FILENAME) treeview.append_column(column) column.add_attribute(leftjust, 'background-set', True) remove the above line. column.add_attribute(leftjust, 'background', COLUMN_FLAG) but when I run the program, I keep getting Warning: unable to set property `background-set' of type `gboolean' from value of type `gchararray' Is there really no way of doing this without creating another column of booleans? You don't have to set background-set - it's set automatically when background is set. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] gtk.Image write text inside Image
Luis Gonzalez wrote: Hi to all , I have a gtk.Image load from file. I want to write text inside this Image and then write to a file (jpg or png). I try to do use gtk.gdk.Pixbuf but to write text , draw lines , draw rectangle I need a drawable object like gtk.gdk.Pixmap. How can i do this? If you want to read an image from a file draw on it and write it back you don't need to use a gtk.Image - that's only used for displaying an image. In fact you don't need PyGTK you can use cairo or PIL to do the job. If however you are using PyGTK anyway or are also going to use the image within PyGTK, the basic procedure is: - load a pixbuf with the image from a file using gtk.gdk.pixbuf_new_from_file() - create a pixmap of the same size using gtk.gdk.Pixmap() or gtk.gdk.Pixbuf.render_pixmap_and_mask() - draw the pixbuf image on the pixmap using gtk.gdk.Drawable.draw_pixbuf() (not needed if render_pixmap_and_mask was used) - draw your text, lines, etc. in the pixmap using either the cairo or gtk methods - transfer the pixmap to the pixbuf using gtk.gdk.Pixbuf.get_from_drawable() - write out the image using gtk.gdk.Pixbuf.save() John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] inhibate menu of window manager
awalter1 wrote: Thanks for your help I take a look to the set_functions() method and I've found the constants as gtk.gdk.FUNC_CLOSE that allows the window to be closeable. In fact I don't know how to allow the window to be NOT closeable and it seems that all functions (minimize, close, move ...) are set by default. I have found also a function set_deletable that should be adapted to my needs, but I'm not using the right pygtk version. If you set the functions and don't include the gtk.gdk.FUNC_CLOSE that tells the WM that you don't want to display the close button in the window frame. John Finlay wrote: awalter1 wrote: Hello, In my application python/gtk, I want to inhibate the item close from the standard menu available in all windows (bottom up of the window) and that allows actions as : minimize, maximise, ... close. If it is not possible to do that, which signal may I connect to be wake up ? I've found the signal delete-event to catch the close action, but it is required to connect it for each windows that is a little bit heavy for my Application. Thanks for your help Try the gtk.gdk.Window.set_functions() method to see if that works with your window manager. Not all window managers will honor the request. John. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/ ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] spinbutton set value and signal
Frédéric wrote: On mercredi 05 novembre 2008, Frédéric wrote: Is there a way to set the value of a spinbutton without having its 'value-changed' signal emitted? I mean set the value from the code, not from the GUI... You could save the handler id and use handler_block() and handler_unblock() around the code that sets the value to prevent the handler from running. Other handlers connected to the signal will still run though. Otherwise stop_emission should prevent all handlers from being called. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] pygtk, drawing area
Tomáš Dohnálek wrote: Hello, i have some trouble with drawing area. I am actually not able to configure colours of lines and other object. self.gc.set_foreground(gtk.gdk.Color(1,1,6)) widget.window.draw_rectangle(self.gc, True, x*70, y*70, 70, 70) I thought that this will work fine, but the line is black. You need to allocate the color. see: http://faq.pygtk.org/index.py?req=showfile=faq04.008.htp http://faq.pygtk.org/index.py?req=showfile=faq04.008.htp John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Adding progressbar into a liststore
Timo wrote: Hello, I want to make some sort of downloadmanager like Firefox has, but not that advanced. Just a window that adds a progressbar (and maybe a label) for each download. But I already get stuck by adding a progressbar into the liststore. This is what I have: You could use set_cell_data_func() to register a function that will provide the text data for display like: liststore = gtk.ListStore(object) renderer = gtk.CellRendererText() column = gtk.TreeViewColumn(Downloads,renderer, text=0) def func(column, cell, model, iter, func_data): # create some text string to display cell.set_property('text', string) return column = gtk.TreeViewColumn(Downloads,renderer) column.set_cell_data_func(renderer, func, func_data) treeview.set_model(self.liststore) treeview.append_column(column) liststore.append([gtk.ProgressBar]) Then I get this error: Warning: unable to set property `text' of type `gchararray' from value of type `PyObject' There is a row in the treeview, cause I can select one line, but nothing is in it. ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Two models: can I have only one?
José Luis wrote: Hello to all! First, I explain my situation: I have one treeview and one combobox on my GUI. The treeview model contains objects (it is a ListStore(object)). The ComboBox model has only strings (ListStore(str)). My problem is that the information represented by the second model is a subset of the informationon the treeview model. Is one method that I need to implement on my treeview model objects to make it representable by the combobox? You could use a TreeModelFilter to get what you wan. Seet: http://pygtk.org/pygtk2tutorial/sec-TreeModelSortAndTreeModelFilter.html#sec-TreeModelFilter http://pygtk.org/docs/pygtk/class-gtktreemodelfilter.html John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] How can I suppress redraw of a gtk.ScrolledWindow and children until I'm done changing stuff?
Joel Hedlund wrote: Hi all! I've got a large widget (W) in an alignment in a viewport in a small scrolledwindow (S). S overrides the do_scroll_event method, so that ctrl-scroll zooms by doing W.set_size_request(). Since what's under the mouse pointer should stay put and not be scrolled off the screen as W resizes, the values on the adjustments on S need to be changed to compensate. Now, my problem. GTK redraws after W.set_size_request() and after S.props.vadjustment.set_value(), making zooming a very flickery and migraine inducing experience that I don't want to subject my users to. So, how can I suppress redraws on a gtk.ScrolledWindow and its children until I'm done changing stuff? Try: http://pygtk.org/docs/pygtk/class-gdkwindow.html#method-gdkwindow--freeze-updates John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] returning window.handle from drawingarea
Patty Ackermann wrote: hi, I have initialized a gtk.DrawingArea() object and am trying to return window.handle, but it's always returning None. Anyone have any ideas? If you mean that the drawingarea.window attribute is None it's usually because the drawingarea hasn't been realized so call show() or realize() before accessing the window attribure. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Filechooserbutton callback
Frédéric wrote: On mercredi 22 octobre 2008, John Finlay wrote: AFAICT the FileChooserButton is a replacement for using an entry/label and associated file browser button. It only allows selecting one existing file or folder and displays the name of the selected file in the button label. The most likely application is to use the FCB in a dialog where a file or folder is to be selected (along with other info) and finally another action (e.g. clicking an OK button) is used to retrieve the currently selected file or folder and perform some operations. I don't think it works very well if you want to perform some actions immediately after selecting a file or folder unless you pass in a FileChooserDialog and add the buttons and handle its responses and signals. You can use the selection-changed signal with the FCB to be notified when a different file has been selected and the dialog is closed. Using the selection-changed signal does not work; it is never emited. Works for me on: Python 2.5.1, PyGTK 2.12.0 (Gtk+ 2.12.5) Anyway, as you suggested, I just get the value when the entire config dialog is closed, and it works fine... except under Windows! get_current_folder() always returns the first dir I set in the chooser, with set_current_folder() method. Note that it works fine under linux and Nokia/maemo. ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Filechooserbutton callback
Frédéric wrote: On jeudi 23 octobre 2008, John Finlay wrote: Using the selection-changed signal does not work; it is never emited. Works for me on: Python 2.5.1, PyGTK 2.12.0 (Gtk+ 2.12.5) Wich plateform? Fedora 8 and Ubuntu Hardy ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Filechooserbutton callback
Frédéric wrote: Hello, I added a Filechooserbutton in my GUI (using glade-3). When I clik on the button, it opens the file dialog, and I can choose a file. But how can I be notified that the user has used that button? What signal to bind, so I can retreive what was the user action (Accept/Cancel), and the file he chosed? AFAICT the FileChooserButton is a replacement for using an entry/label and associated file browser button. It only allows selecting one existing file or folder and displays the name of the selected file in the button label. The most likely application is to use the FCB in a dialog where a file or folder is to be selected (along with other info) and finally another action (e.g. clicking an OK button) is used to retrieve the currently selected file or folder and perform some operations. I don't think it works very well if you want to perform some actions immediately after selecting a file or folder unless you pass in a FileChooserDialog and add the buttons and handle its responses and signals. You can use the selection-changed signal with the FCB to be notified when a different file has been selected and the dialog is closed. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] How to do_size_allocate properly in a gtk.Viewport subclass?
Joel Hedlund wrote: Hi! I was directed here from comp.lang.python, so sorry for the cross-post. I've also raised this issue on #pygtk and #gtk+ but with no luck. I haven't been able to solve this even with aid of google, the pygtk reference and the gtk C source, so pretty please help? I'm making an application that you can think of as an image viewer. I want to display a widget in a gtk.Viewport. The widget can have any size from tiny to humungous. I don't want the viewport to ever give the widget a larger size allocation than requested, and I don't want the viewport to ever resize to accomodate a large widget. It should rather leave grey areas around the widget/show only a portion of the widget. To do this I have subclassed gtk.Viewport (MyViewport) and overrided the do_size_allocate method: def do_size_allocate(self, allocation): self.allocation = allocation child_req = self.child.get_child_requisition() child_alloc = gtk.gdk.Rectangle(0, 0, *child_req) self.child.size_allocate(child_alloc) self.props.hadjustment.update(allocation.width, child_alloc.width) self.props.vadjustment.update(allocation.height, child_alloc.height) if self.flags() gtk.REALIZED: self.window.move_resize(*self.allocation) self.child.window() When I add a very large widget (a gtk.DrawingArea) to MyViewport only the originally visible portion of the widget is redrawn when I resize the window using the mouse, and the grey area around widget gets littered with grey lines that are not redrawn if you minimize and restore the window. I assume this comes from that the proper gdk windows haven't been updated, and that the grey lines are remnants of old Viewport borders. In gtk_viewport_size_allocate in gtkviewport.c, gdk_window_move_resize is called on three gdk windows: viewport-window, viewport-view_window and viewport-bin_window, but in pygtk I only have gtk.Viewport.window. I assume that this is the problem? If so, how can I fix this? Or is there something else that I have overlooked? And another relevant question: am I overcomplicating this? Is there some kind of flag that I could set on a vanilla viewport to accomplish this? I'm not sure what behavior you are looking for so I'll assume that you have one widget (e.g. Image) that you want to put inside a Viewport in a ScrolledWindow in a Window. I'll also assume that you want the widget to float in the center of the Window when the widget is smaller than the Window. Finally I assume that you want the widget to be partially displayed but scrollable within the window when the widget is larger than the Window. If these assumptions are wrong that ignore the following suggestion. If so then I suggest that you put the widget inside a Table of size 1,1 and attach it with EXPAND but not FILL. Put the table in a Viewport inside a ScrolledWindow inside a Window. This should keep the widget to a fixed size within the Window. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Possible error in the reference manual
Eric S. Raymond wrote: I think I've spotted an error in the Reference: --- pygtk-gobject.xml (revision 3046) +++ pygtk-gobject.xml (working copy) @@ -513,7 +513,7 @@ methodnameconnect_object/methodname() method. For example, a call with a function handler:/para programlisting - handler_id = object(signal_name, handler, gobject) + handler_id = connect_object(signal_name, handler, gobject) /programlisting parawill cause the parameterhandler/parameter to be invoked as:/para If this is not an error, it need more explanation than it presently has. I think you're looking at the defunct version of the pygobject docs which used to be part of the pygtk docs. Pygobject has it's own source tree and its docs live there. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] Is the pygtk tutorial still being maintained?
Eric S. Raymond wrote: In the course of a recent project, I found myself consultung the pygtk tutorial and developed some updates abnd additions for it. I mailed one to John Findlay but received no response. Oops. Your email got buried until you reminded me of it. I have written documentation and an example program for the MessageDialog widget. Thanks. I have the following list of issues about the tutorial: 1. What is private tooltip data and how is it used. 2. The Toolbar request to add space is deprected. What should replace it? 3. Entire toobar section should be rewritten for new API. Yes there are a lot of sections of the tutorial that have become out-of-date and should be rewritten. I lost interest in maintaining the tutorial (and time) a couple of years ago due to other commitments, etc. I hope someone will volunteer to take up the challenge. 4. How can I set a single dimension on a widget to be fixed in the presence of resizes? I don't know of any easy way to do this. 5. What, exactly triggers the appearance of scrollbars with automatic policy? If I understand your question correctly I've assumed that when the window became smaller than the widget required allocation in a direction that the scrollbar would appear. I note that the last update was in 2006. Is this document still being maintained? Are the sources in a version-control system that I might get write access to? I think Gian answered this. You'd have to get checkin access (ssh) for svn on the gnone servers. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] setting a filter for gtk.FontSelection
Le Roux Bodenstein wrote: This feature was removed from gtk after 2.2. There should be a note similar to the note in the description of the FontSelectionDialog documentation. Aah thanks. So it is a bug in the documentation? I don't mind just using a normal widget and populating it with the right fonts. Any idea how to list and filter fonts so that you get all the monospace fonts on the system? I can't find it in the documentation. Retrieve the pango context from the main widget and then get the list of the font families in the pango context and filter them for monospace fonts e.g.: context = gtk.Window().get_pango_context() monofonts = [fam for fam in context.list_families() if fam.is_monospace()] John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] CellRendererCombo Question
Andrea Caminiti wrote: hi john: is there a way to do that wrapping but for rows in the combobox? becuase i have a combobox with 8 elements (image + label) and so the pop down list is very large. it would be great to do that. I must have missed a message. Is the problem that you have a combobox but the list is too long? Amd each row has 8 cellrenderers in it? John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Pygtk does not play nicely with speech-dispatcher
James Simmons wrote: Michael, Thanks for the tip! It was a big help. I put gtk.gdk.threads_init() in the __init__ method of my program and I did get callbacks. It looks like I didn't get callbacks for every word, but Pygtk seems to not be the problem anymore. Thanks again, The problem is that gtk and by extension pygtk has an event loop, and the python speechd api has implemented its own event loop within a thread. The speechd protocol is synchronous and sounds similar to RPCs. This event loop conflict was in general a problem with RPC programming with GUIs. The best solution is to integrate the two event loops using io_add_watch but that would entail throwing away the python speechd api and you would not have to use threads. This is the course I would take if I was doing your project. If you want to use the speechd python api you have to make your pygtk program threaded and that is more than just calling threads_init. Others on this list can point you to a list of best practices for threading in pygtk. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] liststore (ComboBoxEntry) alignment (justify)
Andrea Caminiti wrote: - Original Message From: Andrea Caminiti [EMAIL PROTECTED] To: John Finlay [EMAIL PROTECTED] Sent: Wednesday, April 23, 2008 9:16:24 AM Subject: Re: [pygtk] liststore (ComboBoxEntry) alignment (justify) Andrea Caminiti wrote: hi john: i was trying to use the code you just posted to to have a combobox with images and it's labels (text), only, no text entry needed. but i got some warnings. the code i used: def combo(self): #lists = self.list combobox = gtk.ComboBox() list = gtk.ListStore(gtk.gdk.Pixbuf, str) px = gtk.CellRendererPixbuf() text = gtk.CellRendererText() combobox.pack_start(px, True) combobox.pack_start(text, True) combobox.add_attribute(px, pixbuf, 0) combobox.add_attribute(text, text, 1) combobox.pack_end(text, True) you seem to be adding this twice. I think that's what the error message is about. You are adding the cellrenderertext text to the combobox twice - once in the pack_start and once in the pack_end. You can only add it once. Remove the line containing pack_end. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] shrink property of gtk.Paned
Geoff Bache wrote: Hi all, Is there any way to set up gtk.Paned such that automatic shrinking on resize never occurs, but shrinking by manually dragging the separator is still allowed? As far as I can see setting shrink=False prevents both from occurring. If I understand your situation the default behavior should do this i.e. pane1 should have resize=False and pane2, resize=True which should allow resizing to apply all additional space to pane2 and none to pane1. A short example would help. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] liststore (ComboBoxEntry) alignment (justify)
Andrea Caminiti wrote: hi john: i was trying to use the code you just posted to to have a combobox with images and it's labels (text), only, no text entry needed. but i got some warnings. the code i used: def combo(self): #lists = self.list combobox = gtk.ComboBox() list = gtk.ListStore(gtk.gdk.Pixbuf, str) px = gtk.CellRendererPixbuf() text = gtk.CellRendererText() combobox.pack_start(px, True) combobox.pack_start(text, True) combobox.add_attribute(px, pixbuf, 0) combobox.add_attribute(text, text, 1) combobox.pack_end(text, True) you seem to be adding this twice. I think that's what the error message is about. #for n in range (8): #numb =+ 1 pics = gtk.gdk.pixbuf_new_from_file('c:\\images\\bumps\\NE_to_SW_LowerTrace.jpg')#dicts.images['b1']) list.append((pics, 'fucking shit'))#dicts.names['b1']) python warnings: dgc-gui.py:71: GtkWarning: gtk_cell_view_cell_layout_pack_end: assertion `!gtk_c ell_view_get_cell_info (cellview, renderer)' failed combobox.pack_end(text, True) dgc-gui.py:71: GtkWarning: gtk_tree_view_column_cell_layout_pack_end: assertion `! gtk_tree_view_column_get_cell_info (column, cell)' failed combobox.pack_end(text, True) dgc-gui.py:94: GtkWarning: gtk_cell_view_cell_layout_pack_end: assertion `!gtk_c ell_view_get_cell_info (cellview, renderer)' failed combobox.set_model(list) dgc-gui.py:278: GtkWarning: gtk_tree_view_column_cell_layout_pack_end: assertion `! gtk_tree_view_column_get_cell_info (column, cell)' failed window.show() and on the other hand. as you can see, i was trying to use a dictionary in a class to get the name and path for the images. but seem that doesn't work. is there any way to do it?? or i need to write down each path and label for each image... What was the error message when you tried this, if any? John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Getting widget visibility
Mitko Haralanov wrote: What is the best way to get whether a widget is visible or not? According to the documentation, gtk.Widget has the 'visible' property which is Read-Write. However, gtk.Frame for example does not seem to inherit that property of gtk.Widget. It does inherit the visible property - what makes you think it doesn't? John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] TreeView and CellRendererCombo - MS Access-like form behaviour
Stéphane Brunet wrote: John Finlay a écrit : Stéphane Brunet wrote: Hi, btw, thank you John Finlay for the answer on my last question. In my quest of a GUI interfacing my small database application (I did try OpenOffice Base and went mad after one hour :S ) I would like to copy some behaviour of MS Access in my forms. Say I have two (SQL) tables with two fields and one relation between the two: |Table1| |Table2| | Field1 (int) || Field1 (int) | | Field2 (str) | | Field2 (str) | Now in my PyGTK form of Table1 (a TreeView), when I display the Field1 in the first column, I would like to have a ComboBox which displays the text associated to the integer value of Table2 (i.e. Table2.Field2) rather than the value directly. However, I still want it stored as an integer in Table1.Field1. How would you do this in an elegant manner ? Do I have to create my own CellRenderer more generic than a CellRendererCombo ? How do you want the db info displayed in the treeview? I think of actually displaying the content of Table1 with Field1 in the first column and Field2 in a second column. However, Field1 wouldn't be displayed as an integer but as a string coming from Table2. In order to modify the content of Field1, I would like the user to select a string (of Table2.Field2) in a CellRendererCombo rather than an integer. Are you planning on inserting the table info into a liststore or generating it on the fly? I thought of using two separate ListStore to store the content of each table. I don't know if it is the best way but I want to alter the information in the DB only when the user has finished his modifications in the GUI. To set the value displayed in the first column you could use set_cell_data_func and then set the text in the associated function using the table1 field1 value to select the table2 field2 value. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Checkbutton alignment
Joaquim Rocha wrote: Hi all, I got a checkbutton with a large label which is being wrapped into a few lines. Due to the height of the label, the checkbutton aligns vertically ending up set on the center of its space. Is there a way I can set the vertical alignment of the checkbutton so it remains in the top of its space if its label is too big (has many lines)? Here's an example. As you can see when you run the code, the checkbutton stays aligned vertically to the center of its space. Can anyone help? thanks #!/usr/bin/env python import pygtk pygtk.require('2.0') import gtk class Base: def __init__(self): self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.show() self.checkbox = gtk.CheckButton(lalalaaskjansnajksansjkasnjkansajksnajksnajnsajkns jkasna\najnsajksnaksnanjksajksnas\njkabnsjkansjkan as\najibsajksa) self.window.add(self.checkbox) self.checkbox.show() def main(self): gtk.main() if __name__ == __main__: base = Base() base.main() Screenshots: Here's what I got: http://neei.uevora.pt/~jay/ssGTKProblem/ss.png http://neei.uevora.pt/%7Ejay/ssGTKProblem/ss.png Here's what I want (GIMP helped me on this): http://neei.uevora.pt/~jay/ssGTKProblem/ss1.png http://neei.uevora.pt/%7Ejay/ssGTKProblem/ss1.png This is the only way using the standard checkbutton. I suppose you could subclass checkbutton and set its do_draw_indicator method to change the behavior. John ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/