Пример #1
0
    def __init__(self, parent, id=-1):
        ## Any data the Draw() function needs must be initialized before
        ## calling BufferedWindow.__init__, as it will call the Draw
        ## function.

        self.DrawData = {}

        ## create a marker bitmap
        print "initing the marker"

        MaskColor = wx.Colour(254, 255, 255)

        self.Marker = wx.EmptyBitmap(40, 40)
        dc = wx.MemoryDC()
        dc.SelectObject(self.Marker)

        dc.BeginDrawing()
        dc.SetBackground(wx.Brush(MaskColor))
        dc.Clear()
        dc.SetPen(wx.RED_PEN)
        dc.SetBrush(wx.GREEN_BRUSH)
        dc.DrawPolygon(((20, 0), (30, 10), (24, 24), (40, 40), (0, 20)))
        dc.EndDrawing()
        Mask = wx.MaskColour(self.Marker, MaskColor)

        self.Marker.SetMask(Mask)

        BufferedWindow.__init__(self, parent, id)
Пример #2
0
def convert(file, maskClr, outputDir, outputName, outType, outExt):
    if string.lower(os.path.splitext(file)[1]) == ".ico":
        icon = wx.Icon(file, wx.BITMAP_TYPE_ICO)
        img = wx.BitmapFromIcon(icon)
    else:
        img = wx.Bitmap(file, wx.BITMAP_TYPE_ANY)

    if not img.Ok():
        return 0, file + " failed to load!"
    else:
        if maskClr:
            om = img.GetMask()
            mask = wx.MaskColour(img, maskClr)
            img.SetMask(mask)
            if om is not None:
                om.Destroy()
        if outputName:
            newname = outputName
        else:
            newname = os.path.join(
                outputDir,
                os.path.basename(os.path.splitext(file)[0]) + outExt)
        if img.SaveFile(newname, outType):
            return 1, file + " converted to " + newname
        else:
            img = wx.ImageFromBitmap(img)
            if img.SaveFile(newname, outType):
                return 1, "ok"
            else:
                return 0, file + " failed to save!"
Пример #3
0
    def __init__(self, parent, log):
        wx.Panel.__init__(self, parent, -1, style=wx.NO_FULL_REPAINT_ON_RESIZE)
        self.log = log

        if 0:  # a test case for catching wx.PyAssertionError

            #wx.GetApp().SetAssertMode(wx.PYAPP_ASSERT_SUPPRESS)
            #wx.GetApp().SetAssertMode(wx.PYAPP_ASSERT_EXCEPTION)
            #wx.GetApp().SetAssertMode(wx.PYAPP_ASSERT_DIALOG)
            #wx.GetApp().SetAssertMode(wx.PYAPP_ASSERT_EXCEPTION | wx.PYAPP_ASSERT_DIALOG)

            try:
                bmp = wx.Bitmap("nosuchfile.bmp", wx.BITMAP_TYPE_BMP)
                mask = wx.Mask(bmp, wx.BLUE)
            except wx.PyAssertionError:
                self.log.write(
                    "Caught wx.PyAssertionError!  I will fix the problem.\n")
                bmp = images.getTest2Bitmap()
                mask = wx.MaskColour(bmp, wx.BLUE)
        else:
            bmp = images.getTest2Bitmap()
            mask = wx.Mask(bmp, wx.BLUE)

        bmp.SetMask(mask)
        b = wx.BitmapButton(self, 30, bmp, (20, 20),
                            (bmp.GetWidth() + 10, bmp.GetHeight() + 10))
        b.SetToolTipString("This is a bitmap button.")
        self.Bind(wx.EVT_BUTTON, self.OnClick, b)
Пример #4
0
    def DoDrag(self, x, y):
        """
          Implement all the drag and drop functionality:
        """

        """
          Create the dragImage and begin dragging over the full screen
        """
        offscreenBuffer = wx.EmptyBitmap (self.bounds.GetWidth(), self.bounds.GetHeight())
        memoryDC = wx.MemoryDC()
        memoryDC.SelectObject (offscreenBuffer)

        memoryDC.BeginDrawing()
        self.Draw (memoryDC)

        maskBitmap = wx.EmptyBitmap (self.bounds.GetWidth(), self.bounds.GetHeight(), 1)
        memoryDC.SelectObject (maskBitmap)

        memoryDC.SetBackground (wx.BLACK_BRUSH)
        memoryDC.Clear()

        self.DrawMask (memoryDC)
        memoryDC.EndDrawing()

        memoryDC.SelectObject (wx.NullBitmap)

        if "__WXMAC__" in wx.PlatformInfo:  # workaround for wxMac bug
            offscreenBuffer.SetMask (wx.MaskColour(maskBitmap, wx.BLACK))
        else:
            offscreenBuffer.SetMask (wx.Mask(maskBitmap))

        """
          Create the dragImage and begin dragging
        """
        if "__WXGTK__" in wx.PlatformInfo:
            # The "hole punching" trick dosen't work on wxGTK, move the hostspot
            # to be just outside the image
            x, y = -1, -1
        self.dragImage = wxCanvasDragImage (offscreenBuffer)

        self.dragImage.BeginDrag(wx.Point (x,y), self.canvas, True)
        self.dragImage.Move (self.ConvertToCanvasDeviceCoordinates (x, y))
        self.dragImage.Show()

        """
          We need to keep a reference to the dataObject, rather than create
        it in the construction because wxCanvasDropSource doesn't own the
        data so the garbage collector will delete it.
        """
        dataObject = self.ConvertDrawableObjectToDataObject(x, y)
        dropSource = wxCanvasDropSource (self, dataObject)

        self.canvas.internalDnDItem = self
        result = dropSource.DoDragDrop (wx.Drag_AllowMove)
        self.canvas.internalDnDItem = None
        self.dragImage.Hide()
        self.dragImage.EndDrag()
        del self.dragImage
Пример #5
0
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1,
                         style=wx.NO_FULL_REPAINT_ON_RESIZE)
#         self.log = log

        if 0:  # a test case for catching wx.PyAssertionError

            #wx.GetApp().SetAssertMode(wx.PYAPP_ASSERT_SUPPRESS)
            #wx.GetApp().SetAssertMode(wx.PYAPP_ASSERT_EXCEPTION)
            #wx.GetApp().SetAssertMode(wx.PYAPP_ASSERT_DIALOG)
            #wx.GetApp().SetAssertMode(wx.PYAPP_ASSERT_EXCEPTION | wx.PYAPP_ASSERT_DIALOG)

            try:
                bmp = wx.Bitmap("nosuchfile.bmp", wx.BITMAP_TYPE_BMP)
                mask = wx.Mask(bmp, wx.BLUE)
            except wx.PyAssertionError:
                self.log.write("Caught wx.PyAssertionError!  I will fix the problem.\n")
                bmp = images.Test2.GetBitmap()
                mask = wx.MaskColour(bmp, wx.BLUE)
        else:
            ima = wx.Image("../icons/closeTrans.png", type=wx.BITMAP_TYPE_ANY)
            ima = ima.Scale(20,20, wx.IMAGE_QUALITY_HIGH)
            bmp=ima.ConvertToBitmap()
            
#             bmp = images.Test2.GetBitmap()
            mask = wx.Mask(bmp, wx.BLUE)

#         bmp.SetMask(mask)
#         b = wx.BitmapButton(self, -1, bmp, (20, 20),
#                        (bmp.GetWidth()+10, bmp.GetHeight()+10))
# #         b.SetToolTipString("This is a bitmap button.")
#         self.Bind(wx.EVT_BUTTON, self.OnClick, b)

        b = wx.BitmapButton(self, -1, bmp, (10, 10),
                            style = wx.NO_BORDER)
        
        # hide a little surprise in the button...
#         img = images.Robin.GetImage()
        # we need to make it be the same size as the primary image, so
        # grab a subsection of this new image
#         cropped = img.GetSubImage((20, 20, bmp.GetWidth(), bmp.GetHeight()))
        b.SetBitmapSelected(ima.ConvertToBitmap())

        b.SetToolTipString("This is a bitmap button with \nwx.NO_BORDER style.")
        self.Bind(wx.EVT_BUTTON, self.OnClick, b)
Пример #6
0
def createBitmap(ImgFileName_, MakeMask_=False):
    """
    Создать объект Bitmap из файла ImgFileName_.
    @param ImgFileName_: Имя файла.
    @param MakeMask_: Флаг создания маски по изображению.
        Фон д.б. DEFAULT_MASK_COLOUR.
    @return: Возвращает созданный объект или None в случае ошибки.
    """
    try:
        # Преобразовать относительные пути в абсолютные
        ImgFileName_ = ic_file.AbsolutePath(ImgFileName_)
        if (not ImgFileName_) or (not os.path.exists(ImgFileName_)):
            log.warning(u'Некорректное имя файла образа: <%s>' % ImgFileName_)
            return None
        bmp = wx.Bitmap(ImgFileName_, getImageFileType(ImgFileName_))
        if MakeMask_:
            # Создать маску и присоединить ее к битмапу
            phone_color = DEFAULT_MASK_COLOUR
            bmp.SetMask(wx.MaskColour(bmp, phone_color))
        return bmp
    except:
        log.fatal(u'Ошибка создания образа файла <%s>' % ImgFileName_)
        return None
Пример #7
0
def createBitmap(img_filename, bMakeMask=False):
    """
    Создать объект Bitmap из файла ImgFileName_.
    @param img_filename: Имя файла.
    @param bMakeMask: Флаг создания маски по изображению.
        Фон д.б. CYAN (0, 255, 255)
    @return: Возвращает созданный объект или None в случае ошибки.
    """
    try:
        # Преобразовать относительные пути в абсолютные
        img_filename = os.path.abspath(os.path.normpath(img_filename))
        if not img_filename or not os.path.exists(img_filename):
            log.warning('File <%s> not found' % img_filename)
            return None

        bmp = wx.Bitmap(img_filename, getImageFileType(img_filename))
        if bMakeMask:
            # Создать маску и присоединить ее к битмапу
            phone_colour = wx.CYAN
            bmp.SetMask(wx.MaskColour(bmp, phone_colour))
        return bmp
    except:
        log.error(u'Ошибка создания образа файла <%s>' % img_filename)
        return None
Пример #8
0
def create_mask(bitmap, colour):
   if IS_WXP4:
      return wx.Mask(bitmap, colour)
   else:
      return wx.MaskColour(bitmap, colour)