Re: CellRendererText validation



On September 2, 2005 03:49 am, Gergely Kontra wrote:
> Hi!
>
> I'm trying to implement an editable cell in a treeview.
> It's a CellRendererText, but in the model it is actually not a
> string, but has string representation. When the user edits the
> cell, I must check it.
> If the check fails, it shouldn't allow me to leave the field,
> but tell me what's wrong.

Can I suggest that you consider other possibilities to achieve 
the same aim?  I've just been going through the whole area of 
field validation myself so I can appreciate how much you have 
thought about this yourself and how difficult it can be.  My 
current preferred method is to check the value as the focus 
leaves the field and leave behind a visual clue as to its 
validity (e.g. change the text colour and display the problem in 
an adjacent label or support some sort of error popup on 
hovering over the cell).  As far as I am concerned the worst 
thing you can do is simply to refuse to allow the focus to move  
out; if you do that then make sure you only do it when the focus 
is moving into something else within your application.

>
> So, I begin to edit the cell, type in a lot of cool stuff.
> Then, I try to leave the cell, but the cell's content is not
> valid. Falling back to the last good value is not a solution
> for me, I want to get a message about the invalid entry and
> keep editing the field. How can I achieve this?
>

Assuming that you have decided that you need to do this you will 
need to add code so that you can track where the focus is 
currently, trap attempts to change the focus from that field to 
another widget in your application and do it then.  That is 
going to be further complicated if you want to pop up an error 
dialog because, of course, you must let the focus move to the 
error dialog but not to another field.

Please note that I am new to doing this sort of stuff but I 
expect you can do something with gtk_widget_grab_focus.

> In fact, it is a Regexp, and I'm coding in ruby, but that's
> not the point. --
> +-[ Gergely Kontra <kgergely mcl hu>
> http://www.mcl.hu/~kgergely ]------+
>
> | PhD Student (Room:IB113)  PGP ID: 0x7E3846BF  Mobile:(+36
> | 20)356 9656 | Budapest University of Technology and
> | Economics        ICQ# 175564914 |
>
> +------------- "Olyan langesz vagyok, hogy poroltoval kellene
> jarnom!" -+ _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list

-- 
Bill Medland
mailto:billmedland mercuryspeed com
http://webhome.idirect.com/~kbmed




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]