[wxPython] Looking for a sample project of the wxPython

Dear

I’m a beginner of the wxPython.

I’m looking for a sample project of the Python and wxPython for study.

The demo of the wxPython is good but it’s difficult to understand the wxPython totally.

Where is a sample project of the wxPython?

Thanks

Where is a sample project of the wxPython?

In the 2.3.0 distribution of wxPython there are a few smaller sample apps in
wxPython/sampes.

There is also a (work in progress) getting started guide here:

http://wxpython.org/cgi-bin/wiki/Getting_20Started

···

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

Thank you for your answer.

I've tested a sample file in the site.

The program is executed correctly.

But I've quited the program by the menu "exit" button.

And run again and exit repeatly 2-3 times.

The Python shut down.

I've installed the Activepython 2.1.211 and wxpython (the latest ver.).

I have no idea whether the python has a problem or the wxpython has.

Would you mind testing it?

(This is the program)

from wxPython.wx import *
ID_ABOUT=101
ID_OPEN=102
ID_BUTTON1=110
ID_EXIT=200
class MainWindow(wxFrame):
    def __init__(self,parent,id,title):
        self.dirname=''
        wxFrame.__init__(self,parent,-4, title, style=wxDEFAULT_FRAME_STYLE|
                                        wxNO_FULL_REPAINT_ON_RESIZE)
        self.control = wxTextCtrl(self, 1, style=wxTE_MULTILINE)
        self.CreateStatusBar() # A Statusbar in the bottom of the window
        # Setting up the menu.
        filemenu= wxMenu()
        filemenu.Append(ID_OPEN, "&Open"," Open a file to edit")
        filemenu.AppendSeparator()
        filemenu.Append(ID_ABOUT, "&About"," Information about this program")
        filemenu.AppendSeparator()
        filemenu.Append(ID_EXIT,"E&xit"," Terminate the program")
        # Creating the menubar.
        menuBar = wxMenuBar()
        menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the MenuBar
        self.SetMenuBar(menuBar) # Adding the MenuBar to the Frame content.
        EVT_MENU(self, ID_ABOUT, self.OnAbout)
        EVT_MENU(self, ID_EXIT, self.OnExit)
        EVT_MENU(self, ID_OPEN, self.OnOpen)

        self.sizer2 = wxBoxSizer(wxHORIZONTAL)
        self.buttons=
        for i in range(0,6):
            self.buttons.append(wxButton(self, ID_BUTTON1+i, "Button &"+`i`))
            self.sizer2.Add(self.buttons[i],1,wxEXPAND)

        # Use some sizers to see layout options
        self.sizer=wxBoxSizer(wxVERTICAL)
        self.sizer.Add(self.control,1,wxEXPAND)
        self.sizer.Add(self.sizer2,0,wxEXPAND)
         
        #Layout sizers
        self.SetSizer(self.sizer)
        self.SetAutoLayout(1)
        self.sizer.Fit(self)

        self.Show(1)

    def OnAbout(self,e):
        d= wxMessageDialog( self, " A sample editor \n"
                            " in wxPython","About Sample Editor", wxOK)
                            # Create a message dialog box
        d.ShowModal() # Shows it
        d.Destroy() # finally destroy it when finished.

    def OnExit(self,e):
        self.Close(true) # Close the frame.

    def OnOpen(self,e):
        """ Open a file"""
        dlg = wxFileDialog(self, "Choose a file", self.dirname, "", "*.*", wxOPEN)
        if dlg.ShowModal() == wxID_OK:
            self.filename=dlg.GetFilename()
            self.dirname=dlg.GetDirectory()
            f=open(self.dirname+'\\'+self.filename,'r')
            self.control.SetValue(f.read())
            f.close()
        dlg.Destroy()
         
app = wxPySimpleApp()
frame = MainWindow(None, -1, "Sample editor")
frame.Show(1)
app.MainLoop()

···

----- Original Message -----
From: "Robin Dunn" <robin@alldunn.com>
To: <wxpython-users@lists.wxwindows.org>
Sent: Saturday, June 16, 2001 12:11 PM
Subject: Re: [wxPython] Looking for a sample project of the wxPython

> Where is a sample project of the wxPython?

In the 2.3.0 distribution of wxPython there are a few smaller sample apps in
wxPython/sampes.

There is also a (work in progress) getting started guide here:

http://wxpython.org/cgi-bin/wiki/Getting_20Started

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

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

Song wrote:

Would you mind testing it?

        dlg = wxFileDialog(self, "Choose a file", self.dirname, "", "*.*", wxOPEN)
        if dlg.ShowModal() == wxID_OK:
            self.filename=dlg.GetFilename()
            self.dirname=dlg.GetDirectory()
            f=open(self.dirname+'\\'+self.filename,'r')

You should use os.path.join, rather than +"\\"+ (which only works on windows)

            f=open(os.path.join(self.dirname,self.filename),'r')

Other than that, this code works fine on Linux (python 2.0, wxPython 2.3.0)

Thanks

But in Activepython's IDLE it is shut down in executing repeatedly.

I do worry about developing and debugging in IDLE.

Let me know how to develope a python code efficiently.

···

----- Original Message -----
From: "Terrel Shumway" <tshumway@ics.uci.edu>
To: <wxpython-users@lists.wxwindows.org>
Sent: Sunday, June 17, 2001 2:31 PM
Subject: Re: [wxPython] Looking for a sample project of the wxPython

Song wrote:

> Would you mind testing it?

> dlg = wxFileDialog(self, "Choose a file", self.dirname, "", "*.*", wxOPEN)
> if dlg.ShowModal() == wxID_OK:
> self.filename=dlg.GetFilename()
> self.dirname=dlg.GetDirectory()
> f=open(self.dirname+'\\'+self.filename,'r')
>

You should use os.path.join, rather than +"\\"+ (which only works on windows)

            f=open(os.path.join(self.dirname,self.filename),'r')

Other than that, this code works fine on Linux (python 2.0, wxPython 2.3.0)

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

But in Activepython's IDLE it is shut down in executing repeatedly.

I do worry about developing and debugging in IDLE.

Let me know how to develope a python code efficiently.

Since both IDLE Pythonwin use a different GUI toolkit than wxPython, they do
not operate well together. It is an issue of different event loops trying
to control the total (combined) application.

Unlike other programming environments, you do not have to use the IDE that
comes with it in order to use the language. You can use whatever text
editor you like and execute your python programs from a separate command
line.

There is also Boa Constructor (http://boa-constructor.sourceforge.net/)
which is an IDE written with wxPython for developing wxPython applications.

···

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