Printing in wx

Hi Chris:

Thanks for your answer!
I try the with Python 2.5, MPlot 0.8 and wxPython and its just crashes after I want to print or preview (unfortunately without any error message) and closes Python.

Here's an example of my program:

# -*- coding: latin1 -*-
import sys
import os

import wx
import wx.lib.scrolledpanel as SP
from wx.lib.mixins.listctrl import CheckListCtrlMixin
import wx.lib.mixins.listctrl as listmix

import pylab
from matplotlib.backends.backend_wx import FigureCanvasWx
from matplotlib.font_manager import fontManager, FontProperties

class CheckListCtrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
    def __init__(self, parent, nr):
        wx.ListCtrl.__init__(self, parent, -1, size=(900, ((nr*8)+50)), style=wx.LC_REPORT|wx.LC_VRULES|wx.LC_HRULES)

class MyFrame(wx.Frame, listmix.ColumnSorterMixin):

    def __init__(self):
        wx.Frame.__init__(self, None, -1, "Results", size=(300, 300))
        self.panel = SP.ScrolledPanel(self, -1)

        d = {1:('test','22')}
        nr = 1
        self.list = CheckListCtrl(self.panel, nr)
        self.list.SetFont(wx.Font(8, wx.SWISS, wx.NORMAL, wx.NORMAL))

        self.b = wx.Button(self.panel, 10, "Copy to clipboard")
        self.b.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL))
        self.Bind(wx.EVT_BUTTON, self.to_clipboard, self.b)

        l1 = wx.StaticText(self.panel, -1, "RNAi Scan Results")
        l1.SetFont(wx.Font(16, wx.SWISS, wx.NORMAL, wx.NORMAL))
        dummy = wx.StaticText(self.panel, -1, "")

        self.fig = pylab.figure(figsize=(10,8))
        self.fig.subplots_adjust(hspace = 0.5, left=0.07, right=0.95, top=0.93)
        self.canvas = FigureCanvasWx(self.panel, -1, self.fig)

        self.vbox = wx.BoxSizer(wx.VERTICAL)
        sizer = wx.GridBagSizer(hgap = 10, vgap = 10)

        sizer.Add(l1, pos = (0, 1), flag = wx.ALIGN_CENTER)
        sizer.Add(self.list, pos = (1, 1), span = (2,1), flag = wx.EXPAND|wx.GROW|wx.ALIGN_CENTER)
        sizer.Add(self.b, pos = (1, 2))
        sizer.Add(self.canvas, pos = (3, 1), flag = wx.EXPAND|wx.GROW|wx.ALIGN_CENTER)
        sizer.Add(dummy, pos = (4, 1), flag = wx.EXPAND|wx.GROW|wx.ALIGN_CENTER)

        self.vbox.Add(sizer, 1, wx.ALL|wx.ALIGN_CENTER,10)


        self.list.InsertColumn(0, "ID")
        self.list.InsertColumn(1, "All Hits")
        self.list.InsertColumn(2, "Efficient Hits")
        for key, data in d.iteritems():
            index = self.list.InsertStringItem(sys.maxint, data[0])
            self.list.SetStringItem(index, 1, data[1])
            self.list.SetItemData(index, key)
        self.list.SetColumnWidth(0, 200)
        self.list.SetColumnWidth(1, 100)
        self.list.SetColumnWidth(2, 150)

        self.ShowFullScreen(True, style = wx.FULLSCREEN_NOMENUBAR)


    def Build_Menus(self):
        """ build menus """
        MENU_EXIT = wx.NewId()
        MENU_SAVE = wx.NewId()
        MENU_PRINT = wx.NewId()
        MENU_PSETUP= wx.NewId()
        MENU_CLIPB =wx.NewId()
        MENU_HELP =wx.NewId()

        menuBar = wx.MenuBar()

        f0 = wx.Menu()
        f0.Append(MENU_SAVE, "&Export", "Save Image of Plot")
        f0.Append(MENU_PSETUP, "Page Setup...", "Printer Setup")
        f0.Append(MENU_PREVIEW,"Print Preview...", "Print Preview")
        f0.Append(MENU_PRINT, "&Print", "Print Plot")
        f0.Append(MENU_EXIT, "E&xit", "Exit")
        menuBar.Append(f0, "&File");

        f1 = wx.Menu()
        f1.Append(MENU_HELP, "Quick Reference", "Quick Reference")

        menuBar.Append(f1, "&Help");


        self.Bind(wx.EVT_MENU, self.onPrint, id=MENU_PRINT)
        self.Bind(wx.EVT_MENU, self.onPrinterSetup, id=MENU_PSETUP)
        self.Bind(wx.EVT_MENU, self.onPrinterPreview, id=MENU_PREVIEW)
        self.Bind(wx.EVT_MENU,, id=MENU_SAVE)
        self.Bind(wx.EVT_MENU, self.onExit , id=MENU_EXIT)
        self.Bind(wx.EVT_MENU, self.onHelp, id=MENU_HELP)

    def onPrinterSetup(self,event=None):

    def onPrinterPreview(self,event=None):

    def onPrint(self,event=None):

    def onHelp(self, event=None):

    def onExit(self,event=None):

    def save(self, event):

    def to_clipboard(self, evt):
        f = open("data_hits.txt", "r")
        msg = 'Id' + '\t' + 'All Hits' + '\t' 'Eff Hits' + '\n' +
        data = wx.TextDataObject()
        if wx.TheClipboard.Open():

    def plot_data(self, figure):
        query_plot = figure.add_subplot(1, 1, 1)
        listex = [0,1,2,3]
        listey = [0,1,2,3]

if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = MyFrame()


----- Original Message ----- From: "Christopher Barker" <Chris.Barker@...259...>
To: "matplotlib-users" <>
Sent: Wednesday, May 27, 2009 6:28 PM
Subject: Re: [Matplotlib-users] Printing in wx

Stefanie Lück wrote:

I'm trying to print my plots in a wxScrolledPanel under Windows XP but
it dosen't work. I only can print / preview the start of the plot on the
left upper site, the rest of page is empty:

I wonder if that has to do with how you are using the scolledpanel, and
DCs. Post a sample (as a as-small-as-possible-running-app, if you can),
and we can take a look.

I used printing according the example of matplotlib

BTW if I want to run this demo, Python crashes.

it works fine for me on OS-X

What messages to you get with your crash? What versions of Python,
wxPython and MPL are you running?


Christopher Barker, Ph.D.

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


Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, &
iPhoneDevCamp as they present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship.
Matplotlib-users mailing list