2014-07-18 17:53:19 -04:00
|
|
|
import os
|
2014-07-05 22:54:00 -04:00
|
|
|
import sys
|
|
|
|
|
2014-07-18 17:53:19 -04:00
|
|
|
from PySide.QtGui import QWidget, QApplication, QLabel, QPushButton, QDesktopWidget, QVBoxLayout
|
|
|
|
|
|
|
|
|
|
|
|
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()
|
2014-07-05 22:54:00 -04:00
|
|
|
|
2014-07-10 08:08:37 -04:00
|
|
|
|
2014-07-05 22:54:00 -04:00
|
|
|
def main():
|
2014-07-18 17:53:19 -04:00
|
|
|
# TODO Should be moved out into a separate module
|
2014-07-05 22:54:00 -04:00
|
|
|
app = QApplication(sys.argv)
|
2014-07-18 17:53:19 -04:00
|
|
|
view = MenuScreen(app)
|
2014-07-05 22:54:00 -04:00
|
|
|
view.show()
|
|
|
|
app.exec_()
|
2014-07-18 17:53:19 -04:00
|
|
|
sys.exit(0)
|
2014-07-05 22:54:00 -04:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|