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

Commit

Permalink
Restyled by black
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 3026e73 commit e082133
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 89 deletions.
85 changes: 41 additions & 44 deletions guiscrcpy/lib/toolkit.py
Expand Up @@ -30,8 +30,7 @@
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,28 +44,29 @@ 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)
),
_xdotool_proc = subprocess.Popen(
shlex.split(
"xdotool key --clearmodifiers {}+{}".format(
os.getenv("GUISCRCPY_MODIFIER") or "alt", key
)
),
stdout=sys.stdout,
stderr=sys.stderr
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 @@ -82,16 +82,16 @@ def __init__(self, adb, device_id=None, sha_shift=5):
logging.debug("Launching UX Mapper")
self.has_modules = getWindowsWithTitle and auto
logging.debug("Calculating Screen Size")
self.android_dimensions = adb.get_dimensions(
device_id=device_id
)
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 @@ -104,7 +104,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 @@ -115,8 +115,9 @@ 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 @@ -125,8 +126,7 @@ 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 All @@ -135,7 +135,7 @@ def copy_devpc(self):
scrcpywindow.focus()
auto.hotkey("alt", "c")
else:
wmctrl_xdotool_linux_send_key('c')
wmctrl_xdotool_linux_send_key("c")

def key_power(self):
logging.debug("Passing POWER")
Expand Down Expand Up @@ -167,20 +167,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
"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 rotation 1", device_id=self.deviceId)

def expand_notifications(self):
logging.debug("Passing NOTIF EXPAND")
Expand All @@ -196,12 +193,12 @@ def copy_pc2dev(self):
scrcpywindow.focus()
auto.hotkey("alt", "shift", "c")
else:
wmctrl_xdotool_linux_send_key('shift+c')
wmctrl_xdotool_linux_send_key("shift+c")

def fullscreen(self):
if self.has_modules:
scrcpy_window = getWindowsWithTitle("scrcpy")[0]
scrcpy_window.focus()
auto.hotkey("alt", "f")
else:
wmctrl_xdotool_linux_send_key('f')
wmctrl_xdotool_linux_send_key("f")
36 changes: 21 additions & 15 deletions guiscrcpy/ux/toolkit.py
Expand Up @@ -30,8 +30,7 @@


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 @@ -60,24 +59,27 @@ def __init__(self, ux_mapper=None, parent=None, frame=False,

def init(self):
if platform.system() != "Linux" or (
shutil.which('wmctrl') and
shutil.which('xdotool') and
platform.system() == "Linux"):
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)
else:
# the tools do not exist on Linux. user has to manually install
for button, helper in (
(self.clipD2PC, 'Alt + C'),
(self.clipPC2D, 'Alt + Shift + C'),
(self.fullscreenUI, 'Alt + F')):
(self.clipD2PC, "Alt + C"),
(self.clipPC2D, "Alt + Shift + C"),
(self.fullscreenUI, "Alt + F"),
):
button.setDisabled(True)
button.setToolTip(
'This function is disabled because "wmctrl"'
' or "xdotool" is not found on your installation.'
'Keyboard shortcut can be used instead'
': <b>{}</b>'.format(helper))
"Keyboard shortcut can be used instead"
": <b>{}</b>".format(helper)
)

self.back.clicked.connect(self.ux.key_back)
self.screenfreeze.clicked.connect(self.quit_window)
Expand Down Expand Up @@ -117,14 +119,18 @@ 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()
2 changes: 1 addition & 1 deletion guiscrcpy/version.py
Expand Up @@ -20,4 +20,4 @@
"""

VERSION = 'v4.7.2.post3.dev'
VERSION = "v4.7.2.post3.dev"
54 changes: 25 additions & 29 deletions setup.py
Expand Up @@ -27,52 +27,48 @@

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"
long_description = "Open Source Android Screen Mirroring System by @srevinsaju"

requirements = ['PyQt5>=5.14,<5.16', 'pynput', 'qtpy', 'click', 'colorama']
if platform.system() == 'Windows':
requirements.extend(['pywin32', 'psutil'])
elif platform.system() == 'Linux':
requirements.extend(['psutil', 'cairosvg'])
requirements = ["PyQt5>=5.14,<5.16", "pynput", "qtpy", "click", "colorama"]
if platform.system() == "Windows":
requirements.extend(["pywin32", "psutil"])
elif platform.system() == "Linux":
requirements.extend(["psutil", "cairosvg"])

data_files = [
('share/applications', ['guiscrcpy.desktop']),
('share/icons/hicolor/scalable/apps', ['appimage/guiscrcpy.png']),
("share/applications", ["guiscrcpy.desktop"]),
("share/icons/hicolor/scalable/apps", ["appimage/guiscrcpy.png"]),
]

setup(
name='guiscrcpy',
version='v4.7.2.post3.dev',
description='An Open Source - Fast - Android Screen Mirroring system.',
name="guiscrcpy",
version="v4.7.2.post3.dev",
description="An Open Source - Fast - Android Screen Mirroring system.",
long_description=long_description,
long_description_content_type='text/markdown',
license='GPL v3',
author='srevinsaju',
long_description_content_type="text/markdown",
license="GPL v3",
author="srevinsaju",
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',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.8',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)'
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.8",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
],
)

0 comments on commit e082133

Please sign in to comment.