I Read Andrea’s reply about using a thread for GUI manipulation. If I can do what I want to do in the main thread and not lock up the GUI in the mean time that would be great, but I’m shooting for some type of “animation” on a mouse over, and I’d like those animations to have an alpha channel.
I’ve come a long way from where I first started, but I am aware I have much farther to go before I can call myself anything other than a novice. Thanks in advance!
Code below.
import wx
import time
import thread
import wx.lib.inspection
print wx.version()
Thread that color changing boxes around the event object on the client.
This works.
class MouseOverThread:
def init(self, EventObj, DC):
self.EventObj = EventObj
self.DC = DC
def Start(self):
self.Working = self.running = True
thread.start_new_thread(self.Run, ())
def Stop(self):
self.Working = False
def IsRunning(self):
return self.running
def Run(self):
while self.Working:
self.ObjSize = self.EventObj.GetSize()
self.ObjPos = self.EventObj.GetPosition()
RGB = [(0, 255, 255), (0, 200, 255), (0, 150, 255), (0, 100, 255), (0, 50, 255), (0, 0, 255)]
for Color in RGB:
R, G, B = Color
self.DC.SetPen(wx.Pen(wx.Colour(R, G, B)))
LConstX = self.ObjPos[0] - 1
LStartY = self.ObjPos[1]
LEndY = self.ObjPos[1] + self.ObjSize[1]
self.DC.DrawLine(LConstX, LStartY, LConstX, LEndY)
RConstX = self.ObjPos[0] + self.ObjSize[0]
RStartY = self.ObjPos[1]
REndY = self.ObjPos[1] + self.ObjSize[1]
self.DC.DrawLine(RConstX, RStartY, RConstX, REndY)
TStartX = self.ObjPos[0] - 1
TEndX = self.ObjPos[0] + self.ObjSize[0] + 1
TConstY = self.ObjPos[1] - 1
self.DC.DrawLine(TStartX, TConstY, TEndX, TConstY)
BStartX = self.ObjPos[0] - 1
BEndX = self.ObjPos[0] + self.ObjSize[0] + 1
BConstY = self.ObjPos[1] + self.ObjSize[1]
self.DC.DrawLine(BStartX, BConstY, BEndX, BConstY)
time.sleep(0.05)
LConstX = self.ObjPos[0] - 2
LStartY = self.ObjPos[1] - 1
LEndY = self.ObjPos[1] + self.ObjSize[1] + 1
self.DC.DrawLine(LConstX, LStartY, LConstX, LEndY)
RConstX = self.ObjPos[0] + self.ObjSize[0] + 1
RStartY = self.ObjPos[1] - 1
REndY = self.ObjPos[1] + self.ObjSize[1] + 1
self.DC.DrawLine(RConstX, RStartY, RConstX, REndY)
TStartX = self.ObjPos[0] - 2
TEndX = self.ObjPos[0] + self.ObjSize[0] + 2
TConstY = self.ObjPos[1] - 2
self.DC.DrawLine(TStartX, TConstY, TEndX, TConstY)
BStartX = self.ObjPos[0] - 2
BEndX = self.ObjPos[0] + self.ObjSize[0] + 2
BConstY = self.ObjPos[1] + self.ObjSize[1] + 1
self.DC.DrawLine(BStartX, BConstY, BEndX, BConstY)
time.sleep(0.05)
LConstX = self.ObjPos[0] - 3
LStartY = self.ObjPos[1] - 2
LEndY = self.ObjPos[1] + self.ObjSize[1] + 2
self.DC.DrawLine(LConstX, LStartY, LConstX, LEndY)
RConstX = self.ObjPos[0] + self.ObjSize[0] + 2
RStartY = self.ObjPos[1] - 2
REndY = self.ObjPos[1] + self.ObjSize[1] + 2
self.DC.DrawLine(RConstX, RStartY, RConstX, REndY)
TStartX = self.ObjPos[0] - 3
TEndX = self.ObjPos[0] + self.ObjSize[0] + 3
TConstY = self.ObjPos[1] - 3
self.DC.DrawLine(TStartX, TConstY, TEndX, TConstY)
BStartX = self.ObjPos[0] - 3
BEndX = self.ObjPos[0] + self.ObjSize[0] + 3
BConstY = self.ObjPos[1] + self.ObjSize[1] + 2
self.DC.DrawLine(BStartX, BConstY, BEndX, BConstY)
time.sleep(0.05)
self.running = False
class BasePanel(wx.Panel):
def init(self, parent):
wx.Panel.init(self, parent, -1)
self.SetBackgroundColour(“yellow”)
self.GP = self.GetParent()
self.DC = wx.ClientDC(self)
wx.StaticText(self, -1, “Hover over a button to trigger the EVT_ENTER_WINDOW event.”, (10, 10))
wx.StaticText(self, -1, “The event starts a thread that paints colored boxes on the”,(10, 30))
wx.StaticText(self, -1, “client, but around the event object no matter it’s position”,(10, 50))
wx.StaticText(self, -1, “or size. Leave the window to trigger the EVT_LEAVE_WINDOW”, (10,70))
wx.StaticText(self, -1, “even. This stops the thread.”, (10, 90))
wx.StaticText(self, -1, “Help on making the exact same thing happen but with a GCDC”, (10, 130))
wx.StaticText(self, -1, “so the colored boxes can have an alpha channel would be great!”, (10, 150))
TestButton1 = wx.Button(self, -1, “Thanks”, (40,200))
TestButton2 = wx.Button(self, -1, “For The”, (130,200))
TestButton3 = wx.Button(self, -1, “Help!!!”, (220,200))
TestButton1.Bind(wx.EVT_ENTER_WINDOW, self.OnWindowEnter)
TestButton1.Bind(wx.EVT_LEAVE_WINDOW, self.OnWindowLeave)
TestButton2.Bind(wx.EVT_ENTER_WINDOW, self.OnWindowEnter)
TestButton2.Bind(wx.EVT_LEAVE_WINDOW, self.OnWindowLeave)
TestButton3.Bind(wx.EVT_ENTER_WINDOW, self.OnWindowEnter)
TestButton3.Bind(wx.EVT_LEAVE_WINDOW, self.OnWindowLeave)
def OnGUIThreadStop(self):
self.Refresh()
self.t.Stop()
running = 1
while running:
running = 0
running = running + self.t.IsRunning()
time.sleep(0.05)
def OnWindowEnter(self, event):
self.EventObj = event.GetEventObject()
self.t = MouseOverThread(self.EventObj, self.DC)
self.t.Start()
def OnWindowLeave(self, event):
self.OnGUIThreadStop()
def OnCloseWindowClick(self, event):
self.OnGUIThreadStop()
self.GP.Close()
def OnMinimizeWindowClick(self, event):
self.GP.Iconize(True)
class BaseFrame(wx.Frame):
def init(self):
wx.Frame.init(self, None, -1, “wx.ClientDC test.py”, size=(350,300), pos=(100,100))
self.BP = BasePanel(self)
wx.lib.inspection.InspectionTool().Show()
class SomaApp(wx.App):
def OnInit(self):
BF = BaseFrame()
BF.Show(True)
return True
App = SomaApp(False)
App.MainLoop()