#1
  1. Wacky hack
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2001
    Location
    London, England
    Posts
    513
    Rep Power
    14

    text ui development


    Hullo,

    I'm currently trying to find a good way to rewrite the text-based interface to QuickRip. At the moment, it just uses print statements and pipes to open the "clear" command, which works OK but has major drawbacks:

    1) If the contents is bigger than the screen, the top is pushed off the screen
    2) Getting user input isn't as intuitive as it should be

    I've been pulling my hair out playing with curses, which is quite frankly horrible to code with, and I'm getting nowhere slowly.

    Has anyone stumbled across any good text-based UIs? Got any of their own code to make life easier in the shell?

    Any discussion is really appreciated at the moment!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    133
    Rep Power
    12
    I don't know if it'll help, but look at cmd.py in your python distribution.

    "A generic class to build line-oriented command interpreters."

    Might be less than you want, or plain wrong. Anyway, there it is.
  4. #3
  5. Wacky hack
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2001
    Location
    London, England
    Posts
    513
    Rep Power
    14
    I'll have a look... thanks for the tip.

    At the moment I'm persevering with curses as the only option. It's really annoying that about 5 years ago someone wrote a wrapper for curses called Tinker which is exactly what I want, but it no longer exists!
  6. #4
  7. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Hi Telex,

    I dont know if this is what your looking for but the ui bit attracted me, and since it mentions Tk and well , anyway here's the link

    http://www.pythonware.com/products/uitoolkit/

    Mark.
  8. #5
  9. Wacky hack
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2001
    Location
    London, England
    Posts
    513
    Rep Power
    14
    Thanks for that link Mark. They only seem to have Tk 'bindings' at the moment, so it's not much use to me. I'm still blundering on with curses, trying to force it to behave the way I want. If I end up getting it to work, I might try to release a module that makes some useable widgets using curses, just so the next fool who decides to try this has something useful to work with
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    25
    Rep Power
    0
    I don't know a thing about curses, but heres some code i'm using for my ui:

    #Prompt: The prompt text (colon automagically added)
    #Type: 0 for str, 1 for num input
    #ValidResp: a list of Valid Responses
    def Prompter(Prompt, Type=0, ValidResp=[]):
    Valid = 0
    while Valid == 0:
    if Type == 0:
    Resp = raw_input(Prompt + ": ")
    if ValidResp != []:
    for Case in ValidResp:
    if Resp == Case:
    Valid = 1

    if Valid == 0:
    print "Error - Invalid Input (" + `Resp` + ")"
    else:
    Valid = 1

    elif Type == 1:
    try:
    Resp = input(Prompt + ": ")
    if ValidResp != []:
    for Case in ValidResp:
    if Resp == Case:
    Valid = 1

    if Valid == 0:
    print "Error - Invalid Input (" + `Resp` + ")"
    else:
    Valid = 1

    except ValueError:
    print "Error - Invalid Input"
    except NameError:
    print "Error - Invalid Input"
    except SyntaxError:
    print "Error - Invalid Input"
    return Resp

    #Banner: a title for the menu
    #OptDict: a dict with the keys as the display text, and the values as #the functs to be called
    def Menu(Banner, OptDict):
    print Banner
    print "-"*(len(Banner) + 3)
    print
    Order = [Key for Key in OptDict]
    Order.sort()
    Counter = 1
    for Key in Order:
    print "(" + `Counter` + ")", Key
    Counter += 1
    print
    Choice = Prompter("Enter your choice", 1, [i for i in range(0, Counter)])
    OptDict[Choice]()

    Don't know if it'll help much, but good luck!
  12. #7
  13. Wacky hack
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2001
    Location
    London, England
    Posts
    513
    Rep Power
    14
    It's quite similar to the code I already have, or rather the more modular code I've been considering to replace the current CLI code.

    I'm dropping curses because it's just too painful to work with.

    p.s. any chance you could format that code using the forum's code tags? That way the indentation would be kept...
  14. #8
  15. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Hey guys, what are curses? There seems to be allot of talk about them and I have no idea what hey are

    Mark.
  16. #9
  17. Wacky hack
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2001
    Location
    London, England
    Posts
    513
    Rep Power
    14
    curses is an API for command line interfaces. It's useful when developing complex CLIs, though it'd really awful to work with. Lots and lots of GNU tools use ncurses (ncurses being the Free version of curses)
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    133
    Rep Power
    12
    telex4, I don't know how far you've got, but have you checked out Pyncurses or PySlang? They might bring something new to what you're trying to do.

    There's also the Python Dialog project, and pyrepl, a replacement for the readline module in python.

    And what about Iface? Might it be something?

    Also, I guess you've already checked out the Charming Python: Curses Programming article.

    If you already know about these, they might help someone else.
    Last edited by percivall; August 20th, 2003 at 11:45 AM.

IMN logo majestic logo threadwatch logo seochat tools logo