def onParserReady(self): for fight in log_parser.get().fights: if fight == log_parser.get().fight: continue self.addFightToSelector(fight)
def run(self): prnt("RaidClient: Booting up...") self.conn = net.node.connect(self.serverNode, "swap:raid") if not self.conn or self.conn.state != fuzion.CS_CONNECTED: raid.leaveRaid() wx.CallAfter(self.failureFunc, "node_connect_failed") prnt("RaidClient: Connection failed, shutting down...") return # Inform the UI of raid join success. wx.CallAfter(self.successFunc) while not self.stoppedEvent.isSet(): if self.pausedEvent.isSet(): sleep(0.4) continue if self.conn.recvPending(): data = self.conn.recv() if data == None: if self.conn.closedReason != 0: # If we're paused, we don't want to reconnect yet. if self.pausedEvent.isSet(): continue prnt("RaidClient: Connection lost, reason=%s"%fuzion.formatError(self.conn.closedReason)) # Fetch new raid info self.serverNode = None self.conn = None while self.serverNode == None or self.conn == None: prnt("RaidClient: Reconnecting...") self.serverNode = raid.getNewServerNode() if self.serverNode == None: prnt("RaidClient: Failed to get new server node...") sleep(2) continue conn = net.node.connect(self.serverNode, "swap:raid") if conn.state == fuzion.CS_CONNECTED: self.conn = conn self.lastTicks = 2 continue else: prnt("RaidClient: Failed to connect to new node! Connection state = %d"%conn.state) sleep(2) continue packet = data.readByte() if packet == pkt.RAID_UPDATE: self.gotRaidUpdate(data) now = time() if now - self.lastUpdateSent >= 2 and (log_parser.get().inCombat or self.lastTicks >= 1): if not log_parser.get().inCombat: self.lastTicks -= 1 else: self.lastTicks = 2 self.sendPlayerUpdate() self.lastUpdateSent = now sleep(0.1) self.conn.close() prnt("RaidClient: Shutting down...")
def __init__(self): wx.Frame.__init__(self, None, title="SWAP %s"%VERSION, size=(900, 520)) if not util.isCombatLoggingEnabled(): dlg = wx.MessageDialog(self, MSG_COMBAT_LOGGING_DISABLED_TEXT, MSG_COMBAT_LOGGING_DISABLED_TITLE, wx.OK | wx.CANCEL | wx.ICON_ERROR) result = dlg.ShowModal() dlg.Destroy() if result == wx.ID_OK: util.enableCombatLogging() # Check for changelog try: f = open('_changelog.txt', 'r') except IOError: pass else: with f: changelog = f.read() changelogDialog = ChangelogDialog(changelog) changelogDialog.ShowModal() changelogDialog.Destroy() os.remove('_changelog.txt') self.SetMinSize((900, 520)) if IS_FROZEN: self.SetIcon(wx.Icon('swap.exe', wx.BITMAP_TYPE_ICO)) else: self.SetIcon(wx.Icon('../etc/app.ico', wx.BITMAP_TYPE_ICO)) # Setup menu bar menuBar = wx.MenuBar() self.SetMenuBar(menuBar) # File menu = wx.Menu() menuBar.Append(menu, "&File") m_exit = menu.Append(MENU_ID_EXIT, MENU_TITLE_EXIT, MENU_TIP_EXIT) self.Bind(wx.EVT_MENU, self.onClose, id=MENU_ID_EXIT) # Tools menu = wx.Menu() menuBar.Append(menu, "&Tools") m_preferences = menu.Append(MENU_ID_PREFERENCES, MENU_TITLE_PREFERENCES, MENU_TIP_PREFERENCES) self.Bind(wx.EVT_MENU, self.onPreferences, id=MENU_ID_PREFERENCES) menu.AppendSeparator() m_enrageTime = menu.Append(MENU_ID_ENRAGE_TIME, MENU_TITLE_ENRAGE_TIME, MENU_TIP_ENRAGE_TIME) self.Bind(wx.EVT_MENU, self.onSetEnrageTime, id=MENU_ID_ENRAGE_TIME) # Overlay menu = wx.Menu() menuBar.Append(menu, "&Overlay") categoryMenus = {} for category in overlays.getOverlayCategoryList(): name = category['name'] title = category['title'] categoryMenus[name] = subMenu = wx.Menu() menu.AppendSubMenu(subMenu, title, "") self.m_overlays = {} for overlay in overlays.getOverlayList(): targetMenu = menu if overlay['category'] != None: targetMenu = categoryMenus[overlay['category']] if overlay['name'] == '-': targetMenu.AppendSeparator() continue id = wx.NewId() self.m_overlays[id] = targetMenu.AppendCheckItem(id, overlay['title'], MENU_TIP_OVERLAY_SELECT) self.Bind(wx.EVT_MENU, (lambda n: lambda e: overlays.toggleOverlay(n))(overlay['name']), id=id) menu.AppendSeparator() m_dark = menu.AppendCheckItem(MENU_ID_OVERLAY_DARK, MENU_TITLE_OVERLAY_DARK, MENU_TIP_OVERLAY_DARK) m_dark.Check(overlays.isDarkTheme()) self.Bind(wx.EVT_MENU, lambda e: overlays.toggleDarkTheme(), id=MENU_ID_OVERLAY_DARK) m_sizeToGrid = menu.AppendCheckItem(MENU_ID_OVERLAY_SIZE_TO_GRID, MENU_TITLE_OVERLAY_SIZE_TO_GRID, MENU_TIP_OVERLAY_SIZE_TO_GRID) m_sizeToGrid.Check(config.get("overlaySizeToGrid") == True) self.Bind(wx.EVT_MENU, lambda e: config.set("overlaySizeToGrid", m_sizeToGrid.IsChecked()), id=MENU_ID_OVERLAY_SIZE_TO_GRID) m_snapOverlays = menu.AppendCheckItem(MENU_ID_OVERLAY_SNAP, MENU_TITLE_OVERLAY_SNAP, MENU_TIP_OVERLAY_SNAP) m_snapOverlays.Check(config.get("overlaySnap") == True) self.Bind(wx.EVT_MENU, lambda e: config.set("overlaySnap", m_snapOverlays.IsChecked()), id=MENU_ID_OVERLAY_SNAP) m_clickThrough = menu.AppendCheckItem(MENU_ID_OVERLAY_CLICK_THROUGH, MENU_TITLE_OVERLAY_CLICK_THROUGH, MENU_TIP_OVERLAY_CLICK_THROUGH) m_clickThrough.Check(config.get("overlayClickThrough") == True) self.Bind(wx.EVT_MENU, lambda e: config.set("overlayClickThrough", m_clickThrough.IsChecked()), id=MENU_ID_OVERLAY_CLICK_THROUGH) menu.AppendSeparator() m_reset = menu.Append(MENU_ID_OVERLAY_RESET, MENU_TITLE_OVERLAY_RESET, MENU_TIP_OVERLAY_RESET) self.Bind(wx.EVT_MENU, self.onResetOverlays, id=MENU_ID_OVERLAY_RESET) m_close = menu.Append(MENU_ID_OVERLAY_CLOSE, MENU_TITLE_OVERLAY_CLOSE, MENU_TIP_OVERLAY_CLOSE) self.Bind(wx.EVT_MENU, self.onCloseOverlays, id=MENU_ID_OVERLAY_CLOSE) # Help menu = wx.Menu() menuBar.Append(menu, "&Help") m_checkUpdates = menu.Append(MENU_ID_HELP_UPDATES, MENU_TITLE_HELP_UPDATES, MENU_TIP_HELP_UPDATES) m_openLog = menu.Append(MENU_ID_HELP_LOG, MENU_TITLE_HELP_LOG, MENU_TIP_HELP_LOG) m_sendLog = menu.Append(MENU_ID_HELP_SEND_LOG, MENU_TITLE_HELP_SEND_LOG, MENU_TIP_HELP_SEND_LOG) menu.AppendSeparator() m_about = menu.Append(MENU_ID_HELP_ABOUT, MENU_TITLE_HELP_ABOUT, MENU_TIP_HELP_ABOUT) self.Bind(wx.EVT_MENU, self.onCheckUpdates, id=MENU_ID_HELP_UPDATES) self.Bind(wx.EVT_MENU, self.onOpenLog, id=MENU_ID_HELP_LOG) self.Bind(wx.EVT_MENU, self.onSendLog, id=MENU_ID_HELP_SEND_LOG) self.Bind(wx.EVT_MENU, self.onAbout, id=MENU_ID_HELP_ABOUT) # UI self.panel = wx.Panel(self) self.panel.SetDoubleBuffered(True) self.horzBox = wx.BoxSizer(wx.HORIZONTAL) self.box = wx.BoxSizer(wx.VERTICAL) self.horzBox.Add(self.box, 1, wx.EXPAND) # ----------------------------------- # Header # ----------------------------------- headerBox = wx.BoxSizer(wx.HORIZONTAL) self.keyText = wx.StaticText(self.panel, -1, "Key:") self.keyBox = wx.TextCtrl(self.panel, -1, "", size=(150, -1)) lastRaidKey = config.get("lastRaidKey") if lastRaidKey: self.keyBox.SetValue(lastRaidKey) self.keyGenerateButton = wx.Button(self.panel, -1, "Generate") self.keyGenerateButton.Bind(wx.EVT_BUTTON, self.onGenerateButton) self.keyJoinButton = wx.Button(self.panel, -1, "Join Raid") self.keyJoinButton.Bind(wx.EVT_BUTTON, self.onJoinRaidButton) self.keyVanityCheck = wx.CheckBox(self.panel, -1, "Generate Vanity Key") self.keyStatus = wx.StaticText(self.panel, -1, "") self.fightSelector = wx.Choice(self.panel, -1) self.fightSelector.Append("Latest Fight", None) self.fightSelector.SetSelection(0) self.fightSelector.Bind(wx.EVT_CHOICE, self.onFightSelected) log_parser.get().registerObserver(log_parser.Parser.EVENT_FIGHT_BEGIN, util.wxFunc(self.onFightBegin)) log_parser.get().registerObserver(log_parser.Parser.EVENT_FIGHT_END, util.wxFunc(self.onFightEnd)) log_parser.get().registerObserver(log_parser.Parser.EVENT_NEW_LOG, util.wxFunc(self.onNewLog)) log_parser.get().registerObserver(log_parser.Parser.EVENT_READY, util.wxFunc(self.onParserReady)) if log_parser.get().ready: self.onParserReady() self.dashboardFight = None self.historicRaidFights = {} headerBox.Add(self.keyText, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 10) headerBox.Add(self.keyBox, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 10) headerBox.Add(self.keyGenerateButton, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 5) headerBox.Add(self.keyJoinButton, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 10) headerBox.Add(self.keyVanityCheck, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT) headerBox.Add(self.keyStatus, 0, wx.ALIGN_CENTER_VERTICAL | wx.LEFT, 10) headerBox.Add(self.fightSelector, 1, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 10) self.box.Add(headerBox, 0, wx.EXPAND | wx.ALL, 10) # ----------------------------------- # Tabs # ----------------------------------- self.tabs = wx.Notebook(self.panel) # Create Overview tab self.overviewPanel = wx.Panel(self.tabs) self.overviewSizer = wx.BoxSizer(wx.VERTICAL) self.overviewPanel.SetSizer(self.overviewSizer) self.overviewPanel.Layout() self.createOverviewView(self.overviewSizer, self.overviewPanel) self.tabs.AddPage(self.overviewPanel, "Overview") # Create Report tab self.reportPanel = wx.Panel(self.tabs) self.reportSizer = wx.BoxSizer(wx.VERTICAL) self.reportPanel.SetSizer(self.reportSizer) self.reportPanel.Layout() self.createReportView(self.reportSizer, self.reportPanel) self.tabs.AddPage(self.reportPanel, "Report") # Create Raid tab self.raidPanel = wx.Panel(self.tabs) self.raidSizer = wx.BoxSizer(wx.VERTICAL) self.raidPanel.SetSizer(self.raidSizer) self.raidPanel.Layout() self.createRaidView(self.raidSizer, self.raidPanel) self.tabs.AddPage(self.raidPanel, "Raid") # Create Ability tab self.abilityPanel = wx.Panel(self.tabs) self.abilitySizer = wx.BoxSizer(wx.VERTICAL) self.abilityPanel.SetSizer(self.abilitySizer) self.abilityPanel.Layout() self.createAbilityView(self.abilitySizer, self.abilityPanel) self.tabs.AddPage(self.abilityPanel, "By Ability") # Create Targets tab self.targetsPanel = wx.Panel(self.tabs) self.targetsSizer = wx.BoxSizer(wx.VERTICAL) self.targetsPanel.SetSizer(self.targetsSizer) self.targetsPanel.Layout() self.createTargetsView(self.targetsSizer, self.targetsPanel) self.tabs.AddPage(self.targetsPanel, "By Target") self.box.Add(self.tabs, 1, wx.EXPAND | wx.ALL & ~wx.TOP, 10) # ----------------------------------- # Console # ----------------------------------- self.console = wx.TextCtrl(self.panel, style=wx.TE_MULTILINE | wx.TE_READONLY, size=(200, -1)) self.console.SetFont(wx.Font(7, wx.DEFAULT, wx.NORMAL, wx.NORMAL)) self.horzBox.Add(self.console, 0, wx.EXPAND | wx.ALL & ~wx.LEFT, 10) self.panel.SetSizer(self.horzBox) self.panel.Layout() # Events self.Bind(wx.EVT_CLOSE, self.onClose) log_analyzer.get().registerFrame(self) self.addToConsole("SWAP %s started."%(VERSION))
def onFightEnd(self): fight = log_parser.get().fights[-1] self.addFightToSelector(fight) self.historicRaidFights[fight] = raid.playerData
def updateOverviewView(self, analyzer): self.overviewUsername.SetLabel(log_parser.get().me.name.upper()) for analyzerUpdater in self.overviewUpdaters: analyzerUpdater(analyzer) self.overviewPanel.Layout()
locale.setlocale(locale.LC_ALL, '') if IS_FROZEN: if len(sys.argv) != 2 or sys.argv[1] != '--from-updater': subprocess.Popen(["updater.exe"], close_fds=True) exit() prnt("SWAP %s booting up..."%VERSION) net.init() config.load() log_parser.start() log_analyzer.start(log_parser.getThread()) if config.get('tr0lled') == None: p = log_parser.get() def f(): if p.me.name in ('Darith', 'Bev\xec\xecn'): import webbrowser webbrowser.open("http://www.youtube.com/watch?v=gvGyS5j9aFY") config.set('tr0lled', True) config.save() if p.me: f() else: log_parser.get().registerObserver(log_parser.Parser.EVENT_PLAYER_IDENTIFIED, f) if os.path.isdir("pending"): prnt("Finalizing update...") for f in os.listdir("pending"):
def run(self): prnt("RaidClient: Booting up...") self.conn = net.node.connect(self.serverNode, "swap:raid") if not self.conn or self.conn.state != fuzion.CS_CONNECTED: raid.leaveRaid() wx.CallAfter(self.failureFunc, "node_connect_failed") prnt("RaidClient: Connection failed, shutting down...") return # Inform the UI of raid join success. wx.CallAfter(self.successFunc) while not self.stoppedEvent.isSet(): if self.pausedEvent.isSet(): sleep(0.4) continue if self.conn.recvPending(): data = self.conn.recv() if data == None: if self.conn.closedReason != 0: # If we're paused, we don't want to reconnect yet. if self.pausedEvent.isSet(): continue prnt("RaidClient: Connection lost, reason=%s" % fuzion.formatError(self.conn.closedReason)) # Fetch new raid info self.serverNode = None self.conn = None while self.serverNode == None or self.conn == None: prnt("RaidClient: Reconnecting...") self.serverNode = raid.getNewServerNode() if self.serverNode == None: prnt( "RaidClient: Failed to get new server node..." ) sleep(2) continue conn = net.node.connect(self.serverNode, "swap:raid") if conn.state == fuzion.CS_CONNECTED: self.conn = conn self.lastTicks = 2 continue else: prnt( "RaidClient: Failed to connect to new node! Connection state = %d" % conn.state) sleep(2) continue packet = data.readByte() if packet == pkt.RAID_UPDATE: self.gotRaidUpdate(data) now = time() if now - self.lastUpdateSent >= 2 and (log_parser.get().inCombat or self.lastTicks >= 1): if not log_parser.get().inCombat: self.lastTicks -= 1 else: self.lastTicks = 2 self.sendPlayerUpdate() self.lastUpdateSent = now sleep(0.1) self.conn.close() prnt("RaidClient: Shutting down...")