示例#1
0
def add_image_to_netview(image_path, pane, pwd):
    """.
    """
    # add image to network view
    image = hou.NetworkImage(image_path)
    image.setBrightness(0.75)
    #image.setRect(hou.BoundingRect(0, 0, 5, 2))
    s = pane.visibleBounds()
    center = s.center()
    s.translate(-center)
    s.scale((0.25, 0.25, ))
    s.translate(center)
    image.setRect(s)

    images = nodegraphutils.loadBackgroundImages(pwd)
    images.append(image)
    pane.setBackgroundImages(images)
    nodegraphutils.saveBackgroundImages(pwd, images)
示例#2
0
def paste_clipboard_to_netview(kwargs):
    """Paste clipboard contents (text or image) into the network editor.
    """
    clipboard = Qt.QtGui.QGuiApplication.clipboard()
    image = clipboard.image()
    text = clipboard.text()
    pane = kwargs.get('editor', None)

    if pane:
        pwd = pane.pwd()

        if image.isNull():
            # paste text (if any)
            if text != "":
                note = pwd.createStickyNote()
                note.move(pane.visibleBounds().center())
                s = note.size()
                s = hou.Vector2((
                    s.x() * 1.5,
                    s.y() * 0.5,
                ))
                note.setText(text)
                note.setSize(s)
        else:
            # paste image

            # TODO: generate automatic name
            image_name = ''
            ok, image_name = hou.ui.readInput(
                'Enter name of image to be pasted:',
                buttons=(
                    'Ok',
                    'Cancel',
                ),
                close_choice=1,
                initial_contents=image_name)
            if image_name == '':
                ok = 1
            image_name += '.png'

            if ok == 0:
                category = hou.objNodeTypeCategory()
                hda_typename = 'qLib::embedded_images'
                embedded = 'Embedded'
                hda_def = hou.hdaDefinition(category, hda_typename, embedded)

                # create hda definition if doesn't exist
                if not hda_def:
                    temp_node = hou.node('/obj').createNode('subnet')
                    hda_node = temp_node.createDigitalAsset(
                        name=hda_typename, save_as_embedded=True)
                    hda_node.destroy()

                hda_def = hou.hdaDefinition(category, hda_typename, embedded)

                # create an instance in /obj if doesn't exist
                node = None
                nodes = [
                    n for n in hou.node('/obj').children()
                    if n.type().name() == hda_typename
                ]

                if len(nodes) == 0:
                    node = hou.node('/obj').createNode(
                        hda_typename, node_name="embedded_images")

                # add clipboard image to hda definition (as section)
                ba = Qt.QtCore.QByteArray()
                buffer = Qt.QtCore.QBuffer(ba)
                buffer.open(Qt.QtCore.QIODevice.WriteOnly)
                image.save(buffer, "png")
                buffer.close()
                hda_def.addSection(image_name, str(buffer.data()))

                # add image to network view
                image = hou.NetworkImage(
                    "opdef:/qLib::Object/embedded_images?%s" % image_name)
                image.setBrightness(0.75)
                #image.setRect(hou.BoundingRect(0, 0, 5, 2))
                s = pane.visibleBounds()
                center = s.center()
                s.translate(-center)
                s.scale((
                    0.25,
                    0.25,
                ))
                s.translate(center)
                image.setRect(s)

                images = nodegraphutils.loadBackgroundImages(pwd)
                images.append(image)
                pane.setBackgroundImages(images)
                nodegraphutils.saveBackgroundImages(pwd, images)
示例#3
0
def paste_clipboard_to_netview(kwargs):
    """Paste clipboard contents (text or image) into the network editor.
    """
    clipboard = Qt.QtGui.QGuiApplication.clipboard()
    image = clipboard.image()
    text = clipboard.text()
    pane = kwargs.get('editor', None)

    if pane:
        pwd = pane.pwd()

        if image.isNull():
            # paste text (if any)
            if text!="":
                note = pwd.createStickyNote()
                note.move(pane.visibleBounds().center())
                s = note.size()
                s = hou.Vector2((s.x()*1.5, s.y()*0.5, ))
                note.setText(text)
                note.setSize(s)
        else:
            # paste image

            # TODO: generate automatic name
            image_name = ''
            ok, image_name = hou.ui.readInput('Enter name of image to be pasted:',
                buttons=('Ok', 'Cancel', ), close_choice=1,
                initial_contents=image_name)
            if image_name=='':
                ok = 1
            image_name += '.png'

            if ok==0:
                category = hou.objNodeTypeCategory()
                hda_typename = 'qLib::embedded_images'
                embedded = 'Embedded'
                hda_def = hou.hdaDefinition(category, hda_typename, embedded)
                
                # create hda definition if doesn't exist
                if not hda_def:
                    temp_node = hou.node('/obj').createNode('subnet')
                    hda_node = temp_node.createDigitalAsset(name=hda_typename, save_as_embedded=True)
                    hda_node.destroy()
        
                hda_def = hou.hdaDefinition(category, hda_typename, embedded)
        
                # create an instance in /obj if doesn't exist
                node = None
                nodes = [ n for n in hou.node('/obj').children() if n.type().name()==hda_typename ]
                
                if len(nodes)==0:
                    node = hou.node('/obj').createNode(hda_typename, node_name="embedded_images")
        
                # add clipboard image to hda definition (as section)
                ba = Qt.QtCore.QByteArray();
                buffer = Qt.QtCore.QBuffer(ba)
                buffer.open(Qt.QtCore.QIODevice.WriteOnly)
                image.save(buffer, "png")       
                buffer.close()
                hda_def.addSection(image_name, str(buffer.data()))
                
                # add image to network view
                image = hou.NetworkImage("opdef:/qLib::Object/embedded_images?%s" % image_name)
                image.setBrightness(0.75)
                #image.setRect(hou.BoundingRect(0, 0, 5, 2))
                s = pane.visibleBounds()
                center = s.center()
                s.translate(-center)
                s.scale((0.25, 0.25, ))
                s.translate(center)
                image.setRect(s)

                images = nodegraphutils.loadBackgroundImages(pwd)
                images.append(image)
                pane.setBackgroundImages(images)
                nodegraphutils.saveBackgroundImages(pwd, images)