Skip to content

Create a web interface for command line programs or python functions

License

Notifications You must be signed in to change notification settings

aivuk/formcreator

Repository files navigation

formcreator

formcreator is a program that creates simple web forms for your programs or python functions, without requiring any webprogramming code.

Install

Just install with

$ python setup.py install

or

$ pip install formcreator

How it works

An example, if you want to create a simple form for the man program, you can write the code:

from formcreator import *

man  = Form("man")
man += Boolean("Apropos mode?", cmd_opt="-k")
man += Text("What manual page?")

app = MainApp("Man interface", [man])
app.run()

And run the program above:

$ python app.py

If you go to your browser at http://localhost:5000 you will see the form:

Imgur

You can use other field types like TextArea, File for file uploads, SelectFile for a widget where you can select a file from a directory, simple numerical types like Integer, Decimal and Float. Is possible to insert any Markdown text between your form fields with the type Doc:

from formcreator import *

man  = Form("man")
man += Boolean("Apropos mode?", cmd_opt="-k")
man += Doc("""
Man web interface
=================

This is a simple example of a _form_ with
two fields. 

![Tux image])(http://images.all-free-download.com/images/graphiclarge/linux_tux_1_107532.jpg)

""")
man += Text("What manual page?")

app = MainApp("Man interface", [man])
app.run()

A MainApp can have more than one form inside, just pass the forms like:

app = MainApp("Example", [man, cowsay, convert])

If the first argument to Form is not a string and is a python function, the form data will be used in this function:

from formcreator import *

def f(x, d=1):
	return x**d

simple  = Form(f)
simple += Integer("A number")
simple += Integer("Other number", cmd_opt="d")

app = MainApp("Function example", [simple])
app.run()

In this case, all fields with cmd_opt arguments will be passed like keywords arguments for the python function. If you want to see contents of one or more directories in the web interface, just pass the dirs argument to Form:

Form(f, dirs=["updir"])

And you will see this on the form page:

Directory contents

This is usefull when the output of your function or program is in a file. In the widget you can download any file created.

You can see a more complex example test_app.py in the repository.

TODO

  • User access control.
  • Save form sessions.
  • Tests!
  • Display image results.
  • Better widgets for file selection.
  • Other types of fields (Select, Checkbox, etc).
  • Handle cases when program do not terminate.

About

Create a web interface for command line programs or python functions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published