Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.2 / 3....
  • LibreOffice 3.6.6 / 4.0.3
  • MPlayer 1.1.1
  • systemd 204
  • Arch Linux 2013.05.01
  • Blender 2.67
  • KDE Software Compilatio...
  • CrunchBang Linux Stable...
  • Elementary OS 0.1 / 0.2...
  • SystemRescueCd 3.6.0
  • Home > Linux > Programming > Libraries

    TUI 1.1.1

    Download button

    No screenshots available
    Downloads: 142  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Joel Hedlund | More programs
    MIT/X Consortium Lic... / FREE
    February 24th, 2011, 14:57 GMT
    ROOT / Programming / Libraries

     Read user reviews (0)  Refer to a friend  Subscribe

    TUI description

    Quickly add a competent textual user interface to your Python program

    TUI is a tool straightforward to use, both for developers and users. It can parse options from multiple config files and command line, and can produce constructive error messages given bad input. It can also help keep the source code clean by moving help text to a separate documentation file.

    If you have problems with this package, please contact the author.

    Getting started

    Typically, you will need to import the tui class and some format classes from the tui.formats module. The tui.docparser module has documentation on how to write tui-compatible documentation files, but you won't likely need anything else from there. You probably won't ever have to use anything from the TextBlockParser module.

    Howto

    Let's pretend we're making a moose counter. First, we create the script file 'moosecounter.py', a docs file 'moosecounter.docs' and a config file 'moosecounter.cfg' in the same dir. Leave the latter two empty and start editing the scriptfile.

    Instantiate a textual user interface object and give it the proper name right from the start and use the magical initprog() feature, like so:

    #!/usr/bin/env python

    from tui import tui, formats

    __version__ = "0.1.0"
    if __name__ == '__main__':
     o = tui(progname='MooseCounter', main=__file__)
     o.initprog()


    Save and execute your moose counter with no arguments, and voila: usage instructions! Execute it with the --HELP flag, and voila: verbose program information, including syntax help for the config file! The config files are meant to be used by your users to configure your program with, by the way.

    A quick note on using main=__file__:

    Doing this is handy because it enables tui to find any .cfg or .docs files you want to distribute with your program, however if you do not supply a version str, tui will attempt to import the module and read the __version__ attribute (if present), so if you are planning to use this feature, make sure your script can be imported without side effects. But as this is standard python coding practice, you should probably be doing this already!

    Now you can go on to adding more options to your moose counter. Just stick some o.makeoption() and o.makeposarg() clauses between the last two lines in the example above. You will probably also need to import some formats for your options from the formats module in this package. For example you can do something like this:

    #!/usr/bin/env python

    from tui import tui, formats

    __version__ = "0.1.0"
    if __name__ == '__main__':
     o = tui(main=__file__, progname='MooseCounter')
     o.makeoption('horn-points', formats.BoundedInt(lowerbound=1), '13')
     o.makeoption('weight', formats.Float, '450.0', 'w')
     o.makeposarg('observation_data', formats.ReadableFile)
     o.makeposarg('result_file', formats.WritableFile)
     o.initprog()


    After you have saved you can execute your moose counter in same manner as before and see your new options turn up in the help screens. You are highly encouraged to document the program and its options better, and your docs file is the place to do it. Check the help for the tui.docparser module for the syntax.

    OK, so that's a handful of lines of code that take care of all the boring old run of the mill config file and parameter parsing and help screen generation, and now you're free to write code that actally counts mooses. Use o.options() to return a dict of options and values, and o.posargs() to get a list of values for all positional arguments.


    Product's homepage

    Requirements:

    · Python

      


    TAGS:

    user interface | textual UI | Python | UI | textual

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM