Skip to content
This repository has been archived by the owner on Dec 29, 2023. It is now read-only.

Commit

Permalink
Restyled by yapf
Browse files Browse the repository at this point in the history
  • Loading branch information
restyled-commits authored and srevinsaju committed Sep 24, 2020
1 parent b949229 commit acc232c
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 76 deletions.
70 changes: 33 additions & 37 deletions guiscrcpy/lib/toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
import pyautogui as auto
from pygetwindow import getWindowsWithTitle
except ModuleNotFoundError as e:
logging.debug("pygetwindow, pyautogui " "failed with error code {}".format(e))
logging.debug("pygetwindow, pyautogui "
"failed with error code {}".format(e))
auto = None
getWindowsWithTitle = None
else:
Expand All @@ -45,29 +46,26 @@ def wmctrl_xdotool_linux_send_key(key):
wmctrl = shutil.which("wmctrl")
xdotool = shutil.which("xdotool")
if not wmctrl or not xdotool:
print(
"E: Could not find {} on PATH. Make sure "
"that a compatible package is installed "
"on your system for this function"
)
print("E: Could not find {} on PATH. Make sure "
"that a compatible package is installed "
"on your system for this function")
return
_proc = subprocess.Popen(
shlex.split("wmctrl -x -a scrcpy"), stdout=sys.stdout, stderr=sys.stderr
)
_proc = subprocess.Popen(shlex.split("wmctrl -x -a scrcpy"),
stdout=sys.stdout,
stderr=sys.stderr)
if _proc.wait() == 0:
_xdotool_proc = subprocess.Popen(
shlex.split(
"xdotool key --clearmodifiers {}+{}".format(
os.getenv("GUISCRCPY_MODIFIER") or "alt", key
)
),
shlex.split("xdotool key --clearmodifiers {}+{}".format(
os.getenv("GUISCRCPY_MODIFIER") or "alt", key)),
stdout=sys.stdout,
stderr=sys.stderr,
)
if _xdotool_proc.wait() != 0:
print("E (xdotool): Failed to send key {} to " "scrcpy window.".format(key))
print("E (xdotool): Failed to send key {} to "
"scrcpy window.".format(key))
else:
print("E (wmctrl): Failed to get scrcpy window. " "(Is scrcpy running?)")
print("E (wmctrl): Failed to get scrcpy window. "
"(Is scrcpy running?)")


class UXMapper:
Expand All @@ -85,14 +83,12 @@ def __init__(self, adb, device_id=None, sha_shift=5):
logging.debug("Calculating Screen Size")
self.android_dimensions = adb.get_dimensions(device_id=device_id)
if not self.android_dimensions:
print(
"E: guiscrcpy has crashed because of a failure in the "
"execution of `adb shell wm size`. This might be because "
"of an improper connection of adb. Please reconnect your "
"device (disconnect from WiFi / Reconnect USB) or try \n\n"
"guiscrcpy --killserver\n\nas a command line to restart adb "
"server"
)
print("E: guiscrcpy has crashed because of a failure in the "
"execution of `adb shell wm size`. This might be because "
"of an improper connection of adb. Please reconnect your "
"device (disconnect from WiFi / Reconnect USB) or try \n\n"
"guiscrcpy --killserver\n\nas a command line to restart adb "
"server")
self.deviceId = device_id

# each device connected is uniquely identified by the tools by
Expand All @@ -105,7 +101,7 @@ def get_sha(self):
A method which returns the unique UUID of the the device
:return: The hexdigest of a salted hash
"""
return self.__sha[self.sha_shift : self.sha_shift + 6]
return self.__sha[self.sha_shift:self.sha_shift + 6]

def do_swipe(self, x1=10, y1=10, x2=10, y2=10):
"""
Expand All @@ -116,9 +112,8 @@ def do_swipe(self, x1=10, y1=10, x2=10, y2=10):
:param y2: y2 coordinate
:return: Boolean True, in success
"""
self.adb.shell_input(
"swipe {} {} {} {}".format(x1, y1, x2, y2), device_id=self.deviceId
)
self.adb.shell_input("swipe {} {} {} {}".format(x1, y1, x2, y2),
device_id=self.deviceId)
return True

def do_keyevent(self, key):
Expand All @@ -127,7 +122,8 @@ def do_keyevent(self, key):
:param key: The ADB predefined keycode
:return:
"""
self.adb.shell_input("keyevent {}".format(key), device_id=self.deviceId)
self.adb.shell_input("keyevent {}".format(key),
device_id=self.deviceId)
return True

def copy_devpc(self):
Expand Down Expand Up @@ -168,17 +164,17 @@ def key_switch(self):

def reorient_portrait(self):
logging.debug("Passing REORIENT [POTRAIT]")
self.adb.shell(
"settings put system accelerometer_rotation 0", device_id=self.deviceId
)
self.adb.shell("settings put system rotation 1", device_id=self.deviceId)
self.adb.shell("settings put system accelerometer_rotation 0",
device_id=self.deviceId)
self.adb.shell("settings put system rotation 1",
device_id=self.deviceId)

def reorient_landscape(self):
logging.debug("Passing REORIENT [LANDSCAPE]")
self.adb.shell(
"settings put system accelerometer_rotation 0", device_id=self.deviceId
)
self.adb.shell("settings put system rotation 1", device_id=self.deviceId)
self.adb.shell("settings put system accelerometer_rotation 0",
device_id=self.deviceId)
self.adb.shell("settings put system rotation 1",
device_id=self.deviceId)

def expand_notifications(self):
logging.debug("Passing NOTIF EXPAND")
Expand Down
30 changes: 13 additions & 17 deletions guiscrcpy/ux/toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@


class InterfaceToolkit(QMainWindow, Ui_ToolbarPanel):
def __init__(self, ux_mapper=None, parent=None, frame=False, always_on_top=True):
def __init__(self,
ux_mapper=None,
parent=None,
frame=False,
always_on_top=True):
"""
Side panel toolkit for guiscrcpy main window
:param ux_mapper:
Expand Down Expand Up @@ -57,11 +61,9 @@ def __init__(self, ux_mapper=None, parent=None, frame=False, always_on_top=True)
self.ux = UXMapper()

def init(self):
if platform.system() != "Linux" or (
shutil.which("wmctrl")
and shutil.which("xdotool")
and platform.system() == "Linux"
):
if platform.system() != "Linux" or (shutil.which("wmctrl")
and shutil.which("xdotool")
and platform.system() == "Linux"):
self.clipD2PC.clicked.connect(self.ux.copy_devpc)
self.clipPC2D.clicked.connect(self.ux.copy_pc2dev)
self.fullscreenUI.clicked.connect(self.ux.fullscreen)
Expand All @@ -77,8 +79,7 @@ def init(self):
'This function is disabled because "wmctrl"'
' or "xdotool" is not found on your installation.'
"Keyboard shortcut can be used instead"
": <b>{}</b>".format(helper)
)
": <b>{}</b>".format(helper))

self.back.clicked.connect(self.ux.key_back)
self.screenfreeze.clicked.connect(self.quit_window)
Expand Down Expand Up @@ -118,18 +119,13 @@ def quit_window(self):
# This method checks if we are the last member of the windows
# spawned and we ourselves are not a member of ourself by
# checking the uuid generated on creation
if (
not instance.isHidden()
and instance.name != "swipe"
and instance.uid != self.uid
):
if (not instance.isHidden() and instance.name != "swipe"
and instance.uid != self.uid):
self.hide()
break
else:
for instance in self.parent.child_windows: # noqa
if (
instance.name == "swipe"
and instance.ux.get_sha() == self.ux.get_sha()
):
if (instance.name == "swipe"
and instance.ux.get_sha() == self.ux.get_sha()):
instance.hide()
self.hide()
34 changes: 15 additions & 19 deletions releaser
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ Categories=Utility;Development;
StartupWMClass=UGENE
"""


DATA_FILES_MANIPULATE = {
"setup.py": "",
"setup.py-manylinux2014-scrcpy": """
"setup.py":
"",
"setup.py-manylinux2014-scrcpy":
"""
def get_scrcpy_libs():
libs = []
Expand Down Expand Up @@ -92,14 +93,12 @@ def gen_version():
git_version = "{}".format(raw_version[0])
elif len(raw_version) == 2:
# Release Candidate
git_version = "{major}.post{minor}".format(
major=raw_version[0], minor=raw_version[1]
)
git_version = "{major}.post{minor}".format(major=raw_version[0],
minor=raw_version[1])
else:
# Revision Dev
git_version = "{major}.post{minor}.dev".format(
major=raw_version[0], minor=raw_version[1]
)
major=raw_version[0], minor=raw_version[1])
return git_version


Expand Down Expand Up @@ -186,7 +185,7 @@ VERSION = "{version}"
# this was because GitPython created a lot of problems
# hardcoding the information before each release, solved the problem

for setup in ("setup.py",):
for setup in ("setup.py", ):
with open(setup, "w") as w:
w.write(
setupfile.format(
Expand All @@ -195,23 +194,20 @@ for setup in ("setup.py",):
entry_points=CONSOLE_SCRIPTS,
extras=EXTRAS_REQUIRE,
DATA_FILE_MANIPULATE=DATA_FILES_MANIPULATE[setup],
)
)
))

with open("guiscrcpy/version.py", "w") as w:
w.write(
VERSION_FILE.format(
COPYRIGHT=COPYRIGHT,
version=v,
)
)

w.write(VERSION_FILE.format(
COPYRIGHT=COPYRIGHT,
version=v,
))

with open("guiscrcpy.desktop", "w") as w:
w.write(DESKTOP_FILE.format(v=v, icon_path="guiscrcpy"))

with open("snap/gui/guiscrcpy.desktop", "w") as w:
w.write(DESKTOP_FILE.format(v=v, icon_path="${SNAP}/meta/gui/guiscrcpy.png"))
w.write(
DESKTOP_FILE.format(v=v, icon_path="${SNAP}/meta/gui/guiscrcpy.png"))

with open("snap/local/snapcraft.yaml", "r") as r:
SNAPCRAFT_FILE = r.read()
Expand Down
11 changes: 8 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@

try:
this_directory = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(this_directory, "README.md"), encoding="utf-8") as f:
with open(os.path.join(this_directory, "README.md"),
encoding="utf-8") as f:
long_description = f.read()
except FileNotFoundError:
long_description = "Open Source Android Screen Mirroring System by @srevinsaju"
Expand All @@ -54,13 +55,17 @@
author_email="srevin03@gmail.com",
packages=find_packages(),
data_files=data_files,
extras_require={"pyqt5": "PyQt5", "pyside2": "PySide2"},
extras_require={
"pyqt5": "PyQt5",
"pyside2": "PySide2"
},
url="https://srevinsaju.github.io/guiscrcpy",
download_url="https://github.com/srevinsaju/guiscrcpy/archive/master.zip",
include_package_data=True,
install_requires=requirements,
scripts=["scripts/guiscrcpy"],
entry_points={"console_scripts": ["guiscrcpy = guiscrcpy.cli:cli"]}, # noqa: E501
entry_points={"console_scripts":
["guiscrcpy = guiscrcpy.cli:cli"]}, # noqa: E501
classifiers=[
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.7",
Expand Down

0 comments on commit acc232c

Please sign in to comment.