grab_focus

View: New views
4 Messages — Rating Filter:   Alert me  

grab_focus

by Alessandro Dentella :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi,

  I want to let an entry to (be created and) get the focus when I select a
  menu item on another window.

  I'm using grab_focus, but that only does half of the job. It get focus *if
  I move the mouse over the window of the entry*.

  I'd rather have the mouse stay where it is. How can I do that?
  I'm afraid that depends on the focus model of the window manager but I'm
  not sure.

  TIA
  sandro
  *:-)

_______________________________________________
pygtk mailing list   pygtk@...
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Re: grab_focus

by Alessandro Dentella :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, May 16, 2008 at 09:19:01AM +0200, Alessandro Dentella wrote:

> hi,
>
>   I want to let an entry to (be created and) get the focus when I select a
>   menu item on another window.
>
>   I'm using grab_focus, but that only does half of the job. It get focus *if
>   I move the mouse over the window of the entry*.
>
>   I'd rather have the mouse stay where it is. How can I do that?
>   I'm afraid that depends on the focus model of the window manager but I'm
>   not sure.


It turns out grab_focus works as expected if the creation of the entry (and
successive grab_focus) starts from the callback ov a click on an eventBox,
but not from the menu entry. Can it depend on some interaction with the menu
entry?

I set it with this code:


   item = gtk.MenuItem(label="add %s to filter" % field_name.replace('_', ' '))
   item.connect('activate', self.filter_panel.add, ev, field_name )
   menu.append(item)


where sel.filter_panel.add works correctly if called from the EventBox cb.


TIA
sandro
_______________________________________________
pygtk mailing list   pygtk@...
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Re: grab_focus

by Alessandro Dentella :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Sorry for the noise. But I added one more false info...



It turns out grab_focus works as expected when I first create the window and
entry. Any successive entry, added to this window will not get the focus.

Following code doesn't ever get the focus to the entry... why?

import gtk

class Layout(object):
    def __init__(self):
        self.w = gtk.Window()
        self.b = gtk.HBox()
        self.w.add(self.b)
        self.butt = gtk.Button(label="add entry")
        self.butt.connect('clicked', self.butt_cb)
        self.b.add(self.butt)
        self.w.show_all()

        self.w2 = gtk.Window()
        self.w2.set_default_size(200, 100)
        self.b2 = gtk.VBox()
        self.w2.add(self.b2)
       
        label = gtk.Label('Entries')
        self.b2.add(label)
        self.w2.show_all()
       
    def butt_cb(self, wdg):
        e = gtk.Entry()
        self.b2.add(e)
        e.show()
        e.grab_focus()
        self.w2.show_all()

l = Layout()
gtk.main()

_______________________________________________
pygtk mailing list   pygtk@...
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Re: grab_focus - partial solution

by Alessandro Dentella :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> It turns out grab_focus works as expected when I first create the window and
> entry. Any successive entry, added to this window will not get the focus.
>

Ok, I partially solved my problem adding a .present() to the callback. I say
'partially' since that makes the window to raise to the toplevel, that is
not necessarily what I want...

Is there a way to prevent that?


sandro

--
mi sento come una goccia di sodio in una bottoglia di acqua lete...
_______________________________________________
pygtk mailing list   pygtk@...
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/