Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 26th, 2006, 6:12 PM   #1
Yarvin
Programmer
 
Join Date: Sep 2005
Location: Anchorage, Alaska
Posts: 37
Rep Power: 0 Yarvin is on a distinguished road
Exclamation wxPython syntax error help.

I'm following the getting started tutorial here and when I try adding the OnOpen method I get this syntax error:
: python partTwo.py 
  File "partTwo.py", line 15
    filemenu.Append(ID_OPEN, '&Open', 'Open a file')
    ^
SyntaxError: invalid syntax
:

here is the full source code.

import os
import wx
ID_ABOUT=101
ID_EXIT=110
ID_OPEN=111
class MainWindow(wx.Frame):
    def __init__(self,parent,id,title):
        wx.Frame.__init__(self,parent,wx.ID_ANY, title, size = ( 200,100),
                                        style=wx.DEFAULT_FRAME_STYLE|
                                        wx.NO_FULL_REPAINT_ON_RESIZE)
        self.control = wx.TextCtrl(self, 1, style=wx.TE_MULTILINE)
        self.CreateStatusBar() # A StatusBar in the bottom of the window
        # Setting up the menu.
        filemenu= wx.Menu()
		filemenu.Append(ID_OPEN, '&Open', 'Open a file')
        filemenu.Append(ID_ABOUT, "&About"," Information about this program")
        filemenu.AppendSeparator()
        filemenu.Append(ID_EXIT,"E&xit"," Terminate the program")
        # Creating the menubar.
        menuBar = wx.MenuBar()
        menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the MenuBar
        self.SetMenuBar(menuBar)  # Adding the MenuBar to the Frame content.
        wx.EVT_MENU(self, ID_ABOUT, self.OnAbout) # attach the menu-event ID_ABOUT to the
                                                           # method self.OnAbout
        wx.EVT_MENU(self, ID_EXIT, self.OnExit)   # attach the menu-event ID_EXIT to the
                                                           # method self.OnExit
		wx.EVT_MENU(self, ID_OPEN, self.OnOpen)
        self.Show(True)
    def OnAbout(self,e):
        d= wx.MessageDialog( self, " A sample editor \n"
                            " in wxPython","About Sample Editor", wx.OK)
                            # 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"""
        self.dirname = ''
        dlg = wx.FileDialog(self, "Choose a file", self.dirname, "", "*.*", wx.OPEN)
        if dlg.ShowModal() == wx.ID_OK:
            self.filename=dlg.GetFilename()
            self.dirname=dlg.GetDirectory()
            f=open(os.path.join(self.dirname,self.filename),'r')
            self.control.SetValue(f.read())
            f.close()
        dlg.Destroy()
app = wx.PySimpleApp()
frame = MainWindow(None, -1, "Sample editor")
app.MainLoop()

I'm running this on Mac OS 10.4.7 with Python 2.4.3 and wxPython 2.6.

any and all help is very much appreciated thank you.

Alvin
Yarvin is offline   Reply With Quote
Old Jul 26th, 2006, 6:20 PM   #2
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,888
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
In Python, indentation matters. You must keep the level of all indented blocks the same. You have some lines that are randomly bumped out of place.

Also, you can not add multiple strings together by merely placing one beneath an other. You need to use triple quotes """ to enclose multi-line text.

"""this is the first line
this is the second line"""
Sane is offline   Reply With Quote
Old Jul 26th, 2006, 9:12 PM   #3
Yarvin
Programmer
 
Join Date: Sep 2005
Location: Anchorage, Alaska
Posts: 37
Rep Power: 0 Yarvin is on a distinguished road
the indent is a mistake in my posting it to the forum. this is how the code looks on my screen: image

as for the comments. thats how the comments were on the tutorial, I never touched them. all I'm trying to do is add the OnOpen method as an excerise.
__________________
[ADM]art
Yarvin is offline   Reply With Quote
Old Jul 26th, 2006, 9:15 PM   #4
Yarvin
Programmer
 
Join Date: Sep 2005
Location: Anchorage, Alaska
Posts: 37
Rep Power: 0 Yarvin is on a distinguished road
ok I figured it out! it was the text editor that I'm using. when I opened it in vim I saw the lines that were out of place.

thanks for the help.
__________________
[ADM]art
Yarvin is offline   Reply With Quote
Old Jul 26th, 2006, 9:29 PM   #5
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,888
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Oh, wow. That multiline literal worked? I never knew you could concact them by simply starting a new literal on the next line... heh.

Glad you figured it out.
Sane is offline   Reply With Quote
Old Jul 26th, 2006, 9:31 PM   #6
Yarvin
Programmer
 
Join Date: Sep 2005
Location: Anchorage, Alaska
Posts: 37
Rep Power: 0 Yarvin is on a distinguished road
well yeah... with the multi-line literal I can see the whole line if code without having to adjust the size of my text editor... it really helps
__________________
[ADM]art
Yarvin is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
C# corruption!!! Kilo C++ 32 May 21st, 2006 8:44 PM
Masm rsnd Assembly 4 May 20th, 2006 9:05 PM
From C syntax to C++ syntax Navid C++ 13 Jan 15th, 2006 7:42 AM
Cobra Sane Python 18 Aug 22nd, 2005 5:19 PM
syntax problems. troubleshooter Bash / Shell Scripting 2 Apr 5th, 2005 9:34 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:21 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC