def restoreStateAndGeometry(self): saved = Settings.value(Settings.SAVESTATES_DIALOG_GEOMETRY) if saved: self.restoreGeometry(saved) saved = Settings.value(Settings.SAVESTATES_DIALOG_TABLE_HEADER_STATE) if saved: self.uiSavestatesTblv.horizontalHeader().restoreState(saved)
def __init__(self, *args, **kwargs): super(EmoticonDialog, self).__init__(*args, **kwargs) saved = Settings.value(Settings.EMOTICON_DIALOG_GEOMETRY) if saved: self.restoreGeometry(saved) self._value = '' flowLayout = FlowLayout(self) customEmoticons = Settings.value(Settings.CUSTOM_EMOTICONS) if customEmoticons: customEmoticons = filter(None, [ line.strip() for line in customEmoticons.split("\n") if 0 < len(line) < 64 ]) else: customEmoticons = [] for emoticon in customEmoticons + _emoticons.split("\n"): act = QtGui.QAction(emoticon, self) act.triggered.connect(self.onActionTriggered) btn = QtGui.QToolButton(self) btn.setDefaultAction(act) flowLayout.addWidget(btn) self.setLayout(flowLayout) self.setWindowTitle("Insert emoticon") self.accepted.connect(self.saveGeometrySettings) self.finished.connect(self.saveGeometrySettings) self.rejected.connect(self.saveGeometrySettings)
def setupMenuSettings(self): self.uiMuteChallengeSoundAct.toggled.connect(self.__class__.toggleSound) self.uiMuteNotifySoundAct.toggled.connect(self.__class__.toggleNotifySound) self.uiFontAct.triggered.connect(self.changeFont) self.setupMenuTheme() self.setupMenuSmoothing() self.setupMenuChallengeSound() self.uiCustomEmoticonsAct.triggered.connect(self.setCustomEmoticons) #self.uiLocateGgpofbaAct.triggered.connect(self.locateGGPOFBA) self.uiLocateROMsAct.triggered.connect(self.locateROMsDir) #self.uiLocateUnsupportedSavestatesDirAct.triggered.connect(self.locateUnsupportedSavestatesDirAct) self.uiLocateCustomChallengeSoundAct.triggered.connect(self.locateCustomChallengeSound) #if GeoIP2Reader: # self.uiLocateGeommdbAct.triggered.connect(self.locateGeoMMDB) #else: # self.uiLocateGeommdbAct.setVisible(False) self.uiNotifyPlayerStateChangeAct.toggled.connect(self.__class__.toggleNotifyPlayerStateChange) self.uiShowCountryFlagInChatAct.toggled.connect(self.__class__.toggleShowCountryFlagInChat) self.uiShowTimestampInChatAct.toggled.connect(self.__class__.toggleShowTimestampInChatAct) #self.uiDisableAutoAnnounceAct.toggled.connect(self.__class__.toggleDisableAutoAnnounceUnsupported) self.uiDisableAutoColorNicks.toggled.connect(self.__class__.toggleDisableAutoColorNicks) self.uiHideGamesWithoutRomAct.toggled.connect(self.toggleHideGamesWithoutRomAct) self.uiFilterFavoriteLobbies.toggled.connect(self.toggleFilterFavoriteLobbies) if Settings.value(Settings.DEBUG_LOG): self.uiDebugLogAct.setChecked(True) if Settings.value(Settings.USER_LOG_CHAT): self.uiLogChatAct.setChecked(True) if Settings.value(Settings.USER_LOG_PLAYHISTORY): self.uiLogPlayHistoryAct.setChecked(True) self.uiDebugLogAct.triggered.connect(self.__class__.logdebugTriggered) self.uiLogChatAct.triggered.connect(self.__class__.loguserChatTriggered) self.uiLogPlayHistoryAct.triggered.connect(self.__class__.loguserPlayHistoryTriggered)
def __init__(self, parent=None): super(LoginDialog, self).__init__(parent) # ggpo.gui.loadUi(__file__, self) if IS_WINDOWS: download_url='http://www.fightcade.com/download/windows' if IS_OSX: download_url='http://www.fightcade.com/download/osx' if IS_LINUX: download_url='http://www.fightcade.com/download/linux' self.setupUi(self) self.uiNewVersionLink.clicked.connect( lambda: openURL(download_url)) self.uiNewVersionLink.setVisible(False) self.uiRegisterLink.setVisible(False) versionLabel = 'v' + copyright.versionString() self.uiVersionLbl.setText(versionLabel) self.controller = None if Settings.value(Settings.SAVE_USERNAME_PASSWORD): self.uiSavePasswordChk.setChecked(True) username = Settings.value(Settings.USERNAME) password = Settings.value(Settings.PASSWORD) if username: self.uiUsernameLine.setText(username) if password: self.uiPasswordLine.setText(base64.decodestring(password)) if not username and not password: self.uiRegisterLink.setVisible(True) self.uiSavePasswordChk.toggled.connect(self.savePassword) self.uiUsernameLine.returnPressed.connect(self.login) self.uiPasswordLine.returnPressed.connect(self.login) self.uiLoginBtn.clicked.connect(self.login) self.uiRegisterLink.clicked.connect( lambda: openURL('http://www.fightcade.com/#register'))
def __init__(self, QWidget_parent=None): super(GGPOWindow, self).__init__(QWidget_parent) self.setupUi(self) self.controller = None self.channels = {} self.expectFirstChannelResponse = True self.lastSplitterExpandedSizes = [] self.lastStateChangeMsg = '' self.uiChatInputEdit.returnPressed.connect(self.returnPressed) self.setupMenu() self.uiEmoticonTbtn.setDefaultAction(self.uiEmoticonAct) self.uiEmoticonTbtn.setText(':)') self.addSplitterHandleToggleButton() self.uiChatHistoryTxtB.anchorClicked.connect(self.onAnchorClicked) self.autoAnnounceUnsupportedTime = 0 self.refreshChannelsListTime = time.time() self.refreshListUsersTime = time.time() self.savestatesChecked = False if Settings.value( Settings.CHANNELS_FAVORITES ) != None: # default value if it's not present in config file self.favorites = Settings.value(Settings.CHANNELS_FAVORITES) else: self.favorites = '' self.showfavorites = False if Settings.value(Settings.FILTER_FAVORITES): self.showfavorites = True self.hidemissing = False if Settings.value(Settings.HIDE_GAMES_WITHOUT_ROM): self.hidemissing = True self.uiChannelsTree.itemDoubleClicked.connect( self.AddRemoveFavorites) # call to double click handler
def __init__(self, parent=None): super(LoginDialog, self).__init__(parent) # ggpo.gui.loadUi(__file__, self) if IS_WINDOWS: download_url = 'http://www.fightcade.com/download/windows' if IS_OSX: download_url = 'http://www.fightcade.com/download/osx' if IS_LINUX: download_url = 'http://www.fightcade.com/download/linux' self.setupUi(self) self.uiNewVersionLink.clicked.connect(lambda: openURL(download_url)) self.uiNewVersionLink.setVisible(False) self.uiRegisterLink.setVisible(False) versionLabel = 'v' + copyright.versionString() self.uiVersionLbl.setText(versionLabel) self.controller = None if Settings.value(Settings.SAVE_USERNAME_PASSWORD): self.uiSavePasswordChk.setChecked(True) username = Settings.value(Settings.USERNAME) password = Settings.value(Settings.PASSWORD) if username: self.uiUsernameLine.setText(username) if password: self.uiPasswordLine.setText(base64.decodestring(password)) if not username and not password: self.uiRegisterLink.setVisible(True) self.uiSavePasswordChk.toggled.connect(self.savePassword) self.uiUsernameLine.returnPressed.connect(self.login) self.uiPasswordLine.returnPressed.connect(self.login) self.uiLoginBtn.clicked.connect(self.login) self.uiRegisterLink.clicked.connect( lambda: openURL('http://www.fightcade.com/#register'))
def __init__(self, parent=None): super(LoginDialog, self).__init__(parent) # ggpo.gui.loadUi(__file__, self) self.setupUi(self) self.uiNewVersionLink.clicked.connect( lambda: openURL('https://github.com/doctorguile/pyqtggpo/releases')) self.uiNewVersionLink.setVisible(False) versionLabel = 'v' + copyright.versionString() self.uiVersionLbl.setText(versionLabel) self.controller = None if Settings.value(Settings.SAVE_USERNAME_PASSWORD): self.uiSavePasswordChk.setChecked(True) if Settings.value(Settings.AUTOLOGIN): self.uiAutologinChk.setChecked(True) username = Settings.value(Settings.USERNAME) password = Settings.value(Settings.PASSWORD) serverAddress = Settings.value(Settings.SERVER_ADDRESS) or 'ggpo.net' if username: self.uiUsernameLine.setText(username) if password: self.uiPasswordLine.setText(base64.decodestring(password)) self.uiServerLine.setText(serverAddress) self.uiSavePasswordChk.toggled.connect(self.savePassword) self.uiUsernameLine.returnPressed.connect(self.login) self.uiPasswordLine.returnPressed.connect(self.login) self.uiServerLine.returnPressed.connect(self.login) self.uiLoginBtn.clicked.connect(self.login) self.uiRegisterLink.clicked.connect( lambda: openURL('http://ggpo.net/forums/ucp.php?mode=register'))
def setupMenuSettings(self): self.uiMuteChallengeSoundAct.toggled.connect(self.__class__.toggleSound) self.uiFontAct.triggered.connect(self.changeFont) self.setupMenuTheme() self.setupMenuSmoothing() self.uiCustomEmoticonsAct.triggered.connect(self.setCustomEmoticons) self.uiLocateGgpofbaAct.triggered.connect(self.locateGGPOFBA) if IS_WINDOWS: self.uiLocateWineAct.setVisible(False) else: self.uiLocateWineAct.triggered.connect(self.locateWine) self.uiLocateUnsupportedSavestatesDirAct.triggered.connect(self.locateUnsupportedSavestatesDirAct) self.uiLocateCustomChallengeSoundAct.triggered.connect(self.locateCustomChallengeSound) if GeoIP2Reader: self.uiLocateGeommdbAct.triggered.connect(self.locateGeoMMDB) else: self.uiLocateGeommdbAct.setVisible(False) self.uiNotifyPlayerStateChangeAct.toggled.connect(self.__class__.toggleNotifyPlayerStateChange) self.uiShowCountryFlagInChatAct.toggled.connect(self.__class__.toggleShowCountryFlagInChat) self.uiShowTimestampInChatAct.toggled.connect(self.__class__.toggleShowTimestampInChatAct) self.uiDisableAutoAnnounceAct.toggled.connect(self.__class__.toggleDisableAutoAnnounceUnsupported) if Settings.value(Settings.DEBUG_LOG): self.uiDebugLogAct.setChecked(True) if Settings.value(Settings.USER_LOG_CHAT): self.uiLogChatAct.setChecked(True) if Settings.value(Settings.USER_LOG_PLAYHISTORY): self.uiLogPlayHistoryAct.setChecked(True) self.uiDebugLogAct.triggered.connect(self.__class__.logdebugTriggered) self.uiLogChatAct.triggered.connect(self.__class__.loguserChatTriggered) self.uiLogPlayHistoryAct.triggered.connect(self.__class__.loguserPlayHistoryTriggered)
def restoreStateAndGeometry(self): saved = Settings.value(Settings.SAVESTATES_DIALOG_GEOMETRY) if saved: self.restoreGeometry(saved) saved = Settings.value(Settings.SAVESTATES_DIALOG_TABLE_HEADER_STATE) if saved: self.uiSavestatesTblv.horizontalHeader().restoreState(saved)
def __init__(self, QWidget_parent=None): super(GGPOWindow, self).__init__(QWidget_parent) self.setupUi(self) self.controller = None self.channels = {} self.expectFirstChannelResponse = True self.lastSplitterExpandedSizes = [] self.lastStateChangeMsg = '' self.uiChatInputEdit.returnPressed.connect(self.returnPressed) self.setupMenu() self.uiEmoticonTbtn.setDefaultAction(self.uiEmoticonAct) self.uiEmoticonTbtn.setText(':)') self.addSplitterHandleToggleButton() self.uiChatHistoryTxtB.anchorClicked.connect(self.onAnchorClicked) self.autoAnnounceUnsupportedTime = 0 self.refreshChannelsListTime = time.time() self.refreshListUsersTime = time.time() self.savestatesChecked = False if Settings.value(Settings.CHANNELS_FAVORITES) != None: # default value if it's not present in config file self.favorites = Settings.value(Settings.CHANNELS_FAVORITES) else: self.favorites = '' self.showfavorites=False if Settings.value(Settings.FILTER_FAVORITES): self.showfavorites = True self.hidemissing = False if Settings.value(Settings.HIDE_GAMES_WITHOUT_ROM): self.hidemissing = True self.uiChannelsTree.itemDoubleClicked.connect(self.AddRemoveFavorites) # call to double click handler
def __init__(self, *args, **kwargs): super(EmoticonDialog, self).__init__(*args, **kwargs) saved = Settings.value(Settings.EMOTICON_DIALOG_GEOMETRY) if saved: self.restoreGeometry(saved) self._value = '' flowLayout = FlowLayout(self) customEmoticons = Settings.value(Settings.CUSTOM_EMOTICONS) if customEmoticons: customEmoticons = filter(None, [line.strip() for line in customEmoticons.split("\n") if 0 < len(line) < 64]) else: customEmoticons = [] for emoticon in customEmoticons + _emoticons.split("\n"): act = QtGui.QAction(emoticon, self) act.triggered.connect(self.onActionTriggered) btn = QtGui.QToolButton(self) btn.setDefaultAction(act) flowLayout.addWidget(btn) self.setLayout(flowLayout) self.setWindowTitle("Insert emoticon") self.accepted.connect(self.saveGeometrySettings) self.finished.connect(self.saveGeometrySettings) self.rejected.connect(self.saveGeometrySettings)
def wavfile(): filename = Settings.value(Settings.CUSTOM_CHALLENGE_SOUND_LOCATION) if filename and os.path.isfile(filename): return filename fba = Settings.value(Settings.GGPOFBA_LOCATION) if fba: filename = os.path.join(os.path.dirname(fba), "assets", "challenger-comes.wav") if os.path.isfile(filename): return filename
def wavfile(): filename = Settings.value(Settings.CUSTOM_CHALLENGE_SOUND_LOCATION) if filename and os.path.isfile(filename): return filename fba = Settings.value(Settings.GGPOFBA_LOCATION) if fba: filename = os.path.join(os.path.dirname(fba), "assets", "challenger-comes.wav") if os.path.isfile(filename): return filename
def runFBA(self, quark): if not self.checkRom(): return if not self.fba: self.sigStatusMessage.emit( "Please configure Setting > Locate ggpofba.exe") return wine = '' args = [] fba = self.fba if IS_WINDOWS: if Settings.value(Settings.SERVER_ADDRESS) == 'ggpo.net': ngexe = os.path.join(os.path.dirname(fba), 'ggpofba-ng.exe') if os.path.exists(ngexe): fba = ngexe args = [fba, quark, '-w'] else: wine = findWine() if Settings.value(Settings.SERVER_ADDRESS) != 'ggpo.net': fba = fba.replace('.exe', '.py') if IS_LINUX: args = [ packagePathJoin('ggpo', 'scripts', 'ggpofba.sh'), fba, quark ] else: args = [fba, quark] else: if not wine: self.sigStatusMessage.emit( "Please configure Setting > Locate wine") return if IS_LINUX: args = [ packagePathJoin('ggpo', 'scripts', 'ggpofba.sh'), wine, fba, quark ] else: args = [wine, fba, quark] logdebug().info(" ".join(args)) try: # starting python from cmd.exe and redirect stderr and we got # python WindowsError(6, 'The handle is invalid') # apparently it's still not fixed if IS_WINDOWS: Popen(args) else: devnull = open(os.devnull, 'w') Popen(args, stdout=devnull, stderr=devnull) devnull.close() except OSError, ex: self.sigStatusMessage.emit("Error executing " + " ".join(args) + "\n" + repr(ex))
def restoreStateAndGeometry(self): saved = Settings.value(Settings.WINDOW_GEOMETRY) if saved: self.restoreGeometry(saved) saved = Settings.value(Settings.WINDOW_STATE) if saved: self.restoreState(saved) saved = Settings.value(Settings.SPLITTER_STATE) if saved: self.uiSplitter.restoreState(saved) saved = Settings.value(Settings.TABLE_HEADER_STATE) if saved: self.uiPlayersTableV.horizontalHeader().restoreState(saved)
def main(argv=None): app = None started = False # create the application if necessary if not QtGui.QApplication.instance(): app = QtGui.QApplication(argv) app.setQuitOnLastWindowClosed(True) app.setOrganizationName("FightCade") QtCore.QCoreApplication.setApplicationName("FightCade") ColorTheme.saveDefaultStyle() if not Settings.value(Settings.COLORTHEME) or Settings.value( Settings.COLORTHEME) == 'fightcade' or Settings.value( Settings.COLORTHEME) == 'ggpong': ColorTheme.setGNGTheme(True) controller = Controller() thread = QtCore.QThread() controller.moveToThread(thread) thread.started.connect(controller.selectLoop) thread.start() def loggedIn(): if started == False: window = GGPOWindow() window.setWindowIcon(QtGui.QIcon(':/assets/icon-128.png')) window.setController(controller) window.restorePreference() controller.sendListChannels() window.show() window.raise_() window.activateWindow() UDP = False port = 6009 while True: UDP = controller.connectUdp(port) port = port - 1 if (UDP == True or port < 6006): break logindialog = LoginDialog() logindialog.setController(controller) logindialog.accepted.connect(loggedIn) logindialog.rejected.connect(sys.exit) logindialog.exec_() logindialog.raise_() logindialog.activateWindow() started = True return app.exec_()
def main(argv=None): app = None # create the application if necessary if not QtGui.QApplication.instance(): app = QtGui.QApplication(argv) app.setQuitOnLastWindowClosed(True) app.setOrganizationName("FightCade") QtCore.QCoreApplication.setApplicationName("FightCade") ColorTheme.saveDefaultStyle() if ( not Settings.value(Settings.COLORTHEME) or Settings.value(Settings.COLORTHEME) == "fightcade" or Settings.value(Settings.COLORTHEME) == "ggpong" ): ColorTheme.setGNGTheme(True) controller = Controller() thread = QtCore.QThread() controller.moveToThread(thread) thread.started.connect(controller.selectLoop) thread.start() def loggedIn(): UDP = False port = 6009 while True: UDP = controller.connectUdp(port) port = port - 1 if UDP == True or port < 6006: break window = GGPOWindow() window.setWindowIcon(QtGui.QIcon(":/assets/icon-128.png")) window.setController(controller) window.restorePreference() controller.sendListChannels() window.show() window.raise_() window.activateWindow() logindialog = LoginDialog() logindialog.setController(controller) logindialog.accepted.connect(loggedIn) logindialog.rejected.connect(sys.exit) logindialog.exec_() logindialog.raise_() logindialog.activateWindow() return app.exec_()
def setupROMsDir(self): romdir = Settings.value(Settings.ROMS_DIR) if not romdir: return #on linux & MAC, symlink the ROMs folder to avoid configuring FBA if not IS_WINDOWS: fbaRomPath = os.path.join( os.path.abspath(os.path.dirname(sys.argv[0])), "ROMs") # remove it if it's a link or an empty dir if os.path.islink(fbaRomPath): os.remove(fbaRomPath) if os.path.isdir(fbaRomPath) and not os.listdir(fbaRomPath): os.rmdir(fbaRomPath) if not os.path.exists(fbaRomPath): os.symlink(romdir, fbaRomPath) # on windows, update fba's ini file with the new location if IS_WINDOWS: # make sure FBA is not running, otherwise we can't modify the config file self.killEmulator() fbaini = os.path.join( os.path.abspath(os.path.dirname(sys.argv[0])), 'config', 'ggpofba-ng.ini') if fbaini and os.path.isfile(fbaini): for line in fileinput.input(fbaini, inplace=True, backup='.bak'): new = "szAppRomPaths[7] " + str( os.path.join(romdir.upper(), '') + "\\") sys.stdout.write(re.sub("szAppRomPaths\[7\].*", new, line)) fileinput.close()
def sendJoinChannelRequest(self, channel=None): if channel: self.channel = channel Settings.setValue(Settings.SELECTED_CHANNEL, channel) if channel in self.channels: if channel != 'lobby': self.rom = self.channels[channel]['rom'] else: self.rom = '' else: logdebug().error("Invalid channel {}".format(channel)) if (int(self.channelport) != int(self.channels[channel]['port'])): self.switchingServer = True self.channelport = int(self.channels[channel]['port']) Settings.setValue(Settings.PORT, self.channelport) self.tcpSock.close() self.sequence = 0x1 self.connectTcp() self.sendWelcome() self.sendAuth(self.username, self.password) if Settings.value(Settings.AWAY): self.sendToggleAFK(1) self.sendAndRemember(Protocol.JOIN_CHANNEL, Protocol.packTLV(self.channel))
def AddRemoveFavorites(self): it = self.uiChannelsTree.currentItem().text(1) bold_font = QtGui.QFont() bold_font.setBold(True) not_bold_font = QtGui.QFont() not_bold_font.setBold(False) if not ("," + self.channels[it] + "," in self.favorites): # Add favorite self.favorites = self.favorites + "," + self.channels[it] + "," self.uiChannelsTree.currentItem().setFont(1, bold_font) else: # Remove favorite self.favorites = self.favorites.replace( "," + self.channels[it] + ",", ",") self.uiChannelsTree.currentItem().setFont(1, not_bold_font) if (not self.expectFirstChannelResponse) and Settings.value( Settings.FILTER_FAVORITES ): # Update list when removing from the filtered list self.expectFirstChannelResponse = True self.controller.sigChannelsLoaded.emit() self.uiChannelsTree.setCurrentItem(None) pattern1 = re.compile(",*,") # trimming unwanted commas self.favorites = pattern1.sub(",", self.favorites) if self.favorites == ",": # if it's only a comma after RegEx, then clear the favorites self.favorites = "" Settings.setValue(Settings.CHANNELS_FAVORITES, self.favorites)
def setupROMsDir(self): romdir=Settings.value(Settings.ROMS_DIR) if not romdir: return #on linux & MAC, symlink the ROMs folder to avoid configuring FBA if not IS_WINDOWS: fbaRomPath = os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), "ROMs") # remove it if it's a link or an empty dir if os.path.islink(fbaRomPath): os.remove(fbaRomPath) if os.path.isdir(fbaRomPath) and not os.listdir(fbaRomPath): os.rmdir(fbaRomPath) if not os.path.exists(fbaRomPath): os.symlink(romdir, fbaRomPath) # on windows, update fba's ini file with the new location if IS_WINDOWS: # make sure FBA is not running, otherwise we can't modify the config file self.killEmulator() fbaini = os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), 'config', 'ggpofba-ng.ini') if fbaini and os.path.isfile(fbaini): for line in fileinput.input(fbaini, inplace=True, backup='.bak'): new="szAppRomPaths[7] "+str(os.path.join(romdir.upper(),'')+"\\") sys.stdout.write(re.sub("szAppRomPaths\[7\].*", new, line)) fileinput.close()
def parseStateChangesResponse(self, data): count, data = Protocol.extractInt(data) while count > 0 and len(data) >= 4: state, p1, p2, playerinfo, data = self.__class__.extractStateChangesResponse(data) if state == PlayerStates.PLAYING: self.parsePlayerStartGameResponse(p1, p2, playerinfo) if self.username == p1: self.playingagainst = p2 if self.username == p2: self.playingagainst = p1 if Settings.value(Settings.USER_LOG_PLAYHISTORY) and self.username in [p1, p2]: loguser().info(u"[IN A GAME] {} vs {}".format(p1, p2)) elif state == PlayerStates.AVAILABLE: self.parsePlayerAvailableResponse(p1, playerinfo) if self.playingagainst == p1: self.playingagainst = '' self.killEmulator() elif state == PlayerStates.AFK: self.parsePlayerAFKResponse(p1, playerinfo) if self.playingagainst == p1: self.playingagainst = '' self.killEmulator() elif state == PlayerStates.QUIT: self.parsePlayerLeftResponse(p1) else: logdebug().error( "Unknown state change payload state: {} {}".format(state, repr(data))) if state == PlayerStates.PLAYING: msg = p1 + ' ' + PlayerStates.codeToString(state) + ' ' + p2 else: msg = p1 + ' ' + PlayerStates.codeToString(state) logdebug().info(msg) count -= 1
def __init__(self, *args, **kwargs): super(CustomEmoticonsDialog, self).__init__(*args, **kwargs) self.setupUi(self) customEmoticons = Settings.value(Settings.CUSTOM_EMOTICONS) if customEmoticons: self.uiEmoticonTextEdit.setPlainText(customEmoticons) self.accepted.connect(self.onAccepted)
def onChatReceived(self, name, txt): if name=="System" and "GAME: " in txt and Settings.value(Settings.HIDE_INGAME_CHAT): return if name=="System" and "GAME: " in txt and not Settings.value(Settings.HIDE_INGAME_CHAT): txt = re.sub(r'<System> ', r'', txt) prefix = self.controller.getPlayerPrefix(name, Settings.value(Settings.SHOW_COUNTRY_FLAG_IN_CHAT)) if (self.controller.username+" ".lower() in txt.lower() or " "+self.controller.username.lower() in txt.lower() or txt.lower()==self.controller.username.lower()): txt = cgi.escape(txt.strip()).replace(self.controller.username, "<b>{}</b>".format(self.controller.username)) ggpo.common.sound.notify() else: txt = cgi.escape(txt.strip()) urls = findURLs(txt) chat = prefix + txt if urls: chat = prefix + replaceURLs(txt) self.appendChat(replaceReplayID(chat))
def loggerInit(): debuglog = logging.getLogger('GGPODebug') debuglog.setLevel(logging.INFO) fh = logging.handlers.RotatingFileHandler( os.path.join(expanduser("~"), 'fightcade-debug.log'), mode='a', maxBytes=500000, backupCount=10) if Settings.value(Settings.DEBUG_LOG): fh.setLevel(logging.INFO) else: fh.setLevel(logging.ERROR) ch = logging.StreamHandler() ch.setLevel(logging.ERROR) debuglog.addHandler(fh) debuglog.addHandler(ch) def handle_exception(exc_type, exc_value, exc_traceback): if issubclass(exc_type, KeyboardInterrupt): sys.__excepthook__(exc_type, exc_value, exc_traceback) return debuglog.error("<Uncaught exception>", exc_info=(exc_type, exc_value, exc_traceback)) sys.excepthook = handle_exception if __name__ == "__main__": raise RuntimeError("Test unhandled") userlog = logging.getLogger('GGPOUser') userlog.setLevel(logging.INFO) fh = logging.handlers.RotatingFileHandler( os.path.join(expanduser("~"), 'fightcade.log'), mode='a', maxBytes=500000, backupCount=10) fh.setLevel(logging.INFO) formatter = logging.Formatter('%(asctime)s - %(message)s', "%Y-%m-%d %H:%M") fh.setFormatter(formatter) userlog.addHandler(fh)
def loggerInit(): debuglog = logging.getLogger('GGPODebug') debuglog.setLevel(logging.INFO) fh = logging.handlers.RotatingFileHandler( os.path.join(expanduser("~"), 'fightcade-debug.log'), mode='a', maxBytes=500000, backupCount=10) if Settings.value(Settings.DEBUG_LOG): fh.setLevel(logging.INFO) else: fh.setLevel(logging.ERROR) ch = logging.StreamHandler() ch.setLevel(logging.ERROR) debuglog.addHandler(fh) debuglog.addHandler(ch) def handle_exception(exc_type, exc_value, exc_traceback): if issubclass(exc_type, KeyboardInterrupt): sys.__excepthook__(exc_type, exc_value, exc_traceback) return debuglog.error("<Uncaught exception>", exc_info=(exc_type, exc_value, exc_traceback)) sys.excepthook = handle_exception if __name__ == "__main__": raise RuntimeError("Test unhandled") userlog = logging.getLogger('GGPOUser') userlog.setLevel(logging.INFO) fh = logging.handlers.RotatingFileHandler( os.path.join(expanduser("~"), 'fightcade.log'), mode='a', maxBytes=500000, backupCount=10) fh.setLevel(logging.INFO) formatter = logging.Formatter('%(asctime)s - %(message)s', "%Y-%m-%d %H:%M") fh.setFormatter(formatter) userlog.addHandler(fh)
def __init__(self, *args, **kwargs): super(CustomEmoticonsDialog, self).__init__(*args, **kwargs) self.setupUi(self) customEmoticons = Settings.value(Settings.CUSTOM_EMOTICONS) if customEmoticons: self.uiEmoticonTextEdit.setPlainText(customEmoticons) self.accepted.connect(self.onAccepted)
def restorePreference(self): theme = Settings.value(Settings.COLORTHEME) if theme: if theme == 'darkorange': self.uiDarkThemeAct.setChecked(True) elif theme == 'custom': fname = Settings.value(Settings.CUSTOM_THEME_FILENAME) self.setCustomQssfile(fname) else: cleanname = self.buildInStyleToActionName(theme) if hasattr(self, cleanname): getattr(self, cleanname).setChecked(True) smooth = Settings.value(Settings.SMOOTHING) if smooth: cleanname = self.buildInSmoothingToActionName(smooth) if hasattr(self, cleanname): getattr(self, cleanname).setChecked(True) if Settings.value(Settings.MUTE_CHALLENGE_SOUND): self.uiMuteChallengeSoundAct.setChecked(True) if Settings.value(Settings.NOTIFY_PLAYER_STATE_CHANGE): self.uiNotifyPlayerStateChangeAct.setChecked(True) if Settings.value(Settings.SHOW_COUNTRY_FLAG_IN_CHAT): self.uiShowCountryFlagInChatAct.setChecked(True) if Settings.value(Settings.SHOW_TIMESTAMP_IN_CHAT): self.uiShowTimestampInChatAct.setChecked(True) fontsetting = Settings.pythonValue(Settings.CHAT_HISTORY_FONT) if fontsetting: self.uiChatHistoryTxtB.setFont(QtGui.QFont(*fontsetting)) self.restoreStateAndGeometry()
def runFBA(self, quark): if not self.checkRom(): return if not self.fba: self.sigStatusMessage.emit("Please configure Setting > Locate ggpofba.exe") return wine = '' args = [] fba = self.fba if IS_WINDOWS: if Settings.value(Settings.SERVER_ADDRESS) == 'ggpo.net': ngexe = os.path.join(os.path.dirname(fba), 'ggpofba-ng.exe') if os.path.exists(ngexe): fba = ngexe args = [fba, quark, '-w'] else: wine = findWine() if Settings.value(Settings.SERVER_ADDRESS) != 'ggpo.net': fba = fba.replace('.exe', '.py') if IS_LINUX: args = [packagePathJoin('ggpo', 'scripts', 'ggpofba.sh'), fba, quark] else: args = [fba, quark] else: if not wine: self.sigStatusMessage.emit("Please configure Setting > Locate wine") return if IS_LINUX: args = [packagePathJoin('ggpo', 'scripts', 'ggpofba.sh'), wine, fba, quark] else: args = [wine, fba, quark] logdebug().info(" ".join(args)) try: # starting python from cmd.exe and redirect stderr and we got # python WindowsError(6, 'The handle is invalid') # apparently it's still not fixed if IS_WINDOWS: Popen(args) else: devnull = open(os.devnull, 'w') Popen(args, stdout=devnull, stderr=devnull) devnull.close() except OSError, ex: self.sigStatusMessage.emit("Error executing " + " ".join(args) + "\n" + repr(ex))
def onChatReceived(self, name, txt): prefix = self.controller.getPlayerPrefix(name, Settings.value(Settings.SHOW_COUNTRY_FLAG_IN_CHAT)) txt = cgi.escape(txt.strip()).replace(self.controller.username, "<b>{}</b>".format(self.controller.username)) urls = findURLs(txt) chat = prefix + txt if urls: for url in urls: chat += " <a href='" + url + "'><font color=green>link</font></a>" self.appendChat(chat)
def onPlayerStateChange(self, name, state): if Settings.value(Settings.NOTIFY_PLAYER_STATE_CHANGE): if state == PlayerStates.QUIT: self.notifyStateChange(name, " left") elif state == PlayerStates.AVAILABLE: self.notifyStateChange(name, " becomes available") elif state == PlayerStates.PLAYING: self.notifyStateChange(name, " is in a game") self.updateStatusBar()
def getPlayerColor(self, name): if name == self.username: return '#ff0000' elif name in self.players: if Settings.value(Settings.DISABLE_AUTOCOLOR_NICKS): return '#034456' if hasattr(self.players[name], 'id'): return ColorTheme.getPlayerColor(self.players[name].id) return '#808080'
def getPlayerColor(self, name): if name == self.username: return '#ff0000' elif name in self.players: if Settings.value(Settings.DISABLE_AUTOCOLOR_NICKS): return '#034456' if hasattr(self.players[name], 'id'): return ColorTheme.getPlayerColor(self.players[name].id) return '#808080'
def findGeoIPDB(): dbs = [Settings.value(Settings.GEOIP2DB_LOCATION), os.path.join(os.getcwd(), 'GeoLite2-City.mmdb'), packagePathJoin('GeoLite2-City.mmdb'), os.path.join(os.getcwd(), 'GeoLite2-Country.mmdb'), packagePathJoin('GeoLite2-Country.mmdb')] for db in dbs: if db and os.path.isfile(db): return db
def setupMenuSettings(self): self.uiMuteChallengeSoundAct.toggled.connect( self.__class__.toggleSound) self.uiMuteNotifySoundAct.toggled.connect( self.__class__.toggleNotifySound) self.uiFontAct.triggered.connect(self.changeFont) self.setupMenuTheme() self.setupMenuSmoothing() self.setupMenuChallengeSound() self.uiCustomEmoticonsAct.triggered.connect(self.setCustomEmoticons) #self.uiLocateGgpofbaAct.triggered.connect(self.locateGGPOFBA) self.uiLocateROMsAct.triggered.connect(self.locateROMsDir) #self.uiLocateUnsupportedSavestatesDirAct.triggered.connect(self.locateUnsupportedSavestatesDirAct) self.uiLocateCustomChallengeSoundAct.triggered.connect( self.locateCustomChallengeSound) #if GeoIP2Reader: # self.uiLocateGeommdbAct.triggered.connect(self.locateGeoMMDB) #else: # self.uiLocateGeommdbAct.setVisible(False) self.uiNotifyPlayerStateChangeAct.toggled.connect( self.__class__.toggleNotifyPlayerStateChange) self.uiShowCountryFlagInChatAct.toggled.connect( self.__class__.toggleShowCountryFlagInChat) self.uiShowTimestampInChatAct.toggled.connect( self.__class__.toggleShowTimestampInChatAct) #self.uiDisableAutoAnnounceAct.toggled.connect(self.__class__.toggleDisableAutoAnnounceUnsupported) self.uiDisableAutoColorNicks.toggled.connect( self.__class__.toggleDisableAutoColorNicks) self.uiHideGamesWithoutRomAct.toggled.connect( self.toggleHideGamesWithoutRomAct) self.uiFilterFavoriteLobbies.toggled.connect( self.toggleFilterFavoriteLobbies) if Settings.value(Settings.DEBUG_LOG): self.uiDebugLogAct.setChecked(True) if Settings.value(Settings.USER_LOG_CHAT): self.uiLogChatAct.setChecked(True) if Settings.value(Settings.USER_LOG_PLAYHISTORY): self.uiLogPlayHistoryAct.setChecked(True) self.uiDebugLogAct.triggered.connect(self.__class__.logdebugTriggered) self.uiLogChatAct.triggered.connect( self.__class__.loguserChatTriggered) self.uiLogPlayHistoryAct.triggered.connect( self.__class__.loguserPlayHistoryTriggered)
def restoreStateAndGeometry(self): saved = Settings.value(Settings.WINDOW_GEOMETRY) if saved: self.restoreGeometry(saved) saved = Settings.value(Settings.WINDOW_STATE) if saved: self.restoreState(saved) saved = Settings.value(Settings.SPLITTER_STATE) if saved: self.uiSplitter.restoreState(saved) saved = Settings.value(Settings.TABLE_HEADER_STATE) if saved: self.uiPlayersTableV.horizontalHeader().restoreState(saved) saved = Settings.value(Settings.CHANNELS_HEADER_STATE) if saved: self.uiChannelsTree.header().restoreState(saved) else: self.uiChannelsTree.setColumnWidth(0, 50) self.uiChannelsTree.setColumnWidth(1, 300)
def play(self): if not Settings.value(Settings.MUTE_CHALLENGE_SOUND): filename = self.wavfile() if filename: #noinspection PyBroadException try: # winsound can only play one clip at a time and will throw error winsound.PlaySound(filename, winsound.SND_FILENAME | winsound.SND_ASYNC | winsound.SND_NOSTOP) except: pass
def play(self): if not Settings.value(Settings.MUTE_CHALLENGE_SOUND): filename = self.wavfile() if filename: #noinspection PyBroadException try: # winsound can only play one clip at a time and will throw error winsound.PlaySound(filename, winsound.SND_FILENAME | winsound.SND_ASYNC | winsound.SND_NOSTOP) except: pass
def restoreStateAndGeometry(self): saved = Settings.value(Settings.WINDOW_GEOMETRY) if saved: self.restoreGeometry(saved) saved = Settings.value(Settings.WINDOW_STATE) if saved: self.restoreState(saved) saved = Settings.value(Settings.SPLITTER_STATE) if saved: self.uiSplitter.restoreState(saved) saved = Settings.value(Settings.TABLE_HEADER_STATE) if saved: self.uiPlayersTableV.horizontalHeader().restoreState(saved) saved = Settings.value(Settings.CHANNELS_HEADER_STATE) if saved: self.uiChannelsTree.header().restoreState(saved) else: self.uiChannelsTree.setColumnWidth(0,50) self.uiChannelsTree.setColumnWidth(1,300)
def findGeoIPDB(): dbs = [ Settings.value(Settings.GEOIP2DB_LOCATION), os.path.join(os.getcwd(), "GeoLite2-City.mmdb"), packagePathJoin("GeoLite2-City.mmdb"), os.path.join(os.getcwd(), "GeoLite2-Country.mmdb"), packagePathJoin("GeoLite2-Country.mmdb"), ] for db in dbs: if db and os.path.isfile(db): return db
def onPlayerNewlyJoined(self, name): if self.controller.channel == 'unsupported' and self.controller.unsupportedRom and \ not Settings.value(Settings.DISABLE_AUTO_ANNOUNCE_UNSUPPORTED) and \ time.time() - self.autoAnnounceUnsupportedTime > 3 and \ self.controller.username in self.controller.playing: basename = os.path.splitext(self.controller.unsupportedRom)[0] desc = '' if basename in allgames: desc = allgames[basename][FBA_GAMEDB_DESCRIPTION] QtCore.QTimer.singleShot(1000, lambda: self.controller.sendChat("* I'm playing {}".format(desc))) self.autoAnnounceUnsupportedTime = time.time()
def locateGeoMMDB(self): oldval = Settings.value(Settings.GEOIP2DB_LOCATION) if oldval and os.path.isdir(os.path.dirname(oldval)): dirname = os.path.dirname(oldval) else: dirname = os.path.expanduser("~") fname = QtGui.QFileDialog.getOpenFileName(self, 'Locate Geo mmdb file', dirname, "Geo mmdb (*.mmdb)") if fname: Settings.setValue(Settings.GEOIP2DB_LOCATION, fname) geolookupInit()
def locateGGPOFBA(self): oldval = Settings.value(Settings.GGPOFBA_LOCATION) if oldval and os.path.isdir(os.path.dirname(oldval)): dirname = os.path.dirname(oldval) else: dirname = os.path.expanduser("~") fname = QtGui.QFileDialog.getOpenFileName(self, 'Locate ggpofba.exe', dirname, "ggpofba.exe (ggpofba.exe)") if fname: Settings.setValue(Settings.GGPOFBA_LOCATION, fname) self.controller.checkInstallation()
def locateCustomChallengeSound(self): oldval = Settings.value(Settings.CUSTOM_CHALLENGE_SOUND_LOCATION) if oldval and os.path.isdir(os.path.dirname(oldval)): dirname = os.path.dirname(oldval) else: dirname = os.path.expanduser("~") fname = QtGui.QFileDialog.getOpenFileName(self, 'Locate custom wave file', dirname, "wav file (*.wav)") if fname: Settings.setValue(Settings.CUSTOM_CHALLENGE_SOUND_LOCATION, fname) ggpo.common.sound.play()
def parseChatResponse(self, data): name, data = Protocol.extractTLV(data) if name in self.ignored: return msg, data = Protocol.extractTLV(data) try: msg = msg.decode('utf-8') except ValueError: msg = msg if Settings.value(Settings.USER_LOG_CHAT): loguser().info(u"<{}> {}".format(name, msg)) self.sigChatReceived.emit(name, msg)
def setCustomQss(self): oldval = Settings.value(Settings.CUSTOM_THEME_FILENAME) if oldval and os.path.isdir(os.path.dirname(oldval)): dirname = os.path.dirname(oldval) else: dirname = os.path.expanduser("~") fname = QtGui.QFileDialog.getOpenFileName(self, 'Locate Qt Stylesheet qss file', dirname, "qss file (*.qss)") if self.setCustomQssfile(fname): for a in self.uiMenuThemeGroup.actions(): if a.isChecked(): a.setChecked(False)
def wavfile(): filename = Settings.value(Settings.CUSTOM_CHALLENGE_SOUND_LOCATION) if filename and os.path.isfile(filename): return filename fba = findFba() if fba: filename = os.path.join(os.path.dirname(fba), "assets", "challenger-comes.wav") if os.path.isfile(filename): return filename filename = os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), "assets", "challenger-comes.wav") if filename and os.path.isfile(filename): return filename
def onChatReceived(self, name, txt): prefix = self.controller.getPlayerPrefix(name, Settings.value(Settings.SHOW_COUNTRY_FLAG_IN_CHAT)) if (self.controller.username+" ".lower() in txt.lower() or " "+self.controller.username.lower() in txt.lower() or txt.lower()==self.controller.username.lower()): txt = cgi.escape(txt.strip()).replace(self.controller.username, "<b>{}</b>".format(self.controller.username)) ggpo.common.sound.notify() else: txt = cgi.escape(txt.strip()) urls = findURLs(txt) chat = prefix + txt if urls: chat = prefix + replaceURLs(txt) self.appendChat(replaceReplayID(chat))
def runFBA(self, quark): if "served" in quark: self.killEmulator() self.killPuncher() time.sleep(2) self.checkRom() self.fba = findFba() if not self.fba: self.sigStatusMessage.emit( "ERROR: make sure ggpofba-ng.exe is in the same folder as FightCade" ) return args = [] fba = self.fba if IS_WINDOWS: fba = fba.replace('ggpofba-ng.exe', 'ggpofba.exe') else: fba = fba.replace('ggpofba-ng.exe', 'ggpofba.sh') args = [fba, quark, '-w'] fbaini = os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), 'config', 'ggpofba-ng.ini') fbadat = os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), 'config', 'ggpofba-ng.roms.dat') fbainibkp = os.path.join(os.path.abspath(os.path.expanduser("~")), 'ggpofba-ng.bkp.ini') if not os.path.isfile(fbaini): self.createFbaIni() logdebug().info(" ".join(args)) if Settings.value(Settings.COMPOSITION_DISABLED): self.desktopComposition(0) try: # starting python from cmd.exe and redirect stderr and we got # python WindowsError(6, 'The handle is invalid') # apparently it's still not fixed if IS_WINDOWS: Popen(args, shell=True) else: devnull = open(os.devnull, 'w') Popen(args, stdout=devnull, stderr=devnull) devnull.close() except OSError: self.sigStatusMessage.emit("Error executing " + " ".join(args) + "\n" + repr(ex)) # backup FBA settings if os.path.isfile(fbaini) and os.path.isfile(fbadat): copyfile(fbaini, fbainibkp)