示例#1
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_()
示例#2
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()
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>

from PySide import QtGui, QtCore
from client import audio
import lib.graphics as g, tools as t

def show_notification(text):
    t.thread_status('notification')
    text = 'Playing {}'.format(text)
    g.Notification(window, text, positioner=g.Relative_Positioner().centerH().south(20))

t.thread_status('main')

app = QtGui.QApplication([])

window = QtGui.QWidget()
window.show()

playlist = audio.load_soundtrack_playlist()

player = audio.Player()
player.next.connect(show_notification)
player.set_playlist(playlist)
player.start()
QtCore.QTimer.singleShot(0, lambda: t.thread_status('qt'))
app.exec_()
示例#4
0
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>

from PySide import QtGui

from client import audio
import lib.graphics as g


def show_notification(text):
    text = 'Playing {}'.format(text)
    g.Notification(
        window,
        text,
        positioner=g.Relative_Positioner().center_horizontal().south(20))


app = QtGui.QApplication([])

window = QtGui.QWidget()
window.show()

playlist = audio.load_soundtrack_playlist()

player = audio.Player()
player.next.connect(show_notification)
player.set_playlist(playlist)
player.start()
app.exec_()