fix a few bugs in python3

This commit is contained in:
Qijun Gu 2021-06-15 00:34:35 -05:00
parent 60192aecfa
commit c82fea480d
9 changed files with 25 additions and 7 deletions

4
README.md Normal file → Executable file
View File

@ -20,9 +20,9 @@ This tool can run on Linux, Windows and MAC.
## Install and Run ## Install and Run
1. pip install Flask-Bootstrap pyscreenshot 1. pip install flask-bootstrap pyscreenshot
2. In a directory, run "**git clone https://gitlab.com/qijungu/screenshare.git**". You will have a new directory "screenshare" with code inside. 2. In a directory, run "**git clone https://github.com/qijungu/screenshare.git**". You will have a new directory "screenshare" with code inside.
3. To start the screen sharing service, run "**python screenshare.py [port]**". 3. To start the screen sharing service, run "**python screenshare.py [port]**".

0
__init__.py Normal file → Executable file
View File

27
screen.py Normal file → Executable file
View File

@ -1,13 +1,24 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import threading, StringIO, time, base64 import threading, time, base64
import pyscreenshot as ig import pyscreenshot as ig
import sys
ver = sys.version_info.major
if ver==2:
import StringIO
elif ver==3:
import io
class Screen(): class Screen():
def __init__(self): def __init__(self):
self.FPS = 10 self.FPS = 10
self.screenbuf = "" self.screenbuf = ""
self.screenfile = StringIO.StringIO() if ver==2:
self.screenfile = StringIO.StringIO()
elif ver==3:
self.screenfile = io.BytesIO()
threading.Thread(target=self.getframes).start() threading.Thread(target=self.getframes).start()
def __del__(self): def __del__(self):
@ -15,13 +26,19 @@ class Screen():
def getframes(self): def getframes(self):
while True: while True:
im = ig.grab(childprocess=False) im = ig.grab(childprocess=False,backend="pygdk3")
self.screenfile.seek(0)
self.screenfile.truncate(0) self.screenfile.truncate(0)
im.save(self.screenfile, format="jpeg", quality=75, progressive=True) im.save(self.screenfile, format="jpeg", quality=75, progressive=True)
self.screenbuf = base64.b64encode(self.screenfile.getvalue()) self.screenbuf = base64.b64encode(self.screenfile.getvalue())
time.sleep(1.0/self.FPS) time.sleep(1.0/self.FPS)
def gen(self): def gen(self):
return self.screenbuf s = ''
if ver==2:
s = self.screenbuf
elif ver==3:
s = self.screenbuf.decode()
return s
screenlive = Screen() screenlive = Screen()

1
screenshare.py Normal file → Executable file
View File

@ -1,3 +1,4 @@
#!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from flask import Flask from flask import Flask

0
static/css/common.css Normal file → Executable file
View File

0
static/css/jquery-confirm.min.css vendored Normal file → Executable file
View File

0
static/js/jquery-confirm.min.js vendored Normal file → Executable file
View File

0
static/js/screen.js Normal file → Executable file
View File

0
templates/screen.html Normal file → Executable file
View File