Dialog to ask the user for a string?


What's the easiest way to, via a keyboard shortcut, display a modal dialog in the latest RV on Linux (3.12.13) for the user to enter a string in, that gets passed back to a python function?

Are there any such examples shipping with RV? Sorry if there are obvious ones present, am a bit stressed and thought that it might be easier and quicker to just pop you nice guys a question. :)




  • 0
    Alan Trombla

    Just to update this post with the contents of my email conversation with David, here's the gist:

    Basically you want to write a small RV Package to add a single mode, with one event handler for your hotkey (and possibly a menu item). RV Package Documentation here starts here:


    Description of sample (Mu) package:


    RV comes with many sample packages in Mu and one sample Python package, called pyhello-1.0.rvpkg (note that all package files are just zip files, so they can be unzipped to inspect them).

    About the dialog: it's much easier to do this from Mu, IE it's a one liner:

    (string,bool) ans = qt.QInputDialog.getText (mainWindowWidget(), "TITLE", "String here:", qt.QLineEdit.Normal, "default text", 0);

    From Python it's going to be trickier, but you have a couple options. You could write this in PyQt, but there's the possibility of conflicts between PyQt's version of Qt and RV's, and also there are some issues with Python thread management in 3.12.13 (fixed in 3.12.14, due out in a week or so). So I wouldn't advise that.

    I'd recommend using the "eval" portal in the runtime module to evaluate the above Mu from Python. Like this:

    def getInputString (event) :

        title = "Window Title"
        label = "input label:"
        defaultText = "default input text"
        dialogCode = """
            (string,bool) ans = qt.QInputDialog.getText(commands.mainWindowWidget(), "%s", "%s", qt.QLineEdit.Normal, "%s", 0);
            ans._0 + "|" + string(ans._1);
        print "%s" % rv.runtime.eval(dialogCode % (title, label, defaultText), ["qt", "commands"])


    You'll have to parse the returned string to pull apart the returned string to separate the answer from the status, but that shouldn't be too hard.



  • 0
    Rene Grasser

    Hi Alan,

    do you have an example with a text box to type multiple lines of text?