def test_save_load_settings(): sett = settings.Settings() sett.future_forecast_time = 1 assert sett.future_forecast_time == 1 sett.future_forecast_time = 2 sett.save_to_file() settings2 = settings.Settings() assert settings2.future_forecast_time == 2
def run_game(): #constructing the main window pygame.init() ai_settings = settings.Settings() screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_width), RESIZABLE) # set the resolution pygame.display.set_caption("Alien Invasion") #set the window title stats = GameStats(ai_settings) #Adding the ship to the screen player_ship = ship.Ship(ai_settings, screen) #enemy=ship.Alien(ai_settings,screen) bullets = Group() aliens = Group() # make the fleet visible functions.create_fleet(ai_settings, screen, player_ship, aliens) # main loop while True: functions.event_checker(ai_settings, screen, player_ship, bullets) if stats.game_active: player_ship.movement() functions.bullets_refresh(ai_settings, screen, player_ship, aliens, bullets) functions.update_aliens(ai_settings, stats, screen, player_ship, aliens, bullets) functions.update_screen(ai_settings, screen, player_ship, aliens, bullets)
def saveLyrics(self, lyrics): try: self._lyrics = lyrics self._settings = settings.Settings() lyric_grabber.write_file(artist=self._artist, title=self._title, write_info=self._settings.info, write_metadata=self._settings.metadata, write_text=self._settings.text, lyrics=lyrics, song_filepath=self._filepath) except Exception as e: logger.log(logger.LOG_LEVEL_ERROR, str(e))
def __init__(self, parent, filepath, artist=None, title=None, url=None, source=None): super().__init__() self._filepath = filepath self._artist = artist self._title = title self._url = url self._source = source self._settings = settings.Settings() self.setProgressIcon.emit(states.NOT_STARTED)
def test_edit_settings_properties(): sett = settings.Settings() # mode sett.mode = 'social' assert sett.mode == 'social' sett.mode = 'non-existent' assert sett.mode == 'social' # refresh_interval sett.mode = 'social' sett.refresh_interval = 1 assert sett.refresh_interval == 15 # if interval < 15, return 15 sett.refresh_interval = 16 assert sett.refresh_interval == 16 sett.refresh_interval = "test" assert sett.refresh_interval == 16 sett.mode = 'weather' assert sett.refresh_interval == 16 # future_forecast_time sett.future_forecast_time = 2 sett.future_forecast_time = "wow" assert sett.future_forecast_time == 2 # brightness sett.brightness = 50 sett.brightness = 101 sett.brightness = -1 sett.brightness = "test" assert sett.brightness == 50 # subjects sett.subjects = "hoi,kaas,test" assert sett.subjects == ['hoi', 'kaas', 'test'] sett.subjects = ['test1', 'test2'] assert sett.subjects == ['test1', 'test2'] sett.subjects = 5 assert sett.subjects == ['test1', 'test2'] # location sett.location = "1.02,2.01" assert sett.location == ['1.02', '2.01'] sett.location = ['50.1', '100.2'] assert sett.location == ['50.1', '100.2'] sett.location = 5 assert sett.location == ['50.1', '100.2'] # max_future_forecast_time with pytest.raises(AttributeError): sett.max_future_forecast_time = 5 assert sett.max_future_forecast_time == 24
def __init__(self, parent, filepaths): super().__init__() self._filepaths = filepaths self._settings = settings.Settings() self._metadataExecutor = futures.ThreadPoolExecutor(max_workers=20) if self._settings.source == 'azlyrics' or self._settings.source == 'musixmatch': self._lyricsExecutor = futures.ThreadPoolExecutor(max_workers=3) else: self._lyricsExecutor = futures.ThreadPoolExecutor(max_workers=10) self._fileWritingExecutor = futures.ThreadPoolExecutor(max_workers=10) self._metadataResults = [] self._lyricsResults = [] self._fileWritingResults = [] self._songs = []
def __init__(self, parent=None): super().__init__(parent) # Style the window if utils.IS_WINDOWS: self.setWindowIcon( QtGui.QIcon(utils.resource_path('./assets/icon.png'))) # Get settings from settings.ini file self._settings = settings.Settings() # Wrapper for settings class def set_source(): self._settings.source = self._sourceComboBox.currentText() def set_approximate(state): self._settings.approximate = state def set_remove_brackets(state): self._settings.remove_brackets = state def set_info(state): self._settings.info = state def set_metadata(state): self._settings.metadata = state def set_text(state): self._settings.text = state def set_sounds(state): self._settings.play_sounds = state def set_errors(state): self._settings.show_errors = state def set_updates(state): self._settings.show_updates = state # Add settings controls self._sourceLabel = QtWidgets.QLabel('Lyrics source:') self._sourceLabel.setAlignment(QtCore.Qt.AlignRight) self._sourceComboBox = QtWidgets.QComboBox() self._sourceComboBox.setMaximumWidth(150) for source in utils.SUPPORTED_SOURCES: self._sourceComboBox.addItem(source) index = self._sourceComboBox.findText(self._settings.source, QtCore.Qt.MatchFixedString) self._sourceComboBox.currentIndexChanged.connect(set_source) if index >= 0: self._sourceComboBox.setCurrentIndex(index) self._optionsLabel = QtWidgets.QLabel('Lyrics options:') self._optionsLabel.setAlignment(QtCore.Qt.AlignRight) self._approximateCheckBox = QtWidgets.QCheckBox( 'Search only by song title and ignore artist') self._approximateCheckBox.setChecked(self._settings.approximate) self._approximateCheckBox.stateChanged.connect( lambda state: set_approximate(state)) self._bracketCheckBox = QtWidgets.QCheckBox( 'Remove parts of song title and artist in brackets\nwhen searching for lyrics' ) self._bracketCheckBox.setStyleSheet( 'QCheckBox::indicator { subcontrol-position: left top; }') self._bracketCheckBox.stateChanged.connect( lambda state: set_remove_brackets(state)) self._bracketCheckBox.setChecked(self._settings.remove_brackets) self._infoCheckBox = QtWidgets.QCheckBox( 'Add title and artist to top of saved lyrics') self._infoCheckBox.stateChanged.connect(lambda state: set_info(state)) self._infoCheckBox.setChecked(self._settings.info) self._metadataCheckBox = QtWidgets.QCheckBox( 'Save lyrics to song metadata\n(e.g. for display in music apps on phone)' ) self._metadataCheckBox.setStyleSheet( 'QCheckBox::indicator { subcontrol-position: left top; }') self._metadataCheckBox.stateChanged.connect( lambda state: set_metadata(state)) self._metadataCheckBox.setChecked(self._settings.metadata) self._textCheckBox = QtWidgets.QCheckBox('Save lyrics to a text file') self._textCheckBox.stateChanged.connect(lambda state: set_text(state)) self._textCheckBox.setChecked(self._settings.text) # Separator Line self._separatorLineFrame = QtWidgets.QFrame() self._separatorLineFrame.setFrameShape(QtWidgets.QFrame.HLine) self._separatorLineFrame.setFrameShadow(QtWidgets.QFrame.Raised) # Other controls self._playSoundsLabel = QtWidgets.QLabel('Sounds and dialogs:') self._playSoundsCheckBox = QtWidgets.QCheckBox('Enable sound effects') self._playSoundsCheckBox.stateChanged.connect( lambda state: set_sounds(state)) self._playSoundsCheckBox.setChecked(self._settings.play_sounds) self._showErrorCheckBox = QtWidgets.QCheckBox('Show error messages') self._showErrorCheckBox.stateChanged.connect( lambda state: set_errors(state)) self._showErrorCheckBox.setChecked(self._settings.show_errors) self._showUpdatesCheckBox = QtWidgets.QCheckBox('Show update messages') self._showUpdatesCheckBox.stateChanged.connect( lambda state: set_updates(state)) self._showUpdatesCheckBox.setChecked(self._settings.show_updates) # For testing # self._approximateCheckBox.setChecked(True) # self._tagCheckBox.setChecked(True) # Separator leave a bunch of space in case settings expands self._verticalSpacer = QtWidgets.QSpacerItem( 0, 0, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) # Add settings and about to dialog self._settingsGridLayout = QtWidgets.QGridLayout() self._settingsGridLayout.addWidget(self._sourceLabel, 0, 0) self._settingsGridLayout.addWidget(self._sourceComboBox, 0, 1) self._settingsGridLayout.addWidget(self._optionsLabel, 1, 0) self._settingsGridLayout.addWidget(self._approximateCheckBox, 1, 1) self._settingsGridLayout.addWidget(self._bracketCheckBox, 2, 1) self._settingsGridLayout.addWidget(self._infoCheckBox, 3, 1) self._settingsGridLayout.addWidget(self._metadataCheckBox, 4, 1) self._settingsGridLayout.addWidget(self._textCheckBox, 5, 1) self._settingsGridLayout.addWidget(self._separatorLineFrame, 6, 0, 1, -1) self._settingsGridLayout.addWidget(self._playSoundsLabel, 7, 0) self._settingsGridLayout.addWidget(self._playSoundsCheckBox, 7, 1) self._settingsGridLayout.addWidget(self._showErrorCheckBox, 8, 1) self._settingsGridLayout.addWidget(self._showUpdatesCheckBox, 9, 1) self._settingsGridLayout.addItem(self._verticalSpacer, 10, 0, -1, -1) self.setLayout(self._settingsGridLayout) # Style settings dialog if utils.IS_WINDOWS: self.setWindowIcon( QtGui.QIcon(utils.resource_path('./assets/icon.png'))) if utils.IS_MAC: self.setWindowTitle('Preferences') else: self.setWindowTitle('Settings') self.setWindowModality(QtCore.Qt.ApplicationModal) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.setFixedSize(self.minimumSizeHint()) # Center dialog in relation to parent self.resize(self.minimumSizeHint()) self.move(parent.x() + (parent.width() - self.width()) / 2, parent.y() + (parent.height() - self.height()) / 2)
def __init__(self): # self.battleye_event_queue = Queue.Queue(400) self.settings, self.vac_bans_file = settings.Settings().load_rcon_bot_config() self.vac_bans = ConfigParser.ConfigParser().read(self.vac_bans_file)
def __init__(self): super(MainWindow, self).__init__() # Create a settings object self._settings = settings.Settings() # Create and add items to menubar # Actions are ordered by their location in the macOS menubar # macOS menubar is significantly larger by OS convention # See https://developer.apple.com/design/human-interface-guidelines/macos/menus/menu-bar-menus/ self._openAboutAction = QtWidgets.QAction('About Quaver') self._openAboutAction.triggered.connect(self.openAboutDialog) if utils.IS_MAC: self._openSettingsAction = QtWidgets.QAction('Preferences') else: self._openSettingsAction = QtWidgets.QAction('Settings') self._openSettingsAction.setShortcut('Ctrl+Comma') self._openSettingsAction.triggered.connect(self.openSettingsDialog) self._openFileAction = QtWidgets.QAction('Open File...', self) self._openFileAction.setShortcut('Ctrl+O') self._openFileAction.triggered.connect( lambda: self.openFileDialog(QtWidgets.QFileDialog.ExistingFiles)) self._openFolderAction = QtWidgets.QAction('Open Folder...', self) self._openFolderAction.setShortcut('Ctrl+Shift+O') self._openFolderAction.triggered.connect( lambda: self.openFileDialog(QtWidgets.QFileDialog.Directory)) self._closeAction = QtWidgets.QAction('Close') self._closeAction.setShortcut('Ctrl+W') self._closeAction.triggered.connect(self.close) if utils.IS_MAC: self._openFinderAction = QtWidgets.QAction( 'Open Selected File in Finder', self) self._openFinderAction.triggered.connect(self.openFinder) self._openFinderAction.setEnabled(False) self._removeAllAction = QtWidgets.QAction('Remove All Files') self._removeAllAction.setShortcut('Ctrl+Shift+Backspace') self._removeAllAction.triggered.connect(self.removeAllFilesFromList) self._removeCompletedAction = QtWidgets.QAction( 'Remove All Files with Lyrics') self._removeCompletedAction.setShortcut('Ctrl+Alt+Shift+Backspace') self._removeCompletedAction.triggered.connect( self.removeCompletedFiles) self._removeCurrentAction = QtWidgets.QAction('Remove Selected File') self._removeCurrentAction.setShortcut('Ctrl+Backspace') self._removeCurrentAction.triggered.connect(self.removeCurrentFile) self._removeCurrentAction.setEnabled(False) if utils.IS_MAC: self._copyLyricsAction = QtWidgets.QAction('Copy Lyrics') self._copyLyricsAction.setShortcut('Ctrl+C') self._copyLyricsAction.triggered.connect(self.copyLyrics) self._copyLyricsAction.setEnabled(False) self._saveLyricsAction = QtWidgets.QAction('Save Lyrics') self._saveLyricsAction.setShortcut('Ctrl+S') self._saveLyricsAction.triggered.connect(self.saveLyrics) self._saveLyricsAction.setEnabled(False) self._removeLyricsAction = QtWidgets.QAction('Remove Lyrics') self._removeLyricsAction.setShortcut('Ctrl+Shift+X') self._removeLyricsAction.triggered.connect(self.removeLyrics) self._removeLyricsAction.setEnabled(False) self._undoAction = QtWidgets.QAction('Undo Typing') self._undoAction.setShortcut('Ctrl+Z') self._undoAction.triggered.connect(self.undoLyrics) self._undoAction.setEnabled(False) self._redoAction = QtWidgets.QAction('Redo Typing') self._redoAction.setShortcut('Ctrl+Shift+Z') self._redoAction.triggered.connect(self.redoLyrics) self._redoAction.setEnabled(False) self._viewSongsSubMenuAction = QtWidgets.QAction( 'View Lyrics For...', self) self._noLyricsAction = QtWidgets.QAction('No songs added', self) self._noLyricsAction.setEnabled(False) self._viewPreviousAction = QtWidgets.QAction('View Previous', self) self._viewPreviousAction.setShortcut('Ctrl+Up') self._viewPreviousAction.triggered.connect(self.viewPreviousWidget) self._viewPreviousAction.setEnabled(False) self._viewNextAction = QtWidgets.QAction('View Next', self) self._viewNextAction.setShortcut('Ctrl+Down') self._viewNextAction.triggered.connect(self.viewNextWidget) self._viewNextAction.setEnabled(False) self._toolBarAction = QtWidgets.QAction('Hide Toolbar', self) self._toolBarAction.setShortcut('Ctrl+Alt+T') self._toolBarAction.triggered.connect(self.toggleToolBar) self._minimizeAction = QtWidgets.QAction('Minimize', self) self._minimizeAction.setShortcut('Ctrl+M') self._minimizeAction.triggered.connect(self.toggleMinimized) self._maximizeAction = QtWidgets.QAction('Zoom', self) self._maximizeAction.triggered.connect(self.toggleMaximized) self._showNormalAction = QtWidgets.QAction('Bring to Front', self) self._showNormalAction.triggered.connect(self.showNormal) self._helpAction = QtWidgets.QAction('Help', self) self._helpAction.triggered.connect(self.openAboutDialog) if utils.IS_MAC: self._menuBar = QtWidgets.QMenuBar() else: self._menuBar = self.menuBar() if utils.IS_MAC: self._fileMenu = self._menuBar.addMenu('Quaver') self._fileMenu.addAction(self._openAboutAction) self._fileMenu.addSeparator() self._fileMenu.addAction(self._openSettingsAction) self._fileMenu = self._menuBar.addMenu('File') self._fileMenu.addAction(self._openFileAction) self._fileMenu.addAction(self._openFolderAction) if utils.IS_MAC: self._fileMenu.addSeparator() self._fileMenu.addAction(self._openFinderAction) self._fileMenu.addSeparator() self._fileMenu.addAction(self._closeAction) self._editMenu = self._menuBar.addMenu('Edit') self._editMenu.addAction(self._removeCurrentAction) self._editMenu.addSeparator() self._editMenu.addAction(self._removeAllAction) self._editMenu.addAction(self._removeCompletedAction) if utils.IS_MAC: self._editMenu.addSeparator() self._editMenu.addAction(self._copyLyricsAction) self._editMenu.addAction(self._saveLyricsAction) self._editMenu.addAction(self._removeLyricsAction) self._editMenu.addAction(self._undoAction) self._editMenu.addAction(self._redoAction) self._viewMenu = self._menuBar.addMenu('View') self._viewMenu.addAction(self._viewSongsSubMenuAction) self._songsSubMenu = QtWidgets.QMenu(self._menuBar) self._songsSubMenu.addAction(self._noLyricsAction) self._viewSongsSubMenuAction.setMenu(self._songsSubMenu) self._viewMenu.addSeparator() self._viewMenu.addAction(self._viewPreviousAction) self._viewMenu.addAction(self._viewNextAction) self._viewMenu.addSeparator() self._viewMenu.addAction(self._toolBarAction) self._windowMenu = self._menuBar.addMenu('Window') self._windowMenu.addAction(self._minimizeAction) self._windowMenu.addAction(self._maximizeAction) self._windowMenu.addSeparator() self._windowMenu.addAction(self._showNormalAction) if not utils.IS_MAC: self._toolsMenu = self._menuBar.addMenu('Tools') self._toolsMenu.addAction(self._openSettingsAction) self._helpMenu = self._menuBar.addMenu('Help') self._helpMenu.addAction(self._helpAction) if not utils.IS_MAC: self._helpMenu.addAction(self._openAboutAction) # Create toolbar, but only on Mac # On other platforms, the menubar essentially takes on the role that the menu bar takes on Mac if utils.IS_MAC: self._leftAlignSpacer = QtWidgets.QSpacerItem( 15, 25, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum) if utils.IS_MACOS_DARK_MODE: self._addFileButton = QtWidgets.QPushButton( QtGui.QIcon( utils.resource_path( './assets/add_music_inverted.png')), 'Add song') self._addFolderButton = QtWidgets.QPushButton( QtGui.QIcon( utils.resource_path( './assets/add_folder_inverted.png')), 'Add folder') self._removeFileButton = QtWidgets.QPushButton( QtGui.QIcon( utils.resource_path('./assets/delete_inverted.png')), 'Remove all') self._settingsButton = QtWidgets.QPushButton( QtGui.QIcon( utils.resource_path('./assets/settings_inverted.png')), 'Preferences') else: self._addFileButton = QtWidgets.QPushButton( QtGui.QIcon(utils.resource_path('./assets/add_music.png')), 'Add song') self._addFileButton.pressed.connect( lambda: self._addFileButton.setIcon( QtGui.QIcon( utils.resource_path( './assets/add_music_inverted.png')))) self._addFileButton.released.connect( lambda: self._addFileButton.setIcon( QtGui.QIcon( utils.resource_path('./assets/add_music.png')))) self._addFolderButton = QtWidgets.QPushButton( QtGui.QIcon( utils.resource_path('./assets/add_folder.png')), 'Add folder') self._addFolderButton.pressed.connect( lambda: self._addFolderButton.setIcon( QtGui.QIcon( utils.resource_path( './assets/add_folder_inverted.png')))) self._addFolderButton.released.connect( lambda: self._addFolderButton.setIcon( QtGui.QIcon( utils.resource_path('./assets/add_folder.png')))) self._removeFileButton = QtWidgets.QPushButton( QtGui.QIcon(utils.resource_path('./assets/delete.png')), 'Remove all') self._removeFileButton.pressed.connect( lambda: self._removeFileButton.setIcon( QtGui.QIcon( utils.resource_path('./assets/delete_inverted.png') ))) self._removeFileButton.released.connect( lambda: self._removeFileButton.setIcon( QtGui.QIcon(utils.resource_path('./assets/delete.png')) )) self._settingsButton = QtWidgets.QPushButton( QtGui.QIcon(utils.resource_path('./assets/settings.png')), 'Preferences') self._settingsButton.pressed.connect( lambda: self._settingsButton.setIcon( QtGui.QIcon( utils.resource_path( './assets/settings_inverted.png')))) self._settingsButton.released.connect( lambda: self._settingsButton.setIcon( QtGui.QIcon( utils.resource_path('./assets/settings.png')))) self._addFileButton.clicked.connect(lambda: self.openFileDialog( QtWidgets.QFileDialog.ExistingFiles)) self._addFolderButton.clicked.connect( lambda: self.openFileDialog(QtWidgets.QFileDialog.Directory)) self._removeFileButton.clicked.connect(self.removeAllFilesFromList) self._horizontalSpacer = QtWidgets.QSpacerItem( 20, 25, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self._settingsButton.clicked.connect(self.openSettingsDialog) self._rightAlignSpacer = QtWidgets.QSpacerItem( 15, 25, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum) self._toolBarLayout = QtWidgets.QHBoxLayout() self._toolBarLayout.addItem(self._leftAlignSpacer) self._toolBarLayout.addWidget(self._addFileButton) self._toolBarLayout.addWidget(self._addFolderButton) self._toolBarLayout.addWidget(self._removeFileButton) self._toolBarLayout.addItem(self._horizontalSpacer) self._toolBarLayout.addWidget(self._settingsButton) self._toolBarLayout.addItem(self._rightAlignSpacer) self._toolBarLayout.setSpacing(5) self._toolBarLayout.setContentsMargins(0, 0, 0, 0) self._toolBarItems = QtWidgets.QWidget() self._toolBarItems.setLayout(self._toolBarLayout) # Add toolbar to window with name 'main' self._toolBar = self.addToolBar('main') self._toolBar.addWidget(self._toolBarItems) self._toolBar.setFloatable(False) self._toolBar.setMovable(False) self._toolBarVisible = True if utils.IS_MACOS_DARK_MODE: # Workaround for the weird white line that shows up at the bottom. self._toolBar.setStyleSheet('\ QToolBar {border-bottom: 1px solid rgb(21, 24, 24); \ border-top: 0px; \ background-color: rgb(42, 42, 42)}') self.setContextMenuPolicy(QtCore.Qt.NoContextMenu) # Create a hint for the user # This is the image/text in middle of screen on startup self._instructionIconLabel = QtWidgets.QLabel() self._instructionIconLabel.setSizePolicy( QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self._instructionIconLabel.setAlignment(QtCore.Qt.AlignCenter) self._quaverIcon = QtGui.QPixmap( utils.resource_path('./assets/icon_monochrome.png')) self._quaverIcon.setDevicePixelRatio(self.devicePixelRatio()) self._iconWidth = self.devicePixelRatio() * 150 self._iconHeight = self.devicePixelRatio() * 150 self._instructionIconLabel.setPixmap( self._quaverIcon.scaled(self._iconWidth, self._iconHeight, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)) self._verticalSpacer = QtWidgets.QSpacerItem( 20, 20, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum) if utils.IS_MAC: self._instructionLabel = QtWidgets.QLabel( 'Grab lyrics by adding a song.' '<br>Drag a song in, or click "Add song" to get started.') else: self._instructionLabel = QtWidgets.QLabel( 'Grab lyrics by adding a song.' '<br>Drag a song in, or open the "File" menu to get started.') self._instructionLabel.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self._instructionLabel.setAlignment(QtCore.Qt.AlignCenter) self._instructionLabel.setStyleSheet('color: grey') self._instructionLabel.setFont(appearance.SMALL_FONT) self._removedInstructions = False # This layout contains all the items in the song list # Style the layout: spacing (between items), content (padding within items) self._mainScrollAreaWidgetLayout = QtWidgets.QVBoxLayout() self._mainScrollAreaWidgetLayout.setAlignment(QtCore.Qt.AlignCenter) self._mainScrollAreaWidgetLayout.setSpacing(0) self._mainScrollAreaWidgetLayout.setContentsMargins(0, 0, 0, 0) self._mainScrollAreaWidgetLayout.addWidget(self._instructionIconLabel) self._mainScrollAreaWidgetLayout.addItem(self._verticalSpacer) self._mainScrollAreaWidgetLayout.addWidget(self._instructionLabel) # mainScrollAreaWidget contains the layout that contains all listwidgets self._mainScrollAreaWidget = QtWidgets.QWidget() self._mainScrollAreaWidget.setMinimumWidth(400) self._mainScrollAreaWidget.setLayout(self._mainScrollAreaWidgetLayout) # Create QScrollArea to contains widget containing list of all list items # NOTE: Not using QListWidget because scrolling is choppy on macOS self._mainScrollArea = QtWidgets.QScrollArea(self) self._mainScrollArea.setFrameShape(QtWidgets.QFrame.NoFrame) self._mainScrollArea.setWidgetResizable(True) self._mainScrollArea.setAttribute(QtCore.Qt.WA_MacShowFocusRect, False) self._mainScrollArea.setFocusPolicy(QtCore.Qt.NoFocus) self._mainScrollArea.setWidget(self._mainScrollAreaWidget) self.setCentralWidget(self._mainScrollArea) # Style main window self.setMinimumSize(600, 400) self.setUnifiedTitleAndToolBarOnMac(True) if not utils.IS_MAC: self.setWindowIcon( QtGui.QIcon(utils.resource_path('./assets/icon.png'))) self.setAcceptDrops(True)
def close_battleye_connection(serverConnection): try: serverConnection.stop() except Exception: pass parser = argparse.ArgumentParser( description= 'pyBE_raw Usage: pyBE_raw <serverid> <command to send to server>') parser.add_argument("serverid") parser.add_argument("command") args = parser.parse_args() settings, vac_bans_file = settings.Settings().load_rcon_bot_config() for server in settings: if server["Server ID"] == args.serverid: serverConnection = None try: serverConnection = rcon.BattleyeServer(server["ServerIP"], server["ServerPort"], server["RconPassword"]) timeout = 60 + time.time() while (time.time() < timeout) and not (serverConnection.connected): print("Retrying to connect to " + server["ServerName"]) time.sleep(5) close_battleye_connection(serverConnection) serverConnection = rcon.BattleyeServer(server["ServerIP"], server["ServerPort"],
import program as program import modules.settings as settings import time import json prog = program.Program(settings.Settings()) def test_change_interval_task(): assert program.change_interval_task('test', 20, prog) == 20 program.cancel_task('test') assert program.change_interval_task('test', 20) is None def test_get_social_rating(): prog.settings.subjects = ['max verstappen'] assert len(prog.get_current_social_rating()) > 0 def test_program_mqtt(): prog.MQTT.subscribe_topic("[email protected]/app") prog.MQTT.send_message("test") time.sleep(1) # sleep because sending the message takes time assert prog.MQTT.messages[0] == "test" prog.MQTT.retrieve_message() def test_check_messages_program(): msg = prog.check_messages() assert msg == None prog.MQTT.messages.append("testvalue")
""" Programm for analyzing an ODS spreadsheet. The program takes a file as argument (ODS file) and loads its columns and rows into the database. Then you can filter and search things. """ from modules import arguments from modules import catalog from modules import settings ARGS = arguments.getArguments() if __name__ == '__main__': # initialize SETTINGS SETTINGS = settings.Settings(force_convert=ARGS.force_convert) # initialize DB DB = catalog.Catalog(file=ARGS.file, settings=SETTINGS, quiet=ARGS.quiet, inject=ARGS.inject) # count query if ARGS.count: show, null = DB.count(search=ARGS.count, csv=ARGS.csv, date=ARGS.date, sort=ARGS.sort, reverse=ARGS.reverse, filter=ARGS.filter,
def __init__(self, args): self.config = settings.Settings()
import modules.settings as settings import modules.api as api_conn socialkey = "bddae9b9df86095e0d4b9908a7a9b622" weatherkey = "f71af11b8e02b30c2ed988487f0dd533" settings = settings.Settings() weather_connect = api_conn.WeatherConnect(weatherkey, settings) social_connect = api_conn.SocialConnect(socialkey, settings) def test_fetch_weather_hourly_2_days(): forecast_time = weather_connect.fetch_hourly_2_days() assert isinstance(forecast_time, object) assert len(forecast_time) > 0 def test_weather_update_url(): weather_connect.coordinates = "lat=" + str(1) + "&lon=" + str(5) weather_connect.exclusions = "exclude=current" weather_connect.units = "units=imperial" weather_connect.app_id = "appid=test_id" weather_connect.update_url() assert weather_connect.complete_url == "https://api.openweathermap.org/data/2.5/onecall?" + \ weather_connect.coordinates + "&exclude=current&units=imperial&appid=test_id" weather_connect.complete_url = "wow wat gaaf" assert weather_connect.complete_url == "wow wat gaaf" def test_fetch_social_data_calc_avg(): social_data = social_connect.fetch_data() assert isinstance(social_data, object)
def __init__(self, bans_deamon=False): self.interval, self.server_ban_deamon, self.server_settings = settings.Settings( bans_deamon).load_config()
class ModalDialog (QtWidgets.QDialog): """A modal dialog with some virtual functions that blocks user input. By default, has icon, message, informative text, suppression checkbox, affirmative/negative repsonse button, and show more button. Can be inherited from to customize and add more elements or remove elements. If used as base class, inheritor must implement virtual functions, corresponding to slots for the signals emitted by buttons/checkboxes. Attributes: settings (Settings): A settings object _iconLabel (QtWidgets.QLabel): Label used to display icon on left _titleLabel (QtWidgets.QLabel): Label used to display HIG message _messageLabel (QtWidgets.QLabel): Label used to display HIG informative text _showAgainCheckBox (QtWidgets.QCheckBox): Checkbox used has HIG suppression checkbox _noButton (QtWidget.QPushButton): Button used as negative response button _okButton (QtWidget.QPushButton): Button used as positive response button _showMoreButton (QtWidget.QPushButton): Button used to expand an HIG accessory view """ settings = settings.Settings() def __init__(self, parent): super().__init__(parent) self._iconLabel = QtWidgets.QLabel() self._iconLabel.setFixedWidth(75) self._iconLabel.setFixedHeight(75) self._titleLabel = QtWidgets.QLabel() self._titleLabel.setFont(appearance.SMALL_FONT_BOLD) self._messageLabel = QtWidgets.QLabel() self._messageLabel.setFixedWidth(375) self._messageLabel.setMinimumHeight(self._messageLabel.minimumSizeHint().height()) self._messageLabel.setWordWrap(True) self._messageLabel.setFont(appearance.SMALLER_FONT) if utils.IS_MAC and utils.IS_MACOS_DARK_MODE: self._messageLabel.setStyleSheet('color: grey') else: self._messageLabel.setStyleSheet('color: dimgrey') # Option to suppress further errors self._showAgainCheckBox = QtWidgets.QCheckBox('Do not show this message again') self._showAgainCheckBox.stateChanged.connect(lambda state: self.showAgainAction(state)) self._showAgainCheckBox.setChecked(False) # Buttons self._noButton = QtWidgets.QPushButton('Cancel') self._noButton.setMaximumWidth(125) self._noButton.clicked.connect(self.noAction) self._showMoreButton = QtWidgets.QPushButton('Show Details') self._showMoreButton.setMaximumWidth(125) self._showMoreButton.clicked.connect(self.showDetails) self._okButton = QtWidgets.QPushButton('OK') self._okButton.setDefault(True) self._okButton.setMaximumWidth(125) self._okButton.clicked.connect(self.okAction) self._dialogGridLayout = QtWidgets.QGridLayout() # self._dialogGridLayout.setSpacing(0) self._dialogGridLayout.addWidget(self._iconLabel, 1, 0, 2, 1) self._dialogGridLayout.setAlignment(self._iconLabel, QtCore.Qt.AlignTop) self._dialogGridLayout.addWidget(self._titleLabel, 1, 1, 1, -1) self._dialogGridLayout.addWidget(self._messageLabel, 2, 1, 1, -1) self._dialogGridLayout.addWidget(self._showAgainCheckBox, 6, 1, 1, -1) self._dialogGridLayout.addWidget(self._showMoreButton, 7, 1, 1, 1) self._dialogGridLayout.addWidget(self._noButton, 7, 3, 1, 1) self._dialogGridLayout.addWidget(self._okButton, 7, 4, 1, 1) self.setLayout(self._dialogGridLayout) # Style error dialog if utils.IS_WINDOWS: self.setWindowIcon(QtGui.QIcon(utils.resource_path('./assets/icon.png'))) if not utils.IS_MAC: self.setWindowTitle('Quaver') self.setWindowModality(QtCore.Qt.ApplicationModal) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) flags = self.windowFlags() | QtCore.Qt.CustomizeWindowHint | QtCore.Qt.WindowTitleHint flags &= ~(QtCore.Qt.WindowMinMaxButtonsHint | QtCore.Qt.WindowCloseButtonHint | QtCore.Qt.WindowFullscreenButtonHint) self.setWindowFlags(flags) def setIcon(self, url): icon = QtGui.QPixmap(utils.resource_path(url)) icon.setDevicePixelRatio(self.devicePixelRatio()) self._iconWidth = self.devicePixelRatio() * self._iconLabel.width() - 10 self._iconHeight = self.devicePixelRatio() * self._iconLabel.height() - 10 self._iconLabel.setPixmap(icon.scaled(self._iconWidth, self._iconHeight, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)) def setTitle(self, title): self._titleLabel.setText(title) def setMessage(self, message): self._messageLabel.setText(message) def showAgainAction(self, state): raise NotImplementedError('Must implement this in your child class!') def noAction(self): raise NotImplementedError('Must implement this in your child class!') def showDetails(self): raise NotImplementedError('Must implement this in your child class!') def hideDetails(self): raise NotImplementedError('Must implement this in your child class!') def okAction(self): raise NotImplementedError('Must implement this in your child class!')