annotate orpg/tools/predTextCtrl.py @ 228:24769389a7ba alpha

Traipse Alpha 'OpenRPG' {100612-01} 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 (Preparing to close updates) New Features: New to Map, can re-order Grid, Miniatures, and Whiteboard layer draw order Fixes: Fix to InterParse that was causing an Infernal Loop with Namespace Internal Fix to XML data, removed old Minidom and switched to Element Tree Fix to Server that was causing eternal attempt to find a Server ID, in Register Rooms thread Fix to metaservers.xml file not being created
author sirebral
date Sat, 12 Jun 2010 04:38:29 -0500
parents b633f4c64aae
children
rev   line source
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
1 # Copyright (C) 2001 The OpenRPG Project
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
2 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
3 # openrpg-dev@lists.sourceforge.net
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
4 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
5 # This program is free software; you can redistribute it and/or modify
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
6 # it under the terms of the GNU General Public License as published by
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
7 # the Free Software Foundation; either version 2 of the License, or
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
8 # (at your option) any later version.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
9 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
10 # This program is distributed in the hope that it will be useful,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
13 # GNU General Public License for more details.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
14 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
15 # You should have received a copy of the GNU General Public License
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
16 # along with this program; if not, write to the Free Software
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
18 # --
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
19 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
20 # File: predTextCtrl.py
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
21 # Author: Andrew Bennett
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
22 # Maintainer: Andrew Bennett
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
23 # Version: $id:$
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
24 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
25 # Description: This file contains an extension to the wxPython wx.TextCtrl that provides predictive word completion
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
26 # based on a word file loaded at instantiation. Also, it learns new words as you type, dynamically
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
27 # adjusting a weight for each word based on how often you type it.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
28 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
29
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
30 ##
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
31 ## Module Loading
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
32 ##
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
33
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
34 import string
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
35 from orpg.orpg_windows import *
127
0f720618a8bd Traipse Alpha 'OpenRPG' {091002-01}
sirebral
parents: 122
diff changeset
36 import wx #wx.SystemSettings.GetMetric(wx.SYS_VSCROLL_X)
59
5aff3ef1ae46 New dev branch for Ornery Orc. Adds CSS styling to chat messages. Updates
sirebral
parents: 0
diff changeset
37 from wx.lib.expando import ExpandoTextCtrl
127
0f720618a8bd Traipse Alpha 'OpenRPG' {091002-01}
sirebral
parents: 122
diff changeset
38 from orpg.tools.orpg_log import logger, debug
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
39
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
40 # This line added to test CVS commit
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
41
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
42 ##
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
43 ## Class Definitions
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
44 ##
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
45
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
46 # This class implements a tree node that represents a letter
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
47 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
48 # Defines:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
49 # __init__(self,filename)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
50 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
51 class Letter:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
52 def __init__(self,asciiCharIn,parentNodeIn):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
53 self.asciiChar = asciiCharIn # should be an ASCII char
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
54 self.parentNode = parentNodeIn # should be ref to a class Letter
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
55 self.priority = 0 # should be an int
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
56 self.mostCommon = self # should be a ref to a class Letter
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
57 self.children = {} # should be a ref to a dictionary of class Letter
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
58
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
59 def __str__(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
60 return self.asciiChar
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
61
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
62
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
63 class LetterTreeClass(object):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
64
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
65 def __init__(self, singletonKey):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
66 if not isinstance(singletonKey, _SingletonKey):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
67 raise invalid_argument(_("Use LetterTree() to get access to singleton"))
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
68
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
69 self.rootNode = Letter("",None)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
70 self.rootNode.children = {}
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
71
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
72 def updateMostCommon(self, target):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
73 prev = target.parentNode
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
74 while prev:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
75 if prev.mostCommon is None:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
76 prev.mostCommon = target
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
77 else:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
78 if target.priority > prev.mostCommon.priority:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
79 prev.mostCommon = target
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
80 prev = prev.parentNode
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
81
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
82 def setWord(self,wordText,priority = 1,sumFlag = 0):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
83 cur = self.rootNode
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
84 for ch in wordText:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
85 if cur.children.has_key(ch):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
86 cur = cur.children[ch]
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
87 else:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
88 newLetter = Letter(ch,cur)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
89 if cur is self.rootNode:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
90 newLetter.parentNode = None
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
91 cur.children[ch] = newLetter
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
92 cur = newLetter
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
93 if sumFlag: cur.priority += priority
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
94 else: cur.priority = priority
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
95 self.updateMostCommon(cur)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
96
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
97 def addWord(self,wordText):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
98 self.setWord(wordText,priority = 1)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
99
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
100 def incWord(self,wordText):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
101 self.setWord(wordText,priority = 1, sumFlag = 1)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
102
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
103 def setWordPriority(self,wordText,priority):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
104 self.setWord(wordText,priority = priority)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
105
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
106
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
107 def findWordNode(self,wordText):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
108 cur = self.rootNode
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
109 for ch in wordText:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
110 if cur.children.has_key(ch):
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
111 cur = cur.children[ch]
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
112 else: return None
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
113 return cur
127
0f720618a8bd Traipse Alpha 'OpenRPG' {091002-01}
sirebral
parents: 122
diff changeset
114
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
115 def findWordPriority(self,wordText):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
116
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
117 cur = self.findWordNode(wordText)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
118 if cur: return cur.priority
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
119 else: return 0
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
120
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
121 def printTree(self, current=None):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
122 letters = []
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
123 if current is None:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
124 current = self.rootNode
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
125 for l, letter in current.children.iteritems():
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
126 letters.append(str(letter))
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
127 if letter.children != {}:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
128 m = self.printTree(letter)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
129 letters.append(m)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
130 return letters
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
131
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
132 def getPrediction(self,k,cur):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
133
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
134 if cur.children.has_key(k) :
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
135 cur = cur.children[k]
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
136 backtrace = cur.mostCommon
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
137 returnText = ''
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
138 while cur is not backtrace:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
139 returnText = backtrace.asciiChar + returnText
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
140 backtrace = backtrace.parentNode
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
141 return returnText
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
142 else:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
143 return ""
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
144
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
145
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
146 class _SingletonKey(object):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
147 def __new__(cls, *args, **kwargs):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
148 if not hasattr(cls, '_inst'):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
149 cls._inst = super(_SingletonKey, cls).__new__(cls, *args, **kwargs)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
150 return cls._inst
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
151
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
152 __key = _SingletonKey()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
153 LetterTree = LetterTreeClass(__key)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
154
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
155
59
5aff3ef1ae46 New dev branch for Ornery Orc. Adds CSS styling to chat messages. Updates
sirebral
parents: 0
diff changeset
156 class predTextCtrl(ExpandoTextCtrl):
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
157
178
ff19dd30064b Traipse Alpha 'OpenRPG' {100114-02}
sirebral
parents: 167
diff changeset
158 def __init__(self, parent, id = -1, value = "", size = (30,30), style = 0, name = "text", keyHook = None, validator=None):
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
159 if validator:
59
5aff3ef1ae46 New dev branch for Ornery Orc. Adds CSS styling to chat messages. Updates
sirebral
parents: 0
diff changeset
160 ExpandoTextCtrl.__init__(self, parent, id=id, value=value, size=size, style=style, name=name, validator=validator )
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
161 else:
59
5aff3ef1ae46 New dev branch for Ornery Orc. Adds CSS styling to chat messages. Updates
sirebral
parents: 0
diff changeset
162 ExpandoTextCtrl.__init__(self, parent, id=id, value=value, size=size, style=style, name=name)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
163
178
ff19dd30064b Traipse Alpha 'OpenRPG' {100114-02}
sirebral
parents: 167
diff changeset
164
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
165 self.tree = LetterTree
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
166 self.parent = parent
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
167 self.cur = self.tree.rootNode
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
168 self.keyHook = keyHook
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 95
diff changeset
169 ExpandoTextCtrl._wrapLine = self._wrapLine
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 95
diff changeset
170
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
171
122
36919b8a3ef9 Traipse Alpha 'OpenRPG' {091031-00}
sirebral
parents: 119
diff changeset
172 def _wrapLine(self, line, dc, width):
36919b8a3ef9 Traipse Alpha 'OpenRPG' {091031-00}
sirebral
parents: 119
diff changeset
173 pte = dc.GetPartialTextExtents(line)
36919b8a3ef9 Traipse Alpha 'OpenRPG' {091031-00}
sirebral
parents: 119
diff changeset
174 width -= wx.SystemSettings.GetMetric(wx.SYS_VSCROLL_X)
36919b8a3ef9 Traipse Alpha 'OpenRPG' {091031-00}
sirebral
parents: 119
diff changeset
175 idx = 0
36919b8a3ef9 Traipse Alpha 'OpenRPG' {091031-00}
sirebral
parents: 119
diff changeset
176 start = 0
36919b8a3ef9 Traipse Alpha 'OpenRPG' {091031-00}
sirebral
parents: 119
diff changeset
177 count = 0
36919b8a3ef9 Traipse Alpha 'OpenRPG' {091031-00}
sirebral
parents: 119
diff changeset
178 spc = -1
36919b8a3ef9 Traipse Alpha 'OpenRPG' {091031-00}
sirebral
parents: 119
diff changeset
179 while idx < len(pte):
143
dc74dca250d1 Traipse Alpha 'OpenRPG' {091123-02}
sirebral
parents: 127
diff changeset
180 if line[idx] == ' ': spc = idx
122
36919b8a3ef9 Traipse Alpha 'OpenRPG' {091031-00}
sirebral
parents: 119
diff changeset
181 if pte[idx] - start > width:
36919b8a3ef9 Traipse Alpha 'OpenRPG' {091031-00}
sirebral
parents: 119
diff changeset
182 count += 1
127
0f720618a8bd Traipse Alpha 'OpenRPG' {091002-01}
sirebral
parents: 122
diff changeset
183 if spc != -1:
0f720618a8bd Traipse Alpha 'OpenRPG' {091002-01}
sirebral
parents: 122
diff changeset
184 idx = spc + 1
0f720618a8bd Traipse Alpha 'OpenRPG' {091002-01}
sirebral
parents: 122
diff changeset
185 spc = -1
0f720618a8bd Traipse Alpha 'OpenRPG' {091002-01}
sirebral
parents: 122
diff changeset
186 start = pte[idx]
0f720618a8bd Traipse Alpha 'OpenRPG' {091002-01}
sirebral
parents: 122
diff changeset
187 else:
0f720618a8bd Traipse Alpha 'OpenRPG' {091002-01}
sirebral
parents: 122
diff changeset
188 idx += 1
122
36919b8a3ef9 Traipse Alpha 'OpenRPG' {091031-00}
sirebral
parents: 119
diff changeset
189 return count
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
190
127
0f720618a8bd Traipse Alpha 'OpenRPG' {091002-01}
sirebral
parents: 122
diff changeset
191 def findWord(self, insert, st):
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
192 begin = 0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
193 for offset in range(insert - 1):
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents: 143
diff changeset
194 if st[-(offset + 2)] not in string.ascii_letters:
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
195 begin = insert - (offset + 1)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
196 break
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
197 return st[begin:insert]
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
198
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
199 def OnChar(self,event):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
200
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
201 if(self.keyHook):
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
202 if self.keyHook(event) == 1:
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
203 self.parent.OnChar(event)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
204 return
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
205 asciiKey = ""
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
206 if (event.GetKeyCode() < 256) and (event.GetKeyCode() > 19):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
207 asciiKey = chr(event.GetKeyCode())
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
208 if asciiKey == "":
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
209 if event.GetKeyCode() == wx.WXK_TAB:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
210 fromPos = toPos = 0
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
211 (fromPos,toPos) = self.GetSelection()
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
212 if (toPos - fromPos) == 0:
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
213 self.parent.OnChar(event)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
214 return
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
215 else:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
216 self.SetInsertionPoint(toPos)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
217 self.SetSelection(toPos,toPos)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
218 return
95
af6bf998f425 Traipse Alpha 'OpenRPG' {090919-00}
sirebral
parents: 59
diff changeset
219
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
220 elif event.GetKeyCode() == wx.WXK_RETURN:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
221 st = self.GetValue()
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
222 newSt = ""
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
223 (startSel,endSel) = self.GetSelection()
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
224 self.Remove( startSel, endSel )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
225 st = string.strip( self.GetValue() )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
226 for ch in st:
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents: 143
diff changeset
227 if ch not in string.ascii_letters:
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
228 newSt += " "
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
229 else:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
230 newSt += ch
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
231 for aWord in string.split(newSt):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
232 self.tree.incWord(string.lower(aWord))
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
233 self.parent.OnChar(event)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
234 return
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
235
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
236 elif event.GetKeyCode() == wx.WXK_RIGHT:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
237 (startSel,endSel) = self.GetSelection()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
238 self.SetInsertionPoint(endSel)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
239 self.parent.OnChar(event)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
240 return
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
241
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
242 elif event.GetKeyCode() == wx.WXK_LEFT:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
243 (startSel,endSel) = self.GetSelection()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
244 self.SetInsertionPoint(startSel)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
245 self.parent.OnChar(event)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
246 return
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
247 else:
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
248
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
249 self.parent.OnChar(event)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
250 return
167
5c9a118476b2 Traipse Alpha 'OpenRPG' {091210-00}
sirebral
parents: 143
diff changeset
251 elif asciiKey in string.ascii_letters:
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
252 (startSel,endSel) = self.GetSelection()
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
253 st = self.GetValue()
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
254 front = st[:startSel]
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
255 back = st[endSel:]
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
256 st = front + asciiKey + back
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
257 insert = startSel + 1
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
258 curWord = ""
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
259 if (len(back) == 0) or (back[0] not in string.ascii_letters):
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
260
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
261 curWord = self.findWord(insert,front + asciiKey)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
262 else:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
263 self.parent.OnChar(event)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
264 return
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
265
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
266 if curWord == "":
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
267 self.parent.OnChar(event)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
268 return
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
269
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
270 self.cur = self.tree.findWordNode(string.lower(curWord[:-1]))
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
271 if self.cur is None:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
272 self.parent.OnChar(event)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
273 return
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
274 predictText = self.tree.getPrediction(string.lower(asciiKey),self.cur)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
275
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
276 if predictText == "":
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
277 self.parent.OnChar(event)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
278 return
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
279 front = st[:insert]
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
280 back = st[insert:]
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
281
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
282 st = front + predictText + back
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
283 self.SetValue(st)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
284 self.SetInsertionPoint(insert)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
285 self.SetSelection(insert,insert+len(predictText))
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
286 return
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
287 else:
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
288
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
289 self.parent.OnChar(event)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 178
diff changeset
290 return
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
291