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.
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.
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
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.
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.
···
On 6/1/11 9:32 AM, jaffar@gmail.com 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.
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
And obviously you can still keep asking questions here.
Werner
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
wrote:
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.
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
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!
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.
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:
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:robin@alldunn.com>
*Date:* Thursday, June 02, 2011 1:22 AM
*To:* wxpython-users@googlegroups.com <mailto:wxpython-users@googlegroups.com>
*Subject:* Re: [wxPython-users] cannot compile my wxPython frame code
On 6/1/11 9:32 AM, jaffar@gmail.com 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.
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
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!
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:
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!
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.
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
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 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.
If I understand correctly, none of these things will be much help for a blind person using a screen reader.
···
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.
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.
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.
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.
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!
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.
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
#}
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!
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.