Split up current app into separate UI components.

Add backdrop to main window.
Add troves and main entry point for app.
This commit is contained in:
Dorian 2014-07-31 21:25:50 -04:00
parent 5d2ecec3fb
commit b80009850e
6 changed files with 215 additions and 76 deletions

View File

@ -1,84 +1,36 @@
import os #
# Copyright (c) 2014 Dorian Pula <dorian.pula@amber-penguin-software.ca>
#
# justCheckers is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# justCheckers is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with justCheckers. If not, see <http://www.gnu.org/licenses/>.
#
# Please share and enjoy!
#
import sys import sys
from PySide.QtCore import QCoreApplication from PySide import QtGui
from PySide.QtGui import *
from justcheckers.ui.window import DesktopGameWindow
class MenuScreen(QWidget):
# TODO Divide up into separate widgets for the window and its contents.
# TODO Setup functional testing with PySide.QtTest
def __init__(self):
super(MenuScreen, self).__init__()
self.setWindowTitle('justCheckers')
self.setGeometry(300, 300, 800, 600)
self.setWindowIcon(QIcon('images/icon.png'))
self.add_backdrop()
self.setup_components()
self.center()
def add_backdrop(self):
tile = QPixmap('images/backdrop.jpg')
palette = QPalette()
palette.setBrush(QPalette.Background, tile)
self.setPalette(palette)
def setup_components(self):
"""Setup the components that make up the widget."""
print(self.get_system_info())
self.new_game = QPushButton('&New Game', self)
self.open_game = QPushButton('&Open Game', self)
self.save_game = QPushButton('&Save Game', self)
# TODO Render buttons greyed out.
self.about_game = QPushButton('About Game', self)
# TODO Add links to site and display license inside about game widget.
self.settings = QPushButton('Settings', self)
self.exit_button = QPushButton('Exit', self)
self.exit_button.clicked.connect(self.exit_app)
widget_layout = QVBoxLayout(self)
widget_layout.addStretch()
widget_layout.addWidget(self.new_game)
widget_layout.addWidget(self.open_game)
widget_layout.addWidget(self.save_game)
widget_layout.addWidget(self.about_game)
widget_layout.addWidget(self.settings)
widget_layout.addWidget(self.exit_button)
widget_layout.addStretch()
self.setLayout(widget_layout)
@staticmethod
def get_system_info():
"""Retrieve information about the system."""
message = 'I am running on {os}.\nMy 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):
"""Exits the application."""
QCoreApplication.instance().exit()
def main(): def main():
# TODO Should be moved out into a separate module app = QtGui.QApplication(sys.argv)
app = QApplication(sys.argv) view = DesktopGameWindow()
view = MenuScreen()
view.show() view.show()
app.exec_() app.exec_()
sys.exit(0) sys.exit()
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -0,0 +1,81 @@
#
# Copyright (c) 2014 Dorian Pula <dorian.pula@amber-penguin-software.ca>
#
# justCheckers is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# justCheckers is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with justCheckers. If not, see <http://www.gnu.org/licenses/>.
#
# Please share and enjoy!
#
"""
Main window for the game.
:copyright: Copyright 2013, Dorian Pula <dorian.pula@amber-penguin-software.ca>
:license: GPL v3+
"""
import os
import sys
from PySide import QtCore
from PySide import QtGui
class MainMenuView(QtGui.QWidget):
# TODO Setup functional testing with PySide.QtTest
def __init__(self):
super(MainMenuView, self).__init__()
self.setup_components()
def setup_components(self):
"""Setup the components that make up the widget."""
print(self.get_system_info())
self.new_game = QtGui.QPushButton('&New Game', self)
self.open_game = QtGui.QPushButton('&Open Game', self)
self.save_game = QtGui.QPushButton('&Save Game', self)
# TODO Render buttons greyed out.
self.about_game = QtGui.QPushButton('About Game', self)
# TODO Add links to site and display license inside about game widget.
self.settings = QtGui.QPushButton('Settings', self)
self.exit_button = QtGui.QPushButton('Exit', self)
self.exit_button.clicked.connect(self.exit_app)
widget_layout = QtGui.QVBoxLayout(self)
widget_layout.addStretch()
widget_layout.addWidget(self.new_game)
widget_layout.addWidget(self.open_game)
widget_layout.addWidget(self.save_game)
widget_layout.addWidget(self.about_game)
widget_layout.addWidget(self.settings)
widget_layout.addWidget(self.exit_button)
widget_layout.addStretch()
self.setLayout(widget_layout)
@staticmethod
def get_system_info():
"""Retrieve information about the system."""
message = 'I am running on {os}.\nMy screen is {height}x{width}'
geometry = QtGui.QDesktopWidget().availableGeometry()
os_sys = sys.platform
if sys.platform == 'posix':
os_name, _, _, _, os_arch = os.uname()
os_sys = '{name} {arch}'.format(name=os_name, arch=os_arch)
return message.format(os=os_sys, height=geometry.height(), width=geometry.width())
def exit_app(self):
"""Exits the application."""
QtCore.QCoreApplication.instance().exit()

78
justcheckers/ui/window.py Normal file
View File

@ -0,0 +1,78 @@
#
# Copyright (c) 2014 Dorian Pula <dorian.pula@amber-penguin-software.ca>
#
# justCheckers is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# justCheckers is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with justCheckers. If not, see <http://www.gnu.org/licenses/>.
#
# Please share and enjoy!
#
"""
Main window for the game.
:copyright: Copyright 2013, Dorian Pula <dorian.pula@amber-penguin-software.ca>
:license: GPL v3+
"""
import os
from PySide import QtGui
from justcheckers.ui.menu_view import MainMenuView
class DesktopGameWindow(QtGui.QMainWindow):
# TODO Setup functional testing with PySide.QtTest
def __init__(self):
super(DesktopGameWindow, self).__init__()
self.setWindowTitle('justCheckers')
self.setGeometry(300, 300, 800, 600)
self.setWindowIcon(QtGui.QIcon(self.path_to_asset('icon.png')))
self.setup_components()
self.add_backdrop()
self.center()
def add_backdrop(self):
tile = QtGui.QPixmap(self.path_to_asset('backdrop.jpg'))
palette = QtGui.QPalette()
palette.setBrush(QtGui.QPalette.Background, tile)
self.setPalette(palette)
def setup_components(self):
"""Setup the components that make up the widget."""
self.view_stack = QtGui.QStackedWidget()
self.view_stack.addWidget(MainMenuView())
self.setCentralWidget(self.view_stack)
def center(self):
"""Centers the widget in the middle of the screen."""
widget_rectangle = self.frameGeometry()
center_point = QtGui.QDesktopWidget().availableGeometry().center()
widget_rectangle.moveCenter(center_point)
self.move(widget_rectangle.topLeft())
IMAGE_ASSETS = 'images'
TEXT_ASSETS = 'assets'
@staticmethod
def path_to_asset(filename, asset_type=IMAGE_ASSETS):
"""
Helper utility for getting the path to an asset.
:param filename: The filename of the asset.
:param asset_type: The type of asset. Defaults to images.
:return: The path to the asset.
"""
return os.path.join(os.path.dirname(__file__), os.pardir, asset_type.lower(), filename)

View File

@ -1,3 +1,4 @@
#!/usr/bin/env python
# coding=utf-8 # coding=utf-8
import re import re
@ -17,12 +18,12 @@ def gather_requirements(filename='requirements.txt'):
for requirement in raw_requirements for requirement in raw_requirements
if requirement.strip() and not re.match('#|-(?!e)', requirement)] if requirement.strip() and not re.match('#|-(?!e)', requirement)]
setup( setup(
name='justcheckers', name='justcheckers',
version='0.5.0', version='0.5.0',
packages=['justcheckers'],
url='http://justcheckers.org/', url='http://justcheckers.org/',
license='Affero GPL v3', license='GPL v3',
author='Dorian Pula', author='Dorian Pula',
author_email='dorian.pula@gmail.com', author_email='dorian.pula@gmail.com',
description='An advanced cross-platform checkers game.', description='An advanced cross-platform checkers game.',
@ -32,6 +33,33 @@ setup(
'web': gather_requirements('requirements/web.txt'), 'web': gather_requirements('requirements/web.txt'),
}, },
packages=find_packages('justcheckers'), packages=find_packages(exclude=['test']),
include_package_data=True, include_package_data=True,
entry_points={
'console_scripts': [
'justcheckers = justcheckers.app:main',
]
},
classifiers=[
'Development Status :: 3 - Alpha',
'Environment :: Console',
'Environment:: MacOS',
'Environment :: Web Environment',
'Environment :: Win32 (MS Windows)',
'Environment :: X11 Applications :: Qt',
'Intended Audience:: End Users / Desktop',
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX :: Linux',
'Operating System :: Unix',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Topic :: Games/Entertainment',
'Topic :: Games/Entertainment :: Board Games',
],
) )

0
test/__Init__.py Normal file
View File

0
test/game/__init__.py Normal file
View File