Two more newbie questions

Ben Finney ben at benfinney.id.au
Fri Jul 18 11:45:55 CEST 2014


Shieldfire <shieldfire at gmail.com> writes:

> On fre, 2014-07-18 at 18:23 +1000, Ben Finney wrote:
> > So, if by “slap a GUI onto” you mean something that is a no-frills
> > plain-HTML form, with essentially no assistance for the user and no
> > error handling, this will be a lot simpler to implement than
> > something easier for the human to use.
>
> Pretty much this. Because anyone using the tool would understand what to
> enter. There are things like opponent, result, tournament and rating
> without which there wouldn't be a need to use the tool in the first
> place. 

In that case, design the UI as an HTML form; this is a task that
requires no knowledge of Python, since you're just writing according to
basic HTML.

    <html>
    <head><title>The Amazing Gezundheiticator</title>
    </head>
    <body>

    <h1>The Amazing Gezundheiticator</h1>

    <p>Fill out the inputs to the program and submit the form.</p>

    <form name="app-input" action="/uri/to/backend-program">
    <p>
        <label for="foo">Foo:</label>
        <input name="foo" type="number" maxwidth="10" />
    </p>
    <p>
        <label for="bar">Bar:</label>
        <input name="bar" type="text" maxwith="25" />
    </p>
    <input type="submit" value="Gezundheiticate" />
    </form>

    </body></html>

That's the input part of the UI; the other part is a response page with
whatever result (error output, requested output, whatever) your back-end
program will create. You'll need to write HTML pages for all the
different kinds of responses your program can produce.

It submits the input as an HTTP request to ‘/uri/to/backend-program’.
The web server's job is to turn that URI into a call to your Python
program; and your program then needs to extract from the HTTP request
the values to process, and generate an HTTP response.

So you have these additional, related tasks for your UI:

* Accepting HTTP requests and routing them to your back-end program.
  You'll need to run a web server of some kind, and configure a map of
  routes from incoming URIs to the corresponding program to handle them
  <URL:https://wiki.python.org/moin/WebServers>.

* Generating HTML for all the different kinds of response (requested
  output, error output, requests to re-try, etc.) from the back-end
  program. This is the job of an HTML templating library; see
  <URL:https://wiki.python.org/moin/Templating> for details.

  Start simple, with a very bare HTML template populated using the
  standard library's ‘string.Template’ class
  <URL:https://docs.python.org/3/library/string.html#template-strings>.

* Serving the resulting generated page as an HTTP response. This needs
  to be handled in a standard way to conform to networking and
  web-browser expectations. The library handling your interface to the
  web server is the best candidate for this task.

If you want a small framework to handle these while letting you keep
your configuration work reasonably simple, I recommend Bottle
<URL:http://bottlepy.org/>.

Good hunting!

-- 
 \        “Perchance you who pronounce my sentence are in greater fear |
  `\   than I who receive it.” —Giordano Bruno, burned at the stake by |
_o__)  the Catholic church for the heresy of heliocentrism, 1600-02-16 |
Ben Finney




More information about the Python-list mailing list