Example #1
0
    def __init__(self, client):
        super().__init__()

        self.toolbar = QtWidgets.QToolBar()
        action_help = QtWidgets.QAction(tools.load_ui_icon('icon.help.png'), 'Show help', self)
        action_help.triggered.connect(client.show_help_browser)  # TODO with partial make reference to specific page
        self.toolbar.addAction(action_help)

        action_quit = QtWidgets.QAction(tools.load_ui_icon('icon.back_to_startscreen.png'), 'Exit to main menu', self)
        action_quit.triggered.connect(client.switch_to_start_screen)
        self.toolbar.addAction(action_quit)

        # main map
        self.main_map = MainMap()

        # mini map
        self.mini_map = MiniMap()

        # info box
        self.info_box = InfoBox()

        # layout
        layout = QtWidgets.QGridLayout(self)
        layout.addWidget(self.toolbar, 0, 0)
        layout.addWidget(self.mini_map, 1, 0)
        layout.addWidget(self.info_box, 2, 0)
        layout.addWidget(self.main_map, 0, 1, 3, 1)
        layout.setRowStretch(2, 1)  # the info box will take all vertical space left
        layout.setColumnStretch(1, 1)  # the main map will take all horizontal space left
Example #2
0
    def __init__(self, *args, **kwargs):
        """
        Sets up the graphics view.
        """
        super().__init__(*args, **kwargs)
        self.setObjectName('mini-map-widget')

        layout = QtWidgets.QVBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)

        # the content is a scene
        self.scene = QtWidgets.QGraphicsScene()

        # tracker rectangle that tracks the view of the map, initially hidden
        self.tracker = QtWidgets.QGraphicsRectItem()
        self.tracker.setCursor(QtCore.Qt.PointingHandCursor)
        self.tracker.setZValue(1000)
        self.tracker.hide()
        self.scene.addItem(self.tracker)

        # the view on the scene (no scroll bars)
        self.view = QtWidgets.QGraphicsView(self.scene)
        self.view.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.view.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        layout.addWidget(self.view)

        # the width and height (fixed width throughout the game)
        # TODO make this adjustable
        self.view.setFixedWidth(self.VIEW_WIDTH)
        view_height = math.floor(0.6 * self.VIEW_WIDTH)
        self.view.setFixedHeight(view_height)

        # tool bar below the mini map
        self.toolbar = QtWidgets.QToolBar()
        self.toolbar.setIconSize(QtCore.QSize(20, 20))

        # action group (only one of them can be checked at each time)
        action_group = QtWidgets.QActionGroup(self.toolbar)
        # political view in the beginning
        a = qt.create_action(tools.load_ui_icon('icon.mini.political.png'), 'Show political view', action_group,
            toggle_connection=self.switch_to_political_view, checkable=True)
        self.toolbar.addAction(a)
        # geographical view
        a = qt.create_action(tools.load_ui_icon('icon.mini.geographical.png'), 'Show geographical view', action_group,
            toggle_connection=self.switch_to_geographical_view, checkable=True)
        self.toolbar.addAction(a)
        self.mode = constants.OverviewMapMode.POLITICAL

        # wrap tool bar into horizontal layout with stretch
        l = QtWidgets.QHBoxLayout()
        l.setContentsMargins(0, 0, 0, 0)
        l.addWidget(self.toolbar)
        l.addStretch()

        # add layout containing tool bar
        layout.addLayout(l)

        # graphics items in scene (except the tracker)
        self.scene_items = []
Example #3
0
    def contextMenuEvent(self, event):
        """
        Right click (context click) on a tile. Shows the context menu, depending on the tile position
        """

        # get mouse position in scene coordinates
        scene_position = self.mapToScene(event.pos()) / self.TILE_SIZE
        column, row = editor_scenario.scenario.map_position(scene_position.x(), scene_position.y())

        # create context menu
        menu = QtWidgets.QMenu(self)

        # change terrain
        a = qt.create_action(tools.load_ui_icon('icon.editor.change_terrain.png'), 'Set terrain', self, partial(self.change_terrain.emit, column, row))
        menu.addAction(a)

        # is there a province
        province = editor_scenario.scenario.province_at(column, row)
        if province:
            a = qt.create_action(tools.load_ui_icon('icon.editor.province_info.png'), 'Province info', self, partial(self.province_info.emit, province))
            menu.addAction(a)

            # is there also nation
            nation = editor_scenario.scenario.province_property(province, constants.ProvinceProperty.NATION)
            if nation:
                a = qt.create_action(tools.load_ui_icon('icon.editor.nation_info.png'), 'Nation info', self, partial(self.nation_info.emit, nation))
                menu.addAction(a)

        menu.exec(event.globalPos())
Example #4
0
    def __init__(self, *args, **kwargs):
        """
        Create toolbar.
        """
        super().__init__(*args, **kwargs)

        self.layout = QtWidgets.QVBoxLayout(self)
        self.layout.setContentsMargins(0, 0, 0, 0)

        # create tool bar
        toolbar = QtWidgets.QToolBar()
        action_group = QtWidgets.QActionGroup(toolbar)

        # actions single player new/load
        a = qt.create_action(tools.load_ui_icon('icon.lobby.single.new.png'), 'Start new single player scenario', action_group, toggle_connection=self.toggled_single_player_scenario_selection, checkable=True)
        toolbar.addAction(a)
        a = qt.create_action(tools.load_ui_icon('icon.lobby.single.load.png'), 'Continue saved single player scenario', action_group, toggle_connection=self.toggled_single_player_load_scenario, checkable=True)
        toolbar.addAction(a)

        toolbar.addSeparator()

        # actions multi player
        a = qt.create_action(tools.load_ui_icon('icon.lobby.network.png'), 'Show server lobby', action_group, toggle_connection=self.toggled_server_lobby, checkable=True)
        toolbar.addAction(a)
        a = qt.create_action(tools.load_ui_icon('icon.lobby.multiplayer-game.png'), 'Start or continue multiplayer scenario', action_group, toggle_connection=self.toggled_multiplayer_scenario_selection, checkable=True)
        toolbar.addAction(a)

        self.layout.addWidget(toolbar, alignment=QtCore.Qt.AlignTop)

        self.content = None
Example #5
0
    def __init__(self, *args, **kwargs):
        """
        Sets up the graphics view, the toolbar and the tracker rectangle.
        """
        super().__init__(*args, **kwargs)
        self.setObjectName('mini-map-widget')

        layout = QtWidgets.QVBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)

        # the content is a scene
        self.scene = QtWidgets.QGraphicsScene()

        # tracker rectangle that tracks the view of the map, initially hidden
        self.tracker = QtWidgets.QGraphicsRectItem()
        self.tracker.setCursor(QtCore.Qt.PointingHandCursor)
        self.tracker.setZValue(1000)
        self.tracker.hide()
        self.scene.addItem(self.tracker)

        # the view on the scene (no scroll bars)
        self.view = QtWidgets.QGraphicsView(self.scene)
        self.view.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.view.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        layout.addWidget(self.view)

        # the width and height (fixed width throughout the game)
        # TODO make this adjustable
        self.view.setFixedWidth(self.VIEW_WIDTH)
        view_height = math.floor(0.6 * self.VIEW_WIDTH)
        self.view.setFixedHeight(view_height)

        # tool bar below the mini map
        self.toolbar = QtWidgets.QToolBar()
        self.toolbar.setIconSize(QtCore.QSize(20, 20))

        # action group (only one of them can be checked at each time)
        action_group = QtWidgets.QActionGroup(self.toolbar)
        # political view in the beginning
        a = qt.create_action(tools.load_ui_icon('icon.mini.political.png'), 'Show political view', action_group, toggle_connection=self.switch_to_political_view, checkable=True)
        self.toolbar.addAction(a)
        # geographical view
        a = qt.create_action(tools.load_ui_icon('icon.mini.geographical.png'), 'Show geographical view', action_group, toggle_connection=self.switch_to_geographical_view, checkable=True)
        self.toolbar.addAction(a)
        self.mode = constants.OverviewMapMode.POLITICAL

        # wrap tool bar into horizontal layout with stretch
        l = QtWidgets.QHBoxLayout()
        l.setContentsMargins(0, 0, 0, 0)
        l.addWidget(self.toolbar)
        l.addStretch()

        # add layout containing tool bar
        layout.addLayout(l)

        # graphics items in scene (except the tracker)
        self.scene_items = []
Example #6
0
    def __init__(self, initial_nation=None):
        super().__init__()

        widget_layout = QtWidgets.QVBoxLayout(self)

        # toolbar
        toolbar = QtWidgets.QToolBar()
        a = qt.create_action(tools.load_ui_icon('icon.add.png'), 'Add nation', toolbar, self.add_nation)
        toolbar.addAction(a)
        a = qt.create_action(tools.load_ui_icon('icon.delete.png'), 'Remove nation', toolbar, self.remove_nation)
        toolbar.addAction(a)
        widget_layout.addLayout(qt.wrap_in_boxlayout(toolbar))

        # nation selection combo box
        label = QtWidgets.QLabel('Choose')
        self.nation_combobox = QtWidgets.QComboBox()
        self.nation_combobox.setFixedWidth(200)
        self.nation_combobox.currentIndexChanged.connect(self.nation_selected)
        widget_layout.addWidget(qt.wrap_in_groupbox(qt.wrap_in_boxlayout((label, self.nation_combobox)), 'Nations'))

        # nation info panel
        layout = QtWidgets.QVBoxLayout()

        # description
        self.description_edit = QtWidgets.QLineEdit()
        self.description_edit.setFixedWidth(300)
        self.description_edit.setText('Test')
        layout.addLayout(qt.wrap_in_boxlayout((QtWidgets.QLabel('Description'), self.description_edit)))

        # color
        self.color_picker = QtWidgets.QPushButton()
        self.color_picker.setFixedSize(24, 24)
        self.color_picker.clicked.connect(self.show_color_picker)
        layout.addLayout(qt.wrap_in_boxlayout((QtWidgets.QLabel('Color'), self.color_picker)))

        # capital province
        self.capital_province_edit = QtWidgets.QLineEdit()
        self.capital_province_edit.setFixedWidth(300)
        layout.addLayout(qt.wrap_in_boxlayout((QtWidgets.QLabel('Capital'), self.capital_province_edit)))

        # all provinces
        self.provinces_combobox = QtWidgets.QComboBox()
        self.provinces_combobox.setFixedWidth(300)
        self.number_provinces_label = QtWidgets.QLabel()
        layout.addLayout(qt.wrap_in_boxlayout((self.number_provinces_label, self.provinces_combobox)))

        widget_layout.addWidget(qt.wrap_in_groupbox(layout, 'Info'))

        # vertical stretch
        widget_layout.addStretch()

        # reset content
        self.reset_content()

        # select initial nation if given
        if initial_nation:
            index = utils.index_of_element(self.nations, initial_nation)
            self.nation_combobox.setCurrentIndex(index)
Example #7
0
    def __init__(self, parent, content, title=None, modal=True, delete_on_close=False, help_callback=None,
                 close_callback=None):
        # no frame but a standalone window
        super().__init__(parent, flags=QtCore.Qt.FramelessWindowHint | QtCore.Qt.Window)

        # we need this
        self.setAttribute(QtCore.Qt.WA_StyledBackground)
        self.setObjectName('game-dialog')

        # should be deleted on close
        if delete_on_close:
            self.setAttribute(QtCore.Qt.WA_DeleteOnClose)

        # default state is Qt.NonModal
        if modal:
            self.setWindowModality(QtCore.Qt.WindowModal)

        # title bar
        title_bar = qt.DraggableToolBar()
        title_bar.setIconSize(QtCore.QSize(20, 20))
        title_bar.setObjectName('game-dialog-titlebar')
        title_bar.setSizePolicy(QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Fixed)
        title_bar.dragged.connect(lambda delta: self.move(self.pos() + delta))

        # title in titlebar and close icon
        title = QtWidgets.QLabel(title)
        title.setObjectName('game-dialog-title')
        title_bar.addWidget(title)

        # spacer between titlebar and help/close cursors
        spacer = QtWidgets.QWidget()
        spacer.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
        title_bar.addWidget(spacer)

        # if help call back is given, add help icon
        if help_callback:
            help_action = QtWidgets.QAction(tools.load_ui_icon('icon.help.png'), 'Help', title_bar)
            help_action.triggered.connect(help_callback)
            title_bar.addAction(help_action)

        self.close_callback = close_callback
        # the close button always calls self.close (but in closeEvent we call the close callback if existing)
        close_action = QtWidgets.QAction(tools.load_ui_icon('icon.close.png'), 'Close', title_bar)
        close_action.triggered.connect(self.close)
        title_bar.addAction(close_action)

        # escape key for close
        action = QtWidgets.QAction(self)
        action.setShortcut(QtGui.QKeySequence('Escape'))
        action.triggered.connect(self.close)
        self.addAction(action)

        # layout is 2 pixel contents margin (border), title bar and content widget
        self.layout = QtWidgets.QVBoxLayout(self)
        self.layout.setContentsMargins(2, 2, 2, 2)
        self.layout.addWidget(title_bar)
        self.layout.addWidget(content)
Example #8
0
    def __init__(self, parent, content, title=None, modal=True, delete_on_close=False, help_callback=None,
                 close_callback=None):
        # no frame but a standalone window
        super().__init__(parent, flags=QtCore.Qt.FramelessWindowHint | QtCore.Qt.Window)

        # we need this
        self.setAttribute(QtCore.Qt.WA_StyledBackground)
        self.setObjectName('game-dialog')

        # should be deleted on close
        if delete_on_close:
            self.setAttribute(QtCore.Qt.WA_DeleteOnClose)

        # default state is Qt.NonModal
        if modal:
            self.setWindowModality(QtCore.Qt.WindowModal)

        # title bar
        title_bar = qt.DraggableToolBar()
        title_bar.setIconSize(QtCore.QSize(20, 20))
        title_bar.setObjectName('game-dialog-titlebar')
        title_bar.setSizePolicy(QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Fixed)
        title_bar.dragged.connect(lambda delta: self.move(self.pos() + delta))

        # title in titlebar and close icon
        title = QtWidgets.QLabel(title)
        title.setObjectName('game-dialog-title')
        title_bar.addWidget(title)

        # spacer between titlebar and help/close icons
        spacer = QtWidgets.QWidget()
        spacer.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
        title_bar.addWidget(spacer)

        # if help call back is given, add help icon
        if help_callback:
            help_action = QtWidgets.QAction(tools.load_ui_icon('icon.help.png'), 'Help', title_bar)
            help_action.triggered.connect(help_callback)
            title_bar.addAction(help_action)

        self.close_callback = close_callback
        # the close button always calls self.close (but in closeEvent we call the close callback if existing)
        close_action = QtWidgets.QAction(tools.load_ui_icon('icon.close.png'), 'Close', title_bar)
        close_action.triggered.connect(self.close)
        title_bar.addAction(close_action)

        # escape key for close
        action = QtWidgets.QAction(self)
        action.setShortcut(QtGui.QKeySequence('Escape'))
        action.triggered.connect(self.close)
        self.addAction(action)

        # layout is 2 pixel contents margin (border), title bar and content widget
        self.layout = QtWidgets.QVBoxLayout(self)
        self.layout.setContentsMargins(2, 2, 2, 2)
        self.layout.addWidget(title_bar)
        self.layout.addWidget(content)
Example #9
0
    def __init__(self, *args, **kwargs):
        """
        Create and add all tab
        """
        super().__init__(*args, **kwargs)

        toolbar = QtWidgets.QToolBar()
        toolbar.setIconSize(QtCore.QSize(32, 32))
        action_group = QtWidgets.QActionGroup(toolbar)

        # general preferences
        action_general = qt.create_action(tools.load_ui_icon('icon.preferences.general.png'), 'Show general preferences', action_group, toggle_connection=self._toggled_action_preferences_general, checkable=True)
        toolbar.addAction(action_general)

        # network preferences
        a = qt.create_action(tools.load_ui_icon('icon.preferences.network.png'), 'Show network preferences', action_group, toggle_connection=self._toggled_action_preferences_network, checkable=True)
        toolbar.addAction(a)

        # graphics preferences
        a = qt.create_action(tools.load_ui_icon('icon.preferences.graphics.png'), 'Show graphics preferences', action_group, toggle_connection=self._toggled_action_preferences_graphics, checkable=True)
        toolbar.addAction(a)

        # music preferences
        a = qt.create_action(tools.load_ui_icon('icon.preferences.music.png'), 'Show music preferences', action_group, toggle_connection=self._toggled_action_preferences_music, checkable=True)
        toolbar.addAction(a)

        # spacer
        spacer = QtWidgets.QWidget()
        spacer.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
        toolbar.addWidget(spacer)

        # reset preferences
        a = QtWidgets.QAction(tools.load_ui_icon('icon.preferences.reset.png'), 'Reset preferences', self)
        a.triggered.connect(self.reset_preferences)
        toolbar.addAction(a)

        self.stacked_layout = QtWidgets.QStackedLayout()

        layout = QtWidgets.QVBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(toolbar)
        layout.addLayout(self.stacked_layout)

        # empty lists
        self._check_boxes = []
        self._line_edits = []
        self._sliders = []

        # add tabs
        self._layout_widget_preferences_general()
        self._layout_widget_preferences_graphics()
        self._layout_widget_preferences_music()
        self._layout_widget_preferences_network()

        # initially show general preferences
        action_general.setChecked(True)
Example #10
0
    def contextMenuEvent(self, event):  # noqa: N802
        """
        Right click (context click) on a tile. Shows the context menu, depending on the tile position
        """

        logger.debug('contextMenuEvent event.pos:%s', event.pos())

        # if there is no scenario existing, don't process the context click
        if not self.scenario.server_scenario:
            return

        # get mouse position in scene coordinates
        scene_position = self.mapToScene(event.pos()) / constants.TILE_SIZE
        column, row = self.scenario.server_scenario.map_position(
            scene_position.x(), scene_position.y())

        # create context menu
        menu = QtWidgets.QMenu(self)

        # change terrain
        a = qt.create_action(
            tools.load_ui_icon('icon.editor.change_terrain.png'),
            'Set terrain', self, partial(self.change_terrain.emit, column,
                                         row))
        menu.addAction(a)

        terrain_type = self.scenario.server_scenario.terrain_at(column, row)
        if terrain_type != TerrainType.SEA.value:
            a = qt.create_action(
                tools.load_ui_icon('icon.editor.change_terrain_resource.png'),
                'Set resource', self,
                partial(self.change_terrain_resource.emit, column, row))
            menu.addAction(a)

        # is there a province
        province = self.scenario.server_scenario.province_at(column, row)
        if province:
            a = qt.create_action(
                tools.load_ui_icon('icon.editor.province_info.png'),
                'Province info', self,
                partial(self.province_info.emit, province))
            menu.addAction(a)

            # is there also nation
            nation = self.scenario.server_scenario.province_property(
                province, constants.ProvinceProperty.NATION)
            if nation:
                a = qt.create_action(
                    tools.load_ui_icon('icon.editor.nation_info.png'),
                    'Nation info', self, partial(self.nation_info.emit,
                                                 nation))
                menu.addAction(a)

        menu.exec(event.globalPos())
Example #11
0
    def __init__(self, *args, **kwargs):
        """
        Create toolbar.
        """
        super().__init__(*args, **kwargs)

        self.layout = QtWidgets.QVBoxLayout(self)
        self.layout.setContentsMargins(0, 0, 0, 0)

        # create tool bar
        toolbar = QtWidgets.QToolBar()
        action_group = QtWidgets.QActionGroup(toolbar)

        # actions single player new/load
        a = qt.create_action(
            tools.load_ui_icon('icon.lobby.single.new.png'),
            'Start new single player scenario',
            action_group,
            toggle_connection=self.toggled_single_player_scenario_selection,
            checkable=True)
        toolbar.addAction(a)
        a = qt.create_action(
            tools.load_ui_icon('icon.lobby.single.load.png'),
            'Continue saved single player scenario',
            action_group,
            toggle_connection=self.toggled_single_player_load_scenario,
            checkable=True)
        toolbar.addAction(a)

        toolbar.addSeparator()

        # actions multi player
        a = qt.create_action(tools.load_ui_icon('icon.lobby.network.png'),
                             'Show server lobby',
                             action_group,
                             toggle_connection=self.toggled_server_lobby,
                             checkable=True)
        toolbar.addAction(a)
        a = qt.create_action(
            tools.load_ui_icon('icon.lobby.multiplayer-game.png'),
            'Start or continue multiplayer scenario',
            action_group,
            toggle_connection=self.toggled_multiplayer_scenario_selection,
            checkable=True)
        toolbar.addAction(a)

        self.layout.addWidget(toolbar, alignment=QtCore.Qt.AlignTop)

        self.content = None
Example #12
0
    def __init__(self, *args, **kwargs):
        """
        All the necessary initializations. Is shown at the end.
        """
        super().__init__(*args, **kwargs)
        # set geometry
        self.setGeometry(tools.get_option(constants.Option.MAINWINDOW_BOUNDS))
        # set icon
        self.setWindowIcon(tools.load_ui_icon('window.icon.ico'))
        # set title
        self.setWindowTitle('Imperialism Remake')

        # just a layout but nothing else
        self.layout = QtWidgets.QHBoxLayout(self)
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.content = None

        # show in full screen, maximized or normal
        if tools.get_option(constants.Option.MAINWINDOW_FULLSCREEN):
            self.setWindowFlags(self.windowFlags() | QtCore.Qt.FramelessWindowHint)
            self.showFullScreen()
        elif tools.get_option(constants.Option.MAINWINDOW_MAXIMIZED):
            self.showMaximized()
        else:
            self.show()

        # loading animation
        # TODO animation right and start, stop in client
        self.animation = QtGui.QMovie(constants.extend(constants.GRAPHICS_UI_FOLDER, 'loading.gif'))
        # self.animation.start()
        self.loading_label = QtWidgets.QLabel(self, flags=QtCore.Qt.FramelessWindowHint | QtCore.Qt.Window)
        self.loading_label.setAttribute(QtCore.Qt.WA_TranslucentBackground)
        self.loading_label.setMovie(self.animation)
Example #13
0
    def __init__(self, scenario, initial_province=None):
        super().__init__()

        self.scenario = scenario

        widget_layout = QtWidgets.QVBoxLayout(self)

        # toolbar
        toolbar = QtWidgets.QToolBar()
        a = qt.create_action(tools.load_ui_icon('icon.add.png'),
                             'Add province', toolbar, self.add_province)
        toolbar.addAction(a)
        a = qt.create_action(tools.load_ui_icon('icon.delete.png'),
                             'Remove province', toolbar, self.remove_province)
        toolbar.addAction(a)
        widget_layout.addLayout(qt.wrap_in_boxlayout(toolbar))

        # provinces selection combo box
        label = QtWidgets.QLabel('Choose')
        self.provinces_combobox = QtWidgets.QComboBox()
        self.provinces_combobox.setFixedWidth(200)
        self.provinces_combobox.currentIndexChanged.connect(
            self.province_combobox_index_changed)
        widget_layout.addWidget(
            qt.wrap_in_groupbox(
                qt.wrap_in_boxlayout((label, self.provinces_combobox)),
                constants.SCENARIO_FILE_PROVINCES))

        # province info panel
        layout = QtWidgets.QVBoxLayout()

        # nation
        self.nation_label = QtWidgets.QLabel('Nation')
        layout.addWidget(self.nation_label)

        widget_layout.addWidget(qt.wrap_in_groupbox(layout, 'Info'))

        # vertical stretch
        widget_layout.addStretch()

        # reset content
        self.reset_content()

        # if province is given, select it
        if initial_province:
            index = utils.index_of_element(self.provinces, initial_province)
            self.provinces_combobox.setCurrentIndex(index)
Example #14
0
def start_client():
    """
    Creates the Qt application and shows the main window.
    """

    logger.debug('start_client')

    # create app
    app = QtWidgets.QApplication([])

    # test for desktop availability
    desktop = app.desktop()
    rect = desktop.screenGeometry()
    if ((rect.width() < constants.MINIMAL_SCREEN_SIZE[0])
            or (rect.height() < constants.MINIMAL_SCREEN_SIZE[1])):
        # noinspection PyTypeChecker
        QtWidgets.QMessageBox.warning(
            None, 'Warning',
            'Actual screen size below minimal screen size {}.'.format(
                constants.MINIMAL_SCREEN_SIZE))
        return

    # if no bounds are set, set reasonable bounds
    if tools.get_option(constants.Option.MAINWINDOW_BOUNDS) is None:
        tools.set_option(
            constants.Option.MAINWINDOW_BOUNDS,
            desktop.availableGeometry().adjusted(50, 50, -100, -100))
        tools.set_option(constants.Option.MAINWINDOW_MAXIMIZED, True)
        logger.info(
            'No previous bounds of the main window stored, start maximized')

    # load global stylesheet to app
    # open is 'r' by default
    with open(constants.GLOBAL_STYLESHEET_FILE, encoding='utf-8') as file:
        style_sheet = file.read()
    app.setStyleSheet(style_sheet)

    # set icon
    app.setWindowIcon(tools.load_ui_icon('window.icon.ico'))

    # setup sound system
    audio.load_soundtrack_playlist()
    audio.setup_soundtrack_player()

    # start audio player if wished
    if not tools.get_option(constants.Option.SOUNDTRACK_MUTE):
        audio.soundtrack_player.play()

    # create client object and switch to start screen
    client = Client()
    client.switch_to_start_screen()

    # start Qt app execution and immediately try to connect to local server
    logger.info('client initialized (pid=%d), start Qt app execution',
                os.getpid())

    # noinspection PyCallByClass
    QtCore.QTimer.singleShot(0, local_network_connect)
    app.exec_()
Example #15
0
    def _add_help_and_exit_buttons(self, client):
        # spacer
        spacer = QtWidgets.QWidget()
        spacer.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
        self._toolbar.addWidget(spacer)

        self._toolbar.addSeparator()

        clock = qt.ClockLabel()
        self._toolbar.addWidget(clock)

        # help and exit action
        a = QtWidgets.QAction(tools.load_ui_icon('icon.help.png'), 'Show help', self)
        a.triggered.connect(client.show_help_browser)  # TODO with partial make reference to specific page
        self._toolbar.addAction(a)

        a = QtWidgets.QAction(tools.load_ui_icon('icon.back_to_startscreen.png'), 'Exit to main menu', self)
        a.triggered.connect(client.switch_to_start_screen)
        # TODO ask if something is changed we should save.. (you might loose progress)
        self._toolbar.addAction(a)
    def __init__(self, *args, **kwargs):
        """
        Sets up all the input elements of the create new scenario dialog.
        """
        super().__init__(*args, **kwargs)

        self.parameters = {}
        widget_layout = QtWidgets.QVBoxLayout(self)

        # title box
        box = QtWidgets.QGroupBox('Title')
        layout = QtWidgets.QVBoxLayout(box)
        edit = QtWidgets.QLineEdit()
        edit.setFixedWidth(300)
        edit.setPlaceholderText('Unnamed')
        self.parameters[constants.ScenarioProperty.TITLE] = edit
        layout.addWidget(edit)
        widget_layout.addWidget(box)

        # map size
        box = QtWidgets.QGroupBox('Map size')
        layout = QtWidgets.QHBoxLayout(box)

        layout.addWidget(QtWidgets.QLabel('Width'))
        edit = QtWidgets.QLineEdit()
        edit.setFixedWidth(50)
        edit.setValidator(QtGui.QIntValidator(1, 1000))
        edit.setPlaceholderText('100')
        self.parameters[constants.ScenarioProperty.MAP_COLUMNS] = edit
        layout.addWidget(edit)

        layout.addWidget(QtWidgets.QLabel('Height'))
        edit = QtWidgets.QLineEdit()
        edit.setFixedWidth(50)
        edit.setValidator(QtGui.QIntValidator(1, 1000))
        edit.setPlaceholderText('60')
        self.parameters[constants.ScenarioProperty.MAP_ROWS] = edit
        layout.addWidget(edit)
        layout.addStretch()

        widget_layout.addWidget(box)

        # vertical stretch
        widget_layout.addStretch()

        # add confirmation button
        layout = QtWidgets.QHBoxLayout()
        toolbar = QtWidgets.QToolBar()
        a = qt.create_action(tools.load_ui_icon('icon.confirm.png'),
                             'Create new scenario', toolbar, self.on_ok)
        toolbar.addAction(a)
        layout.addStretch()
        layout.addWidget(toolbar)
        widget_layout.addLayout(layout)
Example #17
0
    def __init__(self):
        super().__init__()

        logger.debug('__init__')

        buttons = QtWidgets.QToolBar()
        buttons.setFixedWidth(constants.PANEL_VIEW_WIDTH)
        buttons.setFixedHeight(BUTTON_WIDTH)

        button = QtWidgets.QPushButton("", self)
        button.setIcon(tools.load_ui_icon('icon.transport.button.png'))
        button.setFixedSize(BUTTON_WIDTH, BUTTON_WIDTH)
        button.clicked.connect(self._transport_clicked)

        buttons.addWidget(button)

        button = QtWidgets.QPushButton("", self)
        button.setIcon(tools.load_ui_icon('icon.industry.button.png'))
        button.setFixedSize(BUTTON_WIDTH, BUTTON_WIDTH)
        button.clicked.connect(self._industry_clicked)

        buttons.addWidget(button)

        button = QtWidgets.QPushButton("", self)
        button.setIcon(tools.load_ui_icon('icon.market.button.png'))
        button.setFixedSize(BUTTON_WIDTH, BUTTON_WIDTH)
        button.clicked.connect(self._market_clicked)

        buttons.addWidget(button)

        button = QtWidgets.QPushButton("", self)
        button.setIcon(tools.load_ui_icon('icon.diplomacy.button.png'))
        button.setFixedSize(BUTTON_WIDTH, BUTTON_WIDTH)
        button.clicked.connect(self._diplomacy_clicked)

        buttons.addWidget(button)

        layout = QtWidgets.QHBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(buttons)
        layout.addStretch()
Example #18
0
    def __init__(self):
        super().__init__()

        logger.debug('__init__')

        buttons = QtWidgets.QToolBar()
        buttons.setFixedWidth(constants.PANEL_VIEW_WIDTH - 32)
        buttons.setFixedHeight(BUTTON_WIDTH)

        button = QtWidgets.QPushButton("", self)
        button.setIcon(tools.load_ui_icon('icon.unit.disband.png'))
        button.setFixedSize(BUTTON_WIDTH, BUTTON_WIDTH)
        button.clicked.connect(self._disband_clicked)

        buttons.addWidget(button)

        button = QtWidgets.QPushButton("", self)
        button.setIcon(tools.load_ui_icon('icon.unit.next.png'))
        button.setFixedSize(BUTTON_WIDTH, BUTTON_WIDTH)
        button.clicked.connect(self._next_unit_clicked)

        buttons.addWidget(button)

        button = QtWidgets.QPushButton("", self)
        button.setIcon(tools.load_ui_icon('icon.unit.done.png'))
        button.setFixedSize(BUTTON_WIDTH, BUTTON_WIDTH)
        button.clicked.connect(self._done_clicked)

        buttons.addWidget(button)

        button = QtWidgets.QPushButton("", self)
        button.setIcon(tools.load_ui_icon('icon.unit.sleep.png'))
        button.setFixedSize(BUTTON_WIDTH, BUTTON_WIDTH)
        button.clicked.connect(self._sleep_clicked)

        buttons.addWidget(button)

        layout = QtWidgets.QHBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(buttons)
        layout.addStretch()
Example #19
0
def start_client():
    """
    Creates the Qt application and shows the main window.
    """

    # create app
    app = QtWidgets.QApplication([])

    # test for desktop availability
    desktop = app.desktop()
    rect = desktop.screenGeometry()
    if ((rect.width() < constants.MINIMAL_SCREEN_SIZE[0])
            or (rect.height() < constants.MINIMAL_SCREEN_SIZE[1])):
        # noinspection PyTypeChecker
        QtWidgets.QMessageBox.warning(None, 'Warning',
                                      'Actual screen size below minimal screen size {}.'
                                      .format(constants.MINIMAL_SCREEN_SIZE))
        return

    # if no bounds are set, set reasonable bounds
    if tools.get_option(constants.Option.MAINWINDOW_BOUNDS) is None:
        tools.set_option(constants.Option.MAINWINDOW_BOUNDS,
                         desktop.availableGeometry().adjusted(50, 50, -100, -100))
        tools.set_option(constants.Option.MAINWINDOW_MAXIMIZED, True)
        logger.info('No previous bounds of the main window stored, start maximized')

    # load global stylesheet to app
    # open is 'r' by default
    with open(constants.GLOBAL_STYLESHEET_FILE, encoding='utf-8') as file:
        style_sheet = file.read()
    app.setStyleSheet(style_sheet)

    # set icon
    app.setWindowIcon(tools.load_ui_icon('window.icon.ico'))

    # setup sound system
    audio.load_soundtrack_playlist()
    audio.setup_soundtrack_player()

    # start audio player if wished
    if not tools.get_option(constants.Option.SOUNDTRACK_MUTE):
        audio.soundtrack_player.play()
    pass

    # create client object and switch to start screen
    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')
    # noinspection PyCallByClass
    QtCore.QTimer.singleShot(0, local_network_connect)
    app.exec_()
Example #20
0
    def __init__(self, *args, **kwargs):
        """
        Sets up all the input elements of the create new scenario dialog.
        """
        super().__init__(*args, **kwargs)

        self.parameters = {}
        widget_layout = QtWidgets.QVBoxLayout(self)

        # title box
        box = QtWidgets.QGroupBox('Title')
        layout = QtWidgets.QVBoxLayout(box)
        edit = QtWidgets.QLineEdit()
        edit.setFixedWidth(300)
        edit.setPlaceholderText('Unnamed')
        self.parameters[constants.ScenarioProperty.TITLE] = edit
        layout.addWidget(edit)
        widget_layout.addWidget(box)

        # map size
        box = QtWidgets.QGroupBox('Map size')
        layout = QtWidgets.QHBoxLayout(box)

        layout.addWidget(QtWidgets.QLabel('Width'))
        edit = QtWidgets.QLineEdit()
        edit.setFixedWidth(50)
        edit.setValidator(QtGui.QIntValidator(1, 1000))
        edit.setPlaceholderText('100')
        self.parameters[constants.ScenarioProperty.MAP_COLUMNS] = edit
        layout.addWidget(edit)

        layout.addWidget(QtWidgets.QLabel('Height'))
        edit = QtWidgets.QLineEdit()
        edit.setFixedWidth(50)
        edit.setValidator(QtGui.QIntValidator(1, 1000))
        edit.setPlaceholderText('60')
        self.parameters[constants.ScenarioProperty.MAP_ROWS] = edit
        layout.addWidget(edit)
        layout.addStretch()

        widget_layout.addWidget(box)

        # vertical stretch
        widget_layout.addStretch()

        # add confirmation button
        layout = QtWidgets.QHBoxLayout()
        toolbar = QtWidgets.QToolBar()
        a = qt.create_action(tools.load_ui_icon('icon.confirm.png'), 'Create new scenario', toolbar, self.on_ok)
        toolbar.addAction(a)
        layout.addStretch()
        layout.addWidget(toolbar)
        widget_layout.addLayout(layout)
Example #21
0
    def __init__(self, initial_province=None):
        super().__init__()

        widget_layout = QtWidgets.QVBoxLayout(self)

        # toolbar
        toolbar = QtWidgets.QToolBar()
        a = qt.create_action(tools.load_ui_icon('icon.add.png'), 'Add province', toolbar, self.add_province)
        toolbar.addAction(a)
        a = qt.create_action(tools.load_ui_icon('icon.delete.png'), 'Remove province', toolbar, self.remove_province)
        toolbar.addAction(a)
        widget_layout.addLayout(qt.wrap_in_boxlayout(toolbar))

        # provinces selection combo box
        label = QtWidgets.QLabel('Choose')
        self.provinces_combobox = QtWidgets.QComboBox()
        self.provinces_combobox.setFixedWidth(200)
        self.provinces_combobox.currentIndexChanged.connect(self.province_combobox_index_changed)
        widget_layout.addWidget(qt.wrap_in_groupbox(qt.wrap_in_boxlayout((label, self.provinces_combobox)), 'provinces'))

        # province info panel
        layout = QtWidgets.QVBoxLayout()

        # nation
        self.nation_label = QtWidgets.QLabel('Nation')
        layout.addWidget(self.nation_label)

        widget_layout.addWidget(qt.wrap_in_groupbox(layout, 'Info'))

        # vertical stretch
        widget_layout.addStretch()

        # reset content
        self.reset_content()

        # if province is given, select it
        if initial_province:
            index = utils.index_of_element(self.provinces, initial_province)
            self.provinces_combobox.setCurrentIndex(index)
    def __init__(self, turn_manager: TurnManager):
        super().__init__()

        logger.debug('__init__')

        button = QtWidgets.QPushButton( "", self)
        button.setIcon(tools.load_ui_icon('icon.end_turn.png'))
        button.setIconSize(QtCore.QSize(24, 24))
        button.clicked.connect(self._turn_end_clicked)

        layout = QtWidgets.QVBoxLayout(self)
        layout.addWidget(button)

        self._turn_manager = turn_manager
Example #23
0
    def __init__(self, client):
        super().__init__()

        self.toolbar = QtWidgets.QToolBar()
        action_help = QtWidgets.QAction(tools.load_ui_icon('icon.help.png'),
                                        'Show help', self)
        action_help.triggered.connect(
            client.show_help_browser
        )  # TODO with partial make reference to specific page
        self.toolbar.addAction(action_help)

        action_quit = QtWidgets.QAction(
            tools.load_ui_icon('icon.back_to_startscreen.png'),
            'Exit to main menu', self)
        action_quit.triggered.connect(client.switch_to_start_screen)
        self.toolbar.addAction(action_quit)

        # main map
        self.main_map = MainMap()

        # mini map
        self.mini_map = MiniMap()

        # info box
        self.info_box = InfoBox()

        # layout
        layout = QtWidgets.QGridLayout(self)
        layout.addWidget(self.toolbar, 0, 0)
        layout.addWidget(self.mini_map, 1, 0)
        layout.addWidget(self.info_box, 2, 0)
        layout.addWidget(self.main_map, 0, 1, 3, 1)
        layout.setRowStretch(
            2, 1)  # the info box will take all vertical space left
        layout.setColumnStretch(
            1, 1)  # the main map will take all horizontal space left
Example #24
0
    def __init__(self, client):
        """
        Create and setup all the elements.
        """
        self.scenario = EditorScenario()

        super().__init__(client, self.scenario,
                         EditorMainMap(self.scenario, None))

        # new, load, save scenario actions
        a = qt.create_action(tools.load_ui_icon('icon.scenario.new.png'),
                             'Create new scenario', self,
                             self.new_scenario_dialog)
        self._toolbar.addAction(a)
        a = qt.create_action(tools.load_ui_icon('icon.scenario.load.png'),
                             'Load scenario', self, self.load_scenario_dialog)
        self._toolbar.addAction(a)
        a = qt.create_action(tools.load_ui_icon('icon.scenario.save.png'),
                             'Save scenario', self, self.save_scenario_dialog)
        self._toolbar.addAction(a)

        # main map
        self.main_map.change_terrain.connect(self.map_change_terrain)
        self.main_map.change_terrain_resource.connect(
            self.map_change_terrain_resource)
        self.main_map.province_info.connect(self.provinces_dialog)
        self.main_map.nation_info.connect(self.nations_dialog)

        # edit properties (general, nations, provinces) actions
        a = qt.create_action(tools.load_ui_icon('icon.editor.general.png'),
                             'Edit general properties', self,
                             self.general_properties_dialog)
        self._toolbar.addAction(a)
        a = qt.create_action(tools.load_ui_icon('icon.editor.nations.png'),
                             'Edit nations', self, self.nations_dialog)
        self._toolbar.addAction(a)
        a = qt.create_action(tools.load_ui_icon('icon.editor.provinces.png'),
                             'Edit provinces', self, self.provinces_dialog)
        self._toolbar.addAction(a)

        self._layout.addWidget(self._toolbar, 0, 0, 1, 2)
        self._layout.addWidget(self._mini_map, 1, 0)
        self._layout.addWidget(self.main_map, 1, 1, 2, 1)
        self._layout.addWidget(self._info_panel, 2, 0)
        self._layout.setRowStretch(
            2, 1)  # the info box will take all vertical space left
        self._layout.setColumnStretch(
            1, 1)  # the main map will take all horizontal space left

        self._add_help_and_exit_buttons(client)
Example #25
0
    def __init__(self, *args, **kwargs):
        """
        All the necessary initializations. Is shown at the end.
        """
        super().__init__(*args, **kwargs)
        # set geometry
        self.setGeometry(tools.get_option(constants.Option.MAINWINDOW_BOUNDS))
        # set icon
        self.setWindowIcon(tools.load_ui_icon('window.icon.ico'))
        # set title
        self.setWindowTitle('Imperialism Remake')

        # just a layout but nothing else
        self.layout = QtWidgets.QHBoxLayout(self)
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.content = None

        # show in full screen, maximized or normal
        if tools.get_option(constants.Option.MAINWINDOW_FULLSCREEN):
            self.setWindowFlags(self.windowFlags()
                                | QtCore.Qt.FramelessWindowHint)
            self.showFullScreen()
        elif tools.get_option(constants.Option.MAINWINDOW_MAXIMIZED):
            self.showMaximized()
        else:
            self.show()

        # loading animation
        # TODO animation right and start, stop in client
        self.animation = QtGui.QMovie(
            constants.extend(constants.GRAPHICS_UI_FOLDER, 'loading.gif'))
        # self.animation.start()
        self.loading_label = QtWidgets.QLabel(
            self, flags=QtCore.Qt.FramelessWindowHint | QtCore.Qt.Window)
        self.loading_label.setAttribute(QtCore.Qt.WA_TranslucentBackground)
        self.loading_label.setMovie(self.animation)
Example #26
0
    def received_preview(self, client, channel, action, message):
        """
        Populates the widget after the network reply comes from the server with the preview.
        """

        # immediately unsubscribe, we need it only once
        local_network_client.disconnect_from_channel(constants.C.LOBBY,
                                                     self.received_preview)

        # unpack message
        nations = [(message['nations'][key][constants.NationProperty.NAME],
                    key) for key in message['nations']]
        nations = sorted(nations)  # by first element, which is the name
        nation_names, self.nation_ids = zip(*nations)

        # fill the widget with useful stuff
        layout = QtWidgets.QGridLayout(self)

        # selection list for nations
        self.nations_list = QtWidgets.QListWidget()
        # self.nations_list.setFixedWidth(200)
        self.nations_list.setSelectionMode(
            QtWidgets.QAbstractItemView.SingleSelection)
        self.nations_list.itemSelectionChanged.connect(
            self.nations_list_selection_changed)
        self.nations_list.addItems(nation_names)
        self.nations_list.setHorizontalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        # 10px extra
        self.nations_list.setFixedWidth(
            self.nations_list.sizeHintForColumn(0) +
            2 * self.nations_list.frameWidth() + 17 + 10)
        # TODO use app.style().pixelMetric(QtWidgets.QStyle.PM_ScrollBarExtent)
        layout.addWidget(qt.wrap_in_groupbox(self.nations_list, 'Nations'), 0,
                         0)

        # map view (no scroll bars)
        self.map_scene = QtWidgets.QGraphicsScene()
        self.map_view = qt.FitSceneInViewGraphicsView(self.map_scene)
        self.map_view.setHorizontalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        self.map_view.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        #       self.map_view.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding)
        #       self.map_view.setFixedSize(100, 100)
        layout.addWidget(qt.wrap_in_groupbox(self.map_view, 'Map'), 0, 1)

        # scenario description
        self.description = QtWidgets.QPlainTextEdit()
        self.description.setHorizontalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        self.description.setVerticalScrollBarPolicy(
            QtCore.Qt.ScrollBarAsNeeded)
        self.description.setReadOnly(True)
        self.description.setPlainText(
            message[constants.ScenarioProperty.DESCRIPTION])
        height = self.description.fontMetrics().lineSpacing(
        ) * 4  # 4 lines high
        self.description.setFixedHeight(height)
        layout.addWidget(qt.wrap_in_groupbox(self.description, 'Description'),
                         1, 0, 1, 2)  # goes over two columns

        # nation description
        self.nation_info = QtWidgets.QPlainTextEdit()
        self.nation_info.setHorizontalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        self.nation_info.setVerticalScrollBarPolicy(
            QtCore.Qt.ScrollBarAsNeeded)
        self.nation_info.setReadOnly(True)
        height = self.nation_info.fontMetrics().lineSpacing(
        ) * 6  # 6 lines high
        self.nation_info.setFixedHeight(height)
        layout.addWidget(qt.wrap_in_groupbox(self.nation_info, 'Nation Info'),
                         2, 0, 1, 2)

        # stretching of the elements
        layout.setRowStretch(
            0, 1)  # nation list and map get all the available height
        layout.setColumnStretch(1, 1)  # map gets all the available width

        # add the start button
        toolbar = QtWidgets.QToolBar()
        toolbar.addAction(
            qt.create_action(tools.load_ui_icon('icon.confirm.png'),
                             'Start selected scenario',
                             toolbar,
                             trigger_connection=self.start_scenario_clicked))
        layout.addWidget(toolbar, 3, 0, 1, 2, alignment=QtCore.Qt.AlignRight)

        # draw the map
        columns = message[constants.ScenarioProperty.MAP_COLUMNS]
        rows = message[constants.ScenarioProperty.MAP_ROWS]
        self.map_scene.setSceneRect(0, 0, columns, rows)

        # fill the ground layer with a neutral color
        item = self.map_scene.addRect(0, 0, columns, rows)
        item.setBrush(QtCore.Qt.lightGray)
        item.setPen(qt.TRANSPARENT_PEN)
        item.setZValue(0)

        # for all nations
        for nation_id, nation in message['nations'].items():

            # get nation color
            color_string = nation[constants.NationProperty.COLOR]
            color = QtGui.QColor()
            color.setNamedColor(color_string)

            # get nation name
            nation_name = nation[constants.NationProperty.NAME]

            # get nation outline
            path = QtGui.QPainterPath()
            # TODO traversing everything is quite slow go only once and add to paths
            for column in range(0, columns):
                for row in range(0, rows):
                    if nation_id == message['map'][column + row * columns]:
                        path.addRect(column, row, 1, 1)
            path = path.simplified()

            item = graphics.MiniMapNationItem(path)
            item.signaller.clicked.connect(
                partial(self.map_selected_nation,
                        utils.index_of_element(nation_names, nation_name)))
            #           item.signaller.entered.connect(partial(self.change_map_name, nation_name))
            #           item.signaller.left.connect(partial(self.change_map_name, ''))
            brush = QtGui.QBrush(color)
            item.setBrush(brush)

            item.setToolTip(nation_name)

            pen = QtGui.QPen()
            pen.setWidth(2)
            pen.setCosmetic(True)
            item.setPen(pen)

            self.map_scene.addItem(item)
#           item = self.map_scene.addPath(path, brush=brush) # will use the default pen for outline

        self.preview = message
Example #27
0
    def _layout_widget_preferences_network(self):
        """
        Create network options widget.
        """
        tab = QtWidgets.QWidget()
        tab_layout = QtWidgets.QVBoxLayout(tab)

        # client
        layout = QtWidgets.QVBoxLayout()
        if local_network_client.is_connected():
            peer_address, peer_port = local_network_client.peer_address()
            status = 'Connected to {}:{}'.format(peer_address.toString(),
                                                 peer_port)
        else:
            status = 'Disconnected'
        layout.addWidget(QtWidgets.QLabel(status))
        tab_layout.addWidget(qt.wrap_in_groupbox(layout, 'Client'))
        # alias name edit box
        label = QtWidgets.QLabel('Alias')
        edit = QtWidgets.QLineEdit()
        edit.setFixedWidth(300)
        self._register_line_edit(edit, constants.Option.LOCALCLIENT_NAME)
        layout.addLayout(qt.wrap_in_boxlayout((label, edit)))

        # local server group box
        layout = QtWidgets.QVBoxLayout()
        import ipgetter
        local_ip = ipgetter.myip()
        layout.addWidget(
            QtWidgets.QLabel('Local public IP address: {}'.format(local_ip)))
        # accepts incoming connections checkbox
        checkbox = QtWidgets.QCheckBox('Accepts incoming connections')
        self._register_check_box(checkbox, constants.Option.LOCALSERVER_OPEN)
        layout.addWidget(checkbox)
        # alias name edit box
        label = QtWidgets.QLabel('Alias')
        edit = QtWidgets.QLineEdit()
        edit.setFixedWidth(300)
        self._register_line_edit(edit, constants.Option.LOCALSERVER_NAME)
        layout.addLayout(qt.wrap_in_boxlayout((label, edit)))
        # actions toolbar
        toolbar = QtWidgets.QToolBar()
        toolbar.setIconSize(QtCore.QSize(24, 24))
        # show local server monitor
        toolbar.addAction(
            qt.create_action(
                tools.load_ui_icon('icon.preferences.network.png'),
                'Show local server monitor', toolbar))
        layout.addLayout(qt.wrap_in_boxlayout(toolbar))
        tab_layout.addWidget(qt.wrap_in_groupbox(layout, 'Local Server'))

        # remote server group box
        layout = QtWidgets.QVBoxLayout()
        # remote server address
        label = QtWidgets.QLabel('Remote IP address')
        edit = QtWidgets.QLineEdit()
        edit.setFixedWidth(300)
        layout.addLayout(qt.wrap_in_boxlayout((label, edit)))
        # actions toolbar
        toolbar = QtWidgets.QToolBar()
        toolbar.setIconSize(QtCore.QSize(24, 24))
        # connect to remote server
        a = qt.create_action(
            tools.load_ui_icon('icon.preferences.network.png'),
            'Connect/Disconnect to remote server',
            toolbar,
            checkable=True)
        toolbar.addAction(a)
        layout.addLayout(qt.wrap_in_boxlayout(toolbar))
        tab_layout.addWidget(qt.wrap_in_groupbox(layout, 'Remote Server'))

        # vertical stretch
        tab_layout.addStretch()

        # add tab
        self.tab_network = tab
        self.stacked_layout.addWidget(tab)
    def _layout_widget_preferences_network(self):
        """
        Create network options widget.
        """
        tab = QtWidgets.QWidget()
        tab_layout = QtWidgets.QVBoxLayout(tab)

        # client
        layout = QtWidgets.QVBoxLayout()
        if local_network_client.is_connected():
            peer_address, peer_port = local_network_client.peer_address()
            status = 'Connected to {}:{}'.format(peer_address.toString(), peer_port)
        else:
            status = 'Disconnected'
        layout.addWidget(QtWidgets.QLabel(status))
        tab_layout.addWidget(qt.wrap_in_groupbox(layout, 'Client'))
        # alias name edit box
        label = QtWidgets.QLabel('Alias')
        edit = QtWidgets.QLineEdit()
        edit.setFixedWidth(300)
        self._register_line_edit(edit, constants.Option.LOCALCLIENT_NAME)
        layout.addLayout(qt.wrap_in_boxlayout((label, edit)))

        # local server group box
        layout = QtWidgets.QVBoxLayout()
        import ipgetter
        local_ip = ipgetter.myip()
        layout.addWidget(QtWidgets.QLabel('Local public IP address: {}'.format(local_ip)))
        # accepts incoming connections checkbox
        checkbox = QtWidgets.QCheckBox('Accepts incoming connections')
        self._register_check_box(checkbox, constants.Option.LOCALSERVER_OPEN)
        layout.addWidget(checkbox)
        # alias name edit box
        label = QtWidgets.QLabel('Alias')
        edit = QtWidgets.QLineEdit()
        edit.setFixedWidth(300)
        self._register_line_edit(edit, constants.Option.LOCALSERVER_NAME)
        layout.addLayout(qt.wrap_in_boxlayout((label, edit)))
        # actions toolbar
        toolbar = QtWidgets.QToolBar()
        toolbar.setIconSize(QtCore.QSize(24, 24))
        # show local server monitor
        toolbar.addAction(
            qt.create_action(tools.load_ui_icon('icon.preferences.network.png'), 'Show local server monitor', toolbar))
        layout.addLayout(qt.wrap_in_boxlayout(toolbar))
        tab_layout.addWidget(qt.wrap_in_groupbox(layout, 'Local Server'))

        # remote server group box
        layout = QtWidgets.QVBoxLayout()
        # remote server address
        label = QtWidgets.QLabel('Remote IP address')
        edit = QtWidgets.QLineEdit()
        edit.setFixedWidth(300)
        layout.addLayout(qt.wrap_in_boxlayout((label, edit)))
        # actions toolbar
        toolbar = QtWidgets.QToolBar()
        toolbar.setIconSize(QtCore.QSize(24, 24))
        # connect to remote server
        a = qt.create_action(tools.load_ui_icon('icon.preferences.network.png'), 'Connect/Disconnect to remote server',
                             toolbar, checkable=True)
        toolbar.addAction(a)
        layout.addLayout(qt.wrap_in_boxlayout(toolbar))
        tab_layout.addWidget(qt.wrap_in_groupbox(layout, 'Remote Server'))

        # vertical stretch
        tab_layout.addStretch()

        # add tab
        self.tab_network = tab
        self.stacked_layout.addWidget(tab)
    app = QtWidgets.QApplication([])

    # test for desktop availability
    desktop = app.desktop()
    rect = desktop.screenGeometry()
    print('desktop geometry', rect, 'minimal required screen size',
          constants.MINIMAL_SCREEN_SIZE)

    # load global stylesheet to app
    with open(constants.GLOBAL_STYLESHEET_FILE, encoding='utf-8') as file:
        style_sheet = file.read()
    app.setStyleSheet(style_sheet)

    # set icon
    app.setWindowIcon(tools.load_ui_icon('window.icon.ico'))

    # main window
    main_window = QtWidgets.QWidget()
    # set geometry
    main_window.setGeometry(
        tools.get_option(constants.Option.MAINWINDOW_BOUNDS))
    # set title
    main_window.setWindowTitle('Imperialism Remake')
    # show in full screen, maximized or normal
    if tools.get_option(constants.Option.MAINWINDOW_FULLSCREEN):
        main_window.setWindowFlags(main_window.windowFlags()
                                   | QtCore.Qt.FramelessWindowHint)
        main_window.showFullScreen()
    elif tools.get_option(constants.Option.MAINWINDOW_MAXIMIZED):
        main_window.showMaximized()
Example #30
0
    def __init__(self, *args, **kwargs):
        """
        Create and add all tab
        """
        super().__init__(*args, **kwargs)

        toolbar = QtWidgets.QToolBar()
        toolbar.setIconSize(QtCore.QSize(32, 32))
        action_group = QtWidgets.QActionGroup(toolbar)

        # general preferences
        action_general = qt.create_action(
            tools.load_ui_icon('icon.preferences.general.png'),
            'Show general preferences',
            action_group,
            toggle_connection=self._toggled_action_preferences_general,
            checkable=True)
        toolbar.addAction(action_general)

        # network preferences
        a = qt.create_action(
            tools.load_ui_icon('icon.preferences.network.png'),
            'Show network preferences',
            action_group,
            toggle_connection=self._toggled_action_preferences_network,
            checkable=True)
        toolbar.addAction(a)

        # graphics preferences
        a = qt.create_action(
            tools.load_ui_icon('icon.preferences.graphics.png'),
            'Show graphics preferences',
            action_group,
            toggle_connection=self._toggled_action_preferences_graphics,
            checkable=True)
        toolbar.addAction(a)

        # music preferences
        a = qt.create_action(
            tools.load_ui_icon('icon.preferences.music.png'),
            'Show music preferences',
            action_group,
            toggle_connection=self._toggled_action_preferences_music,
            checkable=True)
        toolbar.addAction(a)

        # spacer
        spacer = QtWidgets.QWidget()
        spacer.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                             QtWidgets.QSizePolicy.Expanding)
        toolbar.addWidget(spacer)

        # reset preferences
        a = QtWidgets.QAction(tools.load_ui_icon('icon.preferences.reset.png'),
                              'Reset preferences', self)
        a.triggered.connect(self.reset_preferences)
        toolbar.addAction(a)

        self.stacked_layout = QtWidgets.QStackedLayout()

        layout = QtWidgets.QVBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(toolbar)
        layout.addLayout(self.stacked_layout)

        # empty lists
        self._check_boxes = []
        self._line_edits = []
        self._sliders = []

        # add tabs
        self._layout_widget_preferences_general()
        self._layout_widget_preferences_graphics()
        self._layout_widget_preferences_music()
        self._layout_widget_preferences_network()

        # initially show general preferences
        action_general.setChecked(True)
    def __init__(self, client, server_base_scenario, selected_nation):
        logger.debug('__init__ server_base_scenario:%s, selected_nation:%s',
                     server_base_scenario, selected_nation)

        self.scenario = GameScenario()

        self._main_map = MainMap(self.scenario, selected_nation)

        super().__init__(client, self.scenario, self._main_map)
        self._layout.addWidget(self._toolbar, 0, 0, 1, 2)
        self._layout.addWidget(self._mini_map, 1, 0)

        self.scenario.init(server_base_scenario)

        self._selected_object = GameSelectedObject(self._info_panel)

        self._default_cursor = self.main_map.viewport().cursor()

        self._main_map.mouse_press_event.connect(
            self._main_map_mouse_press_event)
        self._main_map.mouse_move_event.connect(
            self._main_map_mouse_move_event)

        self._turn_manager = TurnManager(self.scenario, selected_nation)
        self._turn_manager.event_turn_completed.connect(
            self._event_turn_completed)

        turn_end_widget = TurnEndWidget(self._turn_manager)
        order_buttons_widget = OrderButtonsWidget()

        self._layout.addWidget(order_buttons_widget, 2, 0)
        self._layout.addWidget(self._info_panel, 3, 0)
        self._layout.addWidget(turn_end_widget, 4, 0)
        self._layout.addWidget(self.main_map, 1, 1, 3, 1)
        self._layout.setRowStretch(
            3, 1)  # the info box will take all vertical space left
        self._layout.setColumnStretch(
            1, 1)  # the main map will take all horizontal space left

        self._workforce_widgets = {}

        # !!! TODO this is just to test, remove me a little bit later!!!
        self._create_workforce_widget(13, 29, WorkforceType.ENGINEER)
        self._create_workforce_widget(11, 27, WorkforceType.PROSPECTOR)
        self._create_workforce_widget(12, 30, WorkforceType.FARMER)
        self._create_workforce_widget(15, 29, WorkforceType.FORESTER)
        self._create_workforce_widget(14, 29, WorkforceType.MINER)
        self._create_workforce_widget(13, 29, WorkforceType.RANCHER)
        # !!! TODO remove above

        a = qt.create_action(tools.load_ui_icon('icon.scenario.load.png'),
                             'Load scenario', self, self.load_scenario_dialog)
        self._toolbar.addAction(a)
        a = qt.create_action(tools.load_ui_icon('icon.scenario.save.png'),
                             'Save scenario', self, self.save_scenario_dialog)
        self._toolbar.addAction(a)

        self._add_help_and_exit_buttons(client)

        self._add_workforces()

        self._info_panel.refresh_nation_asset_info()

        logger.debug('__init__ finished')
Example #32
0
    def __init__(self, client):
        """
        Create and setup all the elements.
        """
        super().__init__()

        # store the client
        self.client = client

        # toolbar on top of the window
        self.toolbar = QtWidgets.QToolBar()
        self.toolbar.setIconSize(QtCore.QSize(32, 32))

        # new, load, save scenario actions
        a = qt.create_action(tools.load_ui_icon('icon.scenario.new.png'), 'Create new scenario', self,
            self.new_scenario_dialog)
        self.toolbar.addAction(a)
        a = qt.create_action(tools.load_ui_icon('icon.scenario.load.png'), 'Load scenario', self,
            self.load_scenario_dialog)
        self.toolbar.addAction(a)
        a = qt.create_action(tools.load_ui_icon('icon.scenario.save.png'), 'Save scenario', self,
            self.save_scenario_dialog)
        self.toolbar.addAction(a)
        self.toolbar.addSeparator()

        # edit properties (general, nations, provinces) actions
        a = qt.create_action(tools.load_ui_icon('icon.editor.general.png'), 'Edit general properties', self,
            self.general_properties_dialog)
        self.toolbar.addAction(a)
        a = qt.create_action(tools.load_ui_icon('icon.editor.nations.png'), 'Edit nations', self, self.nations_dialog)
        self.toolbar.addAction(a)
        a = qt.create_action(tools.load_ui_icon('icon.editor.provinces.png'), 'Edit provinces', self,
            self.provinces_dialog)
        self.toolbar.addAction(a)

        # spacer
        spacer = QtWidgets.QWidget()
        spacer.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
        self.toolbar.addWidget(spacer)

        clock = qt.ClockLabel()
        self.toolbar.addWidget(clock)

        # help and exit action
        a = QtWidgets.QAction(tools.load_ui_icon('icon.help.png'), 'Show help', self)
        a.triggered.connect(client.show_help_browser)  # TODO with partial make reference to specific page
        self.toolbar.addAction(a)
        a = QtWidgets.QAction(tools.load_ui_icon('icon.back_to_startscreen.png'), 'Exit to main menu', self)
        a.triggered.connect(client.switch_to_start_screen)
        # TODO ask if something is changed we should save.. (you might loose progress)
        self.toolbar.addAction(a)

        # info box widget
        self.info_panel = InfoPanel()

        # main map
        self.main_map = MainMap()
        self.main_map.focus_changed.connect(self.info_panel.update_tile_info)
        self.main_map.change_terrain.connect(self.map_change_terrain)
        self.main_map.province_info.connect(self.provinces_dialog)
        self.main_map.nation_info.connect(self.nations_dialog)

        # mini map
        self.mini_map = MiniMap()
        self.mini_map.roi_changed.connect(self.main_map.set_center_position)

        # connect to editor_scenario
        editor_scenario.changed.connect(self.scenario_changed)

        # layout of widgets and toolbar
        layout = QtWidgets.QGridLayout(self)
        layout.addWidget(self.toolbar, 0, 0, 1, 2)
        layout.addWidget(self.mini_map, 1, 0)
        layout.addWidget(self.info_panel, 2, 0)
        layout.addWidget(self.main_map, 1, 1, 2, 1)
        layout.setRowStretch(2, 1)  # the info box will take all vertical space left
        layout.setColumnStretch(1, 1)  # the main map will take all horizontal space left
    tools.load_options(options_file)

    app = QtWidgets.QApplication([])

    # test for desktop availability
    desktop = app.desktop()
    rect = desktop.screenGeometry()
    print('desktop geometry', rect, 'minimal required screen size', constants.MINIMAL_SCREEN_SIZE)

    # load global stylesheet to app
    with open(constants.GLOBAL_STYLESHEET_FILE, encoding='utf-8') as file:
        style_sheet = file.read()
    app.setStyleSheet(style_sheet)

    # set icon
    app.setWindowIcon(tools.load_ui_icon('window.icon.ico'))

    # main window
    main_window = QtWidgets.QWidget()
    # set geometry
    main_window.setGeometry(tools.get_option(constants.Option.MAINWINDOW_BOUNDS))
    # set title
    main_window.setWindowTitle('Imperialism Remake')
    # show in full screen, maximized or normal
    if tools.get_option(constants.Option.MAINWINDOW_FULLSCREEN):
        main_window.setWindowFlags(main_window.windowFlags() | QtCore.Qt.FramelessWindowHint)
        main_window.showFullScreen()
    elif tools.get_option(constants.Option.MAINWINDOW_MAXIMIZED):
        main_window.showMaximized()
    else:
        main_window.show()
Example #34
0
    def received_preview(self, client, channel, action, message):
        """
        Populates the widget after the network reply comes from the server with the preview.
        """

        # immediately unsubscribe, we need it only once
        local_network_client.disconnect_from_channel(constants.C.LOBBY, self.received_preview)

        # unpack message
        nations = [(message['nations'][key][constants.NationProperty.NAME], key) for key in message['nations']]
        nations = sorted(nations)  # by first element, which is the name
        nation_names, self.nation_ids = zip(*nations)

        # fill the widget with useful stuff
        layout = QtWidgets.QGridLayout(self)

        # selection list for nations
        self.nations_list = QtWidgets.QListWidget()
        # self.nations_list.setFixedWidth(200)
        self.nations_list.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
        self.nations_list.itemSelectionChanged.connect(self.nations_list_selection_changed)
        self.nations_list.addItems(nation_names)
        self.nations_list.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        # 10px extra
        self.nations_list.setFixedWidth(self.nations_list.sizeHintForColumn(0) +
                                        2 * self.nations_list.frameWidth() + 17 + 10)
        # TODO use app.style().pixelMetric(QtWidgets.QStyle.PM_ScrollBarExtent)
        layout.addWidget(qt.wrap_in_groupbox(self.nations_list, 'Nations'), 0, 0)

        # map view (no scroll bars)
        self.map_scene = QtWidgets.QGraphicsScene()
        self.map_view = qt.FitSceneInViewGraphicsView(self.map_scene)
        self.map_view.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.map_view.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
#       self.map_view.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding)
#       self.map_view.setFixedSize(100, 100)
        layout.addWidget(qt.wrap_in_groupbox(self.map_view, 'Map'), 0, 1)

        # scenario description
        self.description = QtWidgets.QPlainTextEdit()
        self.description.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.description.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
        self.description.setReadOnly(True)
        self.description.setPlainText(message[constants.ScenarioProperty.DESCRIPTION])
        height = self.description.fontMetrics().lineSpacing() * 4  # 4 lines high
        self.description.setFixedHeight(height)
        layout.addWidget(qt.wrap_in_groupbox(self.description, 'Description'), 1, 0, 1, 2)  # goes over two columns

        # nation description
        self.nation_info = QtWidgets.QPlainTextEdit()
        self.nation_info.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.nation_info.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
        self.nation_info.setReadOnly(True)
        height = self.nation_info.fontMetrics().lineSpacing() * 6  # 6 lines high
        self.nation_info.setFixedHeight(height)
        layout.addWidget(qt.wrap_in_groupbox(self.nation_info, 'Nation Info'), 2, 0, 1, 2)

        # stretching of the elements
        layout.setRowStretch(0, 1)  # nation list and map get all the available height
        layout.setColumnStretch(1, 1)  # map gets all the available width

        # add the start button
        toolbar = QtWidgets.QToolBar()
        toolbar.addAction(qt.create_action(tools.load_ui_icon('icon.confirm.png'), 'Start selected scenario', toolbar,
                                           trigger_connection=self.start_scenario_clicked))
        layout.addWidget(toolbar, 3, 0, 1, 2, alignment=QtCore.Qt.AlignRight)

        # draw the map
        columns = message[constants.ScenarioProperty.MAP_COLUMNS]
        rows = message[constants.ScenarioProperty.MAP_ROWS]
        self.map_scene.setSceneRect(0, 0, columns, rows)

        # fill the ground layer with a neutral color
        item = self.map_scene.addRect(0, 0, columns, rows)
        item.setBrush(QtCore.Qt.lightGray)
        item.setPen(qt.TRANSPARENT_PEN)
        item.setZValue(0)

        # for all nations
        for nation_id, nation in message['nations'].items():

            # get nation color
            color_string = nation[constants.NationProperty.COLOR]
            color = QtGui.QColor()
            color.setNamedColor(color_string)

            # get nation name
            nation_name = nation[constants.NationProperty.NAME]

            # get nation outline
            path = QtGui.QPainterPath()
            # TODO traversing everything is quite slow go only once and add to paths
            for column in range(0, columns):
                for row in range(0, rows):
                    if nation_id == message['map'][column + row * columns]:
                        path.addRect(column, row, 1, 1)
            path = path.simplified()

            item = graphics.MiniMapNationItem(path)
            item.signaller.clicked.connect(
                partial(self.map_selected_nation, utils.index_of_element(nation_names, nation_name)))
#           item.signaller.entered.connect(partial(self.change_map_name, nation_name))
#           item.signaller.left.connect(partial(self.change_map_name, ''))
            brush = QtGui.QBrush(color)
            item.setBrush(brush)

            item.setToolTip(nation_name)

            pen = QtGui.QPen()
            pen.setWidth(2)
            pen.setCosmetic(True)
            item.setPen(pen)

            self.map_scene.addItem(item)
#           item = self.map_scene.addPath(path, brush=brush) # will use the default pen for outline

        self.preview = message