]> git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/stxview/StructuredText/Zwiki.py
Update makefile and module def for new dynlib stuff. Also some control colouring...
[wxWidgets.git] / wxPython / samples / stxview / StructuredText / Zwiki.py
1 #!/usr/bin/python
2 ##############################################################################
3 #
4 # Zope Public License (ZPL) Version 1.0
5 # -------------------------------------
6 #
7 # Copyright (c) Digital Creations. All rights reserved.
8 #
9 # This license has been certified as Open Source(tm).
10 #
11 # Redistribution and use in source and binary forms, with or without
12 # modification, are permitted provided that the following conditions are
13 # met:
14 #
15 # 1. Redistributions in source code must retain the above copyright
16 # notice, this list of conditions, and the following disclaimer.
17 #
18 # 2. Redistributions in binary form must reproduce the above copyright
19 # notice, this list of conditions, and the following disclaimer in
20 # the documentation and/or other materials provided with the
21 # distribution.
22 #
23 # 3. Digital Creations requests that attribution be given to Zope
24 # in any manner possible. Zope includes a "Powered by Zope"
25 # button that is installed by default. While it is not a license
26 # violation to remove this button, it is requested that the
27 # attribution remain. A significant investment has been put
28 # into Zope, and this effort will continue if the Zope community
29 # continues to grow. This is one way to assure that growth.
30 #
31 # 4. All advertising materials and documentation mentioning
32 # features derived from or use of this software must display
33 # the following acknowledgement:
34 #
35 # "This product includes software developed by Digital Creations
36 # for use in the Z Object Publishing Environment
37 # (http://www.zope.org/)."
38 #
39 # In the event that the product being advertised includes an
40 # intact Zope distribution (with copyright and license included)
41 # then this clause is waived.
42 #
43 # 5. Names associated with Zope or Digital Creations must not be used to
44 # endorse or promote products derived from this software without
45 # prior written permission from Digital Creations.
46 #
47 # 6. Modified redistributions of any form whatsoever must retain
48 # the following acknowledgment:
49 #
50 # "This product includes software developed by Digital Creations
51 # for use in the Z Object Publishing Environment
52 # (http://www.zope.org/)."
53 #
54 # Intact (re-)distributions of any official Zope release do not
55 # require an external acknowledgement.
56 #
57 # 7. Modifications are encouraged but must be packaged separately as
58 # patches to official Zope releases. Distributions that do not
59 # clearly separate the patches from the original work must be clearly
60 # labeled as unofficial distributions. Modifications which do not
61 # carry the name Zope may be packaged in any form, as long as they
62 # conform to all of the clauses above.
63 #
64 #
65 # Disclaimer
66 #
67 # THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
68 # EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
69 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
70 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
71 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
72 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
73 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
74 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
75 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
76 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
77 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
78 # SUCH DAMAGE.
79 #
80 #
81 # This software consists of contributions made by Digital Creations and
82 # many individuals on behalf of Digital Creations. Specific
83 # attributions are listed in the accompanying credits file.
84 #
85 ##############################################################################
86
87 from Html import HTML
88 from string import split
89 from ST import DOC
90 import re
91
92 """
93 This is the new structured text type.
94 """
95
96 class Zwiki_Title:
97 def __init__(self,str=''):
98 self.expr1 = re.compile('([A-Z]+[A-Z]+[a-zA-Z]*)').search
99 self.expr2 = re.compile('([A-Z]+[a-z]+[A-Z]+[a-zA-Z]*)').search
100 self.str = [str]
101 self.typ = "Zwiki_Title"
102
103 def type(self):
104 return '%s' % self.typ
105
106 def string(self):
107 return self.str
108
109 def __getitem__(self,index):
110 return self.str[index]
111
112 def __call__(self,raw_string,subs):
113
114 """
115 The raw_string is checked to see if it matches the rules
116 for this structured text expression. If the raw_string does,
117 it is parsed for the sub-string which matches and a doc_inner_link
118 instance is returned whose string is the matching substring.
119 If raw_string does not match, nothing is returned.
120 """
121
122 if self.expr1(raw_string):
123 start,end = self.expr1(raw_string).span()
124 result = Zwiki_Title(raw_string[start:end])
125 result.start,result.end = self.expr1(raw_string).span()
126 return result
127 elif self.expr2(raw_string):
128 start,end = self.expr2(raw_string).span()
129 result = Zwiki_Title(raw_string[start:end])
130 result.start,result.end = self.expr2(raw_string).span()
131 return result
132 else:
133 return None
134
135 def span(self):
136 return self.start,self.end
137
138 class Zwiki_doc(DOC):
139
140 def __init__(self):
141 DOC.__init__(self)
142 """
143 Add the new type to self.types
144 """
145 self.types.append(Zwiki_Title())
146
147 class Zwiki_parser(HTML):
148 def __init__(self):
149 HTML.__init__(self)
150 self.types["Zwiki_Title"] = self.zwiki_title
151
152 def zwiki_title(self,object):
153 result = ""
154 for x in object.string():
155 result = result + x
156 result = "<a href=%s>%s</a>" % (result,result)
157 #result = "<dtml-wikiname %s>" % result
158 self.string = self.string + result