def show_notification(self):
     message = 'Test notification'
     self.notification = qt.Notification(
         self,
         message,
         position_constraint=qt.RelativeLayoutConstraint(
         ).center_horizontal().south(20))
     self.notification.show()
Esempio n. 2
0
    def test_calculate_constraints(self):

        parent = QtCore.QRect(10, 10, 1000, 500)
        size = QtCore.QSize(200, 100)

        constraint = qt.RelativeLayoutConstraint().south(10).west(20)
        x, y = qt.calculate_relative_position(parent, size, constraint)
        self.assertEqual((x, y), (30, 400))

        constraint = qt.RelativeLayoutConstraint().north(30).east(40)
        x, y = qt.calculate_relative_position(parent, size, constraint)
        self.assertEqual((x, y), (770, 40))

        constraint = qt.RelativeLayoutConstraint().center_horizontal(
        ).center_vertical()
        x1, y1 = qt.calculate_relative_position(parent, size, constraint)
        self.assertEqual((x1, y1), (410, 210))
Esempio n. 3
0
    def __init__(self):
        """
        Create the main window, the help browser dialog, the audio player, ...
        """
        # main window
        self.main_window = QtWidgets.QWidget()
        # set geometry
        self.main_window.setGeometry(
            tools.get_option(constants.Option.MAINWINDOW_BOUNDS))
        # set title
        self.main_window.setWindowTitle('Imperialism Remake')
        # show in full screen, maximized or normal
        if tools.get_option(constants.Option.MAINWINDOW_FULLSCREEN):
            self.main_window.setWindowFlags(self.main_window.windowFlags()
                                            | QtCore.Qt.FramelessWindowHint)
            self.main_window.showFullScreen()
        elif tools.get_option(constants.Option.MAINWINDOW_MAXIMIZED):
            self.main_window.showMaximized()
        else:
            self.main_window.show()

        # widget switcher
        self.widget_switcher = qt.WidgetSwitcher(self.main_window)

        # help browser
        # TODO help browser only if QtWebEngineWidgets available (or preferences)
        # self.help_browser_widget = qt.BrowserWidget(tools.load_ui_icon)
        # self.help_browser_widget = qt.BrowserWidget(tools.load_ui_icon)
        # self.help_browser_widget.home_url = tools.local_url(constants.DOCUMENTATION_INDEX_FILE)
        # self.help_browser_widget.home()
        # self.help_dialog = graphics.GameDialog(self.main_window, self.help_browser_widget, title='Help')
        # self.help_dialog.setFixedSize(QtCore.QSize(800, 600))
        # move to lower right border, so that overlap with other windows is not that strong
        # self.help_dialog.move(self.main_window.x() + self.main_window.width() - 800,
        #                      self.main_window.y() + self.main_window.height() - 600)

        # add help browser keyboard shortcut
        action = QtWidgets.QAction(self.main_window)
        action.setShortcut(QtGui.QKeySequence('F1'))
        action.triggered.connect(self.show_help_browser)
        self.main_window.addAction(action)

        # add server monitor keyboard shortcut
        action = QtWidgets.QAction(self.main_window)
        action.setShortcut(QtGui.QKeySequence('F2'))
        action.triggered.connect(self.show_server_monitor)
        self.main_window.addAction(action)

        # for the notifications
        self.pending_notifications = []
        self.notification_position_constraint = qt.RelativeLayoutConstraint().center_horizontal()\
            .south(20)
        self.notification = None

        # after the player starts, the main window is not active anymore
        # set it active again or it doesn't get keyboard focus
        self.main_window.activateWindow()
Esempio n. 4
0
    def __init__(self):
        """
            Create the main window, the help browser dialog, the audio player, ...
        """
        # main window
        self.main_window = ClientMainWindowWidget()

        # help browser
        # TODO help browser only if
        # self.help_browser_widget = qt.BrowserWidget(tools.load_ui_icon)
        # self.help_browser_widget = qt.BrowserWidget(tools.load_ui_icon)
        # self.help_browser_widget.home_url = tools.local_url(constants.DOCUMENTATION_INDEX_FILE)
        # self.help_browser_widget.home()
        # self.help_dialog = graphics.GameDialog(self.main_window, self.help_browser_widget, title='Help')
        # self.help_dialog.setFixedSize(QtCore.QSize(800, 600))
        # move to lower right border, so that overlap with other windows is not that strong
        # self.help_dialog.move(self.main_window.x() + self.main_window.width() - 800,
        #                      self.main_window.y() + self.main_window.height() - 600)

        # add help browser keyboard shortcut
        action = QtWidgets.QAction(self.main_window)
        action.setShortcut(QtGui.QKeySequence('F1'))
        action.triggered.connect(self.show_help_browser)
        self.main_window.addAction(action)

        # add server monitor keyboard shortcut
        action = QtWidgets.QAction(self.main_window)
        action.setShortcut(QtGui.QKeySequence('F2'))
        action.triggered.connect(self.show_server_monitor)
        self.main_window.addAction(action)

        # for the notifications
        self.pending_notifications = []
        self.notification_position_constraint = qt.RelativeLayoutConstraint(
        ).center_horizontal().south(20)
        self.notification = None

        # after the player starts, the main window is not active anymore
        # set it active again or it doesn't get keyboard focus
        self.main_window.activateWindow()
Esempio n. 5
0
    def __init__(self, client):
        super().__init__()

        self.setAttribute(QtCore.Qt.WA_StyledBackground)
        self.setProperty('background', 'black')

        layout = qt.RelativeLayout(self)

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

        scene = QtWidgets.QGraphicsScene(self)
        scene.addItem(start_image_item)

        view = QtWidgets.QGraphicsView(scene)
        view.resize(start_image.size())
        view.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        view.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        view.setSceneRect(0, 0, start_image.width(), start_image.height())
        view.layout_constraint = qt.RelativeLayoutConstraint(
        ).center_horizontal().center_vertical()
        layout.addWidget(view)

        subtitle = QtWidgets.QLabel('')
        subtitle.layout_constraint = qt.RelativeLayoutConstraint(
            (0.5, -0.5, 0), (0.5, -0.5, start_image.height() / 2 + 20))
        layout.addWidget(subtitle)

        actions = {
            'exit': client.quit,
            'help': client.show_help_browser,
            'lobby': client.show_game_lobby_dialog,
            'editor': client.switch_to_editor_screen,
            'options': client.show_preferences_dialog
        }

        image_map_file = constants.extend(constants.GRAPHICS_UI_FOLDER,
                                          'start.overlay.info')
        image_map = utils.read_as_yaml(image_map_file)

        # security check, they have to be the same
        if list(actions.keys()) != list(image_map.keys()):
            raise RuntimeError(
                'Start screen hot map info file ({}) corrupt.'.format(
                    image_map_file))

        for k, v in list(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.item.setZValue(3)
            offset = v['offset']
            map_item.item.setOffset(QtCore.QPointF(offset[0], offset[1]))
            map_item.item.signaller.clicked.connect(actions[k])

            frame_path = QtGui.QPainterPath()
            frame_path.addRect(map_item.item.boundingRect())
            frame_item = scene.addPath(frame_path, StartScreen.frame_pen)
            frame_item.setZValue(4)
            scene.addItem(map_item.item)

        version_label = QtWidgets.QLabel(
            '<font color=#ffffff>{}</font>'.format(version.__version_full__))
        version_label.layout_constraint = qt.RelativeLayoutConstraint().east(
            20).south(20)
        layout.addWidget(version_label)
Esempio n. 6
0
def playlist_index_changed(position):
    print('Next song')
    qt.Notification(window,
                    'Next song',
                    position_constraint=qt.RelativeLayoutConstraint().
                    center_horizontal().south(20))
Esempio n. 7
0
def create_start_screen_widget(actions):
    """
    Creates the start screen.

    :param client:
    :return:
    """

    screen = QtWidgets.QWidget()
    screen.setAttribute(QtCore.Qt.WA_StyledBackground, True)
    screen.setProperty('background', 'black')

    layout = qt.RelativeLayout(screen)

    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)

    scene = QtWidgets.QGraphicsScene(screen)
    scene.addItem(start_image_item)

    view = QtWidgets.QGraphicsView(scene)
    view.resize(start_image.size())
    view.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
    view.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
    view.setSceneRect(0, 0, start_image.width(), start_image.height())
    view.layout_constraint = qt.RelativeLayoutConstraint().center_horizontal()\
        .center_vertical()
    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)

    image_map_file = constants.extend(constants.GRAPHICS_UI_FOLDER,
                                      'start.overlay.info')
    image_map = utils.read_as_yaml(image_map_file)

    # security check, they have to be the same
    if actions.keys() != image_map.keys():
        raise RuntimeError(
            'Start screen hot map info file ({}) corrupt.'.format(
                image_map_file))

    frame_pen = QtGui.QPen(QtGui.QBrush(QtGui.QColor(255, 255, 255, 64)), 6)
    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(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]))
        map_item.item.signaller.clicked.connect(actions[k])

        frame_path = QtGui.QPainterPath()
        frame_path.addRect(map_item.item.boundingRect())
        frame_item = scene.addPath(frame_path, frame_pen)
        frame_item.setZValue(4)
        scene.addItem(map_item.item)

    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)

    return screen