provide full model information and not only the truncated version

Issue #400 resolved
Andreas Janz created an issue

Model information is shown as truncated string, which is good for navigation inside the model:

But when copying the content, I want ALL the data!

Comments (3)

  1. Benjamin Jakimow

    Good idead, but wow do you like to get large n-d arrays printed, which by default are cutted by str(array)?

    hubflow models might additionally implement a mimeData() -> QMimeData function that allows to copy / paste them into various formats and eases sharing them via the QClipboard.

  2. Andreas Janz reporter

    Use the np.printoptions context manager:

    import numpy as np
    
    with np.printoptions(threshold=np.inf):
        s = str(np.ones((50,50)))
        print(s)
    

  3. Benjamin Jakimow

    Seems to be resolved with

    class HubFlowPyObjectTreeNode(PyObjectTreeNode):
    
        def __init__(self, *args, **kwds):
            super().__init__(*args, **kwds)
    
        def populateContextMenu(self, menu: QMenu):
            def copyToClipboard():
                state = np.get_printoptions()['threshold']
                np.set_printoptions(threshold=np.inf)
                QApplication.clipboard().setText(str(self.mPyObject))
                np.set_printoptions(threshold=state)
    
            if isinstance(self.mPyObject, np.ndarray):
                a = menu.addAction('Copy Array')
                a.setToolTip('Copy Numpy Array to Clipboard.')
                a.triggered.connect(copyToClipboard)
    

    Please test and close if appropriate @Andreas Janz

  4. Log in to comment