327
334
self.canvas.drawRectangle( rect )
329
336
def configure_subplots(self):
330
self.adj_window = QtGui.QDialog()
337
self.adj_window = QtGui.QMainWindow()
331
338
win = self.adj_window
332
339
win.setAttribute(QtCore.Qt.WA_DeleteOnClose)
333
341
win.setWindowTitle("Subplot Configuration Tool")
334
image = os.path.join( matplotlib.rcParams['datapath'],'matplotlib.png' )
342
image = os.path.join( matplotlib.rcParams['datapath'],'images','matplotlib.png' )
335
343
win.setWindowIcon(QtGui.QIcon( image ))
337
toolfig = Figure(figsize=(6,3))
338
toolfig.subplots_adjust(top=0.9)
339
canvas = self._get_canvas(toolfig)
340
tool = SubplotTool(self.canvas.figure, toolfig)
342
canvas.setParent(win)
343
w = int (toolfig.bbox.width())
344
h = int (toolfig.bbox.height())
345
tool = SubplotToolQt(self.canvas.figure, win)
346
win.setCentralWidget(tool)
347
win.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
351
# self.adj_window = QtGui.QDialog()
352
# win = self.adj_window
353
# win.setAttribute(QtCore.Qt.WA_DeleteOnClose)
354
# win.setWindowTitle("Subplot Configuration Tool")
355
# image = os.path.join( matplotlib.rcParams['datapath'],'images','matplotlib.png' )
356
# win.setWindowIcon(QtGui.QIcon( image ))
358
# toolfig = Figure(figsize=(6,3))
359
# toolfig.subplots_adjust(top=0.9)
360
# canvas = self._get_canvas(toolfig)
361
# tool = SubplotTool(self.canvas.figure, toolfig)
363
# canvas.setParent(win)
364
# w = int (toolfig.bbox.width())
365
# h = int (toolfig.bbox.height())
351
373
def _get_canvas(self, fig):
352
374
return FigureCanvasQT(fig)
357
379
self.canvas.print_figure( str(fname.toLatin1()) )
382
class SubplotToolQt( SubplotTool, QtGui.QWidget ):
383
def __init__(self, targetfig, parent):
384
QtGui.QWidget.__init__(self, None)
386
self.targetfig = targetfig
389
self.sliderleft = QtGui.QSlider(QtCore.Qt.Horizontal)
390
self.sliderbottom = QtGui.QSlider(QtCore.Qt.Vertical)
391
self.sliderright = QtGui.QSlider(QtCore.Qt.Horizontal)
392
self.slidertop = QtGui.QSlider(QtCore.Qt.Vertical)
393
self.sliderwspace = QtGui.QSlider(QtCore.Qt.Horizontal)
394
self.sliderhspace = QtGui.QSlider(QtCore.Qt.Vertical)
397
QtCore.QObject.connect( self.sliderleft, QtCore.SIGNAL( "valueChanged(int)" ),
398
self.sliderright.setMinimum )
399
QtCore.QObject.connect( self.sliderright, QtCore.SIGNAL( "valueChanged(int)" ),
400
self.sliderleft.setMaximum )
401
QtCore.QObject.connect( self.sliderbottom, QtCore.SIGNAL( "valueChanged(int)" ),
402
self.slidertop.setMinimum )
403
QtCore.QObject.connect( self.slidertop, QtCore.SIGNAL( "valueChanged(int)" ),
404
self.sliderbottom.setMaximum )
406
sliders = (self.sliderleft, self.sliderbottom, self.sliderright,
407
self.slidertop, self.sliderwspace, self.sliderhspace, )
408
adjustments = ('left:', 'bottom:', 'right:', 'top:', 'wspace:', 'hspace:')
410
for slider, adjustment in zip(sliders, adjustments):
412
slider.setMaximum(1000)
413
slider.setSingleStep(5)
415
layout = QtGui.QGridLayout()
417
leftlabel = QtGui.QLabel('left')
418
layout.addWidget(leftlabel, 2, 0)
419
layout.addWidget(self.sliderleft, 2, 1)
421
toplabel = QtGui.QLabel('top')
422
layout.addWidget(toplabel, 0, 2)
423
layout.addWidget(self.slidertop, 1, 2)
424
layout.setAlignment(self.slidertop, QtCore.Qt.AlignHCenter)
426
bottomlabel = QtGui.QLabel('bottom')
427
layout.addWidget(QtGui.QLabel('bottom'), 4, 2)
428
layout.addWidget(self.sliderbottom, 3, 2)
429
layout.setAlignment(self.sliderbottom, QtCore.Qt.AlignHCenter)
431
rightlabel = QtGui.QLabel('right')
432
layout.addWidget(rightlabel, 2, 4)
433
layout.addWidget(self.sliderright, 2, 3)
435
hspacelabel = QtGui.QLabel('hspace')
436
layout.addWidget(hspacelabel, 0, 6)
437
layout.setAlignment(hspacelabel, QtCore.Qt.AlignHCenter)
438
layout.addWidget(self.sliderhspace, 1, 6)
439
layout.setAlignment(self.sliderhspace, QtCore.Qt.AlignHCenter)
441
wspacelabel = QtGui.QLabel('wspace')
442
layout.addWidget(wspacelabel, 4, 6)
443
layout.setAlignment(wspacelabel, QtCore.Qt.AlignHCenter)
444
layout.addWidget(self.sliderwspace, 3, 6)
445
layout.setAlignment(self.sliderwspace, QtCore.Qt.AlignBottom)
447
layout.setRowStretch(1,1)
448
layout.setRowStretch(3,1)
449
layout.setColumnStretch(1,1)
450
layout.setColumnStretch(3,1)
451
layout.setColumnStretch(6,1)
453
self.setLayout(layout)
455
self.sliderleft.setSliderPosition(int(targetfig.subplotpars.left*1000))
456
self.sliderbottom.setSliderPosition(int(targetfig.subplotpars.bottom*1000))
457
self.sliderright.setSliderPosition(int(targetfig.subplotpars.right*1000))
458
self.slidertop.setSliderPosition(int(targetfig.subplotpars.top*1000))
459
self.sliderwspace.setSliderPosition(int(targetfig.subplotpars.wspace*1000))
460
self.sliderhspace.setSliderPosition(int(targetfig.subplotpars.hspace*1000))
462
QtCore.QObject.connect( self.sliderleft, QtCore.SIGNAL( "valueChanged(int)" ),
464
QtCore.QObject.connect( self.sliderbottom, QtCore.SIGNAL( "valueChanged(int)" ),
466
QtCore.QObject.connect( self.sliderright, QtCore.SIGNAL( "valueChanged(int)" ),
468
QtCore.QObject.connect( self.slidertop, QtCore.SIGNAL( "valueChanged(int)" ),
470
QtCore.QObject.connect( self.sliderwspace, QtCore.SIGNAL( "valueChanged(int)" ),
472
QtCore.QObject.connect( self.sliderhspace, QtCore.SIGNAL( "valueChanged(int)" ),
475
def funcleft(self, val):
476
self.targetfig.subplots_adjust(left=val/1000.)
477
if self.drawon: self.targetfig.canvas.draw()
479
def funcright(self, val):
480
self.targetfig.subplots_adjust(right=val/1000.)
481
if self.drawon: self.targetfig.canvas.draw()
483
def funcbottom(self, val):
484
self.targetfig.subplots_adjust(bottom=val/1000.)
485
if self.drawon: self.targetfig.canvas.draw()
487
def functop(self, val):
488
self.targetfig.subplots_adjust(top=val/1000.)
489
if self.drawon: self.targetfig.canvas.draw()
491
def funcwspace(self, val):
492
self.targetfig.subplots_adjust(wspace=val/1000.)
493
if self.drawon: self.targetfig.canvas.draw()
495
def funchspace(self, val):
496
self.targetfig.subplots_adjust(hspace=val/1000.)
497
if self.drawon: self.targetfig.canvas.draw()
359
500
def error_msg_qt( msg, parent=None ):
360
501
if not is_string_like( msg ):
361
502
msg = ','.join( map( str,msg ) )