def __init__(self, parent, startFunc, endFunc): self.startFunc = startFunc self.endFunc = endFunc self.text = eg.plugins.Window.FindWindow.text wx.PyWindow.__init__(self, parent, -1, style=wx.SIMPLE_BORDER) self.SetBackgroundColour( wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW) ) self.lastTarget = None # load images self.dragBoxBitmap = GetInternalBitmap("findert") image = GetInternalImage('findertc') image.SetMaskColour(255, 0, 0) # since this image didn't come from a .cur file, tell it where the # hotspot is image.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_X, 15) image.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_Y, 16) # make the image into a cursor self.cursor = wx.CursorFromImage(image) # the image of the drag target dragBoxImage = wx.StaticBitmap(self, -1, self.dragBoxBitmap) dragBoxImage.SetMinSize(self.dragBoxBitmap.GetSize()) dragBoxImage.Bind(wx.EVT_LEFT_DOWN, self.OnDragboxClick) self.dragBoxImage = dragBoxImage # some description for the drag target dragBoxText = wx.StaticText( self, -1, self.text.drag2, style=wx.ALIGN_CENTRE ) x1, y1 = dragBoxText.GetBestSize() dragBoxText.SetLabel(self.text.drag1) x2, y2 = dragBoxText.GetBestSize() dragBoxText.SetMinSize((max(x1, x2), max(y1, y2))) #dragBoxText.Bind(wx.EVT_LEFT_DOWN, self.OnDragboxClick) self.dragBoxText = dragBoxText self.Bind(wx.EVT_SIZE, self.OnSize) # put our drag target together sizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(dragBoxImage, 0, wx.ALIGN_CENTER_VERTICAL) sizer.Add(dragBoxText, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL) self.SetSizer(sizer) self.SetAutoLayout(True) sizer.Fit(self) self.SetMinSize(self.GetSize()) wx.CallAfter(self.dragBoxImage.SetBitmap, self.dragBoxBitmap)
def __init__(self, parent): wx.PyWindow.__init__(self, parent) self.font = wx.Font(40, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_ITALIC, wx.FONTWEIGHT_BOLD) self.SetBackgroundColour((255, 255, 255)) self.logo1 = GetInternalBitmap("opensource-55x48") self.logo2 = GetInternalBitmap("python-powered") self.logo3 = GetInternalBitmap("logo2") self.image = GetInternalImage("logo") self.bmpWidth = self.image.GetWidth() self.bmpHeight = self.image.GetHeight() self.time = clock() self.count = 0 self.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_TIMER, self.UpdateDrawing) self.OnSize(None) self.timer = wx.Timer(self) self.timer.Start(10)
class AnimatedWindow(wx.PyWindow): def __init__(self, parent): wx.PyWindow.__init__(self, parent) self.font = wx.Font(40, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_ITALIC, wx.FONTWEIGHT_BOLD) self.SetBackgroundColour((255, 255, 255)) self.logo1 = GetInternalBitmap("opensource-55x48") self.logo2 = GetInternalBitmap("python-powered") self.logo3 = GetInternalBitmap("logo2") self.image = GetInternalImage("logo") self.bmpWidth = self.image.GetWidth() self.bmpHeight = self.image.GetHeight() self.time = clock() self.count = 0 self.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_TIMER, self.UpdateDrawing) self.OnSize(None) self.timer = wx.Timer(self) self.timer.Start(10) def AcceptsFocus(self): return False def AcceptsFocusFromKeyboard(self): return False def Draw(self, deviceContext): deviceContext.BeginDrawing() deviceContext.DrawBitmap(self.backbuffer, 0, 0, False) t = clock() / 2.0 y3 = self.y3 x3 = self.x3 y = (sin(t) + sin(1.8 * t)) * y3 + y3 * 2.0 x = (sin(t * 0.8) + sin(1.9 * t)) * x3 + x3 * 2.0 alpha = sin(t) / 2.0 + 0.5 image = self.image.AdjustChannels(1.0, 1.0, 1.0, alpha) bmp = wx.BitmapFromImage(image, 24) deviceContext.DrawBitmap(bmp, x, y, True) deviceContext.EndDrawing() def MakeBackground(self): self.backbuffer = wx.EmptyBitmap(self.width, self.height) deviceContext = wx.MemoryDC() deviceContext.SelectObject(self.backbuffer) deviceContext.BeginDrawing() deviceContext.SetBackground(wx.Brush(self.GetBackgroundColour())) deviceContext.Clear() # make sure you clear the bitmap! deviceContext.SetFont(self.font) deviceContext.SetTextForeground((128, 128, 128)) width1 = self.logo1.GetWidth() width2 = self.logo2.GetWidth() height1 = self.logo1.GetHeight() height2 = self.logo2.GetHeight() height = max(height1, height2) deviceContext.DrawBitmap( self.logo1, self.width - width1 - width2, self.height - height + (height - height1) // 2, True) deviceContext.DrawBitmap( self.logo2, self.width - width2, self.height - height + (height - height2) // 2, True) deviceContext.DrawBitmap(self.logo3, (self.width - self.logo3.GetWidth()) // 2, (self.height - self.logo3.GetHeight()) // 3, True) deviceContext.EndDrawing() def OnSize(self, dummyEvent): self.width, self.height = self.GetClientSizeTuple() self.dcBuffer = wx.EmptyBitmap(self.width, self.height) self.y3 = (self.height - self.bmpHeight) / 4.0 self.x3 = (self.width - self.bmpWidth) / 4.0 self.MakeBackground() self.UpdateDrawing() def UpdateDrawing(self, dummyEvent=None): deviceContext = wx.BufferedDC(wx.ClientDC(self), self.dcBuffer) self.Draw(deviceContext)