[pygccxml-commit] SF.net SVN: pygccxml:[1447] ui/web
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2008-10-26 13:01:03
|
Revision: 1447 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1447&view=rev Author: roman_yakovenko Date: 2008-10-26 13:00:57 +0000 (Sun, 26 Oct 2008) Log Message: ----------- adding textcha Modified Paths: -------------- ui/web/forms.py ui/web/templates/generated.html ui/web/templates/generator.html Added Paths: ----------- ui/web/static/generator.css ui/web/textcha.py Modified: ui/web/forms.py =================================================================== --- ui/web/forms.py 2008-10-23 05:40:53 UTC (rev 1446) +++ ui/web/forms.py 2008-10-26 13:00:57 UTC (rev 1447) @@ -1,96 +1,91 @@ -import config -import web - -class Label(web.form.Input): - tmpl = """<label name="%(name)s" %(atts)s>%(value)s</label>%(note)s""" - def render(self): - value = '' - if self.value is not None: - value = web.net.websafe(self.value) - return self.tmpl % dict( name=web.net.websafe(self.name) - , value=value - , atts=self.addatts() - , note=self.rendernote(self.note) ) - -class RawHTML(web.form.Input): - def __init__(self, html, *validators, **attrs): - web.form.Input.__init__( self, '', *validators, **attrs ) - self.__html = html - def render(self): - return self.__html - -class SimpleForm( web.form.Form ): - tmpl = """<form %(attrs)s>\n%(inputs)s\n</form>\n""" - def __init__(self, *inputs, **kw): - web.form.Form.__init__( self, *inputs, **kw ) - self.__kw = kw - self.__kw.pop( 'validators', None ) - - def render_addattrs( self ): - attrs = [] - for (n, v) in self.__kw.iteritems(): - attrs.append( ' %s="%s"' % (n, web.net.websafe(v)) ) - return ''.join( attrs ) - - def render( self ): - controls = [] - controls.append( self.rendernote(self.note) ) - for i in self.inputs: - if i.pre: - controls.append( i.pre ) - controls.append( i.render() ) - if i.post: - controls.append( i.post ) - return self.tmpl % dict( attrs=self.render_addattrs(), inputs='\n'.join( controls ) ) - - -""" - <form action="/generated.html" method="post" id="SourceCodeForm" style="width:80%; float:left;"> - <label>Source code:</label> - <br/> - <textarea name="source_code" rows="20" style="width:100%;"></textarea> - <br/> - <input type="submit" name="show_decls" value="Show declarations" /> - <a></a> - <input type="submit" name="generate_bp" value="Generate Boost.Python code" /> - <a></a> - <input type="submit" name="generate_pypp" value="Generate Py++ code" /> - </form> -""" - - -class generator_t( SimpleForm ): - def __init__( self, action, code_generator=None, method='post' ): - self.__code_generator = code_generator - self.__show_decls = web.form.Button( 'Show declarations', type="submit" ) - self.__generate_bpl_code = web.form.Button( 'Generate Boost.Python code', type="submit" ) - self.__generate_pypp_code = web.form.Button( 'Generate Py++ code', id="generate_pypp_code", type="submit" ) - self.__source_code = web.form.Textarea( "source_code", rows="20", style="width:100%;") - SimpleForm.__init__( self - , Label( 'source_code', value="Source code:" ) - , RawHTML( '<br/>' ) - , self.__source_code - , RawHTML( '<br/>' ) - , self.__show_decls - , RawHTML( '<a></a>' ) - , self.__generate_bpl_code - , RawHTML( '<a></a>' ) - , self.__generate_pypp_code - , action=action - , method=method - , style="width:80%; float:left;" ) - - def process( self, request_data ): - warnings = '' - generated = '' - source_code = request_data[ self.__source_code.name] - if self.__show_decls.name in request_data: - generated = self.__code_generator.show_declarations( source_code ) - elif self.__generate_pypp_code.name in request_data: - generated = self.__code_generator.generate_pypp_code( source_code ) - elif self.__generate_bpl_code.name in request_data: - generated, warnings = self.__code_generator.generate_bpl_code( source_code ) - else: - generated = 'error - unknown submit action' - return generated, warnings - +import config +import web +import textcha + +class Label(web.form.Input): + tmpl = """<label name="%(name)s" %(atts)s>%(value)s</label>%(note)s""" + def render(self): + value = '' + if self.value is not None: + value = web.net.websafe(self.value) + return self.tmpl % dict( name=web.net.websafe(self.name) + , value=value + , atts=self.addatts() + , note=self.rendernote(self.note) ) + +class RawHTML(web.form.Input): + def __init__(self, html, *validators, **attrs): + web.form.Input.__init__( self, '', *validators, **attrs ) + self.__html = html + def render(self): + return self.__html + +class SimpleForm( web.form.Form ): + tmpl = """<form %(attrs)s>\n%(inputs)s\n</form>\n""" + def __init__(self, *inputs, **kw): + web.form.Form.__init__( self, *inputs, **kw ) + self.__kw = kw + self.__kw.pop( 'validators', None ) + + def render_addattrs( self ): + attrs = [] + for (n, v) in self.__kw.iteritems(): + attrs.append( ' %s="%s"' % (n, web.net.websafe(v)) ) + return ''.join( attrs ) + + def render( self ): + controls = [] + controls.append( self.rendernote(self.note) ) + for i in self.inputs: + if i.pre: + controls.append( i.pre ) + controls.append( i.render() ) + if i.post: + controls.append( i.post ) + return self.tmpl % dict( attrs=self.render_addattrs(), inputs='\n'.join( controls ) ) + + +class generator_t( SimpleForm ): + def __init__( self, action, code_generator=None, method='post' ): + self.__code_generator = code_generator + self.__show_decls = web.form.Button( 'Show declarations', type="submit" ) + self.__generate_bpl_code = web.form.Button( 'Generate Boost.Python code', type="submit" ) + self.__generate_pypp_code = web.form.Button( 'Generate Py++ code', id="generate_pypp_code", type="submit" ) + self.__source_code = web.form.Textarea( "source_code", rows="20", style="width:100%") + self.__textcha_question = web.form.Hidden( "textcha_question", value=textcha.random_question(), style="width:60%;", id='textcha-question') + self.__textcha_answer = web.form.Textbox( "textcha_answer", value="", style="width:40%;", maxlength="120", id='textcha-answer') + SimpleForm.__init__( self + , Label( 'source_code', value="Source code:" ) + , RawHTML( '<br/>' ) + , self.__source_code + , RawHTML( '<br/>' ) + , self.__textcha_question + , Label( 'textcha_question', value=self.__textcha_question.value ) + , self.__textcha_answer + , RawHTML( '<br/><br/>' ) + , self.__show_decls + , RawHTML( '<a></a>' ) + , self.__generate_bpl_code + , RawHTML( '<a></a>' ) + , self.__generate_pypp_code + , action=action + , method=method + , style="width:80%; float:left;" ) + + def process( self, request_data ): + warnings = '' + generated = '' + if not textcha.is_human( request_data[ self.__textcha_question.name], request_data[ self.__textcha_answer.name] ): + generated = warnings = "Please answer the question!" + return generated, warnings + source_code = request_data[ self.__source_code.name] + if self.__show_decls.name in request_data: + generated = self.__code_generator.show_declarations( source_code ) + elif self.__generate_pypp_code.name in request_data: + generated = self.__code_generator.generate_pypp_code( source_code ) + elif self.__generate_bpl_code.name in request_data: + generated, warnings = self.__code_generator.generate_bpl_code( source_code ) + else: + generated = 'error - unknown submit action' + return generated, warnings + Added: ui/web/static/generator.css =================================================================== --- ui/web/static/generator.css (rev 0) +++ ui/web/static/generator.css 2008-10-26 13:00:57 UTC (rev 1447) @@ -0,0 +1,13 @@ +#textcha { + font-size: 100%; + margin-top: 0.5em; + border: 2px solid #FF8888; + color: black; + vertical-align: middle; + padding: 3px 2px; +} + +#textcha-answer { + border: 2px solid #000000; + padding: 3px 2px; +} Modified: ui/web/templates/generated.html =================================================================== --- ui/web/templates/generated.html 2008-10-23 05:40:53 UTC (rev 1446) +++ ui/web/templates/generated.html 2008-10-26 13:00:57 UTC (rev 1447) @@ -1,35 +1,36 @@ -$def with (code, warnings) -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> - <link rel="shortcut icon" href="/static/favicon.ico" /> - <link rel="icon" href="/static/favicon.ico" /> - <title>pygccxml & py++ demo - generated code</title> -</head> -<body> - <h2>pygccxml & py++ demo - generated code</h2> - <span style="width:80%; float:left;"> - <label>Generated code:</label> - <br/> - <textarea name="generated_code" rows="20" readonly="true" style="width:100%;">$:code</textarea> - </span> - <a> </a> - <span style="float : left; padding-left : 10px; width : 18%;"> - <br/> - <label style="width:100%;">What is ... ?</label> - <dt> - <dd><a href="http://www.language-binding.net">py++</a></dd> - <dd><a href="http://www.language-binding.net">pygccxml</a></dd> - </dt> - <label style="width:100%;">Adsense placeholder</label> - <textarea name="adsense" rows="15" style="width:100;">jjjjjjjjjjjjjjjjjjjjjjjjjj</textarea> - </span> - <span style="width:100%;"> - <br/> - <label>Warnings:</label> - <br/> - <textarea name="warnings" rows="15" readonly="true" style="width:100%;">$:warnings</textarea> - </span> -</body> -</html> +$def with (code, warnings) +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <link rel="shortcut icon" href="/static/favicon.ico" /> + <link rel="icon" href="/static/favicon.ico" /> + <!--link rel="stylesheet" type="text/css" charset="utf-8" media="all" href="/static/generator.css"--> + <title>pygccxml & py++ demo - generated code</title> +</head> +<body> + <h2>pygccxml & py++ demo - generated code</h2> + <span style="width:80%; float:left;"> + <label>Generated code:</label> + <br/> + <textarea name="generated_code" rows="20" readonly="true" style="width:100%;">$:code</textarea> + </span> + <a> </a> + <span style="float : left; padding-left : 10px; width : 18%;"> + <br/> + <label style="width:100%;">What is ... ?</label> + <dt> + <dd><a href="http://www.language-binding.net">py++</a></dd> + <dd><a href="http://www.language-binding.net">pygccxml</a></dd> + </dt> + <label style="width:100%;">Adsense placeholder</label> + <textarea name="adsense" rows="15" style="width:100;">jjjjjjjjjjjjjjjjjjjjjjjjjj</textarea> + </span> + <span style="width:100%;"> + <br/> + <label>Warnings:</label> + <br/> + <textarea name="warnings" rows="15" readonly="true" style="width:100%;">$:warnings</textarea> + </span> +</body> +</html> Modified: ui/web/templates/generator.html =================================================================== --- ui/web/templates/generator.html 2008-10-23 05:40:53 UTC (rev 1446) +++ ui/web/templates/generator.html 2008-10-26 13:00:57 UTC (rev 1447) @@ -1,25 +1,26 @@ -$def with (generator_form) -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> -<head> - <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> - <link rel="shortcut icon" href="/static/favicon.ico" /> - <link rel="icon" href="/static/favicon.ico" /> - <title>pygccxml & py++ demo</title> -</head> -<body> - <h2>pygccxml & py++ demo</h2> - $:generator_form.render() - <a> </a> - <span style="float : left; padding-left : 10px; width : 18%;"> - <br/> - <label style="width:100;">What is ... ?</label> - <dt> - <dd><a href="http://www.language-binding.net">py++</a></dd> - <dd><a href="http://www.language-binding.net">pygccxml</a></dd> - </dt> - <label style="width:100;">Adsense placeholder</label> - <textarea name="adsense" rows="15" style="width:100;">jjjjjjjjjjjjjjjjjjjjjjjjjj</textarea> - </span> -</body> -</html> +$def with (generator_form) +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <link rel="shortcut icon" href="/static/favicon.ico" /> + <link rel="icon" href="/static/favicon.ico" /> + <!--link rel="stylesheet" type="text/css" charset="utf-8" media="all" href="/static/generator.css"--> + <title>pygccxml & py++ demo</title> +</head> +<body> + <h2>pygccxml & py++ demo</h2> + $:generator_form.render() + <a> </a> + <span style="float : left; padding-left : 10px; width : 18%;"> + <br/> + <label style="width:100;">What is ... ?</label> + <dt> + <dd><a href="http://www.language-binding.net">py++</a></dd> + <dd><a href="http://www.language-binding.net">pygccxml</a></dd> + </dt> + <label style="width:100;">Adsense placeholder</label> + <textarea name="adsense" rows="15" style="width:100;">jjjjjjjjjjjjjjjjjjjjjjjjjj</textarea> + </span> +</body> +</html> Added: ui/web/textcha.py =================================================================== --- ui/web/textcha.py (rev 0) +++ ui/web/textcha.py 2008-10-26 13:00:57 UTC (rev 1447) @@ -0,0 +1,20 @@ +import re +import random +import config + +questions = { + 'Which programming language does the pygccxml project mainly use?' : re.compile( '\s*python\s*' ) +} + +question_keys = questions.keys() +question_keys_len = len(question_keys) + +def random_question(): + return question_keys[ random.randrange( question_keys_len ) ] + +def is_human( question, answer ): + if question not in questions: + return False + return questions[question].match( answer.lower() ) + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |