How to make UEdit support python?
Ian Parker
parker at gol.com
Sun Sep 2 05:18:18 EDT 2001
In article <9mog9u$d94$1 at newsg1.svr.pol.co.uk>, Dave Berkeley
<dave at rotwang.freeserve.co.uk> writes
>
>Formalin <formalin14 at email.com.cn> wrote in message
>news:9mk7ur$hbv$1 at mail.cn99.com...
>> How to make UEdit support python?
>>
>>
>
>The following script can be used to allow pop-up Python language help from
>within UltraEdit. It does Java, Javascript and PHP too. You will have to
>acquire the docs and point the paths at them for this to work. Then you need
>to configure a User Tool to invoke the help. I use this all the time.
>
>Anyone got any C library help in HTML?
>
>Dave Berkeley
>----
>#! Python
>#
># Utility to access Python / Java API / PHP help from within UltraEdit.
>#
># Needs to be invoked: python help.py %e %sel%
>#
># Use ToolConfiguration:
># %e is the file extension
># %sel% is UltraEdit's currently selected text.
>#
># Note :- this program relies on the format of help documents
># so could easily be broken by later version documents.
>
># Copyright (C) 1999 Dave Berkeley dave at rotwang.freeserve.co.uk
>#
># This program is free software; you can redistribute it and/or modify
># it under the terms of the GNU General Public License as published by
># the Free Software Foundation; either version 2 of the License, or
># (at your option) any later version.
>
># This program is distributed in the hope that it will be useful, but
># WITHOUT ANY WARRANTY; without even the implied warranty of
># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
># General Public License for more details.
>
># You should have received a copy of the GNU General Public License
># along with this program; if not, write to the Free Software
># Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
># USA
>
>import os, sys, string, re, getopt, webbrowser
>
># Point these at your Java API, Python etc. docs
>#
>java_root = r"C:\Program files\JDK1.3\docs\api\index-files"
>python_root = r"C:\Program Files\Python20\Doc\lib"
>python_index = "genindex.html"
>php_root = r"D:\Mirror\Download\Docs\Php4"
>php_index = 'index.html'
>js_root = r'D:\mirror\docs.iplanet.com\docs\manuals\js\client\jsref'
>js_index = r'bklast.htm'
>temp_file = r"c:\Temp\temp.html"
>
>#
>#
>#
>
>class Base:
>
> def __init__(self, lang, word):
> self.lines = []
> self.lang = lang
> self.word = word
>
> def add(self, line):
> self.lines.append(line)
>
> def add_tag(self, text, url):
> self.add('<a href="%s"> %s </a><br>' % (url, text,))
>
> def make_html(self):
> html = "<HTML><BODY>\n<H2>%s help index for <B>%s</B></H2>" %
>(self.lang, self.word,)
> for line in self.lines:
> html = html + line
> html = html + "</BODY></HTML>\n"
> return html
>
> def get_file(self):
>
> if self.word == None:
> return self.get_path()
>
> self.data = open(self.get_path(), "r").read()
> match = self.word_re.sub(self.on_match, self.data)
>
> if len(self.lines) == 0:
> return self.get_path()
>
> return self.get_html()
>
> def get_html(self):
> open(self.get_temp(), "w").write(self.make_html())
> return self.get_temp()
>
> def get_temp(self):
> return temp_file
>
>#
>#
>#
>
>class Java(Base):
>
> def __init__(self, word):
> Base.__init__(self, "Java", word)
> if word:
> self.index = max(1, ord(word[0]) - ord('a') + 1)
> else:
> self.index = 1
> if word != None:
> re_text = "<DT>(<A HREF=\"(.*)\"><B>(%s.*)</B>.*)$" % word
> self.word_re = re.compile(re_text, re.MULTILINE + re.IGNORECASE)
>
> def on_match(self,match):
> self.add(match.group(1))
> i = match.end()+1
> j = i
> while self.data[j] != '\n':
> j = j + 1
> after = self.data[i:j]
> self.add(after + "<BR>\n")
> return ""
>
> def get_path(self):
> file = java_root + r"\index-%d.html"
> return file % self.index
>
> def get_temp(self):
> return r"%s\temp.html" % java_root
>
>#
>#
>#
>
>class Python(Base):
>
> def __init__(self, word):
> Base.__init__(self, "Python", word)
> if word != None:
> re_text = "<a href='(.*)'>(%s.*)</a>" % word
> self.word_re = re.compile(re_text, re.MULTILINE + re.IGNORECASE)
>
> def on_match(self,match):
> href, text = match.groups()
> path = 'file://' + os.path.join(python_root, href)
> self.add_tag(text, path)
> return ""
>
> def get_path(self):
> return os.path.join(python_root, python_index)
>
>#
>#
>#
>
>class JavaScript(Base):
>
> def __init__(self, word):
> Base.__init__(self, "JavaScript", word)
> if word != None:
> re_text = '<a href="(.*)">(%s.*)</a>' % word
> self.word_re = re.compile(re_text, re.MULTILINE + re.IGNORECASE)
>
> def on_match(self,match):
> href, text = match.groups()
> path = os.path.join(js_root, href)
> self.add_tag(text, path)
> return ""
>
> def get_path(self):
> return os.path.join(js_root, js_index)
>
> def get_temp(self):
> return r"%s\temp.html" % js_root
>#
>#
>#
>
>class Php(Base):
>
> file_re = re.compile(r'function\.(.*).html')
>
> def __init__(self, word):
> Base.__init__(self, "PHP", word)
>
> files = []
> for f in os.listdir(php_root):
> if self.file_re.match(f):
> files.append(f)
>
> if not word:
> self.path = self.default()
> return
>
> file = 'function.%s.html' % word.replace('_', '-')
> if not file in files:
> self.partial_match(word, files)
> self.path = None
> else:
> self.path = os.path.join(php_root, file)
>
> def default(self):
> return os.path.join(php_root, php_index)
>
> def partial_match(self, word, files):
> for file in files:
> match = self.file_re.match(file.replace('-', '_'))
> if not match:
> continue
>
> fn = match.groups()[0]
> if not fn.startswith(word):
> continue
>
> path = os.path.join(php_root, file)
> self.add_tag(fn, path)
>
> def get_path(self):
> return self.path
>
> def get_file(self):
> if self.path:
> return self.get_path()
> if len(self.lines):
> return self.get_html();
> return self.default()
>
>#
>#
>#
>
>handlers = {
> '.java' : Java,
> '.py' : Python,
> '.cgi' : Python,
> '.cgp' : Python,
> '.php' : Php,
> '.js' : JavaScript,
>}
>
>def report_error(text):
> file = open(temp_file, 'w')
> file.write("<HTML><BODY><H2> Error invoking Help: %s
></h2></BODY></HTML>" % text)
> file.close()
> webbrowser.open_new(temp_file)
>
>#
>#
>
>def help():
>
> args = getopt.getopt(sys.argv[1:], '')[1]
>
> if len(args) < 1:
> report_error("No args")
> return
>
> ext = string.lower(args[0])
>
> if len(args) < 2:
> word = None
> else:
> word = string.lower(args[1])
>
> if handlers.has_key(ext):
> help = handlers[ext](word)
> else:
> report_error("Unknown extension '%s'" % ext);
> return
>
> webbrowser.open_new(help.get_file())
>
>#
>#
>
>help()
>
>
>
That's excellent. All I need to now is to work out how to add MySQL as
well.
Regards
Ian
--
Ian Parker
More information about the Python-list
mailing list