Advertisement
Guest User

Untitled

a guest
Nov 5th, 2014
547
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.96 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # quitter.py - provide a button to quit this "program"
  4.  
  5. import sys
  6.  
  7. from PySide.QtGui import QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QStackedWidget, QPushButton
  8. from PySide.QtCore import Qt
  9.  
  10.  
  11. class MainWindow(QMainWindow):
  12.     def __init__(self):
  13.         super(MainWindow, self).__init__()
  14.  
  15.         self.mainWidget = MainWidget(self)
  16.         self.setCentralWidget(self.mainWidget)
  17.  
  18.         self.initUI()
  19.  
  20.     def initUI(self):
  21.         self.resize(300, 500)
  22.         self.statusBar()
  23.         self.statusBar().showMessage('Elo Elo')
  24.         self.setWindowTitle('StartApp Welcome')
  25.  
  26.     # Instead of overriding this method you should look into using QActions instead.
  27.     """ Esc zamyka program (keyPressEvent) """
  28.     def keyPressEvent(self, e):
  29.         if e.key() == Qt.Key_Escape:
  30.             self.close()
  31.         else:
  32.             # Don't forget to call the super class method otherwise any key
  33.             # other than the escape key won't do anything.
  34.             super(MainWindow, self).keyPressEvent(e)
  35.  
  36.  
  37. # This class is where we handle switching between QStackedWidget pages
  38. class MainWidget(QWidget):
  39.     def __init__(self, parent=None):
  40.         super(MainWidget, self).__init__(parent)
  41.         self.initUI()
  42.  
  43.     def initUI(self):
  44.         layout = QVBoxLayout(self)
  45.  
  46.         self.stack = QStackedWidget(parent=self)
  47.  
  48.         self.search = SearchWidget(parent=self)
  49.         self.search.searchButton.clicked.connect(self.goSearch)
  50.         self.back = BackWidget(parent=self)
  51.         self.back.backButton.clicked.connect(self.goBack)
  52.  
  53.         self.stack.addWidget(self.search)
  54.         self.stack.addWidget(self.back)
  55.  
  56.         layout.addWidget(self.stack)
  57.  
  58.     def goSearch(self):
  59.         self.stack.setCurrentWidget(self.back)
  60.  
  61.     def goBack(self):
  62.         self.stack.setCurrentWidget(self.search)
  63.  
  64.  
  65. class SearchWidget(QWidget):
  66.     def __init__(self, parent=None):
  67.         super(SearchWidget, self).__init__(parent)
  68.         self.initUI()
  69.  
  70.     def initUI(self):
  71.         self.searchButton = QPushButton('searchButton', parent=self)
  72.         optionButton = QPushButton('optionButton', parent=self)
  73.         quitButton = QPushButton('quitButton', parent=self)
  74.         listButton = QPushButton('listButton', parent=self)
  75.  
  76.         vbox = QVBoxLayout(self)
  77.         vbox.addStretch(1)
  78.         vbox.addWidget(self.searchButton)
  79.         vbox.addWidget(optionButton)
  80.  
  81.         hbox = QHBoxLayout()
  82.         hbox.addWidget(listButton)
  83.         hbox.addWidget(quitButton)
  84.  
  85.         vbox.addLayout(hbox)
  86.  
  87.  
  88. class BackWidget(QWidget):
  89.     def __init__(self, parent=None):
  90.         super(BackWidget, self).__init__(parent)
  91.         self.initUI()
  92.  
  93.     def initUI(self):
  94.         self.backButton = QPushButton('GoBack', parent=self)
  95.  
  96.  
  97. def main():
  98.     app = QApplication(sys.argv)
  99.     frame = MainWindow()
  100.     frame.show()
  101.     app.exec_()
  102.  
  103. if __name__ == '__main__':
  104.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement