Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Darken screen around area
import wx
import time
from multiprocessing import Process, Lock
def darkenScreenAroundArea(lock, x, y, width, height):
app = wx.App(False)
screensize = wx.GetDisplaySize()
frm = DarkFrame(lock, 0, 0, screensize[0], y) # top
frm = DarkFrame(lock, 0, y, x, height) # left
frm = DarkFrame(lock, (x + width), y, (screensize[0] - x + width), height) # right
frm = DarkFrame(lock, 0, (y + height), screensize[0], (screensize[1] - y + height)) # bottom
app.MainLoop()
class DarkFrame(wx.Frame):
def __init__(self, lock, x, y, width, height):
wx.Frame.__init__(self, None, title='', style=wx.NO_BORDER, size=(width,height), pos=(x,y))
self.SetBackgroundColour('BLACK')
self.SetTransparent(140)
self.Show()
self.lock = lock
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.update, self.timer)
self.timer.Start(50, wx.TIMER_CONTINUOUS)
def update(self, event):
if self.lock.acquire(block=False):
self.lock.release()
self.Close()
lock = Lock()
lock.acquire()
p = Process(target=darkenScreenAroundArea, args=(lock, 400, 200, 500, 300))
p.start()
time.sleep(5)
lock.release()
p.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment