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

Commit

Permalink
Flake8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
srevinsaju committed Apr 18, 2020
1 parent bea7f92 commit bbf33b2
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 74 deletions.
20 changes: 13 additions & 7 deletions guiscrcpy/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,25 +336,31 @@ def refresh_devices_combo(self):
invalid_devices = []
for dev, stat in devices_list:
if stat == "unauthorized":
invalid_devices.append(f"{dev} IS UNAUTHORIZED. CLICK 'ok' when asked.")
invalid_devices.append(
f"{dev} IS UNAUTHORIZED. CLICK 'ok' when asked.")
elif stat == "device":
valid_devices.append(dev)
else:
invalid_devices.append(f"{dev} is connected. Failed to establish connection")
invalid_devices.append(
f"{dev} is connected. Failed to establish connection")
self.runningNot.setText(
"Connected: {};".format(', '.join(valid_devices))
)
if len(valid_devices) > 1:
if self.devices_combox.currentText() == '' or self.devices_combox.currentText().isspace():
logging.info("Found more than one device. Please select device in drop down box")
self.runningNot.setText("Found more than one device. Please select device in drop down box")
logging.info(
"Found more than one device. Please select device in drop down box")
self.runningNot.setText(
"Found more than one device. Please select device in drop down box")
self.devices_combox.clear()
self.devices_combox.addItems([f"{x[0]} : {x[1]}" for x in devices_list])
self.devices_combox.addItems(
[f"{x[0]} : {x[1]}" for x in devices_list])
return 0,

else:
more_devices = True
device_id = self.devices_combox.currentText().split(":")[0].strip()
device_id = self.devices_combox.currentText().split(":")[
0].strip()
else:
more_devices = False
device_id = None
Expand Down Expand Up @@ -444,7 +450,7 @@ def start_act(self):

dimValues = adb.get_dimensions(adb.path, device_id=device_id)
self.progressBar.setValue(70)

swipe_instance.init()
panel_instance.init()
side_instance.init()
Expand Down
23 changes: 15 additions & 8 deletions guiscrcpy/lib/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ def shell_input(path, command, device_id=None):
@staticmethod
def get_dimensions(path, device_id=None):
if device_id:
shellx = Popen(_("{} -s {} shell wm size".format(path, device_id)), stdout=PIPE, stderr=PIPE)
shellx = Popen(
_("{} -s {} shell wm size".format(path, device_id)), stdout=PIPE, stderr=PIPE)
else:
shellx = Popen(_("{} shell wm size".format(path)), stdout=PIPE, stderr=PIPE)
shellx = Popen(_("{} shell wm size".format(path)),
stdout=PIPE, stderr=PIPE)
raw_dimensions = shellx.stdout.read().decode().strip('\n')
for i in ['Override size', 'Physical size']:
if i in raw_dimensions:
Expand All @@ -109,17 +111,21 @@ def get_dimensions(path, device_id=None):
@staticmethod
def shell(path, command, device_id=None):
if device_id:
shellx = Popen(_("{} -s {} shell {}".format(path, device_id, command)), stdout=PIPE, stderr=PIPE)
shellx = Popen(_("{} -s {} shell {}".format(path,
device_id, command)), stdout=PIPE, stderr=PIPE)
else:
shellx = Popen(_("{} shell {}".format(path, command)), stdout=PIPE, stderr=PIPE)
shellx = Popen(_("{} shell {}".format(path, command)),
stdout=PIPE, stderr=PIPE)
return True

@staticmethod
def command(path, command, device_id=None):
if device_id:
shellx = Popen(_("{} -s {} {}".format(path, device_id, command)), stdout=PIPE, stderr=PIPE)
shellx = Popen(
_("{} -s {} {}".format(path, device_id, command)), stdout=PIPE, stderr=PIPE)
else:
shellx = Popen(_("{} {}".format(path, command)), stdout=PIPE, stderr=PIPE)
shellx = Popen(_("{} {}".format(path, command)),
stdout=PIPE, stderr=PIPE)
return shellx

@staticmethod
Expand All @@ -128,7 +134,8 @@ def devices(increment=''):
raise FileNotFoundError(
"guiscrcpy couldn't find adb. Please specify path to adb in configuration file")
proc = Popen(_(increment + " devices"), stdout=PIPE)
output = [[y.strip() for y in x.split('\t')] for x in decode_process(proc)[1:]][:-1]

output = [[y.strip() for y in x.split('\t')]
for x in decode_process(proc)[1:]][:-1]

logging.debug("ADB: {}".format(output))
return output
21 changes: 14 additions & 7 deletions guiscrcpy/lib/toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ def __init__(self, device_id=None):
logging.debug("Launching UX Mapper")
self.has_modules = getWindowsWithTitle and auto
logging.debug("Calculating Screen Size")
self.android_dimensions = adb.get_dimensions(adb.path, device_id=device_id)
self.android_dimensions = adb.get_dimensions(
adb.path, device_id=device_id)
self.deviceId = device_id

def do_swipe(self, x1=10, y1=10, x2=10, y2=10):
adb.shell_input(adb.path, "swipe {} {} {} {}".format(x1, y1, x2, y2), device_id=self.deviceId)
adb.shell_input(adb.path, "swipe {} {} {} {}".format(
x1, y1, x2, y2), device_id=self.deviceId)
return True

def do_keyevent(self, key):
adb.shell_input(adb.path, "keyevent {}".format(key), device_id=self.deviceId)
adb.shell_input(adb.path, "keyevent {}".format(key),
device_id=self.deviceId)
return True

def copy_devpc(self):
Expand Down Expand Up @@ -87,13 +90,17 @@ def key_switch(self):

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

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

def expand_notifications(self):
logging.debug("Passing NOTIF EXPAND")
Expand Down
7 changes: 4 additions & 3 deletions guiscrcpy/platform/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def install_fonts():
if not os.path.exists(sys_font_dir):
os.makedirs(sys_font_dir)
from fontTools.ttLib import TTFont
font_dir = os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(__file__))), 'ui', 'fonts')
font_dir = os.path.join(os.path.abspath(
os.path.dirname(os.path.dirname(__file__))), 'ui', 'fonts')
try:
fonts = os.listdir(font_dir)
for i in fonts:
Expand All @@ -109,8 +110,8 @@ def install_fonts():
return True
except Exception as e:
logging.error("Error Installing the fonts. "
"You might have to manually install the fonts"
"Titillium Web : https://fonts.google.com/specimen/Titillium+Web")
"You might have to manually install the fonts"
"Titillium Web : https://fonts.google.com/specimen/Titillium+Web")
return False

@staticmethod
Expand Down
9 changes: 5 additions & 4 deletions guiscrcpy/platform/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def make_config():
except Exception as e:
logging.error(
"Error creating configuration file in dir {path}. Error code:{e}"
.format(
.format(
path=path,
e=e
))
Expand Down Expand Up @@ -68,7 +68,8 @@ def install_fonts(self):
cmd = r"""copy "{fontdir}" "%WINDIR%\Fonts"
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /
v "FontName (TrueType)" / t REG_SZ / d {font} / f """
font_dir = os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(__file__))), 'ui', 'fonts')
font_dir = os.path.join(os.path.abspath(
os.path.dirname(os.path.dirname(__file__))), 'ui', 'fonts')
try:
fonts = os.listdir(font_dir)
for i in fonts:
Expand All @@ -79,8 +80,8 @@ def install_fonts(self):
except Exception as e:
print("Installing fonts failed")
logging.error("Error Installing the fonts. "
"You might have to manually install the fonts"
"Titillium Web : https://fonts.google.com/specimen/Titillium+Web")
"You might have to manually install the fonts"
"Titillium Web : https://fonts.google.com/specimen/Titillium+Web")
return False

def create_desktop(self):
Expand Down
15 changes: 9 additions & 6 deletions guiscrcpy/platform/windows_tools/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
Create desktop shortcuts for Windows
"""
from __future__ import print_function
from win32com.shell import shell, shellcon
import win32com.client
import os
import sys
import time
from collections import namedtuple
UserFolders = namedtuple("UserFolders", ("home", "desktop", "startmenu"))
import win32com.client
from win32com.shell import shell, shellcon

scut_ext = 'lnk'
ico_ext = 'ico'


def get_conda_active_env():
'''Return name of active conda environment or empty string'''
conda_env = None
Expand All @@ -24,6 +25,7 @@ def get_conda_active_env():
conda_env = ""
return conda_env


# batch file to activate the environment
# for Anaconda Python before running command.
conda_env = get_conda_active_env()
Expand Down Expand Up @@ -75,14 +77,15 @@ def get_folders():
"""
return UserFolders(get_homedir(), get_desktop(), get_startmenu())


def make_shortcut():
userfolders = get_folders()

full_script = 'guiscrcpy'
desktop, startmenu = True, True
for (create, folder) in ((desktop,userfolders.desktop),
for (create, folder) in ((desktop, userfolders.desktop),
(startmenu, userfolders.startmenu)):

if not os.path.exists(folder):
os.makedirs(folder)
dest = os.path.join(folder, "guiscrcpy.lnk")
Expand All @@ -93,7 +96,7 @@ def make_shortcut():
wscript.WindowStyle = 0
wscript.Description = "An Open Source Android Screen Mirroring System"
wscript.IconLocation = os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))),
'ui', 'icons', 'guiscrcpy_logo_SRj_icon.ico')
'ui', 'icons', 'guiscrcpy_logo_SRj_icon.ico')
wscript.save()

return True
return True
Loading

0 comments on commit bbf33b2

Please sign in to comment.