diff --git a/guiscrcpy/lib/check.py b/guiscrcpy/lib/check.py index 58bc76e5..8e003b2d 100644 --- a/guiscrcpy/lib/check.py +++ b/guiscrcpy/lib/check.py @@ -96,7 +96,8 @@ def get_dimensions(path): return dimValues else: logging.error( - "AndroidDeviceError: adb shell wm size did not return 'Physical Size' or 'Override Size'") + "AndroidDeviceError: adb shell wm size did not return 'Physical Size' or 'Override Size'" + ) return False @staticmethod diff --git a/guiscrcpy/lib/mapper.py b/guiscrcpy/lib/mapper.py index d542b5de..8a32a71e 100644 --- a/guiscrcpy/lib/mapper.py +++ b/guiscrcpy/lib/mapper.py @@ -17,7 +17,8 @@ along with this program. If not, see . """ - +from guiscrcpy.lib.config import InterfaceConfig +from guiscrcpy.lib.check import adb import argparse from subprocess import PIPE, Popen from pynput import keyboard @@ -37,16 +38,11 @@ fixedpos = [0, 0] finalpos = [0, 0] +cfgmgr = InterfaceConfig() +config = cfgmgr.get_config() +adb.path = config['adb'] jsong = 'guiscrcpy.mapper.json' -if platform.system() == "Windows": - if os.path.isfile("./scrcpy.exe"): - increment = ".\\" - # print(bcolors.BOLD + "LOG: Found scrcpy.exe in current directory.") - else: - increment = "" -else: - increment = "" print("+++++++++++++++++++++++++++++++++++++++") print("guiscrcpy ~ mapper by srevinsaju") @@ -55,19 +51,10 @@ print('With USB debugging turned on.') print("+++++++++++++++++++++++++++++++++++++++") print("Waiting for device") -po(increment + "adb wait-for-any-device", shell=True) +adb.command(adb.path, 'wait-for-any-device') print("Device : OK!") - -# Declare key_a. path position -if (platform.system() == 'Windows'): - cfgpath = os.path.expanduser("~/AppData/Local/guiscrcpy/") -else: - if (os.getenv('XDG_CONFIG_HOME') is None): - cfgpath = os.path.expanduser("~/.config/guiscrcpy/") - else: - cfgpath = os.getenv('XDG_CONFIG_HOME').split(":")[0] + "/guiscrcpy/" - +cfgpath = cfgmgr.cfgpath parser = argparse.ArgumentParser() parser.add_argument('-t', '--delay', default=10, @@ -76,20 +63,7 @@ help="Remove prefernces") args = parser.parse_args() -adb_dim = po( - "adb shell wm size", shell=True, stdout=PIPE, stderr=PIPE -) - -out = adb_dim.stdout.read() -out_decoded = out.decode("utf-8") -out_decoded = out_decoded[:-1] -dimVal = out_decoded.split(": ") -try: - dimensions_ = dimVal[1] - dimValues = dimensions_.split("x") - print(dimValues, " DIMENSIONS ") -except: - print("Error Device not connected") +dimensions = adb.get_dimensions(adb.path) class MapperUI(QtWidgets.QWidget): @@ -181,8 +155,8 @@ def keyreg(self): #print("REL POS :: ", fixedpos) relx = fixedpos[0]/self.label.width() rely = fixedpos[1]/self.label.height() - fixx = relx * int(dimValues[0]) - fixy = rely * int(dimValues[1]) + fixx = relx * int(dimensions[0]) + fixy = rely * int(dimensions[1]) print("FINALIZED POS :: ", fixx, fixy) finalpos[0] = fixx @@ -255,7 +229,6 @@ def on_press0(key): try: if key.char in key_a.keys(): - print(key.char) print("running cmd") finalpos0 = key_a[key.char] @@ -278,17 +251,11 @@ def on_press0(key): def sth(): import sys - app = QtWidgets.QApplication(sys.argv) window = MapperUI() - sys.exit(app.exec_()) -def sth_w0(): - pass - - def file_check(): jsong = 'guiscrcpy.mapper.json' @@ -373,15 +340,13 @@ def file_checkm(): ) if not fileExist: - # Init json file for first time use key_a = {"key": [], "pos": []} - with open(cfgpath + jsong, 'w') as f: + with open(os.path.join(cfgpath, jsong), 'w') as f: json.dump(key_a, f) - sth_w0() elif fileExist: - with open(cfgpath + jsong, 'r') as f: + with open(os.path.join(cfgpath, jsong), 'r') as f: key_a = json.load(f) listen_keypress(key_a)