Ejemplo n.º 1
0
def runTest(frame, nb, log):
    bmp = wx.Image(opj('bitmaps/image.bmp'),
                   wx.BITMAP_TYPE_BMP).ConvertToBitmap()
    gif = wx.Image(opj('bitmaps/image.gif'),
                   wx.BITMAP_TYPE_GIF).ConvertToBitmap()
    png = wx.Image(opj('bitmaps/image.png'),
                   wx.BITMAP_TYPE_PNG).ConvertToBitmap()
    jpg = wx.Image(opj('bitmaps/image.jpg'),
                   wx.BITMAP_TYPE_JPEG).ConvertToBitmap()

    panel = wx.Panel(nb, -1)

    pos = 10
    wx.StaticBitmap(panel, -1, bmp, (10, pos),
                    (bmp.GetWidth(), bmp.GetHeight()))

    pos = pos + bmp.GetHeight() + 10
    wx.StaticBitmap(panel, -1, gif, (10, pos),
                    (gif.GetWidth(), gif.GetHeight()))

    pos = pos + gif.GetHeight() + 10
    wx.StaticBitmap(panel, -1, png, (10, pos),
                    (png.GetWidth(), png.GetHeight()))

    pos = pos + png.GetHeight() + 10
    wx.StaticBitmap(panel, -1, jpg, (10, pos),
                    (jpg.GetWidth(), jpg.GetHeight()))

    return panel
Ejemplo n.º 2
0
    def __init__(self, parent):
        wx.Window.__init__(self, parent)
        self.image1= wx.Image(opj('bitmaps/image.bmp'), wx.BITMAP_TYPE_BMP)
        self.image2= wx.Image(opj('bitmaps/toucan.png'), wx.BITMAP_TYPE_PNG)

        # the factors -- 1.0 does not not modify the image
        self.factorred=   1.0
        self.factorgreen= 1.0
        self.factorblue=  1.0
        self.factoralpha= 1.0

        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
        self.Bind(wx.EVT_SIZE, self.OnSize)
Ejemplo n.º 3
0
    def __init__(self, parent):
        wx.Window.__init__(self, parent)
        self.image1 = wx.Image(opj('bitmaps/image.bmp'), wx.BITMAP_TYPE_BMP)
        self.image2 = wx.Image(opj('bitmaps/toucan.png'), wx.BITMAP_TYPE_PNG)

        # the factors -- 1.0 does not not modify the image
        self.factorred = 1.0
        self.factorgreen = 1.0
        self.factorblue = 1.0
        self.factoralpha = 1.0

        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
        self.Bind(wx.EVT_SIZE, self.OnSize)
Ejemplo n.º 4
0
    def OnPaint(self, evt):
        dc = wx.PaintDC(self)
        dc.SetBackground(wx.Brush("WHITE"))
        dc.Clear()

        dc.SetFont(wx.Font(16, wx.SWISS, wx.NORMAL, wx.BOLD, True))
        dc.DrawText("Bitmap alpha blending (on all ports but gtk+ 1.2)",
                    25,25)
        
        bmp = wx.Bitmap(opj('bitmaps/toucan.png'))
        if "gtk1" in wx.PlatformInfo:
            # Try to make up for lack of alpha support in wxGTK (gtk+
            # 1.2) by converting the alpha blending into a
            # transparency mask.

            # first convert to a wx.Image
            img = bmp.ConvertToImage()

            # Then convert the alpha channel to a mask, specifying the
            # threshold below which alpha will be made fully
            # transparent
            img.ConvertAlphaToMask(220)

            # convert back to a wx.Bitmap
            bmp = img.ConvertToBitmap()

            
        dc.DrawBitmap(bmp, 25,100, True)

        dc.SetFont(self.GetFont())
        y = 75
        for line in range(10):
            y += dc.GetCharHeight() + 5
            dc.DrawText(msg, 200, y)
        dc.DrawBitmap(bmp, 250,100, True)
Ejemplo n.º 5
0
 def OnButton2(self, evt):
     try:
         if True:
             sound = wx.Sound(opj('data/plan.wav'))
         else:
             # sounds can also be loaded from a buffer object
             data = open(opj('data/plan.wav'), 'rb').read()
             sound = wx.SoundFromData(data)
             
         self.log.write("before Play...\n")
         sound.Play(wx.SOUND_ASYNC)
         self.sound = sound  # save a reference (This shoudln't be needed, but there seems to be a bug...)
         wx.YieldIfNeeded()
         self.log.write("...after Play\n")
     except NotImplementedError, v:
         wx.MessageBox(str(v), "Exception Message")
Ejemplo n.º 6
0
    def OnButton2(self, evt):
        try:
            if True:
                sound = wx.adv.Sound(opj('data/plan.wav'))
            else:
                # sounds can also be loaded from a buffer object
                data = open(opj('data/plan.wav'), 'rb').read()
                sound = wx.SoundFromData(data)

            self.log.write("before Play...\n")
            sound.Play(wx.adv.SOUND_ASYNC)
            self.sound = sound  # save a reference (This shoudln't be needed, but there seems to be a bug...)
            # wx.YieldIfNeeded()
            self.log.write("...after Play\n")
        except NotImplementedError as v:
            wx.MessageBox(str(v), "Exception Message")
Ejemplo n.º 7
0
    def onGenerateImage(self, evt):
        self.colorLst = []
        self.panelLst = []
        self.png = wx.Image(opj('testimage.png'),
                            wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        pos = 10
        wx.StaticBitmap(self, -1, self.png, (10, pos),
                        (self.png.GetWidth(), self.png.GetHeight()))
        self.fgs1.Clear(True)
        self.dstImage = wx.ImageFromBitmap(self.png)

        for x in xrange(self.png.GetWidth()):
            for y in xrange(self.png.GetHeight()):
                redColor = self.dstImage.GetRed(x, y)
                greenColor = self.dstImage.GetGreen(x, y)
                blueColor = self.dstImage.GetBlue(x, y)
                tempColor = colda.colorData(redColor, greenColor, blueColor)
                if self.isColorExist(tempColor) == False:
                    self.colorLst.append(tempColor)
                    colorPanel = colp.ColorPanel(self.scrollPanel, -1,
                                                 tempColor)
                    self.fgs1.Add(colorPanel, flag=wx.CENTER, border=10)
                    self.panelLst.append(colorPanel)

        self.scrollPanel.SetSizer(self.fgs1)
        self.scrollPanel.SetAutoLayout(1)
        self.scrollPanel.SetupScrolling()
Ejemplo n.º 8
0
    def OnPaint(self, evt):
        dc = wx.PaintDC(self)
        dc.SetBackground(wx.Brush("WHITE"))
        dc.Clear()

        dc.SetFont(wx.Font(16, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, True))
        dc.DrawText("Bitmap alpha blending (on all ports but gtk+ 1.2)",
                    25,25)
        
        bmp = wx.Bitmap(opj('bitmaps/toucan.png'))
        if "gtk1" in wx.PlatformInfo:
            # Try to make up for lack of alpha support in wxGTK (gtk+
            # 1.2) by converting the alpha blending into a
            # transparency mask.

            # first convert to a wx.Image
            img = bmp.ConvertToImage()

            # Then convert the alpha channel to a mask, specifying the
            # threshold below which alpha will be made fully
            # transparent
            img.ConvertAlphaToMask(220)

            # convert back to a wx.Bitmap
            bmp = img.ConvertToBitmap()

            
        dc.DrawBitmap(bmp, 25,100, True)

        dc.SetFont(self.GetFont())
        y = 75
        for line in range(10):
            y += dc.GetCharHeight() + 5
            dc.DrawText(msg, 200, y)
        dc.DrawBitmap(bmp, 250,100, True)
Ejemplo n.º 9
0
 def OnButton1(self, evt):
     try:
         sound = wx.Sound(opj('data/anykey.wav'))
         self.log.write("before Play...\n")
         sound.Play(wx.SOUND_SYNC)
         self.log.write("...after Play\n")
     except NotImplementedError, v:
         wx.MessageBox(str(v), "Exception Message")
Ejemplo n.º 10
0
 def OnButton1(self, evt):
     try:
         sound = wx.adv.Sound(opj('data/anykey.wav'))
         self.log.write("before Play...\n")
         sound.Play(wx.adv.SOUND_SYNC)
         self.log.write("...after Play\n")
     except NotImplementedError as v:
         wx.MessageBox(str(v), "Exception Message")
Ejemplo n.º 11
0
def runTest(frame, nb, log):
    bmp = wx.Image(opj('bitmaps/image.bmp'), wx.BITMAP_TYPE_BMP).ConvertToBitmap()
    gif = wx.Image(opj('bitmaps/image.gif'), wx.BITMAP_TYPE_GIF).ConvertToBitmap()
    png = wx.Image(opj('bitmaps/image.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap()
    jpg = wx.Image(opj('bitmaps/image.jpg'), wx.BITMAP_TYPE_JPEG).ConvertToBitmap()

    panel = wx.Panel(nb, -1)

    pos = 10
    wx.StaticBitmap(panel, -1, bmp, (10, pos), (bmp.GetWidth(), bmp.GetHeight()))

    pos = pos + bmp.GetHeight() + 10
    wx.StaticBitmap(panel, -1, gif, (10, pos), (gif.GetWidth(), gif.GetHeight()))

    pos = pos + gif.GetHeight() + 10
    wx.StaticBitmap(panel, -1, png, (10, pos), (png.GetWidth(), png.GetHeight()))

    pos = pos + png.GetHeight() + 10
    wx.StaticBitmap(panel, -1, jpg, (10, pos), (jpg.GetWidth(), jpg.GetHeight()))

    return panel
Ejemplo n.º 12
0
    def __init__(self, parent, log):
        self.log = log
        wx.Panel.__init__(self,
                          parent,
                          -1,
                          style=wx.TAB_TRAVERSAL | wx.CLIP_CHILDREN)

        # Create some controls
        try:
            self.mc = wx.media.MediaCtrl(self, style=wx.SIMPLE_BORDER)
        except NotImplementedError:
            self.Destroy()
            raise

        btn1 = wx.Button(self, -1, "Load File")
        self.Bind(wx.EVT_BUTTON, self.OnLoadFile, btn1)

        btn2 = wx.Button(self, -1, "Play")
        self.Bind(wx.EVT_BUTTON, self.OnPlay, btn2)

        btn3 = wx.Button(self, -1, "Pause")
        self.Bind(wx.EVT_BUTTON, self.OnPause, btn3)

        btn4 = wx.Button(self, -1, "Stop")
        self.Bind(wx.EVT_BUTTON, self.OnStop, btn4)

        slider = wx.Slider(self, -1, 0, 0, 0)
        self.slider = slider
        self.Bind(wx.EVT_SLIDER, self.OnSeek, slider)

        self.st_size = wx.StaticText(self, -1, size=(100, -1))
        self.st_len = wx.StaticText(self, -1, size=(100, -1))
        self.st_pos = wx.StaticText(self, -1, size=(100, -1))

        # setup the layout
        sizer = wx.GridBagSizer(5, 5)
        sizer.Add(self.mc, (1, 1), span=(5, 1))  #, flag=wx.EXPAND)
        sizer.Add(btn1, (1, 3))
        sizer.Add(btn2, (2, 3))
        sizer.Add(btn3, (3, 3))
        sizer.Add(btn4, (4, 3))
        sizer.Add(slider, (6, 1), flag=wx.EXPAND)
        sizer.Add(self.st_size, (1, 5))
        sizer.Add(self.st_len, (2, 5))
        sizer.Add(self.st_pos, (3, 5))
        self.SetSizer(sizer)

        self.DoLoadFile(opj("data/testmovie.mpg"))
        self.mc.Stop()

        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.OnTimer)
        self.timer.Start(100)
Ejemplo n.º 13
0
    def __init__(self, parent, log):
        self.log = log
        wx.Panel.__init__(self, parent, -1)
        sizer = wx.FlexGridSizer(cols=3, hgap=5, vgap=5)

        for name in GIFNames:
            # There are a few usage patterns for creating the control and the
            # animation object. They're more-or-less equivalent, but if you have
            # non-standard needs in your application then one pattern may make
            # more sense for you to use.
            if False:
                # If you need a separate animation object then you can have the
                # control create one for you.
                ctrl = AnimationCtrl(self)
                ani = ctrl.CreateAnimation()
                ani.LoadFile(opj(name))
                ctrl.SetAnimation(ani)
            elif False:
                # if you need to have the animation object before the control is
                # created, then you can do it like this:
                ani = AnimationCtrl.CreateCompatibleAnimation()
                ani.LoadFile(opj(name))
                ctrl = AnimationCtrl(self, -1, ani)
            else:
                # Or you can keep it simple and just have the control make and
                # use its own animation object internally.
                ctrl = AnimationCtrl(self)
                ctrl.LoadFile(opj(name))

            ctrl.SetBackgroundColour(self.GetBackgroundColour())
            ctrl.Play()
            sizer.Add(ctrl, 0, wx.ALL, 10)

        if UseNative and 'wxGTK' in wx.PlatformInfo:
            # See comment in updateBestSizes below
            wx.CallAfter(self.updateBestSizes)

        border = wx.BoxSizer()
        border.Add(sizer, 1, wx.EXPAND | wx.ALL, 20)
        self.SetSizer(border)
Ejemplo n.º 14
0
    def __init__(self, parent, log):
        self.log = log
        wx.Panel.__init__(self, parent, -1,
                          style=wx.TAB_TRAVERSAL|wx.CLIP_CHILDREN)

        # Create some controls
        try:
            self.mc = wx.media.MediaCtrl(self, style=wx.SIMPLE_BORDER)
        except NotImplementedError:
            self.Destroy()
            raise

        btn1 = wx.Button(self, -1, "Load File")
        self.Bind(wx.EVT_BUTTON, self.OnLoadFile, btn1)
        
        btn2 = wx.Button(self, -1, "Play")
        self.Bind(wx.EVT_BUTTON, self.OnPlay, btn2)
        
        btn3 = wx.Button(self, -1, "Pause")
        self.Bind(wx.EVT_BUTTON, self.OnPause, btn3)
        
        btn4 = wx.Button(self, -1, "Stop")
        self.Bind(wx.EVT_BUTTON, self.OnStop, btn4)

        slider = wx.Slider(self, -1, 0, 0, 0)
        self.slider = slider
        self.Bind(wx.EVT_SLIDER, self.OnSeek, slider)

        self.st_size = wx.StaticText(self, -1, size=(100,-1))
        self.st_len  = wx.StaticText(self, -1, size=(100,-1))
        self.st_pos  = wx.StaticText(self, -1, size=(100,-1))
        
        
        # setup the layout
        sizer = wx.GridBagSizer(5,5)
        sizer.Add(self.mc, (1,1), span=(5,1))#, flag=wx.EXPAND)
        sizer.Add(btn1, (1,3))
        sizer.Add(btn2, (2,3))
        sizer.Add(btn3, (3,3))
        sizer.Add(btn4, (4,3))
        sizer.Add(slider, (6,1), flag=wx.EXPAND)
        sizer.Add(self.st_size, (1, 5))
        sizer.Add(self.st_len,  (2, 5))
        sizer.Add(self.st_pos,  (3, 5))
        self.SetSizer(sizer)

        self.DoLoadFile(opj("data/testmovie.mpg"))
        self.mc.Stop()

        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.OnTimer)
        self.timer.Start(100)
Ejemplo n.º 15
0
    def __init__(self, parent, log):
        wx.Panel.__init__(self, parent, -1)

        data = open(opj('bitmaps/image.png'), "rb").read()
        stream = BytesIO(data)

        bmp = wx.Bitmap(wx.Image(stream))

        wx.StaticText(self, -1,
                      "This image was loaded from a Python file-like object:",
                      (15, 15))

        wx.StaticBitmap(self, -1, bmp,
                        (15, 45))  #, (bmp.GetWidth(), bmp.GetHeight()))
Ejemplo n.º 16
0
    def __init__(self, parent, log):
        self.log = log
        wx.Panel.__init__(self, parent, -1)

        sizer = wx.FlexGridSizer(2,3,5,5)
        for name in GIFNames:
            ani = GIFAnimationCtrl(self, -1, opj(name))
            ani.GetPlayer().UseBackgroundColour(True)
            ani.Play()
            sizer.Add(ani, 0, wx.ALL, 10)

        border = wx.BoxSizer()
        border.Add(sizer, 1, wx.EXPAND|wx.ALL, 20)
        self.SetSizer(border)
Ejemplo n.º 17
0
    def __init__(self, parent, log):
        self.log = log
        wx.Panel.__init__(self, parent, -1)

        sizer = wx.FlexGridSizer(cols=3, hgap=5, vgap=5)
        for name in GIFNames:
            ani = GIFAnimationCtrl(self, -1, opj(name))
            ani.GetPlayer().UseBackgroundColour(True)
            ani.Play()
            sizer.Add(ani, 0, wx.ALL, 10)

        border = wx.BoxSizer()
        border.Add(sizer, 1, wx.EXPAND | wx.ALL, 20)
        self.SetSizer(border)
Ejemplo n.º 18
0
    def __init__(self, parent, log):
        wx.Panel.__init__(self, parent, -1)

        data = open(opj('bitmaps/image.png'), "rb").read()
        stream = cStringIO.StringIO(data)

        bmp = wx.BitmapFromImage( wx.ImageFromStream( stream ))

        wx.StaticText(
            self, -1, "This image was loaded from a Python file-like object:", 
            (15, 15)
            )

        wx.StaticBitmap(self, -1, bmp, (15, 45))#, (bmp.GetWidth(), bmp.GetHeight()))
Ejemplo n.º 19
0
    def __init__(self, parent, log):
        self.log = log
        wx.Panel.__init__(self, parent, -1)

        sizer = wx.FlexGridSizer(2,3,5,5)
        for name in GIFNames:
            ani = wx.animate.Animation(opj(name))
            ctrl = wx.animate.AnimationCtrl(self, -1, ani)
            ctrl.SetUseWindowBackgroundColour()
            ctrl.Play()
            sizer.Add(ctrl, 0, wx.ALL, 10)

        border = wx.BoxSizer()
        border.Add(sizer, 1, wx.EXPAND|wx.ALL, 20)
        self.SetSizer(border)
Ejemplo n.º 20
0
    def __init__(self, parent, log):
        self.log = log
        wx.Panel.__init__(self, parent, -1)

        sizer = wx.FlexGridSizer(2, 3, 5, 5)
        for name in GIFNames:
            ani = wx.animate.Animation(opj(name))
            ctrl = wx.animate.AnimationCtrl(self, -1, ani)
            ctrl.SetUseWindowBackgroundColour()
            ctrl.Play()
            sizer.AddF(ctrl, wx.SizerFlags().Border(wx.ALL, 10))

        border = wx.BoxSizer()
        border.AddF(sizer, wx.SizerFlags(1).Expand().Border(wx.ALL, 20))
        self.SetSizer(border)
Ejemplo n.º 21
0
    def __init__(self, parent, log):
        self.log = log
        wx.Panel.__init__(self, parent, -1)

        sizer = wx.FlexGridSizer(cols=3, hgap=5, vgap=5)
        for name in GIFNames:
            ani = wx.animate.Animation(opj(name))
            ctrl = wx.animate.AnimationCtrl(self, -1, ani)
            ctrl.SetUseWindowBackgroundColour()
            ctrl.Play()
            sizer.AddF(ctrl, wx.SizerFlags().Border(wx.ALL, 10))

        border = wx.BoxSizer()
        border.AddF(sizer, wx.SizerFlags(1).Expand().Border(wx.ALL, 20))
        self.SetSizer(border)
Ejemplo n.º 22
0
    def __init__(self, parent, log):
        self.log = log
        wx.Panel.__init__(self, parent, -1)

        sizer = wx.FlexGridSizer(cols=3, hgap=5, vgap=5)
        for name in GIFNames:
            ani = Animation(opj(name))
            ctrl = AnimationCtrl(self, -1, ani)
            ctrl.SetBackgroundColour(self.GetBackgroundColour())
            ctrl.Play()
            sizer.Add(ctrl, 0, wx.ALL, 10)

        border = wx.BoxSizer()
        border.Add(sizer, 1, wx.EXPAND | wx.ALL, 20)
        self.SetSizer(border)
Ejemplo n.º 23
0
    def __init__(self, parent, log):
        self.log = log
        wx.Panel.__init__(self, parent, -1)

        sizer = wx.FlexGridSizer(2, 3, 5, 5)
        for name in GIFNames:
            ani = wx.animate.Animation(opj(name))
            ctrl = wx.animate.AnimationCtrl(self, -1, ani)
            ctrl.SetUseWindowBackgroundColour()
            ctrl.Play()
            sizer.Add(ctrl, 0, wx.ALL, 10)

        border = wx.BoxSizer()
        border.Add(sizer, 1, wx.EXPAND | wx.ALL, 20)
        self.SetSizer(border)
Ejemplo n.º 24
0
    def __init__(self, parent, log):
        self.log = log
        wx.Panel.__init__(self, parent, -1)

        sizer = wx.FlexGridSizer(cols=3, hgap=5, vgap=5)
        for name in GIFNames:
            ani = Animation(opj(name))
            ctrl = AnimationCtrl(self, -1, ani)
            ctrl.SetBackgroundColour(self.GetBackgroundColour())
            ctrl.Play()
            sizer.Add(ctrl, 0, wx.ALL, 10)

        border = wx.BoxSizer()
        border.Add(sizer, 1, wx.EXPAND | wx.ALL, 20)
        self.SetSizer(border)
Ejemplo n.º 25
0
    def __init__(self, parent, log):
        self.choices = []
        self.choices = exampleStrings

        self._init_ctrls(parent)

        self.log = log

        lang = wx.LANGUAGE_DEFAULT
        filter = 'demo'
        langs = (wx.LANGUAGE_AFRIKAANS, wx.LANGUAGE_ENGLISH,
                 wx.LANGUAGE_DEFAULT, wx.LANGUAGE_SPANISH, wx.LANGUAGE_GERMAN,
                 wx.LANGUAGE_ITALIAN, wx.LANGUAGE_FRENCH)

        # usually you would define wx.Locale in your wx.App.OnInit class.
        # for the demo we just define it in this module
        self.locale = None
        wx.Locale.AddCatalogLookupPathPrefix(opj('data/locale'))
        self.updateLanguage(wx.LANGUAGE_DEFAULT)

        self.filterMap = {
            'demo': langlistctrl.LC_ONLY,
            'available': langlistctrl.LC_AVAILABLE,
            'all': langlistctrl.LC_ALL
        }

        self.filterIdxMap = {0: 'demo', 1: 'available', 2: 'all'}
        self.langs = langs
        self.langCtrl = langlistctrl.LanguageListCtrl(
            self.langCtrlContainer,
            -1,
            filter=self.filterMap[filter],
            only=langs,
            select=lang)

        self.langCtrl.Bind(wx.EVT_LIST_ITEM_SELECTED,
                           self.OnLangSelectAndTranslate)
        self.langCtrl.Bind(wx.EVT_LIST_ITEM_DESELECTED,
                           self.OnClearTranslatedText)

        self.OnLangCtrlContainerSize()

        self.englishBaseCh.Select(0)
        self.OnLangSelectAndTranslate()
Ejemplo n.º 26
0
    def OnButton(self, evt):
        png = wx.Image(opj('testimage.png'),
                       wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        pos = 10
        wx.StaticBitmap(self, -1, png, (10, pos),
                        (png.GetWidth(), png.GetHeight()))

        dstImage = wx.ImageFromBitmap(png)

        emptyImage = wx.EmptyImage(png.GetWidth(), png.GetHeight())
        defaultRed = 138
        defaultGreen = 102
        defaultBlue = 110
        defaultRed1 = 183
        defaultGreen2 = 171
        defaultBlue3 = 173
        rcr = rcolor.randomColor()
        randomRed, randomGreen, randomBlue = rcr.getRandomColor()
        randomRed1, randomGreen1, randomBlue1 = rcr.getRandomColor()
        indexColor = 0
        for x in xrange(png.GetWidth()):
            for y in xrange(png.GetHeight()):
                if defaultRed == dstImage.GetRed(
                        x, y) and defaultGreen == dstImage.GetGreen(
                            x, y) and defaultBlue == dstImage.GetBlue(x, y):
                    emptyImage.SetRGB(x, y, randomRed, randomGreen, randomBlue)
                elif defaultRed1 == dstImage.GetRed(
                        x, y) and defaultGreen2 == dstImage.GetGreen(
                            x, y) and defaultBlue3 == dstImage.GetBlue(x, y):
                    emptyImage.SetRGB(x, y, randomRed1, randomGreen1,
                                      randomBlue1)
                else:
                    emptyImage.SetRGB(x, y, dstImage.GetRed(x, y),
                                      dstImage.GetGreen(x, y),
                                      dstImage.GetBlue(x, y))
                indexColor = indexColor + 1

        pos = pos + png.GetHeight() + 10
        self.tempImage = emptyImage.ConvertToBitmap()
        wx.StaticBitmap(
            self, -1, self.tempImage, (10, pos),
            (self.tempImage.GetWidth(), self.tempImage.GetHeight()))
Ejemplo n.º 27
0
def runTest(frame, nb, log):
    bmp = wx.Image(opj('bitmaps/image.bmp'),
                   wx.BITMAP_TYPE_BMP).ConvertToBitmap()
    gif = wx.Image(opj('bitmaps/image.gif'),
                   wx.BITMAP_TYPE_GIF).ConvertToBitmap()
    png = wx.Image(opj('bitmaps/image.png'),
                   wx.BITMAP_TYPE_PNG).ConvertToBitmap()
    jpg = wx.Image(opj('bitmaps/image.jpg'),
                   wx.BITMAP_TYPE_JPEG).ConvertToBitmap()

    panel = wx.Panel(nb, -1)

    pos = 10
    wx.StaticBitmap(panel, -1, bmp, (10, pos))

    pos = pos + bmp.GetHeight() + 10
    wx.StaticBitmap(panel, -1, gif, (10, pos))

    pos = pos + gif.GetHeight() + 10
    wx.StaticBitmap(panel, -1, png, (10, pos))

    pos = pos + png.GetHeight() + 10
    wx.StaticBitmap(panel, -1, jpg, (10, pos))

    greyscale = wx.Image(
        opj('bitmaps/image.png'),
        wx.BITMAP_TYPE_PNG).ConvertToGreyscale().ConvertToBitmap()
    disabled = wx.Image(
        opj('bitmaps/image.png'),
        wx.BITMAP_TYPE_PNG).ConvertToDisabled().ConvertToBitmap()
    mono = wx.Image(opj('bitmaps/image.png'),
                    wx.BITMAP_TYPE_PNG).ConvertToMono(0, 255,
                                                      255).ConvertToBitmap()

    pos = 10
    wx.StaticBitmap(panel, -1, greyscale, (320, pos))

    pos = pos + greyscale.GetHeight() + 10
    wx.StaticBitmap(panel, -1, disabled, (320, pos))

    pos = pos + disabled.GetHeight() + 10
    wx.StaticBitmap(panel, -1, mono, (320, pos))

    return panel
Ejemplo n.º 28
0
    def __init__(self, parent, log):
        self.choices = []
        self.choices = exampleStrings
        
        self._init_ctrls(parent)

        self.log = log

        lang = wx.LANGUAGE_DEFAULT
        filter = 'demo'
        langs = (wx.LANGUAGE_AFRIKAANS, wx.LANGUAGE_ENGLISH, wx.LANGUAGE_DEFAULT, 
                 wx.LANGUAGE_SPANISH, wx.LANGUAGE_GERMAN, wx.LANGUAGE_ITALIAN,
                 wx.LANGUAGE_FRENCH)


        # usually you would define wx.Locale in your wx.App.OnInit class.
        # for the demo we just define it in this module
        self.locale = None
        wx.Locale.AddCatalogLookupPathPrefix(opj('data/locale'))
        self.updateLanguage(wx.LANGUAGE_DEFAULT)

        
        self.filterMap = {'demo': langlistctrl.LC_ONLY, 
                          'available': langlistctrl.LC_AVAILABLE, 
                          'all': langlistctrl.LC_ALL}
                        
        self.filterIdxMap = {0: 'demo', 
                             1: 'available', 
                             2: 'all'}
        self.langs = langs
        self.langCtrl = langlistctrl.LanguageListCtrl(self.langCtrlContainer, -1, 
              filter=self.filterMap[filter], only=langs, select=lang)
        
        self.langCtrl.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnLangSelectAndTranslate)
        self.langCtrl.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnClearTranslatedText)
              
        self.OnLangCtrlContainerSize()
        
        self.englishBaseCh.Select(0)
        self.OnLangSelectAndTranslate()
Ejemplo n.º 29
0
def runTest(frame, nb, log):
    bmp = wx.Image(opj('bitmaps/image.bmp'), wx.BITMAP_TYPE_BMP).ConvertToBitmap()
    gif = wx.Image(opj('bitmaps/image.gif'), wx.BITMAP_TYPE_GIF).ConvertToBitmap()
    png = wx.Image(opj('bitmaps/image.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap()
    jpg = wx.Image(opj('bitmaps/image.jpg'), wx.BITMAP_TYPE_JPEG).ConvertToBitmap()

    panel = wx.Panel(nb, -1)

    pos = 10
    wx.StaticBitmap(panel, -1, bmp, (10, pos))

    pos = pos + bmp.GetHeight() + 10
    wx.StaticBitmap(panel, -1, gif, (10, pos))

    pos = pos + gif.GetHeight() + 10
    wx.StaticBitmap(panel, -1, png, (10, pos))

    pos = pos + png.GetHeight() + 10
    wx.StaticBitmap(panel, -1, jpg, (10, pos))


    greyscale = wx.Image(opj('bitmaps/image.png'), wx.BITMAP_TYPE_PNG).ConvertToGreyscale().ConvertToBitmap()
    disabled = wx.Image(opj('bitmaps/image.png'), wx.BITMAP_TYPE_PNG).ConvertToDisabled().ConvertToBitmap()
    mono = wx.Image(opj('bitmaps/image.png'), wx.BITMAP_TYPE_PNG).ConvertToMono(0,255,255).ConvertToBitmap()
    
    pos = 10
    wx.StaticBitmap(panel, -1, greyscale, (320, pos))
    
    pos = pos + greyscale.GetHeight() + 10
    wx.StaticBitmap(panel, -1, disabled, (320, pos))

    pos = pos + disabled.GetHeight() + 10
    wx.StaticBitmap(panel, -1, mono, (320, pos))


    return panel
Ejemplo n.º 30
0
 def getImg(self):
     # Start with a fresh copy of the image to mod.
     path = opj(self.filebutton.GetPath())
     type = self.imgType
     return wx.Image(path, type)
Ejemplo n.º 31
0
    def Draw(self, gc):
        font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
        font.SetWeight(wx.FONTWEIGHT_BOLD)
        gc.SetFont(font, wx.BLACK)

        # make a path that contains a circle and some lines, centered at 0,0
        path = gc.CreatePath()
        path.AddCircle(0, 0, BASE2)
        path.MoveToPoint(0, -BASE2)
        path.AddLineToPoint(0, BASE2)
        path.MoveToPoint(-BASE2, 0)
        path.AddLineToPoint(BASE2, 0)
        path.CloseSubpath()
        path.AddRectangle(-BASE4, -BASE4/2, BASE2, BASE4)


        # Now use that path to demonstrate various capbilites of the grpahics context
        gc.PushState()             # save current translation/scale/other state
        gc.Translate(60, 75)       # reposition the context origin

        gc.SetPen(wx.Pen("navy", 1))
        gc.SetBrush(wx.Brush("pink"))

        # show the difference between stroking, filling and drawing
        for label, PathFunc in [("StrokePath", gc.StrokePath),
                                ("FillPath",   gc.FillPath),
                                ("DrawPath",   gc.DrawPath)]:
            w, h = gc.GetTextExtent(label)

            gc.DrawText(label, -w/2, -BASE2-h-4)
            PathFunc(path)
            gc.Translate(2*BASE, 0)


        gc.PopState()              # restore saved state
        gc.PushState()             # save it again
        gc.Translate(60, 200)      # offset to the lower part of the window

        gc.DrawText("Scale", 0, -BASE2)
        gc.Translate(0, 20)

        # for testing clipping
        #gc.Clip(0, 0, 100, 100)
        #rgn = wx.RegionFromPoints([ (0,0), (75,0), (75,25,), (100, 25),
        #                            (100,100), (0,100), (0,0)  ])
        #gc.ClipRegion(rgn)
        #gc.ResetClip()

        gc.SetBrush(wx.Brush(wx.Colour(178,  34,  34, 128)))   # 128 == half transparent
        for cnt in range(8):
            gc.Scale(1.08, 1.08)    # increase scale by 8%
            gc.Translate(5,5)
            gc.DrawPath(path)


        gc.PopState()              # restore saved state
        gc.PushState()             # save it again
        gc.Translate(400, 200)
        gc.DrawText("Rotate", 0, -BASE2)

        # Move the origin over to the next location
        gc.Translate(0, 75)

        # draw our path again, rotating it about the central point,
        # and changing colors as we go
        for angle in range(0, 360, 30):
            gc.PushState()         # save this new current state so we can
                                   # pop back to it at the end of the loop
            r, g, b = [int(c * 255) for c in colorsys.hsv_to_rgb(float(angle)/360, 1, 1)]
            gc.SetBrush(wx.Brush(wx.Colour(r, g, b, 64)))
            gc.SetPen(wx.Pen(wx.Colour(r, g, b, 128)))

            # use translate to artfully reposition each drawn path
            gc.Translate(1.5 * BASE2 * cos(radians(angle)),
                         1.5 * BASE2 * sin(radians(angle)))

            # use Rotate to rotate the path
            gc.Rotate(radians(angle))

            # now draw it
            gc.DrawPath(path)
            gc.PopState()

        # Draw a bitmap with an alpha channel on top of the last group
        bmp = wx.Bitmap(opj('bitmaps/toucan.png'))
        bsz = bmp.GetSize()
        gc.DrawBitmap(bmp,
                      #-bsz.width,
                      #-bsz.height/2,

                      -bsz.width/2.5,
                      -bsz.height/2.5,

                      bsz.width, bsz.height)


        gc.PopState()
Ejemplo n.º 32
0
 def OnWithWidgets(self, event):
     os.chdir(self.cwd)
     name = os.path.join(self.cwd, opj('data/widgetTest.htm'))
     self.html.LoadPage(name)
Ejemplo n.º 33
0
 def OnWithWidgets(self, event):
     name = os.path.join(self.cwd, opj('data/widgetTest.htm'))
     self.html.LoadPage(name)
Ejemplo n.º 34
0
    def Render(self, dc):
        # Draw some stuff on the plain dc
        sz = self.GetSize()
        dc.SetPen(wx.Pen("navy", 1))
        x = y = 0
        while x < sz.width * 2 or y < sz.height * 2:
            x += 20
            y += 20
            dc.DrawLine(x, 0, 0, y)
        
        # now draw something with cairo
        ctx = wx.lib.wxcairo.ContextFromDC(dc)
        ctx.set_line_width(15)
        ctx.move_to(125, 25)
        ctx.line_to(225, 225)
        ctx.rel_line_to(-200, 0)
        ctx.close_path()
        ctx.set_source_rgba(0, 0, 0.5, 1)
        ctx.stroke()

        # and something else...
        ctx.arc(200, 200, 80, 0, math.pi*2)
        ctx.set_source_rgba(0, 1, 1, 0.5)
        ctx.fill_preserve()
        ctx.set_source_rgb(1, 0.5, 0)
        ctx.stroke()

        # here's a gradient pattern
        ptn = cairo.RadialGradient(315, 70, 25,
                                   302, 70, 128)
        ptn.add_color_stop_rgba(0, 1,1,1,1)
        ptn.add_color_stop_rgba(1, 0,0,0,1)
        ctx.set_source(ptn)
        ctx.arc(328, 96, 75, 0, math.pi*2)
        ctx.fill()

        # Draw some text
        face = wx.lib.wxcairo.FontFaceFromFont(
            wx.FFont(10, wx.SWISS, wx.FONTFLAG_BOLD))
        ctx.set_font_face(face)
        ctx.set_font_size(60)
        ctx.move_to(360, 180)
        ctx.set_source_rgb(0, 0, 0)
        ctx.show_text("Hello")

        # Text as a path, with fill and stroke
        ctx.move_to(400, 220)
        ctx.text_path("World")
        ctx.set_source_rgb(0.39, 0.07, 0.78)
        ctx.fill_preserve()
        ctx.set_source_rgb(0,0,0)
        ctx.set_line_width(2)
        ctx.stroke()

        # Show iterating and modifying a (text) path
        ctx.new_path()
        ctx.move_to(0, 0)
        ctx.set_source_rgb(0.3, 0.3, 0.3)
        ctx.set_font_size(30)
        text = "This path was warped..."
        ctx.text_path(text)
        tw, th = ctx.text_extents(text)[2:4]
        self.warpPath(ctx, tw, th, 360,300)
        ctx.fill()

        # Drawing a bitmap.  Note that we can easily load a PNG file
        # into a surface, but I wanted to show how to convert from a
        # wx.Bitmap here instead.
        #img = cairo.ImageSurface.create_from_png(opj('bitmaps/toucan.png'))
        bmp = wx.Bitmap(opj('bitmaps/toucan.png'))
        img = wx.lib.wxcairo.ImageSurfaceFromBitmap(bmp)
        ctx.set_source_surface(img, 70, 230)
        ctx.paint()
Ejemplo n.º 35
0
    def __init__(self, parent, id=wx.ID_ANY):
        scrolled.ScrolledPanel.__init__(self, parent, id)
        # self.log = log
        # self.SetDoubleBuffered(True)

        hdrFont = wx.Font(18, wx.FONTFAMILY_DEFAULT,
                              wx.FONTSTYLE_NORMAL,
                              wx.FONTWEIGHT_BOLD)

        StatText1 = wx.StaticText(self, wx.ID_ANY, 'wx.Image',)
        StatText1.SetFont(wx.Font(wx.FontInfo(24).Bold()))

        StatText2 = wx.StaticText(self, wx.ID_ANY, 'Supported Bitmap Types')
        StatText2.SetFont(hdrFont)

        vsizer0 = wx.BoxSizer(wx.VERTICAL)
        vsizer0.Add(StatText1, 0, wx.ALL|wx.ALIGN_CENTER, 10)
        vsizer0.Add(wx.StaticText(self, wx.ID_ANY, description),
                    0, wx.LEFT|wx.BOTTOM, 10)
        vsizer0.Add(StatText2, 0, wx.ALL, 10)

        fgsizer1 = wx.FlexGridSizer(cols=2, vgap=10, hgap=10)
        fgsizer1.AddGrowableCol(0)
        bmp = wx.Image(opj('bitmaps/image.bmp'), wx.BITMAP_TYPE_BMP)
        gif = wx.Image(opj('bitmaps/image.gif'), wx.BITMAP_TYPE_GIF)
        png = wx.Image(opj('bitmaps/image.png'), wx.BITMAP_TYPE_PNG)
        jpg = wx.Image(opj('bitmaps/image.jpg'), wx.BITMAP_TYPE_JPEG)
        ico = wx.Image(opj('bitmaps/image.ico'), wx.BITMAP_TYPE_ICO)
        tif = wx.Image(opj('bitmaps/image.tif'), wx.BITMAP_TYPE_TIF)
        dict = OrderedDict([
            (bmp, 'bmp\n*.bmp;*rle;*dib'),
            (gif, 'gif\n*.gif'),
            (png, 'png\n*.png'),
            (jpg, 'jpg\n*.jpg;*.jpeg;*.jpe'),
            (ico, 'ico\n*.ico'),
            (tif, 'tif\n*.tif;*.tiff'),
            ])
        for bmpType, tip in list(dict.items()):
            statBmp = wx.StaticBitmap(self, wx.ID_ANY, bmpType.ConvertToBitmap())
            type = bmpType.GetType()
            if type in supportedBitmapTypes:
                typeStr = 'wx.' + supportedBitmapTypes[type][:supportedBitmapTypes[type].find(':')]
            statText = wx.StaticText(self, -1, typeStr)
            fgsizer1.Add(statText)
            fgsizer1.Add(statBmp)

        vsizer0.Add(fgsizer1, 0, wx.LEFT, 25)
        vsizer0.AddSpacer(35)

        StatText3 = wx.StaticText(self, wx.ID_ANY, 'Basic Image Manipulation Operations')
        StatText3.SetFont(hdrFont)
        vsizer0.Add(StatText3, 0, wx.LEFT|wx.BOTTOM, 10)


        self.imgPath = 'bitmaps/image.png'
        self.imgType = wx.BITMAP_TYPE_ANY
        self.fgsizer2 = fgsizer2 = wx.FlexGridSizer(cols=2, vgap=10, hgap=10)
        fgsizer2.AddGrowableCol(0)

        self.colorbutton = wx.ColourPickerCtrl(self, wx.ID_ANY,
                                               size=(175, -1),
                                               style=wx.CLRP_USE_TEXTCTRL)
        self.colorbutton.Bind(wx.EVT_COLOURPICKER_CHANGED, self.ChangePanelColor)
        vsizer1 = wx.BoxSizer(wx.VERTICAL)
        vsizer1.Add(wx.StaticText(self, -1, "Panel colour:"))
        vsizer1.Add(self.colorbutton, 0, wx.LEFT, 15)
        fgsizer2.Add(vsizer1)


        self.SetBackgroundColour(self.defBackgroundColour)
        self.colorbutton.SetColour(self.defBackgroundColour)
        self.colorbutton.SetToolTip('Change Panel Color')

        self.filebutton = wx.FilePickerCtrl(self, wx.ID_ANY,
                                            path=os.path.abspath(opj(self.imgPath)),
                                            message='',
                                            wildcard=wx.Image.GetImageExtWildcard(),
                                            style=wx.FLP_OPEN
                                                | wx.FLP_FILE_MUST_EXIST
                                                | wx.FLP_USE_TEXTCTRL
                                                | wx.FLP_CHANGE_DIR
                                                # | wx.FLP_SMALL
                                                )
        self.filebutton.SetToolTip('Browse for a image to preview modifications')
        self.filebutton.Bind(wx.EVT_FILEPICKER_CHANGED, self.ChangeModdedImages)
        vsizer2 = wx.BoxSizer(wx.VERTICAL)
        vsizer2.Add(wx.StaticText(self, -1, "Load test image:"))
        vsizer2.Add(self.filebutton, 0, wx.EXPAND|wx.LEFT, 15)
        fgsizer2.Add(vsizer2, 0, wx.EXPAND)

        fgsizer2.AddSpacer(10)
        fgsizer2.AddSpacer(10)

        def getImg():
            # Start with a fresh copy of the image to mod.
            path = opj(self.imgPath)
            type = self.imgType
            return wx.Image(path, type)

        self.allModdedStatBmps = []
        self.img = getImg()
        self.imgWidth = getImg().GetWidth()
        self.imgHeight = getImg().GetHeight()
        self.imgCenterPt = wx.Point(self.imgWidth//2, self.imgHeight//2)

        imgBmp = wx.StaticBitmap(self, wx.ID_ANY, self.img.ConvertToBitmap())
        fgsizer2.Add(wx.StaticText(self, -1, "Original test image:"))
        fgsizer2.Add(imgBmp)
        self.allModdedStatBmps.append(imgBmp)

        self.DoImageMods()

        dict = OrderedDict([
            (self.greyscale  , 'img.ConvertToGreyscale()'),
            (self.disabled   , 'img.ConvertToDisabled()'),
            (self.mono       , 'img.ConvertToMono(r=255, g=255, b=255)'),
            (self.mask       , 'img.SetMaskColour(\n\tred=255, green=255, blue=255)'),
            (self.blur       , 'img.Blur(blurRadius=3)'),
            (self.blurH      , 'img.BlurHorizontal(blurRadius=3)'),
            (self.blurV      , 'img.BlurVertical(blurRadius=3)'),
            (self.mirrorH    , 'img.Mirror(horizontally=True)'),
            (self.mirrorV    , 'img.Mirror(horizontally=False)'),
            (self.mirrorBoth , 'img.Mirror(horizontally=True).\n\tMirror(horizontally=False)'),
            (self.adjustChan , 'img.AdjustChannels(factor_red=2.0,\n\tfactor_green=1.0,\n\tfactor_blue=1.0,\n\tfactor_alpha=1.0)'),
            (self.rotate     , 'img.Rotate(angle=45.0,\n\trotationCentre=imgCenterPt,\n\tinterpolating=True,\n\toffsetAfterRotation=None)'),
            (self.rotate90   , 'img.Rotate90(clockwise=True)'),
            (self.rotate180  , 'img.Rotate180()'),
            (self.replace    , 'img.Replace(r1=0, g1=0, b1=0,\n\tr2=0, g2=255, b2=0)'),
            (self.scale      , 'img.Scale(width=128, height=32,\n\tquality=wx.IMAGE_QUALITY_NORMAL)'),
            (self.rescale    , 'img.Rescale(width=128, height=32,\n\tquality=wx.IMAGE_QUALITY_NORMAL)'),
            (self.resize     , 'img.Resize(size=(256 + 16, 64 + 8),\n\tpos=(0+8, 0+4),\n\tred=0, green=0, blue=255)'),
            (self.paste      , 'img.Paste(image=getImg(), x=16, y=16)'),
            (self.rotatehue  , 'img.RotateHue(0.5)'),
            ])

        for imgModification, tip in list(dict.items()):
            statBmp = wx.StaticBitmap(self, wx.ID_ANY,
                                      imgModification.ConvertToBitmap())
            self.allModdedStatBmps.append(statBmp)
            tip = tip.replace('\t', ' '*8)
            statText = wx.StaticText(self, -1, tip)
            fgsizer2.Add(statText) #, 0, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER, 5)
            fgsizer2.Add(statBmp)#, 0, wx.ALL, 5)

        vsizer0.Add(fgsizer2, 0, wx.LEFT, 25)
        self.SetSizer(vsizer0)
        self.SetupScrolling()
Ejemplo n.º 36
0
import wx
import wx.xrc as xrc

from Main import opj

#----------------------------------------------------------------------

RESFILE = opj("data/resource_wdr.xrc")


class TestPanel(wx.Panel):
    def __init__(self, parent, log):
        wx.Panel.__init__(self, parent, -1)
        self.log = log

        # make the components
        label = wx.StaticText(self, -1,
                              "The lower panel was built from this XML:")
        label.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))

        resourceText = open(RESFILE).read()
        text = wx.TextCtrl(self,
                           -1,
                           resourceText,
                           style=wx.TE_READONLY | wx.TE_MULTILINE)
        text.SetInsertionPoint(0)

        line = wx.StaticLine(self, -1)

        # This shows a few different ways to load XML Resources
        if 0:
Ejemplo n.º 37
0
 def OnListBoxSelect(self, evt):
     snippet_file = opj('snippets/%s.py' % evt.GetString())
     text = file(snippet_file).read()
     self.canvas.SetSnippet(text)
     self.editor.SetValue(text)
Ejemplo n.º 38
0
    def Render(self, dc):
        # Draw some stuff on the plain dc
        sz = self.GetSize()
        dc.SetPen(wx.Pen("navy", 1))
        x = y = 0
        while x < sz.width * 2 or y < sz.height * 2:
            x += 20
            y += 20
            dc.DrawLine(x, 0, 0, y)

        # now draw something with cairo
        ctx = wx.lib.wxcairo.ContextFromDC(dc)
        ctx.set_line_width(15)
        ctx.move_to(125, 25)
        ctx.line_to(225, 225)
        ctx.rel_line_to(-200, 0)
        ctx.close_path()
        ctx.set_source_rgba(0, 0, 0.5, 1)
        ctx.stroke()

        # and something else...
        ctx.arc(200, 200, 80, 0, math.pi * 2)
        ctx.set_source_rgba(0, 1, 1, 0.5)
        ctx.fill_preserve()
        ctx.set_source_rgb(1, 0.5, 0)
        ctx.stroke()

        # here's a gradient pattern
        ptn = cairo.RadialGradient(315, 70, 25, 302, 70, 128)
        ptn.add_color_stop_rgba(0, 1, 1, 1, 1)
        ptn.add_color_stop_rgba(1, 0, 0, 0, 1)
        ctx.set_source(ptn)
        ctx.arc(328, 96, 75, 0, math.pi * 2)
        ctx.fill()

        # Draw some text
        face = wx.lib.wxcairo.FontFaceFromFont(
            wx.FFont(10, wx.SWISS, wx.FONTFLAG_BOLD))
        ctx.set_font_face(face)
        ctx.set_font_size(60)
        ctx.move_to(360, 180)
        ctx.set_source_rgb(0, 0, 0)
        ctx.show_text("Hello")

        # Text as a path, with fill and stroke
        ctx.move_to(400, 220)
        ctx.text_path("World")
        ctx.set_source_rgb(0.39, 0.07, 0.78)
        ctx.fill_preserve()
        ctx.set_source_rgb(0, 0, 0)
        ctx.set_line_width(2)
        ctx.stroke()

        # Show iterating and modifying a (text) path
        ctx.new_path()
        ctx.move_to(0, 0)
        ctx.set_source_rgb(0.3, 0.3, 0.3)
        ctx.set_font_size(30)
        text = "This path was warped..."
        ctx.text_path(text)
        tw, th = ctx.text_extents(text)[2:4]
        self.warpPath(ctx, tw, th, 360, 300)
        ctx.fill()

        # Drawing a bitmap.  Note that we can easily load a PNG file
        # into a surface, but I wanted to show how to convert from a
        # wx.Bitmap here instead.  This is how to do it using just cairo:
        #img = cairo.ImageSurface.create_from_png(opj('bitmaps/toucan.png'))

        # And this is how to convert a wx.Btmap to a cairo image
        # surface.  NOTE: currently on Mac there appears to be a
        # problem using conversions of some types of images.  They
        # show up totally transparent when used. The conversion itself
        # appears to be working okay, because converting back to
        # wx.Bitmap or writing the image surface to a file produces
        # the expected result.  The other platforms are okay.
        bmp = wx.Bitmap(opj('bitmaps/toucan.png'))
        #bmp = wx.Bitmap(opj('bitmaps/splash.png'))
        img = wx.lib.wxcairo.ImageSurfaceFromBitmap(bmp)

        ctx.set_source_surface(img, 70, 230)
        ctx.paint()

        # this is how to convert an image surface to a wx.Bitmap
        bmp2 = wx.lib.wxcairo.BitmapFromImageSurface(img)
        dc.DrawBitmap(bmp2, 280, 300)
Ejemplo n.º 39
0
 def getImg():
     # Start with a fresh copy of the image to mod.
     path = opj(self.imgPath)
     type = self.imgType
     return wx.Image(path, type)
Ejemplo n.º 40
0
    def Render(self, dc):
        # Draw some stuff on the plain dc
        sz = self.GetSize()
        dc.SetPen(wx.Pen("navy", 1))
        x = y = 0
        while x < sz.width * 2 or y < sz.height * 2:
            x += 20
            y += 20
            dc.DrawLine(x, 0, 0, y)

        # now draw something with cairo
        ctx = wx.lib.wxcairo.ContextFromDC(dc)
        ctx.set_line_width(15)
        ctx.move_to(125, 25)
        ctx.line_to(225, 225)
        ctx.rel_line_to(-200, 0)
        ctx.close_path()
        ctx.set_source_rgba(0, 0, 0.5, 1)
        ctx.stroke()

        # and something else...
        ctx.arc(200, 200, 80, 0, math.pi*2)
        ctx.set_source_rgba(0, 1, 1, 0.5)
        ctx.fill_preserve()
        ctx.set_source_rgb(1, 0.5, 0)
        ctx.stroke()

        # here's a gradient pattern
        ptn = cairo.RadialGradient(315, 70, 25,
                                   302, 70, 128)
        ptn.add_color_stop_rgba(0, 1,1,1,1)
        ptn.add_color_stop_rgba(1, 0,0,0,1)
        ctx.set_source(ptn)
        ctx.arc(328, 96, 75, 0, math.pi*2)
        ctx.fill()

        # Draw some text
        face = wx.lib.wxcairo.FontFaceFromFont(
            wx.FFont(10, wx.FONTFAMILY_SWISS, wx.FONTFLAG_BOLD))
        ctx.set_font_face(face)
        ctx.set_font_size(60)
        ctx.move_to(360, 180)
        ctx.set_source_rgb(0, 0, 0)
        ctx.show_text("Hello")

        # Text as a path, with fill and stroke
        ctx.move_to(400, 220)
        ctx.text_path("World")
        ctx.set_source_rgb(0.39, 0.07, 0.78)
        ctx.fill_preserve()
        ctx.set_source_rgb(0,0,0)
        ctx.set_line_width(2)
        ctx.stroke()

        # Show iterating and modifying a (text) path
        ctx.new_path()
        ctx.move_to(0, 0)
        ctx.set_source_rgb(0.3, 0.3, 0.3)
        ctx.set_font_size(30)
        text = "This path was warped..."
        ctx.text_path(text)
        tw, th = ctx.text_extents(text)[2:4]
        self.warpPath(ctx, tw, th, 360,300)
        ctx.fill()

        # Drawing a bitmap.  Note that we can easily load a PNG file
        # into a surface, but I wanted to show how to convert from a
        # wx.Bitmap here instead.  This is how to do it using just cairo:
        #img = cairo.ImageSurface.create_from_png(opj('bitmaps/toucan.png'))

        # And this is how to convert a wx.Btmap to a cairo image
        # surface.  NOTE: currently on Mac there appears to be a
        # problem using conversions of some types of images.  They
        # show up totally transparent when used. The conversion itself
        # appears to be working okay, because converting back to
        # wx.Bitmap or writing the image surface to a file produces
        # the expected result.  The other platforms are okay.
        bmp = wx.Bitmap(opj('bitmaps/toucan.png'))
        #bmp = wx.Bitmap(opj('bitmaps/splash.png'))
        img = wx.lib.wxcairo.ImageSurfaceFromBitmap(bmp)

        ctx.set_source_surface(img, 70, 230)
        ctx.paint()

        # this is how to convert an image surface to a wx.Bitmap
        bmp2 = wx.lib.wxcairo.BitmapFromImageSurface(img)
        dc.DrawBitmap(bmp2, 280, 300)
Ejemplo n.º 41
0
 def getImg(self):
     # Start with a fresh copy of the image to mod.
     path = opj(self.filebutton.GetPath())
     type = self.imgType
     return wx.Image(path, type)
Ejemplo n.º 42
0
 def getImg():
     # Start with a fresh copy of the image to mod.
     path = opj(self.imgPath)
     type = self.imgType
     return wx.Image(path, type)
Ejemplo n.º 43
0
    def initialise(self):

        #title font
        self.font = wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.BOLD)

        #use of scroll bar window
        self.scroll = wx.ScrolledWindow(self, -1)
        self.scroll.SetScrollbars(1, 1, 1000, 1000)

        #setting up the sizer for use with scroll bar window
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.scroll.SetSizer(self.sizer)

        #the karstolution schematic diagram in the top-left
        png = wx.Image(opj('structure.png'),
                       wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        wx.StaticBitmap(self.scroll, -1, png, (10, 10),
                        (png.GetWidth(), png.GetHeight()))
        #the run button on the top-left, binded to self.OnButtonClick function
        button = wx.Button(self.scroll, -1, "Run Karstolution", (800, 60))
        self.Bind(
            wx.EVT_BUTTON,
            partial(self.OnButtonClick,
                    data=self.data,
                    output=self.output_file), button)
        # the rest of the GUI interface takes either from the basic or advanced view
        #which come from their independant modules
        self.basic_panel = Basic(self.scroll, self.data, self.name_config)
        self.advanced_panel = Advanced(self.scroll, self.data,
                                       self.name_config)
        #the basic view is hidden first but can be switched into
        self.basic_panel.Hide()
        #adding the two views into the sizer
        self.sizer.Add(self.basic_panel, 1, wx.EXPAND)
        self.sizer.Add(self.advanced_panel, 2, wx.EXPAND)

        #creating the status bar at the bottom
        self.CreateStatusBar()

        #creating menu at top
        filemenu = wx.Menu()
        menuBar = wx.MenuBar()
        #file is only option at this stage
        menuBar.Append(filemenu, "&File")
        self.SetMenuBar(menuBar)

        #switch between the Advanced and Basic view
        toggle = filemenu.Append(
            wx.ID_ANY, "Switch Basic/Advanced",
            """Switch between the default Basic view or the Advanced view 
        with all possible parameters""")
        #open box with information about Karstolution
        menuAbout = filemenu.Append(wx.ID_ABOUT, "&About",
                                    "Information about this program")
        #exit the program
        menuExit = filemenu.Append(wx.ID_EXIT, "&Exit",
                                   "Terminate the program")

        #binding the events (functions) to the menu items
        self.Bind(wx.EVT_MENU, self.OnAbout, menuAbout)
        self.Bind(wx.EVT_MENU, self.OnCheck, toggle)
        self.Bind(wx.EVT_MENU, self.OnExit, menuExit)

        #hidden features, that you need to expand the window to access
        #the Calculate Drip option (default=yes), allows you to over-ride the
        #drip-rate calculation (based on user-inputted min drip interval & store size)
        #and instead run the model just using the user-inputted values as the
        #absolute drip-rate (used for all time-steps of the model)
        self.cb = wx.CheckBox(self, -1, 'Calculate Drips ?', (1050, 270))
        self.cb.SetValue(True)
        self.Bind(wx.EVT_CHECKBOX, self.GetId, self.cb)

        #Allows the model to be run multiple times, iterating over a range
        #of parameter values.
        batch1 = wx.Button(self, -1, "Run Batch Mode", (1050, 225))
        self.Bind(wx.EVT_BUTTON, self.OnBatch, batch1)
        self.label = wx.StaticText(self, -1, 'Batch Mode: ', (1050, 10))
        self.label.SetFont(self.font)
        self.label = wx.StaticText(self, -1, 'Choose parameter to iterate: ',
                                   (1050, 40))
        lister = wx.ListBox(self, -1, (1050, 60), (180, 80),
                            [thing[0] for thing in self.list_options],
                            wx.LB_SINGLE)
        lister.SetSelection(0)
        self.Bind(wx.EVT_LISTBOX, self.OnChoose, lister)
        self.min_b = wx.StaticText(self, -1, 'Min Value: ', (1050, 150))
        self.min_batch = wx.TextCtrl(self, -1, str(self.batch_p[0]),
                                     (1130, 150))
        self.Bind(wx.EVT_TEXT, partial(self.assign, name=self.min_batch,
                                       id1=0), self.min_batch)
        self.max_b = wx.StaticText(self, -1, 'Max Value: ', (1050, 175))
        self.max_batch = wx.TextCtrl(self, -1, str(self.batch_p[1]),
                                     (1130, 175))
        self.Bind(wx.EVT_TEXT, partial(self.assign, name=self.max_batch,
                                       id1=1), self.max_batch)
        self.it_b = wx.StaticText(self, -1, '# Iterations: ', (1050, 200))
        self.it_batch = wx.TextCtrl(self, -1, str(self.batch_p[2]),
                                    (1130, 200))
        self.Bind(wx.EVT_TEXT, partial(self.assign, name=self.it_batch, id1=2),
                  self.it_batch)

        #telling wxpython the layout is all G
        self.sizer.Layout()
Ejemplo n.º 44
0
    def Render(self, dc):
        # Draw some stuff on the plain dc
        sz = self.GetSize()
        dc.SetPen(wx.Pen("navy", 1))
        x = y = 0
        while x < sz.width * 2 or y < sz.height * 2:
            x += 20
            y += 20
            dc.DrawLine(x, 0, 0, y)

        # now draw something with cairo
        ctx = wx.lib.wxcairo.ContextFromDC(dc)
        ctx.set_line_width(15)
        ctx.move_to(125, 25)
        ctx.line_to(225, 225)
        ctx.rel_line_to(-200, 0)
        ctx.close_path()
        ctx.set_source_rgba(0, 0, 0.5, 1)
        ctx.stroke()

        # and something else...
        ctx.arc(200, 200, 80, 0, math.pi * 2)
        ctx.set_source_rgba(0, 1, 1, 0.5)
        ctx.fill_preserve()
        ctx.set_source_rgb(1, 0.5, 0)
        ctx.stroke()

        # here's a gradient pattern
        ptn = cairo.RadialGradient(315, 70, 25, 302, 70, 128)
        ptn.add_color_stop_rgba(0, 1, 1, 1, 1)
        ptn.add_color_stop_rgba(1, 0, 0, 0, 1)
        ctx.set_source(ptn)
        ctx.arc(328, 96, 75, 0, math.pi * 2)
        ctx.fill()

        # Draw some text
        face = wx.lib.wxcairo.FontFaceFromFont(
            wx.FFont(10, wx.SWISS, wx.FONTFLAG_BOLD))
        ctx.set_font_face(face)
        ctx.set_font_size(60)
        ctx.move_to(360, 180)
        ctx.set_source_rgb(0, 0, 0)
        ctx.show_text("Hello")

        # Text as a path, with fill and stroke
        ctx.move_to(400, 220)
        ctx.text_path("World")
        ctx.set_source_rgb(0.39, 0.07, 0.78)
        ctx.fill_preserve()
        ctx.set_source_rgb(0, 0, 0)
        ctx.set_line_width(2)
        ctx.stroke()

        # Show iterating and modifying a (text) path
        ctx.new_path()
        ctx.move_to(0, 0)
        ctx.set_source_rgb(0.3, 0.3, 0.3)
        ctx.set_font_size(30)
        text = "This path was warped..."
        ctx.text_path(text)
        tw, th = ctx.text_extents(text)[2:4]
        self.warpPath(ctx, tw, th, 360, 300)
        ctx.fill()

        # Drawing a bitmap.  Note that we can easily load a PNG file
        # into a surface, but I wanted to show how to convert from a
        # wx.Bitmap here instead.
        #img = cairo.ImageSurface.create_from_png(opj('bitmaps/toucan.png'))
        bmp = wx.Bitmap(opj('bitmaps/toucan.png'))
        #bmp = wx.Bitmap(opj('bitmaps/splash.png'))
        #print 'depth:', bmp.GetDepth()
        #print 'alpha:', bmp.HasAlpha()
        img = wx.lib.wxcairo.ImageSurfaceFromBitmap(bmp)
        ctx.set_source_surface(img, 70, 230)
        ctx.paint()
Ejemplo n.º 45
0
    def Draw(self, gc):
        font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
        font.SetWeight(wx.BOLD)
        gc.SetFont(font, wx.BLACK)

        # make a path that contains a circle and some lines, centered at 0,0
        path = gc.CreatePath()
        path.AddCircle(0, 0, BASE2)
        path.MoveToPoint(0, -BASE2)
        path.AddLineToPoint(0, BASE2)
        path.MoveToPoint(-BASE2, 0)
        path.AddLineToPoint(BASE2, 0)
        path.CloseSubpath()
        path.AddRectangle(-BASE4, -BASE4 / 2, BASE2, BASE4)

        # Now use that path to demonstrate various capbilites of the grpahics context
        gc.PushState()  # save current translation/scale/other state
        gc.Translate(60, 75)  # reposition the context origin

        gc.SetPen(wx.Pen("navy", 1))
        gc.SetBrush(wx.Brush("pink"))

        # show the difference between stroking, filling and drawing
        for label, PathFunc in [("StrokePath", gc.StrokePath),
                                ("FillPath", gc.FillPath),
                                ("DrawPath", gc.DrawPath)]:
            w, h = gc.GetTextExtent(label)

            gc.DrawText(label, -w / 2, -BASE2 - h - 4)
            PathFunc(path)
            gc.Translate(2 * BASE, 0)

        gc.PopState()  # restore saved state
        gc.PushState()  # save it again
        gc.Translate(60, 200)  # offset to the lower part of the window

        gc.DrawText("Scale", 0, -BASE2)
        gc.Translate(0, 20)

        # for testing clipping
        #gc.Clip(0, 0, 100, 100)
        #rgn = wx.RegionFromPoints([ (0,0), (75,0), (75,25,), (100, 25),
        #                            (100,100), (0,100), (0,0)  ])
        #gc.ClipRegion(rgn)
        #gc.ResetClip()

        gc.SetBrush(wx.Brush(wx.Colour(178, 34, 34,
                                       128)))  # 128 == half transparent
        for cnt in range(8):
            gc.Scale(1.08, 1.08)  # increase scale by 8%
            gc.Translate(5, 5)
            gc.DrawPath(path)

        gc.PopState()  # restore saved state
        gc.PushState()  # save it again
        gc.Translate(400, 200)
        gc.DrawText("Rotate", 0, -BASE2)

        # Move the origin over to the next location
        gc.Translate(0, 75)

        # draw our path again, rotating it about the central point,
        # and changing colors as we go
        for angle in range(0, 360, 30):
            gc.PushState()  # save this new current state so we can
            # pop back to it at the end of the loop
            r, g, b = [
                int(c * 255)
                for c in colorsys.hsv_to_rgb(float(angle) / 360, 1, 1)
            ]
            gc.SetBrush(wx.Brush(wx.Colour(r, g, b, 64)))
            gc.SetPen(wx.Pen(wx.Colour(r, g, b, 128)))

            # use translate to artfully reposition each drawn path
            gc.Translate(1.5 * BASE2 * cos(radians(angle)),
                         1.5 * BASE2 * sin(radians(angle)))

            # use Rotate to rotate the path
            gc.Rotate(radians(angle))

            # now draw it
            gc.DrawPath(path)
            gc.PopState()

        # Draw a bitmap with an alpha channel on top of the last group
        bmp = wx.Bitmap(opj('bitmaps/toucan.png'))
        bsz = bmp.GetSize()
        gc.DrawBitmap(
            bmp,
            #-bsz.width,
            #-bsz.height/2,
            -bsz.width / 2.5,
            -bsz.height / 2.5,
            bsz.width,
            bsz.height)

        gc.PopState()
Ejemplo n.º 46
0
 def initialise(self):
     
     #title font
     self.font = wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.BOLD)
            
     #use of scroll bar window
     self.scroll = wx.ScrolledWindow(self, -1)
     self.scroll.SetScrollbars(1,1,1000,1000)
     
     #setting up the sizer for use with scroll bar window 
     self.sizer = wx.BoxSizer(wx.VERTICAL)
     self.scroll.SetSizer(self.sizer)
     
     #the karstolution schematic diagram in the top-left
     png = wx.Image(opj('structure.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap()
     wx.StaticBitmap(self.scroll, -1, png, (10, 10), (png.GetWidth(), png.GetHeight())) 
     #the run button on the top-left, binded to self.OnButtonClick function
     button=wx.Button(self.scroll,-1,"Run Karstolution",(800,60))
     self.Bind(wx.EVT_BUTTON,partial( self.OnButtonClick,data=self.data,output=self.output_file),button)
     # the rest of the GUI interface takes either from the basic or advanced view
     #which come from their independant modules
     self.basic_panel=Basic(self.scroll,self.data,self.name_config)
     self.advanced_panel=Advanced(self.scroll,self.data,self.name_config)
     #the basic view is hidden first but can be switched into
     self.basic_panel.Hide()
     #adding the two views into the sizer
     self.sizer.Add(self.basic_panel, 1, wx.EXPAND)
     self.sizer.Add(self.advanced_panel, 2, wx.EXPAND)
     
     #creating the status bar at the bottom
     self.CreateStatusBar()
     
     #creating menu at top
     filemenu=wx.Menu()
     menuBar=wx.MenuBar()
     #file is only option at this stage
     menuBar.Append(filemenu,"&File")
     self.SetMenuBar(menuBar)
     
     #switch between the Advanced and Basic view
     toggle=filemenu.Append(wx.ID_ANY,"Switch Basic/Advanced",
     """Switch between the default Basic view or the Advanced view 
     with all possible parameters""")
     #open box with information about Karstolution
     menuAbout=filemenu.Append(wx.ID_ABOUT, "&About",
     "Information about this program")
     #exit the program
     menuExit=filemenu.Append(wx.ID_EXIT,"&Exit","Terminate the program")
     
     #binding the events (functions) to the menu items
     self.Bind(wx.EVT_MENU,self.OnAbout,menuAbout)
     self.Bind(wx.EVT_MENU,self.OnCheck,toggle)
     self.Bind(wx.EVT_MENU,self.OnExit, menuExit)
     
     #hidden features, that you need to expand the window to access
     #the Calculate Drip option (default=yes), allows you to over-ride the
     #drip-rate calculation (based on user-inputted min drip interval & store size)
     #and instead run the model just using the user-inputted values as the
     #absolute drip-rate (used for all time-steps of the model)
     self.cb = wx.CheckBox(self, -1, 'Calculate Drips ?', (1050, 270))
     self.cb.SetValue(True)
     self.Bind(wx.EVT_CHECKBOX, self.GetId, self.cb)
     
     #Allows the model to be run multiple times, iterating over a range
     #of parameter values. 
     batch1=wx.Button(self,-1,"Run Batch Mode",(1050,225))
     self.Bind(wx.EVT_BUTTON,self.OnBatch,batch1)
     self.label=wx.StaticText(self,-1,'Batch Mode: ',(1050,10))
     self.label.SetFont(self.font)
     self.label=wx.StaticText(self,-1,'Choose parameter to iterate: ',(1050,40))
     lister=wx.ListBox(self,-1,(1050,60),(180,80),[thing[0] for thing in self.list_options],wx.LB_SINGLE)
     lister.SetSelection(0)
     self.Bind(wx.EVT_LISTBOX,self.OnChoose,lister)
     self.min_b=wx.StaticText(self,-1,'Min Value: ',(1050,150))
     self.min_batch=wx.TextCtrl(self,-1,str(self.batch_p[0]),(1130,150))
     self.Bind(wx.EVT_TEXT,partial( self.assign, name=self.min_batch,id1=0),self.min_batch)
     self.max_b=wx.StaticText(self,-1,'Max Value: ',(1050,175))
     self.max_batch=wx.TextCtrl(self,-1,str(self.batch_p[1]),(1130,175))
     self.Bind(wx.EVT_TEXT,partial( self.assign, name=self.max_batch,id1=1),self.max_batch)
     self.it_b=wx.StaticText(self,-1,'# Iterations: ',(1050,200))
     self.it_batch=wx.TextCtrl(self,-1,str(self.batch_p[2]),(1130,200))
     self.Bind(wx.EVT_TEXT,partial( self.assign, name=self.it_batch,id1=2),self.it_batch)
     
     #telling wxpython the layout is all G       
     self.sizer.Layout()
Ejemplo n.º 47
0
 def OnShowDefault(self, event):
     name = os.path.join(self.cwd, opj('data/test.htm'))
     self.html.LoadPage(name)
Ejemplo n.º 48
0
    def __init__(self, parent, id=wx.ID_ANY):
        scrolled.ScrolledPanel.__init__(self, parent, id)
        # self.log = log
        # self.SetDoubleBuffered(True)

        hdrFont = wx.Font(18, wx.FONTFAMILY_DEFAULT,
                              wx.FONTSTYLE_NORMAL,
                              wx.FONTWEIGHT_BOLD)

        StatText1 = wx.StaticText(self, wx.ID_ANY, 'wx.Image',)
        StatText1.SetFont(wx.Font(wx.FontInfo(24).Bold()))

        StatText2 = wx.StaticText(self, wx.ID_ANY, 'Supported Bitmap Types')
        StatText2.SetFont(hdrFont)

        vsizer0 = wx.BoxSizer(wx.VERTICAL)
        vsizer0.Add(StatText1, 0, wx.ALL|wx.ALIGN_CENTER, 10)
        vsizer0.Add(wx.StaticText(self, wx.ID_ANY, description),
                    0, wx.LEFT|wx.BOTTOM, 10)
        vsizer0.Add(StatText2, 0, wx.ALL, 10)

        fgsizer1 = wx.FlexGridSizer(cols=2, vgap=10, hgap=10)
        fgsizer1.AddGrowableCol(0)
        bmp = wx.Image(opj('bitmaps/image.bmp'), wx.BITMAP_TYPE_BMP)
        gif = wx.Image(opj('bitmaps/image.gif'), wx.BITMAP_TYPE_GIF)
        png = wx.Image(opj('bitmaps/image.png'), wx.BITMAP_TYPE_PNG)
        jpg = wx.Image(opj('bitmaps/image.jpg'), wx.BITMAP_TYPE_JPEG)
        ico = wx.Image(opj('bitmaps/image.ico'), wx.BITMAP_TYPE_ICO)
        tif = wx.Image(opj('bitmaps/image.tif'), wx.BITMAP_TYPE_TIF)
        dict = OrderedDict([
            (bmp, 'bmp\n*.bmp;*rle;*dib'),
            (gif, 'gif\n*.gif'),
            (png, 'png\n*.png'),
            (jpg, 'jpg\n*.jpg;*.jpeg;*.jpe'),
            (ico, 'ico\n*.ico'),
            (tif, 'tif\n*.tif;*.tiff'),
            ])
        for bmpType, tip in list(dict.items()):
            statBmp = wx.StaticBitmap(self, wx.ID_ANY, bmpType.ConvertToBitmap())
            type = bmpType.GetType()
            if type in supportedBitmapTypes:
                typeStr = 'wx.' + supportedBitmapTypes[type][:supportedBitmapTypes[type].find(':')]
            statText = wx.StaticText(self, -1, typeStr)
            fgsizer1.Add(statText)
            fgsizer1.Add(statBmp)

        vsizer0.Add(fgsizer1, 0, wx.LEFT, 25)
        vsizer0.AddSpacer(35)

        StatText3 = wx.StaticText(self, wx.ID_ANY, 'Basic Image Manipulation Operations')
        StatText3.SetFont(hdrFont)
        vsizer0.Add(StatText3, 0, wx.LEFT|wx.BOTTOM, 10)


        self.imgPath = 'bitmaps/image.png'
        self.imgType = wx.BITMAP_TYPE_ANY
        self.fgsizer2 = fgsizer2 = wx.FlexGridSizer(cols=2, vgap=10, hgap=10)
        fgsizer2.AddGrowableCol(0)

        self.colorbutton = wx.ColourPickerCtrl(self, wx.ID_ANY,
                                               size=(175, -1),
                                               style=wx.CLRP_USE_TEXTCTRL)
        self.colorbutton.Bind(wx.EVT_COLOURPICKER_CHANGED, self.ChangePanelColor)
        vsizer1 = wx.BoxSizer(wx.VERTICAL)
        vsizer1.Add(wx.StaticText(self, -1, "Panel colour:"))
        vsizer1.Add(self.colorbutton, 0, wx.LEFT, 15)
        fgsizer2.Add(vsizer1)


        self.SetBackgroundColour(self.defBackgroundColour)
        self.colorbutton.SetColour(self.defBackgroundColour)
        self.colorbutton.SetToolTip('Change Panel Color')

        self.filebutton = wx.FilePickerCtrl(self, wx.ID_ANY,
                                            path=os.path.abspath(opj(self.imgPath)),
                                            message='',
                                            wildcard=wx.Image.GetImageExtWildcard(),
                                            style=wx.FLP_OPEN
                                                | wx.FLP_FILE_MUST_EXIST
                                                | wx.FLP_USE_TEXTCTRL
                                                | wx.FLP_CHANGE_DIR
                                                # | wx.FLP_SMALL
                                                )
        self.filebutton.SetToolTip('Browse for a image to preview modifications')
        self.filebutton.Bind(wx.EVT_FILEPICKER_CHANGED, self.ChangeModdedImages)
        vsizer2 = wx.BoxSizer(wx.VERTICAL)
        vsizer2.Add(wx.StaticText(self, -1, "Load test image:"))
        vsizer2.Add(self.filebutton, 0, wx.EXPAND|wx.LEFT, 15)
        fgsizer2.Add(vsizer2, 0, wx.EXPAND)

        fgsizer2.AddSpacer(10)
        fgsizer2.AddSpacer(10)

        def getImg():
            # Start with a fresh copy of the image to mod.
            path = opj(self.imgPath)
            type = self.imgType
            return wx.Image(path, type)

        self.allModdedStatBmps = []
        self.img = getImg()
        self.imgWidth = getImg().GetWidth()
        self.imgHeight = getImg().GetHeight()
        self.imgCenterPt = wx.Point(self.imgWidth//2, self.imgHeight//2)

        imgBmp = wx.StaticBitmap(self, wx.ID_ANY, self.img.ConvertToBitmap())
        fgsizer2.Add(wx.StaticText(self, -1, "Original test image:"))
        fgsizer2.Add(imgBmp)
        self.allModdedStatBmps.append(imgBmp)

        self.DoImageMods()

        dict = OrderedDict([
            (self.greyscale  , 'img.ConvertToGreyscale()'),
            (self.disabled   , 'img.ConvertToDisabled()'),
            (self.mono       , 'img.ConvertToMono(r=255, g=255, b=255)'),
            (self.mask       , 'img.SetMaskColour(\n\tred=255, green=255, blue=255)'),
            (self.blur       , 'img.Blur(blurRadius=3)'),
            (self.blurH      , 'img.BlurHorizontal(blurRadius=3)'),
            (self.blurV      , 'img.BlurVertical(blurRadius=3)'),
            (self.mirrorH    , 'img.Mirror(horizontally=True)'),
            (self.mirrorV    , 'img.Mirror(horizontally=False)'),
            (self.mirrorBoth , 'img.Mirror(horizontally=True).\n\tMirror(horizontally=False)'),
            (self.adjustChan , 'img.AdjustChannels(factor_red=2.0,\n\tfactor_green=1.0,\n\tfactor_blue=1.0,\n\tfactor_alpha=1.0)'),
            (self.rotate     , 'img.Rotate(angle=45.0,\n\trotationCentre=imgCenterPt,\n\tinterpolating=True,\n\toffsetAfterRotation=None)'),
            (self.rotate90   , 'img.Rotate90(clockwise=True)'),
            (self.rotate180  , 'img.Rotate180()'),
            (self.replace    , 'img.Replace(r1=0, g1=0, b1=0,\n\tr2=0, g2=255, b2=0)'),
            (self.scale      , 'img.Scale(width=128, height=32,\n\tquality=wx.IMAGE_QUALITY_NORMAL)'),
            (self.rescale    , 'img.Rescale(width=128, height=32,\n\tquality=wx.IMAGE_QUALITY_NORMAL)'),
            (self.resize     , 'img.Resize(size=(256 + 16, 64 + 8),\n\tpos=(0+8, 0+4),\n\tred=0, green=0, blue=255)'),
            (self.paste      , 'img.Paste(image=getImg(), x=16, y=16)'),
            (self.rotatehue  , 'img.RotateHue(0.5)'),
            ])

        for imgModification, tip in list(dict.items()):
            statBmp = wx.StaticBitmap(self, wx.ID_ANY,
                                      imgModification.ConvertToBitmap())
            self.allModdedStatBmps.append(statBmp)
            tip = tip.replace('\t', ' '*8)
            statText = wx.StaticText(self, -1, tip)
            fgsizer2.Add(statText) #, 0, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER, 5)
            fgsizer2.Add(statBmp)#, 0, wx.ALL, 5)

        vsizer0.Add(fgsizer2, 0, wx.LEFT, 25)
        self.SetSizer(vsizer0)
        self.SetupScrolling()
Ejemplo n.º 49
0
 def OnShowDefault(self, event):
     name = os.path.join(self.cwd, opj('data/test.htm'))
     self.html.LoadPage(name)
Ejemplo n.º 50
0
 def OnListBoxSelect(self, evt):
     snippet_file = opj('snippets/%s.py' % evt.GetString())
     with open(snippet_file) as f:
         text = f.read()
     self.canvas.SetSnippet(text)
     self.editor.SetValue(text)
Ejemplo n.º 51
0
import  wx
import  wx.xrc  as  xrc

from Main import opj

#----------------------------------------------------------------------

RESFILE = opj("data/resource_wdr.xrc")

class TestPanel(wx.Panel):
    def __init__(self, parent, log):
        wx.Panel.__init__(self, parent, -1)
        self.log = log

        # make the components
        label = wx.StaticText(self, -1, "The lower panel was built from this XML:")
        label.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))

        resourceText = open(RESFILE).read()
        text = wx.TextCtrl(self, -1, resourceText,
                          style=wx.TE_READONLY|wx.TE_MULTILINE)
        text.SetInsertionPoint(0)

        line = wx.StaticLine(self, -1)

        # This shows a few different ways to load XML Resources
        if 0:
            # XML Resources can be loaded from a file like this:
            res = xrc.XmlResource(RESFILE)
Ejemplo n.º 52
0
 def OnListBoxSelect(self, evt):
     snippet_file = opj("snippets/%s.py" % evt.GetString())
     with open(snippet_file) as f:
         text = f.read()
     self.canvas.SetSnippet(text)
     self.editor.SetValue(text)