what is the difference in to .py files?

I'm new to wxpython and reading and playing with examples, I get to an
issue. What is the difference in the two examples?

--- example 1
import wx
import wx.lib.dialogs

application = wx.PySimpleApp()

# Create a list of choices

choices = [ 'Red', 'Blue', 'Green', 'Pink', 'White' ]

# Create the dialog

dialog = wx.lib.dialogs.singleChoiceDialog ( None, 'Pick something....', 'Dialog Title', choices )
--- end example 1

and

--- example 2
from wxPython.wx import *

from wxPython.lib.dialogs import *

application = wxPySimpleApp()

# Create a list of choices

choices = [ 'Red', 'Blue', 'Green', 'Pink', 'White' ]

# Create the dialog

dialog = wxSingleChoiceDialog ( None, 'Pick something....', 'Dialog Title', choices )

# Show the dialog

dialog.ShowModal()

# Destroy the dialog

dialog.Destroy()
--- end example 1

In particular, why in the first example dialog.ShowModal() and
dialog.Destroy() are not available and produce errors?

I would be gratefull for any explaination,
Best regards
Seweryn Kokot

Seweryn Kokot wrote:

I'm new to wxpython and reading and playing with examples, I get to an
issue. What is the difference in the two examples?

--- example 1
import wx
import wx.lib.dialogs

application = wx.PySimpleApp()

# Create a list of choices

choices = [ 'Red', 'Blue', 'Green', 'Pink', 'White' ]

# Create the dialog

dialog = wx.lib.dialogs.singleChoiceDialog ( None, 'Pick something....', 'Dialog Title', choices )
--- end example 1

and

--- example 2
from wxPython.wx import *

from wxPython.lib.dialogs import *

application = wxPySimpleApp()

# Create a list of choices

choices = [ 'Red', 'Blue', 'Green', 'Pink', 'White' ]

# Create the dialog

dialog = wxSingleChoiceDialog ( None, 'Pick something....', 'Dialog Title', choices )

# Show the dialog

dialog.ShowModal()

# Destroy the dialog

dialog.Destroy()
--- end example 1

Principially it is the same.
This is the old style valid until 2.4
Since wxPython 2.5 you should use the import wx,
as you did above.

There was another structure before.

In particular, why in the first example dialog.ShowModal() and
dialog.Destroy() are not available and produce errors?

I would be gratefull for any explaination,
Best regards
Seweryn Kokot

That sorry, I cannot answer.

But anyway, I think you have to pack the whole
application in a mainloop with the wx.App or
derived classes like:

import wx
import wx.lib.dialogs

choices = [ 'Red', 'Blue', 'Green', 'Pink', 'White' ]

app=wx.App(0)
w = wx.lib.dialogs.singleChoiceDialog ( None, 'Pick something....',
'Dialog Title', choices )
app.MainLoop()

If the dialog is a user defined one:

import wx

app=wx.App(0)
w = wx.Dialog(None, -1, "Test")
w.ShowModal()
w.Destroy()
app.MainLoop()

I think, the singleChoiceDialg is wrapped by something more,
with the Show and Destroy also inside.

···

--
Franz Steinhaeusler

Seweryn Kokot wrote:

I'm new to wxpython and reading and playing with examples, I get to an
issue. What is the difference in the two examples?

In particular, why in the first example dialog.ShowModal() and
dialog.Destroy() are not available and produce errors?

Because wx.lib.dialogs.singleChoiceDialog is not a class, it's a function.

def singleChoiceDialog(parent=None, message='', title='', lst=,
                        style=wx.OK | wx.CANCEL | wx.CENTRE):
     dialog = wx.SingleChoiceDialog(parent, message, title, list(lst), style | wx.DEFAULT_DIALOG_STYLE)
     result = DialogResults(dialog.ShowModal())
     result.selection = dialog.GetStringSelection()
     dialog.Destroy()
     return result

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!