Initial attempt at a PySide based UI.
This commit is contained in:
parent
fff98a41df
commit
c3bb8b453d
|
@ -1,24 +1,59 @@
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from PySide.QtCore import QUrl
|
from PySide.QtGui import QWidget, QApplication, QLabel, QPushButton, QDesktopWidget, QVBoxLayout
|
||||||
from PySide.QtGui import QApplication
|
|
||||||
from PySide.QtDeclarative import QDeclarativeView
|
|
||||||
|
class MenuScreen(QWidget):
|
||||||
|
# TODO Divide up into separate widgets for the window and its contents.
|
||||||
|
# TODO Figure out testing mechanism for PySide UIs.
|
||||||
|
|
||||||
|
def __init__(self, app):
|
||||||
|
super(MenuScreen, self).__init__()
|
||||||
|
self.setWindowTitle('justCheckers')
|
||||||
|
self.setGeometry(300, 300, 800, 600)
|
||||||
|
self.setup_components()
|
||||||
|
self.app = app
|
||||||
|
self.center()
|
||||||
|
|
||||||
|
def setup_components(self):
|
||||||
|
self.systemLabel = QLabel(self.get_system_info(), self)
|
||||||
|
self.exitButton = QPushButton('Exit', self)
|
||||||
|
self.exitButton.clicked.connect(self.exit_app)
|
||||||
|
|
||||||
|
widget_layout = QVBoxLayout(self)
|
||||||
|
widget_layout.addWidget(self.systemLabel)
|
||||||
|
widget_layout.addStretch()
|
||||||
|
widget_layout.addWidget(self.exitButton)
|
||||||
|
widget_layout.addStretch()
|
||||||
|
self.setLayout(widget_layout)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_system_info():
|
||||||
|
"""Retrieve information about the system."""
|
||||||
|
message = 'I am running on {os}.\n My screen is {height}x{width}'
|
||||||
|
geometry = QDesktopWidget().availableGeometry()
|
||||||
|
os_sys = ' '.join(os.uname())
|
||||||
|
return message.format(os=os_sys, height=geometry.height(), width=geometry.width())
|
||||||
|
|
||||||
|
def center(self):
|
||||||
|
"""Centers the widget in the middle of the screen."""
|
||||||
|
widget_rectangle = self.frameGeometry()
|
||||||
|
center_point = QDesktopWidget().availableGeometry().center()
|
||||||
|
widget_rectangle.moveCenter(center_point)
|
||||||
|
self.move(widget_rectangle.topLeft())
|
||||||
|
|
||||||
|
def exit_app(self):
|
||||||
|
self.app.quit()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# Create app
|
# TODO Should be moved out into a separate module
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
|
view = MenuScreen(app)
|
||||||
# Setup the QML declartive view
|
|
||||||
view = QDeclarativeView()
|
|
||||||
menu_view_url = QUrl('menu_view.qml')
|
|
||||||
view.setSource(menu_view_url)
|
|
||||||
view.show()
|
view.show()
|
||||||
|
|
||||||
# Enter app loop
|
|
||||||
app.exec_()
|
app.exec_()
|
||||||
sys.exit()
|
sys.exit(0)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue