예제 #1
0
    def __init__(self):
        """
            All the necessary initializations. Is shown at the end.
        """
        super().__init__()
        # set geometry
        self.setGeometry(t.get_option(c.O.MW_BOUNDS))
        # set icon
        self.setWindowIcon(t.load_ui_icon('icon.ico'))
        # set title
        self.setWindowTitle('Imperialism Remake')

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

        # show in full screen, maximized or normal
        if t.get_option(c.O.FULLSCREEN):
            self.setWindowFlags(self.windowFlags() | QtCore.Qt.FramelessWindowHint)
            self.showFullScreen()
        elif t.get_option(c.O.MW_MAXIMIZED):
            self.showMaximized()
        else:
            self.show()

        # loading animation
        # TODO animation right and start, stop in client
        self.animation = QtGui.QMovie(c.extend(c.Graphics_UI_Folder, 'loading.gif'))
        # self.animation.start()
        self.loading_label = QtGui.QLabel(self, f=QtCore.Qt.FramelessWindowHint | QtCore.Qt.Window)
        self.loading_label.setAttribute(QtCore.Qt.WA_TranslucentBackground)
        self.loading_label.setMovie(self.animation)
예제 #2
0
    def close_request(self, parent_widget):
        """
            User wants to close the dialog, check if an option has been changed. If an option has been changed, ask for
            okay from user and update the options.

            Also react on some updated options (others might only take affect after a restart of the application).
            We immediately : start/stop music (mute option)
        """
        # check if something was changed
        options_modified = any([box.isChecked() is not tools.get_option(option) for (box, option) in self._check_boxes])
        # TODO line edits and sliders


        if options_modified:
            answer = QtWidgets.QMessageBox.question(parent_widget, 'Preferences', 'Save modified preferences',
                QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.Yes)
            if answer == QtWidgets.QMessageBox.Yes:
                # all _check_boxes
                for (box, option) in self._check_boxes:
                    tools.set_option(option, box.isChecked())
                # start/stop audio player (depending on mute)
                if tools.get_option(constants.Opt.SOUNDTRACK_MUTE):
                    audio.soundtrack_player.stop()
                    pass
                else:
                    audio.soundtrack_player.play()
                    pass
        return True
예제 #3
0
    def close_request(self, parent_widget):
        """
            User wants to close the dialog, check if an option has been changed. If an option has been changed, ask for
            okay from user and update the options.

            Also react on some updated options (others might only take affect after a restart of the application).
            We immediately : start/stop music (mute option)
        """
        # check if something was changed
        options_modified = any([box.isChecked() is not t.get_option(option) for (box, option) in self.checkboxes])
        if options_modified:
            answer = QtGui.QMessageBox.question(parent_widget, 'Preferences', 'Save modified preferences',
                                                QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.Yes)
            if answer == QtGui.QMessageBox.Yes:
                # all checkboxes
                for (box, option) in self.checkboxes:
                    t.set_option(option, box.isChecked())
                # what else do we need to do?
                if t.get_option(c.O.BG_MUTE):
                    # t.player.stop()
                    pass
                else:
                    # t.player.start()
                    pass
        return True
예제 #4
0
 def register_checkbox(self, checkbox, option):
     """
         Takes an option identifier (str) where the option value must be True/False and sets a checkbox according
         to the current value. Stores the checkbox, option pair in a list.
     """
     checkbox.setChecked(t.get_option(option))
     self.checkboxes.append((checkbox, option))
예제 #5
0
def start_client():
    """
        Creates the Qt application and shows the main window.
    """

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

    # TODO multiple screen support?

    # 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 resonable bounds
    if tools.get_option(constants.Opt.MAINWINDOW_BOUNDS) is None:
        tools.set_option(constants.Opt.MAINWINDOW_BOUNDS, desktop.availableGeometry().adjusted(50, 50, -100, -100))
        tools.set_option(constants.Opt.MAINWINDOW_MAXIMIZED, True)
        tools.log_info('No previous bounds of the main window stored, start maximized')

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

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

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

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

    tools.log_info('client initialized, start Qt app execution')
    # TODO is this necessary to run as event?
    # QtCore.QTimer.singleShot(0, network_start)
    app.exec_()
예제 #6
0
    def __init__(self, client):
        super().__init__()

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

        layout = qt_graphics.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_graphics.RelativeLayoutConstraint().center_horizontal().center_vertical()
        layout.addWidget(view)

        subtitle = QtWidgets.QLabel('')
        subtitle.layout_constraint = qt_graphics.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 actions.keys() != image_map.keys():
            raise RuntimeError('Start screen hot map info file ({}) corrupt.'.format(image_map_file))

        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']))
            mapitem = MapItem(view, pixmap, label=subtitle, description=v['label'])
            mapitem.item.setZValue(3)
            offset = v['offset']
            mapitem.item.setOffset(QtCore.QPointF(offset[0], offset[1]))
            mapitem.item.signaller.clicked.connect(actions[k])

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

        version_label = QtWidgets.QLabel(
            '<font color=#ffffff>{}</font>'.format(tools.get_option(constants.Opt.VERSION)))
        version_label.layout_constraint = qt_graphics.RelativeLayoutConstraint().east(20).south(20)
        layout.addWidget(version_label)
예제 #7
0
    def __init__(self):
        """
            Create the main window, the help browser dialog, the audio player, ...
        """
        # main window
        self.main_window = MainWindow()

        # help browser
        self.help_browser_widget = BrowserWidget(QtCore.QUrl(c.Manual_Index), t.load_ui_icon)
        self.help_dialog = cg.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 = QtGui.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 = QtGui.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 = g.RelativeLayoutConstraint().center_horizontal().south(20)
        self.notification = None

        # audio player
        self.player = audio.Player()
        self.player.next.connect(self.audio_notification)
        self.player.set_playlist(audio.load_soundtrack_playlist())
        # start audio player if wished
        if not t.get_option(c.O.BG_MUTE):
            self.player.start()

        # 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()
예제 #8
0
def start():
    """
        Creates the Qt application and shows the main window.
    """

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

    # TODO multiple screen support?

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

    # if no bounds are set, set resonable bounds
    if t.get_option(c.O.MW_BOUNDS) is None:
        t.set_option(c.O.MW_BOUNDS, desktop.availableGeometry().adjusted(50, 50, -100, -100))
        t.set_option(c.O.MW_MAXIMIZED, True)
        t.log_info('No previous bounds of the main window stored, start maximized')

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

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

    t.log_info('client initialized, start Qt app execution')
    # TODO is this necessary to run as event?
    QtCore.QTimer.singleShot(0, network_start)
    app.exec_()
예제 #9
0
    def __init__(self, client):
        super().__init__()

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

        layout = g.RelativeLayout(self)

        start_image = QtGui.QPixmap(c.extend(c.Graphics_UI_Folder, 'start.background.jpg'))
        start_image_item = QtGui.QGraphicsPixmapItem(start_image)
        start_image_item.setZValue(1)

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

        view = QtGui.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 = g.RelativeLayoutConstraint().center_horizontal().center_vertical()
        layout.addWidget(view)

        subtitle = QtGui.QLabel('')
        subtitle.layout_constraint = g.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_options_dialog
        }

        image_map_file = c.extend(c.Graphics_UI_Folder, 'start.overlay.info')
        image_map = u.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))

        for k, v in image_map.items():
            # add action from our predefined action dictionary
            pixmap = QtGui.QPixmap(c.extend(c.Graphics_UI_Folder, v['overlay']))
            mapitem = MapItem(view, pixmap, label=subtitle, description=v['label'])
            mapitem.item.setZValue(3)
            offset = v['offset']
            mapitem.item.setOffset(QtCore.QPointF(offset[0], offset[1]))
            mapitem.item.clicked.connect(actions[k])

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

        version_label = QtGui.QLabel('<font color=#ffffff>{}</font>'.format(t.get_option(c.O.VERSION)))
        version_label.layout_constraint = g.RelativeLayoutConstraint().east(20).south(20)
        layout.addWidget(version_label)
예제 #10
0
    def register_lineedit(self, edit, option):
        """

        """
        edit.setText(t.get_option(option))
        self.lineedits.append((edit, option))
예제 #11
0
    # import some base libraries
    from base import constants as c
    from base import tools as t

    # search for existing options file, if not existing, save it once (should just save an empty dictionary
    Options_File = os.path.join(User_Folder, 'options.info')
    if not os.path.exists(Options_File):
        t.save_options(Options_File)

    # create single options object, load options and send a log message
    t.load_options(Options_File)
    t.log_info('options loaded from user folder ({})'.format(User_Folder))

    # test for phonon availability
    if t.get_option(c.O.PHONON_SUPPORTED):
        try:
            from PySide.phonon import Phonon
        except ImportError:
            t.log_error('Phonon backend not available, no sound.')
            t.set_option(c.O.PHONON_SUPPORTED, False)

    # special case of some desktop environments under Linux where full screen mode does not work well
    if t.get_option(c.O.FULLSCREEN_SUPPORTED):
        desktop_session = os.environ.get("DESKTOP_SESSION")
        if desktop_session and (desktop_session.startswith('ubuntu')
                                or 'xfce' in desktop_session
                                or desktop_session.startswith('xubuntu')
                                or 'gnome' in desktop_session):
            t.set_option(c.O.FULLSCREEN_SUPPORTED, False)
            t.log_warning(
예제 #12
0
    # import some base libraries
    from base import constants as c
    from base import tools as t

    # search for existing options file, if not existing, save it once (should just save an empty dictionary
    Options_File = os.path.join(User_Folder, 'options.info')
    if not os.path.exists(Options_File):
        t.save_options(Options_File)

    # create single options object, load options and send a log message
    t.load_options(Options_File)
    t.log_info('options loaded from user folder ({})'.format(User_Folder))

    # test for phonon availability
    if t.get_option(c.O.PHONON_SUPPORTED):
        try:
            from PySide.phonon import Phonon
        except ImportError:
            t.log_error('Phonon backend not available, no sound.')
            t.set_option(c.O.PHONON_SUPPORTED, False)

    # special case of some desktop environments under Linux where full screen mode does not work well
    if t.get_option(c.O.FULLSCREEN_SUPPORTED):
        desktop_session = os.environ.get("DESKTOP_SESSION")
        if desktop_session and (desktop_session.startswith('ubuntu') or 'xfce' in desktop_session
                                or desktop_session.startswith('xubuntu') or 'gnome' in desktop_session):
            t.set_option(c.O.FULLSCREEN_SUPPORTED, False)
            t.log_warning(
                'Desktop environment {} has problems with full screen mode. Will turn if off.'.format(desktop_session))
    if not t.get_option(c.O.FULLSCREEN_SUPPORTED):
예제 #13
0
    def _register_line_edit(self, edit, option):
        """

        """
        edit.setText(tools.get_option(option))
        self._line_edits.append((edit, option))
예제 #14
0
    def _register_slider(self, slider, option):
        """

        """
        slider.setValue(tools.get_option(option))
        self._sliders.append((slider, option))
예제 #15
0
        sys.stderr = codecs.open(Error_File, encoding='utf-8', mode='w')

    # import some base libraries
    import base.tools as tools

    # search for existing options file, if not existing, save it once (should just save an empty dictionary)
    Options_File = os.path.join(user_folder, 'options.info')
    if not os.path.exists(Options_File):
        tools.save_options(Options_File)

    # create single options object, load options and send a log message
    tools.load_options(Options_File)
    tools.log_info('options loaded from user folder ({})'.format(user_folder))

    # special case of some desktop environments under Linux where full screen mode does not work well
    if tools.get_option(constants.Opt.FULLSCREEN_SUPPORTED):
        desktop_session = os.environ.get("DESKTOP_SESSION")
        if desktop_session and (
                    desktop_session.startswith('ubuntu') or 'xfce' in desktop_session or desktop_session.startswith(
                'xubuntu') or 'gnome' in desktop_session):
            tools.set_option(constants.Opt.FULLSCREEN_SUPPORTED, False)
            tools.log_warning(
                'Desktop environment {} has problems with full screen mode. Will turn if off.'.format(desktop_session))
    if not tools.get_option(constants.Opt.FULLSCREEN_SUPPORTED):
        tools.set_option(constants.Opt.FULLSCREEN, False)

    # now we can safely assume that the environment is good to us

    # start server
    import multiprocessing
    # multiprocessing.freeze_support()