wxPython in Action (英語) ペーパーバック – 2006/3/28
Kindle 端末は必要ありません。無料 Kindle アプリのいずれかをダウンロードすると、スマートフォン、タブレットPCで Kindle 本をお読みいただけます。
Provides information on using wxPython to build cross-platform applications.
Noel Rappin is a senior software engineer at Motorola and has extensive Python experience. He has a Ph.D. from the Georgia Institute of Technology, where he studied educational software and user interface design. Noel co-authored the book Jython Essential. Robin Dunn, the creator and maintainer of WXPython has been working in the software industry for 18 years on a wide variety of applications. He discovered both wxWindows and Python in 1995 while looking for a cross platform toolkit and has never (willingly) looked back. Robin was awarded the ActiveState Programmers Choice Award at the 2002 O'Reilly Open Source Convention. Robin also worked for the Open Source Application Foundation, improving wxPython for use in their flagship product, Chandler.
この本は、主な Widget と その主なメソッドを丁寧に紹介している。たいていのGUIアプリなら、これを読めば作れるようになる。この本はすべての機能を網羅しているわけではないが、この本を読んで wxWidget・wxPython の基礎をしっかり理解しておけば、自力で wxWidget・wxPython のリファレンスを読み進めることができるようになる。
・Widgetをカスタマイズするために派生クラスを作るとき、なぜ wx.PyXxx というクラスから派生しないといけないのか
・wxPython には PyCrust という非常に便利なPythonシェルが付属している
# これがあれば Borland / C++ Builder 亡き後も生きていける。
1. It is badly organized. Part I, called "Introduction to wxPython," deals with high-level abstractions and advanced topics. For example, Chapter 6, called "Working with the basic building blocks," is mainly concerned with constructing a drawing program, and doesn't discuss the most basic widgets in wxPython. Only in Part 2, starting on page 183, does the book "explore the essential widgets that make up the core of the wxPython toolkit." Who wants to wade through 182 pages before learning how to do basic things with wxPython?
2. The authors' explanations tend to be vague and incomplete, often omitting very basic information. For example, if I want a user to enter text into the program, then I'll want the program to get that text. Section 7.1.2 of this book, titled "How can I get the user to enter text?" doesn't show how to get the text that the user entered. In fact, the method for getting the text is GetValue() but in this book that is listed in the next section, titled "How do I change the text without user input?" (another example of bad organization). And I didn't find any explanation or example of how to use this very basic method. Another example: Section 7.1.2 says that the style wx.TE_PROCESS_ENTER triggers "a text enter event" when the user presses the enter key but doesn't give the name of this event or say where to find it; in fact it is in section 7.1.8 but you have to hunt to find it.
3. The index is weak. For example, suppose you want to find where wx.TextCtrl is discussed. If you look up "TextCtrl" in the index you won't find it; it is under "wx.TextCtrl." OK, but then the index refers you to pages "189-190, 192, 195, 198" whereas in fact all of pages 189-199 are concerned with wx.TextCtrl. Also, there are no subheadings in the index, so you can't tell from the index where to find specific information about a control.
I made much better progress when I abandoned this book and worked through the online tutorials. But those are very incomplete and I like working with books, so I've now ordered Cody Precord's book wxPython 2.8 Application Development Cookbook; I think I'll like that better.
As I tried to start work on a GUI application I've designed for my customer, I was frustrated by either the lack of or the poor quality of web-based documentation for wxPython. I decided to buy this book to help me get up to speed on the basics.
The book is definitely worth getting to help you get going doing basic wxPython programming. The demos that come with wxPython are great, but they are not good teaching tools for the basic principles. Realize that this book is only an introduction; there's no way they had enough room for a comprehensive treatise. I gave the book 4 stars only because I reserve 5 stars for books that I consider exceptional.
GUI (graphical user interface) toolkits are complex beasts. The learning curve to be able to do the things you want can be steep. Alas, there is no royal road to this knowledge. There are some things that can help, however. This book is certainly a good first step.
IMPORTANT: ignore the complaints of people who don't like this book and complain that it didn't help them do anything. I can tell the authors put a lot of work sweating over organization, pedagogy, what to include, examples, etc. You will get the basics of the information you need to pull yourself up by the bootstraps. Just don't expect to be able to turn to a page and have your application written for you -- things simply don't work that way. You will be expected to provide some sweat equity if you want to learn the ropes. The information is there -- I know, because I found it for myself. There will also be things that are missing that you think should be there -- the web can help you find those things.
Other things you should know about if you want to learn wxPython:
Definitely peruse and study the demos that come with wxPython. First, it will take you quite a bit of time just to go through them all since there are so many of them. You'll also be impressed with the creativity of the many folks who have made these contributions. Keep notes on the widgets that interest you most, as you'll want to go back later to find them and use them.
Manually laying out menus, dialogs, etc., via a text editor is tiresome. Get a tool like wxDesigner -- it can save you a lot of time and make it easier to make changes as your customers request them (or you see the need). Plus, all your resources for a project can go into one file. wxDesigner isn't a perfect tool (I'd like to see better documentation and more control over how things are done); however, it will pay for itself quickly if your time is valuable.
Check the wxPython wiki and FAQ. You will uncover answers to things you will struggle with.
wxPython comes with a tool called PyCrust that can help you discover things -- especially because of the lacking/poor wxPython reference documentation. In the directory I'm working in, I put a file named z.py that contains something like (Amazon's tool screws up the indenting):
#frame = wx.Frame(None)
app = MyApp()
frame = wx.MDIParentFrame(None)
window = wx.MDIChildFrame(frame)
panel = wx.Panel(frame)
button = wx.Button(frame)
textbox = wx.TextCtrl(frame)
togglebutton = wx.ToggleButton(frame)
toolbar = frame.CreateToolBar()
colorpicker = wx.ColourPickerCtrl(frame)
dialog = wx.Dialog(frame)
canvas = wx.Window(frame)
dc = wx.BufferedDC(wx.ClientDC(canvas))
brush = wx.Brush("black")
font = wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL)
I then start PyCrust and immediately type 'from z import *'. Now, if you look on the Namespace tab, you'll see a local variable tree. Click on the + and you'll expand the tree. Expand the variable of interest to see the attributes and methods for that type. Click on a symbol name and in the frame to the right, you'll see useful information about that thing, such as the docstring. Example: if you used the above z.py file, click on frame, then click on BackgroundColour. You'll see some details on this method. This will be your Obi Wan Kenobi when the documentation has let you down. A minor nit is that you'll often see C++ documentation rather than python, but it's pretty easy to figure things out.
Even with these resources, expect to spend a lot of time puzzling over things, cursing the lack of good documentation. But you'll eventually find what you need. In spite of the poor documentation, I'm extremely grateful for the powerful tool that is available, put together by lots of dedicated and hard-working volunteers.
In a couple of weeks, I've gotten most of a program I've envisioned for my customer working. It's going to be a very powerful tool for manipulating waveforms (partly because it uses numpy). I suspect they're going to be pretty surprised by the rich functionality in the prototype they see next week.
The price is typical for programming books, and easily worth it for a professional programmer like me. I used an on-line version for about three days, at which point I realized that it was available as a paper book. I ordered it right away. The paper book is easier to use, and includes good illustrations and examples.
"WxPython in Action" is suitable for beginners and old pros. The examples are detailed and progress step by step. Full source code is available for download from the publisher's web site.
"WxPython in Action" covers the wxWidgets GUI system as implemented in Python. It is not a Python tutorial. If you are new to Python, I recommend also purchasing "Learning Python" by Lutz.