From 7b48ba5a6b1393412444eba0eb702d70594df346 Mon Sep 17 00:00:00 2001 From: Qijun Gu Date: Mon, 11 Oct 2021 09:55:57 -0500 Subject: [PATCH] add windows screenshot --- README.md | 2 +- screen.py | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 466496d..a7c55ce 100755 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ This tool can run on Linux, Windows and MAC. ## Install -1. pip install flask-bootstrap pyscreenshot pyopenssl +1. pip install flask-bootstrap pyscreenshot pyopenssl pillow 2. In a directory, run "**git clone https://github.com/qijungu/screenshare.git**". You will have a new directory "screenshare" with code inside. diff --git a/screen.py b/screen.py index fcefda8..d6e80a7 100755 --- a/screen.py +++ b/screen.py @@ -15,24 +15,28 @@ #You should have received a copy of the GNU General Public License #along with Screenshare. If not, see . -import threading, time, base64 -import pyscreenshot as ig - -import sys +import threading, time, base64, sys ver = sys.version_info.major if ver==2: - import StringIO + import StringIO as io elif ver==3: import io +if sys.platform in ["win32", "darwin"]: + from PIL import ImageGrab as ig +else: + import pyscreenshot as ig + bkend = "pygdk3" + + class Screen(): def __init__(self): self.FPS = 10 self.screenbuf = "" self.password = "" if ver==2: - self.screenfile = StringIO.StringIO() + self.screenfile = io.StringIO() elif ver==3: self.screenfile = io.BytesIO() threading.Thread(target=self.getframes).start() @@ -42,7 +46,10 @@ class Screen(): def getframes(self): while True: - im = ig.grab(childprocess=False,backend="pygdk3") + if sys.platform in ["win32", "darwin"]: + im = ig.grab() + else: + im = ig.grab(childprocess=False,backend=bkend) self.screenfile.seek(0) self.screenfile.truncate(0) im.save(self.screenfile, format="jpeg", quality=75, progressive=True)