Printing in wx

Hi Chris:

Thanks for your answer!
I try the printing_in_wx.py with Python 2.5, MPlot 0.8 and wxPython 2.8.7.1. 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)
        listmix.ListCtrlAutoWidthMixin.__init__(self)

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)
        self.panel.SetBackgroundColour('WHITE')

        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.panel.SetSizer(self.vbox)
        self.panel.SetAutoLayout(1)
        self.panel.SetupScrolling()

        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.Show()
        self.ShowFullScreen(True, style = wx.FULLSCREEN_NOMENUBAR)

        self.Build_Menus()
        self.plot_data(self.fig)

    def Build_Menus(self):
        """ build menus """
        MENU_EXIT = wx.NewId()
        MENU_SAVE = wx.NewId()
        MENU_PRINT = wx.NewId()
        MENU_PSETUP= wx.NewId()
        MENU_PREVIEW=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.AppendSeparator()
        f0.Append(MENU_PSETUP, "Page Setup...", "Printer Setup")
        f0.Append(MENU_PREVIEW,"Print Preview...", "Print Preview")
        f0.Append(MENU_PRINT, "&Print", "Print Plot")
        f0.AppendSeparator()
        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.SetMenuBar(menuBar)

        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, self.save, 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):
        self.canvas.Printer_Setup(event=event)

    def onPrinterPreview(self,event=None):
        self.canvas.Printer_Preview(event=event)

    def onPrint(self,event=None):
        self.canvas.Printer_Print(event=event)

    def onHelp(self, event=None):
        pass

    def onExit(self,event=None):
        self.Destroy()

    def save(self, event):
        pass

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

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

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

···

----- Original Message ----- From: "Christopher Barker" <Chris.Barker@...259...>
To: "matplotlib-users" <matplotlib-users@lists.sourceforge.net>
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 printing_in_wx.py.

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?

-Chris

--
Christopher Barker, Ph.D.
Oceanographer

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

Chris.Barker@...259...

------------------------------------------------------------------------------
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. http://p.sf.net/sfu/creativitycat-com
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users