Skip to content

Commit

Permalink
layout of start screen fixed and new scenario signal type changed to …
Browse files Browse the repository at this point in the history
…fix PyQt5 inconsistencies when emitting dictionaries
  • Loading branch information
Trilarion committed Jul 10, 2017
1 parent 0c594a5 commit 875f8b4
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 23 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

[![Build Status](https://travis-ci.org/Trilarion/imperialism-remake.svg?branch=master)](https://travis-ci.org/Trilarion/imperialism-remake)

## Requirements

- Minimal screen size: 1024 x 768
- Python (with some modules (see below) or included in a package)

## Getting Started

### Access the source code
Expand Down
2 changes: 1 addition & 1 deletion source/imperialism_remake/base/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def extend(path, *parts):
@unique
class Option(utils.AutoNumberedEnum):
"""
Options as automatically numbered enum. The members of it are then the Options.
Options as automatically numbered enum. The members of it are then the Options.
"""
LOCALSERVER_OPEN = ()
# local server accepts outside connections
Expand Down
4 changes: 2 additions & 2 deletions source/imperialism_remake/base/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>

"""
Non-specific independent helper functions. Do not depend on any other part of the project except on package lib
and base.constants and is specifically used by the project.
Non-specific independent helper functions. Do not depend on any other part of the project except on package lib
and base.constants and is specifically used by the project.
"""

import PyQt5.QtGui as QtGui
Expand Down
28 changes: 15 additions & 13 deletions source/imperialism_remake/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@

class MapItem(QtCore.QObject):
"""
Holds together a clickable QPixmapItem, a description text and a reference to a label that
shows the text
Holds together a clickable QPixmapItem, a description text and a reference to a label that
shows the text
TODO use signals to show the text instead
TODO use signals to show the text instead
"""
description_change = QtCore.pyqtSignal(str)

Expand All @@ -75,22 +75,21 @@ def __init__(self, parent, pixmap, label, description):

def show_description(self):
"""
Shows the description in the label.
Shows the description in the label.
"""
self.label.setText('<font color=#ffffff size=6>{}</font>'.format(self.description))

def hide_description(self):
"""
Hides the description from the label.
Hides the description from the label.
"""
self.label.setText('')


# TODO convert to simple method which does it, no need to be a class
class StartScreen(QtWidgets.QWidget):
"""
Creates the start screen
TODO convert to simple method which does it, no need to be a class
Creates the start screen
"""

frame_pen = QtGui.QPen(QtGui.QBrush(QtGui.QColor(255, 255, 255, 64)), 6)
Expand All @@ -103,8 +102,8 @@ def __init__(self, client):

layout = qt.RelativeLayout(self)

start_image = QtGui.QPixmap(constants.extend(constants.GRAPHICS_UI_FOLDER,
'start.background.jpg'))
path = constants.extend(constants.GRAPHICS_UI_FOLDER, 'start.background.jpg')
start_image = QtGui.QPixmap(path)
start_image_item = QtWidgets.QGraphicsPixmapItem(start_image)
start_image_item.setZValue(1)

Expand All @@ -121,6 +120,8 @@ def __init__(self, client):
layout.addWidget(view)

subtitle = QtWidgets.QLabel('')
subtitle.resize(0,0)
# TODO this is below the main image but collides with screens only 768 px high
subtitle.layout_constraint = qt.RelativeLayoutConstraint(
(0.5, -0.5, 0), (0.5, -0.5, start_image.height() / 2 + 20))
layout.addWidget(subtitle)
Expand All @@ -142,7 +143,7 @@ def __init__(self, client):
for k, v in image_map.items():
# add action from our predefined action dictionary
pixmap = QtGui.QPixmap(constants.extend(constants.GRAPHICS_UI_FOLDER, v['overlay']))
map_item = MapItem(view, pixmap, label=subtitle, description=v['label'])
map_item = MapItem(scene, pixmap, label=subtitle, description=v['label'])
map_item.item.setZValue(3)
offset = v['offset']
map_item.item.setOffset(QtCore.QPointF(offset[0], offset[1]))
Expand All @@ -156,6 +157,7 @@ def __init__(self, client):

version_label = QtWidgets.QLabel('<font color=#ffffff>{}</font>'
.format(version.__version_full__))
version_label.resize(version_label.sizeHint())
version_label.layout_constraint = qt.RelativeLayoutConstraint().east(20).south(20)
layout.addWidget(version_label)

Expand Down Expand Up @@ -400,7 +402,7 @@ def local_network_connect():

def start_client():
"""
Creates the Qt application and shows the main window.
Creates the Qt application and shows the main window.
"""

# create app
Expand Down Expand Up @@ -445,8 +447,8 @@ def start_client():
client = Client()
client.switch_to_start_screen()

# start Qt app execution and immediately try to connect to local server
logger.info('client initialized, start Qt app execution')
# TODO is this necessary to run as event?
# noinspection PyCallByClass
QtCore.QTimer.singleShot(0, local_network_connect)
app.exec_()
5 changes: 4 additions & 1 deletion source/imperialism_remake/client/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,10 @@ class NewScenarioWidget(QtWidgets.QWidget):
"""

#: signal, emitted if this dialog finishes successfully and transmits parameters in the dictionary
finished = QtCore.pyqtSignal(dict)
finished = QtCore.pyqtSignal(object)
# see also: https://stackoverflow.com/questions/43964766/pyqt-emit-signal-with-dict
# and https://www.riverbankcomputing.com/pipermail/pyqt/2017-May/039175.html
# may be changed back to dict with a later PyQt5 version

def __init__(self, *args, **kwargs):
"""
Expand Down
14 changes: 8 additions & 6 deletions source/imperialism_remake/lib/qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>

"""
Graphics (PyQt5) based objects and algorithms that do not depend specifically on the project but only on PyQt5.
Graphics (PyQt5) based objects and algorithms that do not depend specifically on the project but only on PyQt5.
Abstraction of the used elements in the project to achieve an intermediate layer and to minimize dependencies.
Abstraction of the used elements in the project to achieve an intermediate layer and to minimize dependencies.
"""

from datetime import datetime
Expand Down Expand Up @@ -147,7 +147,7 @@ class RelativeLayout(QtWidgets.QLayout):
An implementation of QLayout working with RelativeLayoutConstraints so the position can be estimated by
method calculate_relative_position()
Note: No margins in this layout.
Note: No margins in this layout. The elements must have been set to their target size.
"""

def __init__(self, *args):
Expand All @@ -174,12 +174,14 @@ def sizeHint(self): # noqa: N802

def setGeometry(self, rect: QtCore.QRect): # noqa: N802
"""
Layout the elements by calculating their relative position inside the parent, given the parents coordinates.
Layout the elements by calculating their relative position inside the parent, given the parents coordinates
and the sizes of the elements. The width and height are not changed but the offset is computed according to
the layout constraint and the parent size.
:param rect: Position and size of the parent.
"""
for item in self.items:
o_size = item.sizeHint()
o_size = item.widget().size()

c = item.widget().layout_constraint

Expand Down Expand Up @@ -217,7 +219,7 @@ def minimumSize(self): # noqa: N802
min_height = 0

for item in self.items:
o_size = item.sizeHint()
o_size = item.widget().size()

c = item.widget().layout_constraint
gap_x = abs(c.x[2])
Expand Down

0 comments on commit 875f8b4

Please sign in to comment.