Python


March 8, 2008: 3:17 pm: kpdPython, wxPython

TimeSpin has a bug in that it reports the same width for GetBestSize when AM/PM is shown and when it is not (24 hour format). This causes an empty space to appear after the control when it is set to display time in 24 hours. I’m not able to fix the bug at this point, but I was able to add a workaround that adjusts the width as needed.

Version 1.4 of the time_spin_and_control distrubution contains the workaround.

February 13, 2008: 7:21 am: kpdPython, wxPython

I added a workaround for a problem with timectrl.

You’ll want to upgrade to the 1.4 version of the time_spin_and_control distribution if you use limited, min, max, or value parameters in Glade when specifying the control.

Edit - 3/8 - updated to version 1.4

February 11, 2008: 7:17 am: kpdPython, wxPython

The program I’m working on (ErgMate) requires entry of hours/mins/seconds durations. I just defined input as total number of seconds for the initial prototypes, but the time has come to make it more usable. I was able to create the bridge code necessary to add the wx.lib.masked.TimeCtrl to the wxGlade widget palette by following examples from Alberto Griggio .

The normal TimeCtrl can bind to an external scroll button. The package also includes a new control called TimeSpin. It is based on Andrea Gavana’s FloatSpin control, and provides both a TimeCtrl and scroll button in one control. TimeSpin does not accept the format nor the scrollBar parameters, otherwise it should be a drop-in replacement for TimeCtrl. Let me know if I missed something important in the interface.

There is (at least!) one minor problem with TimeSpin: It seems to report too large a width - its bounding box is actually wider than the displayed control. I’d appreciate anyone with more knowledge of wxPython than I looking into it and sending a patch. For now it’s good enough to get started using.

Both time widgets are added to wxGlade by untarring the time_spin_and_control distribution from within your .wxglade directory. The included README contains more details.

Edit:
1.1 - fixed codegen problem w/value
1.2 - fixed loading problem when presetting a value
1.3 - added workaround for bug in timectrl when using min/max/limited settings

February 5, 2008: 5:43 am: kpdPython

The February Cleveland Area Python Users Group Meeting was held last night. The guys at BitBacker opened their doors and supplied pizza. It was the best meeting in awhile - 3 talks!

Christian Wyglendowski kicked things off with an overview of SimpleParse. He’s used it in applications from an ini file parser to a parser for an online survey processing language. It looks easy to use. Some time ago I wrote a parser for generating Python code from FLTK’s Fluid GUI builder data files using Spark. A great library, but SimpleParse might have been so much easier - it depends if I could have created or found a grammar for the fluid file format.

Matt Wilson spoke on IPython. I’ve been using IPython for some time and realized I wasn’t making full use of it. Until his talk I didn’t realize how much of IPython I was missing (”You only use 10% of your Ipython’s capabilities….”). Never knew it would assign results to _## where ## is the history line number. That alone will save a lot of time. Matt’s Ipython talk notes are online at his website.

Matt also gave a short talk on Twill. Twill is a domain-specific language used to test websites and web applications. The most interesting part of Twill is its extensibility. He demonstrated how one can add automatic checks as Twill encounters each page in your application - checks for tables-within-tables for example. Matt’s notes contain more information.

These talks gave us a lot to take home and think about.

February 2, 2008: 8:18 am: kpdwxPython

This morning I started getting the following exception when generating code from wxGlade:

Traceback (most recent call last):
  File "c:tempwxGladeapplication.py", line 394, in generate_code
    class_names=class_names)
  File "c:tempwxGladexml_parse.py", line 503, in __init__
   .
   .
   .
  File "c:tempwxGladexml_parse.py", line 593, in endElement
    self.code_writer.add_class(obj)
  File "c:tempwxGladecodegenpy_codegen.py", line 640, in add_class
    indentation = prev_src.spaces[code_obj.klass]
KeyError: 'FancyListControl'

There was only one mention of a similar problem on the wxGlade mailing list. The solution posted there was to start a new project - not really an option at this stage of development.

So after a little digging, I found a different solution.

The item causing the problem is a fancy subclass of ListControl defined in another module. I had placed a wx.Panel in the sizer slot, and had then changed the class to my fancy ListControl. Is the problem now obvious? This fancy list control is not equivalent to a wx.Panel from wxGlade’s perspective. Removing the panel and instead adding a ListControl with my fancy control as the class name fixed everything up.

So, in summary, use the closest matching wxGlade class (ListControl instead of Panel) when using your own classes.

Doh.

February 15, 2007: 8:02 am: kpdwxPython

wxGlade has an option for ‘overwrite sources’ in the application dialog:

I normally have it off, but when doing some exploratory testing I enabled it. This morning I was working on my main application and regenerated the code. Guess what? Yes, it overwrote every gui class. Three things led to this:

1. I had assumed the overwrite setting was stored in the .wxg file (it is part of the configuration for a given application.)
2. My main wxsGlade window is sized so that option is not normally visible.
3. The value for ‘overwrite sources’ is actually a global configuration.

So BE CAREFUL with this option. Fortunately, a svn update brought the code back to where it was just a few minutes earlier minus a minor gui change.

February 11, 2007: 12:53 am: kpdwxPython

I just noticed that my wxPython application looks different after creation of an exe with Py2Exe. The image on the left is the application running under the normal python interpreter. The one on the right is the same application after creation of an exe with Py2exe.

Notice:
1. The dark gray below the Music label instead of white.
2. The area around Music is inset in the exe version.
3. The splash handle separator is different, it looks more 3D in the Py2EXE version.

This is with wxPython 2.8.1.1.

I’d guess there is a simple solution, but I’m not finding it. Any ideas?

Edit:
Solution is at: http://wiki.wxpython.org/index.cgi/DistributingYourApplication

February 7, 2007: 9:29 pm: kpdPython

A discussion over on the Business of Software about embedded firmware testers brought this software back to mind. I created this around 1998 to exercise the firmware (and hardware) of a steer-by-wire system for power boats I was working on. It was written using Tkinter for the GUI. It sent a simple command protocol over an RS-232 link to the system. It was amazing when I brought the system over from Windows NT to the Linux development box and did not have to change a line of code. Go Python!

The original page (which is long gone, thanks way-back machine) describing it said:

his is a screenshot of an application written in Python using the TK interpreter and the Python MegaWidgets Toolkit. It communicates with an embedded module via the RS-232 serial port. We use it to exercise new circuit boards and to debug hardware problems.

Most of the windows are generic, although they do have symbolic names for important microprocessor ports such as data I/O direction. One can also enter a numeric address to work with any memory location. The Motor Drive window presents high-level functionality specific to the product being tested.

I developed the application under Windows NT. The application ran with zero source-code changes when I later moved our development platform to Linux (the serial-port classes contained support for both Linux and NT).

Tkinter Firmware/Hardware Tester

January 22, 2007: 6:21 am: kpdPython, programming

The slides from my Code Mash presentation on Test Driven Development in Python are now online at: http://powertwenty.com/kpd/downloads/TestDrivenDevelopmentInPython.pdf

It is an introduction to TDD, some tools that work well when doing TDD in python, and the results of a case study in TDD game development using pygame.

January 19, 2007: 7:31 pm: kpdPython, programming

Wow, CodeMash turned out to be a fabulous conference. The atmosphere was one of learning from others in a friendly way - people checked their religious wars at the door. It was a fun conference. Feeling a little under the weather, I didn’t have a chance to check out the water slide park, but the movie shown at the closing ‘can geeks surf in Ohio?’ leads me to believe that might not be a bad thing.

I enjoyed the Neal Ford and Bruce Eckel’s keynotes the best. Neal spoke of mini-domain languages. Bruce tied in some great shots of Burning Man with a thought-provoking talk on using your imagination and thinking outside normal limits.

Between Kevin Dangoor’s talk on TurboGears, David Stanek’s talks on Enterprise Python Architecture and Web Services in Python, Mark Ramm’s talk on SQLAlchemy ( which made me vow to look into this library), and my talk on TDD Python, the language was well represented.

I am happy with how my talk on Test-Driven Python went. I hope to post the slides some time soon. Running through the presentation at this month’s Cleveland Python Users’ Group pointed out some areas that need refining, especially around the live demos. Fortunately I had the time to make the changes before Code Mash.

Oh, and the winning program in the coding contest was by Matt from CLEPY and coded in Python. There was some debate about the grand prize in the contest because the winner did not code the solution but instead solved it manually due to a loophole in the requirements.

The conference organizers did a fabulous job pulling things together. As an attendee and speaker there were no hitches, and in fact they even had a speaker’s room and gift bags for each speaker. That was a nice consideration. The only hitch in the conference overall that I am aware of was some issues with audio recording of the earlier sessions, and that was really the fault of the resort and its confusion between male and female audio jacks.

In the end, there is nothing I’d have changed for this conference, other than hitting the water park next time and perhaps fairing a little better in the XBox 360 and WII drawings.

Next Page »