[pygtk] Re: segfault when using gtk.glade.set_custom_handler() on windows
Johan Dahlin <[EMAIL PROTECTED]> writes: > Can you put this in bugzilla? > It would be great if you can trim down the test case even further, not > having a single unnecessary line usually helps us to track the bug down. filed as bug no. 342270 (http://bugzilla.gnome.org/show_bug.cgi?id=342270) I filed it on the pygtk component, even though I'm not sure it is a bug in pygtk. After all, it might be a bug in the installers (or the way they are compiled). Sorry I couldn't figure out how to include the glade XML in the .py file, (gtk.glade.XML doesn't seem to have a "create from XML string" option or at least I didn't find one). And also sorry for creating 3 mails for one bugreport, couldn't figure out how to attach files to the original bugreport, or how to attach two files at once. -- Abel Daniel ___ 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/
[pygtk] segfault when using gtk.glade.set_custom_handler() on windows
Hi! I'm trying to create a windows installer for a small app that uses python + pygtk + gtk with the 'py2exe + innosetup' method. For that I first have to get the app working with hand-installed python + pygtk + gtk, of course (so that I can run py2exe and copy the necessary dll-s). I installed python-2.4.3.msi from python.org, pygtk-2.8.6-1.win32-py2.4.exe from http://www.pcpm.ucl.ac.be/~gustin/win32_ports/ and gtk-win32-2.8.14-rc1 from http://gladewin32.sourceforge.net/ (I'm using windows 2000 as an OS) Small 'Helloworld' apps work, but I get a segfault when calling gtk.glade.set_custom_handler(). Attached is a small example which segfaults. I also tried to use the gtk installer from http://gimp-win.sourceforge.net/stable.html (version gtk+-2.8.9-setup-1.zip) instead of the ones from gladewin32, but in that case even 'helloworld' apps crash with a 'libglib.dll not found' error message. (where is the version, etc.) such a dll file is installed by the gimp-win installer to a directory that is on the PATH, so I think that the pygtk bindings should be able to find it. Any ideas what else should be set? I guess the segfaults when calling gtk.glade.set_custom_handler() are due to some internal mismatch (perhaps because python and gtk where compiled with different compilers?). But the above should work (as that is the "recommended way" as far as I could see). And I bet that _some_ people have installed python + pygtk + gtk with basically the same method. Which exact installers and versions have you used? (I would like to avoid having to compile anything, if at all possible. Using older versions would be acceptable, however.) Thanks in advance, Abel Daniel -- #!/usr/bin/env python # originally from a tutorial which was: #Licence: GPLv2.0 #Copyright: Dave Aitel import sys import pygtk #tell pyGTK, if possible, that we want GTKv2 pygtk.require("2.0") import gtk import gtk.glade import gobject def insert_row(model,parent,firstcolumn,secondcolumn): myiter=model.insert_after(parent,None) model.set_value(myiter,0,firstcolumn) model.set_value(myiter,1,secondcolumn) return myiter class appgui: def __init__(self): """ In this init we are going to display the main serverinfo window """ gladefile="demogtk.glade" windowname="serverinfo" print "this is where the segfault happens:" gtk.glade.set_custom_handler(self.custom_maker) print "we wont reach this" self.wTree=gtk.glade.XML (gladefile,windowname) dic = { "on_button1_clicked" : self.button1_clicked, "on_serverinfo_destroy" : (gtk.main_quit)} self.wTree.signal_autoconnect (dic) #CALLLBACKS def button1_clicked(self,widget): print "button clicked" def custom_maker(self, *args, **kw_args): print args, kw_args l = gtk.Label('Foo') l.show() return l app=appgui() gtk.main() -- where demogtk.glade is: -- http://glade.gnome.org/glade-2.0.dtd";> True Server Info GTK_WINDOW_TOPLEVEL GTK_WIN_POS_NONE False True False True False 0 True True GO! True GTK_RELIEF_NORMAL 0 False False True make_custom 0 0 Mon, 01 May 2006 10:08:53 GMT 0 False False -- ___ 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/
[pygtk] Multiple selection in treeview, was: Re: CellRendererText doesn't have clicked signal now what?
Thomas Mills Hinkle writes: > An additional query -- does anyone know if it's possible to select and > arbitrary range of a treeview, a la spreadsheets? I'd like to let the > user, for example, select four rows of one column so that I could > offer e.g. a "fill down" action. Sure. You have to enable "multiple selection mode" by calling treeview.get_selection().set_mode(gtk.SELECTION_MULTIPLE) After that, the user can use the usual Shift + click and Ctrl + click to select multiple rows. ___ 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/
[pygtk] gnome-canvas demo (partially) ported to python
As an exercise, I converted about half of the canvas-demo (from libgnomecanvas) to python. The tarball is at: http://abeld.web.elte.hu/canvas-demo/canvas-demo.tar.gz -- Abel Daniel ___ 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/
[pygtk] popup menu when multiple selection is in use in TreeView
The FAQ entry 13.17 on popup menus in TreeViews (http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq13.017.htp) has the unfortunate feature that it forces the selection to be the row that is clicked. (The line "treeview.set_cursor( path, col, 0)" ) This means that if multiple selection is allowed in the Treeview, and one selects multiple lines then right-clicks, the previous selection is lost. Obviously this is not the right thing to do as other programs in this situation change the selection as if a normal mouseclick with the same modifier keys would have been pressed. (So if the ctrl is pressed, they add that row, if shift is pressed, they select the rows between the two clicks, etc.) How should I implement that? The current version works if no modifier-keys are pressed. Handling ctrl correctly is pretty easy. The bigger problem is shift. It seems to me that the accepted meaning of shift-click in a list is "select all rows between this and the place of last click". How could I get the place of the last event? Would it be easier if I would simply generate a fake left-click event with the right modifier keys? How could I do this? Thanks in advance, Abel Daniel ___ 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/
[pygtk] What is gtk.CellEditable usefull for?
According to http://www.mail-archive.com/[EMAIL PROTECTED]/msg08337.html CellEditable can't be used to implement an editable cellrenderer in python. However, there _is_ a gtk.CellEditable in pygtk: http://www.pygtk.org/pygtk2reference/class-gtkcelleditable.html If it can't be used for editable cells, what is this gtk.CellEditable class usefull for? Are there any examples of it's usage?[1] Shouldn't the class's intended purpose be noted in the docs? (Especially the fact that it can't yet be used for the most obvious task ) -- Abel Daniel [1] or the usage of other interfaces, for that matter (like gtk.CellLayout) ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] inconsistency in treeview dnd behaviour in a certain case
I have a 'feature' I discovered and can't decide whether to file a bug, or a faq entry or what. Make a TreeView which has some rows, but there is space at the end where there are no rows (i.e. the window/scrolledwindow is bigger than the TreeView). Enable drag&drop. Drag a row so that it would be dropped on the empty space at the end. Notice that there _is_ a line after the last row indicating that it will be dropped there. Drop the row, and notice that the app raises an exception and doesn't do the drop. (As an example app the one provided in http://www.daa.com.au/pipermail/pygtk/2003-November/006304.html is perfect.) Reason: the 'drag-data-received' signal's handler uses TreeView.get_dest_row_at_pos(x, y) to find out the place of the drop. In this case, however, as the drop position doesn't have rows underneath, it returns None. And TreeView.get_drag_dest_row() returns None in this case, too. (Try it out by catching the exception in the above example code and printing the values) The real suprise is that in the UI, the line appears, so one would guess the drop should work, and so should .get_dest_row_at_pos(x, y), but it doesn't. This is at least a documentation bug, as gtk.TreeView.get_drag_dest_row()'s entry in the API docs says "Returns: a 2-tuple containing the tree path and the drop position relative to the tree path" That is, it doesn't mention returning None. However, I think only fixing this as a documentiation bug isn't the best idea. Making a work-around for this isn't too dificult, as the return values in both cases should be (to match what the UI is showing with the black line): ((len(TreeView.get_model()),) ,gtk.TREE_VIEW_DROP_AFTER) (at least I think so, not tested.) so one can simply catch the exception and use these values. However, this would mean every drag&drop-handling TreeView would need this workaround, which would be really unfortunate (and not at all pythonic, and so on.) For somebody writing an App which uses dnd in a TreeView, the best solution would be if TreeView.get_dest_row_at_pos(x, y) would work in this case, too. (So this is what I would like, if it doesn't break something else.) -- Abel Daniel ps. all this with >>> gtk.gtk_version (2, 4, 4) I'm using the 2.3.94-1 .deb package from debian experimental ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] freeze when trying to dynamically update menus
I was trying to implement dynamic menus. The idea is that the menu-items are created when the menu is activated (shown). This would be for an undo-menu where the menu-items would name the previously done editing actions, so dynamically creating the menu is vital. With a bit of help from #pygtk (on gimpnet) I came up with the attached code. (Most of the code is the itemfactory example from the pygtk tutorial.) The problem appears if the dynamically created menu is the first sub-menu from the menubar. When activating this menu the second time, the app freezes and I get a lot of the following messages on stderr: (itemfactory.py:2223): Gtk-CRITICAL **: file gtkwidget.c: line 3359 (gtk_widget_event): assertion `WIDGET_REALIZED_FOR_EVENT (widget, event)' failed (It looked like one for each redraw.) (This means that I have to go to a console with Ctrl-Alt-F2 and kill the app. X is unusable after triggering the bug, as the app won't give up focus, so mouseclicks go nowhere.) If the dynamically created menu is the second sub-menu from the menubar, (which means the menuitem which's 'activated' signal triggers the re-creation of the menu is not on the menubar, but in a submenu) it works fine. In the attached code, the menu Options->Test works, but the top-level Test does not. Is this a bug in my code? Thanks in advance, Abel Daniel #!/usr/bin/env python # example itemfactory.py import gtk import time class ItemFactoryExample: # Obligatory basic callback def print_hello(self, widget, data): print "Hello, World!" def update_menu(self, widget): #print 'updating' t=time.time() menu = gtk.Menu() menu_item = gtk.MenuItem(label=str(t)) menu.append(menu_item) menu_item.show() #?? widget.set_submenu(menu) menu.show() #widget.show() #print 'updated:', t # This is the ItemFactoryEntry structure used to generate new menus. # Item 1: The menu path. The letter after the underscore indicates an # accelerator key once the menu is open. # Item 2: The accelerator key for the entry # Item 3: The callback. # Item 4: The callback action. This changes the parameters with # which the callback is called. The default is 0. # Item 5: The item type, used to define what kind of an item it is. # Here are the possible values: # NULL -> "" # "" -> "" # "" -> create a title item # "" -> create a simple item # "" -> create a check item # "" -> create a toggle item # "" -> create a radio item #-> path of a radio item to link against # "" -> create a separator # "" -> create an item to hold sub items (optional) # "" -> create a right justified branch def get_main_menu(self, window): accel_group = gtk.AccelGroup() # This function initializes the item factory. # Param 1: The type of menu - can be MenuBar, Menu, # or OptionMenu. # Param 2: The path of the menu. # Param 3: A reference to an AccelGroup. The item factory sets up # the accelerator table while generating menus. item_factory = gtk.ItemFactory(gtk.MenuBar, "", accel_group) # This method generates the menu items. Pass to the item factory # the list of menu items item_factory.create_items(self.menu_items) menuitem = item_factory.get_widget('/Test') # <-- SWITCH HERE !!! menuitem.connect('activate', self.update_menu) menuitem = item_factory.get_widget('/Options/Test') menuitem.connect('activate', self.update_menu) # Attach the new accelerator group to the window. window.add_accel_group(accel_group) # need to keep a reference to item_factory to prevent its destruction self.item_factory = item_factory # Finally, return the actual menu bar created by the item factory. return item_factory.get_widget("") def __init__(self): self.menu_items = ( ( "/_File", None, None, 0, "" ), ( "/File/_New", "N", self.print_hello, 0, None ), ( "/File/_Open","O", self.print_hello, 0, None ), ( "/File/_Save","S", self.print_hello, 0, None ), ( "/File/Save _As", None, None, 0, None ), ( "/File/sep1", None, None, 0, ""
[pygtk] Re: How to focos a TreeView's cell?
Mauricio Téllez writes: > Hi, I have a ListStore with 3 column of type gobject.TYPE_STRING, > the first and thirth columns are editable, but the second is not. I > have an "Add" button that when I click it append a new row to the > model, so I want that the first cell in the view's new row get > selected and ready to insert text (as if I clicked the cell), You can use TreeView.set_cursor(path, focus_column, start_editing) to start editing the cell. (with start_editing=True) You say you want the "new row get selected". I think that the row doesn't need to be selected to start editing it. I think the cursor (a dashed line around the row) needs to be on the row, but it doesn't needs to be selected (which changes the rows' background to blue). If you _do_ want the row to be selected, you can do that with sel = TreeView.get_selection() sel.select_path( path ) > and that when I finished with that cell, the thirth cell get > "activated". I already use the "edited" signal of the render to get > the text inserted and put that text in the model. That means you simply have to call TreeView.set_cursor(...) in the function you handle the 'edited' singal with. -- Abel Daniel ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] Re: On displaying a TreeView and selecting the right element...
Martin Gadbois <[EMAIL PROTECTED]> writes: > I want to display a TreeView and have the initial selection to be > the last saved value. [ ...code snipped... ] > How to select the right initial value in a gtk.TreeView when > displaying it? > > I would like to show the initial selection when I display the > TreeView but it works only when I press the "Action" button. > > Is that a bug or a feature? > > Notice the "Selected:" printed on the screen: it contains the right > value. > > How do an experimented Gtk coder would do that? I don't know as I wouldn't call myself experienced :), but this version seems to work: --- # rest of the code not changed def dir_dialog(): ds = gtk.Dialog("Select directory") model = gtk.TreeStore(gobject.TYPE_STRING) for cnt in range(5): root = model.insert(None,cnt,[ item[cnt] ]) model.insert(root,0,[ "." ]) tv = gtk.TreeView(model) col= gtk.TreeViewColumn("",gtk.CellRendererText(),text=0) tv.append_column(col) tv.set_headers_visible(gtk.FALSE) ds.vbox.pack_start(tv)# this is changed: in your version this b = gtk.Button("Action") # part was at the end of the b.connect("clicked",doit,tv) # dir_dialog() function ds.action_area.pack_start(b) # ds.show_all() # end of changes sel = tv.get_selection() sel.set_mode(gtk.SELECTION_SINGLE) # This select_path() does nothing to the display... sel.select_path( (2,) ) tv.set_cursor( (2,), None, False ) # an extra line added to set cursor, too s = tv.get_selection().get_selected() print "Selected:",model.get_value(s[1],0) ds.run() --- Moving the 'display the widgets' code before the 'set selection' part apparently fixes it. This, of course, only sets the selection and will leave the cursor (a dashed box around the row) at the first row. The tv.set_cursor line sets this to the selected row, too. (This might or might not make sense in your case.) -- Abel Daniel ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] Re: comparision between pygtk & other pyGUI
"Somesh Bartakke" writes: > can you tell mw comparision points bet pygtk annd other gui tools ? I think you'll find several comparisons with a little googling, (some usefull bits might also be found in the paralell thread "IDLE-Gtk / Should PyGtk be proposed for the Python 2.4 release?") but here is mine: I have some (not much) experience with Tkinter, pyGtk and (even less) wxPython. IMHO, Tkinter is a really fine gui toolkit. The problem is that it is old. This means it won't really get new stuff (like new widgets) and it will look out-of place in modern desktops. If you only want a simple gui, like a couple of buttons and entry fields, Tkinter is really easy. If you need a toolkit for something bigger, choose pygtk instead. In comparison with pygtk, wxPython is really bad. When I fooled around with it, I could segfault it pretty easily. Of course, these segfaults where my fault (supplying a bad argument somewhere, using a wrong callback, etc.) but getting a verbose error message is _much_ more helpfull than getting a simple "Segmentation fault", which tells _nothing_ about _what_ you are doing wrong. One of the reasons I use python is because error messages and crashes actually make sense. So getting segmentation faults from a toolkit is really bad. It is especially bad when you would want to play around in the interactive interpreter. Apart from that, parts of wxPython look really ugly. For example, in wxMenu, you apparently need to use numerical constants to define menu options. That might be fine when you are coding in C or C++, but in Python it looks awfully bad. (an example: http://wiki.wxpython.org/index.cgi/DragAndDrop some selected lines: # Declare GUI Constants MENU_FILE_EXIT = 101 menu1.Append(MENU_FILE_EXIT, "E&xit", "Quit Application") EVT_MENU(self, MENU_FILE_EXIT, self.CloseWindow) Here, the code is using a numerical constant to refer to an object. Doing that in Python is truly stupid.) In fact, wxPython is so bad somebody created a "A friendly python-like wrapper for wxPython." (http://www.python.org/pypi?:action=display&name=wax&version=1.44) (Of course, with this he will have wrappers 3 deep (wax - wxPython - wxWindows - gtk)!) I have the feeling that wxPython is a great toolkit _if_ you are coming from C++ or MFC or somesuch. It might be great compared to windows gui programming, but its sure not better than pygtk. -- Abel Daniel ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] how to use set_widget method of TreeViewColumn?
I tried column.set_widget(gtk.Label('foo')), but instead of what I expected (getting a label in the header, the same as passing in 'foo' when creating the TreeViewColumn), I got an empty, about 9 pixel wide, empty header. What am I doing wrong? -- Abel Daniel --- example code: --- import pygtk pygtk.require('2.0') import gtk import gobject class App(gtk.Window): def __init__(self): gtk.Window.__init__(self) scrolled_window = gtk.ScrolledWindow() scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.add(scrolled_window) model = gtk.TreeStore(gobject.TYPE_STRING) tree_view = gtk.TreeView(model) tree_view.set_rules_hint(gtk.TRUE) cell = gtk.CellRendererText() column = gtk.TreeViewColumn('spam', cell, text=0) column.set_widget(gtk.Label('foo')) # <- !!! toggle this line model.insert(None, 1, ("some content",) ) for i in range(5): model.insert(None, i, ("some more content",) ) tree_view.append_column(column) scrolled_window.add(tree_view) self.set_default_size(500, 400) self.show_all() self.model=model self.tree_view = tree_view if __name__ == '__main__': a=App() gtk.main() ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] removing keybindings
How can I remove keybindings added with gtk.binding_entry_add_signal()? I would like to make my app to have modes, a bit like the vi editor. Launching a mode would change some keybindings. I figured I can add the keybindings with gtk.binding_entry_add_signal() when the mode is started, but the problem is, how do I remove them when the user exits the mode? -- Abel Daniel ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] multi-line cellrenderertext in C was: Re: VBox in a treeview?
Graham Ashton writes: > Apologies for responding to my own message, but I found a way to achieve > the same result (multi-line text inside a cell) by drawing a pango > layout directly onto the treeview widget. Apparently others want multi-line text in trees, too, so here is my version: (first release, not really polished, but should work. It should be good enough for debugging, but not for end-user release.) http://abeld.web.elte.hu/wrappedtext.tar.gz It is a C widget, you need to compile the widget part first. It can also be edited, the editing is handled by a TextView which is modified to implement the CellEditable interface. I will use it in an outliner program I am working on. I also tried the 'draw a pango layout on the widget' idea, but I decided against it. Can't exactly remember why, I think I had problems with setting the cell size. You set it to be big enough, right? So there will be a varying amount of space below each cell. Doesn't that look ugly? -- Abel Daniel -- abeld.web.elte.hu ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] Re: help, creating dynamic treeview
iip writes: > Is anyone have experience creating dynamic liststore for browsing > data? so I can add column or delete column in the list when the > application run. >From a bit of experimenting, this is what I found: making a dynamic liststore like this most likely won't work. If you make your own TreeModel (by inheriting from gtk.GenericTreeModel or gtk.ListStore and overriding methods) you will need a on_get_n_columns method, which should return the number of columns. However, this is called only once (at least I couldn't make it get called again), so I don't see any way to tell the treeview that the number of columns has changed. As a work-around you could create a new model with the required number of columns, ad use TreeView.set_model() to make the TreeView display that. (This switch will close all leafs you have opened in the tree, but as you want a list, and not a tree, that won't affect you.) Maybe you could avoid having to create treemodels all the time by making an extensible treemodel you can add columns to(by subclassing one of the existing ones) and telling the treeview that the treemodel has changed with TreeView.set_model(model) (i.e. setting the model to the existing one). (Note that if you want to change what is displayed, you need to add a column to the _treeview_, which can be done the same way as adding columns when you create the treeview, and works fine.) -- Abel Daniel ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] Re: swap rows in TreeView
Johannes Jordens writes: > I'd like to implement moving a row in a TreeView, > specifically in a ListStore, up/down via two buttons. I have implemented > moving the row downwards using the iter_next(iter) function so that > I have an iter on the row below the one currently selected. > But: there is no corresponding function to iter_next if one wants to > have an iter on the preceding row (at least I couldn't find one). > So I figured that there must be some function to turn an iter into a > path I think you need the .get_path(iter) method of TreeModel (just to make sure: iter_next and similar methods don't move a row, you have to do that by removing and reinserting the row. But I guess you already know that :) ) -- Abel Daniel ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] Re: creating new signals and keybindings in subclassed widgets
Lorenzo Gil Sanchez writes: > > Try changing the __init__ method to: > > def __init__(self, model, *a, **kw): > self.__gobject_init__() > self.set_model(model) > Gee, thanks a lot, that helped. > Anyway, I run into other problem: when I type CTRL+Up the signal is > emitted but this is what i get: > > (widgettest.py:2227): Gtk-WARNING **: gtk_binding_entry_activate(): > binding "__main__+HnbTreeView::Up": signal > "move-to-sibling" in the `__main__+HnbTreeView' class ancestry > cannot be used for action emissions Well, adding gobject.SIGNAL_ACTION to the signal's flags made that go away. (And in the C code for treeview similar signals, like 'move-cursor' are created with those flags so I guess that's the way to do it.) (So it now looks like this: __gsignals__={ 'move-to-sibling' : (gobject.SIGNAL_RUN_LAST | gobject.SIGNAL_ACTION, gobject.TYPE_NONE, (gobject.TYPE_INT,)) } ) -- Abel Daniel ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] creating new signals and keybindings in subclassed widgets
I'm trying to create a modified TreeView which would have a bit different style of moving around. (Like pressing up and down would only move to the next sibling and wouldn't move if there are no siblings in that direction, pressing left would move to the parent node and close that subtree, etc.) I thought the best way of doing this is to subclass TreeView, add new signals (like 'move-to-signal', 'ascend-and-close' etc.) and create default keybindings. Just to try out this idea, I wrote the following test: ---8<- class HnbTreeView(gtk.TreeView): """ TreeView with modified keybindings """ __gsignals__={ 'move-to-sibling' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_INT,)) } def __init__(self, model, *a, **kw): self.__gobject_init__() gtk.TreeView.__init__(self, model, *a, **kw) def do_move_to_sibling(*a, **kw): print 'called' print a print kw gobject.type_register(HnbTreeView) gtk.binding_entry_add_signal(HnbTreeView, gtk.gdk.keyval_from_name('Up'), gtk.gdk.CONTROL_MASK, 'move-to-sibling', gobject.TYPE_INT, 1) --8<--- The gobject tutorial at http://www.sicem.biz/personal/lgs/docs/gobject-tutorial/gobject-tutorial.html mentions that: """ If you define custom properties or signals in your new class you can't call the superclass __init__ method in your __init__ method or it will overwrite your property definitions. You should call the __gobject_init__ method instead. """ Apparently this is my problem. If I call gtk.TreeView.__init__, nothing happens, and the new signal is not usable (Control-Up does the same as Up in itself, and if I try to emit the signal with treeview.emit(...) I get a "TypeError: unknown signal name".) If I leave out the call to gtk.TreeView.__init__(), I get a completly blank widget. (Which does have the new signal as I can with treeview.emit()) Is creating new signals in subclasses of existing widgets impossible? -- Abel Daniel ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] Re: hide certain rows in treeview
Yang Zheng writes: > Is it possible to not show certain rows in a treeview that is attached > to a treestore? I know you can display only certain columns, but what > if there are some rows in a treestore structure that I do not want to be > displayed? Can I set a flag and have it skipped? I don't know how much this will help, but here are a few links I happened to bump into: I found a thread about filtering treeviews. It starts at: http://mail.gnome.org/archives/gtk-app-devel-list/2002-October/msg00262.html according to: http://mail.gnome.org/archives/gtk-app-devel-list/2002-October/msg00290.html (in the same thread) it will be in gtk 2.4. In the meantime you might have to use treemodelfilter from libegg, maybe by wrapping it yourself. In this case http://usefulinc.com/edd/blog/2003/8/20#12:33 and http://www-106.ibm.com/developerworks/linux/library/l-wrap/ might help. -- Abel Daniel ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] Re: problems with TreeView...
Abel Daniel writes: > Christian Reis writes: >> -> FAQ 13.36 (wow, 36 entries) >> >> http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq13.036.htp > Strange, I only see 21 in that category. Arrgh, you moved them. Sorry. -- Abel Daniel ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] Re: problems with TreeView...
Christian Reis writes: > -> FAQ 13.36 (wow, 36 entries) > > http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq13.036.htp Strange, I only see 21 in that category. -- Abel Daniel ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] Re: problems with TreeView...
Thomi Richards <[EMAIL PROTECTED]> writes: > however, now all the columns display the first name! I'm not sure i completely > understand this... i associated the correct data with the correct columns in > the "model" part of the thing But you also have to tell the CellRenderer which column to get the data from. You set up the column with: renderer = gtk.CellRendererText() column = gtk.TreeViewColumn("First Name", renderer, text=1) # ^^ self.eview.append_column(column) There with 'text=1' you tell the column to get the text from column 1 of the model. (Column numbers start with 0, so the column 1 in your model is the 'first_name'.) So you should have 'text=0' for the first column, 'text=1' for the next, and so on. And if you want to avoid repetitive code, you can do something like: column_headers=['EID', 'First Name', 'Last Name', 'Home Phone', 'Cell Phone'] for i in range(5): renderer = gtk.CellRendererText() column = gtk.TreeViewColumn(column_headers[i], renderer, text=i) self.eview.append_column(column) Instead of repeating that three lines five times. Also, where you load the data into the ListStore, you have the line: for i in range(4): Don't you want range(5) instead? range(4) is [0, 1, 2, 3] so you'll get four columns, but it seems like you want 5. -- Abel Daniel ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] Re: A question about gtk.TreeView
"Jeff Cutsinger" <[EMAIL PROTECTED]> writes: [...drag & drop not working...] > class PlaylistModel(g.ListStore): > ...snip... > def drag_data_received(self, dest, selection_data): > rox.info(str(dest)) > rox.info(str(selection_data)) > return g.FALSE > def row_drop_possible(self, dest, data): > return g.TRUE > > def window(player): > ... > tree=g.TreeView(model=PlaylistModel(player)) > ... > tree.enable_model_drag_dest([('text/uri-list', 0, 0)], gdk.ACTION_COPY | > gdk.ACTION_MOVE | gdk.ACTION_PRIVATE) This is just a wild guess, but shouldn't you call those two on_drag_data_received() and on_row_drop_possible() ? Abel Daniel ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] Re: Creating custom CellRenderer
Lorenzo Gil Sanchez <[EMAIL PROTECTED]> writes: > I think I know where is your problem. I just compared your code with > Johan code and look what he does in his on_render method: > > def on_render(...): > x_offset, y_offset, width, height = self.on_get_size(widget, > cell_area) > > So that's why the method on_get_size is called the second time with a > valid value for cell_area. > > Hope it helps No it doesnt. Whatever on_get_size returns at that call has no effect on the size of the cell. (Since the return value is used in on_render and not by the TreeView or whatever gtk code.) I think I would need a way to set the size of the cell, but I see nothing like that in the API docs. Is there something I could use for this? Abel Daniel ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] Re: Creating custom CellRenderer
Lorenzo Gil Sanchez writes: > I think you should check if cell_area is None in your on_get_size() > method because IIRC only the first time that is called it is None. I > don't know why btw. The problem is that it isn't called again, no matter what I do with the window (iconize, resize, etc.). Does this mean that it is impossible to create a CellRenderer that adjustes it's height according to it's width? > http://www.daa.com.au/pipermail/pygtk/2003-January/004239.html that was where I started from when creating mine. Abel Daniel ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] Creating custom CellRenderer
Hi! As a beginner pygtk user, I'm trying to make a TreeView which has multi-line cells. Each node would contain about 1-4 lines of text. If I were to use a gtk.CellRendererText, only 1 line would be visible, and the user would have to scroll horizontally to see the rest of the text. I want the full text to be visible, by having it wrap if it is more than one line. The best solution would be using a TextView as a CellRenderer. But it looks like normal widgets can't be used like that. (Is there a reason for this? One would think that CellRenderers would be very similar to normal widgets.) So I guess my best bet is making a custom CellRenderer. I thought something like this would work: ---8< import pygtk pygtk.require('2.0') import gtk import gobject import pango class MyCellRenderer(gtk.GenericCellRenderer): def __init__(self): self.__gobject_init__() def on_render(self, window, widget, background_area, cell_area, expose_area, flags): context = widget.get_pango_context() layout = pango.Layout(context) layout.set_text(long_string) layout.set_wrap(gtk.WRAP_CHAR) layout.set_width(cell_area.width) widget.style.paint_layout(window, gtk.STATE_NORMAL, gtk.TRUE, cell_area, widget, 'footext', cell_area.x, cell_area.y, layout) def on_get_size(self, widget, cell_area): return 0,0,100,100 # return something big enough gobject.type_register(MyCellRenderer) class Tree(gtk.TreeView): def __init__(self): self.store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_PYOBJECT) gtk.TreeView.__init__(self) self.set_size_request(300, 200) self.set_model(self.store) self.set_headers_visible(gtk.TRUE) rend = gtk.CellRendererText() column = gtk.TreeViewColumn('First', rend, text=0) self.append_column(column) rend = MyCellRenderer() column = gtk.TreeViewColumn('Second', rend) self.append_column(column) def insert(self, name): iter = self.store.append() self.store.set(iter, 0, name) long_string="""long-long string for testing asdf asdf asdf asdf adsf asdf asdf asdasdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf """ w = gtk.Window() w.set_position(gtk.WIN_POS_CENTER) w.connect('delete-event', gtk.mainquit) t = Tree() t.insert('baz') w.add(t) w.show_all() gtk.main() ---8<--- The immedate problem is that layout.set_width() apparently expects something other than pixels. If I do layout.set_width(20), get_pixel_size() will return a width of 195 pixels. I couldn't find anything in the documentation about the units set_width() expects or how to convert number of pixels to it. Where is this documented, and how could I handle the conversion? Even if I somehow manage to convert pixels to this unit system, I will have another problem: I want the width of the text to adjust to the width of the TreeView widget. The height of the text should adjust to the amount of text in that given node. The problem is, that as I understand it, the CellRenderer has to calculate the size needed in on_get_size(). But I couldn't find a way to get the size of the TreeWidget (or rather, the size left for the cell after indentation, the little icon showing expandedness, etc.) in that method. cell_area is None there. I can access the width of the cell from on_render(), (it seems to be cell_area.width) but I don't see a way to change the height of the cell there. Is there a way to solve this? Thanks in advance, Abel Daniel ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/