wxPython Demo crushes and can not work even after computer re-started... shall I re-install the software

I used to read the sample codes and then edit my codes in the modified
version and then run the code.
I am a newbie and I googled online for more resources. After I copied
some codes from a website and put it in the modified version of
CheckBox, which I am working on. It crushes.

Now even after I restart wxPython demo or computer, it does not help.
Once I clicked on Demo and goes to Core Windows/Controls and to
CheckBox, the wxPython Demo is freezed and the mouse showing it is
running for ever and it does not respond any more. I guess something
went wrong. But the problem is I can not correct it because now the
wxPython does not respond any more. Anybody can give any suggestions?
I don't want to re-install the software.

The part of code is the following:

#!/usr/bin/python

# checkbox.py

import wx

class CheckBox(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(250, 170))

        panel = wx.Panel(self, -1)
        self.cb = wx.CheckBox(panel, -1, 'Show Title', (10, 10))
        self.cb.SetValue(True)

        wx.EVT_CHECKBOX(self, self.cb.GetId(), self.ShowTitle)

        self.Show()
        self.Centre()

    def ShowTitle(self, event):
        if self.cb.GetValue():
            self.SetTitle('checkbox.py')
        else: self.SetTitle('')

app = wx.App()
CheckBox(None, -1, 'checkbox.py')
app.MainLoop()

I used to read the sample codes and then edit my codes in the modified
version and then run the code.
I am a newbie and I googled online for more resources. After I copied
some codes from a website and put it in the modified version of
CheckBox, which I am working on. It crushes.

Now even after I restart wxPython demo or computer, it does not help.
Once I clicked on Demo and goes to Core Windows/Controls and to
CheckBox, the wxPython Demo is freezed and the mouse showing it is
running for ever and it does not respond any more. I guess something
went wrong. But the problem is I can not correct it because now the
wxPython does not respond any more. Anybody can give any suggestions?
I don't want to re-install the software.

The part of code is the following:

If what you're trying to say is that you copied the code below into the demo folder as CheckBox.py, and then the demo no longer executes correctly, then yes, that is what is expected. The modules in the demo implement a specific function and other module-level items to enable them to be dynamically imported and run from the main demo framework. What you have below is a standalone application that unconditionally creates its own wx.App and runs MainLoop, so it can not fit in a well-behaved way in the demo framework. Instead run it by itself without the demo.

#!/usr/bin/python

# checkbox.py

import wx

class CheckBox(wx.Frame):
     def __init__(self, parent, id, title):
         wx.Frame.__init__(self, parent, id, title, size=(250, 170))

         panel = wx.Panel(self, -1)
         self.cb = wx.CheckBox(panel, -1, 'Show Title', (10, 10))
         self.cb.SetValue(True)

         wx.EVT_CHECKBOX(self, self.cb.GetId(), self.ShowTitle)

That is the old way to bind event handlers. This is how to do the same thing in the new way:

            self.Bind(wx.EVT_CHECKBOX, self.ShowTitle, self.cb)

Or moving the binding to the checkbox like this would work too:

            self.cb.Bind(wx.EVT_CHECKBOX, self.ShowTitle)

···

On 5/24/11 12:43 PM, mua wrote:

         self.Show()
         self.Centre()

     def ShowTitle(self, event):
         if self.cb.GetValue():
             self.SetTitle('checkbox.py')
         else: self.SetTitle('')

app = wx.App()
CheckBox(None, -1, 'checkbox.py')
app.MainLoop()

--
Robin Dunn
Software Craftsman

Is there a way to fix this? I can not now start demo correctly after
click on the checkbox.

···

On May 24, 4:10 pm, Robin Dunn <ro...@alldunn.com> wrote:

On 5/24/11 12:43 PM, mua wrote:

> I used to read the sample codes and then edit my codes in the modified
> version and then run the code.
> I am a newbie and I googled online for more resources. After I copied
> some codes from a website and put it in the modified version of
> CheckBox, which I am working on. It crushes.

> Now even after I restart wxPython demo or computer, it does not help.
> Once I clicked on Demo and goes to Core Windows/Controls and to
> CheckBox, the wxPython Demo is freezed and the mouse showing it is
> running for ever and it does not respond any more. I guess something
> went wrong. But the problem is I can not correct it because now the
> wxPython does not respond any more. Anybody can give any suggestions?
> I don't want to re-install the software.

> The part of code is the following:

If what you're trying to say is that you copied the code below into the
demo folder as CheckBox.py, and then the demo no longer executes
correctly, then yes, that is what is expected. The modules in the demo
implement a specific function and other module-level items to enable
them to be dynamically imported and run from the main demo framework.
What you have below is a standalone application that unconditionally
creates its own wx.App and runs MainLoop, so it can not fit in a
well-behaved way in the demo framework. Instead run it by itself
without the demo.

> #!/usr/bin/python

> # checkbox.py

> import wx

> class CheckBox(wx.Frame):
> def __init__(self, parent, id, title):
> wx.Frame.__init__(self, parent, id, title, size=(250, 170))

> panel = wx.Panel(self, -1)
> self.cb = wx.CheckBox(panel, -1, 'Show Title', (10, 10))
> self.cb.SetValue(True)

> wx.EVT_CHECKBOX(self, self.cb.GetId(), self.ShowTitle)

That is the old way to bind event handlers. This is how to do the same
thing in the new way:

        self\.Bind\(wx\.EVT\_CHECKBOX, self\.ShowTitle, self\.cb\)

Or moving the binding to the checkbox like this would work too:

        self\.cb\.Bind\(wx\.EVT\_CHECKBOX, self\.ShowTitle\)

> self.Show()
> self.Centre()

> def ShowTitle(self, event):
> if self.cb.GetValue():
> self.SetTitle('checkbox.py')
> else: self.SetTitle('')

> app = wx.App()
> CheckBox(None, -1, 'checkbox.py')
> app.MainLoop()

--
Robin Dunn
Software Craftsmanhttp://wxPython.org- Hide quoted text -

- Show quoted text -

I used to read the sample codes and then edit my codes in the modified
version and then run the code.
I am a newbie and I googled online for more resources. After I copied
some codes from a website and put it in the modified version of
CheckBox, which I am working on. It crushes.

Now even after I restart wxPython demo or computer, it does not help.
Once I clicked on Demo and goes to Core Windows/Controls and to
CheckBox, the wxPython Demo is freezed and the mouse showing it is
running for ever and it does not respond any more. I guess something
went wrong. But the problem is I can not correct it because now the
wxPython does not respond any more. Anybody can give any suggestions?
I don't want to re-install the software.

The part of code is the following:

If what you're trying to say is that you copied the code below into the
demo folder as CheckBox.py, and then the demo no longer executes
correctly, then yes, that is what is expected. The modules in the demo
implement a specific function and other module-level items to enable
them to be dynamically imported and run from the main demo framework.
What you have below is a standalone application that unconditionally
creates its own wx.App and runs MainLoop, so it can not fit in a
well-behaved way in the demo framework. Instead run it by itself
without the demo.

Is there a way to fix this? I can not now start demo correctly after
click on the checkbox.

If you edited the CheckBox.py file in the demo folder then you can either extract the file from the demo tarball to restore the original CheckBox.py file or you can simply reinstall the whole demo.

Or if you've edited the code of the sample within the "Demo Code" notebook tab in the running demo application then it will have stored your modified version in some folder like {DATADIR}/wxPyDemo/modified where the value of DATADIR depends on the platform and environment settings. To find out for sure where it is located on your system you can use code like this:

  >>> import wx
  >>> app = wx.App(False)
  >>> app.SetAppName('wxPyDemo')
  >>> sp = wx.StandardPaths.Get()
  >>> print sp.GetUserDataDir()
  C:\Users\robind\AppData\Roaming\wxPyDemo

···

On 5/25/11 12:31 PM, mua wrote:

On May 24, 4:10 pm, Robin Dunn<ro...@alldunn.com> wrote:

On 5/24/11 12:43 PM, mua wrote:

  >>>

--
Robin Dunn
Software Craftsman