Mercurial > traipse_dev
diff orpg/chat/chatwnd.py @ 135:dcf4fbe09b70 beta
Traipse Beta 'OpenRPG' {091010-00}
Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on
code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to
offer more advanced features and enhance the productivity of the user.
Update Summary (Beta)
Added Bookmarks
Fix to Remote Admin Commands
Minor fix to text based Server
Fix to Pretty Print, from Core
Fix to Splitter Nodes not being created
Fix to massive amounts of images loading, from Core
Added 'boot' command to remote admin
Added confirmation window for sent nodes
Minor changes to allow for portability to an OpenSUSE linux OS
Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG
Zoom Mouse plugin added
Images added to Plugin UI
Switching to Element Tree
Map efficiency, from FlexiRPG
Added Status Bar to Update Manager
default_manifest.xml renamed to default_upmana.xml
Cleaner clode for saved repositories
New TrueDebug Class in orpg_log (See documentation for usage)
Mercurial's hgweb folder is ported to upmana
**Pretty important update that can help remove thousands of dead children from your gametree.
**Children, <forms />, <group_atts />, <horizontal />, <cols />, <rows />, <height />, etc... are all tags now. Check your gametree and
look for dead children!!
**New Gamtree Recusion method, mapping, and context sensitivity. !!Alpha - Watch out for infinite loops!!
author | sirebral |
---|---|
date | Tue, 10 Nov 2009 14:11:28 -0600 |
parents | 7ed4979cc1cf |
children | e842a5f1b775 |
line wrap: on
line diff
--- a/orpg/chat/chatwnd.py Fri Sep 25 20:47:16 2009 -0500 +++ b/orpg/chat/chatwnd.py Tue Nov 10 14:11:28 2009 -0600 @@ -42,37 +42,30 @@ ## ## Module Loading -## +## +import os, time, re, sys, traceback, webbrowser, commands, chat_msg, chat_util + +from orpg.orpg_version import VERSION from orpg.orpg_windows import * from orpg.player_list import WG_LIST from orpg.dirpath import dir_struct +#from orpg.tools.metamenus import MenuEx #Needed? +from string import * + +import cStringIO # for reading inline imagedata as a stream +from HTMLParser import HTMLParser +from wx.lib.expando import EVT_ETC_LAYOUT_NEEDED + import orpg.tools.rgbhex import orpg.tools.inputValidator -#from orpg.tools.metamenus import MenuEx #Needed? - -import webbrowser -from string import * -from orpg.orpg_version import VERSION -import commands -import chat_msg -import time +from orpg.tools.validate import validate +from orpg.tools.orpg_settings import settings import orpg.tools.predTextCtrl +from orpg.tools.orpg_log import logger, debug +from orpg.orpgCore import component +from xml.etree.ElementTree import tostring + from orpg.networking.mplay_client import MPLAY_CONNECTED # needed to only send typing/not_typing messages while connected -import os -import time -import re -import sys -import cStringIO # for reading inline imagedata as a stream -from HTMLParser import HTMLParser -import chat_util -import traceback -from wx.lib.expando import EVT_ETC_LAYOUT_NEEDED - -from orpg.tools.validate import validate -from orpg.tools.orpg_settings import settings -from orpg.orpgCore import component -from orpg.tools.orpg_log import logger -from orpg.tools.decorators import debugging NEWCHAT = False try: @@ -84,39 +77,39 @@ # Global parser for stripping HTML tags: # The 'tag stripping' is implicit, because this parser echoes every # type of html data *except* the tags. -class HTMLStripper(HTMLParser): - @debugging +class HTMLStripper(HTMLParser): + def __init__(self): self.accum = "" - self.special_tags = ['hr', 'br', 'img'] - @debugging + self.special_tags = ['hr', 'br', 'img'] + def handle_data(self, data): # quote cdata literally - self.accum += data - @debugging + self.accum += data + def handle_entityref(self, name): # entities must be preserved exactly - self.accum += "&" + name + ";" - @debugging + self.accum += "&" + name + ";" + def handle_starttag(self, tag, attrs): if tag in self.special_tags: self.accum += '<' + tag for attrib in attrs: self.accum += ' ' + attrib[0] + '="' + attrib[1] + '"' - self.accum += '>' - @debugging + self.accum += '>' + def handle_charref(self, name): # charrefs too self.accum += "&#" + name + ";" htmlstripper = HTMLStripper() -# utility function; see Post(). -@debugging +# utility function; see Post(). + def strip_html(string): "Return string tripped of html tags." htmlstripper.reset() htmlstripper.accum = "" htmlstripper.feed(string) htmlstripper.close() - return htmlstripper.accum + return htmlstripper.accum -@debugging + def log( settings, c, text ): filename = settings.get_setting('GameLogPrefix') if filename > '' and filename[0] != commands.ANTI_LOG_CHAR: @@ -148,9 +141,9 @@ # !self : instance of self # !parent : # !id : - @debugging + def __init__(self, parent, id): - wx.html.HtmlWindow.__init__(self, parent, id, + wx.html.HtmlWindow.__init__(self, parent, id, style=wx.SUNKEN_BORDER|wx.html.HW_SCROLLBAR_AUTO|wx.NO_FULL_REPAINT_ON_RESIZE) self.parent = parent self.build_menu() @@ -159,50 +152,50 @@ if "gtk2" in wx.PlatformInfo: self.SetStandardFonts() # def __init__ - end - @debugging + def onPopup(self, evt): self.PopupMenu(self.menu) - @debugging + def LeftUp(self, event): event.Skip() wx.CallAfter(self.parent.set_chat_text_focus, None) - @debugging + def build_menu(self): self.menu = wx.Menu() item = wx.MenuItem(self.menu, wx.ID_ANY, "Copy", "Copy") self.Bind(wx.EVT_MENU, self.OnM_EditCopy, item) self.menu.AppendItem(item) - @debugging - def OnM_EditCopy(self, evt): - wx.TheClipboard.UsePrimarySelection(False) - wx.TheClipboard.Open() - wx.TheClipboard.SetData(wx.TextDataObject(self.SelectionToText())) - wx.TheClipboard.Close() + + def OnM_EditCopy(self, evt): + wx.TheClipboard.UsePrimarySelection(False) + wx.TheClipboard.Open() + wx.TheClipboard.SetData(wx.TextDataObject(self.SelectionToText())) + wx.TheClipboard.Close() - @debugging + def scroll_down(self): maxrange = self.GetScrollRange(wx.VERTICAL) pagesize = self.GetScrollPageSize(wx.VERTICAL) self.Scroll(-1, maxrange-pagesize) - @debugging + def mouse_wheel(self, event): amt = event.GetWheelRotation() units = amt/(-(event.GetWheelDelta())) self.ScrollLines(units*3) - @debugging + def Header(self): return '<html><body bgcolor="' + self.parent.bgcolor + '" text="' + self.parent.textcolor + '">' - @debugging + def StripHeader(self): return self.GetPageSource().replace(self.Header(), '') - @debugging + def GetPageSource(self): return self.GetParser().GetSource() @@ -210,14 +203,14 @@ # # !self : instance of self # !linkinfo : instance of a class that contains the link information - @debugging + def OnLinkClicked(self, linkinfo): href = linkinfo.GetHref() wb = webbrowser.get() wb.open(href) # def OnLinkClicked - end - @debugging + def CalculateAllFonts(self, defaultsize): return [int(defaultsize * 0.4), int(defaultsize * 0.7), @@ -227,17 +220,17 @@ int(defaultsize * 2), int(defaultsize * 2.5)] - @debugging + def SetDefaultFontAndSize(self, fontname, fontsize): """Set 'fontname' to the default chat font. Returns current font settings in a (fontname, fontsize) tuple.""" self.SetFonts(fontname, "", self.CalculateAllFonts(int(fontsize))) return (self.GetFont().GetFaceName(), self.GetFont().GetPointSize()) - + # class chat_html_window - end if NEWCHAT: class ChatHtmlWindow(wx.webview.WebView): - @debugging + def __init__(self, parent, id): wx.webview.WebView.__init__(self, parent, id) self.parent = parent @@ -248,79 +241,79 @@ self.Bind(wx.webview.EVT_WEBVIEW_BEFORE_LOAD, self.OnLinkClicked) #Wrapers so I dont have to add special Code - @debugging + def SetPage(self, htmlstring): self.SetPageSource(htmlstring) - @debugging + def AppendToPage(self, htmlstring): self.SetPageSource(self.GetPageSource() + htmlstring) - @debugging + def GetFont(self): return self.__font - @debugging + def CalculateAllFonts(self, defaultsize): return - @debugging + def SetDefaultFontAndSize(self, fontname, fontsize): - self.__font = wx.Font(int(fontsize), - wx.FONTFAMILY_ROMAN, wx.FONTSTYLE_NORMAL, + self.__font = wx.Font(int(fontsize), + wx.FONTFAMILY_ROMAN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, faceName=fontname) try: self.SetPageSource(self.Header() + self.StripHeader()) except Exception, e: print e return (self.GetFont().GetFaceName(), self.GetFont().GetPointSize()) #Events - @debugging + def OnLinkClicked(self, linkinfo): href = linkinfo.GetHref() wb = webbrowser.get() wb.open(href) - @debugging + def onPopup(self, evt): self.PopupMenu(self.menu) - @debugging + def LeftUp(self, event): event.Skip() wx.CallAfter(self.parent.set_chat_text_focus, None) - @debugging - def OnM_EditCopy(self, evt): - wx.TheClipboard.UsePrimarySelection(False) - wx.TheClipboard.Open() - wx.TheClipboard.SetData(wx.TextDataObject(self.SelectionToText())) + + def OnM_EditCopy(self, evt): + wx.TheClipboard.UsePrimarySelection(False) + wx.TheClipboard.Open() + wx.TheClipboard.SetData(wx.TextDataObject(self.SelectionToText())) wx.TheClipboard.Close() #Cutom Methods - @debugging + def Header(self): return "<html><head><style>body {font-size: " + str(self.GetFont().GetPointSize()) + "px;font-family: " + self.GetFont().GetFaceName() + ";color: " + self.parent.textcolor + ";background-color: " + self.parent.bgcolor + ";margin: 0;padding: 0 0;height: 100%;}</style></head><body>" - @debugging + def StripHeader(self): tmp = self.GetPageSource().split('<BODY>') if tmp[-1].find('<body>') > -1: tmp = tmp[-1].split('<body>') return tmp[-1] - @debugging + def build_menu(self): self.menu = wx.Menu() item = wx.MenuItem(self.menu, wx.ID_ANY, "Copy", "Copy") self.Bind(wx.EVT_MENU, self.OnM_EditCopy, item) self.menu.AppendItem(item) - @debugging + def scroll_down(self): maxrange = self.GetScrollRange(wx.VERTICAL) pagesize = self.GetScrollPageSize(wx.VERTICAL) self.Scroll(-1, maxrange-pagesize) - @debugging + def mouse_wheel(self, event): amt = event.GetWheelRotation() units = amt/(-(event.GetWheelDelta())) @@ -353,10 +346,10 @@ # OnPageChanged(self, event) # set_default_font(self, font, fontsize) -class chat_notebook(orpgTabberWnd): - @debugging +class chat_notebook(orpgTabberWnd): + def __init__(self, parent, size): - orpgTabberWnd.__init__(self, parent, True, size=size, + orpgTabberWnd.__init__(self, parent, True, size=size, style=FNB.FNB_DROPDOWN_TABS_LIST|FNB.FNB_NO_NAV_BUTTONS|FNB.FNB_MOUSE_MIDDLE_CLOSES_TABS) self.settings = component.get("settings") self.whisper_tabs = [] @@ -385,24 +378,24 @@ if self.settings.get_setting("GMWhisperTab") == '1': self.create_gm_tab() self.SetSelection(0) - - @debugging + + def get_tab_index(self, chatpanel): "Return the index of a chatpanel in the wxNotebook." for i in xrange(self.GetPageCount()): if (self.GetPage(i) == chatpanel): return i - - @debugging + + def create_gm_tab(self): if self.GMChatPanel == None: self.GMChatPanel = chat_panel(self, -1, MAIN_TAB, 'gm') self.AddPage(self.GMChatPanel, "GM", False) self.SetPageImage(self.GetPageCount()-1, 1) self.GMChatPanel.chatwnd.SetDefaultFontAndSize(self.font, self.fontsize) - - @debugging + + def create_whisper_tab(self, playerid): "Add a new chatpanel directly connected to integer 'playerid' via whispering." private_tab = chat_panel(self, -1, WHISPER_TAB, playerid) @@ -414,8 +407,8 @@ self.AliasLib = component.get('alias') wx.CallAfter(self.AliasLib.RefreshAliases) return private_tab - - @debugging + + def create_group_tab(self, group_name): "Add a new chatpanel directly connected to integer 'playerid' via whispering." private_tab = chat_panel(self, -1, GROUP_TAB, group_name) @@ -426,8 +419,8 @@ self.AliasLib = component.get('alias') wx.CallAfter(self.AliasLib.RefreshAliases) return private_tab - - @debugging + + def create_null_tab(self, tab_name): "Add a new chatpanel directly connected to integer 'playerid' via whispering." private_tab = chat_panel(self, -1, NULL_TAB, tab_name) @@ -438,8 +431,8 @@ self.AliasLib = component.get('alias') wx.CallAfter(self.AliasLib.RefreshAliases) return private_tab - - @debugging + + def onCloseTab(self, evt): try: tabid = evt.GetSelection() except: tabid = self.GetSelection() @@ -467,17 +460,17 @@ if panel in self.whisper_tabs: self.whisper_tabs.remove(panel) elif panel in self.group_tabs: self.group_tabs.remove(panel) elif panel in self.null_tabs: self.null_tabs.remove(panel) - - @debugging + + def newMsg(self, tabid): if tabid != self.GetSelection(): self.SetPageImage(tabid, 0) - - @debugging + + def onPageChanging(self, event): """When private chattabs are selected, set the bitmap back to 'normal'.""" event.Skip() - - @debugging + + def onPageChanged(self, event): """When private chattabs are selected, set the bitmap back to 'normal'.""" selected_idx = event.GetSelection() @@ -485,7 +478,7 @@ page = self.GetPage(selected_idx) #wx.CallAfter(page.set_chat_text_focus, 0) event.Skip() - + """ This class defines and builds the Chat Frame for OpenRPG @@ -512,11 +505,11 @@ ParseNodes(self,s) get_sha_checksum(self) get_color(self) - + """ class chat_panel(wx.Panel): - + """ This is the initialization subroutine @@ -524,13 +517,13 @@ !parent : parent that defines the chatframe !id : !openrpg : - !sendtarget: who gets outbound messages: either 'all' or a playerid - """ - - @debugging + !sendtarget: who gets outbound messages: either 'all' or a playerid + """ + + def __init__(self, parent, id, tab_type, sendtarget): - wx.Panel.__init__(self, parent, id) - logger._set_log_to_console(False) + wx.Panel.__init__(self, parent, id) + logger._set_log_to_console(False) self.session = component.get('session') self.settings = component.get('settings') self.activeplugins = component.get('plugins') @@ -562,8 +555,8 @@ self.advancedFilter = False self.lastSend = 0 # this is used to help implement the player typing indicator self.lastPress = 0 # this is used to help implement the player typing indicator - self.Bind(wx.EVT_SIZE, self.OnSize) - self.Bind(EVT_ETC_LAYOUT_NEEDED, self.OnSize) #require to keep text at bottom of chat when text entry expands --SD + self.Bind(wx.EVT_SIZE, self.OnSize) + self.Bind(EVT_ETC_LAYOUT_NEEDED, self.OnSize) #require to keep text at bottom of chat when text entry expands --SD self.build_ctrls() StartupFont = self.settings.get_setting("defaultfont") StartupFontSize = self.settings.get_setting("defaultfontsize") @@ -572,11 +565,11 @@ except: pass self.font = self.chatwnd.GetFont().GetFaceName() self.fontsize = self.chatwnd.GetFont().GetPointSize() - self.scroll_down() - - @debugging + self.scroll_down() + + def set_default_font(self, fontname=None, fontsize=None): - """Set all chatpanels to new default fontname/fontsize. + """Set all chatpanels to new default fontname/fontsize. Returns current font settings in a (fontname, fontsize) tuple.""" if (fontname is not None): newfont = fontname else: newfont = self.font @@ -587,10 +580,10 @@ self.font = newfont self.fontsize = newfontsize return (self.font, self.fontsize) - - @debugging + + def build_menu(self): - top_frame = component.get('frame') + top_frame = component.get('frame') menu = wx.Menu() item = wx.MenuItem(menu, wx.ID_ANY, "&Background color", "Background color") top_frame.Bind(wx.EVT_MENU, self.OnMB_BackgroundColor, item) @@ -625,7 +618,7 @@ tabmenu = wx.Menu() toolmenu = wx.Menu() item = wx.MenuItem(wndmenu, wx.ID_ANY, "Show Images", "Show Images", wx.ITEM_CHECK) - top_frame.Bind(wx.EVT_MENU, self.OnMB_ShowImages, item) + top_frame.Bind(wx.EVT_MENU, self.OnMB_ShowImages, item) wndmenu.AppendItem(item) if self.settings.get_setting("Show_Images_In_Chat") == '1': item.Check(True) @@ -676,58 +669,58 @@ toolmenu.AppendItem(item) if self.settings.get_setting("AliasTool_On") == '1': item.Check(True) settingmenu.AppendMenu(wx.ID_ANY, 'Chat Tool Bars', toolmenu) - menu.AppendMenu(wx.ID_ANY, 'Chat Settings', settingmenu) + menu.AppendMenu(wx.ID_ANY, 'Chat Settings', settingmenu) top_frame.mainmenu.Insert(2, menu, '&Chat') - ## Settings Menu Events - @debugging + ## Settings Menu Events + def OnMB_ShowImages(self, event): if event.IsChecked(): self.settings.set_setting("Show_Images_In_Chat", '1') else: self.settings.set_setting("Show_Images_In_Chat", '0') - - @debugging + + def OnMB_StripHTML(self, event): if event.IsChecked(): self.settings.set_setting("Sstriphtml", '1') else: self.settings.set_setting("striphtml", '0') - - @debugging + + def OnMB_ChatTimeIndex(self, event): if event.IsChecked(): self.settings.set_setting("Chat_Time_Indexing", '1') else: self.settings.set_setting("Chat_Time_Indexing", '0') - - @debugging + + def OnMB_ChatAutoComplete(self, event): if event.IsChecked(): self.settings.set_setting("SuppressChatAutoComplete", '0') else: self.settings.set_setting("SuppressChatAutoComplete", '1') - - @debugging + + def OnMB_ShowIDinChat(self, event): if event.IsChecked(): self.settings.set_setting("ShowIDInChat", '1') else: self.settings.set_setting("ShowIDInChat", '0') - - @debugging + + def OnMB_LogTimeIndex(self, event): if event.IsChecked(): self.settings.set_setting("TimeStampGameLog", '1') else: self.settings.set_setting("TimeStampGameLog", '0') - - @debugging + + def OnMB_TabbedWhispers(self, event): if event.IsChecked(): self.settings.set_setting("tabbedwhispers", '1') else: self.settings.set_setting("tabbedwhispers", '0') - - @debugging + + def OnMB_GMTab(self, event): if event.IsChecked(): self.settings.set_setting("GMWhisperTab", '1') self.parent.create_gm_tab() else: self.settings.set_setting("GMWhisperTab", '0') - - @debugging + + def OnMB_GroupWhisperTabs(self, event): if event.IsChecked(): self.settings.set_setting("GroupWhisperTab", '1') else: self.settings.set_setting("GroupWhisperTab", '0') - - @debugging + + def OnMB_DiceBar(self, event): act = '0' if event.IsChecked(): @@ -740,8 +733,8 @@ for panel in self.parent.whisper_tabs: panel.toggle_dice(act) for panel in self.parent.group_tabs: panel.toggle_dice(act) for panel in self.parent.null_tabs: panel.toggle_dice(act) - - @debugging + + def OnMB_FormatButtons(self, event): act = '0' if event.IsChecked(): @@ -755,8 +748,8 @@ for panel in self.parent.whisper_tabs: panel.toggle_formating(act) for panel in self.parent.group_tabs: panel.toggle_formating(act) for panel in self.parent.null_tabs: panel.toggle_formating(act) - - @debugging + + def OnMB_AliasTool(self, event): act = '0' if event.IsChecked(): @@ -769,8 +762,8 @@ for panel in self.parent.whisper_tabs: panel.toggle_alias(act) for panel in self.parent.group_tabs: panel.toggle_alias(act) for panel in self.parent.null_tabs:panel.toggle_alias(act) - - @debugging + + def OnMB_BackgroundColor(self, event): top_frame = component.get('frame') hexcolor = self.get_color() @@ -791,8 +784,8 @@ top_frame.players.SetForegroundColour('black') top_frame.players.Refresh() self.chatwnd.scroll_down() - - @debugging + + def OnMB_TextColor(self, event): top_frame = component.get('frame') hexcolor = self.get_color() @@ -813,8 +806,8 @@ top_frame.players.SetForegroundColour('black') top_frame.players.Refresh() self.chatwnd.scroll_down() - - @debugging + + def get_hot_keys(self): # dummy menus for hotkeys self.build_menu() @@ -822,8 +815,8 @@ entries.append((wx.ACCEL_CTRL, ord('H'), self.setChatFocusMenu.GetId())) #entries.append((wx.ACCEL_CTRL, wx.WXK_TAB, SWAP_TABS)) return entries - - @debugging + + def forward_tabs(self, evt): self.parent.AdvanceSelection() @@ -832,18 +825,18 @@ # This subroutine builds the controls for the chat frame # - # !self : instance of self - @debugging + # !self : instance of self + def build_ctrls(self): self.chatwnd = chat_html_window(self,-1) self.set_colors() wx.CallAfter(self.chatwnd.SetPage, self.chatwnd.Header()) if (self.sendtarget == "all"): - wx.CallAfter(self.Post, self.colorize(self.syscolor, + wx.CallAfter(self.Post, self.colorize(self.syscolor, "<b>Welcome to <a href='http://www.openrpg.com'>OpenRPG</a> version " + self.version + "... </b>")) #self.chat_cmds.on_help() - self.chattxt = orpg.tools.predTextCtrl.predTextCtrl(self, -1, "", - style=wx.TE_PROCESS_ENTER |wx.TE_PROCESS_TAB|wx.TE_LINEWRAP, + self.chattxt = orpg.tools.predTextCtrl.predTextCtrl(self, -1, "", + style=wx.TE_PROCESS_ENTER |wx.TE_PROCESS_TAB|wx.TE_LINEWRAP, keyHook = self.myKeyHook, validator=None ) self.build_bar() self.basesizer = wx.BoxSizer(wx.VERTICAL) @@ -880,8 +873,8 @@ self.chattxt.Bind(wx.EVT_CHAR, self.chattxt.OnChar) self.chattxt.Bind(wx.EVT_TEXT_COPY, self.chatwnd.OnM_EditCopy) # def build_ctrls - end - - @debugging + + def build_bar(self): self.toolbar_sizer = wx.BoxSizer(wx.HORIZONTAL) self.scroll_lock = None @@ -892,52 +885,47 @@ self.build_dice() self.build_scroll() self.build_text() - self.toolbar_sizer.Add( self.textpop_lock, 0, wx.EXPAND ) - self.toolbar_sizer.Add(self.scroll_lock,0,wx.EXPAND) + self.toolbar_sizer.Add(self.textpop_lock, 0, wx.EXPAND) + self.toolbar_sizer.Add(self.scroll_lock, 0, wx.EXPAND) self.build_formating() self.build_colorbutton() - - @debugging + + def build_scroll(self): self.scroll_lock = wx.Button( self, wx.ID_ANY, "Scroll ON",size= wx.Size(80,25)) - - @debugging - def build_alias(self): + + + def build_alias(self): + self.aliasSizer = wx.BoxSizer(wx.HORIZONTAL) ## Future ## Add these to a sizer, then turn the toolbar_sizer into a grid so these can adjust to the frame. self.aliasList = wx.Choice(self, wx.ID_ANY, size=(100, 25), choices=[self.defaultAliasName]) - self.aliasButton = createMaskedButton( self, dir_struct["icon"] + 'player.gif', + self.aliasButton = createMaskedButton( self, dir_struct["icon"] + 'player.gif', 'Refresh list of aliases from Game Tree', wx.ID_ANY, '#bdbdbd' ) self.aliasList.SetSelection(0) self.filterList = wx.Choice(self, wx.ID_ANY, size=(100, 25), choices=[self.defaultFilterName]) - self.filterButton = createMaskedButton( self, dir_struct["icon"] + 'add_filter.gif', + self.filterButton = createMaskedButton( self, dir_struct["icon"] + 'add_filter.gif', 'Refresh list of filters from Game Tree', wx.ID_ANY, '#bdbdbd' ) - self.filterList.SetSelection(0) - self.toolbar_sizer.Add( self.aliasButton, 0, wx.EXPAND ) - self.toolbar_sizer.Add( self.aliasList,0,wx.EXPAND) - self.toolbar_sizer.Add( self.filterButton, 0, wx.EXPAND ) - self.toolbar_sizer.Add( self.filterList,0,wx.EXPAND) + self.filterList.SetSelection(0) + + self.aliasSizer.Add( self.aliasButton, 0, wx.EXPAND ) + self.aliasSizer.Add( self.aliasList,0,wx.EXPAND) + self.aliasSizer.Add( self.filterButton, 0, wx.EXPAND ) + self.aliasSizer.Add( self.filterList,0,wx.EXPAND) + + self.toolbar_sizer.Add(self.aliasSizer, 0, wx.EXPAND) + if self.settings.get_setting('AliasTool_On') == '0': self.toggle_alias('0') else: self.toggle_alias('1') - - @debugging - def toggle_alias(self, act): - if act == '0': - self.toolbar_sizer.Show(self.aliasList, False) - self.toolbar_sizer.Show(self.filterList, False) - self.toolbar_sizer.Show(self.aliasButton, False) - self.toolbar_sizer.Show(self.filterButton, False) - self.toolbar_sizer.Layout() - else: - self.toolbar_sizer.Show(self.aliasList, True) - self.toolbar_sizer.Show(self.filterList, True) - self.toolbar_sizer.Show(self.aliasButton, True) - self.toolbar_sizer.Show(self.filterButton, True) - self.toolbar_sizer.Layout() - - @debugging + + + def toggle_alias(self, act): + if act == '0': self.toolbar_sizer.Show(self.aliasSizer, False) + else: self.toolbar_sizer.Show(self.aliasSizer, True) + self.toolbar_sizer.Layout() + def build_text(self): self.textpop_lock = createMaskedButton(self, dir_struct["icon"]+'note.gif', 'Open Text View Of Chat Session', wx.ID_ANY, '#bdbdbd') - - @debugging + + def build_dice(self): self.numDieText = wx.TextCtrl( self, wx.ID_ANY, "1", size= wx.Size(25, 25), validator=orpg.tools.inputValidator.MathOnlyValidator() ) self.dieModText = wx.TextCtrl( self, wx.ID_ANY, "", size= wx.Size(50, 25), validator=orpg.tools.inputValidator.MathOnlyValidator() ) @@ -959,8 +947,8 @@ self.toolbar_sizer.Add( self.dieModText, 0, wx.ALIGN_CENTER, 5 ) if self.settings.get_setting('DiceButtons_On') == '0': self.toggle_dice('0') else: self.toggle_dice('1') - - @debugging + + def toggle_dice(self, act): if act == '0': self.toolbar_sizer.Show(self.numDieText, False) @@ -984,22 +972,22 @@ self.toolbar_sizer.Show(self.d100Button, True) self.toolbar_sizer.Show(self.dieModText, True) self.toolbar_sizer.Layout() - - @debugging + + def build_formating(self): - self.boldButton = createMaskedButton( self, dir_struct["icon"]+'bold.gif', + self.boldButton = createMaskedButton( self, dir_struct["icon"]+'bold.gif', 'Make the selected text Bold', wx.ID_ANY, '#bdbdbd') - self.italicButton = createMaskedButton( self, dir_struct["icon"]+'italic.gif', + self.italicButton = createMaskedButton( self, dir_struct["icon"]+'italic.gif', 'Italicize the selected text', wx.ID_ANY, '#bdbdbd' ) - self.underlineButton = createMaskedButton( self, dir_struct["icon"]+'underlined.gif', + self.underlineButton = createMaskedButton( self, dir_struct["icon"]+'underlined.gif', 'Underline the selected text', wx.ID_ANY, '#bdbdbd' ) self.toolbar_sizer.Add( self.boldButton, 0, wx.EXPAND ) self.toolbar_sizer.Add( self.italicButton, 0, wx.EXPAND ) self.toolbar_sizer.Add( self.underlineButton, 0, wx.EXPAND ) if self.settings.get_setting('FormattingButtons_On') == '0': self.toggle_formating('0') else: self.toggle_formating('1') - - @debugging + + def toggle_formating(self, act): if act == '0': self.toolbar_sizer.Show(self.boldButton, False) @@ -1012,21 +1000,21 @@ self.toolbar_sizer.Show(self.underlineButton, True) self.toolbar_sizer.Layout() - # Heroman - Ideally, we would use static labels... - @debugging + # Heroman - Ideally, we would use static labels... + def build_colorbutton(self): - self.color_button = createMaskedButton(self, dir_struct["icon"]+'textcolor.gif', - 'Text Color', wx.ID_ANY, '#bdbdbd', - wx.BITMAP_TYPE_GIF) + self.color_button = createMaskedButton(self, dir_struct["icon"]+'textcolor.gif', + 'Text Color', wx.ID_ANY, '#bdbdbd', + wx.BITMAP_TYPE_GIF) - self.saveButton = createMaskedButton(self, dir_struct["icon"]+'save.bmp', - 'Save the chatbuffer', wx.ID_ANY, - '#c0c0c0', wx.BITMAP_TYPE_BMP ) + self.saveButton = createMaskedButton(self, dir_struct["icon"]+'save.bmp', + 'Save the chatbuffer', wx.ID_ANY, + '#c0c0c0', wx.BITMAP_TYPE_BMP ) self.color_button.SetBackgroundColour(self.settings.get_setting('mytextcolor')) self.toolbar_sizer.Add(self.color_button, 0, wx.EXPAND) - self.toolbar_sizer.Add(self.saveButton, 0, wx.EXPAND) - - @debugging + self.toolbar_sizer.Add(self.saveButton, 0, wx.EXPAND) + + def OnMotion(self, evt): contain = self.chatwnd.GetInternalRepresentation() if contain: @@ -1051,8 +1039,8 @@ # # self: duh - # event: raw KeyEvent from OnChar() - @debugging + # event: raw KeyEvent from OnChar() + def myKeyHook(self, event): if self.session.get_status() == MPLAY_CONNECTED: # only do if we're connected thisPress = time.time() # thisPress is local temp variable @@ -1071,8 +1059,8 @@ # This subroutine gets called once a second by the typing Timer # It checks if we need to send a not_typing message # - # self: duh - @debugging + # self: duh + def typingTimerFunc(self, event): #following added by mDuo13 ##############refresh_counter()############## @@ -1093,9 +1081,9 @@ # This subroutine actually takes care of sending the messages for typing/not_typing events # # self: duh - # typing: boolean - - @debugging + # typing: boolean + + def sendTyping(self, typing): if typing: self.lastSend = time.time() # remember our send time for use in myKeyHook() @@ -1113,8 +1101,8 @@ # This subroutine sets the colors of the chat based on the settings in the # self instance. # - # !self : instance of self - @debugging + # !self : instance of self + def set_colors(self): # chat window backround color self.bgcolor = self.settings.get_setting('bgcolor') @@ -1135,20 +1123,20 @@ # This subroutine will insert text into the chat window # # !self : instance of self - # !txt : text to be inserted into the chat window - @debugging + # !txt : text to be inserted into the chat window + def set_chat_text(self, txt): self.chattxt.SetValue(txt) self.chattxt.SetFocus() self.chattxt.SetInsertionPointEnd() # def set_chat_text - end - - @debugging + + def get_chat_text(self): return self.chattxt.GetValue() - # This subroutine sets the focus to the chat window - @debugging + # This subroutine sets the focus to the chat window + def set_chat_text_focus(self, event): wx.CallAfter(self.chattxt.SetFocus) # def set_chat_text_focus - end @@ -1160,8 +1148,8 @@ # !event : # # Note: self.chattxt now handles it's own Key events. It does, however still - # call it's parent's (self) OnChar to handle "default" behavior. - @debugging + # call it's parent's (self) OnChar to handle "default" behavior. + def OnChar(self, event): s = self.chattxt.GetValue() #self.histlen = len(self.history) - 1 @@ -1174,18 +1162,18 @@ if self.session.get_status() == MPLAY_CONNECTED: # only do if we're connected self.sendTyping(0) # Send a "not_typing" event on enter key press macroText="" - recycle_bin = {wx.WXK_F1: 'event.GetKeyCode() == wx.WXK_F1', wx.WXK_F2: 'event.GetKeyCode() == wx.WXK_F2', - wx.WXK_F3: 'event.GetKeyCode() == wx.WXK_F3', wx.WXK_F4: 'event.GetKeyCode() == wx.WXK_F4', - wx.WXK_F5: 'event.GetKeyCode() == wx.WXK_F5', wx.WXK_F6: 'event.GetKeyCode() == wx.WXK_F6', - wx.WXK_F7: 'event.GetKeyCode() == wx.WXK_F7', wx.WXK_F8: 'event.GetKeyCode() == wx.WXK_F8', - wx.WXK_F9: 'event.GetKeyCode() == wx.WXK_F9', wx.WXK_F10: 'event.GetKeyCode() == wx.WXK_F10', - wx.WXK_F11: 'event.GetKeyCode() == wx.WXK_F11', wx.WXK_F12: 'event.GetKeyCode() == wx.WXK_F12'} - - bin_event = event.GetKeyCode() - if recycle_bin.has_key(bin_event): - logger.debug(lambda bin_event: recycle_bin[bin_event]) - macroText = self.settings.get_setting(recycle_bin[bin_event][29:]) - recycle_bin = {}; del bin_event + recycle_bin = {wx.WXK_F1: 'event.GetKeyCode() == wx.WXK_F1', wx.WXK_F2: 'event.GetKeyCode() == wx.WXK_F2', + wx.WXK_F3: 'event.GetKeyCode() == wx.WXK_F3', wx.WXK_F4: 'event.GetKeyCode() == wx.WXK_F4', + wx.WXK_F5: 'event.GetKeyCode() == wx.WXK_F5', wx.WXK_F6: 'event.GetKeyCode() == wx.WXK_F6', + wx.WXK_F7: 'event.GetKeyCode() == wx.WXK_F7', wx.WXK_F8: 'event.GetKeyCode() == wx.WXK_F8', + wx.WXK_F9: 'event.GetKeyCode() == wx.WXK_F9', wx.WXK_F10: 'event.GetKeyCode() == wx.WXK_F10', + wx.WXK_F11: 'event.GetKeyCode() == wx.WXK_F11', wx.WXK_F12: 'event.GetKeyCode() == wx.WXK_F12'} + + bin_event = event.GetKeyCode() + if recycle_bin.has_key(bin_event): + logger.debug(lambda bin_event: recycle_bin[bin_event]) + macroText = self.settings.get_setting(recycle_bin[bin_event][29:]) + recycle_bin = {}; del bin_event # Append to the existing typed text as needed and make sure the status doesn't change back. if len(macroText): @@ -1301,8 +1289,8 @@ else: event.Skip() logger.debug("Exit chat_panel->OnChar(self, event)") # def OnChar - end - - @debugging + + def onDieRoll(self, evt): """Roll the dice based on the button pressed and the die modifiers entered, if any.""" # Get any die modifiers if they have been entered @@ -1322,8 +1310,8 @@ # FileDialog. # # !self : instance of self - # !evt : - @debugging + # !evt : + def on_chat_save(self, evt): f = wx.FileDialog(self,"Save Chat Buffer",".","","HTM* (*.htm*)|*.htm*|HTML (*.html)|*.html|HTM (*.htm)|*.htm",wx.SAVE) if f.ShowModal() == wx.ID_OK: @@ -1333,20 +1321,20 @@ f.Destroy() os.chdir(dir_struct["home"]) # def on_chat_save - end - - @debugging + + def ResetPage(self): self.set_colors() buffertext = self.chatwnd.Header() + "\n" - buffertext += chat_util.strip_body_tags(self.chatwnd.StripHeader()).replace("<br>", - "<br />").replace('</html>', - '').replace("<br />", + buffertext += chat_util.strip_body_tags(self.chatwnd.StripHeader()).replace("<br>", + "<br />").replace('</html>', + '').replace("<br />", "<br />\n").replace("\n\n", '') return buffertext # This subroutine sets the color of selected text, or base text color if - # nothing is selected - @debugging + # nothing is selected + def on_text_color(self, event): hexcolor = self.r_h.do_hex_color_dlg(self) if hexcolor != None: @@ -1369,8 +1357,8 @@ # # !self : instance of self # !color : color for the text to be set - # !text : text string to be included in the html. - @debugging + # !text : text string to be included in the html. + def colorize(self, color, text): """Puts font tags of 'color' around 'text' value, and returns the string""" return "<font color='" + color + "'>" + text + "</font>" @@ -1380,8 +1368,8 @@ # tags included. # # !self : instance of self - # !event : - @debugging + # !event : + def on_text_format(self, event): id = event.GetId() txt = self.chattxt.GetValue() @@ -1397,8 +1385,8 @@ self.chattxt.SetInsertionPointEnd() self.chattxt.SetFocus() # def on_text_format - end - - @debugging + + def lock_scroll(self, event): if self.lockscroll: self.lockscroll = False @@ -1414,8 +1402,8 @@ # This subroutine will popup a text window with the chatbuffer contents # # !self : instance of self - # !event : - @debugging + # !event : + def pop_textpop(self, event): """searchable popup text view of chatbuffer""" h_buffertext = self.ResetPage() @@ -1425,44 +1413,44 @@ # This subroutine will change the dimension of the window # # !self : instance of self - # !event : - @debugging + # !event : + def OnSize(self, event=None): event.Skip() wx.CallAfter(self.scroll_down) # def OnSize - end - - @debugging + + def scroll_down(self): self.Freeze() self.chatwnd.scroll_down() self.Thaw() - ###### message helpers ###### - @debugging + ###### message helpers ###### + def PurgeChat(self): self.set_colors() self.chatwnd.SetPage(self.chatwnd.Header()) - - @debugging + + def system_message(self, text): self.send_chat_message(text,chat_msg.SYSTEM_MESSAGE) self.SystemPost(text) - - @debugging + + def info_message(self, text): self.send_chat_message(text,chat_msg.INFO_MESSAGE) self.InfoPost(text) - - @debugging + + def get_gms(self): the_gms = [] for playerid in self.session.players: if len(self.session.players[playerid])>7: if self.session.players[playerid][7]=="GM" and self.session.group_id != '0': the_gms += [playerid] return the_gms - - @debugging + + def GetName(self): self.AliasLib = component.get('alias') player = self.session.get_my_info() @@ -1472,8 +1460,8 @@ logger.debug("Exit chat_panel->GetName(self)") return [self.chat_display_name([self.AliasLib.alias[0], player[1], player[2]]), self.AliasLib.alias[1]] return [self.chat_display_name(player), "Default"] - - @debugging + + def GetFilteredText(self, text): advregex = re.compile('\"(.*?)\"', re.I) self.AliasLib = component.get('alias') @@ -1487,12 +1475,12 @@ newmatch = re.sub(rule[0], rule[1], match) text = text.replace(match, newmatch) return text - - @debugging + + def emote_message(self, text): text = self.NormalizeParse(text) text = self.colorize(self.emotecolor, text) - + if self.type == MAIN_TAB and self.sendtarget == 'all': self.send_chat_message(text,chat_msg.EMOTE_MESSAGE) elif self.type == MAIN_TAB and self.sendtarget == "gm": msg_type = chat_msg.WHISPER_EMOTE_MESSAGE @@ -1506,8 +1494,8 @@ name = self.GetName()[0] text = "** " + name + " " + text + " **" self.EmotePost(text) - - @debugging + + def whisper_to_players(self, text, player_ids): tabbed_whispers_p = self.settings.get_setting("tabbedwhispers") # Heroman - apply any filtering selected @@ -1533,8 +1521,8 @@ id = id.strip() if self.session.is_valid_id(id): self.send_chat_message(text,chat_msg.WHISPER_MESSAGE,id) else: self.InfoPost(id + " Unknown!") - - @debugging + + def send_chat_message(self, text, type=chat_msg.CHAT_MESSAGE, player_id="all"): #########send_msg()############# send = 1 @@ -1558,9 +1546,9 @@ msg.set_alias(playername) if send: self.session.send(msg.toxml(),player_id) del msg - - #### incoming chat message handler ##### - @debugging + + #### incoming chat message handler ##### + def post_incoming_msg(self, msg, player): # pull data @@ -1683,21 +1671,21 @@ if sound_file != '': component.get('sound').play(sound_file) #### Posting helpers ##### - - @debugging + + def InfoPost(self, s): self.Post(self.colorize(self.infocolor, s), c='info') - - @debugging + + def SystemPost(self, s): self.Post(self.colorize(self.syscolor, s), c='system') - - @debugging + + def EmotePost(self, s): self.Post(self.colorize(self.emotecolor, s), c='emote') - #### Standard Post method ##### - @debugging + #### Standard Post method ##### + def Post(self, s="", send=False, myself=False, c='post'): strip_p = self.settings.get_setting("striphtml") strip_img = self.settings.get_setting("Show_Images_In_Chat")#moved back 7-11-05. --mDuo13 @@ -1707,7 +1695,7 @@ s = chat_util.strip_script_tags(s) s = chat_util.strip_li_tags(s) s = chat_util.strip_body_tags(s) #7-27-05 mDuo13 - s = chat_util.strip_misalignment_tags(s) #7-27-05 mDuo13 + s = chat_util.strip_misalignment_tags(s) #7-27-05 mDuo13 aliasInfo = self.GetName() display_name = aliasInfo[0] if aliasInfo[1] != 'Default': @@ -1767,7 +1755,7 @@ newline = "<div class='"+c+"'> " + self.TimeIndexString() + name + s2 + "</div>" log( self.settings, c, name+s2 ) else: - newline = "<div class='"+c+"'> " + self.TimeIndexString() + name + s + "</div>" + newline = "<div class='"+c+"'> " + self.TimeIndexString() + name + s + "</div>" log( self.settings, c, name+s ) else: send = False newline = component.get('xml').strip_unicode(newline) @@ -1793,8 +1781,8 @@ # TimeIndexString() # # time indexing for chat display only (don't log time indexing) - # added by Snowdog 4/04 - @debugging + # added by Snowdog 4/04 + def TimeIndexString(self): try: mtime = "" @@ -1807,15 +1795,15 @@ logger.general("EXCEPTION: " + str(e)) return "[ERROR]" - #### Post with parsing dice #### - @debugging + #### Post with parsing dice #### + def ParsePost(self, s, send=False, myself=False): s = self.NormalizeParse(s) self.set_colors() self.Post(s,send,myself) - - @debugging - def NormalizeParse(self, s): + + + def NormalizeParse(self, s): for plugin_fname in self.activeplugins.keys(): plugin = self.activeplugins[plugin_fname] try: s = plugin.pre_parse(s) @@ -1829,31 +1817,30 @@ s = self.ParseFilter(s) self.parsed = 1 return s - - @debugging - def ParseFilter(self, s): + + + def ParseFilter(self, s): s = self.GetFilteredText(s) return s - - @debugging - def ParseNode(self, s): + + def ParseNode(self, s): """Parses player input for embedded nodes rolls""" cur_loc = 0 #[a-zA-Z0-9 _\-\.] - reg = re.compile("(!@([a-zA-Z0-9 _\-\./]+(::[a-zA-Z0-9 _\-\./]+)*)@!)") + reg = re.compile("(!@(.*?)@!)") matches = reg.findall(s) for i in xrange(0,len(matches)): newstr = self.ParseNode(self.resolve_nodes(matches[i][1])) s = s.replace(matches[i][0], newstr, 1) return s - - @debugging - def ParseDice(self, s): + + + def ParseDice(self, s): """Parses player input for embedded dice rolls""" reg = re.compile("\[([^]]*?)\]") matches = reg.findall(s) for i in xrange(0,len(matches)): - newstr = self.PraseUnknowns(matches[i]) + newstr = self.PraseUnknowns(matches[i]) qmode = 0 newstr1 = newstr if newstr[0].lower() == 'q': @@ -1865,9 +1852,9 @@ s = s.replace("[" + matches[i] + "]", "<!-- Official Roll [" + newstr1 + "] => " + newstr + "-->" + newstr, 1) else: s = s.replace("[" + matches[i] + "]", "[" + newstr1 + "<!-- Official Roll -->] => " + newstr, 1) return s - - @debugging - def PraseUnknowns(self, s): + + + def PraseUnknowns(self, s): # Uses a tuple. Usage: ?Label}dY. If no Label is assigned then use ?}DY newstr = "0" reg = re.compile("(\?\{*)([a-zA-Z ]*)(\}*)") @@ -1884,22 +1871,22 @@ if newstr == '': newstr = '0' s = s.replace(matches[i][0], newstr, 1).replace(matches[i][1], '', 1).replace(matches[i][2], '', 1) dlg.Destroy() - return s + return s # This subroutine builds a chat display name. - # - @debugging - def chat_display_name(self, player): + # + + def chat_display_name(self, player): if self.settings.get_setting("ShowIDInChat") == "0": display_name = player[0] else: display_name = "("+player[2]+") " + player[0] return display_name - + # This subroutine will get a hex color and return it, or return nothing - # - @debugging - def get_color(self): + # + + def get_color(self): data = wx.ColourData() data.SetChooseFull(True) dlg = wx.ColourDialog(self, data) @@ -1913,8 +1900,8 @@ dlg.Destroy() return None # def get_color - end - - @debugging + + def replace_quotes(self, s): in_tag = 0 i = 0 @@ -1929,49 +1916,51 @@ if in_tag: rs = rs[:i] + "'" + rs[i+1:] i += 1 - return rs + return rs + + def resolve_loop(self, node, path, step, depth): + if step == depth: + self.resolution(node) + else: + child_list = node.findall('nodehandler') + for child in child_list: + if step == depth: break + if child.get('name') == path[step]: + node = child + step += 1 + self.resolve_loop(node, path, step, depth) - @debugging - def resolve_loop(self, dom, nodeName, doLoop = False): - for node in dom: - if node._get_tagName() != 'nodehandler': - continue - if doLoop and node.getAttribute('class') != 'textctrl_handler' and node.hasChildNodes(): - (found, node) = self.resolve_loop(node.getChildren(), nodeName, doLoop) - if not found: - continue - if node.getAttribute('name') != nodeName: - continue - foundNode = node - return (True, foundNode) - return (False, '') + def resolution(self, node): + if self.passed == False: + self.passed = True + if node.get('class') == 'textctrl_handler': self.data = str(node.find('text').text) + else: self.data = 'Nodehandler for '+ node.get('class') + ' not done!' or 'No Data!' + else: + self.data = '' + pass + self.data = self.ParseMap(self.data, node) + + def ParseMap(self, s, node): + """Parses player input for embedded nodes rolls""" + cur_loc = 0 + reg = re.compile("(!!(.*?)!!)") + matches = reg.findall(s) + print matches + for i in xrange(0,len(matches)): + newstr = txt = '!@' + node.get('map') + '::' + matches[i][1] + '@!' + s = s.replace(matches[i][0], newstr, 1) + s = self.ParseNode(s) + return s - @debugging - def resolve_nodes(self, s): + def resolve_nodes(self, s): + self.passed = False + self.data = 'No Data!' value = "" - node_path_list = s.split("::") - gametree = component.get('tree') - dom = gametree.master_dom.getChildren() - for nodeName in node_path_list: - (found, node) = self.resolve_loop(dom, nodeName) - if not found: - break - dom = node.getChildren() - if not found: - dom = gametree.master_dom.getChildren() - loop = False - if len(node_path_list) == 1: - loop = True - for nodeName in node_path_list: - (found, node) = self.resolve_loop(dom, nodeName, loop) - if not found: - break - dom = node.getChildren() - loop = True - if found: - text = node.getElementsByTagName('text') - node = text[0]._get_firstChild() - value = node._get_nodeValue() - else: - value = s - return value + path = s.split('::') + depth = len(path) + self.gametree = component.get('tree') + dom = self.gametree.xml_root.getchildren() + for node in dom: + if node.get('name') == path[0]: + self.resolve_loop(node, path, 1, len(path)) + return self.data