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
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
def quit(self): """ Cleans up and closes the main window which causes app.exec_() to finish. """ # store state in options t.set_option(c.O.MW_BOUNDS, self.main_window.normalGeometry()) t.set_option(c.O.MW_MAXIMIZED, self.main_window.isMaximized()) # audio # self.player.stop() # close the main window self.main_window.close()
def quit(self): """ Cleans up and closes the main window which causes app.exec_() to finish. """ # store state in options tools.set_option(constants.Opt.MAINWINDOW_BOUNDS, self.main_window.normalGeometry()) tools.set_option(constants.Opt.MAINWINDOW_MAXIMIZED, self.main_window.isMaximized()) # audio audio.soundtrack_player.stop() # close the main window self.main_window.close()
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_()
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_()
# 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): t.set_option(c.O.FULLSCREEN, False)
# 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): t.set_option(c.O.FULLSCREEN, False) # now we can safely assume that the environment is good to us # start server
# 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() multiprocessing.set_start_method('spawn') from server.server import start_server start_server() #from server.network import ServerProcess