comparison 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
comparison
equal deleted inserted replaced
101:394ebb3b6a0f 135:dcf4fbe09b70
41 41
42 42
43 ## 43 ##
44 ## Module Loading 44 ## Module Loading
45 ## 45 ##
46 import os, time, re, sys, traceback, webbrowser, commands, chat_msg, chat_util
47
48 from orpg.orpg_version import VERSION
46 from orpg.orpg_windows import * 49 from orpg.orpg_windows import *
47 from orpg.player_list import WG_LIST 50 from orpg.player_list import WG_LIST
48 from orpg.dirpath import dir_struct 51 from orpg.dirpath import dir_struct
52 #from orpg.tools.metamenus import MenuEx #Needed?
53 from string import *
54
55 import cStringIO # for reading inline imagedata as a stream
56 from HTMLParser import HTMLParser
57 from wx.lib.expando import EVT_ETC_LAYOUT_NEEDED
58
49 import orpg.tools.rgbhex 59 import orpg.tools.rgbhex
50 import orpg.tools.inputValidator 60 import orpg.tools.inputValidator
51 #from orpg.tools.metamenus import MenuEx #Needed?
52
53 import webbrowser
54 from string import *
55 from orpg.orpg_version import VERSION
56 import commands
57 import chat_msg
58 import time
59 import orpg.tools.predTextCtrl
60 from orpg.networking.mplay_client import MPLAY_CONNECTED # needed to only send typing/not_typing messages while connected
61 import os
62 import time
63 import re
64 import sys
65 import cStringIO # for reading inline imagedata as a stream
66 from HTMLParser import HTMLParser
67 import chat_util
68 import traceback
69 from wx.lib.expando import EVT_ETC_LAYOUT_NEEDED
70
71 from orpg.tools.validate import validate 61 from orpg.tools.validate import validate
72 from orpg.tools.orpg_settings import settings 62 from orpg.tools.orpg_settings import settings
63 import orpg.tools.predTextCtrl
64 from orpg.tools.orpg_log import logger, debug
73 from orpg.orpgCore import component 65 from orpg.orpgCore import component
74 from orpg.tools.orpg_log import logger 66 from xml.etree.ElementTree import tostring
75 from orpg.tools.decorators import debugging 67
68 from orpg.networking.mplay_client import MPLAY_CONNECTED # needed to only send typing/not_typing messages while connected
76 69
77 NEWCHAT = False 70 NEWCHAT = False
78 try: 71 try:
79 import wx.webview 72 import wx.webview
80 NEWCHAT = True 73 NEWCHAT = True
83 76
84 # Global parser for stripping HTML tags: 77 # Global parser for stripping HTML tags:
85 # The 'tag stripping' is implicit, because this parser echoes every 78 # The 'tag stripping' is implicit, because this parser echoes every
86 # type of html data *except* the tags. 79 # type of html data *except* the tags.
87 class HTMLStripper(HTMLParser): 80 class HTMLStripper(HTMLParser):
88 @debugging 81
89 def __init__(self): 82 def __init__(self):
90 self.accum = "" 83 self.accum = ""
91 self.special_tags = ['hr', 'br', 'img'] 84 self.special_tags = ['hr', 'br', 'img']
92 @debugging 85
93 def handle_data(self, data): # quote cdata literally 86 def handle_data(self, data): # quote cdata literally
94 self.accum += data 87 self.accum += data
95 @debugging 88
96 def handle_entityref(self, name): # entities must be preserved exactly 89 def handle_entityref(self, name): # entities must be preserved exactly
97 self.accum += "&" + name + ";" 90 self.accum += "&" + name + ";"
98 @debugging 91
99 def handle_starttag(self, tag, attrs): 92 def handle_starttag(self, tag, attrs):
100 if tag in self.special_tags: 93 if tag in self.special_tags:
101 self.accum += '<' + tag 94 self.accum += '<' + tag
102 for attrib in attrs: self.accum += ' ' + attrib[0] + '="' + attrib[1] + '"' 95 for attrib in attrs: self.accum += ' ' + attrib[0] + '="' + attrib[1] + '"'
103 self.accum += '>' 96 self.accum += '>'
104 @debugging 97
105 def handle_charref(self, name): # charrefs too 98 def handle_charref(self, name): # charrefs too
106 self.accum += "&#" + name + ";" 99 self.accum += "&#" + name + ";"
107 htmlstripper = HTMLStripper() 100 htmlstripper = HTMLStripper()
108 101
109 # utility function; see Post(). 102 # utility function; see Post().
110 @debugging 103
111 def strip_html(string): 104 def strip_html(string):
112 "Return string tripped of html tags." 105 "Return string tripped of html tags."
113 htmlstripper.reset() 106 htmlstripper.reset()
114 htmlstripper.accum = "" 107 htmlstripper.accum = ""
115 htmlstripper.feed(string) 108 htmlstripper.feed(string)
116 htmlstripper.close() 109 htmlstripper.close()
117 return htmlstripper.accum 110 return htmlstripper.accum
118 111
119 @debugging 112
120 def log( settings, c, text ): 113 def log( settings, c, text ):
121 filename = settings.get_setting('GameLogPrefix') 114 filename = settings.get_setting('GameLogPrefix')
122 if filename > '' and filename[0] != commands.ANTI_LOG_CHAR: 115 if filename > '' and filename[0] != commands.ANTI_LOG_CHAR:
123 filename = filename + time.strftime( '-%Y-%m-%d.html', time.localtime( time.time() ) ) 116 filename = filename + time.strftime( '-%Y-%m-%d.html', time.localtime( time.time() ) )
124 #filename = time.strftime( filename, time.localtime( time.time() ) ) 117 #filename = time.strftime( filename, time.localtime( time.time() ) )
146 # initialization subroutine 139 # initialization subroutine
147 # 140 #
148 # !self : instance of self 141 # !self : instance of self
149 # !parent : 142 # !parent :
150 # !id : 143 # !id :
151 @debugging 144
152 def __init__(self, parent, id): 145 def __init__(self, parent, id):
153 wx.html.HtmlWindow.__init__(self, parent, id, 146 wx.html.HtmlWindow.__init__(self, parent, id,
154 style=wx.SUNKEN_BORDER|wx.html.HW_SCROLLBAR_AUTO|wx.NO_FULL_REPAINT_ON_RESIZE) 147 style=wx.SUNKEN_BORDER|wx.html.HW_SCROLLBAR_AUTO|wx.NO_FULL_REPAINT_ON_RESIZE)
155 self.parent = parent 148 self.parent = parent
156 self.build_menu() 149 self.build_menu()
157 self.Bind(wx.EVT_LEFT_UP, self.LeftUp) 150 self.Bind(wx.EVT_LEFT_UP, self.LeftUp)
158 self.Bind(wx.EVT_RIGHT_DOWN, self.onPopup) 151 self.Bind(wx.EVT_RIGHT_DOWN, self.onPopup)
159 if "gtk2" in wx.PlatformInfo: self.SetStandardFonts() 152 if "gtk2" in wx.PlatformInfo: self.SetStandardFonts()
160 # def __init__ - end 153 # def __init__ - end
161 154
162 @debugging 155
163 def onPopup(self, evt): 156 def onPopup(self, evt):
164 self.PopupMenu(self.menu) 157 self.PopupMenu(self.menu)
165 158
166 @debugging 159
167 def LeftUp(self, event): 160 def LeftUp(self, event):
168 event.Skip() 161 event.Skip()
169 wx.CallAfter(self.parent.set_chat_text_focus, None) 162 wx.CallAfter(self.parent.set_chat_text_focus, None)
170 163
171 @debugging 164
172 def build_menu(self): 165 def build_menu(self):
173 self.menu = wx.Menu() 166 self.menu = wx.Menu()
174 item = wx.MenuItem(self.menu, wx.ID_ANY, "Copy", "Copy") 167 item = wx.MenuItem(self.menu, wx.ID_ANY, "Copy", "Copy")
175 self.Bind(wx.EVT_MENU, self.OnM_EditCopy, item) 168 self.Bind(wx.EVT_MENU, self.OnM_EditCopy, item)
176 self.menu.AppendItem(item) 169 self.menu.AppendItem(item)
177 170
178 @debugging 171
179 def OnM_EditCopy(self, evt): 172 def OnM_EditCopy(self, evt):
180 wx.TheClipboard.UsePrimarySelection(False) 173 wx.TheClipboard.UsePrimarySelection(False)
181 wx.TheClipboard.Open() 174 wx.TheClipboard.Open()
182 wx.TheClipboard.SetData(wx.TextDataObject(self.SelectionToText())) 175 wx.TheClipboard.SetData(wx.TextDataObject(self.SelectionToText()))
183 wx.TheClipboard.Close() 176 wx.TheClipboard.Close()
184 177
185 @debugging 178
186 def scroll_down(self): 179 def scroll_down(self):
187 maxrange = self.GetScrollRange(wx.VERTICAL) 180 maxrange = self.GetScrollRange(wx.VERTICAL)
188 pagesize = self.GetScrollPageSize(wx.VERTICAL) 181 pagesize = self.GetScrollPageSize(wx.VERTICAL)
189 self.Scroll(-1, maxrange-pagesize) 182 self.Scroll(-1, maxrange-pagesize)
190 183
191 @debugging 184
192 def mouse_wheel(self, event): 185 def mouse_wheel(self, event):
193 amt = event.GetWheelRotation() 186 amt = event.GetWheelRotation()
194 units = amt/(-(event.GetWheelDelta())) 187 units = amt/(-(event.GetWheelDelta()))
195 self.ScrollLines(units*3) 188 self.ScrollLines(units*3)
196 189
197 @debugging 190
198 def Header(self): 191 def Header(self):
199 return '<html><body bgcolor="' + self.parent.bgcolor + '" text="' + self.parent.textcolor + '">' 192 return '<html><body bgcolor="' + self.parent.bgcolor + '" text="' + self.parent.textcolor + '">'
200 193
201 @debugging 194
202 def StripHeader(self): 195 def StripHeader(self):
203 return self.GetPageSource().replace(self.Header(), '') 196 return self.GetPageSource().replace(self.Header(), '')
204 197
205 @debugging 198
206 def GetPageSource(self): 199 def GetPageSource(self):
207 return self.GetParser().GetSource() 200 return self.GetParser().GetSource()
208 201
209 # This subroutine fires up the webbrowser when a link is clicked. 202 # This subroutine fires up the webbrowser when a link is clicked.
210 # 203 #
211 # !self : instance of self 204 # !self : instance of self
212 # !linkinfo : instance of a class that contains the link information 205 # !linkinfo : instance of a class that contains the link information
213 @debugging 206
214 def OnLinkClicked(self, linkinfo): 207 def OnLinkClicked(self, linkinfo):
215 href = linkinfo.GetHref() 208 href = linkinfo.GetHref()
216 wb = webbrowser.get() 209 wb = webbrowser.get()
217 wb.open(href) 210 wb.open(href)
218 # def OnLinkClicked - end 211 # def OnLinkClicked - end
219 212
220 @debugging 213
221 def CalculateAllFonts(self, defaultsize): 214 def CalculateAllFonts(self, defaultsize):
222 return [int(defaultsize * 0.4), 215 return [int(defaultsize * 0.4),
223 int(defaultsize * 0.7), 216 int(defaultsize * 0.7),
224 int(defaultsize), 217 int(defaultsize),
225 int(defaultsize * 1.3), 218 int(defaultsize * 1.3),
226 int(defaultsize * 1.7), 219 int(defaultsize * 1.7),
227 int(defaultsize * 2), 220 int(defaultsize * 2),
228 int(defaultsize * 2.5)] 221 int(defaultsize * 2.5)]
229 222
230 @debugging 223
231 def SetDefaultFontAndSize(self, fontname, fontsize): 224 def SetDefaultFontAndSize(self, fontname, fontsize):
232 """Set 'fontname' to the default chat font. 225 """Set 'fontname' to the default chat font.
233 Returns current font settings in a (fontname, fontsize) tuple.""" 226 Returns current font settings in a (fontname, fontsize) tuple."""
234 self.SetFonts(fontname, "", self.CalculateAllFonts(int(fontsize))) 227 self.SetFonts(fontname, "", self.CalculateAllFonts(int(fontsize)))
235 return (self.GetFont().GetFaceName(), self.GetFont().GetPointSize()) 228 return (self.GetFont().GetFaceName(), self.GetFont().GetPointSize())
236 229
237 # class chat_html_window - end 230 # class chat_html_window - end
238 if NEWCHAT: 231 if NEWCHAT:
239 class ChatHtmlWindow(wx.webview.WebView): 232 class ChatHtmlWindow(wx.webview.WebView):
240 @debugging 233
241 def __init__(self, parent, id): 234 def __init__(self, parent, id):
242 wx.webview.WebView.__init__(self, parent, id) 235 wx.webview.WebView.__init__(self, parent, id)
243 self.parent = parent 236 self.parent = parent
244 self.__font = wx.Font(10, wx.FONTFAMILY_ROMAN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, faceName='Ariel') 237 self.__font = wx.Font(10, wx.FONTFAMILY_ROMAN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, faceName='Ariel')
245 self.build_menu() 238 self.build_menu()
246 self.Bind(wx.EVT_LEFT_UP, self.LeftUp) 239 self.Bind(wx.EVT_LEFT_UP, self.LeftUp)
247 self.Bind(wx.EVT_RIGHT_DOWN, self.onPopup) 240 self.Bind(wx.EVT_RIGHT_DOWN, self.onPopup)
248 self.Bind(wx.webview.EVT_WEBVIEW_BEFORE_LOAD, self.OnLinkClicked) 241 self.Bind(wx.webview.EVT_WEBVIEW_BEFORE_LOAD, self.OnLinkClicked)
249 242
250 #Wrapers so I dont have to add special Code 243 #Wrapers so I dont have to add special Code
251 @debugging 244
252 def SetPage(self, htmlstring): 245 def SetPage(self, htmlstring):
253 self.SetPageSource(htmlstring) 246 self.SetPageSource(htmlstring)
254 247
255 @debugging 248
256 def AppendToPage(self, htmlstring): 249 def AppendToPage(self, htmlstring):
257 self.SetPageSource(self.GetPageSource() + htmlstring) 250 self.SetPageSource(self.GetPageSource() + htmlstring)
258 251
259 @debugging 252
260 def GetFont(self): 253 def GetFont(self):
261 return self.__font 254 return self.__font
262 255
263 @debugging 256
264 def CalculateAllFonts(self, defaultsize): 257 def CalculateAllFonts(self, defaultsize):
265 return 258 return
266 259
267 @debugging 260
268 def SetDefaultFontAndSize(self, fontname, fontsize): 261 def SetDefaultFontAndSize(self, fontname, fontsize):
269 self.__font = wx.Font(int(fontsize), 262 self.__font = wx.Font(int(fontsize),
270 wx.FONTFAMILY_ROMAN, wx.FONTSTYLE_NORMAL, 263 wx.FONTFAMILY_ROMAN, wx.FONTSTYLE_NORMAL,
271 wx.FONTWEIGHT_NORMAL, faceName=fontname) 264 wx.FONTWEIGHT_NORMAL, faceName=fontname)
272 try: self.SetPageSource(self.Header() + self.StripHeader()) 265 try: self.SetPageSource(self.Header() + self.StripHeader())
273 except Exception, e: print e 266 except Exception, e: print e
274 return (self.GetFont().GetFaceName(), self.GetFont().GetPointSize()) 267 return (self.GetFont().GetFaceName(), self.GetFont().GetPointSize())
275 268
276 #Events 269 #Events
277 @debugging 270
278 def OnLinkClicked(self, linkinfo): 271 def OnLinkClicked(self, linkinfo):
279 href = linkinfo.GetHref() 272 href = linkinfo.GetHref()
280 wb = webbrowser.get() 273 wb = webbrowser.get()
281 wb.open(href) 274 wb.open(href)
282 275
283 @debugging 276
284 def onPopup(self, evt): 277 def onPopup(self, evt):
285 self.PopupMenu(self.menu) 278 self.PopupMenu(self.menu)
286 279
287 @debugging 280
288 def LeftUp(self, event): 281 def LeftUp(self, event):
289 event.Skip() 282 event.Skip()
290 wx.CallAfter(self.parent.set_chat_text_focus, None) 283 wx.CallAfter(self.parent.set_chat_text_focus, None)
291 284
292 @debugging 285
293 def OnM_EditCopy(self, evt): 286 def OnM_EditCopy(self, evt):
294 wx.TheClipboard.UsePrimarySelection(False) 287 wx.TheClipboard.UsePrimarySelection(False)
295 wx.TheClipboard.Open() 288 wx.TheClipboard.Open()
296 wx.TheClipboard.SetData(wx.TextDataObject(self.SelectionToText())) 289 wx.TheClipboard.SetData(wx.TextDataObject(self.SelectionToText()))
297 wx.TheClipboard.Close() 290 wx.TheClipboard.Close()
298 291
299 #Cutom Methods 292 #Cutom Methods
300 @debugging 293
301 def Header(self): 294 def Header(self):
302 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>" 295 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>"
303 296
304 @debugging 297
305 def StripHeader(self): 298 def StripHeader(self):
306 tmp = self.GetPageSource().split('<BODY>') 299 tmp = self.GetPageSource().split('<BODY>')
307 if tmp[-1].find('<body>') > -1: tmp = tmp[-1].split('<body>') 300 if tmp[-1].find('<body>') > -1: tmp = tmp[-1].split('<body>')
308 return tmp[-1] 301 return tmp[-1]
309 302
310 @debugging 303
311 def build_menu(self): 304 def build_menu(self):
312 self.menu = wx.Menu() 305 self.menu = wx.Menu()
313 item = wx.MenuItem(self.menu, wx.ID_ANY, "Copy", "Copy") 306 item = wx.MenuItem(self.menu, wx.ID_ANY, "Copy", "Copy")
314 self.Bind(wx.EVT_MENU, self.OnM_EditCopy, item) 307 self.Bind(wx.EVT_MENU, self.OnM_EditCopy, item)
315 self.menu.AppendItem(item) 308 self.menu.AppendItem(item)
316 309
317 @debugging 310
318 def scroll_down(self): 311 def scroll_down(self):
319 maxrange = self.GetScrollRange(wx.VERTICAL) 312 maxrange = self.GetScrollRange(wx.VERTICAL)
320 pagesize = self.GetScrollPageSize(wx.VERTICAL) 313 pagesize = self.GetScrollPageSize(wx.VERTICAL)
321 self.Scroll(-1, maxrange-pagesize) 314 self.Scroll(-1, maxrange-pagesize)
322 315
323 @debugging 316
324 def mouse_wheel(self, event): 317 def mouse_wheel(self, event):
325 amt = event.GetWheelRotation() 318 amt = event.GetWheelRotation()
326 units = amt/(-(event.GetWheelDelta())) 319 units = amt/(-(event.GetWheelDelta()))
327 self.ScrollLines(units*3) 320 self.ScrollLines(units*3)
328 chat_html_window = ChatHtmlWindow 321 chat_html_window = ChatHtmlWindow
352 # destroy_private_tab(self, chatpanel) 345 # destroy_private_tab(self, chatpanel)
353 # OnPageChanged(self, event) 346 # OnPageChanged(self, event)
354 # set_default_font(self, font, fontsize) 347 # set_default_font(self, font, fontsize)
355 348
356 class chat_notebook(orpgTabberWnd): 349 class chat_notebook(orpgTabberWnd):
357 @debugging 350
358 def __init__(self, parent, size): 351 def __init__(self, parent, size):
359 orpgTabberWnd.__init__(self, parent, True, size=size, 352 orpgTabberWnd.__init__(self, parent, True, size=size,
360 style=FNB.FNB_DROPDOWN_TABS_LIST|FNB.FNB_NO_NAV_BUTTONS|FNB.FNB_MOUSE_MIDDLE_CLOSES_TABS) 353 style=FNB.FNB_DROPDOWN_TABS_LIST|FNB.FNB_NO_NAV_BUTTONS|FNB.FNB_MOUSE_MIDDLE_CLOSES_TABS)
361 self.settings = component.get("settings") 354 self.settings = component.get("settings")
362 self.whisper_tabs = [] 355 self.whisper_tabs = []
384 self.GMChatPanel = None 377 self.GMChatPanel = None
385 if self.settings.get_setting("GMWhisperTab") == '1': 378 if self.settings.get_setting("GMWhisperTab") == '1':
386 self.create_gm_tab() 379 self.create_gm_tab()
387 self.SetSelection(0) 380 self.SetSelection(0)
388 381
389 @debugging 382
390 def get_tab_index(self, chatpanel): 383 def get_tab_index(self, chatpanel):
391 "Return the index of a chatpanel in the wxNotebook." 384 "Return the index of a chatpanel in the wxNotebook."
392 385
393 for i in xrange(self.GetPageCount()): 386 for i in xrange(self.GetPageCount()):
394 if (self.GetPage(i) == chatpanel): 387 if (self.GetPage(i) == chatpanel):
395 return i 388 return i
396 389
397 @debugging 390
398 def create_gm_tab(self): 391 def create_gm_tab(self):
399 if self.GMChatPanel == None: 392 if self.GMChatPanel == None:
400 self.GMChatPanel = chat_panel(self, -1, MAIN_TAB, 'gm') 393 self.GMChatPanel = chat_panel(self, -1, MAIN_TAB, 'gm')
401 self.AddPage(self.GMChatPanel, "GM", False) 394 self.AddPage(self.GMChatPanel, "GM", False)
402 self.SetPageImage(self.GetPageCount()-1, 1) 395 self.SetPageImage(self.GetPageCount()-1, 1)
403 self.GMChatPanel.chatwnd.SetDefaultFontAndSize(self.font, self.fontsize) 396 self.GMChatPanel.chatwnd.SetDefaultFontAndSize(self.font, self.fontsize)
404 397
405 @debugging 398
406 def create_whisper_tab(self, playerid): 399 def create_whisper_tab(self, playerid):
407 "Add a new chatpanel directly connected to integer 'playerid' via whispering." 400 "Add a new chatpanel directly connected to integer 'playerid' via whispering."
408 private_tab = chat_panel(self, -1, WHISPER_TAB, playerid) 401 private_tab = chat_panel(self, -1, WHISPER_TAB, playerid)
409 playername = strip_html(self.MainChatPanel.session.get_player_by_player_id(playerid)[0]) 402 playername = strip_html(self.MainChatPanel.session.get_player_by_player_id(playerid)[0])
410 self.AddPage(private_tab, playername, False) 403 self.AddPage(private_tab, playername, False)
413 self.newMsg(self.GetPageCount()-1) 406 self.newMsg(self.GetPageCount()-1)
414 self.AliasLib = component.get('alias') 407 self.AliasLib = component.get('alias')
415 wx.CallAfter(self.AliasLib.RefreshAliases) 408 wx.CallAfter(self.AliasLib.RefreshAliases)
416 return private_tab 409 return private_tab
417 410
418 @debugging 411
419 def create_group_tab(self, group_name): 412 def create_group_tab(self, group_name):
420 "Add a new chatpanel directly connected to integer 'playerid' via whispering." 413 "Add a new chatpanel directly connected to integer 'playerid' via whispering."
421 private_tab = chat_panel(self, -1, GROUP_TAB, group_name) 414 private_tab = chat_panel(self, -1, GROUP_TAB, group_name)
422 self.AddPage(private_tab, group_name, False) 415 self.AddPage(private_tab, group_name, False)
423 private_tab.chatwnd.SetDefaultFontAndSize(self.font, self.fontsize) 416 private_tab.chatwnd.SetDefaultFontAndSize(self.font, self.fontsize)
425 self.newMsg(self.GetPageCount()-1) 418 self.newMsg(self.GetPageCount()-1)
426 self.AliasLib = component.get('alias') 419 self.AliasLib = component.get('alias')
427 wx.CallAfter(self.AliasLib.RefreshAliases) 420 wx.CallAfter(self.AliasLib.RefreshAliases)
428 return private_tab 421 return private_tab
429 422
430 @debugging 423
431 def create_null_tab(self, tab_name): 424 def create_null_tab(self, tab_name):
432 "Add a new chatpanel directly connected to integer 'playerid' via whispering." 425 "Add a new chatpanel directly connected to integer 'playerid' via whispering."
433 private_tab = chat_panel(self, -1, NULL_TAB, tab_name) 426 private_tab = chat_panel(self, -1, NULL_TAB, tab_name)
434 self.AddPage(private_tab, tab_name, False) 427 self.AddPage(private_tab, tab_name, False)
435 private_tab.chatwnd.SetDefaultFontAndSize(self.font, self.fontsize) 428 private_tab.chatwnd.SetDefaultFontAndSize(self.font, self.fontsize)
437 self.newMsg(self.GetPageCount()-1) 430 self.newMsg(self.GetPageCount()-1)
438 self.AliasLib = component.get('alias') 431 self.AliasLib = component.get('alias')
439 wx.CallAfter(self.AliasLib.RefreshAliases) 432 wx.CallAfter(self.AliasLib.RefreshAliases)
440 return private_tab 433 return private_tab
441 434
442 @debugging 435
443 def onCloseTab(self, evt): 436 def onCloseTab(self, evt):
444 try: tabid = evt.GetSelection() 437 try: tabid = evt.GetSelection()
445 except: tabid = self.GetSelection() 438 except: tabid = self.GetSelection()
446 439
447 if self.GetPageText(tabid) == 'Main Room': 440 if self.GetPageText(tabid) == 'Main Room':
466 panel = self.GetPage(tabid) 459 panel = self.GetPage(tabid)
467 if panel in self.whisper_tabs: self.whisper_tabs.remove(panel) 460 if panel in self.whisper_tabs: self.whisper_tabs.remove(panel)
468 elif panel in self.group_tabs: self.group_tabs.remove(panel) 461 elif panel in self.group_tabs: self.group_tabs.remove(panel)
469 elif panel in self.null_tabs: self.null_tabs.remove(panel) 462 elif panel in self.null_tabs: self.null_tabs.remove(panel)
470 463
471 @debugging 464
472 def newMsg(self, tabid): 465 def newMsg(self, tabid):
473 if tabid != self.GetSelection(): self.SetPageImage(tabid, 0) 466 if tabid != self.GetSelection(): self.SetPageImage(tabid, 0)
474 467
475 @debugging 468
476 def onPageChanging(self, event): 469 def onPageChanging(self, event):
477 """When private chattabs are selected, set the bitmap back to 'normal'.""" 470 """When private chattabs are selected, set the bitmap back to 'normal'."""
478 event.Skip() 471 event.Skip()
479 472
480 @debugging 473
481 def onPageChanged(self, event): 474 def onPageChanged(self, event):
482 """When private chattabs are selected, set the bitmap back to 'normal'.""" 475 """When private chattabs are selected, set the bitmap back to 'normal'."""
483 selected_idx = event.GetSelection() 476 selected_idx = event.GetSelection()
484 self.SetPageImage(selected_idx, 1) 477 self.SetPageImage(selected_idx, 1)
485 page = self.GetPage(selected_idx) 478 page = self.GetPage(selected_idx)
525 !id : 518 !id :
526 !openrpg : 519 !openrpg :
527 !sendtarget: who gets outbound messages: either 'all' or a playerid 520 !sendtarget: who gets outbound messages: either 'all' or a playerid
528 """ 521 """
529 522
530 @debugging 523
531 def __init__(self, parent, id, tab_type, sendtarget): 524 def __init__(self, parent, id, tab_type, sendtarget):
532 wx.Panel.__init__(self, parent, id) 525 wx.Panel.__init__(self, parent, id)
533 logger._set_log_to_console(False) 526 logger._set_log_to_console(False)
534 self.session = component.get('session') 527 self.session = component.get('session')
535 self.settings = component.get('settings') 528 self.settings = component.get('settings')
572 except: pass 565 except: pass
573 self.font = self.chatwnd.GetFont().GetFaceName() 566 self.font = self.chatwnd.GetFont().GetFaceName()
574 self.fontsize = self.chatwnd.GetFont().GetPointSize() 567 self.fontsize = self.chatwnd.GetFont().GetPointSize()
575 self.scroll_down() 568 self.scroll_down()
576 569
577 @debugging 570
578 def set_default_font(self, fontname=None, fontsize=None): 571 def set_default_font(self, fontname=None, fontsize=None):
579 """Set all chatpanels to new default fontname/fontsize. 572 """Set all chatpanels to new default fontname/fontsize.
580 Returns current font settings in a (fontname, fontsize) tuple.""" 573 Returns current font settings in a (fontname, fontsize) tuple."""
581 if (fontname is not None): newfont = fontname 574 if (fontname is not None): newfont = fontname
582 else: newfont = self.font 575 else: newfont = self.font
586 self.InfoPost("Font is now " + newfont + " point size " + `newfontsize`) 579 self.InfoPost("Font is now " + newfont + " point size " + `newfontsize`)
587 self.font = newfont 580 self.font = newfont
588 self.fontsize = newfontsize 581 self.fontsize = newfontsize
589 return (self.font, self.fontsize) 582 return (self.font, self.fontsize)
590 583
591 @debugging 584
592 def build_menu(self): 585 def build_menu(self):
593 top_frame = component.get('frame') 586 top_frame = component.get('frame')
594 menu = wx.Menu() 587 menu = wx.Menu()
595 item = wx.MenuItem(menu, wx.ID_ANY, "&Background color", "Background color") 588 item = wx.MenuItem(menu, wx.ID_ANY, "&Background color", "Background color")
596 top_frame.Bind(wx.EVT_MENU, self.OnMB_BackgroundColor, item) 589 top_frame.Bind(wx.EVT_MENU, self.OnMB_BackgroundColor, item)
678 settingmenu.AppendMenu(wx.ID_ANY, 'Chat Tool Bars', toolmenu) 671 settingmenu.AppendMenu(wx.ID_ANY, 'Chat Tool Bars', toolmenu)
679 menu.AppendMenu(wx.ID_ANY, 'Chat Settings', settingmenu) 672 menu.AppendMenu(wx.ID_ANY, 'Chat Settings', settingmenu)
680 top_frame.mainmenu.Insert(2, menu, '&Chat') 673 top_frame.mainmenu.Insert(2, menu, '&Chat')
681 674
682 ## Settings Menu Events 675 ## Settings Menu Events
683 @debugging 676
684 def OnMB_ShowImages(self, event): 677 def OnMB_ShowImages(self, event):
685 if event.IsChecked(): self.settings.set_setting("Show_Images_In_Chat", '1') 678 if event.IsChecked(): self.settings.set_setting("Show_Images_In_Chat", '1')
686 else: self.settings.set_setting("Show_Images_In_Chat", '0') 679 else: self.settings.set_setting("Show_Images_In_Chat", '0')
687 680
688 @debugging 681
689 def OnMB_StripHTML(self, event): 682 def OnMB_StripHTML(self, event):
690 if event.IsChecked(): self.settings.set_setting("Sstriphtml", '1') 683 if event.IsChecked(): self.settings.set_setting("Sstriphtml", '1')
691 else: self.settings.set_setting("striphtml", '0') 684 else: self.settings.set_setting("striphtml", '0')
692 685
693 @debugging 686
694 def OnMB_ChatTimeIndex(self, event): 687 def OnMB_ChatTimeIndex(self, event):
695 if event.IsChecked(): self.settings.set_setting("Chat_Time_Indexing", '1') 688 if event.IsChecked(): self.settings.set_setting("Chat_Time_Indexing", '1')
696 else: self.settings.set_setting("Chat_Time_Indexing", '0') 689 else: self.settings.set_setting("Chat_Time_Indexing", '0')
697 690
698 @debugging 691
699 def OnMB_ChatAutoComplete(self, event): 692 def OnMB_ChatAutoComplete(self, event):
700 if event.IsChecked(): self.settings.set_setting("SuppressChatAutoComplete", '0') 693 if event.IsChecked(): self.settings.set_setting("SuppressChatAutoComplete", '0')
701 else: self.settings.set_setting("SuppressChatAutoComplete", '1') 694 else: self.settings.set_setting("SuppressChatAutoComplete", '1')
702 695
703 @debugging 696
704 def OnMB_ShowIDinChat(self, event): 697 def OnMB_ShowIDinChat(self, event):
705 if event.IsChecked(): self.settings.set_setting("ShowIDInChat", '1') 698 if event.IsChecked(): self.settings.set_setting("ShowIDInChat", '1')
706 else: self.settings.set_setting("ShowIDInChat", '0') 699 else: self.settings.set_setting("ShowIDInChat", '0')
707 700
708 @debugging 701
709 def OnMB_LogTimeIndex(self, event): 702 def OnMB_LogTimeIndex(self, event):
710 if event.IsChecked(): self.settings.set_setting("TimeStampGameLog", '1') 703 if event.IsChecked(): self.settings.set_setting("TimeStampGameLog", '1')
711 else: self.settings.set_setting("TimeStampGameLog", '0') 704 else: self.settings.set_setting("TimeStampGameLog", '0')
712 705
713 @debugging 706
714 def OnMB_TabbedWhispers(self, event): 707 def OnMB_TabbedWhispers(self, event):
715 if event.IsChecked(): self.settings.set_setting("tabbedwhispers", '1') 708 if event.IsChecked(): self.settings.set_setting("tabbedwhispers", '1')
716 else: self.settings.set_setting("tabbedwhispers", '0') 709 else: self.settings.set_setting("tabbedwhispers", '0')
717 710
718 @debugging 711
719 def OnMB_GMTab(self, event): 712 def OnMB_GMTab(self, event):
720 if event.IsChecked(): 713 if event.IsChecked():
721 self.settings.set_setting("GMWhisperTab", '1') 714 self.settings.set_setting("GMWhisperTab", '1')
722 self.parent.create_gm_tab() 715 self.parent.create_gm_tab()
723 else: self.settings.set_setting("GMWhisperTab", '0') 716 else: self.settings.set_setting("GMWhisperTab", '0')
724 717
725 @debugging 718
726 def OnMB_GroupWhisperTabs(self, event): 719 def OnMB_GroupWhisperTabs(self, event):
727 if event.IsChecked(): self.settings.set_setting("GroupWhisperTab", '1') 720 if event.IsChecked(): self.settings.set_setting("GroupWhisperTab", '1')
728 else: self.settings.set_setting("GroupWhisperTab", '0') 721 else: self.settings.set_setting("GroupWhisperTab", '0')
729 722
730 @debugging 723
731 def OnMB_DiceBar(self, event): 724 def OnMB_DiceBar(self, event):
732 act = '0' 725 act = '0'
733 if event.IsChecked(): 726 if event.IsChecked():
734 self.settings.set_setting("DiceButtons_On", '1') 727 self.settings.set_setting("DiceButtons_On", '1')
735 act = '1' 728 act = '1'
739 except: pass 732 except: pass
740 for panel in self.parent.whisper_tabs: panel.toggle_dice(act) 733 for panel in self.parent.whisper_tabs: panel.toggle_dice(act)
741 for panel in self.parent.group_tabs: panel.toggle_dice(act) 734 for panel in self.parent.group_tabs: panel.toggle_dice(act)
742 for panel in self.parent.null_tabs: panel.toggle_dice(act) 735 for panel in self.parent.null_tabs: panel.toggle_dice(act)
743 736
744 @debugging 737
745 def OnMB_FormatButtons(self, event): 738 def OnMB_FormatButtons(self, event):
746 act = '0' 739 act = '0'
747 if event.IsChecked(): 740 if event.IsChecked():
748 self.settings.set_setting("FormattingButtons_On", '1') 741 self.settings.set_setting("FormattingButtons_On", '1')
749 act = '1' 742 act = '1'
754 except: pass 747 except: pass
755 for panel in self.parent.whisper_tabs: panel.toggle_formating(act) 748 for panel in self.parent.whisper_tabs: panel.toggle_formating(act)
756 for panel in self.parent.group_tabs: panel.toggle_formating(act) 749 for panel in self.parent.group_tabs: panel.toggle_formating(act)
757 for panel in self.parent.null_tabs: panel.toggle_formating(act) 750 for panel in self.parent.null_tabs: panel.toggle_formating(act)
758 751
759 @debugging 752
760 def OnMB_AliasTool(self, event): 753 def OnMB_AliasTool(self, event):
761 act = '0' 754 act = '0'
762 if event.IsChecked(): 755 if event.IsChecked():
763 self.settings.set_setting("AliasTool_On", '1') 756 self.settings.set_setting("AliasTool_On", '1')
764 act = '1' 757 act = '1'
768 except: pass 761 except: pass
769 for panel in self.parent.whisper_tabs: panel.toggle_alias(act) 762 for panel in self.parent.whisper_tabs: panel.toggle_alias(act)
770 for panel in self.parent.group_tabs: panel.toggle_alias(act) 763 for panel in self.parent.group_tabs: panel.toggle_alias(act)
771 for panel in self.parent.null_tabs:panel.toggle_alias(act) 764 for panel in self.parent.null_tabs:panel.toggle_alias(act)
772 765
773 @debugging 766
774 def OnMB_BackgroundColor(self, event): 767 def OnMB_BackgroundColor(self, event):
775 top_frame = component.get('frame') 768 top_frame = component.get('frame')
776 hexcolor = self.get_color() 769 hexcolor = self.get_color()
777 if hexcolor != None: 770 if hexcolor != None:
778 self.bgcolor = hexcolor 771 self.bgcolor = hexcolor
790 top_frame.players.SetBackgroundColour('white') 783 top_frame.players.SetBackgroundColour('white')
791 top_frame.players.SetForegroundColour('black') 784 top_frame.players.SetForegroundColour('black')
792 top_frame.players.Refresh() 785 top_frame.players.Refresh()
793 self.chatwnd.scroll_down() 786 self.chatwnd.scroll_down()
794 787
795 @debugging 788
796 def OnMB_TextColor(self, event): 789 def OnMB_TextColor(self, event):
797 top_frame = component.get('frame') 790 top_frame = component.get('frame')
798 hexcolor = self.get_color() 791 hexcolor = self.get_color()
799 if hexcolor != None: 792 if hexcolor != None:
800 self.textcolor = hexcolor 793 self.textcolor = hexcolor
812 top_frame.players.SetBackgroundColour('white') 805 top_frame.players.SetBackgroundColour('white')
813 top_frame.players.SetForegroundColour('black') 806 top_frame.players.SetForegroundColour('black')
814 top_frame.players.Refresh() 807 top_frame.players.Refresh()
815 self.chatwnd.scroll_down() 808 self.chatwnd.scroll_down()
816 809
817 @debugging 810
818 def get_hot_keys(self): 811 def get_hot_keys(self):
819 # dummy menus for hotkeys 812 # dummy menus for hotkeys
820 self.build_menu() 813 self.build_menu()
821 entries = [] 814 entries = []
822 entries.append((wx.ACCEL_CTRL, ord('H'), self.setChatFocusMenu.GetId())) 815 entries.append((wx.ACCEL_CTRL, ord('H'), self.setChatFocusMenu.GetId()))
823 #entries.append((wx.ACCEL_CTRL, wx.WXK_TAB, SWAP_TABS)) 816 #entries.append((wx.ACCEL_CTRL, wx.WXK_TAB, SWAP_TABS))
824 return entries 817 return entries
825 818
826 @debugging 819
827 def forward_tabs(self, evt): 820 def forward_tabs(self, evt):
828 self.parent.AdvanceSelection() 821 self.parent.AdvanceSelection()
829 822
830 def back_tabs(self, evt): 823 def back_tabs(self, evt):
831 self.parent.AdvanceSelection(False) 824 self.parent.AdvanceSelection(False)
832 825
833 # This subroutine builds the controls for the chat frame 826 # This subroutine builds the controls for the chat frame
834 # 827 #
835 # !self : instance of self 828 # !self : instance of self
836 @debugging 829
837 def build_ctrls(self): 830 def build_ctrls(self):
838 self.chatwnd = chat_html_window(self,-1) 831 self.chatwnd = chat_html_window(self,-1)
839 self.set_colors() 832 self.set_colors()
840 wx.CallAfter(self.chatwnd.SetPage, self.chatwnd.Header()) 833 wx.CallAfter(self.chatwnd.SetPage, self.chatwnd.Header())
841 if (self.sendtarget == "all"): 834 if (self.sendtarget == "all"):
879 self.chattxt.Bind(wx.EVT_MOUSEWHEEL, self.chatwnd.mouse_wheel) 872 self.chattxt.Bind(wx.EVT_MOUSEWHEEL, self.chatwnd.mouse_wheel)
880 self.chattxt.Bind(wx.EVT_CHAR, self.chattxt.OnChar) 873 self.chattxt.Bind(wx.EVT_CHAR, self.chattxt.OnChar)
881 self.chattxt.Bind(wx.EVT_TEXT_COPY, self.chatwnd.OnM_EditCopy) 874 self.chattxt.Bind(wx.EVT_TEXT_COPY, self.chatwnd.OnM_EditCopy)
882 # def build_ctrls - end 875 # def build_ctrls - end
883 876
884 @debugging 877
885 def build_bar(self): 878 def build_bar(self):
886 self.toolbar_sizer = wx.BoxSizer(wx.HORIZONTAL) 879 self.toolbar_sizer = wx.BoxSizer(wx.HORIZONTAL)
887 self.scroll_lock = None 880 self.scroll_lock = None
888 self.numDieText = None 881 self.numDieText = None
889 self.dieModText = None 882 self.dieModText = None
890 if self.settings.get_setting('Toolbar_On') == "1": 883 if self.settings.get_setting('Toolbar_On') == "1":
891 self.build_alias() 884 self.build_alias()
892 self.build_dice() 885 self.build_dice()
893 self.build_scroll() 886 self.build_scroll()
894 self.build_text() 887 self.build_text()
895 self.toolbar_sizer.Add( self.textpop_lock, 0, wx.EXPAND ) 888 self.toolbar_sizer.Add(self.textpop_lock, 0, wx.EXPAND)
896 self.toolbar_sizer.Add(self.scroll_lock,0,wx.EXPAND) 889 self.toolbar_sizer.Add(self.scroll_lock, 0, wx.EXPAND)
897 self.build_formating() 890 self.build_formating()
898 self.build_colorbutton() 891 self.build_colorbutton()
899 892
900 @debugging 893
901 def build_scroll(self): 894 def build_scroll(self):
902 self.scroll_lock = wx.Button( self, wx.ID_ANY, "Scroll ON",size= wx.Size(80,25)) 895 self.scroll_lock = wx.Button( self, wx.ID_ANY, "Scroll ON",size= wx.Size(80,25))
903 896
904 @debugging 897
905 def build_alias(self): 898 def build_alias(self):
899 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.
906 self.aliasList = wx.Choice(self, wx.ID_ANY, size=(100, 25), choices=[self.defaultAliasName]) 900 self.aliasList = wx.Choice(self, wx.ID_ANY, size=(100, 25), choices=[self.defaultAliasName])
907 self.aliasButton = createMaskedButton( self, dir_struct["icon"] + 'player.gif', 901 self.aliasButton = createMaskedButton( self, dir_struct["icon"] + 'player.gif',
908 'Refresh list of aliases from Game Tree', wx.ID_ANY, '#bdbdbd' ) 902 'Refresh list of aliases from Game Tree', wx.ID_ANY, '#bdbdbd' )
909 self.aliasList.SetSelection(0) 903 self.aliasList.SetSelection(0)
910 self.filterList = wx.Choice(self, wx.ID_ANY, size=(100, 25), choices=[self.defaultFilterName]) 904 self.filterList = wx.Choice(self, wx.ID_ANY, size=(100, 25), choices=[self.defaultFilterName])
911 self.filterButton = createMaskedButton( self, dir_struct["icon"] + 'add_filter.gif', 905 self.filterButton = createMaskedButton( self, dir_struct["icon"] + 'add_filter.gif',
912 'Refresh list of filters from Game Tree', wx.ID_ANY, '#bdbdbd' ) 906 'Refresh list of filters from Game Tree', wx.ID_ANY, '#bdbdbd' )
913 self.filterList.SetSelection(0) 907 self.filterList.SetSelection(0)
914 self.toolbar_sizer.Add( self.aliasButton, 0, wx.EXPAND ) 908
915 self.toolbar_sizer.Add( self.aliasList,0,wx.EXPAND) 909 self.aliasSizer.Add( self.aliasButton, 0, wx.EXPAND )
916 self.toolbar_sizer.Add( self.filterButton, 0, wx.EXPAND ) 910 self.aliasSizer.Add( self.aliasList,0,wx.EXPAND)
917 self.toolbar_sizer.Add( self.filterList,0,wx.EXPAND) 911 self.aliasSizer.Add( self.filterButton, 0, wx.EXPAND )
912 self.aliasSizer.Add( self.filterList,0,wx.EXPAND)
913
914 self.toolbar_sizer.Add(self.aliasSizer, 0, wx.EXPAND)
915
918 if self.settings.get_setting('AliasTool_On') == '0': self.toggle_alias('0') 916 if self.settings.get_setting('AliasTool_On') == '0': self.toggle_alias('0')
919 else: self.toggle_alias('1') 917 else: self.toggle_alias('1')
920 918
921 @debugging 919
922 def toggle_alias(self, act): 920 def toggle_alias(self, act):
923 if act == '0': 921 if act == '0': self.toolbar_sizer.Show(self.aliasSizer, False)
924 self.toolbar_sizer.Show(self.aliasList, False) 922 else: self.toolbar_sizer.Show(self.aliasSizer, True)
925 self.toolbar_sizer.Show(self.filterList, False) 923 self.toolbar_sizer.Layout()
926 self.toolbar_sizer.Show(self.aliasButton, False) 924
927 self.toolbar_sizer.Show(self.filterButton, False)
928 self.toolbar_sizer.Layout()
929 else:
930 self.toolbar_sizer.Show(self.aliasList, True)
931 self.toolbar_sizer.Show(self.filterList, True)
932 self.toolbar_sizer.Show(self.aliasButton, True)
933 self.toolbar_sizer.Show(self.filterButton, True)
934 self.toolbar_sizer.Layout()
935
936 @debugging
937 def build_text(self): 925 def build_text(self):
938 self.textpop_lock = createMaskedButton(self, dir_struct["icon"]+'note.gif', 'Open Text View Of Chat Session', wx.ID_ANY, '#bdbdbd') 926 self.textpop_lock = createMaskedButton(self, dir_struct["icon"]+'note.gif', 'Open Text View Of Chat Session', wx.ID_ANY, '#bdbdbd')
939 927
940 @debugging 928
941 def build_dice(self): 929 def build_dice(self):
942 self.numDieText = wx.TextCtrl( self, wx.ID_ANY, "1", size= wx.Size(25, 25), validator=orpg.tools.inputValidator.MathOnlyValidator() ) 930 self.numDieText = wx.TextCtrl( self, wx.ID_ANY, "1", size= wx.Size(25, 25), validator=orpg.tools.inputValidator.MathOnlyValidator() )
943 self.dieModText = wx.TextCtrl( self, wx.ID_ANY, "", size= wx.Size(50, 25), validator=orpg.tools.inputValidator.MathOnlyValidator() ) 931 self.dieModText = wx.TextCtrl( self, wx.ID_ANY, "", size= wx.Size(50, 25), validator=orpg.tools.inputValidator.MathOnlyValidator() )
944 self.d4Button = createMaskedButton(self, dir_struct["icon"]+'b_d4.gif', 'Roll d4', wx.ID_ANY) 932 self.d4Button = createMaskedButton(self, dir_struct["icon"]+'b_d4.gif', 'Roll d4', wx.ID_ANY)
945 self.d6Button = createMaskedButton(self, dir_struct["icon"]+'b_d6.gif', 'Roll d6', wx.ID_ANY) 933 self.d6Button = createMaskedButton(self, dir_struct["icon"]+'b_d6.gif', 'Roll d6', wx.ID_ANY)
958 self.toolbar_sizer.Add( self.d100Button, 0 ,wx.EXPAND) 946 self.toolbar_sizer.Add( self.d100Button, 0 ,wx.EXPAND)
959 self.toolbar_sizer.Add( self.dieModText, 0, wx.ALIGN_CENTER, 5 ) 947 self.toolbar_sizer.Add( self.dieModText, 0, wx.ALIGN_CENTER, 5 )
960 if self.settings.get_setting('DiceButtons_On') == '0': self.toggle_dice('0') 948 if self.settings.get_setting('DiceButtons_On') == '0': self.toggle_dice('0')
961 else: self.toggle_dice('1') 949 else: self.toggle_dice('1')
962 950
963 @debugging 951
964 def toggle_dice(self, act): 952 def toggle_dice(self, act):
965 if act == '0': 953 if act == '0':
966 self.toolbar_sizer.Show(self.numDieText, False) 954 self.toolbar_sizer.Show(self.numDieText, False)
967 self.toolbar_sizer.Show(self.d4Button, False) 955 self.toolbar_sizer.Show(self.d4Button, False)
968 self.toolbar_sizer.Show(self.d6Button, False) 956 self.toolbar_sizer.Show(self.d6Button, False)
983 self.toolbar_sizer.Show(self.d20Button, True) 971 self.toolbar_sizer.Show(self.d20Button, True)
984 self.toolbar_sizer.Show(self.d100Button, True) 972 self.toolbar_sizer.Show(self.d100Button, True)
985 self.toolbar_sizer.Show(self.dieModText, True) 973 self.toolbar_sizer.Show(self.dieModText, True)
986 self.toolbar_sizer.Layout() 974 self.toolbar_sizer.Layout()
987 975
988 @debugging 976
989 def build_formating(self): 977 def build_formating(self):
990 self.boldButton = createMaskedButton( self, dir_struct["icon"]+'bold.gif', 978 self.boldButton = createMaskedButton( self, dir_struct["icon"]+'bold.gif',
991 'Make the selected text Bold', wx.ID_ANY, '#bdbdbd') 979 'Make the selected text Bold', wx.ID_ANY, '#bdbdbd')
992 self.italicButton = createMaskedButton( self, dir_struct["icon"]+'italic.gif', 980 self.italicButton = createMaskedButton( self, dir_struct["icon"]+'italic.gif',
993 'Italicize the selected text', wx.ID_ANY, '#bdbdbd' ) 981 'Italicize the selected text', wx.ID_ANY, '#bdbdbd' )
997 self.toolbar_sizer.Add( self.italicButton, 0, wx.EXPAND ) 985 self.toolbar_sizer.Add( self.italicButton, 0, wx.EXPAND )
998 self.toolbar_sizer.Add( self.underlineButton, 0, wx.EXPAND ) 986 self.toolbar_sizer.Add( self.underlineButton, 0, wx.EXPAND )
999 if self.settings.get_setting('FormattingButtons_On') == '0': self.toggle_formating('0') 987 if self.settings.get_setting('FormattingButtons_On') == '0': self.toggle_formating('0')
1000 else: self.toggle_formating('1') 988 else: self.toggle_formating('1')
1001 989
1002 @debugging 990
1003 def toggle_formating(self, act): 991 def toggle_formating(self, act):
1004 if act == '0': 992 if act == '0':
1005 self.toolbar_sizer.Show(self.boldButton, False) 993 self.toolbar_sizer.Show(self.boldButton, False)
1006 self.toolbar_sizer.Show(self.italicButton, False) 994 self.toolbar_sizer.Show(self.italicButton, False)
1007 self.toolbar_sizer.Show(self.underlineButton, False) 995 self.toolbar_sizer.Show(self.underlineButton, False)
1011 self.toolbar_sizer.Show(self.italicButton, True) 999 self.toolbar_sizer.Show(self.italicButton, True)
1012 self.toolbar_sizer.Show(self.underlineButton, True) 1000 self.toolbar_sizer.Show(self.underlineButton, True)
1013 self.toolbar_sizer.Layout() 1001 self.toolbar_sizer.Layout()
1014 1002
1015 # Heroman - Ideally, we would use static labels... 1003 # Heroman - Ideally, we would use static labels...
1016 @debugging 1004
1017 def build_colorbutton(self): 1005 def build_colorbutton(self):
1018 self.color_button = createMaskedButton(self, dir_struct["icon"]+'textcolor.gif', 1006 self.color_button = createMaskedButton(self, dir_struct["icon"]+'textcolor.gif',
1019 'Text Color', wx.ID_ANY, '#bdbdbd', 1007 'Text Color', wx.ID_ANY, '#bdbdbd',
1020 wx.BITMAP_TYPE_GIF) 1008 wx.BITMAP_TYPE_GIF)
1021 1009
1024 '#c0c0c0', wx.BITMAP_TYPE_BMP ) 1012 '#c0c0c0', wx.BITMAP_TYPE_BMP )
1025 self.color_button.SetBackgroundColour(self.settings.get_setting('mytextcolor')) 1013 self.color_button.SetBackgroundColour(self.settings.get_setting('mytextcolor'))
1026 self.toolbar_sizer.Add(self.color_button, 0, wx.EXPAND) 1014 self.toolbar_sizer.Add(self.color_button, 0, wx.EXPAND)
1027 self.toolbar_sizer.Add(self.saveButton, 0, wx.EXPAND) 1015 self.toolbar_sizer.Add(self.saveButton, 0, wx.EXPAND)
1028 1016
1029 @debugging 1017
1030 def OnMotion(self, evt): 1018 def OnMotion(self, evt):
1031 contain = self.chatwnd.GetInternalRepresentation() 1019 contain = self.chatwnd.GetInternalRepresentation()
1032 if contain: 1020 if contain:
1033 sx = sy = 0 1021 sx = sy = 0
1034 x = y = 0 1022 x = y = 0
1050 # It checks if we need to send a typing message 1038 # It checks if we need to send a typing message
1051 1039
1052 # 1040 #
1053 # self: duh 1041 # self: duh
1054 # event: raw KeyEvent from OnChar() 1042 # event: raw KeyEvent from OnChar()
1055 @debugging 1043
1056 def myKeyHook(self, event): 1044 def myKeyHook(self, event):
1057 if self.session.get_status() == MPLAY_CONNECTED: # only do if we're connected 1045 if self.session.get_status() == MPLAY_CONNECTED: # only do if we're connected
1058 thisPress = time.time() # thisPress is local temp variable 1046 thisPress = time.time() # thisPress is local temp variable
1059 if (thisPress - self.lastSend) > 4: # Check to see if it's been 5 seconds since our last notice 1047 if (thisPress - self.lastSend) > 4: # Check to see if it's been 5 seconds since our last notice
1060 # If we're not already typing, then self.lastSend will be 0 1048 # If we're not already typing, then self.lastSend will be 0
1070 1058
1071 # This subroutine gets called once a second by the typing Timer 1059 # This subroutine gets called once a second by the typing Timer
1072 # It checks if we need to send a not_typing message 1060 # It checks if we need to send a not_typing message
1073 # 1061 #
1074 # self: duh 1062 # self: duh
1075 @debugging 1063
1076 def typingTimerFunc(self, event): 1064 def typingTimerFunc(self, event):
1077 #following added by mDuo13 1065 #following added by mDuo13
1078 ##############refresh_counter()############## 1066 ##############refresh_counter()##############
1079 for plugin_fname in self.activeplugins.keys(): 1067 for plugin_fname in self.activeplugins.keys():
1080 plugin = self.activeplugins[plugin_fname] 1068 plugin = self.activeplugins[plugin_fname]
1093 # This subroutine actually takes care of sending the messages for typing/not_typing events 1081 # This subroutine actually takes care of sending the messages for typing/not_typing events
1094 # 1082 #
1095 # self: duh 1083 # self: duh
1096 # typing: boolean 1084 # typing: boolean
1097 1085
1098 @debugging 1086
1099 def sendTyping(self, typing): 1087 def sendTyping(self, typing):
1100 if typing: 1088 if typing:
1101 self.lastSend = time.time() # remember our send time for use in myKeyHook() 1089 self.lastSend = time.time() # remember our send time for use in myKeyHook()
1102 #I think this is cleaner 1090 #I think this is cleaner
1103 status_text = self.settings.get_setting('TypingStatusAlias') 1091 status_text = self.settings.get_setting('TypingStatusAlias')
1112 1100
1113 # This subroutine sets the colors of the chat based on the settings in the 1101 # This subroutine sets the colors of the chat based on the settings in the
1114 # self instance. 1102 # self instance.
1115 # 1103 #
1116 # !self : instance of self 1104 # !self : instance of self
1117 @debugging 1105
1118 def set_colors(self): 1106 def set_colors(self):
1119 # chat window backround color 1107 # chat window backround color
1120 self.bgcolor = self.settings.get_setting('bgcolor') 1108 self.bgcolor = self.settings.get_setting('bgcolor')
1121 # chat window normal text color 1109 # chat window normal text color
1122 self.textcolor = self.settings.get_setting('textcolor') 1110 self.textcolor = self.settings.get_setting('textcolor')
1134 1122
1135 # This subroutine will insert text into the chat window 1123 # This subroutine will insert text into the chat window
1136 # 1124 #
1137 # !self : instance of self 1125 # !self : instance of self
1138 # !txt : text to be inserted into the chat window 1126 # !txt : text to be inserted into the chat window
1139 @debugging 1127
1140 def set_chat_text(self, txt): 1128 def set_chat_text(self, txt):
1141 self.chattxt.SetValue(txt) 1129 self.chattxt.SetValue(txt)
1142 self.chattxt.SetFocus() 1130 self.chattxt.SetFocus()
1143 self.chattxt.SetInsertionPointEnd() 1131 self.chattxt.SetInsertionPointEnd()
1144 # def set_chat_text - end 1132 # def set_chat_text - end
1145 1133
1146 @debugging 1134
1147 def get_chat_text(self): 1135 def get_chat_text(self):
1148 return self.chattxt.GetValue() 1136 return self.chattxt.GetValue()
1149 1137
1150 # This subroutine sets the focus to the chat window 1138 # This subroutine sets the focus to the chat window
1151 @debugging 1139
1152 def set_chat_text_focus(self, event): 1140 def set_chat_text_focus(self, event):
1153 wx.CallAfter(self.chattxt.SetFocus) 1141 wx.CallAfter(self.chattxt.SetFocus)
1154 # def set_chat_text_focus - end 1142 # def set_chat_text_focus - end
1155 1143
1156 # This subrtouine grabs the user input and make the special keys and 1144 # This subrtouine grabs the user input and make the special keys and
1159 # !self : instance of self 1147 # !self : instance of self
1160 # !event : 1148 # !event :
1161 # 1149 #
1162 # Note: self.chattxt now handles it's own Key events. It does, however still 1150 # Note: self.chattxt now handles it's own Key events. It does, however still
1163 # call it's parent's (self) OnChar to handle "default" behavior. 1151 # call it's parent's (self) OnChar to handle "default" behavior.
1164 @debugging 1152
1165 def OnChar(self, event): 1153 def OnChar(self, event):
1166 s = self.chattxt.GetValue() 1154 s = self.chattxt.GetValue()
1167 #self.histlen = len(self.history) - 1 1155 #self.histlen = len(self.history) - 1
1168 1156
1169 ## RETURN KEY (no matter if there is text in chattxt) 1157 ## RETURN KEY (no matter if there is text in chattxt)
1180 wx.WXK_F7: 'event.GetKeyCode() == wx.WXK_F7', wx.WXK_F8: 'event.GetKeyCode() == wx.WXK_F8', 1168 wx.WXK_F7: 'event.GetKeyCode() == wx.WXK_F7', wx.WXK_F8: 'event.GetKeyCode() == wx.WXK_F8',
1181 wx.WXK_F9: 'event.GetKeyCode() == wx.WXK_F9', wx.WXK_F10: 'event.GetKeyCode() == wx.WXK_F10', 1169 wx.WXK_F9: 'event.GetKeyCode() == wx.WXK_F9', wx.WXK_F10: 'event.GetKeyCode() == wx.WXK_F10',
1182 wx.WXK_F11: 'event.GetKeyCode() == wx.WXK_F11', wx.WXK_F12: 'event.GetKeyCode() == wx.WXK_F12'} 1170 wx.WXK_F11: 'event.GetKeyCode() == wx.WXK_F11', wx.WXK_F12: 'event.GetKeyCode() == wx.WXK_F12'}
1183 1171
1184 bin_event = event.GetKeyCode() 1172 bin_event = event.GetKeyCode()
1185 if recycle_bin.has_key(bin_event): 1173 if recycle_bin.has_key(bin_event):
1186 logger.debug(lambda bin_event: recycle_bin[bin_event]) 1174 logger.debug(lambda bin_event: recycle_bin[bin_event])
1187 macroText = self.settings.get_setting(recycle_bin[bin_event][29:]) 1175 macroText = self.settings.get_setting(recycle_bin[bin_event][29:])
1188 recycle_bin = {}; del bin_event 1176 recycle_bin = {}; del bin_event
1189 1177
1190 # Append to the existing typed text as needed and make sure the status doesn't change back. 1178 # Append to the existing typed text as needed and make sure the status doesn't change back.
1300 ## NOTHING 1288 ## NOTHING
1301 else: event.Skip() 1289 else: event.Skip()
1302 logger.debug("Exit chat_panel->OnChar(self, event)") 1290 logger.debug("Exit chat_panel->OnChar(self, event)")
1303 # def OnChar - end 1291 # def OnChar - end
1304 1292
1305 @debugging 1293
1306 def onDieRoll(self, evt): 1294 def onDieRoll(self, evt):
1307 """Roll the dice based on the button pressed and the die modifiers entered, if any.""" 1295 """Roll the dice based on the button pressed and the die modifiers entered, if any."""
1308 # Get any die modifiers if they have been entered 1296 # Get any die modifiers if they have been entered
1309 numDie = self.numDieText.GetValue() 1297 numDie = self.numDieText.GetValue()
1310 dieMod = self.dieModText.GetValue() 1298 dieMod = self.dieModText.GetValue()
1321 # This subroutine saves a chat buffer as html to a file chosen via a 1309 # This subroutine saves a chat buffer as html to a file chosen via a
1322 # FileDialog. 1310 # FileDialog.
1323 # 1311 #
1324 # !self : instance of self 1312 # !self : instance of self
1325 # !evt : 1313 # !evt :
1326 @debugging 1314
1327 def on_chat_save(self, evt): 1315 def on_chat_save(self, evt):
1328 f = wx.FileDialog(self,"Save Chat Buffer",".","","HTM* (*.htm*)|*.htm*|HTML (*.html)|*.html|HTM (*.htm)|*.htm",wx.SAVE) 1316 f = wx.FileDialog(self,"Save Chat Buffer",".","","HTM* (*.htm*)|*.htm*|HTML (*.html)|*.html|HTM (*.htm)|*.htm",wx.SAVE)
1329 if f.ShowModal() == wx.ID_OK: 1317 if f.ShowModal() == wx.ID_OK:
1330 file = open(f.GetPath(), "w") 1318 file = open(f.GetPath(), "w")
1331 file.write(self.ResetPage() + "</body></html>") 1319 file.write(self.ResetPage() + "</body></html>")
1332 file.close() 1320 file.close()
1333 f.Destroy() 1321 f.Destroy()
1334 os.chdir(dir_struct["home"]) 1322 os.chdir(dir_struct["home"])
1335 # def on_chat_save - end 1323 # def on_chat_save - end
1336 1324
1337 @debugging 1325
1338 def ResetPage(self): 1326 def ResetPage(self):
1339 self.set_colors() 1327 self.set_colors()
1340 buffertext = self.chatwnd.Header() + "\n" 1328 buffertext = self.chatwnd.Header() + "\n"
1341 buffertext += chat_util.strip_body_tags(self.chatwnd.StripHeader()).replace("<br>", 1329 buffertext += chat_util.strip_body_tags(self.chatwnd.StripHeader()).replace("<br>",
1342 "<br />").replace('</html>', 1330 "<br />").replace('</html>',
1344 "<br />\n").replace("\n\n", '') 1332 "<br />\n").replace("\n\n", '')
1345 return buffertext 1333 return buffertext
1346 1334
1347 # This subroutine sets the color of selected text, or base text color if 1335 # This subroutine sets the color of selected text, or base text color if
1348 # nothing is selected 1336 # nothing is selected
1349 @debugging 1337
1350 def on_text_color(self, event): 1338 def on_text_color(self, event):
1351 hexcolor = self.r_h.do_hex_color_dlg(self) 1339 hexcolor = self.r_h.do_hex_color_dlg(self)
1352 if hexcolor != None: 1340 if hexcolor != None:
1353 (beg,end) = self.chattxt.GetSelection() 1341 (beg,end) = self.chattxt.GetSelection()
1354 if beg != end: 1342 if beg != end:
1368 # This subroutine take a color and a text string and formats it into html. 1356 # This subroutine take a color and a text string and formats it into html.
1369 # 1357 #
1370 # !self : instance of self 1358 # !self : instance of self
1371 # !color : color for the text to be set 1359 # !color : color for the text to be set
1372 # !text : text string to be included in the html. 1360 # !text : text string to be included in the html.
1373 @debugging 1361
1374 def colorize(self, color, text): 1362 def colorize(self, color, text):
1375 """Puts font tags of 'color' around 'text' value, and returns the string""" 1363 """Puts font tags of 'color' around 'text' value, and returns the string"""
1376 return "<font color='" + color + "'>" + text + "</font>" 1364 return "<font color='" + color + "'>" + text + "</font>"
1377 # def colorize - end 1365 # def colorize - end
1378 1366
1379 # This subroutine takes and event and inserts text with the basic format 1367 # This subroutine takes and event and inserts text with the basic format
1380 # tags included. 1368 # tags included.
1381 # 1369 #
1382 # !self : instance of self 1370 # !self : instance of self
1383 # !event : 1371 # !event :
1384 @debugging 1372
1385 def on_text_format(self, event): 1373 def on_text_format(self, event):
1386 id = event.GetId() 1374 id = event.GetId()
1387 txt = self.chattxt.GetValue() 1375 txt = self.chattxt.GetValue()
1388 (beg,end) = self.chattxt.GetSelection() 1376 (beg,end) = self.chattxt.GetSelection()
1389 if beg != end: sel_txt = txt[beg:end] 1377 if beg != end: sel_txt = txt[beg:end]
1396 self.chattxt.SetValue(txt) 1384 self.chattxt.SetValue(txt)
1397 self.chattxt.SetInsertionPointEnd() 1385 self.chattxt.SetInsertionPointEnd()
1398 self.chattxt.SetFocus() 1386 self.chattxt.SetFocus()
1399 # def on_text_format - end 1387 # def on_text_format - end
1400 1388
1401 @debugging 1389
1402 def lock_scroll(self, event): 1390 def lock_scroll(self, event):
1403 if self.lockscroll: 1391 if self.lockscroll:
1404 self.lockscroll = False 1392 self.lockscroll = False
1405 self.scroll_lock.SetLabel("Scroll ON") 1393 self.scroll_lock.SetLabel("Scroll ON")
1406 if len(self.storedata) != 0: 1394 if len(self.storedata) != 0:
1413 1401
1414 # This subroutine will popup a text window with the chatbuffer contents 1402 # This subroutine will popup a text window with the chatbuffer contents
1415 # 1403 #
1416 # !self : instance of self 1404 # !self : instance of self
1417 # !event : 1405 # !event :
1418 @debugging 1406
1419 def pop_textpop(self, event): 1407 def pop_textpop(self, event):
1420 """searchable popup text view of chatbuffer""" 1408 """searchable popup text view of chatbuffer"""
1421 h_buffertext = self.ResetPage() 1409 h_buffertext = self.ResetPage()
1422 h_dlg = orpgScrolledMessageFrameEditor(self, h_buffertext, "Text View of Chat Window", None, (500,300)) 1410 h_dlg = orpgScrolledMessageFrameEditor(self, h_buffertext, "Text View of Chat Window", None, (500,300))
1423 h_dlg.Show(True) 1411 h_dlg.Show(True)
1424 1412
1425 # This subroutine will change the dimension of the window 1413 # This subroutine will change the dimension of the window
1426 # 1414 #
1427 # !self : instance of self 1415 # !self : instance of self
1428 # !event : 1416 # !event :
1429 @debugging 1417
1430 def OnSize(self, event=None): 1418 def OnSize(self, event=None):
1431 event.Skip() 1419 event.Skip()
1432 wx.CallAfter(self.scroll_down) 1420 wx.CallAfter(self.scroll_down)
1433 # def OnSize - end 1421 # def OnSize - end
1434 1422
1435 @debugging 1423
1436 def scroll_down(self): 1424 def scroll_down(self):
1437 self.Freeze() 1425 self.Freeze()
1438 self.chatwnd.scroll_down() 1426 self.chatwnd.scroll_down()
1439 self.Thaw() 1427 self.Thaw()
1440 1428
1441 ###### message helpers ###### 1429 ###### message helpers ######
1442 @debugging 1430
1443 def PurgeChat(self): 1431 def PurgeChat(self):
1444 self.set_colors() 1432 self.set_colors()
1445 self.chatwnd.SetPage(self.chatwnd.Header()) 1433 self.chatwnd.SetPage(self.chatwnd.Header())
1446 1434
1447 @debugging 1435
1448 def system_message(self, text): 1436 def system_message(self, text):
1449 self.send_chat_message(text,chat_msg.SYSTEM_MESSAGE) 1437 self.send_chat_message(text,chat_msg.SYSTEM_MESSAGE)
1450 self.SystemPost(text) 1438 self.SystemPost(text)
1451 1439
1452 @debugging 1440
1453 def info_message(self, text): 1441 def info_message(self, text):
1454 self.send_chat_message(text,chat_msg.INFO_MESSAGE) 1442 self.send_chat_message(text,chat_msg.INFO_MESSAGE)
1455 self.InfoPost(text) 1443 self.InfoPost(text)
1456 1444
1457 @debugging 1445
1458 def get_gms(self): 1446 def get_gms(self):
1459 the_gms = [] 1447 the_gms = []
1460 for playerid in self.session.players: 1448 for playerid in self.session.players:
1461 if len(self.session.players[playerid])>7: 1449 if len(self.session.players[playerid])>7:
1462 if self.session.players[playerid][7]=="GM" and self.session.group_id != '0': the_gms += [playerid] 1450 if self.session.players[playerid][7]=="GM" and self.session.group_id != '0': the_gms += [playerid]
1463 return the_gms 1451 return the_gms
1464 1452
1465 @debugging 1453
1466 def GetName(self): 1454 def GetName(self):
1467 self.AliasLib = component.get('alias') 1455 self.AliasLib = component.get('alias')
1468 player = self.session.get_my_info() 1456 player = self.session.get_my_info()
1469 if self.AliasLib != None: 1457 if self.AliasLib != None:
1470 self.AliasLib.alias = self.aliasList.GetStringSelection(); 1458 self.AliasLib.alias = self.aliasList.GetStringSelection();
1471 if self.AliasLib.alias[0] != self.defaultAliasName: 1459 if self.AliasLib.alias[0] != self.defaultAliasName:
1472 logger.debug("Exit chat_panel->GetName(self)") 1460 logger.debug("Exit chat_panel->GetName(self)")
1473 return [self.chat_display_name([self.AliasLib.alias[0], player[1], player[2]]), self.AliasLib.alias[1]] 1461 return [self.chat_display_name([self.AliasLib.alias[0], player[1], player[2]]), self.AliasLib.alias[1]]
1474 return [self.chat_display_name(player), "Default"] 1462 return [self.chat_display_name(player), "Default"]
1475 1463
1476 @debugging 1464
1477 def GetFilteredText(self, text): 1465 def GetFilteredText(self, text):
1478 advregex = re.compile('\"(.*?)\"', re.I) 1466 advregex = re.compile('\"(.*?)\"', re.I)
1479 self.AliasLib = component.get('alias') 1467 self.AliasLib = component.get('alias')
1480 if self.AliasLib != None: 1468 if self.AliasLib != None:
1481 self.AliasLib.filter = self.filterList.GetSelection()-1; 1469 self.AliasLib.filter = self.filterList.GetSelection()-1;
1486 match = m.group(0) 1474 match = m.group(0)
1487 newmatch = re.sub(rule[0], rule[1], match) 1475 newmatch = re.sub(rule[0], rule[1], match)
1488 text = text.replace(match, newmatch) 1476 text = text.replace(match, newmatch)
1489 return text 1477 return text
1490 1478
1491 @debugging 1479
1492 def emote_message(self, text): 1480 def emote_message(self, text):
1493 text = self.NormalizeParse(text) 1481 text = self.NormalizeParse(text)
1494 text = self.colorize(self.emotecolor, text) 1482 text = self.colorize(self.emotecolor, text)
1495 1483
1496 if self.type == MAIN_TAB and self.sendtarget == 'all': self.send_chat_message(text,chat_msg.EMOTE_MESSAGE) 1484 if self.type == MAIN_TAB and self.sendtarget == 'all': self.send_chat_message(text,chat_msg.EMOTE_MESSAGE)
1505 elif self.type == NULL_TAB: pass 1493 elif self.type == NULL_TAB: pass
1506 name = self.GetName()[0] 1494 name = self.GetName()[0]
1507 text = "** " + name + " " + text + " **" 1495 text = "** " + name + " " + text + " **"
1508 self.EmotePost(text) 1496 self.EmotePost(text)
1509 1497
1510 @debugging 1498
1511 def whisper_to_players(self, text, player_ids): 1499 def whisper_to_players(self, text, player_ids):
1512 tabbed_whispers_p = self.settings.get_setting("tabbedwhispers") 1500 tabbed_whispers_p = self.settings.get_setting("tabbedwhispers")
1513 # Heroman - apply any filtering selected 1501 # Heroman - apply any filtering selected
1514 text = self.NormalizeParse(text) 1502 text = self.NormalizeParse(text)
1515 player_names = "" 1503 player_names = ""
1532 for id in player_ids: 1520 for id in player_ids:
1533 id = id.strip() 1521 id = id.strip()
1534 if self.session.is_valid_id(id): self.send_chat_message(text,chat_msg.WHISPER_MESSAGE,id) 1522 if self.session.is_valid_id(id): self.send_chat_message(text,chat_msg.WHISPER_MESSAGE,id)
1535 else: self.InfoPost(id + " Unknown!") 1523 else: self.InfoPost(id + " Unknown!")
1536 1524
1537 @debugging 1525
1538 def send_chat_message(self, text, type=chat_msg.CHAT_MESSAGE, player_id="all"): 1526 def send_chat_message(self, text, type=chat_msg.CHAT_MESSAGE, player_id="all"):
1539 #########send_msg()############# 1527 #########send_msg()#############
1540 send = 1 1528 send = 1
1541 for plugin_fname in self.activeplugins.keys(): 1529 for plugin_fname in self.activeplugins.keys():
1542 plugin = self.activeplugins[plugin_fname] 1530 plugin = self.activeplugins[plugin_fname]
1558 msg.set_alias(playername) 1546 msg.set_alias(playername)
1559 if send: self.session.send(msg.toxml(),player_id) 1547 if send: self.session.send(msg.toxml(),player_id)
1560 del msg 1548 del msg
1561 1549
1562 #### incoming chat message handler ##### 1550 #### incoming chat message handler #####
1563 @debugging 1551
1564 def post_incoming_msg(self, msg, player): 1552 def post_incoming_msg(self, msg, player):
1565 1553
1566 # pull data 1554 # pull data
1567 type = msg.get_type() 1555 type = msg.get_type()
1568 text = msg.get_text() 1556 text = msg.get_text()
1682 sound_file = self.settings.get_setting(recvSound) 1670 sound_file = self.settings.get_setting(recvSound)
1683 if sound_file != '': 1671 if sound_file != '':
1684 component.get('sound').play(sound_file) 1672 component.get('sound').play(sound_file)
1685 #### Posting helpers ##### 1673 #### Posting helpers #####
1686 1674
1687 @debugging 1675
1688 def InfoPost(self, s): 1676 def InfoPost(self, s):
1689 self.Post(self.colorize(self.infocolor, s), c='info') 1677 self.Post(self.colorize(self.infocolor, s), c='info')
1690 1678
1691 @debugging 1679
1692 def SystemPost(self, s): 1680 def SystemPost(self, s):
1693 self.Post(self.colorize(self.syscolor, s), c='system') 1681 self.Post(self.colorize(self.syscolor, s), c='system')
1694 1682
1695 @debugging 1683
1696 def EmotePost(self, s): 1684 def EmotePost(self, s):
1697 self.Post(self.colorize(self.emotecolor, s), c='emote') 1685 self.Post(self.colorize(self.emotecolor, s), c='emote')
1698 1686
1699 #### Standard Post method ##### 1687 #### Standard Post method #####
1700 @debugging 1688
1701 def Post(self, s="", send=False, myself=False, c='post'): 1689 def Post(self, s="", send=False, myself=False, c='post'):
1702 strip_p = self.settings.get_setting("striphtml") 1690 strip_p = self.settings.get_setting("striphtml")
1703 strip_img = self.settings.get_setting("Show_Images_In_Chat")#moved back 7-11-05. --mDuo13 1691 strip_img = self.settings.get_setting("Show_Images_In_Chat")#moved back 7-11-05. --mDuo13
1704 if (strip_p == "1"): s = strip_html(s) 1692 if (strip_p == "1"): s = strip_html(s)
1705 if (strip_img == "0"): s = chat_util.strip_img_tags(s) 1693 if (strip_img == "0"): s = chat_util.strip_img_tags(s)
1792 # 1780 #
1793 # TimeIndexString() 1781 # TimeIndexString()
1794 # 1782 #
1795 # time indexing for chat display only (don't log time indexing) 1783 # time indexing for chat display only (don't log time indexing)
1796 # added by Snowdog 4/04 1784 # added by Snowdog 4/04
1797 @debugging 1785
1798 def TimeIndexString(self): 1786 def TimeIndexString(self):
1799 try: 1787 try:
1800 mtime = "" 1788 mtime = ""
1801 if self.settings.get_setting('Chat_Time_Indexing') == "0": pass 1789 if self.settings.get_setting('Chat_Time_Indexing') == "0": pass
1802 elif self.settings.get_setting('Chat_Time_Indexing') == "1": 1790 elif self.settings.get_setting('Chat_Time_Indexing') == "1":
1806 logger.general(traceback.format_exc()) 1794 logger.general(traceback.format_exc())
1807 logger.general("EXCEPTION: " + str(e)) 1795 logger.general("EXCEPTION: " + str(e))
1808 return "[ERROR]" 1796 return "[ERROR]"
1809 1797
1810 #### Post with parsing dice #### 1798 #### Post with parsing dice ####
1811 @debugging 1799
1812 def ParsePost(self, s, send=False, myself=False): 1800 def ParsePost(self, s, send=False, myself=False):
1813 s = self.NormalizeParse(s) 1801 s = self.NormalizeParse(s)
1814 self.set_colors() 1802 self.set_colors()
1815 self.Post(s,send,myself) 1803 self.Post(s,send,myself)
1816 1804
1817 @debugging 1805
1818 def NormalizeParse(self, s): 1806 def NormalizeParse(self, s):
1819 for plugin_fname in self.activeplugins.keys(): 1807 for plugin_fname in self.activeplugins.keys():
1820 plugin = self.activeplugins[plugin_fname] 1808 plugin = self.activeplugins[plugin_fname]
1821 try: s = plugin.pre_parse(s) 1809 try: s = plugin.pre_parse(s)
1822 except Exception, e: 1810 except Exception, e:
1828 s = self.ParseDice(s) 1816 s = self.ParseDice(s)
1829 s = self.ParseFilter(s) 1817 s = self.ParseFilter(s)
1830 self.parsed = 1 1818 self.parsed = 1
1831 return s 1819 return s
1832 1820
1833 @debugging 1821
1834 def ParseFilter(self, s): 1822 def ParseFilter(self, s):
1835 s = self.GetFilteredText(s) 1823 s = self.GetFilteredText(s)
1836 return s 1824 return s
1837 1825
1838 @debugging
1839 def ParseNode(self, s): 1826 def ParseNode(self, s):
1840 """Parses player input for embedded nodes rolls""" 1827 """Parses player input for embedded nodes rolls"""
1841 cur_loc = 0 1828 cur_loc = 0
1842 #[a-zA-Z0-9 _\-\.] 1829 #[a-zA-Z0-9 _\-\.]
1843 reg = re.compile("(!@([a-zA-Z0-9 _\-\./]+(::[a-zA-Z0-9 _\-\./]+)*)@!)") 1830 reg = re.compile("(!@(.*?)@!)")
1844 matches = reg.findall(s) 1831 matches = reg.findall(s)
1845 for i in xrange(0,len(matches)): 1832 for i in xrange(0,len(matches)):
1846 newstr = self.ParseNode(self.resolve_nodes(matches[i][1])) 1833 newstr = self.ParseNode(self.resolve_nodes(matches[i][1]))
1847 s = s.replace(matches[i][0], newstr, 1) 1834 s = s.replace(matches[i][0], newstr, 1)
1848 return s 1835 return s
1849 1836
1850 @debugging 1837
1851 def ParseDice(self, s): 1838 def ParseDice(self, s):
1852 """Parses player input for embedded dice rolls""" 1839 """Parses player input for embedded dice rolls"""
1853 reg = re.compile("\[([^]]*?)\]") 1840 reg = re.compile("\[([^]]*?)\]")
1854 matches = reg.findall(s) 1841 matches = reg.findall(s)
1855 for i in xrange(0,len(matches)): 1842 for i in xrange(0,len(matches)):
1864 if qmode == 1: 1851 if qmode == 1:
1865 s = s.replace("[" + matches[i] + "]", "<!-- Official Roll [" + newstr1 + "] => " + newstr + "-->" + newstr, 1) 1852 s = s.replace("[" + matches[i] + "]", "<!-- Official Roll [" + newstr1 + "] => " + newstr + "-->" + newstr, 1)
1866 else: s = s.replace("[" + matches[i] + "]", "[" + newstr1 + "<!-- Official Roll -->] => " + newstr, 1) 1853 else: s = s.replace("[" + matches[i] + "]", "[" + newstr1 + "<!-- Official Roll -->] => " + newstr, 1)
1867 return s 1854 return s
1868 1855
1869 @debugging 1856
1870 def PraseUnknowns(self, s): 1857 def PraseUnknowns(self, s):
1871 # Uses a tuple. Usage: ?Label}dY. If no Label is assigned then use ?}DY 1858 # Uses a tuple. Usage: ?Label}dY. If no Label is assigned then use ?}DY
1872 newstr = "0" 1859 newstr = "0"
1873 reg = re.compile("(\?\{*)([a-zA-Z ]*)(\}*)") 1860 reg = re.compile("(\?\{*)([a-zA-Z ]*)(\}*)")
1874 matches = reg.findall(s) 1861 matches = reg.findall(s)
1886 dlg.Destroy() 1873 dlg.Destroy()
1887 return s 1874 return s
1888 1875
1889 # This subroutine builds a chat display name. 1876 # This subroutine builds a chat display name.
1890 # 1877 #
1891 @debugging 1878
1892 def chat_display_name(self, player): 1879 def chat_display_name(self, player):
1893 if self.settings.get_setting("ShowIDInChat") == "0": 1880 if self.settings.get_setting("ShowIDInChat") == "0":
1894 display_name = player[0] 1881 display_name = player[0]
1895 else: 1882 else:
1896 display_name = "("+player[2]+") " + player[0] 1883 display_name = "("+player[2]+") " + player[0]
1897 return display_name 1884 return display_name
1898 1885
1899 # This subroutine will get a hex color and return it, or return nothing 1886 # This subroutine will get a hex color and return it, or return nothing
1900 # 1887 #
1901 @debugging 1888
1902 def get_color(self): 1889 def get_color(self):
1903 data = wx.ColourData() 1890 data = wx.ColourData()
1904 data.SetChooseFull(True) 1891 data.SetChooseFull(True)
1905 dlg = wx.ColourDialog(self, data) 1892 dlg = wx.ColourDialog(self, data)
1906 if dlg.ShowModal() == wx.ID_OK: 1893 if dlg.ShowModal() == wx.ID_OK:
1912 else: 1899 else:
1913 dlg.Destroy() 1900 dlg.Destroy()
1914 return None 1901 return None
1915 # def get_color - end 1902 # def get_color - end
1916 1903
1917 @debugging 1904
1918 def replace_quotes(self, s): 1905 def replace_quotes(self, s):
1919 in_tag = 0 1906 in_tag = 0
1920 i = 0 1907 i = 0
1921 rs = s[:] 1908 rs = s[:]
1922 for c in s: 1909 for c in s:
1929 if in_tag: 1916 if in_tag:
1930 rs = rs[:i] + "'" + rs[i+1:] 1917 rs = rs[:i] + "'" + rs[i+1:]
1931 i += 1 1918 i += 1
1932 return rs 1919 return rs
1933 1920
1934 @debugging 1921 def resolve_loop(self, node, path, step, depth):
1935 def resolve_loop(self, dom, nodeName, doLoop = False): 1922 if step == depth:
1923 self.resolution(node)
1924 else:
1925 child_list = node.findall('nodehandler')
1926 for child in child_list:
1927 if step == depth: break
1928 if child.get('name') == path[step]:
1929 node = child
1930 step += 1
1931 self.resolve_loop(node, path, step, depth)
1932
1933 def resolution(self, node):
1934 if self.passed == False:
1935 self.passed = True
1936 if node.get('class') == 'textctrl_handler': self.data = str(node.find('text').text)
1937 else: self.data = 'Nodehandler for '+ node.get('class') + ' not done!' or 'No Data!'
1938 else:
1939 self.data = ''
1940 pass
1941 self.data = self.ParseMap(self.data, node)
1942
1943 def ParseMap(self, s, node):
1944 """Parses player input for embedded nodes rolls"""
1945 cur_loc = 0
1946 reg = re.compile("(!!(.*?)!!)")
1947 matches = reg.findall(s)
1948 print matches
1949 for i in xrange(0,len(matches)):
1950 newstr = txt = '!@' + node.get('map') + '::' + matches[i][1] + '@!'
1951 s = s.replace(matches[i][0], newstr, 1)
1952 s = self.ParseNode(s)
1953 return s
1954
1955 def resolve_nodes(self, s):
1956 self.passed = False
1957 self.data = 'No Data!'
1958 value = ""
1959 path = s.split('::')
1960 depth = len(path)
1961 self.gametree = component.get('tree')
1962 dom = self.gametree.xml_root.getchildren()
1936 for node in dom: 1963 for node in dom:
1937 if node._get_tagName() != 'nodehandler': 1964 if node.get('name') == path[0]:
1938 continue 1965 self.resolve_loop(node, path, 1, len(path))
1939 if doLoop and node.getAttribute('class') != 'textctrl_handler' and node.hasChildNodes(): 1966 return self.data
1940 (found, node) = self.resolve_loop(node.getChildren(), nodeName, doLoop)
1941 if not found:
1942 continue
1943 if node.getAttribute('name') != nodeName:
1944 continue
1945 foundNode = node
1946 return (True, foundNode)
1947 return (False, '')
1948
1949 @debugging
1950 def resolve_nodes(self, s):
1951 value = ""
1952 node_path_list = s.split("::")
1953 gametree = component.get('tree')
1954 dom = gametree.master_dom.getChildren()
1955 for nodeName in node_path_list:
1956 (found, node) = self.resolve_loop(dom, nodeName)
1957 if not found:
1958 break
1959 dom = node.getChildren()
1960 if not found:
1961 dom = gametree.master_dom.getChildren()
1962 loop = False
1963 if len(node_path_list) == 1:
1964 loop = True
1965 for nodeName in node_path_list:
1966 (found, node) = self.resolve_loop(dom, nodeName, loop)
1967 if not found:
1968 break
1969 dom = node.getChildren()
1970 loop = True
1971 if found:
1972 text = node.getElementsByTagName('text')
1973 node = text[0]._get_firstChild()
1974 value = node._get_nodeValue()
1975 else:
1976 value = s
1977 return value