Deal of the Day

Home » Main » Manning Forums » 2006 » wxPython in Action

Thread: Chapter 6 Anomalies & Fixes

Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 10 - Pages: 1 - Last Post: Feb 9, 2010 11:47 PM by: Kit_2010
Kit_2010

Posts: 13
From: West Hills, Calif.
Registered: 1/23/10
Chapter 6 Anomalies & Fixes
Posted: Feb 9, 2010 12:12 PM
  Click to reply to this thread Reply

IMPORTANT NOTE: I understand that the purpose of Chapter 6 is to show examples of how the various wxPython modules can glue together to make a completed, multi-featured program. It was NOT intended to create a perfected Sketch program.

However, there are several errors and/or omissions which can cause runtime anomalies and other confusion. As a novice in Python, a newbie to wxPython, and a person still attempting to fully comprehend OOP in general, these anomalies would often cause me some some time to sort out. Often it was difficult to determine when I was making actual coding mistakes, or was simply encountering errors/omissions in the book.

This was especially true for me, as I insisted on entering all the code manually myself, rather than downloading the source code from the Manning website, and just double-clicking on it. To me, entering your own code is a much better way to understand the code at a fundamental level (I did use the downloaded code for troubleshooting purposes, though).


To assist others in approaching code this way, I have provided this list of anomalies that can be found in Chapter 6. These are the known issues that I am aware of. Each of these items result in some sort of error or program anomaly when run.


Each listed problem is assigned an ISSUE # for reference, along with a brief description of the problem involved. Note that the Issues are not necessarily listed in the same order as they can occur in the chapter.

Check the Reply area to see if there is a solution or suggestion that matches the referenced Issue #. Not all problems are resolved at this point, and the Forum is encouraged to contribute suggestions that will help resolve these outstanding points. Additional problems not listed here are also welcome.

Please note that these problems are provided as information for general Forum knowledge and discussions only, and IT IS NOT EXPECTED TO HAVE THE AUTHORS RESOLVE ANY OF THESE ISSUES PERSONALLY. Of course, their comments and suggestions are always honored and welcome.

Also note that the below listed Issues were detected on Windows OS platforms, but are most likely manifesting on other platforms as well.

I sincerely hope this thread helps the other wxPython newbies on this site.

====================

Issue #1: Listing 6.5 - Program prematurely aborts at runtime with error after adding programming for including a Toolbar.


Issue #2: Nothing happens when the NEW Toolbar button is pressed, or selected from the Menu.


Issue #3: Listing 6.6 - File Operations don't work.


Issue #4: Listing 6.9 - Line Thickness Control Panel buttons do not change line thickness.


Issue #5: Listing 6.11 - Program prematurely aborts at runtime with error after adding programming for including a Splash Screen.


Issue #6: Listing 6.11 - Clicking on Splash Screen with mouse causes Splash Screen to disappear correctly, but creates an unwanted line extending from the upper left screen corner to the position of the mouse click.


Issue #7: Listing 6.10 - HTML doesn't work when adding an About Box.


Issue #8: Listing 6.9 - Buttons don't work on Control Panel.


Issue #9: Listing 6.9 - Control Panel buttons will not change line color after selecting a color with the Color Picker Dialog Box.


Issue #10: When a line color is changed using any tool or menu, the color change indication is not reflected on any of the other color-changing tools.

Kit_2010

Posts: 13
From: West Hills, Calif.
Registered: 1/23/10
Re: Issue #1
Posted: Feb 9, 2010 12:13 PM   in response to: Kit_2010 in response to: Kit_2010
  Click to reply to this thread Reply

RE Issue #1: Part of the Toolbar programming involves the loading of bitmaps to be placed atop the File Handling buttons; specifically, a BMP picture for Open(open.bmp), Save(save.bmp), and New(new.bmp).

This form of picture importation requires that the picture files called upon be placed in the same directory as the Python program calling them(or appropriate paths must be included in the call).

The problem here is that the bmp pictures required must either be generated by the programmer, or downloaded in the book source code provided at www.manning.com. These bmps can be found under the subdirectory Chapter-06. Copy these files into the same directory as your Sketch program.

Kit_2010

Posts: 13
From: West Hills, Calif.
Registered: 1/23/10
Re: Issue #2
Posted: Feb 9, 2010 12:14 PM   in response to: Kit_2010 in response to: Kit_2010
  Click to reply to this thread Reply

RE Issue #2: This is a deliberate omission of code by the authors. The OnNew method has only a pass statement there.

Forum member wxNewbie noted this on an earlier thread. Robin Dunn replied that this should be considered as an "exercise for the reader".

Forum discussions on approaches to implement this code would be stimulating and welcome.

Kit_2010

Posts: 13
From: West Hills, Calif.
Registered: 1/23/10
Re: Issue #3
Posted: Feb 9, 2010 12:15 PM   in response to: Kit_2010 in response to: Kit_2010
  Click to reply to this thread Reply

RE Issue #3: The code in Listing 6.6 depends on Python modules that must be first imported into the main program body, after which can be accessed the basic operating system and pickling methods.

Add to the import list at the top of your file the following:

import cPickle
import os

Kit_2010

Posts: 13
From: West Hills, Calif.
Registered: 1/23/10
Re: Issue #4
Posted: Feb 9, 2010 12:16 PM   in response to: Kit_2010 in response to: Kit_2010
  Click to reply to this thread Reply

RE Issue #4: This is a bit of an outstanding mystery. Book Figure 6.6 shows this feature evidently functioning, yet it does not. There is a module called OnSetThickness with code below it, but apparently this code does not function to change line thickness.

Downloading the source code from www.manning.com sheds no light on the issue; the line thickness does not change with their code either.

Forum discussions on approaches to re-evaluate this code would be stimulating and welcome.

Kit_2010

Posts: 13
From: West Hills, Calif.
Registered: 1/23/10
Re: Issue #5
Posted: Feb 9, 2010 12:17 PM   in response to: Kit_2010 in response to: Kit_2010
  Click to reply to this thread Reply

RE Issue #5: The Splash Screen code uses the bitmap importation technique, as was discussed in Issue #1. So a picture file named splash.bmp must be included in the same directory as the Sketch program. As with the File button images, the picture file for the Splash Screen is included in the source code downloaded from www.manning.com, under the subdirectory Chapter-06.

But this issue has a second bug; the code for the Splash Screen requires a BMP picture file. The picture provided by Manning in its source code is a PNG picture file(splash.png). Therefore, the code can't find the right file, and errors.

The fix for this is to change the first line of the OnInit method of the SketchApp class to the following:

image = wx.Image("splash.png", wx.BITMAP_TYPE_PNG)

Kit_2010

Posts: 13
From: West Hills, Calif.
Registered: 1/23/10
Re: Issue #6
Posted: Feb 9, 2010 12:18 PM   in response to: Kit_2010 in response to: Kit_2010
  Click to reply to this thread Reply

RE Issue #6: This is an anomaly of the drawMotion method, where each mouse click appends a line extending from self.pos to new.pos.

When the Splash Screen method completes, self.pos will normally track and be set to the current mouse position by the OnLeftDown method.

But while the Splash Screen is present, the rest of the program is still in its initialized state, and that means that self.pos is (0,0), which is the upper left corner of the client area. The value new.pos will be a completion of a mouse click, which has occurred on the Splash Screen.

The result is an unwanted line extending from the upper left corner of the client area to where the mouse was clicked.

Obviously, a "hold off" procedure is required to keep the drawMotion method from operating while the Splash Screen timeout is still in operation.

Forum discussions on approaches to implement this code would be stimulating and welcome.

Kit_2010

Posts: 13
From: West Hills, Calif.
Registered: 1/23/10
Re: Issue #7
Posted: Feb 9, 2010 12:19 PM   in response to: Kit_2010 in response to: Kit_2010
  Click to reply to this thread Reply

RE Issue #7: The code in Listing 6.10 depends on the wxPython module that must be first imported into the main program body, after which can be accessed the HTML methods.

Add to the import list at the top of your file the following:

import wx.html

Kit_2010

Posts: 13
From: West Hills, Calif.
Registered: 1/23/10
Re: Issue #8
Posted: Feb 9, 2010 12:19 PM   in response to: Kit_2010 in response to: Kit_2010
  Click to reply to this thread Reply

RE Issue #8: The code in Listing 6.9 depends on the buttons methods, which are located within the wx.lib module. Therefore, these methods must be specifically imported into the main program body at the top of your program.

Add to the import list at the top of your file the following:

from wx.lib import buttons

Kit_2010

Posts: 13
From: West Hills, Calif.
Registered: 1/23/10
Re: Issue #9
Posted: Feb 9, 2010 12:20 PM   in response to: Kit_2010 in response to: Kit_2010
  Click to reply to this thread Reply

RE Issue #9: This bug was discovered and cleverly corrected by Forum member whatteaux. As this is not my correction and I currently do not have permission from him to copy it here, I'll only describe where the correction may be located and viewed:

The fix for this bug can be found on or near Page 9 of this Forum, under the title "Chapter 6 errata: Listing 6.9" posted by whatteaux on December 22, 2006.

There he has clearly listed the problem, and the simple conditional statement to be added in the OnSetColor method to correct it.

Kit_2010

Posts: 13
From: West Hills, Calif.
Registered: 1/23/10
Re: Issue #10
Posted: Feb 9, 2010 12:21 PM   in response to: Kit_2010 in response to: Kit_2010
  Click to reply to this thread Reply

RE Issue #10: This is a deliberate omission of code by the authors. Simply put, there is no code feedback to track the various color tools to the individual color selections.

The anomaly is noted in the book on Page 164, Annotation 6. It has obviously been left for the reader to experiment with fixing on their own, as an independent exercise.

Forum discussions on approaches to implement this code would be stimulating and welcome.

Legend
Gold: 300 + pts
Silver: 100 - 299 pts
Bronze: 25 - 99 pts
Manning Author
Manning Staff
Manning Developmental Editor