Hi,
Although I'm also very new at both python (<month) and wx
python (<week), I was struggling with some of the same
things, so I can give you some advice. If what I’m saying is
not true, I hope that some of the more experienced guys will
jump in and correct me.
Welcome to the wonderful world of (wx)Python!
<Code Snipped>
Best,
Jopeto
PS. Some things which I still don't quite understand myself
and hopefully will have time to figure out in the future are:
1. Should I have the "self.SetAutoLayout(True)" since it
doesn’t really seem to do anything?
Not 100% sure myself but I believe that it controls whether you need
to explicity tell your application when a new layout is needed or it
tries to detect it for you. If you have points when there is a
major change in your layout that will go slowly if the window is
trying to do a new layout between stages then you will need to turn
off Auto Layout until you are done.
2. What does the "id=-1" mean in the creation of
each widget? I’ve never seen any other value than -1, so it
seems a bit unnecessary to me to have to specify it every
time.
You need to specify a unique id for each item, you have the option
of specifying you own so that you can take control of things like
when the item is enabled, etc., by id number. -1 translates to let
the system create a new unique id for this control. You can still
do things like enable/disable the control in other ways such as find
by label or getting the id that windows assigns and keeping track of
it. Like a lot of things in the wx world there are several ways of
doing things and many of them a kept for backwards & cross
platform compatibility - (you may moan a little at some of them but
the first time you move yours source code onto a different
platform/os and it just works you will cheer).
3. Is there a difference between wx.PySimpleApp()
and wx.App()? In the above example it doesn’t seem to make a
difference. There’s some stuff about an ‘OnInit’ method that
differentiates them but that’s still beyond me.
To quote the built in helps:
wx.App - * Normally you would derive from this class and implement
an
OnInit
method that creates a frame and then calls
self.SetTopWindow(frame)
.*
wx.PySimpleApp - * A simple application class. You can just
create one of these and
then then make your top level windows later, and not have to worry
about OnInit. For example::
app = wx.PySimpleApp()
frame = wx.Frame(None, title='Hello World')
frame.Show()
app.MainLoop()*
A tip for you try opening a command prompt and typing:
***python
import wx
a=wx.App
s=wx.PySimpleApp
help(a)
help(s)***
This will let you have a look at the built in documentation. You
can even do the same for your own code as long as you document your
scripts and classes with the treble quote notation. Try the
following, (bold italic is what you type and italic the replies,
spaces are as usual vital):
***python
class myClass()
“”"
A class of my own.
“”"
def MyFn():
“”"
Some information about my function.
“”"
pass
def MyOtherFn():
“”"
This is another function.
“”"
pass
m = MyClass
help(m)
*** You will see:
*Help on class MyClass in module __main__:
class MyClass
> A class of my own.
>
> Methods defined here:
>
> MyFn()
> Some information about my function.
>
> MyOtherFn()
> This is another function.****
dir(m)***
*['MyFn', 'MyOtherFn', '__doc__', '__module__']****
help(m.MyFn)
** Help on method MyFn in module __main__:
MyFn() unbound __main__.MyClass method
Some information about my function.
documentation.
4. Sometimes I see code on the internet that has
wx.App(True) or wx.App(False) and I have no idea what that
boolean parameter sets.
This is also written as wx.App(redirect=True) or in full
wx.App(redirect=True, filename=None) which translates on windows/mac
as stdout and stderr should be redirected to a popup window so any
print or error outputs popup in a fresh window. If a filename is
given then such outputs will go to the file, if redirect = False,
then such output will go to the command window that the script was
started from, (if you started it by clicking on the script it will
be lost). Note that you can also toggle the application redirect
flag depending on the stage you are at or user options.
I hope the above is helpful.
BTW - Try to get into the habit of bottom posting, (where your text
goes at the end or after the bit you are answering), as it is the
preferred practice on this forum. It does make it a lot easier to
read the developing discussions that way.
Gadget/Steve
···
On 08/10/2011 9:32 AM, G. Nikiforov wrote: