Menu

Output from tulip plugins

Ethan K
2015-12-17
2016-04-25
  • Ethan K

    Ethan K - 2015-12-17

    Hi-

    I'm seeing inconsistencies with how plugins write to stdout. When a plugin is loaded automatically (from the Tulip\lib\tulip\python folder), its stdout does not get displayed in the python output box.

    Here's what I'm trying to do. It stops working after Step #3:
    1. Load a plugin automatically
    2. Run the plugin on any graph
    3. Plugin prints some stuff to stdout
    4. Let the user view that stuff

    If I load the plugin using the 'Register Plugin' button in the Tulip Develop Tab, the plugin can write to stdout and it appears in the workspace's python output box. Why do plugins behave differently based on how they're loaded?

    What's the correct way for a plugin to display a bunch of text to the user?

    Thanks,
    Ethan

    For completeness, here's a plugin to reproduce the problem.

    from tulip import *
    import tulipplugins
    
    class HelloWorld(tlp.Algorithm):
        def __init__(self, context):
            tlp.Algorithm.__init__(self, context)
    
        def check(self):
            return (True, "")
    
        def run(self):
            print "Hello World!"
            return True
    
    tulipplugins.registerPlugin("HelloWorld", "HelloWorldPlugin", "", "17/12/2015", "", "1.0")
    
     
  • Antoine Lambert

    Antoine Lambert - 2015-12-18

    Hi Ethan,

    I cannot reproduce your issue with the latest Tulip version (4.8).

    The way Python standard output is handled has changed since the 4.7 release :
    Python messages are now printed to the "Messages log" dialog located
    in the left part of the Tulip GUI (below the "Develop" button).
    When I have implemented that change, I must also have fixed the issue you mention.

    Nevertheless, if you want to stick with Tulip 4.7, launch it through a terminal
    ($ <tulip_install_path>/bin/tulip_perspective -p Tulip) and you should have Python standard output printed to it.

    Antoine

     
  • Ethan K

    Ethan K - 2015-12-18

    Thanks for the fast reply, Antoine.

    The problem I described is resolved.

    I have another problem with the python output now though. I have a plugin that prints a lot of textual statistics about a network. What's the best way to present these statistics to the user?

    The python message log is not large enough to display the messages. With this output, users would have to copy/paste the data to a text editor. My users are not comfortable with the command line to redirect output to a file.

     

    Last edit: Ethan K 2015-12-18
  • Antoine Lambert

    Antoine Lambert - 2015-12-21

    Hi Ethan,

    I have just committed to the tulip trunk some improvements regarding the Tulip message logger : the logger dialog width is now extended to the main window width and the whole content of the log messages can now be copied to clipboard.
    Nevertheless, you will have to compile Tulip yourself (not a complicated operation) by checking out its source code from its subversion repository.

    Another possibility to redirect the plugin output to a file is to add a parameter
    to the Tulip plugin that will allow to select a file from the algorithm parameters GUI.
    In the plugin constructor, if you add the following instruction:

    self.addStringParameter("file::filename", "plugin standard output will be redirected to that file")
    

    it will add a parameter named "filename", the "file::" prefix is here to inform the GUI that
    we want the user to a select a file path and a file select dialog will be created from the algorithm parameters panel. Then from the plugin run method, you can retrieve the path selected by the user trough the following instruction :

    filename = self.dataSet["file::filename"]
    

    You can then open a file decriptor on that file and redirect temporarily the python standard output to it.

    If you want more Tulip python plugins examples, you can check my github account, I have created a repository where I put some plugins I wrote : https://github.com/anlambert/tulip_python_plugins

    Hope that it will help,

    Antoine

     
  • Ethan K

    Ethan K - 2016-01-01

    Thank you for the detailed answer, Antoine!

    I will go with the file output for now.

     
  • Ethan K

    Ethan K - 2016-03-07

    Ok. I've used a line like this to let the user select a file.

    self.addStringParameter("file::filename", "plugin standard output will be redirected to that file")
    

    In Tulip, when I click on this parameter input field, it opens up a file dialog. This dialog makes me select a file that already exists. Is there a way to create a new file from within the dialog?

    Thanks in advance!

     
  • Antoine Lambert

    Antoine Lambert - 2016-04-25

    Hi Ethan,

    Sorry for the late answer, was quite busy the last weeks.
    There is a way to select a new file from the file dialog, simply declare your plugin parameter the following way (notice the anyfile):

    self.addStringParameter("anyfile::filename", "plugin standard output will be redirected to that file")

    You will then be allowed to select a new file.
    Anyway, this is not straightforward ... I will add helper functions to declare the different types of file parameters for the next Tulip release.

    Antoine

     

Log in to post a comment.