Python wx.EmptyImage() Examples

The following are 13 code examples of wx.EmptyImage(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module wx , or try the search function .
Example #1
Source File: rasterwindow.py    From spectral with MIT License 6 votes vote down vote up
def __init__(self, parent, index, rgb, **kwargs):
        if 'title' in kwargs:
            title = kwargs['title']
        else:
            title = 'SPy Image'
#        wxFrame.__init__(self, parent, index, "SPy Frame")
#        wxScrolledWindow.__init__(self, parent, index, style = wxSUNKEN_BORDER)

        img = wx.EmptyImage(rgb.shape[0], rgb.shape[1])
        img = wx.EmptyImage(rgb.shape[1], rgb.shape[0])
        img.SetData(rgb.tostring())
        self.bmp = img.ConvertToBitmap()
        self.kwargs = kwargs
        wx.Frame.__init__(self, parent, index, title,
                          wx.DefaultPosition)
        self.SetClientSizeWH(self.bmp.GetWidth(), self.bmp.GetHeight())
        wx.EVT_PAINT(self, self.on_paint)
        wx.EVT_LEFT_DCLICK(self, self.left_double_click) 
Example #2
Source File: chronolapse.py    From chronolapse with MIT License 6 votes vote down vote up
def callback(self):
        try:
            path = self.parent.takeWebcam(
                        os.path.basename(self.temppath),
                        os.path.dirname(self.temppath),
                        ''
                    )

            # try this so WX doesnt freak out if the file isnt a bitmap
            pilimage = Image.open(path)
            myWxImage = wx.EmptyImage( pilimage.size[0], pilimage.size[1] )
            myWxImage.SetData( pilimage.convert( 'RGB' ).tostring() )
            bitmap = myWxImage.ConvertToBitmap()

            self.previewbitmap.SetBitmap(bitmap)
            self.previewbitmap.CenterOnParent()

        except Exception, e:
            logging.debug(
                    "Exception while showing camera preview: %s" % repr(e)) 
Example #3
Source File: make_timelapse.py    From Pigrow with GNU General Public License v3.0 6 votes vote down vote up
def graph_caps(self, cap_files, graphdir):
        OS = "linux"
        if len(cap_files) > 1:
            print("make caps graph")
            if OS == "linux":
                print("Yay linux")
                os.system("../visualisation/caps_graph.py caps="+capsdir+" out="+graphdir)
            elif OS == 'win':
                print("oh, windows, i prefer linux but no worries...")
                os.system("python ../visualisation/caps_graph.py caps="+capsdir+" out="+graphdir)
        else:
            print("skipping graphing caps - disabled or no caps to make graphs with")
        if os.path.exists(graphdir+'caps_filesize_graph.png'):
            cap_size_graph_path = wx.Image(graphdir+'caps_filesize_graph.png', wx.BITMAP_TYPE_ANY)
            return cap_size_graph_path
        else:
            print("NOT ENOUGH CAPS GRAPH SO USING BLANK THUMB")
            blankimg = wx.EmptyImage(width=100, height=100, clear=True)
            return blankimg 
Example #4
Source File: MeshCanvas.py    From laplacian-meshes with GNU General Public License v3.0 5 votes vote down vote up
def saveImageGL(mvcanvas, filename):
    view = glGetIntegerv(GL_VIEWPORT)
    img = wx.EmptyImage(view[2], view[3] )
    pixels = glReadPixels(0, 0, view[2], view[3], GL_RGB,
                     GL_UNSIGNED_BYTE)
    img.SetData( pixels )
    img = img.Mirror(False)
    img.SaveFile(filename, wx.BITMAP_TYPE_PNG) 
Example #5
Source File: backend_wxagg.py    From Computable with MIT License 5 votes vote down vote up
def _convert_agg_to_wx_image(agg, bbox):
    """
    Convert the region of the agg buffer bounded by bbox to a wx.Image.  If
    bbox is None, the entire buffer is converted.

    Note: agg must be a backend_agg.RendererAgg instance.
    """
    if bbox is None:
        # agg => rgb -> image
        image = wx.EmptyImage(int(agg.width), int(agg.height))
        image.SetData(agg.tostring_rgb())
        return image
    else:
        # agg => rgba buffer -> bitmap => clipped bitmap => image
        return wx.ImageFromBitmap(_WX28_clipped_agg_as_bitmap(agg, bbox)) 
Example #6
Source File: backend_wxagg.py    From matplotlib-4-abaqus with MIT License 5 votes vote down vote up
def _convert_agg_to_wx_image(agg, bbox):
    """
    Convert the region of the agg buffer bounded by bbox to a wx.Image.  If
    bbox is None, the entire buffer is converted.

    Note: agg must be a backend_agg.RendererAgg instance.
    """
    if bbox is None:
        # agg => rgb -> image
        image = wx.EmptyImage(int(agg.width), int(agg.height))
        image.SetData(agg.tostring_rgb())
        return image
    else:
        # agg => rgba buffer -> bitmap => clipped bitmap => image
        return wx.ImageFromBitmap(_WX28_clipped_agg_as_bitmap(agg, bbox)) 
Example #7
Source File: backend_wxagg.py    From neural-network-animation with MIT License 5 votes vote down vote up
def _convert_agg_to_wx_image(agg, bbox):
    """
    Convert the region of the agg buffer bounded by bbox to a wx.Image.  If
    bbox is None, the entire buffer is converted.

    Note: agg must be a backend_agg.RendererAgg instance.
    """
    if bbox is None:
        # agg => rgb -> image
        image = wx.EmptyImage(int(agg.width), int(agg.height))
        image.SetData(agg.tostring_rgb())
        return image
    else:
        # agg => rgba buffer -> bitmap => clipped bitmap => image
        return wx.ImageFromBitmap(_WX28_clipped_agg_as_bitmap(agg, bbox)) 
Example #8
Source File: backend_wxagg.py    From ImageFusion with MIT License 5 votes vote down vote up
def _convert_agg_to_wx_image(agg, bbox):
    """
    Convert the region of the agg buffer bounded by bbox to a wx.Image.  If
    bbox is None, the entire buffer is converted.

    Note: agg must be a backend_agg.RendererAgg instance.
    """
    if bbox is None:
        # agg => rgb -> image
        image = wx.EmptyImage(int(agg.width), int(agg.height))
        image.SetData(agg.tostring_rgb())
        return image
    else:
        # agg => rgba buffer -> bitmap => clipped bitmap => image
        return wx.ImageFromBitmap(_WX28_clipped_agg_as_bitmap(agg, bbox)) 
Example #9
Source File: ColourSelectButton.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def SetValue(self, value):
        self.value = value
        width, height = self.GetSize()
        image = wx.EmptyImage(width - 10, height - 10)
        image.SetRGBRect((1, 1, width - 12, height - 12), *value)
        self.SetBitmapLabel(image.ConvertToBitmap()) 
Example #10
Source File: __init__.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def piltoimage(pil, hasAlpha):
    """
    Convert PIL Image to wx.Image.
    """
    image = wx.EmptyImage(*pil.size)
    rgbPil = pil.convert('RGB')
    if hasAlpha:
        image.SetData(rgbPil.tobytes())
        image.SetAlphaData(pil.convert("RGBA").tobytes()[3::4])
    else:
        new_image = rgbPil
        data = new_image.tobytes()
        image.SetData(data)
    return image 
Example #11
Source File: bitmap_from_array.py    From dials with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def bmp_lst_scaled(self, scale=1.0):
        if self._ini_wx_bmp_lst is None:

            NewW = 350

            wx_image = wx.EmptyImage(NewW, NewW)
            wxBitmap = wx_image.ConvertToBitmap()

            dc = wx.MemoryDC(wxBitmap)
            text = "No Shoebox data"
            w, h = dc.GetSize()
            tw, th = dc.GetTextExtent(text)
            dc.Clear()
            dc.DrawText(text, (w - tw) / 2, (h - th) / 2)  # display text in center
            dc.SelectObject(wxBitmap)
            del dc
            wx_bmp_lst = [[wxBitmap]]

        else:
            wx_bmp_lst = []
            for data_3d in self._ini_wx_bmp_lst:
                single_block_lst = []
                for sigle_img_data in data_3d:
                    single_block_lst.append(self._wx_bmp_scaled(sigle_img_data, scale))

                wx_bmp_lst.append(single_block_lst)

        return wx_bmp_lst 
Example #12
Source File: tile_generation.py    From dials with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def flex_image_get_tile(self, x, y):
        # The supports_rotated_tiles_antialiasing_recommended flag in
        # the C++ FlexImage class indicates whether the underlying image
        # instance supports tilted readouts.  Anti-aliasing only makes
        # sense if it does.
        if (
            self.raw_image is not None
            and self.zoom_level >= 2
            and self.flex_image.supports_rotated_tiles_antialiasing_recommended
            and self.user_requests_antialiasing
        ):
            # much more computationally intensive to prepare nice-looking pictures of tilted readout
            self.flex_image.setZoom(self.zoom_level + 1)
            fraction = 512.0 / self.flex_image.size1() / (2 ** (self.zoom_level + 1))
            self.flex_image.setWindowCart(y, x, fraction)
            self.flex_image.prep_string()
            w, h = self.flex_image.ex_size2(), self.flex_image.ex_size1()
            assert w == 512
            assert h == 512
            wx_image = wx.EmptyImage(w / 2, h / 2)
            import PIL.Image as Image

            Image_from_bytes = Image.frombytes(
                "RGB", (512, 512), self.flex_image.as_bytes()
            )
            J = Image_from_bytes.resize((256, 256), Image.ANTIALIAS)
            wx_image.SetData(J.tostring())
            return wx_image.ConvertToBitmap()
        elif self.raw_image is not None:
            self.flex_image.setZoom(self.zoom_level)
            fraction = 256.0 / self.flex_image.size1() / (2 ** self.zoom_level)
            self.flex_image.setWindowCart(y, x, fraction)
            self.flex_image.prep_string()
            w, h = self.flex_image.ex_size2(), self.flex_image.ex_size1()
            assert w == 256
            assert h == 256
            wx_image = wx.EmptyImage(w, h)
            wx_image.SetData(self.flex_image.as_bytes())
            return wx_image.ConvertToBitmap()
        else:
            wx_image = wx.EmptyImage(256, 256)
            return wx_image.ConvertToBitmap() 
Example #13
Source File: bitmap_from_array.py    From dials with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def _wx_img_w_cpp(self, np_2d_tmp, show_nums, palette, np_2d_mask=None):

        xmax = np_2d_tmp.shape[1]
        ymax = np_2d_tmp.shape[0]

        if np_2d_mask is None:
            np_2d_mask = np.zeros((ymax, xmax), "double")

        transposed_data = np.zeros((ymax, xmax), "double")
        transposed_mask = np.zeros((ymax, xmax), "double")

        transposed_data[:, :] = np_2d_tmp
        transposed_mask[:, :] = np_2d_mask

        flex_data_in = flex.double(transposed_data)
        flex_mask_in = flex.double(transposed_mask)

        if palette == "black2white":
            palette_num = 1
        elif palette == "white2black":
            palette_num = 2
        elif palette == "hot ascend":
            palette_num = 3
        else:  # assuming "hot descend"
            palette_num = 4

        img_array_tmp = self.wx_bmp_arr.gen_bmp(
            flex_data_in, flex_mask_in, show_nums, palette_num
        )

        np_img_array = img_array_tmp.as_numpy_array()

        height = np.size(np_img_array[:, 0:1, 0:1])
        width = np.size(np_img_array[0:1, :, 0:1])
        img_array = np.empty((height, width, 3), "uint8")
        img_array[:, :, :] = np_img_array[:, :, :]

        self._wx_image = (
            wx.EmptyImage(width, height) if WX3 else wx.Image(width, height)
        )
        self._wx_image.SetData(img_array.tostring())

        data_to_become_bmp = (self._wx_image, width, height)

        return data_to_become_bmp