#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QLabel, QGridLayout, QSizePolicy
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot, Qt

sys.path.insert(0, '../')
# import stagecontrol
import servos
from extraFunctions import moveToCentre

class Butt(QWidget):

    def __init__(self, *args):
        super().__init__(*args)

        self.title = 'Optical audio shutter'
        self.left = 10
        self.top = 10
        self.width = 500
        self.height = 500
        self.shutter = servos.Shutter(absoluteMode = True, channel = servos.Servo.RIGHTCH)
        self.isOpen = False
        self.initUI()

    def initUI(self):
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)

        moveToCentre(self)

        self._layout = QGridLayout()

        self.textbox = QLabel(self)
        self.textbox.setText("HELLO WORLD")
        self.setStyleSheet("QLabel {font-weight: bold; font-size: 18pt; font-family: Roboto, 'Segoe UI'; }")
        self.textbox.setMaximumHeight(100)


        button = QPushButton('LAUNCH\nSEQUENCE', self)
        button.setToolTip('A single button. Click it maybe?')
        button.setStyleSheet("QPushButton {background-color: red; color: black; font-weight: bold; font-size: 20pt; font-family: Roboto, 'Segoe UI'; }")
        button.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        button.setMaximumHeight(300)
        button.setMaximumWidth(350)
        button.clicked.connect(self.on_click)

        self._layout.addWidget(self.textbox, 0, 0)
        self._layout.addWidget(button, 1, 0)
        # self._layout.setAlignment(button, Qt.AlignHCenter)

        self.setLayout(self._layout)

        self.show()

    @pyqtSlot()
    def on_click(self):
        if self.isOpen:
            self.shutter.close()
            self.isOpen = False
            self.textbox.setText("You closed the shutter\nGood job!!")
        else:
            self.shutter.open()
            self.isOpen = True
            self.textbox.setText("You opened the shutter\nWE'RE DOOMED!!")

def main():
    app = QApplication(sys.argv)
    ex = Butt()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()

@@ -136,16 +136,29 @@
 dLayout,
+ QHBoxLayout,
  QSizePo
@@ -162,16 +162,16 @@
 ePolicy%0A
-
 from PyQ
@@ -902,17 +902,16 @@
 ayout()%0A
-%0A
         
@@ -979,16 +979,18 @@
 LO WORLD
+%5Cn
 %22)%0A     
@@ -1136,17 +1136,97 @@
 ht(100)%0A
+        # self.textbox.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum)
 %0A
-
 %0A       
@@ -1475,33 +1475,32 @@
 oto, 'Segoe UI';
- 
 %7D%22)%0A        butt
@@ -1737,51 +1737,737 @@
  0)%0A
-        self._layout.addWidget(button, 1, 0
+%0A        # https://stackoverflow.com/a/25515321/3211506%0A        self.horizontal_wrapper = QWidget()%0A        self.horizontal_wrapper_layout = QHBoxLayout()%0A        self.horizontal_wrapper_layout.setContentsMargins(0, 0, 0, 0)%0A        self.horizontal_wrapper_layout.addStretch(1)%0A        self.horizontal_wrapper_layout.addWidget(button)%0A        self.horizontal_wrapper_layout.setStretchFactor(button, 3)%0A        self.horizontal_wrapper_layout.addStretch(1)%0A        self.horizontal_wrapper.setLayout(self.horizontal_wrapper_layout)%0A%0A        self._layout.addWidget(self.horizontal_wrapper, 1, 0)%0A%0A%0A%0A        # We still set this as this is not default behaviour on Windows%0A        self._layout.setAlignment(self.textbox, Qt.AlignCenter
 )%0A  
@@ -2516,17 +2516,16 @@
 Qt.Align
-H
 Center)%0A

add wrapper?