SHOW:
|
|
- or go back to the newest paste.
| 1 | import sys | |
| 2 | from PySide.QtCore import * | |
| 3 | from PySide.QtGui import * | |
| 4 | - | |
| 4 | + | |
| 5 | class TestFrame( QFrame ): | |
| 6 | - | def __init__( self, parent=None ): |
| 6 | + | def __init__( self, area, parent=None ): |
| 7 | super( TestFrame, self ).__init__( parent ) | |
| 8 | self.setFrameStyle( QFrame.StyledPanel ) | |
| 9 | - | self.setSizePolicy( parent.sizePolicy() ) # THIS DOESN'T SEEM TO HAVE ANY EFFECT |
| 9 | + | self.area = area |
| 10 | - | |
| 10 | + | self.frame_height = self.height() |
| 11 | - | class SliderWidget( QWidget ): |
| 11 | + | |
| 12 | def setHeight(self, height): | |
| 13 | self.frame_height = height | |
| 14 | ||
| 15 | def resetGeometry(self, size): | |
| 16 | height = self.frame_height | |
| 17 | ||
| 18 | - | |
| 18 | + | x = 0 |
| 19 | width = size.width() | |
| 20 | ||
| 21 | if self.area == Qt.TopDockWidgetArea: | |
| 22 | y = 0 | |
| 23 | - | self.frameCentre = TestFrame( self ) |
| 23 | + | |
| 24 | - | self.frameTop = TestFrame( self.frameCentre ) |
| 24 | + | elif self.area == Qt.BottomDockWidgetArea: |
| 25 | - | self.frameBottom = TestFrame( self.frameCentre ) |
| 25 | + | y = size.height() - height |
| 26 | ||
| 27 | - | |
| 27 | + | super(TestFrame, self).setGeometry(x, y, width, height) |
| 28 | - | # TOOLTIPS |
| 28 | + | |
| 29 | class CentralFrame(QFrame): | |
| 30 | ||
| 31 | resized = Signal(QSize) | |
| 32 | - | |
| 32 | + | |
| 33 | def resizeEvent(self, event): | |
| 34 | assert isinstance(event, QResizeEvent) | |
| 35 | ||
| 36 | - | # RESIZE AND REPO TOP AND BOTTOM FRAMES |
| 36 | + | self.resized.emit(event.size()) |
| 37 | - | # THIS IS WHERE I HAVE TROUBLE TO SET THE RIGHT SIZE AND POSITION |
| 37 | + | |
| 38 | - | # I'VE SET ABSOLUTE POSITION AND SCALE JUST TO ILLUSTRATE WHAT I'M AFTER. |
| 38 | + | class SliderWidget(QMainWindow): |
| 39 | - | # THIS REALLY NEEDS TO BE LINKED TO THE PARENT SO THE TOP AND BOTOM FRAMES ARE ALWAYS THE SAME WIDTH |
| 39 | + | |
| 40 | - | # AND HAVE THE SAME SIZE POLICY AS THE MIDDLE FRAME |
| 40 | + | |
| 41 | - | self.frameTop.setGeometry( 0, 0, 800, 100 ) |
| 41 | + | |
| 42 | - | self.frameBottom.setGeometry( 0, 600, 800, 100 ) |
| 42 | + | |
| 43 | - | |
| 43 | + | |
| 44 | self.setLayout( QGridLayout() ) | |
| 45 | - | #self.frameTop.hide() |
| 45 | + | |
| 46 | - | #self.frameBottom.hide() |
| 46 | + | |
| 47 | self.animGroup = QParallelAnimationGroup() | |
| 48 | ||
| 49 | - | self.layout().addWidget( self.frameCentre ) |
| 49 | + | |
| 50 | - | self.layout().addWidget( self.btn ) |
| 50 | + | self.frameCentre = CentralFrame( self ) |
| 51 | - | |
| 51 | + | self.frameTop = TestFrame( Qt.TopDockWidgetArea, self.frameCentre ) |
| 52 | - | |
| 52 | + | self.frameBottom = TestFrame( Qt.BottomDockWidgetArea, self.frameCentre ) |
| 53 | self.frameCentre.resized.connect(self.frameTop.resetGeometry) | |
| 54 | self.frameCentre.resized.connect(self.frameBottom.resetGeometry) | |
| 55 | self.btn = QPushButton( 'GO' ) | |
| 56 | ||
| 57 | self.frameTop.setHeight(200) | |
| 58 | - | |
| 58 | + | self.frameBottom.setHeight(200) |
| 59 | self.frameCentre.setMinimumHeight(500) | |
| 60 | ||
| 61 | # TOOLTIPS | |
| 62 | self.frameTop.setToolTip( 'frame top' ) | |
| 63 | self.frameCentre.setToolTip( 'frame centre' ) | |
| 64 | - | start = -1000 |
| 64 | + | |
| 65 | ||
| 66 | # SLIDE IN TOP AND BOTTOM FRAMES | |
| 67 | - | start = 900 |
| 67 | + | |
| 68 | - | end = 600 |
| 68 | + | |
| 69 | - | |
| 69 | + | |
| 70 | self.frameTop.hide() | |
| 71 | self.frameBottom.hide() | |
| 72 | ||
| 73 | # ADD CENTRETO LAYOUT | |
| 74 | - | |
| 74 | + | self.setCentralWidget(self.frameCentre) |
| 75 | layout = QVBoxLayout(self.frameCentre) | |
| 76 | layout.addWidget(self.btn) | |
| 77 | self.frameCentre.setLayout(layout) | |
| 78 | ||
| 79 | ||
| 80 | def moveWidgets( self ): | |
| 81 | '''trigger animations''' | |
| 82 | self.animGroup.clear() | |
| 83 | - | |
| 83 | + | |
| 84 | self.slideInWidget( self.frameBottom, 'bottomUp') | |
| 85 | - | |
| 85 | + | |
| 86 | ||
| 87 | def slideInWidget( self, widget, direction ): | |
| 88 | '''assign animation to frames''' | |
| 89 | assert direction in ( 'topDown', 'bottomUp' ) | |
| 90 | # DEFINE START AND END POSITION - THIS IS WHERE I HAVE TROUBLE SETTING THE RIGHT POSITION | |
| 91 | if direction == 'topDown': | |
| 92 | start = widget.height() * -1 | |
| 93 | end = 0 | |
| 94 | elif direction == 'bottomUp': | |
| 95 | start = self.centralWidget().height() | |
| 96 | end = self.centralWidget().height() - widget.height() | |
| 97 | ||
| 98 | # START ANIMATION | |
| 99 | widget.show() | |
| 100 | slideInAnim = self.slideAnimation( widget, start, end ) | |
| 101 | self.animGroup.addAnimation( slideInAnim ) | |
| 102 | ||
| 103 | def slideAnimation( self, widget, start, end ): | |
| 104 | '''Define sliding animation''' | |
| 105 | slideAnimation = QPropertyAnimation( widget, 'pos' ) | |
| 106 | slideAnimation.setDuration( 1000 ) | |
| 107 | slideAnimation.setStartValue( QPoint( widget.pos().x(), start ) ) | |
| 108 | slideAnimation.setEndValue( QPoint( widget.pos().x(), end ) ) | |
| 109 | slideAnimation.setEasingCurve( QEasingCurve.OutCubic ) | |
| 110 | return slideAnimation | |
| 111 | ||
| 112 | if __name__ == "__main__": | |
| 113 | ||
| 114 | app = QApplication(sys.argv) | |
| 115 | sw = SliderWidget() | |
| 116 | ||
| 117 | sw.resize( 800, 750 ) | |
| 118 | sw.show() | |
| 119 | ||
| 120 | sys.exit(app.exec_()) |