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 907beef commit 1659da1
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 108 deletions.
70 changes: 37 additions & 33 deletions guiscrcpy/lib/toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,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 @@ -46,26 +45,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)),
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 @@ -83,12 +85,14 @@ 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 @@ -101,7 +105,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 @@ -112,8 +116,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 @@ -122,8 +127,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 Down Expand Up @@ -164,17 +168,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: 17 additions & 13 deletions guiscrcpy/ux/toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,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 @@ -61,9 +57,11 @@ def __init__(self,
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 @@ -79,7 +77,8 @@ 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 @@ -119,13 +118,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()
73 changes: 37 additions & 36 deletions releaser
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import sys
from os import path

COPYRIGHT = \
"""
COPYRIGHT = """
GUISCRCPY by srevinsaju
Get it on : https://github.com/srevinsaju/guiscrcpy
Licensed under GNU Public License
Expand All @@ -25,13 +24,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
RAW_VERSION = "4.0"

CONSOLE_SCRIPTS = {
'console_scripts': [
'guiscrcpy = guiscrcpy.cli:cli',
"console_scripts": [
"guiscrcpy = guiscrcpy.cli:cli",
]
}

DESKTOP_FILE = \
"""[Desktop Entry]
DESKTOP_FILE = """[Desktop Entry]
Version={v}
Name=guiscrcpy
GenericName=guiscrcpy
Expand Down Expand Up @@ -61,7 +59,7 @@ and os.path.exists("lib"):
('lib', get_scrcpy_libs() ),
('bin', ['bin/scrcpy', 'bin/adb'])
])
"""
""",
}

EXTRAS_REQUIRE = {"pyqt5": "PyQt5", "pyside2": "PySide2"}
Expand All @@ -74,10 +72,11 @@ def gen_version():
:return:
"""
import git

repo = git.Repo(search_parent_directories=True)
ver = repo.git.describe("--tags")
raw_version = ver.split('-')
if 'release' in sys.argv:
raw_version = ver.split("-")
if "release" in sys.argv:
print("Checking out guiscrcpy to release")
if "releaser" in sys.argv[0] and len(sys.argv) >= 3:
pass
Expand All @@ -94,11 +93,13 @@ def gen_version():
elif len(raw_version) == 2:
# Release Candidate
git_version = "{major}.post{minor}".format(
major=raw_version[0], minor=raw_version[1])
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 All @@ -110,8 +111,7 @@ except Exception as e:

# Attach requirements

setupfile = \
'''#!/usr/bin/env python3
setupfile = '''#!/usr/bin/env python3
"""
{COPYRIGHT}
"""
Expand Down Expand Up @@ -174,8 +174,7 @@ setup(
)
'''

VERSION_FILE = \
'''#!/usr/bin/env python3
VERSION_FILE = '''#!/usr/bin/env python3
"""
{COPYRIGHT}
"""
Expand All @@ -187,35 +186,37 @@ 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", ):
with open(setup, 'w') as w:
w.write(setupfile.format(
for setup in ("setup.py",):
with open(setup, "w") as w:
w.write(
setupfile.format(
COPYRIGHT=COPYRIGHT,
version=v,
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,
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,
))
)
)


with open('guiscrcpy.desktop', 'w') as w:
w.write(DESKTOP_FILE.format(v=v, icon_path='guiscrcpy'))
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'
))
with open("snap/gui/guiscrcpy.desktop", "w") as w:
w.write(DESKTOP_FILE.format(v=v, icon_path="${SNAP}/meta/gui/guiscrcpy.png"))

with open('snap/local/snapcraft.yaml', 'r') as r:
with open("snap/local/snapcraft.yaml", "r") as r:
SNAPCRAFT_FILE = r.read()

with open('snap/snapcraft.yaml', 'w') as w:
with open("snap/snapcraft.yaml", "w") as w:
w.write("name: guiscrcpy\n")
w.write("version: {}\n".format(v))
w.write(SNAPCRAFT_FILE)
Expand Down
Loading

0 comments on commit 1659da1

Please sign in to comment.