Beispiel #1
0
    def idl_output_result(self, result, graphics):

        # Check if PNG
        if result == self._graphicid and len(graphics) > 0:
            # Returns a tuple with the window ID and !magic info.
            idlmagic = graphics.popitem(False)[1]
            img = IDL.EncodeGraphic(idlmagic['WINDOW'], idlmagic['TYPE'])
            if img != None:
                # See Python logging module
                #                self.log.warning("IDL graphic " + str(idlmagic['WINDOW']) + " md5=" +
                #                    hashlib.md5(img.encode()).hexdigest())
                width = str(idlmagic['XSIZE'])
                height = str(idlmagic['YSIZE'])
                response = {
                    'data': {
                        'image/png': img
                    },
                    'metadata': {
                        'image/png': {
                            'width': width,
                            'height': height
                        }
                    }
                }
            else:
                err = 'Error: Unable to encode graphics window ' + str(
                    idlmagic['WINDOW']) + '\n'
                response = {'data': {'text/plain': err}, 'metadata': {}}
        else:
            if result.startswith("<html>"):
                response = {
                    'data': {
                        'text/html': result + '\n'
                    },
                    'metadata': {}
                }
            else:
                response = {
                    'data': {
                        'text/plain': result + '\n'
                    },
                    'metadata': {}
                }

        self.send_response(self.iopub_socket, 'display_data', response)