Mercurial > traipse_dev
comparison orpg/tools/aliaslib.py @ 0:4385a7d0efd1 grumpy-goblin
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author | sirebral |
---|---|
date | Tue, 14 Jul 2009 16:41:58 -0500 |
parents | |
children | c160f26ecf65 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4385a7d0efd1 |
---|---|
1 # Copyright (C) 2000-2001 The OpenRPG Project | |
2 # | |
3 # openrpg-dev@lists.sourceforge.net | |
4 # | |
5 # This program is free software; you can redistribute it and/or modify | |
6 # it under the terms of the GNU General Public License as published by | |
7 # the Free Software Foundation; either version 2 of the License, or | |
8 # (at your option) any later version. | |
9 # | |
10 # This program is distributed in the hope that it will be useful, | |
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 # GNU General Public License for more details. | |
14 # | |
15 # You should have received a copy of the GNU General Public License | |
16 # along with this program; if not, write to the Free Software | |
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
18 # -- | |
19 # | |
20 # File: aliaslib.py | |
21 # Author: Dj Gilcrease | |
22 # Maintainer: | |
23 # Version: | |
24 # $Id: aliaslib.py,v 1.20 2007/08/09 05:23:21 digitalxero Exp $ | |
25 # | |
26 # Description: nodehandler for alias. | |
27 # | |
28 | |
29 __version__ = "$Id: aliaslib.py,v 1.20 2007/08/09 05:23:21 digitalxero Exp $" | |
30 | |
31 from orpg.orpg_wx import * | |
32 from orpg.orpgCore import * | |
33 from orpg.orpg_windows import createMaskedButton, orpgMultiCheckBoxDlg | |
34 from orpg.tools.rgbhex import RGBHex | |
35 import orpg.tools.orpg_log | |
36 import orpg.dirpath | |
37 import orpg.orpg_xml | |
38 import orpg.tools.validate | |
39 import orpg.tools.orpg_settings | |
40 | |
41 class AliasLib(wx.Frame): | |
42 def __init__(self): | |
43 self.orpgframe = open_rpg.get_component('frame') | |
44 self.log = open_rpg.get_component('log') | |
45 self.log.log("Enter AliasLib", ORPG_DEBUG) | |
46 wx.Frame.__init__(self, None, wx.ID_ANY, title="Alias Lib") | |
47 self.orpgframe.Freeze() | |
48 self.Freeze() | |
49 self.SetOwnBackgroundColour('#EFEFEF') | |
50 self.dir_struct = open_rpg.get_component('dir_struct') | |
51 self.settings = open_rpg.get_component('settings') | |
52 self.xml = open_rpg.get_component('xml') | |
53 self.validate = open_rpg.get_component('validate') | |
54 self.filename = self.settings.get_setting('aliasfile') + '.alias' | |
55 self.validate.config_file(self.filename, "default_alias.alias") | |
56 self.buildMenu() | |
57 self.buildButtons() | |
58 self.buildGUI() | |
59 wx.CallAfter(self.InitSetup) | |
60 wx.CallAfter(self.loadFile) | |
61 self.Thaw() | |
62 self.orpgframe.Thaw() | |
63 self.Bind(wx.EVT_CLOSE, self.OnMB_FileExit) | |
64 self.log.log("Exit AliasLib", ORPG_DEBUG) | |
65 | |
66 def InitSetup(self): | |
67 self.chat = open_rpg.get_component('chat') | |
68 self.gametree = open_rpg.get_component('tree') | |
69 self.map = open_rpg.get_component('map') | |
70 self.session = open_rpg.get_component('session') | |
71 | |
72 def buildMenu(self): | |
73 self.log.log("Enter AliasLib->buildMenu(self)", ORPG_DEBUG) | |
74 filemenu = wx.Menu() | |
75 item = wx.MenuItem(filemenu, wx.ID_ANY, "&New\tCtrl+N", "New ALias Lib") | |
76 self.Bind(wx.EVT_MENU, self.OnMB_FileNew, item) | |
77 filemenu.AppendItem(item) | |
78 item = wx.MenuItem(filemenu, wx.ID_ANY, "&Open\tCtrl+O", "Open Alias Lib") | |
79 self.Bind(wx.EVT_MENU, self.OnMB_FileOpen, item) | |
80 filemenu.AppendItem(item) | |
81 item = wx.MenuItem(filemenu, wx.ID_ANY, "&Save\tCtrl+S", "Save Alias Lib") | |
82 self.Bind(wx.EVT_MENU, self.OnMB_FileSave, item) | |
83 filemenu.AppendItem(item) | |
84 item = wx.MenuItem(filemenu, wx.ID_ANY, "&Export to Tree", "Export to Tree") | |
85 self.Bind(wx.EVT_MENU, self.OnMB_FileExportToTree, item) | |
86 filemenu.AppendItem(item) | |
87 item = wx.MenuItem(filemenu, wx.ID_ANY, "&Exit\tCtrl+X", "Exit") | |
88 self.Bind(wx.EVT_MENU, self.OnMB_FileExit, item) | |
89 filemenu.AppendItem(item) | |
90 aliasmenu = wx.Menu() | |
91 item = wx.MenuItem(aliasmenu, wx.ID_ANY, "New", "New") | |
92 self.Bind(wx.EVT_MENU, self.OnMB_AliasNew, item) | |
93 aliasmenu.AppendItem(item) | |
94 item = wx.MenuItem(aliasmenu, wx.ID_ANY, "Add Temporary", "Add Temporary") | |
95 self.Bind(wx.EVT_MENU, self.OnMB_AliasAddTemporary, item) | |
96 aliasmenu.AppendItem(item) | |
97 item = wx.MenuItem(aliasmenu, wx.ID_ANY, "Edit", "Edit") | |
98 self.Bind(wx.EVT_MENU, self.OnMB_AliasEdit, item) | |
99 aliasmenu.AppendItem(item) | |
100 item = wx.MenuItem(aliasmenu, wx.ID_ANY, "Delete", "Delete") | |
101 self.Bind(wx.EVT_MENU, self.OnMB_AliasDelete, item) | |
102 aliasmenu.AppendItem(item) | |
103 filtermenu = wx.Menu() | |
104 item = wx.MenuItem(filtermenu, wx.ID_ANY, "New", "New") | |
105 self.Bind(wx.EVT_MENU, self.OnMB_FilterNew, item) | |
106 filtermenu.AppendItem(item) | |
107 item = wx.MenuItem(filtermenu, wx.ID_ANY, "Edit", "Edit") | |
108 self.Bind(wx.EVT_MENU, self.OnMB_FilterEdit, item) | |
109 filtermenu.AppendItem(item) | |
110 item = wx.MenuItem(filtermenu, wx.ID_ANY, "Delete", "Delete") | |
111 self.Bind(wx.EVT_MENU, self.OnMB_FilterDelete, item) | |
112 filtermenu.AppendItem(item) | |
113 transmitmenu = wx.Menu() | |
114 item = wx.MenuItem(transmitmenu, wx.ID_ANY, "Send\tCtrl+Enter", "Send") | |
115 self.Bind(wx.EVT_MENU, self.OnMB_TransmitSend, item) | |
116 transmitmenu.AppendItem(item) | |
117 item = wx.MenuItem(transmitmenu, wx.ID_ANY, "Emote\tCtrl+E", "Emote") | |
118 self.Bind(wx.EVT_MENU, self.OnMB_TransmitEmote, item) | |
119 transmitmenu.AppendItem(item) | |
120 item = wx.MenuItem(transmitmenu, wx.ID_ANY, "Whisper\tCtrl+W", "Whisper") | |
121 self.Bind(wx.EVT_MENU, self.OnMB_TransmitWhisper, item) | |
122 transmitmenu.AppendItem(item) | |
123 item = wx.MenuItem(transmitmenu, wx.ID_ANY, "Macro\tCtrl+M", "Macro") | |
124 self.Bind(wx.EVT_MENU, self.OnMB_TransmitMacro, item) | |
125 transmitmenu.AppendItem(item) | |
126 menu = wx.MenuBar() | |
127 menu.Append(filemenu, "&File") | |
128 menu.Append(aliasmenu, "&Alias") | |
129 menu.Append(filtermenu, "&Filter") | |
130 menu.Append(transmitmenu, "&Transmit") | |
131 self.SetMenuBar(menu) | |
132 self.log.log("Exit AliasLib->buildMenu(self)", ORPG_DEBUG) | |
133 | |
134 def OnMB_FileNew(self, event): | |
135 self.log.log("Enter AliasLib->OnMB_FileNew(self, event)", ORPG_DEBUG) | |
136 oldfilename = self.filename | |
137 dlg = wx.TextEntryDialog(self, "Please Name This Alias Lib", "New Alias Lib") | |
138 if dlg.ShowModal() == wx.ID_OK: | |
139 self.filename = dlg.GetValue() + '.alias' | |
140 dlg.Destroy() | |
141 if oldfilename != self.filename: | |
142 self.OnMB_FileSave(None, oldfilename) | |
143 self.aliasList = [] | |
144 self.filterList = [] | |
145 self.OnMB_FileSave(None) | |
146 self.settings.set_setting('aliasfile', self.filename[:-6]) | |
147 self.log.log("Exit AliasLib->OnMB_FileNew(self, event)", ORPG_DEBUG) | |
148 | |
149 def OnMB_FileOpen(self, event): | |
150 self.log.log("Enter AliasLib->OnMB_FileOpen(self, event)", ORPG_DEBUG) | |
151 oldfilename = self.filename | |
152 dlg = wx.FileDialog(self, "Select an Alias Lib to Open", self.dir_struct["user"], wildcard="*.alias", style=wx.HIDE_READONLY|wx.OPEN) | |
153 if dlg.ShowModal() == wx.ID_OK: | |
154 self.filename = dlg.GetFilename() | |
155 dlg.Destroy() | |
156 if oldfilename != self.filename: | |
157 self.OnMB_FileSave(None, oldfilename) | |
158 self.loadFile() | |
159 self.settings.set_setting('aliasfile', self.filename[:-6]) | |
160 self.log.log("Exit AliasLib->OnMB_FileOpen(self, event)", ORPG_DEBUG) | |
161 | |
162 def OnMB_FileSave(self, event, file=None): | |
163 self.log.log("Enter AliasLib->OnMB_FileSave(self, event)", ORPG_DEBUG) | |
164 idx = self.aliasIdx | |
165 if file == None: | |
166 file = self.filename | |
167 xml = "<aliaslib>\n" | |
168 for n in xrange(self.selectAliasWnd.GetItemCount()): | |
169 self.alias = n | |
170 xml += "\t<alias " | |
171 xml += 'name="' + self.MakeHTMLSafe(self.alias[0]) + '" ' | |
172 xml += 'color="' + self.alias[1] + '" ' | |
173 xml += "/>\n" | |
174 for n in xrange(1, len(self.filterList)): | |
175 xml += "\t<filter " | |
176 xml += 'name="' + self.filterList[n] + '">' + "\n" | |
177 for rule in self.regExList[n-1]: | |
178 xml += "\t\t<rule " | |
179 xml += 'match="' + self.MakeHTMLSafe(rule[0]) + '" ' | |
180 xml += 'sub="' + self.MakeHTMLSafe(rule[1]) + '" ' | |
181 xml += "/>\n" | |
182 xml += "\t</filter>\n" | |
183 xml += "</aliaslib>" | |
184 self.alias = idx | |
185 f = open(self.dir_struct["user"] + file, "w") | |
186 f.write(xml) | |
187 f.close() | |
188 self.log.log("Exit AliasLib->OnMB_FileSave(self, event)", ORPG_DEBUG) | |
189 | |
190 def OnMB_FileExportToTree(self, event): | |
191 self.log.log("Enter AliasLib->OnMB_FileExportToTree(self, event)", ORPG_DEBUG) | |
192 #tree = open_rpg.get_component("tree") | |
193 xml = '<nodehandler class="voxchat_handler" icon="player" module="voxchat" name="' + self.filename[:-6] + '" use.filter="0" version="1.0">' + "\n" | |
194 idx = self.aliasIdx | |
195 for n in xrange(self.selectAliasWnd.GetItemCount()): | |
196 self.alias = n | |
197 xml += "\t<voxchat.alias " | |
198 xml += 'name="' + self.MakeHTMLSafe(self.alias[0]) + '" ' | |
199 xml += 'color="' + self.alias[1] + '" ' | |
200 xml += "/>\n" | |
201 self.alias = idx | |
202 for n in xrange(1, len(self.filterList)): | |
203 xml += "\t<voxchat.filter " | |
204 xml += 'name="' + self.filterList[n] + '">' + "\n" | |
205 for rule in self.regExList[n-1]: | |
206 xml += "\t\t<rule " | |
207 xml += 'match="' + self.MakeHTMLSafe(rule[0]) + '" ' | |
208 xml += 'sub="' + self.MakeHTMLSafe(rule[1]) + '" ' | |
209 xml += "/>\n" | |
210 xml += "\t</voxchat.filter>\n" | |
211 xml += "</nodehandler>" | |
212 self.gametree.insert_xml(xml) | |
213 self.log.log("Exit AliasLib->OnMB_FileExportToTree(self, event)", ORPG_DEBUG) | |
214 | |
215 def OnMB_FileExit(self, event): | |
216 self.log.log("Enter AliasLib->OnMB_FileExit(self, event)", ORPG_DEBUG) | |
217 self.OnMB_FileSave(0) | |
218 self.Hide() | |
219 top_frame = open_rpg.get_component('frame') | |
220 top_frame.mainmenu.Check(top_frame.mainmenu.FindMenuItem("Windows", "Alias Lib"), False) | |
221 self.log.log("Exit AliasLib->OnMB_FileExit(self, event)", ORPG_DEBUG) | |
222 | |
223 def OnMB_AliasNew(self, event): | |
224 self.log.log("Enter AliasLib->OnMB_AliasNew(self, event)", ORPG_DEBUG) | |
225 self.NewEditAliasDialog("New") | |
226 self.log.log("Exit AliasLib->OnMB_AliasNew(self, event)", ORPG_DEBUG) | |
227 | |
228 def OnMB_AliasAddTemporary(self, event): | |
229 self.log.log("Enter AliasLib->OnMB_AliasAddTemporary(self, event)", ORPG_DEBUG) | |
230 minis = self.map.canvas.layers['miniatures'].miniatures | |
231 for min in minis: | |
232 name = min.label | |
233 if name not in self.aliasList: | |
234 i = self.selectAliasWnd.InsertStringItem(self.selectAliasWnd.GetItemCount(), name) | |
235 self.selectAliasWnd.SetStringItem(i, 1, "Default") | |
236 self.selectAliasWnd.RefreshItem(i) | |
237 self.RefreshAliases() | |
238 self.log.log("Exit AliasLib->OnMB_AliasAddTemporary(self, event)", ORPG_DEBUG) | |
239 | |
240 def OnMB_AliasEdit(self, event): | |
241 self.log.log("Enter AliasLib->OnMB_AliasEdit(self, event)", ORPG_DEBUG) | |
242 if self.aliasIdx != -1: | |
243 self.NewEditAliasDialog("Edit") | |
244 self.log.log("Exit AliasLib->OnMB_AliasEdit(self, event)", ORPG_DEBUG) | |
245 | |
246 def NewEditAliasDialog(self, type): | |
247 self.log.log("Enter AliasLib->NewEditAliasDialog(self, type)", ORPG_DEBUG) | |
248 dlg = wx.Dialog(self, wx.ID_ANY, type + " Alias", style=wx.DEFAULT_DIALOG_STYLE|wx.STAY_ON_TOP) | |
249 txt = wx.TextCtrl(dlg, wx.ID_ANY) | |
250 if type == 'Edit': | |
251 txt.SetValue(self.alias[0]) | |
252 self.colorbtn = wx.Button(dlg, wx.ID_ANY, "Default Color") | |
253 dlg.Bind(wx.EVT_BUTTON, self.ChangeAliasColor, self.colorbtn) | |
254 if self.alias[1] != 'Default': | |
255 self.colorbtn.SetLabel("Chat Color") | |
256 self.colorbtn.SetForegroundColour(self.alias[1]) | |
257 okbtn = wx.Button(dlg, wx.ID_OK) | |
258 sizer = wx.BoxSizer(wx.HORIZONTAL) | |
259 sizer.Add(wx.StaticText(dlg, wx.ID_ANY, "Alias: "), 0, wx.EXPAND) | |
260 sizer.Add(txt, 1, wx.EXPAND) | |
261 sizer.Add(self.colorbtn, 0, wx.EXPAND) | |
262 sizer.Add(okbtn, 0, wx.EXPAND) | |
263 dlg.SetSizer(sizer) | |
264 dlg.SetAutoLayout(True) | |
265 dlg.Fit() | |
266 if dlg.ShowModal() == wx.ID_OK: | |
267 (r, g, b) = self.colorbtn.GetForegroundColour().Get() | |
268 if type == 'Edit': | |
269 self.selectAliasWnd.SetStringItem(self.aliasIdx, 0, txt.GetValue()) | |
270 if self.colorbtn.GetLabel() != 'Default Color': | |
271 self.aliasColor = RGBHex().hexstring(r, g, b) | |
272 self.selectAliasWnd.RefreshItem(self.aliasIdx) | |
273 else: | |
274 i = self.selectAliasWnd.InsertStringItem(self.selectAliasWnd.GetItemCount(), txt.GetValue()) | |
275 if self.colorbtn.GetLabel() == 'Default Color': | |
276 self.selectAliasWnd.SetStringItem(i, 1, "Default") | |
277 else: | |
278 self.selectAliasWnd.SetStringItem(i, 1, RGBHex().hexstring(r, g, b)) | |
279 self.selectAliasWnd.SetItemTextColour(i, RGBHex().hexstring(r, g, b)) | |
280 self.selectAliasWnd.RefreshItem(i) | |
281 self.RefreshAliases() | |
282 self.log.log("Exit AliasLib->NewEditAliasDialog(self, type)", ORPG_DEBUG) | |
283 | |
284 def ChangeAliasColor(self, event): | |
285 self.log.log("Enter AliasLib->ChangeAliasColor(self, event)", ORPG_DEBUG) | |
286 color = RGBHex().do_hex_color_dlg(self) | |
287 self.colorbtn.SetLabel("Chat Color") | |
288 self.colorbtn.SetForegroundColour(color) | |
289 self.log.log("Exit AliasLib->ChangeAliasColor(self, event)", ORPG_DEBUG) | |
290 | |
291 def OnMB_AliasDelete(self, event): | |
292 self.log.log("Enter AliasLib->OnMB_AliasDelete(self, event)", ORPG_DEBUG) | |
293 if self.aliasIdx != -1: | |
294 self.selectAliasWnd.DeleteItem(self.aliasIdx) | |
295 self.RefreshAliases() | |
296 self.log.log("Exit AliasLib->OnMB_AliasDelete(self, event)", ORPG_DEBUG) | |
297 | |
298 def OnMB_FilterNew(self, event): | |
299 self.log.log("Enter AliasLib->OnMB_FilterNew(self, event)", ORPG_DEBUG) | |
300 dlg = wx.TextEntryDialog(self, 'Filter Name: ', 'Please name this filter') | |
301 if dlg.ShowModal() != wx.ID_OK: | |
302 dlg.Destroy() | |
303 return | |
304 filterName = dlg.GetValue() | |
305 i = self.selectFilterWnd.InsertStringItem(self.selectFilterWnd.GetItemCount(), filterName) | |
306 self.filter = i | |
307 self.regExList.append([]) | |
308 self.OnMB_FilterEdit(None) | |
309 self.log.log("Exit AliasLib->OnMB_FilterNew(self, event)", ORPG_DEBUG) | |
310 | |
311 def OnMB_FilterEdit(self, event): | |
312 self.log.log("Enter AliasLib->OnMB_FilterEdit(self, event)", ORPG_DEBUG) | |
313 wnd = FilterEditWnd(self, self.filter, self.filterRegEx) | |
314 wnd.MakeModal(True) | |
315 wnd.Show() | |
316 self.log.log("Exit AliasLib->OnMB_FilterEdit(self, event)", ORPG_DEBUG) | |
317 | |
318 def OnMB_FilterDelete(self, event): | |
319 self.log.log("Enter AliasLib->OnMB_FilterDelete(self, event)", ORPG_DEBUG) | |
320 if self.filterIdx != -1: | |
321 self.selectFilterWnd.DeleteItem(self.filterIdx) | |
322 self.log.log("Exit AliasLib->OnMB_FilterDelete(self, event)", ORPG_DEBUG) | |
323 | |
324 def OnMB_TransmitSend(self, event): | |
325 self.log.log("Enter AliasLib->OnMB_TransmitSend(self, event)", ORPG_DEBUG) | |
326 self.orpgframe.Freeze() | |
327 if self.alias[1] != 'Default': | |
328 defaultcolor = self.settings.get_setting("mytextcolor") | |
329 self.settings.set_setting("mytextcolor", self.alias[1]) | |
330 self.chat.set_colors() | |
331 line = self.textWnd.GetValue().replace("\n", "<br />") | |
332 if self.checkFilterText.IsChecked() and self.filter != self.chat.defaultFilterName: | |
333 for rule in self.filterRegEx: | |
334 line = re.sub(rule[0], rule[1], line) | |
335 if len(line) > 1: | |
336 if len(line) > 1 and line[0] != "/": | |
337 self.chat.ParsePost(line, True, True) | |
338 else: | |
339 self.chat.chat_cmds.docmd(line) | |
340 if self.alias[1] != 'Default': | |
341 self.settings.set_setting("mytextcolor", defaultcolor) | |
342 self.chat.set_colors() | |
343 if self.checkClearText.IsChecked(): | |
344 self.textWnd.SetValue("") | |
345 top_frame.Thaw() | |
346 self.log.log("Exit AliasLib->OnMB_TransmitSend(self, event)", ORPG_DEBUG) | |
347 | |
348 def OnMB_TransmitEmote(self, event): | |
349 self.log.log("Enter AliasLib->OnMB_TransmitEmote(self, event)", ORPG_DEBUG) | |
350 self.orpgframe.Freeze() | |
351 line = self.textWnd.GetValue().replace("\n", "<br />") | |
352 if self.checkFilterText.IsChecked() and self.filter != self.chat.defaultFilterName: | |
353 for rule in self.filterRegEx: | |
354 line = re.sub(rule[0], rule[1], line) | |
355 self.chat.emote_message(line) | |
356 if self.checkClearText.IsChecked(): | |
357 self.textWnd.SetValue("") | |
358 top_frame.Thaw() | |
359 self.log.log("Exit AliasLib->OnMB_TransmitEmote(self, event)", ORPG_DEBUG) | |
360 | |
361 def OnMB_TransmitWhisper(self, event): | |
362 self.log.log("Enter AliasLib->OnMB_TransmitWhisper(self, event)", ORPG_DEBUG) | |
363 self.orpgframe.Freeze() | |
364 players = self.session.get_players() | |
365 if self.alias[1] != 'Default': | |
366 defaultcolor = self.settings.get_setting("mytextcolor") | |
367 self.settings.set_setting("mytextcolor", self.alias[1]) | |
368 self.chat.set_colors() | |
369 opts = [] | |
370 myid = session.get_id() | |
371 for p in players: | |
372 if p[2] != myid: | |
373 opts.append("(" + p[2] + ") " + self.chat.html_strip(p[0])) | |
374 dlg = orpgMultiCheckBoxDlg(self, opts, "Select Players:", "Whisper To", []) | |
375 sendto = [] | |
376 if dlg.ShowModal() == wx.ID_OK: | |
377 selections = dlg.get_selections() | |
378 for s in selections: | |
379 sendto.append(players[s][2]) | |
380 line = self.textWnd.GetValue().replace("\n", "<br />") | |
381 if self.checkFilterText.IsChecked() and self.filter != self.chat.defaultFilterName: | |
382 for rule in self.filterRegEx: | |
383 line = re.sub(rule[0], rule[1], line) | |
384 if len(sendto): | |
385 self.chat.whisper_to_players(line, sendto) | |
386 if self.alias[1] != 'Default': | |
387 self.settings.set_setting("mytextcolor", defaultcolor) | |
388 self.chat.set_colors() | |
389 if self.checkClearText.IsChecked(): | |
390 self.textWnd.SetValue("") | |
391 top_frame.Thaw() | |
392 self.log.log("Exit AliasLib->OnMB_TransmitWhisper(self, event)", ORPG_DEBUG) | |
393 | |
394 def OnMB_TransmitMacro(self, event): | |
395 self.log.log("Enter AliasLib->OnMB_TransmitMacro(self, event)", ORPG_DEBUG) | |
396 self.orpgframe.Freeze() | |
397 if self.alias[1] != 'Default': | |
398 defaultcolor = self.settings.get_setting("mytextcolor") | |
399 self.settings.set_setting("mytextcolor", self.alias[1]) | |
400 self.chat.set_colors() | |
401 lines = self.textWnd.GetValue().split("\n") | |
402 if self.checkFilterText.IsChecked() and self.filter != self.chat.defaultFilterName: | |
403 for rule in self.filterRegEx: | |
404 line = re.sub(rule[0], rule[1], line) | |
405 for line in lines: | |
406 if len(line) > 1: | |
407 if line[0] != "/": | |
408 self.chat.ParsePost(line, True, True) | |
409 else: | |
410 self.chat.chat_cmds.docmd(line) | |
411 if self.alias[1] != 'Default': | |
412 self.settings.set_setting("mytextcolor", defaultcolor) | |
413 self.chat.set_colors() | |
414 if self.checkClearText.IsChecked(): | |
415 self.textWnd.SetValue("") | |
416 top_frame.Thaw() | |
417 self.log.log("Exit AliasLib->OnMB_TransmitMacro(self, event)", ORPG_DEBUG) | |
418 | |
419 def buildButtons(self): | |
420 self.log.log("Enter AliasLib->buildButtons(self)", ORPG_DEBUG) | |
421 self.topBtnSizer = wx.BoxSizer(wx.HORIZONTAL) | |
422 self.middleBtnSizer = wx.BoxSizer(wx.HORIZONTAL) | |
423 self.bottomBtnSizer = wx.BoxSizer(wx.HORIZONTAL) | |
424 self.addFromMapBtn = createMaskedButton(self, self.dir_struct["icon"] + 'install.gif', 'Add temporary aliases from map', wx.ID_ANY, "#C0C0C0") | |
425 self.newAliasBtn = createMaskedButton(self, self.dir_struct["icon"] + 'player.gif', 'Add a new Alias', wx.ID_ANY) | |
426 self.delAliasBtn = createMaskedButton(self, self.dir_struct["icon"] + 'noplayer.gif', 'Delete selected Alias', wx.ID_ANY) | |
427 self.editAliasBtn = createMaskedButton(self, self.dir_struct["icon"] + 'note.gif', 'Edit selected Alias', wx.ID_ANY) | |
428 self.Bind(wx.EVT_BUTTON, self.OnMB_AliasNew, self.newAliasBtn) | |
429 self.Bind(wx.EVT_BUTTON, self.OnMB_AliasAddTemporary, self.addFromMapBtn) | |
430 self.Bind(wx.EVT_BUTTON, self.OnMB_AliasEdit, self.editAliasBtn) | |
431 self.Bind(wx.EVT_BUTTON, self.OnMB_AliasDelete, self.delAliasBtn) | |
432 self.newFilterBtn = createMaskedButton(self, self.dir_struct["icon"] + 'add_filter.gif', 'Add a new Filter', wx.ID_ANY, "#0000FF") | |
433 self.editFilterBtn = createMaskedButton(self, self.dir_struct["icon"] + 'edit_filter.gif', 'Edit selected Filter', wx.ID_ANY, "#FF0000") | |
434 self.delFilterBtn = createMaskedButton(self, self.dir_struct["icon"] + 'delete_filter.gif', 'Delete selected Filter', wx.ID_ANY, "#0000FF") | |
435 self.Bind(wx.EVT_BUTTON, self.OnMB_FilterNew, self.newFilterBtn) | |
436 self.Bind(wx.EVT_BUTTON, self.OnMB_FilterEdit, self.editFilterBtn) | |
437 self.Bind(wx.EVT_BUTTON, self.OnMB_FilterDelete, self.delFilterBtn) | |
438 self.textBoldBtn = createMaskedButton(self, self.dir_struct["icon"] + 'bold.gif', 'Bold', wx.ID_ANY, "#BDBDBD") | |
439 self.textItalicBtn = createMaskedButton(self, self.dir_struct["icon"] + 'italic.gif', 'Italic', wx.ID_ANY, "#BDBDBD") | |
440 self.textUnderlineBtn = createMaskedButton(self, self.dir_struct["icon"] + 'underlined.gif', 'Underline', wx.ID_ANY, "#BDBDBD") | |
441 self.textColorBtn = wx.Button(self, wx.ID_ANY, "Color") | |
442 self.textColorBtn.SetForegroundColour(wx.BLACK) | |
443 self.exportBtn = createMaskedButton(self, self.dir_struct["icon"] + 'grid.gif', 'Export to Tree', wx.ID_ANY) | |
444 self.Bind(wx.EVT_BUTTON, self.FormatText, self.textBoldBtn) | |
445 self.Bind(wx.EVT_BUTTON, self.FormatText, self.textItalicBtn) | |
446 self.Bind(wx.EVT_BUTTON, self.FormatText, self.textUnderlineBtn) | |
447 self.Bind(wx.EVT_BUTTON, self.FormatText, self.textColorBtn) | |
448 self.Bind(wx.EVT_BUTTON, self.OnMB_FileExportToTree, self.exportBtn) | |
449 self.topBtnSizer.Add(self.newAliasBtn, 0, wx.EXPAND) | |
450 self.topBtnSizer.Add(self.addFromMapBtn, 0, wx.EXPAND) | |
451 self.topBtnSizer.Add(self.editAliasBtn, 0, wx.EXPAND) | |
452 self.topBtnSizer.Add(self.delAliasBtn, 0, wx.EXPAND) | |
453 self.topBtnSizer.Add(self.newFilterBtn, 0, wx.EXPAND) | |
454 self.topBtnSizer.Add(self.editFilterBtn, 0, wx.EXPAND) | |
455 self.topBtnSizer.Add(self.delFilterBtn, 0, wx.EXPAND) | |
456 self.topBtnSizer.Add(self.textBoldBtn, 0, wx.EXPAND) | |
457 self.topBtnSizer.Add(self.textItalicBtn, 0, wx.EXPAND) | |
458 self.topBtnSizer.Add(self.textUnderlineBtn, 0, wx.EXPAND) | |
459 self.topBtnSizer.Add(self.textColorBtn, 0, wx.EXPAND) | |
460 self.topBtnSizer.Add(self.exportBtn, 0, wx.EXPAND|wx.ALIGN_RIGHT) | |
461 self.checkFilterText = wx.CheckBox(self, wx.ID_ANY, "Filter Text") | |
462 self.Bind(wx.EVT_CHECKBOX, self.FilterTextChecked, self.checkFilterText) | |
463 self.checkClearText = wx.CheckBox(self, wx.ID_ANY, "Auto Clear Text") | |
464 self.middleBtnSizer.Add(self.checkFilterText, 0, wx.EXPAND) | |
465 self.middleBtnSizer.Add(self.checkClearText, 0, wx.EXPAND) | |
466 self.sayBtn = wx.Button(self, wx.ID_ANY, "Say") | |
467 self.emoteBtn = wx.Button(self, wx.ID_ANY, "Emote") | |
468 self.whisperBtn = wx.Button(self, wx.ID_ANY, "Whisper") | |
469 self.macroBtn = wx.Button(self, wx.ID_ANY, "Macro") | |
470 self.doneBtn = wx.Button(self, wx.ID_ANY, "Done") | |
471 self.Bind(wx.EVT_BUTTON, self.OnMB_TransmitSend, self.sayBtn) | |
472 self.Bind(wx.EVT_BUTTON, self.OnMB_TransmitEmote, self.emoteBtn) | |
473 self.Bind(wx.EVT_BUTTON, self.OnMB_TransmitWhisper, self.whisperBtn) | |
474 self.Bind(wx.EVT_BUTTON, self.OnMB_TransmitMacro, self.macroBtn) | |
475 self.Bind(wx.EVT_BUTTON, self.OnMB_FileExit, self.doneBtn) | |
476 self.bottomBtnSizer.Add(self.sayBtn, 0, wx.EXPAND) | |
477 self.bottomBtnSizer.Add(self.emoteBtn, 0, wx.EXPAND) | |
478 self.bottomBtnSizer.Add(self.whisperBtn, 0, wx.EXPAND) | |
479 self.bottomBtnSizer.Add(self.macroBtn, 0, wx.EXPAND) | |
480 self.bottomBtnSizer.Add(self.doneBtn, 0, wx.EXPAND|wx.ALIGN_RIGHT) | |
481 self.log.log("Exit AliasLib->buildButtons(self)", ORPG_DEBUG) | |
482 | |
483 def buildGUI(self): | |
484 self.log.log("Enter AliasLib->buildGUI(self)", ORPG_DEBUG) | |
485 self.sizer = wx.BoxSizer(wx.VERTICAL) | |
486 rightwnd = wx.SplitterWindow(self, wx.ID_ANY, style=wx.SP_LIVE_UPDATE|wx.SP_NO_XP_THEME|wx.SP_3DSASH) | |
487 leftwnd = wx.SplitterWindow(rightwnd, wx.ID_ANY, style=wx.SP_LIVE_UPDATE|wx.SP_NO_XP_THEME|wx.SP_3DSASH) | |
488 self.selectAliasWnd = wx.ListCtrl(leftwnd, wx.ID_ANY, style=wx.LC_SINGLE_SEL|wx.LC_REPORT|wx.LC_HRULES) | |
489 self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.NewAliasSelection, self.selectAliasWnd) | |
490 self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.NoAliasSelection, self.selectAliasWnd) | |
491 self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnMB_AliasEdit, self.selectAliasWnd) | |
492 self.selectFilterWnd = wx.ListCtrl(leftwnd, wx.ID_ANY, style=wx.LC_SINGLE_SEL|wx.LC_REPORT|wx.LC_HRULES) | |
493 self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.NewFilterSelection, self.selectFilterWnd) | |
494 self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.NoFilterSelection, self.selectFilterWnd) | |
495 self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnMB_FilterEdit, self.selectFilterWnd) | |
496 self.textWnd = wx.TextCtrl(rightwnd, wx.ID_ANY, style=wx.TE_MULTILINE|wx.TE_BESTWRAP) | |
497 leftwnd.SplitHorizontally(self.selectAliasWnd, self.selectFilterWnd) | |
498 rightwnd.SplitVertically(leftwnd, self.textWnd) | |
499 self.sizer.Add(self.topBtnSizer, 0, wx.EXPAND) | |
500 self.sizer.Add(rightwnd, 1, wx.EXPAND) | |
501 self.sizer.Add(self.middleBtnSizer, 0, wx.EXPAND) | |
502 self.sizer.Add(self.bottomBtnSizer, 0, wx.EXPAND) | |
503 self.SetSizer(self.sizer) | |
504 self.SetAutoLayout(True) | |
505 self.Fit() | |
506 self.log.log("Exit AliasLib->buildGUI(self)", ORPG_DEBUG) | |
507 | |
508 def loadFile(self): | |
509 self.log.log("Enter AliasLib->loadFile(self)", ORPG_DEBUG) | |
510 f = open(self.dir_struct["user"] + self.filename, "r") | |
511 data = f.read() | |
512 f.close() | |
513 self.alias = -1 | |
514 self.filter = -1 | |
515 xml_dom = self.xml.parseXml(data) | |
516 del data | |
517 aliases = xml_dom.getElementsByTagName("alias") | |
518 alist = [] | |
519 for alias in aliases: | |
520 if alias.hasAttribute("color"): | |
521 color = alias.getAttribute("color") | |
522 else: | |
523 color = 'Default' | |
524 aname = self.MakeSafeHTML(alias.getAttribute("name")) | |
525 alist.append([aname, color]) | |
526 alist.sort() | |
527 self.aliasList = alist | |
528 filters = xml_dom.getElementsByTagName("filter") | |
529 flist = [] | |
530 self.regExList = [] | |
531 for filter in filters: | |
532 flist.append(filter.getAttribute("name")) | |
533 rules = filter.getElementsByTagName("rule") | |
534 sub = [] | |
535 for rule in rules: | |
536 sub.append([self.MakeSafeHTML(rule.getAttribute("match")), self.MakeSafeHTML(rule.getAttribute("sub"))]) | |
537 self.regExList.append(sub) | |
538 self.filterList = flist | |
539 xml_dom.unlink() | |
540 self.alias = -1 | |
541 self.filter = -1 | |
542 self.log.log("Exit AliasLib->loadFile(self)", ORPG_DEBUG) | |
543 | |
544 def MakeSafeHTML(self, str): | |
545 return str.replace("&", "&").replace("<", "<").replace(""", '"').replace(">", ">").replace("'", "'") | |
546 def MakeHTMLSafe(self, str): | |
547 return str.replace("&", "&").replace("<", "<").replace('"', """).replace(">", ">").replace("'", "'") | |
548 def ImportFromTree(self, xml_dom): | |
549 self.log.log("Enter AliasLib->ImportFromTree(self, xml_dom)", ORPG_DEBUG) | |
550 oldfilename = self.filename | |
551 if xml_dom.getAttribute('name') == 'Alias Library': | |
552 dlg = wx.TextEntryDialog(self, "Please Name This Alias Lib", "New Alias Lib") | |
553 if dlg.ShowModal() == wx.ID_OK: | |
554 self.filename = dlg.GetValue() + '.alias' | |
555 dlg.Destroy() | |
556 else: | |
557 dlg.Destroy() | |
558 return | |
559 else: | |
560 self.filename = xml_dom.getAttribute('name') + '.alias' | |
561 self.settings.set_setting('aliasfile', self.filename[:-6]) | |
562 if oldfilename != self.filename: | |
563 self.OnMB_FileSave(None, oldfilename) | |
564 f = open(self.dir_struct["user"] + self.filename, "w") | |
565 f.write(xml_dom.toxml().replace('nodehandler', 'aliaslib').replace('voxchat.', '')) | |
566 f.close() | |
567 wx.CallAfter(self.loadFile) | |
568 self.log.log("Exit AliasLib->ImportFromTree(self, xml_dom)", ORPG_DEBUG) | |
569 | |
570 def NewAliasSelection(self, event): | |
571 self.log.log("Enter AliasLib->NewAliasSelection(self, event)", ORPG_DEBUG) | |
572 self.alias = event.GetIndex() | |
573 wx.CallAfter(self.chat.aliasList.SetStringSelection, self.alias[0]) | |
574 self.log.log("Exit AliasLib->NewAliasSelection(self, event)", ORPG_DEBUG) | |
575 | |
576 def NoAliasSelection(self, event): | |
577 self.log.log("Enter AliasLib->NoAliasSelection(self, event)", ORPG_DEBUG) | |
578 self.aliasIdx = -1 | |
579 wx.CallAfter(self.chat.aliasList.SetStringSelection, self.alias[0]) | |
580 self.log.log("Exit AliasLib->NoAliasSelection(self, event)", ORPG_DEBUG) | |
581 | |
582 def GetSelectedAlias(self): | |
583 self.log.log("Enter AliasLib->GetSelectedAlias(self)", ORPG_DEBUG) | |
584 self.InitSetup() | |
585 if self.aliasIdx != -1: | |
586 self.log.log("Exit AliasLib->GetSelectedAlias(self) return " + str(self.aliasIdx), ORPG_DEBUG) | |
587 return [self.selectAliasWnd.GetItem(self.aliasIdx, 0).GetText(), self.selectAliasWnd.GetItem(self.aliasIdx, 1).GetText()] | |
588 self.log.log("Exit AliasLib->GetSelectedAlias(self) return " + str(self.aliasIdx), ORPG_DEBUG) | |
589 return [self.chat.defaultAliasName, "Default"] | |
590 | |
591 def SetSelectedAlias(self, alias): | |
592 self.log.log("Enter AliasLib->SetSelectedAlias(self, aliasIdx)", ORPG_DEBUG) | |
593 found = False | |
594 if isinstance(alias, (int, long)): | |
595 self.aliasIdx = alias | |
596 found = True | |
597 else: | |
598 for n in xrange(self.selectAliasWnd.GetItemCount()): | |
599 if self.selectAliasWnd.GetItem(n, 0).GetText() == alias: | |
600 self.aliasIdx = n | |
601 found = True | |
602 if not found: | |
603 self.aliasIdx = -1 | |
604 self.log.log("Exit AliasLib->SetSelectedAlias(self, aliasIdx)", ORPG_DEBUG) | |
605 | |
606 def GetAliasList(self): | |
607 self.log.log("Enter AliasLib->GetAliasList(self)", ORPG_DEBUG) | |
608 alist = [] | |
609 for n in xrange(0, self.selectAliasWnd.GetItemCount()): | |
610 self.alias = n | |
611 alist.append(self.alias[0]) | |
612 self.log.log("Exit AliasLib->GetAliasList(self)", ORPG_DEBUG) | |
613 alist.sort() | |
614 alist.insert(0, self.chat.defaultAliasName) | |
615 return alist | |
616 | |
617 def SetAliasList(self, alist): | |
618 self.log.log("Enter AliasLib->SetAliasList(self, list)", ORPG_DEBUG) | |
619 self.selectAliasWnd.ClearAll() | |
620 self.selectAliasWnd.InsertColumn(0, "Alias") | |
621 self.selectAliasWnd.InsertColumn(1, "Chat Color") | |
622 for item in alist: | |
623 i = self.selectAliasWnd.InsertStringItem(self.selectAliasWnd.GetItemCount(), item[0]) | |
624 self.selectAliasWnd.SetStringItem(i, 1, item[1]) | |
625 if item[1] != 'Default': | |
626 self.selectAliasWnd.SetItemTextColour(i, item[1]) | |
627 self.selectAliasWnd.RefreshItem(i) | |
628 self.aliasIdx = -1 | |
629 self.RefreshAliases() | |
630 self.log.log("Exit AliasLib->SetAliasList(self, list)", ORPG_DEBUG) | |
631 | |
632 def GetAliasColor(self): | |
633 self.log.log("Enter/Exit AliasLib->GetAliasColor(self) return " + self.alias[1], ORPG_DEBUG) | |
634 return self.alias[1] | |
635 | |
636 def RefreshAliases(self): | |
637 self.orpgframe.Freeze() | |
638 self.Freeze() | |
639 self.alias = -1 | |
640 l1 = len(self.aliasList) | |
641 l2 = len(self.filterList) | |
642 if self.chat != None: | |
643 tmp = self.chat.aliasList.GetStringSelection() | |
644 self.alias = tmp | |
645 aidx = self.aliasIdx+1 | |
646 if len(self.aliasList) <= aidx: | |
647 aidx = 0 | |
648 self.chat.aliasList.Clear() | |
649 for n in xrange(l1): | |
650 self.chat.aliasList.Insert(self.aliasList[n], n) | |
651 self.chat.aliasList.SetStringSelection(self.aliasList[aidx]) | |
652 fidx = self.chat.filterList.GetSelection() | |
653 if len(self.filterList) <= fidx: | |
654 fidx = 0 | |
655 self.chat.filterList.Clear() | |
656 for n in xrange(l2): | |
657 self.chat.filterList.Insert(self.filterList[n], n) | |
658 self.chat.filterList.SetStringSelection(self.filterList[fidx]) | |
659 if self.chat.parent.GMChatPanel != None: | |
660 aidx = self.chat.parent.GMChatPanel.aliasList.GetSelection() | |
661 if len(self.aliasList) <- aidx: | |
662 aidx = 0 | |
663 self.chat.parent.GMChatPanel.aliasList.Clear() | |
664 for n in xrange(l1): | |
665 self.chat.parent.GMChatPanel.aliasList.Insert(self.aliasList[n], n) | |
666 self.chat.parent.GMChatPanel.aliasList.SetStringSelection(self.aliasList[aidx]) | |
667 fidx = self.chat.parent.GMChatPanel.filterList.GetSelection() | |
668 self.chat.parent.GMChatPanel.filterList.Clear() | |
669 for n in xrange(l2): | |
670 self.chat.parent.GMChatPanel.filterList.Insert(self.filterList[n], n) | |
671 self.chat.parent.GMChatPanel.filterList.SetStringSelection(self.filterList[fidx]) | |
672 for tab in self.chat.parent.whisper_tabs: | |
673 aidx = tab.aliasList.GetSelection() | |
674 if len(self.aliasList) <= aidx: | |
675 aidx = 0 | |
676 tab.aliasList.Clear() | |
677 for n in xrange(l1): | |
678 tab.aliasList.Insert(self.aliasList[n], n) | |
679 tab.aliasList.SetStringSelection(self.aliasList[aidx]) | |
680 fidx = tab.filterList.GetSelection() | |
681 tab.filterList.Clear() | |
682 for n in xrange(l2): | |
683 tab.filterList.Insert(self.filterList[n], n) | |
684 tab.filterList.SetStringSelection(self.filterList[fidx]) | |
685 | |
686 for tab in self.chat.parent.group_tabs: | |
687 aidx = tab.aliasList.GetSelection() | |
688 if len(self.aliasList) <= aidx: | |
689 aidx = 0 | |
690 tab.aliasList.Clear() | |
691 for n in xrange(l1): | |
692 tab.aliasList.Insert(self.aliasList[n], n) | |
693 tab.aliasList.SetStringSelection(self.aliasList[aidx]) | |
694 fidx = tab.filterList.GetSelection() | |
695 tab.filterList.Clear() | |
696 for n in xrange(l2): | |
697 tab.filterList.Insert(self.filterList[n], n) | |
698 tab.filterList.SetStringSelection(self.filterList[fidx]) | |
699 | |
700 for tab in self.chat.parent.null_tabs: | |
701 aidx = tab.aliasList.GetSelection() | |
702 if len(self.aliasList) <= aidx: | |
703 aidx = 0 | |
704 tab.aliasList.Clear() | |
705 for n in xrange(l1): | |
706 tab.aliasList.Insert(self.aliasList[n], n) | |
707 tab.aliasList.SetStringSelection(self.aliasList[aidx]) | |
708 fidx = tab.filterList.GetSelection() | |
709 tab.filterList.Clear() | |
710 for n in xrange(l2): | |
711 tab.filterList.Insert(self.filterList[n], n) | |
712 tab.filterList.SetStringSelection(self.filterList[fidx]) | |
713 self.Thaw() | |
714 wx.CallAfter(self.orpgframe.Thaw) | |
715 | |
716 def SetAliasColor(self, color): | |
717 self.log.log("Enter AliasLib->SetAliasColor(self, color)", ORPG_DEBUG) | |
718 if self.aliasIdx != -1: | |
719 self.selectAliasWnd.SetStringItem(self.aliasIdx, 1, color) | |
720 self.selectAliasWnd.SetItemTextColour(self.aliasIdx, color) | |
721 self.log.log("Exit AliasLib->SetAliasColor(self, color)", ORPG_DEBUG) | |
722 | |
723 def FilterTextChecked(self, event): | |
724 if self.checkFilterText.IsChecked(): | |
725 self.chat.filterList.SetStringSelection(self.filter) | |
726 else: | |
727 self.chat.filterList.SetStringSelection(self.chat.defaultFilterName) | |
728 | |
729 def NewFilterSelection(self, event): | |
730 self.log.log("Enter AliasLib->NewFilterSelection(self, event)", ORPG_DEBUG) | |
731 self.filter = event.GetIndex() | |
732 if self.checkFilterText.IsChecked(): | |
733 wx.CallAfter(self.chat.filterList.SetStringSelection, self.filter) | |
734 self.log.log("Exit AliasLib->NewFilterSelection(self, event)", ORPG_DEBUG) | |
735 | |
736 def NoFilterSelection(self, event): | |
737 self.log.log("Enter AliasLib->NoFilterSelection(self, event)", ORPG_DEBUG) | |
738 self.filter = -1 | |
739 wx.CallAfter(self.chat.filterList.SetStringSelection, self.filter) | |
740 self.log.log("Exit AliasLib->NoFilterSelection(self, event)", ORPG_DEBUG) | |
741 | |
742 def GetSelectedFilter(self): | |
743 self.log.log("Enter AliasLib->GetSelectedFilter(self)", ORPG_DEBUG) | |
744 if self.filterIdx != -1: | |
745 self.log.log("Exit AliasLib->GetSelectedFilter(self) return " + str(self.filterIdx), ORPG_DEBUG) | |
746 return self.selectFilterWnd.GetItem(self.filterIdx, 0).GetText() | |
747 self.log.log("Exit AliasLib->GetSelectedFilter(self) return " + str(self.filterIdx), ORPG_DEBUG) | |
748 return self.chat.defaultFilterName | |
749 | |
750 def SetSelectedFilter(self, idx): | |
751 self.log.log("Enter AliasLib->SetSelectedFilter(self, filter)", ORPG_DEBUG) | |
752 self.filterIdx = idx | |
753 self.log.log("Exit AliasLib->SetSelectedFilter(self, filter)", ORPG_DEBUG) | |
754 | |
755 def GetFilterList(self): | |
756 self.log.log("Enter AliasLib->GetFilterList(self)", ORPG_DEBUG) | |
757 list = [] | |
758 for n in xrange(-1, self.selectFilterWnd.GetItemCount()): | |
759 self.filter = n | |
760 list.append(self.filter) | |
761 self.log.log("Exit AliasLib->GetFilterList(self)", ORPG_DEBUG) | |
762 return list | |
763 | |
764 def SetFilterList(self, list): | |
765 self.log.log("Enter AliasLib->SetFilterList(self, list)", ORPG_DEBUG) | |
766 self.selectFilterWnd.ClearAll() | |
767 self.selectFilterWnd.InsertColumn(0, "Filter Name") | |
768 for item in list: | |
769 i = self.selectFilterWnd.InsertStringItem(self.selectFilterWnd.GetItemCount(), item) | |
770 self.selectFilterWnd.RefreshItem(i) | |
771 self.selectFilterWnd.SetColumnWidth(0, wx.LIST_AUTOSIZE) | |
772 self.filter = -1 | |
773 self.RefreshAliases() | |
774 self.log.log("Exit AliasLib->SetFilterList(self, list)", ORPG_DEBUG) | |
775 | |
776 def GetFilterRegEx(self): | |
777 if self.filterIdx == -1: | |
778 return [] | |
779 return self.regExList[self.filterIdx] | |
780 | |
781 def SetFilterRegEx(self, list): | |
782 self.regExList[self.filterIdx] = list | |
783 | |
784 def FormatText(self, event): | |
785 #self.textColorBtn = wx.Button(self, wx.ID_ANY, "Color") | |
786 #self.textColorBtn.SetForegroundColour(wx.BLACK) | |
787 id = event.GetId() | |
788 txt = self.textWnd.GetValue() | |
789 (beg, end) = self.textWnd.GetSelection() | |
790 if beg != end: | |
791 sel_txt = txt[beg:end] | |
792 else: | |
793 sel_txt = txt | |
794 if id == self.textBoldBtn.GetId(): | |
795 sel_txt = "<b>" + sel_txt + "</b>" | |
796 elif id == self.textItalicBtn.GetId(): | |
797 sel_txt = "<i>" + sel_txt + "</i>" | |
798 elif id == self.textUnderlineBtn.GetId(): | |
799 sel_txt = "<u>" + sel_txt + "</u>" | |
800 elif id == self.textColorBtn.GetId(): | |
801 dlg = wx.ColourDialog(self) | |
802 if not dlg.ShowModal() == wx.ID_OK: | |
803 dlg.Destroy() | |
804 return | |
805 color = dlg.GetColourData().GetColour() | |
806 color = RGBHex().hexstring(color[0], color[1], color[2]) | |
807 dlg.Destroy() | |
808 sel_txt = '<font color="' + color + '">' + sel_txt + '</font>' | |
809 if beg != end: | |
810 txt = txt[:beg] + sel_txt + txt[end:] | |
811 else: | |
812 txt = sel_txt | |
813 self.textWnd.SetValue(txt) | |
814 self.textWnd.SetInsertionPointEnd() | |
815 self.textWnd.SetFocus() | |
816 | |
817 #Properties | |
818 alias = property(GetSelectedAlias, SetSelectedAlias) | |
819 aliasList = property(GetAliasList, SetAliasList) | |
820 aliasColor = property(GetAliasColor, SetAliasColor) | |
821 | |
822 filter = property(GetSelectedFilter, SetSelectedFilter) | |
823 filterList = property(GetFilterList, SetFilterList) | |
824 filterRegEx = property(GetFilterRegEx, SetFilterRegEx) | |
825 | |
826 | |
827 | |
828 class FilterEditWnd(wx.Frame): | |
829 def __init__(self, parent, filterName, filterList): | |
830 wx.Frame.__init__(self, parent, wx.ID_ANY, "Edit Filter: " + filterName) | |
831 | |
832 self.filterList = filterList | |
833 self.parent = parent | |
834 | |
835 self.Freeze() | |
836 self.buildGUI() | |
837 self.fillList() | |
838 self.Layout() | |
839 self.grid.Select(0) | |
840 self.Thaw() | |
841 | |
842 self.Bind(wx.EVT_CLOSE, self.OnExit) | |
843 | |
844 def buildGUI(self): | |
845 bsizer = wx.BoxSizer(wx.VERTICAL) | |
846 self.panel = wx.Panel(self, wx.ID_ANY) | |
847 bsizer.Add(self.panel, 1, wx.EXPAND) | |
848 self.SetSizer(bsizer) | |
849 self.SetAutoLayout(True) | |
850 | |
851 self.grid = wx.ListCtrl(self.panel, wx.ID_ANY, style=wx.LC_SINGLE_SEL|wx.LC_REPORT|wx.LC_HRULES) | |
852 self.grid.InsertColumn(0, "Replace") | |
853 self.grid.InsertColumn(1, "With") | |
854 self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.selectRule, self.grid) | |
855 self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.RuleEdit, self.grid) | |
856 | |
857 self.addBtn = wx.Button(self.panel, wx.ID_ANY, 'Add') | |
858 self.editBtn = wx.Button(self.panel, wx.ID_ANY, 'Edit') | |
859 self.deleteBtn = wx.Button(self.panel, wx.ID_ANY, 'Delete') | |
860 self.okBtn = wx.Button(self.panel, wx.ID_OK, 'Done') | |
861 | |
862 self.Bind(wx.EVT_BUTTON, self.RuleAdd, self.addBtn) | |
863 self.Bind(wx.EVT_BUTTON, self.RuleEdit, self.editBtn) | |
864 self.Bind(wx.EVT_BUTTON, self.RuleDelete, self.deleteBtn) | |
865 self.Bind(wx.EVT_BUTTON, self.OnDone, self.okBtn) | |
866 | |
867 btsizer = wx.BoxSizer(wx.VERTICAL) | |
868 btsizer.Add(self.addBtn, 0, wx.EXPAND) | |
869 btsizer.Add(self.editBtn, 0, wx.EXPAND) | |
870 btsizer.Add(self.deleteBtn, 0, wx.EXPAND) | |
871 btsizer.Add(self.okBtn, 0, wx.EXPAND) | |
872 | |
873 sizer = wx.GridBagSizer(5,5) | |
874 | |
875 sizer.Add(self.grid, (0,0), flag=wx.EXPAND) | |
876 sizer.Add(btsizer, (0,1), flag=wx.EXPAND) | |
877 | |
878 sizer.AddGrowableCol(0) | |
879 sizer.AddGrowableRow(0) | |
880 sizer.SetEmptyCellSize((0,0)) | |
881 | |
882 self.panel.SetSizer(sizer) | |
883 self.panel.SetAutoLayout(True) | |
884 | |
885 def fillList(self): | |
886 for rule in self.filterList: | |
887 i = self.grid.InsertStringItem(self.grid.GetItemCount(), rule[0]) | |
888 self.grid.SetStringItem(i, 1, rule[1]) | |
889 | |
890 self.grid.SetColumnWidth(0, wx.LIST_AUTOSIZE) | |
891 self.grid.SetColumnWidth(1, wx.LIST_AUTOSIZE) | |
892 | |
893 def selectRule(self, event): | |
894 self.currentIdx = event.GetIndex() | |
895 self.Freeze() | |
896 for i in xrange(0, self.grid.GetItemCount()): | |
897 self.grid.SetItemBackgroundColour(i, (255,255,255)) | |
898 | |
899 self.grid.SetItemBackgroundColour(self.currentIdx, (0,255,0)) | |
900 self.grid.SetItemState(self.currentIdx, 0, wx.LIST_STATE_SELECTED) | |
901 self.grid.EnsureVisible(self.currentIdx) | |
902 self.Thaw() | |
903 | |
904 def RuleEdit(self, event): | |
905 dlg = wx.Dialog(self, wx.ID_ANY, 'Edit Filter Rule') | |
906 sizer = wx.BoxSizer(wx.HORIZONTAL) | |
907 sizer.Add(wx.StaticText(dlg, wx.ID_ANY, 'Replace: '), 0, wx.EXPAND) | |
908 rpltxt = wx.TextCtrl(dlg, wx.ID_ANY) | |
909 sizer.Add(rpltxt, 0, wx.EXPAND) | |
910 sizer.Add(wx.StaticText(dlg, wx.ID_ANY, 'With: '), 0, wx.EXPAND) | |
911 withtxt = wx.TextCtrl(dlg, wx.ID_ANY) | |
912 sizer.Add(withtxt, 0, wx.EXPAND) | |
913 sizer.Add(wx.Button(dlg, wx.ID_OK, 'Ok'), 0, wx.EXPAND) | |
914 sizer.Add(wx.Button(dlg, wx.ID_CANCEL, 'Cancel'), 0, wx.EXPAND) | |
915 | |
916 dlg.SetSizer(sizer) | |
917 dlg.SetAutoLayout(True) | |
918 dlg.Fit() | |
919 | |
920 rpltxt.SetValue(self.grid.GetItem(self.currentIdx, 0).GetText()) | |
921 withtxt.SetValue(self.grid.GetItem(self.currentIdx, 1).GetText()) | |
922 | |
923 if dlg.ShowModal() != wx.ID_OK: | |
924 dlg.Destroy() | |
925 return | |
926 | |
927 self.grid.SetStringItem(self.currentIdx, 0, rpltxt.GetValue()) | |
928 self.grid.SetStringItem(self.currentIdx, 1, withtxt.GetValue()) | |
929 self.grid.RefreshItem(self.currentIdx) | |
930 self.grid.SetColumnWidth(0, wx.LIST_AUTOSIZE) | |
931 self.grid.SetColumnWidth(1, wx.LIST_AUTOSIZE) | |
932 | |
933 dlg.Destroy() | |
934 | |
935 def RuleAdd(self, event): | |
936 i = self.grid.InsertStringItem(self.grid.GetItemCount(), '') | |
937 self.grid.SetStringItem(i, 1, '') | |
938 self.grid.Select(i) | |
939 self.RuleEdit(None) | |
940 | |
941 def RuleDelete(self, event): | |
942 self.grid.DeleteItem(self.currentIdx) | |
943 self.grid.Select(0) | |
944 | |
945 def OnExit(self, event): | |
946 self.MakeModal(False) | |
947 | |
948 list = [] | |
949 for i in xrange(0, self.grid.GetItemCount()): | |
950 list.append([self.grid.GetItem(i, 0).GetText(), self.grid.GetItem(i, 1).GetText()]) | |
951 | |
952 self.parent.filterRegEx = list | |
953 event.Skip() | |
954 | |
955 def OnDone(self, event): | |
956 self.Close() |