[wxPython] Q: quick start examples?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[wxPython] Q: quick start examples?

Huaiyu Zhu-4
Hi,

I'm really impressed by the wxPython demos.  Are there stand-alone
examples for using them?

The tutorial only gives some very basic examples.  My attempt at using
the modules from demo invariably core dumps.  I'd like to see a minimum
program which can be used to call any given demo modules (by changing a
couple of lines).

Alternatively, could somebody provide some example for calling wxOGL,
PythonEvents, and Threads?  I'm going to have a canvas with two curves.  
User drags curve 1 to set parameters, while a numerical engine
continuously updated curve 2 using these parameters.  I guess I need all
these three modules.

BTW, while I'm at this, is it possible/easy to embed Octave in Python?
I've got years of Matlab/Octave codes and I prefer the syntax to NumPy.

Thanks a lot for any pointers.

--
Huaiyu Zhu [hidden email]


_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Q: quick start examples?

Ken Seehof-2
Try taking the frame code from pyTree or hangman in the "Cool Contributions"
section.
You should be able to put any of the demo windows in your own frame.  If you
still
have problems, send a simple example showing your code that core dumps.  I'm
sure
someone will help.


Huaiyu Zhu wrote:

> Hi,
>
> I'm really impressed by the wxPython demos.  Are there stand-alone
> examples for using them?
>
> The tutorial only gives some very basic examples.  My attempt at using
> the modules from demo invariably core dumps.  I'd like to see a minimum
> program which can be used to call any given demo modules (by changing a
> couple of lines).
>
> Alternatively, could somebody provide some example for calling wxOGL,
> PythonEvents, and Threads?  I'm going to have a canvas with two curves.
> User drags curve 1 to set parameters, while a numerical engine
> continuously updated curve 2 using these parameters.  I guess I need all
> these three modules.
>
> BTW, while I'm at this, is it possible/easy to embed Octave in Python?
> I've got years of Matlab/Octave codes and I prefer the syntax to NumPy.
>
> Thanks a lot for any pointers.
>
> --
> Huaiyu Zhu              [hidden email]
>
> _______________________________________________
> wxPython-users maillist  -  [hidden email]
> http://starship.python.net/mailman/listinfo/wxpython-users




_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Q: quick start examples?

Huaiyu Zhu-4
On Sat, 4 Mar 2000, Ken Seehof wrote:

> Try taking the frame code from pyTree or hangman in the "Cool
> Contributions" section. You should be able to put any of the demo
> windows in your own frame.  If you still have problems, send a simple
> example showing your code that core dumps.  I'm sure someone will
> help.

Thanks for the pointer.

It is not obvious to me how to incorporate these with pyOGL.  
Specifically they do not seem to make use of the variables nb and log
which appear everywhere in other demo modules.  I guess the core dumps was
due to my using simple-minded substitutes for them.

This time I made a maximum reduction and came up with the following code.  
Now it shows up a frame containing a small white area but does nothing
else.  Maybe I need to call runTest somewhere (which unfortunately
contains nb and log as arguments)?

Any further help would be greatly appreciated.  It would be extremely
helpful if someone could write a snippet in the if __name__ == "__main__"
style which could be attached to any demo modules.


"""
Testing pyOGL, adapted from pyTree
"""
from wxPython import wx
from wxOGL import * # module dependent

#----------------------------------------------------------------------
if __name__ == '__main__':
    class MyFrame(wx.wxFrame):
        def __init__(self):
            import __main__
            wx.wxFrame.__init__(self, wx.NULL, -1, "pyOGL stand-alone test",
                                wx.wxDefaultPosition, wx.wxSize(800,500))
            split = wx.wxSplitterWindow(self, -1)
            canvas = TestWindow(self, -1, __main__) #  module dependent

            text = wx.wxTextCtrl(split, -1, "", wx.wxDefaultPosition,
                                 wx.wxDefaultSize, wx.wxTE_MULTILINE)

            split.SplitVertically(canvas, text, 200) #  module dependent

    class MyApp(wx.wxApp):
        def OnInit(self):
            frame = MyFrame()
            frame.Show(wx.TRUE)
            self.SetTopWindow(frame)
            return wx.TRUE

    app = MyApp(0)
    app.MainLoop()


--
Huaiyu Zhu [hidden email]


>
>
> Huaiyu Zhu wrote:
>
> > Hi,
> >
> > I'm really impressed by the wxPython demos.  Are there stand-alone
> > examples for using them?
> >
> > The tutorial only gives some very basic examples.  My attempt at using
> > the modules from demo invariably core dumps.  I'd like to see a minimum
> > program which can be used to call any given demo modules (by changing a
> > couple of lines).
> >
> > Alternatively, could somebody provide some example for calling wxOGL,
> > PythonEvents, and Threads?  I'm going to have a canvas with two curves.
> > User drags curve 1 to set parameters, while a numerical engine
> > continuously updated curve 2 using these parameters.  I guess I need all
> > these three modules.
> >
> > BTW, while I'm at this, is it possible/easy to embed Octave in Python?
> > I've got years of Matlab/Octave codes and I prefer the syntax to NumPy.
> >
> > Thanks a lot for any pointers.
> >
> > --
> > Huaiyu Zhu              [hidden email]
> >
> > _______________________________________________
> > wxPython-users maillist  -  [hidden email]
> > http://starship.python.net/mailman/listinfo/wxpython-users
>
>
>


_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

[wxPython] Re: [Solved] Q: quick start examples?

Huaiyu Zhu-4
There was an error in my previous code.  The problem is now solved.
Here's a simple program that can be used to call some of these modules
without generating exceptions, but it does not work for those with split
windows or separate frames.  Hopefully it will be useful for other people
learning wxPython for the first time.

--
Huaiyu Zhu [hidden email]

"""
Stand-alone program for calling modules in wxPython/demo.
Call different modules by editing two module-dependent lines.
"""
from wxPython import wx

from wxOGL import TestWindow        # module-dependent
#from PrintFramework import TestPrintPanel  # module-dependent

class MyFrame(wx.wxFrame):
    def __init__(self, parent = wx.NULL, ID = -1, title = "wxPython test"):
        wx.wxFrame.__init__(self, parent, ID, title,
                            wx.wxDefaultPosition, wx.wxSize(400,300))
        self.CreateStatusBar()
        self.SetStatusText("This is the status bar")
             
class MyApp(wx.wxApp):
    def OnInit(self):
        parent = frame = MyFrame()
        log = -1

        win = TestWindow(parent, log, frame)    # module-dependent
        #win = TestPrintPanel(parent, log, frame)   # module-dependent
       
        frame.Show(wx.TRUE)
        return wx.TRUE

#----------------------------------------------------------------------
if __name__ == '__main__':

    app = MyApp(0)
    app.MainLoop()




_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Q: quick start examples?

Bill Eldridge-2
In reply to this post by Huaiyu Zhu-4

You can find the nb & log references in
/usr/lib/python1.5/site-examples/wxPython/demo/Main.py

nb refers to a wxNotebook,
log refers to a wxTextCtrl

So you probably need to look at lines like:

            self.nb = wxNotebook(frame, -1)
            # Set up a TextCtrl on the Overview Notebook page
            self.ovr = wxTextCtrl(self.nb, -1, style =
wxTE_MULTILINE|wxTE_READONLY)
            self.nb.AddPage(self.ovr, "Overview")
            #self.log = wxTextCtrl(frame, -1,"",(150,0),(50,100),
            self.log = wxTextCtrl(win3, -1,"",(0,300),(400,100),
                              style =
wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL)
            (w, self.charHeight) = self.log.GetTextExtent('X')
            self.log.WriteText('wxPython Demo Log:\n')



A quick Notebook example that includes the OGL demo (TestWindow):

#--------------------------------------------------------------

#!/usr/bin/python

from wxPython.wx import *
from wxOGL import *

class MyFrame(wx.wxFrame):
        def __init__(self):
            import __main__
            wxFrame.__init__(self, NULL, -1, "pyOGL stand-alone test",
                                wxDefaultPosition, wxSize(500,500))
            self.Show(TRUE)

class MyApp(wxApp):
        def OnInit(self):
            frame = MyFrame()
            win=wxWindow(frame,-1,(10,10),(500,500))
            mynb=wxNotebook(win,-1,(15,15),(400,400),style=wxNB_BOTTOM)
           
win1=wxWindow(mynb,-1,wxDefaultPosition,wxDefaultSize,wxRAISED_BORDER)
            win1.SetBackgroundColour(wxBLUE)
           
win2=wxWindow(mynb,-1,wxDefaultPosition,wxDefaultSize,wxRAISED_BORDER)
            win2.SetBackgroundColour(wxRED)
            win3 = TestWindow(mynb, -1, frame)
            mynb.AddPage(win1,"Blue",TRUE)
            mynb.AddPage(win2,"Red")
            mynb.AddPage(win3,"OGL")
           
            st=wxStaticText(win1,-1,"Just some Text",wxPoint(10,10))
            st.SetForegroundColour(wxWHITE)
            st.SetBackgroundColour(wxBLUE)


            frame.Show(TRUE)
            self.SetTopWindow(frame)
            return TRUE

        def OnPageChanged(self,event):
                print "Changed"
                event.Skip()


if __name__ == '__main__':
        app = MyApp(0)
        app.MainLoop()
#----------------------------------------------------------------------------------




Huaiyu Zhu wrote:

>
> On Sat, 4 Mar 2000, Ken Seehof wrote:
>
> > Try taking the frame code from pyTree or hangman in the "Cool
> > Contributions" section. You should be able to put any of the demo
> > windows in your own frame.  If you still have problems, send a simple
> > example showing your code that core dumps.  I'm sure someone will
> > help.
>
> Thanks for the pointer.
>
> It is not obvious to me how to incorporate these with pyOGL.
> Specifically they do not seem to make use of the variables nb and log
> which appear everywhere in other demo modules.  I guess the core dumps was
> due to my using simple-minded substitutes for them.
>
> This time I made a maximum reduction and came up with the following code.
> Now it shows up a frame containing a small white area but does nothing
> else.  Maybe I need to call runTest somewhere (which unfortunately
> contains nb and log as arguments)?
>
> Any further help would be greatly appreciated.  It would be extremely
> helpful if someone could write a snippet in the if __name__ == "__main__"
> style which could be attached to any demo modules.
>
> """
> Testing pyOGL, adapted from pyTree
> """
> from wxPython import wx
> from wxOGL import * # module dependent
>
> #----------------------------------------------------------------------
> if __name__ == '__main__':
>     class MyFrame(wx.wxFrame):
>         def __init__(self):
>             import __main__
>             wx.wxFrame.__init__(self, wx.NULL, -1, "pyOGL stand-alone test",
>                                 wx.wxDefaultPosition, wx.wxSize(800,500))
>             split = wx.wxSplitterWindow(self, -1)
>             canvas = TestWindow(self, -1, __main__) #  module dependent
>
>             text = wx.wxTextCtrl(split, -1, "", wx.wxDefaultPosition,
>                                  wx.wxDefaultSize, wx.wxTE_MULTILINE)
>
>             split.SplitVertically(canvas, text, 200) #  module dependent
>
>     class MyApp(wx.wxApp):
>         def OnInit(self):
>             frame = MyFrame()
>             frame.Show(wx.TRUE)
>             self.SetTopWindow(frame)
>             return wx.TRUE
>
>     app = MyApp(0)
>     app.MainLoop()
>
> --
> Huaiyu Zhu              [hidden email]
>
> >
> >
> > Huaiyu Zhu wrote:
> >
> > > Hi,
> > >
> > > I'm really impressed by the wxPython demos.  Are there stand-alone
> > > examples for using them?
> > >
> > > The tutorial only gives some very basic examples.  My attempt at using
> > > the modules from demo invariably core dumps.  I'd like to see a minimum
> > > program which can be used to call any given demo modules (by changing a
> > > couple of lines).
> > >
> > > Alternatively, could somebody provide some example for calling wxOGL,
> > > PythonEvents, and Threads?  I'm going to have a canvas with two curves.
> > > User drags curve 1 to set parameters, while a numerical engine
> > > continuously updated curve 2 using these parameters.  I guess I need all
> > > these three modules.
> > >
> > > BTW, while I'm at this, is it possible/easy to embed Octave in Python?
> > > I've got years of Matlab/Octave codes and I prefer the syntax to NumPy.
> > >
> > > Thanks a lot for any pointers.
> > >
> > > --
> > > Huaiyu Zhu              [hidden email]
> > >
> > > _______________________________________________
> > > wxPython-users maillist  -  [hidden email]
> > > http://starship.python.net/mailman/listinfo/wxpython-users
> >
> >
> >
>
> _______________________________________________
> wxPython-users maillist  -  [hidden email]
> http://starship.python.net/mailman/listinfo/wxpython-users

--
Bill Eldridge
Radio Free Asia
[hidden email]

_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Q: quick start examples?

Robin Dunn
In reply to this post by Huaiyu Zhu-4
> I'm really impressed by the wxPython demos.  Are there stand-alone
> examples for using them?
>
> The tutorial only gives some very basic examples.  My attempt at using
> the modules from demo invariably core dumps.  I'd like to see a minimum
> program which can be used to call any given demo modules (by changing a
> couple of lines).
>

Attached is a little program that should be able to run any of the indiviual
demos.  Output sent to the log will just go to sys.stdout.  To run it specify
the module name (not the file name) of one of the demos on the command line.

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!



run.py (2K) Download Attachment