jeudi 24 avril 2014

python - ne peut pas la saisie de texte accès boîte après rouvrir la fenêtre GTK - Stack Overflow


First of all, this issue is only happened in WIN7, and it is normally under raspberry pi (Debian Linux).


I have two window, the main window and a child window. The main window has a button which can activate the child window. The child window has a text entry box which can input the strings. The issue is when activate the child window at 1st time, the text entry box is functional. But when the child window is closed and re-opened, the text entry box seems disabled that cannot input any text into it, even set_text("xx") function cannot write any text into it.


The detailed steps are:



  1. run the py script


  2. click the button on main window to open the child window. I have tried with the below three methods, it seems they have same issue:

    def on_button_clicked(self, widget, data=None):
    self.child_window.present()
    #self.child_window.show()
    #self.child_window.show_all()

  3. Now the child window is opened and the text entry box is functional, I can type any text into it.


  4. Close the child window. I have bind the delete signal on to the child window. So every time the child window is closed, the below function will be executed, which will hide the current child window.

    def on_WindowOfScanning_delete_event(self, widget, data=None):
    self.child_window.hide()
    return True

  5. Now the main window is on focus and click the button to activate the child window again.

    self.child_window.present()

  6. Now the child window is appear, but the text entry box seems disabled.



Any one can help me on this issue? Appreciated for that..


The version information is: Python 2.7.3 GTK 2.24.2, and I use glade to manage the GUI interface.


================= The same question with a different example: =====================


http://www.pygtk.org/pygtk2tutorial/sec-TextEntries.html#entryfig


This link is the pygtk's official example. While running on my WIN7(64bit) system, the text entry box cannot be edited since the first time opening. But if you move mouse to activate other window, and turn back to this gtk window, the text entry box can be edited then. I am not sure if this is a pygtk's bug.


I have tried python 2.6.6 and 2.7.3 with pygtk2.24.2-all-in-one.


================= The solution to this issue: =====================


It seems no one have such kind of problem so I post my own solution.


1st, give up using the window.hide() function.


2nd, destroy the child window every time it finished its job, and re-init the gtk.Window again to invoke the child window. Here is a simple example:


#!/usr/bin/env python

import pygtk
pygtk.require( "2.0" )
import gtk

class PopupExample(gtk.Window):
def __init__( self ):
gtk.Window.__init__(self)
self.connect("destroy", lambda *w: gtk.main_quit())
button = gtk.Button("Popup Window")
button.connect("clicked", self.show_popup_window)
self.add(button)

def show_popup_window(self, button):
popup = gtk.Window()
popup.add(gtk.Entry())
popup.show_all()

if __name__ == "__main__":
pe = PopupExample()
pe.show_all()
gtk.main()


First of all, this issue is only happened in WIN7, and it is normally under raspberry pi (Debian Linux).


I have two window, the main window and a child window. The main window has a button which can activate the child window. The child window has a text entry box which can input the strings. The issue is when activate the child window at 1st time, the text entry box is functional. But when the child window is closed and re-opened, the text entry box seems disabled that cannot input any text into it, even set_text("xx") function cannot write any text into it.


The detailed steps are:



  1. run the py script


  2. click the button on main window to open the child window. I have tried with the below three methods, it seems they have same issue:

    def on_button_clicked(self, widget, data=None):
    self.child_window.present()
    #self.child_window.show()
    #self.child_window.show_all()

  3. Now the child window is opened and the text entry box is functional, I can type any text into it.


  4. Close the child window. I have bind the delete signal on to the child window. So every time the child window is closed, the below function will be executed, which will hide the current child window.

    def on_WindowOfScanning_delete_event(self, widget, data=None):
    self.child_window.hide()
    return True

  5. Now the main window is on focus and click the button to activate the child window again.

    self.child_window.present()

  6. Now the child window is appear, but the text entry box seems disabled.



Any one can help me on this issue? Appreciated for that..


The version information is: Python 2.7.3 GTK 2.24.2, and I use glade to manage the GUI interface.


================= The same question with a different example: =====================


http://www.pygtk.org/pygtk2tutorial/sec-TextEntries.html#entryfig


This link is the pygtk's official example. While running on my WIN7(64bit) system, the text entry box cannot be edited since the first time opening. But if you move mouse to activate other window, and turn back to this gtk window, the text entry box can be edited then. I am not sure if this is a pygtk's bug.


I have tried python 2.6.6 and 2.7.3 with pygtk2.24.2-all-in-one.


================= The solution to this issue: =====================


It seems no one have such kind of problem so I post my own solution.


1st, give up using the window.hide() function.


2nd, destroy the child window every time it finished its job, and re-init the gtk.Window again to invoke the child window. Here is a simple example:


#!/usr/bin/env python

import pygtk
pygtk.require( "2.0" )
import gtk

class PopupExample(gtk.Window):
def __init__( self ):
gtk.Window.__init__(self)
self.connect("destroy", lambda *w: gtk.main_quit())
button = gtk.Button("Popup Window")
button.connect("clicked", self.show_popup_window)
self.add(button)

def show_popup_window(self, button):
popup = gtk.Window()
popup.add(gtk.Entry())
popup.show_all()

if __name__ == "__main__":
pe = PopupExample()
pe.show_all()
gtk.main()

0 commentaires:

Enregistrer un commentaire