Tag: wxPython

wxGrid does not update after a change on PyGridTableBase

Hi, I have continued my experiments with the fantastic wxPython library.

Today I had to create a simple grid, so I followed some tutorials and read some documentation on how to use wx.grid.Grid along with wx.grid.PyGridTableBase, in a very MVC-ish fashion. The thing is, that I correctly set up both (you can look up tutorials online on how to use them, or the fantastic wxPython in Action book (which was published back in 2006, making it a little bit old, but very a very useful and educational resource nonetheless). But when invoking the AppendRows or DeleteRows on the grid, I saw no change in the Grid’s presentation (although I double checked that the table’s AppendRows and DeleteRows where called accordingly).

But thanks to the wonders of the lazyweb, I found my answer in this very useful post:

http://groups.google.com/group/wxpython-users/msg/f02fb345ef0b35cf

So, all I had to do was to send the corresponding message  on my table’s AppendRows and DeleteRows methods and all worked just fine.

Hope you find that useful too.

How to get XP Styles on wxPython apps made with py2exe

Let me begin with this: wxPython is fantastic! I could write a moderately simple app in ~17 hours which automates a task that is normally done manually loading data into a web form. The app consists on custom wizard classes, access to web resources (requesting and parsing) and session management with cookies. I’m impressed that I could finish the application, with no previous knowledge on any of the aforementioned subjects, in such a short time span.

Publicity aside, I faced a little problem. I packed the python application into an executable that didn’t require a full python install using the py2exe extension, after reading the guide on how to get py2exe to work with wxPython. My first problem was some silly issue with some MSCV*.dll files:

*** finding dlls needed ***
error: MSVCP90.dll: No such file or directory

After a quick read on several places, I found a simple solution for this problem, ignoring the dll file when building  the executables.

With that solved, I could successfully build and launch my application. The less obvious problem was, that even though the application launched it looked ugly! Here’s a screenshot on what I was getting when running the generated exe vs running the .py file directly:

normal_theme-vs-xp_theme

Hideous indeed. The problem was that for some reason the application was not using XP Themes when drawing the application’s widgets, and after some reading I discovered that there are some serious issues regarding Python2.6 (the version I’m using), wxPython and py2exe when it comes to manifests. Long story short, I had to associate a correct manifest to my exe file, and after lurking around my Python installs, I found a manifest that wxPython creates for Python that served my needs:

<?xml version=’1.0′ encoding=’UTF-8′ standalone=’yes’?>
<assembly xmlns=’urn:schemas-microsoft-com:asm.v1′ manifestVersion=’1.0′>
<trustInfo xmlns=”urn:schemas-microsoft-com:asm.v3″>
<security>
<requestedPrivileges>
<requestedExecutionLevel level=’asInvoker’ uiAccess=’false’ />
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity
type=’win32′
name=’Microsoft.VC90.CRT’
version=’9.0.21022.8′
processorArchitecture=’*’
publicKeyToken=’1fc8b3b9a1e18e3b’ />
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly>
<assemblyIdentity
type=”win32″
name=”Microsoft.Windows.Common-Controls”
version=”6.0.0.0″
processorArchitecture=”*”
publicKeyToken=”6595b64144ccf1df”
language=”*” />
</dependentAssembly>
</dependency>
</assembly>
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
      </requestedPrivileges>
    </security>
  </trustInfo>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
     type='win32'
     name='Microsoft.VC90.CRT'
     version='9.0.21022.8'
     processorArchitecture='*'
     publicKeyToken='1fc8b3b9a1e18e3b' />
    </dependentAssembly>
  </dependency>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
         type="win32"
         name="Microsoft.Windows.Common-Controls"
         version="6.0.0.0"
         processorArchitecture="*"
         publicKeyToken="6595b64144ccf1df"
         language="*" />
    </dependentAssembly>
  </dependency>
</assembly>

Both the “Microsoft.VC90.CRT” and “Microsoft.Windows.Common-Controls” assemblies are important. The first one is mandatory for Python >= 2.6 is built with Visual Studio 2008, and the second one is the one that links our app to the dlls that provide the nice XP Theme widgets.

Just loaded that text into a string (called manifest in my case) in my setup.py file and passed it as an  argument to the setup function like this:

setup(windows=[{
               'script':"app.py",
               'other_resources' : [(24, 1, manifest)]
               }],
        name = "My App",
        version="0.1"
    )

Easy as pie :D.

Hope you find this useful!