On Mon, 16 Jan 2012 08:18:03 -0600 Benjamin Root <[email protected]> wrote:
On Monday, January 16, 2012, Nils Wagner <[email protected]>wrote:Hi all,I have filed a ticket for adding a printer button to the navigation toolbar. https://github.com/matplotlib/matplotlib/issues/670 I am interested in a wider response. Any further comments ? NilsAdding a button is easy... Adding cross-platform printer capability is not. The only way I envision it could happen is if the GUI toolkits have some sort of printing API. We already can convert to postscript.Ben Root
A customization of the navigation toolbar is possible. I have used the qt4 backend. However the quality of the print-out is poor using QPrinter. Moreover the frame including the navigation toolbar is printed.
How can I omit that ? How can I improve the quality of the hardcopy. I have attached the program. Any hint would be appreciated. Thanks in advance. Nils
<<attachment: Fileprint.png>>
import sys
import numpy as np
from PyQt4.QtCore import *
from PyQt4.QtGui import *
#from xlwt import *
from pylab import plot, show
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar2
class ViewWidget(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
# create a simple main widget to keep the figure
self.mainWidget = QWidget()
self.setCentralWidget(self.mainWidget)
layout = QVBoxLayout()
self.mainWidget.setLayout(layout)
# create a figure
self.figure_canvas = FigureCanvas(Figure())
layout.addWidget(self.figure_canvas, 10)
# and the axes for the figure
self.axes = self.figure_canvas.figure.add_subplot(111)
x = np.linspace(0.,2*np.pi,100)
self.axes.plot(x,np.sin(x),label='sin(x) ')
self.axes.plot(x,np.cos(x),label='cos(x) ')
self.axes.figure.set_facecolor('white')
self.axes.grid('on')
self.axes.legend()
# add a navigation toolbar
self.navigation_toolbar = NavigationToolbar2(self.figure_canvas, self)
layout.addWidget(self.navigation_toolbar, 0)
self.print_button = QPushButton()
self.print_button.setIcon(QIcon("Fileprint.png"))
self.print_button.setToolTip("Print the figure")
self.navigation_toolbar.addWidget(self.print_button)
self.connect(self.print_button, SIGNAL('clicked()'), self.goPrinter)
self.quit_button = QPushButton("&Quit")
self.navigation_toolbar.addWidget(self.quit_button)
self.connect(self.quit_button, SIGNAL('clicked()'), self.close)
def goPrinter(self):
printer = QPrinter()
anotherWidget= QPrintDialog(printer,self)
if(anotherWidget.exec_() != QDialog.Accepted):
return
p = QPixmap.grabWidget(self)
printLabel = QLabel()
printLabel.setPixmap(p)
painter = QPainter(printer)
printLabel.render(painter)
painter.end()
show()
if __name__=="__main__":
app=QApplication(sys.argv)
mw=ViewWidget()
mw.show()
sys.exit(app.exec_())
------------------------------------------------------------------------------ Keep Your Developer Skills Current with LearnDevNow! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________ Matplotlib-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-users
