cannot compile my wxPython frame code

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

cannot compile my wxPython frame code

Jaffar
Hi.  I am using wxPython 2.91 Devel with python 2.7 on a 64 bit,
Windows7 AMD processor.  I am mdeveloping an app, still in its first
stages of development.  Here's the code for the windows skeleton.

import wx
class Myapp(wx.App):
    def OnInit(self):
        self.frame = Myframe(None, title="AccessibleWebPad")
        self.SetTopWindow(self.frame)
        self.frame.Show()
        return True
class MyFrame(wx.Frame):
    def __init__(self, parent, id=wx.ID_ANY, title="",
pos=wx.DefaultPosition, size=wx.DefaultSize,
style=wx.DEFAULT_FRAME_STYLE, name ="MyFrane"):
        super(MyFrame, self).__init__(parent, id, title, pos, size,
style, name)
# Attributes
self.panel = wx.Panel(self)
if __name__ == "__main__":
    app = MyApp(False)
    app.MainLoop()  My problem is that this code refuses to compile
because python complains the the name self is undefined.  Where have i
gone wrong, and what changes, if any, do i have to make to resolve
this issue?  Thanks.

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: cannot compile my wxPython frame code

werner
On 06/01/2011 01:43 AM, Jaffar wrote:
> Hi.  I am using wxPython 2.91 Devel with python 2.7 on a 64 bit,
> Windows7 AMD processor.  I am mdeveloping an app, still in its first
> stages of development.  Here's the code for the windows skeleton.
Indentation and case is significant in Python, attached works for me on
Python 2.6.6 on Ubuntu 10.10 with wxPython 2.8.12.0.

It is better to attach to ensure that indentation is not getting messed up.

Werner

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en

jaffar.py (888 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: cannot compile my wxPython frame code

Jaffar
Hi.  My Mistake as I didn’t think of attaching the file instead of copying the code onto my email.  So Here’s the attachment.  Please take a look at the file and give me some suggestions as I am rather stuck.  Thanks and cheers
 
 
Date: Wednesday, June 01, 2011 3:52 PM
Subject: Re: [wxPython-users] cannot compile my wxPython frame code
 
On 06/01/2011 01:43 AM, Jaffar wrote:
> Hi.  I am using wxPython 2.91 Devel with python 2.7 on a 64 bit,
> Windows7 AMD processor.  I am mdeveloping an app, still in its first
> stages of development.  Here's the code for the windows skeleton.
Indentation and case is significant in Python, attached works for me on
Python 2.6.6 on Ubuntu 10.10 with wxPython 2.8.12.0.

It is better to attach to ensure that indentation is not getting messed up.

Werner

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en

BasicApp.py (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: cannot compile my wxPython frame code

Robin Dunn
On 6/1/11 9:32 AM, [hidden email] wrote:
> Hi. My Mistake as I didn’t think of attaching the file instead of
> copying the code onto my email. So Here’s the attachment. Please take a
> look at the file and give me some suggestions as I am rather stuck.

Did you actually read all of Werner's message and compare his working
attachment with yours?  Indentation is an important part of the syntax
in Python, but half the lines in your sample code are not indented at all.

--
Robin Dunn
Software Craftsman
http://wxPython.org

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: cannot compile my wxPython frame code

werner
In reply to this post by Jaffar
On 06/01/2011 06:32 PM, [hidden email] wrote:
Hi.  My Mistake as I didn’t think of attaching the file instead of copying the code onto my email.  So Here’s the attachment.  Please take a look at the file and give me some suggestions as I am rather stuck.  Thanks and cheers
Your problems are:
- indentation
- case

Corrected version is attached, use a diff program to see what I changed to make them work.

You might want to check out some or all of the following:

- THE Book - wxPython in Action by Robin Dunn
- THE other Book - wxPython 2.8 by Cody Precord
- http://wiki.wxpython.org/How%20to%20Learn%20wxPython
- http://wiki.wxpython.org/Getting%20Started

And obviously you can still keep asking questions here.

Werner

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en

BasicApp.py (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: cannot compile my wxPython frame code

Tim Roberts
In reply to this post by Jaffar
[hidden email] wrote:
Hi.  My Mistake as I didn’t think of attaching the file instead of copying the code onto my email.  So Here’s the attachment.  Please take a look at the file and give me some suggestions as I am rather stuck.  Thanks and cheers

Werner showed you the exact solution in the file the HE attached.  Did you just skip right over that?

Indentation is critical to syntax in Python.  It's not just comments, like in other languages.  Your intendentation is screwed up.  Those statements starting with "self.panel" are not seen as part of the MyFrame.__init__ function.  They are seen as global statements, and at the global level, you do not have a name called "self".

You need to indent those 5 "self" lines so they line up at the same level as the "super" call.  Then, make sure that the "def OnButton" is one level out, at the same level as the "def __init__" statement.
-- 
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: cannot compile my wxPython frame code

Jaffar
In reply to this post by Robin Dunn
Ah.  I’ll take another look.  Part of the reason is that My Screen reader doesn’t tell me if those blocks of my code that need indenting are really indented correctly or not.  I am also rather new to Python and WxPython, so I can foresee that indentation will be an issue for me for a while.  Thanks and cheers!
 
Date: Thursday, June 02, 2011 1:22 AM
Subject: Re: [wxPython-users] cannot compile my wxPython frame code
 
On 6/1/11 9:32 AM, [hidden email] wrote:
> Hi. My Mistake as I didn’t think of attaching the file instead of
> copying the code onto my email. So Here’s the attachment. Please take a
> look at the file and give me some suggestions as I am rather stuck.

Did you actually read all of Werner's message and compare his working
attachment with yours?  Indentation is an important part of the syntax
in Python, but half the lines in your sample code are not indented at all.

--
Robin Dunn
Software Craftsman
http://wxPython.org

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: cannot compile my wxPython frame code

Chris Barker - NOAA Federal
[hidden email] wrote:
> Ah.  I’ll take another look.  Part of the reason is that My Screen
> reader doesn’t tell me if those blocks of my code that need indenting
> are really indented correctly or not.

I take it you are visually impaired?

Unfortunately, the indentation syntax of Python, while great for to
those of us that are sighted, is a known issue for folks that use screen
readers.

If you google a bit, you'll probably find multiple discussions of the
issue -- there was one on the Seattle Python Interest Group (SEAPIG)
recently, for instance. Here is that URL:

http://comments.gmane.org/gmane.comp.python.org.seattle/772

I suggest you scan those discussions and see if you can find an
editor/screen reader combination that is known to work well with Python
indentation, or it will be very painful to code in Python.

-good luck!




  I am also rather new to Python

> and WxPython, so I can foresee that indentation will be an issue for me
> for a while.  Thanks and cheers!
>  
> *From:* Robin Dunn <mailto:[hidden email]>
> *Date:* Thursday, June 02, 2011 1:22 AM
> *To:* [hidden email]
> <mailto:[hidden email]>
> *Subject:* Re: [wxPython-users] cannot compile my wxPython frame code
>  
> On 6/1/11 9:32 AM, [hidden email] wrote:
>  > Hi. My Mistake as I didn’t think of attaching the file instead of
>  > copying the code onto my email. So Here’s the attachment. Please take a
>  > look at the file and give me some suggestions as I am rather stuck.
>
> Did you actually read all of Werner's message and compare his working
> attachment with yours?  Indentation is an important part of the syntax
> in Python, but half the lines in your sample code are not indented at all.
>
> --
> Robin Dunn
> Software Craftsman
> http://wxPython.org
>
> --
> To unsubscribe, send email to [hidden email]
> or visit http://groups.google.com/group/wxPython-users?hl=en
>
> --
> To unsubscribe, send email to [hidden email]
> or visit http://groups.google.com/group/wxPython-users?hl=en


--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

[hidden email]

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: cannot compile my wxPython frame code

Jaffar
Hi.  Thanks for the url.  Yes I am visually impaired, but I really like python because of it’s relatively easier learning curve.  I’ll take a look at your recommended resource.  Hopefully it will help.  Cheers!
 
 
Date: Thursday, June 02, 2011 3:21 AM
Subject: Re: [wxPython-users] cannot compile my wxPython frame code
 
[hidden email] wrote:
> Ah.  I’ll take another look.  Part of the reason is that My Screen
> reader doesn’t tell me if those blocks of my code that need indenting
> are really indented correctly or not.

I take it you are visually impaired?

Unfortunately, the indentation syntax of Python, while great for to
those of us that are sighted, is a known issue for folks that use screen
readers.

If you google a bit, you'll probably find multiple discussions of the
issue -- there was one on the Seattle Python Interest Group (SEAPIG)
recently, for instance. Here is that URL:

http://comments.gmane.org/gmane.comp.python.org.seattle/772

I suggest you scan those discussions and see if you can find an
editor/screen reader combination that is known to work well with Python
indentation, or it will be very painful to code in Python.

-good luck!




  I am also rather new to Python

> and WxPython, so I can foresee that indentation will be an issue for me
> for a while.  Thanks and cheers!

> *From:* Robin Dunn <mailto:[hidden email]>
> *Date:* Thursday, June 02, 2011 1:22 AM
> *To:* [hidden email]
> <mailto:[hidden email]>
> *Subject:* Re: [wxPython-users] cannot compile my wxPython frame code

> On 6/1/11 9:32 AM, [hidden email] wrote:
>  > Hi. My Mistake as I didn’t think of attaching the file instead of
>  > copying the code onto my email. So Here’s the attachment. Please take a
>  > look at the file and give me some suggestions as I am rather stuck.
>
> Did you actually read all of Werner's message and compare his working
> attachment with yours?  Indentation is an important part of the syntax
> in Python, but half the lines in your sample code are not indented at all.
>
> --
> Robin Dunn
> Software Craftsman
> http://wxPython.org
>
> --
> To unsubscribe, send email to [hidden email]
> or visit http://groups.google.com/group/wxPython-users?hl=en
>
> --
> To unsubscribe, send email to [hidden email]
> or visit http://groups.google.com/group/wxPython-users?hl=en


--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

[hidden email]

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: cannot compile my wxPython frame code

Ray Pasco-4
I'm a bit surprised that everyone has said that indentation is important, yet no one, so far, has given you tips on how to go about maintaining good indentation. While tab characters can be used for indents, it's highly recommended to use 4 spaces for each level of indentation. Depending on the editor, tab chars get interpreted differently.

Get an editor specifically targeted or "target-able" for the Python language syntax. That will enable two important things: 1) Automatically create 4-space indentations when the <TAB> key is pressed; 2) Automatically produce colorized syntax highlighting specifically for Python keywords. 3) Many "Python enabled" text editors will provide Python syntax tool tips that pop up common method names as you type to help you find the one you want.

I happen to use TextPad which provides features 1) and 2) mentioned above. Everyone has their own preferences. For a start, see PythonEditors.

Maintaining indentation is made much, much simpler using comments as code block terminators. Python syntax doesn't require one like older languages such as C, but using one, even if it's artificial, helps people, not the interpreter/compiler. Sea the short attached file for a sample. Very short code blocks don't need a block terminator comment to give block-start/block-end visual symmetry.

Ray Pasco

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en

ButtonEvents.py (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: cannot compile my wxPython frame code

Robin Dunn
On 6/2/11 9:07 AM, Ray Pasco wrote:
> Get an editor specifically targeted or "target-able" for the Python
> language syntax. That will enable two important things: 1) Automatically
> create 4-space indentations when the <TAB> key is pressed; 2)
> Automatically produce colorized syntax highlighting specifically for
> Python keywords. 3) Many "Python enabled" text editors will provide
> Python syntax tool tips that pop up common method names as you type to
> help you find the one you want.

If I understand correctly,  none of these things will be much help for a
blind person using a screen reader.  :-(

--
Robin Dunn
Software Craftsman
http://wxPython.org

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: cannot compile my wxPython frame code

Ray Pasco-4
I don't remember him stating that he is using a text reader, only that he is visually impaired (legally blind ?). Maybe a screen magnifier is being used.

If a text reader is being used there is likely to be some kind of programmable feedback filter. There should be a way of tuning the feedback mechanism for identifying such lines as "#end if" to help avoid information overload by reading back only these particular comments all the time.

Ray

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: cannot compile my wxPython frame code

Mike Driscoll
The OP said this: "Part of the reason is that My Screen reader doesn’t tell me if those blocks of my code that need indenting are really indented correctly or not."  So it sounds like his screen reader doesn't tell him about indentation all that well.

- Mike

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: cannot compile my wxPython frame code

Rufus V. Smith
One possible solution (or more appropriately: workaround) might help:
 
    The OP can add comment lines, such as
   
        #outdent
 
    or
 
        #outdent <level>
 
at the end of indented blocks.
 
The source code could then be scanned by very simple program which allow indents (thereby not concerning
itself with python syntax), but requiring outdented lines to have been immediately preceded by such a comment line.
 
Rufus
   
----- Original Message -----
Sent: Thursday, June 02, 2011 2:00 PM
Subject: Re: [wxPython-users] cannot compile my wxPython frame code

The OP said this: "Part of the reason is that My Screen reader doesn’t tell me if those blocks of my code that need indenting are really indented correctly or not."  So it sounds like his screen reader doesn't tell him about indentation all that well.

- Mike

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: cannot compile my wxPython frame code

Jaffar
In reply to this post by Ray Pasco-4
Hi.  I am very dependent on a text to speech screen reader to tell me what’s happening on screen because I don’t have any sight to depend on.  I wish there are more transparent ways to make python coding less of a challenge, but there we are, – we can’t have everything in life.  All I can say for now is that I like wxPython, and I shouldn’t allow a small stumbler like indentation get in the way of progress.  Thanks for all the suggestions.  If I progress enough with wxPython, I might, develop a Python IDE in the future to help overcome this challenge.  But for now, I’ll find my way to work around this problem.  Cheers!
 
 
 
Date: Friday, June 03, 2011 1:44 AM
Subject: Re: [wxPython-users] cannot compile my wxPython frame code
 
I don't remember him stating that he is using a text reader, only that he is visually impaired (legally blind ?). Maybe a screen magnifier is being used.

If a text reader is being used there is likely to be some kind of programmable feedback filter. There should be a way of tuning the feedback mechanism for identifying such lines as "#end if" to help avoid information overload by reading back only these particular comments all the time.

Ray
--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: cannot compile my wxPython frame code

Chris Weisiger
The simplest solution I can think of to this problem is to imitate the joke of how your average C++ programmer programs when they first switch to Python:

for i in xrange(10: #{
    if i % 2: #{
        print "i is even"
    #}
    else: #{
        print "i is odd"
    #}
#}

Then you can run your code through a postprocessing script that enforces appropriate indentation levels by counting the number of curly braces they've seen in comments.

This simple script should handle most situations. The main sticking point is if you want to have the '#' character in a string. Multiline strings would also get their whitespace mangled. I didn't spend much time on it; it's more a proof of concept than anything else. It reads from standard input and writes the "corrected" file to standard output.

import re
import sys
curIndentLevel = 0
for line in sys.stdin: #{
    line = line.lstrip().rstrip()
    print ('    ' * curIndentLevel) + line
    if re.search('#.*\\{', line): #{
        curIndentLevel += 1
    #}
    elif re.search('#.*\\}', line): #{
        curIndentLevel -= 1
    #}

-Chris

On Thu, Jun 2, 2011 at 3:38 PM, [hidden email] <[hidden email]> wrote:
Hi.  I am very dependent on a text to speech screen reader to tell me what’s happening on screen because I don’t have any sight to depend on.  I wish there are more transparent ways to make python coding less of a challenge, but there we are, – we can’t have everything in life.  All I can say for now is that I like wxPython, and I shouldn’t allow a small stumbler like indentation get in the way of progress.  Thanks for all the suggestions.  If I progress enough with wxPython, I might, develop a Python IDE in the future to help overcome this challenge.  But for now, I’ll find my way to work around this problem.  Cheers!
 
 
 
Date: Friday, June 03, 2011 1:44 AM
Subject: Re: [wxPython-users] cannot compile my wxPython frame code
 
I don't remember him stating that he is using a text reader, only that he is visually impaired (legally blind ?). Maybe a screen magnifier is being used.

If a text reader is being used there is likely to be some kind of programmable feedback filter. There should be a way of tuning the feedback mechanism for identifying such lines as "#end if" to help avoid information overload by reading back only these particular comments all the time.

Ray
--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en