I've been playing with a few things since I spent a long time reading
about the graphic device interface the past few days and got an idea.
Trying to mix the old school "arcade graphics" feel to some of the GUI
elements for various events. The code is a bit clunky at the moment,
but it does work. I'll flesh it out more when I get a little more
into it.
Anyhow, would someone be willing to take a look, run the code, and
tell me what they think? The background image and two static bitmaps
can be anything. I made the static bitmaps custom looking close
window and minimize "buttons".
Anyhow, when you mouse over the static bitmaps a thread is started
that draws a bunch of lines for make concentric boxes and changes
color of the lines in a for loop.
The nifty thing is it should work with any size widget in any position
as long as the event object is capable of delivering a GetSize() and
GetPosition() the rest is calculated in the thread.
My question is: Is there a better way to do this?
Here is the code... I think it's a cool look tell me what you think.
##CODE
import wx
import time
import thread
class MouseOverThread:
def __init__(self, EventObj):
self.EventObj = EventObj
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.EventObjParent = self.EventObj.GetParent()
self.ObjSize = self.EventObj.GetSize()
self.ObjPos = self.EventObj.GetPosition()
PenColor = ['#0055FF', '#0000FF', '#00D4FF', '#0000FF']
for item in PenColor:
self.EventObjParent.DC.SetPen(wx.Pen(item))
LConstX = self.ObjPos[0] - 1
LStartY = self.ObjPos[1]
LEndY = self.ObjPos[1] + self.ObjSize[1]
self.EventObjParent.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.EventObjParent.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.EventObjParent.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.EventObjParent.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.EventObjParent.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.EventObjParent.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.EventObjParent.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.EventObjParent.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.EventObjParent.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.EventObjParent.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.EventObjParent.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.EventObjParent.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.ScreenResolution = wx.GetDisplaySize()
self.GP = self.GetParent()
self.DC = wx.ClientDC(self)
self.BGBitmap = wx.Bitmap('Graphic Resources\Panel
Background.png')
CloseWindowResource = 'Graphic Resources\Close Window.png'
self.CloseWindowBMP = wx.Bitmap(CloseWindowResource)
self.CloseWindowSBMP = wx.StaticBitmap(self, -1,
self.CloseWindowBMP, (self.ScreenResolution[0] -50, 15))
MinimizeWindowResource = 'Graphic Resources\Minimize
Window.png'
self.MinimizeWindowBMP = wx.Bitmap(MinimizeWindowResource)
self.MinimizeWindowSBMP = wx.StaticBitmap(self, -1,
self.MinimizeWindowBMP, (self.ScreenResolution[0] -100, 15))
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
self.CloseWindowSBMP.Bind(wx.EVT_ENTER_WINDOW,
self.OnWindowEnter)
self.CloseWindowSBMP.Bind(wx.EVT_LEAVE_WINDOW,
self.OnWindowLeave)
self.CloseWindowSBMP.Bind(wx.EVT_LEFT_DOWN,
self.OnCloseWindowClick)
self.MinimizeWindowSBMP.Bind(wx.EVT_ENTER_WINDOW,
self.OnWindowEnter)
self.MinimizeWindowSBMP.Bind(wx.EVT_LEAVE_WINDOW,
self.OnWindowLeave)
self.MinimizeWindowSBMP.Bind(wx.EVT_LEFT_DOWN,
self.OnMinimizeWindowClick)
def OnEraseBackground(self, event):
EraseDC = event.GetDC()
if EraseDC is None:
EraseDC = wx.ClientDC(self)
MemoryDC = wx.MemoryDC()
MemoryDC.SelectObject(self.BGBitmap)
EraseDC.Blit(0,0, self.BGBitmap.GetWidth(),
self.BGBitmap.GetHeight(), MemoryDC, 0,0)
MemoryDC.SelectObject(wx.NullBitmap)
def OnGUIThreadStop(self):
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.t.Start()
def OnWindowLeave(self, event):
self.OnGUIThreadStop()
self.Refresh()
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, "Soma")
self.BP = BasePanel(self)
self. ShowFullScreen(True, style = wx.FULLSCREEN_ALL)
class SomaApp(wx.App):
def OnInit(self):
BF = BaseFrame()
BF.Show(True)
return True
App = SomaApp(False)
App.MainLoop()