[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Gnumed-devel] Printing from wxPython
From: |
Christoph Becker |
Subject: |
Re: [Gnumed-devel] Printing from wxPython |
Date: |
Fri, 25 Feb 2005 12:30:18 +0100 |
User-agent: |
Mozilla Thunderbird 1.0 (Windows/20041206) |
Richard Terry schrieb:
Has anyone on the list done/got code to do printing from wxPython?
There is a printing example in the wxPython demo. I tried printing with
wxPython but than decided that using Latex from wxPython is easier,
faster to programm and probably better to maintain, since tex/latex is
an old, proven standard with very good documentation and with good
tools. With wxPython I have had enough trouble for example to transfer
my GUI from 2.4.2 to 2.5.3.1, which resulted in serveral new, often hard
to find bugs.
So here is how to print from wxPython with latex:
Build a dialog with a print method, triggerd by an event (Button, Enter,
or what you want)
Read a prefabricated tex file with fileinput, to build the desired
tex-file with string find/insert/replace operations, and name the
resultend file temp.tex
Then you may use something like the attached cblatex.py module for the
preview and printing.
I print from wxPython on Windows XP and Windows 98SE using Miktex.
Regards
Christoph Becker
# -*- coding: iso-8859-15 -*-
#---------------------------------------------------------------------------
# Name: start.py
# Author: Christoph Becker
# Created: August 2003
# Copyright: Christoph Becker, Dauner Str. 21, 53539 Kelberg, Germany
# Lisence: LGPL (Lesser GNU Public Lisence)
#---------------------------------------------------------------------------
# functions to work with latex, to centralize them for ease of maintenance
#----------------------------------------------------------------------------
# $LastChangedDate: 2005-02-19 22:41:24 +0100 (Sat, 19 Feb 2005) $
# $LastChangedRevision: 34 $
# $LastChangedBy: cb $
# $LastChangedDate: 2005-02-19 22:41:24 +0100 (Sat, 19 Feb 2005) $
# $LastChangedRevision: 34 $
# $LastChangedBy: cb $
import os
import os.path
import adjust
import globals
import sys
import string
import shutil
mn = "cb.cblatex.py "
prgdir = os.getcwd()
if sys.platform == 'linux2':
s = "cp " + prgdir + "/form/*.cls " + globals.tempdirpath
elif sys.platform == 'win32':
MyLatexClassPath = os.path.normpath(prgdir + "/form/*.cls ")
s = "copy " + MyLatexClassPath + globals.tempdirpath
else:
s = None
os.system(s)
#os.chdir(prgdir)
def transformStr(s):
"""check String s for special latex-characters and transform them
"""
try:
s = string.replace(s,'\\ ','\\textbackslash')
s = string.replace(s,'}','\\}')
s = string.replace(s,'{','\\{')
s = string.replace(s,'%','\\%')
s = string.replace(s,'~','\\textasciitilde')
s = string.replace(s,'&','\\&')
s = string.replace(s,'#','\\#')
s = string.replace(s,'$','\\$')
s = string.replace(s,'^','\\textasciicircum')
s = string.replace(s,'_','\\_')
#print mn + "s: " + `s`
except:
return
return s
def CreateDviAndPsFile(MyDir,MyFileName='temp',runLatex=1):
"""Create a dvi (device independent) file and a PS file
MyFileName is without extension. Thus in MyDir there should be a file
'temp.tex', from which this functions will make a file 'temp.dvi'
and a file 'temptex.log'
runLatex needs to > 1 at least if longtable is used
"""
prgdir = os.getcwd()
os.chdir(MyDir)
prgdir = os.getcwd()
#print "cb.cblatex.CreateDviAndPsFile.MyDir: " + `MyDir`
MyDir = os.getcwd()
#print "cb.cblatex.CreateDviAndPsFile.MyDir: " + `MyDir`
if sys.platform == 'linux2':
s = "latex -interaction=nonstopmode "
s += MyFileName +".tex > " + MyFileName + "tex.log"
for i in range(runLatex):
#print mn + "runLatex s: " + `s`
os.system(s)
s = 'dvips -q ' + MyFileName + '.dvi'
#print mn + "s: " + `s`
os.system(s)
if sys.platform == 'win32':
s = "latex -interaction=nonstopmode "
s += MyFileName +".tex > " + MyFileName + "tex.log"
#print "s: " + `s`
for i in range(1,runLatex):
res = os.system(s)
s = 'dvips -q ' + MyFileName + '.dvi'
res =os.system(s)
# now reset the dir
os.chdir(prgdir)
pass
def ViewDviFile(MyDir,MyDviFile='temp.dvi'):
"""show MyDir/MyDviFile
"""
if sys.platform == 'linux2':
#s = 'kghostview ' + MyDir + '/' + MyPsFile
s = 'xdvi ' + MyDir + '/' + MyDviFile
#print "abrechn_priv.onBtnViewInvoic_s: " + `s`
os.system(s)
return
if sys.platform == 'win32':
s = 'yap ' + MyDir + '\\' + MyDviFile
os.system(s)
def PrintFile(MyDir,MyFile='temp',MyPrinter='lp1'):
"""At the moment, we do need a dvi-file to print from Windows and a
ps file to print from Linux
"""
if sys.platform == 'linux2':
s = 'lpr -P' +MyPrinter + ' '
s += MyDir + '/' + MyFile + '.ps'
#print "cb.cblatex.PrintFile, s: " + `s`
res = os.system(s)
if res != 0:
cb.dialog.Fehler(self, 'Fehler beim Drucken: ' + `res`)
return res
#print mn + "L121 MyPrinter: " + `MyPrinter`
if sys.platform == 'win32':
#s = 'lpr -P' +MyPrinter + ' '
#s += MyDir + '\\' + MyPsFile
s = 'mtprint --printer=' + MyPrinter + ' '
s += MyDir + '\\' + MyFile + '.dvi'
#print mn + "L128 s: " + `s`
res = os.system(s)
if res != 0:
cb.dialog.Fehler(self, 'Fehler beim Drucken: ' + `res`)
return res
return 0