Ejemplo n.º 1
0
 def __init__(self, adb_path=None):
     QMainWindow.__init__(self)
     Ui_NetworkUI.__init__(self)
     self.os = System()
     self.setupUi(self)
     adb.path = adb_path
     self.nm = NetworkManager()
Ejemplo n.º 2
0
 def __init__(self, adb):
     QMainWindow.__init__(self)
     Ui_NetworkUI.__init__(self)
     self.os = System()
     self.setupUi(self)
     self.adb = adb
     self.nm = NetworkManager()
Ejemplo n.º 3
0
def wmctrl_xdotool_linux_send_key(key):
    assert isinstance(key, str)
    assert System.system() == "Linux"
    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")
        return
    _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)),
            stdout=sys.stdout,
            stderr=sys.stderr,
        )
        if _xdotool_proc.wait() != 0:
            print("E (xdotool): Failed to send key {} to "
                  "scrcpy window.".format(key))
    else:
        print("E (wmctrl): Failed to get scrcpy window. "
              "(Is scrcpy running?)")
Ejemplo n.º 4
0
class InterfaceNetwork(QMainWindow, Ui_NetworkUI):
    """
    Network manager UI UX Kit for guiscrcpy
    Scans the open IP Addresses connected on the system,
    on Linux and Mac only, as far as tested
    Does not work satisfactorily on Windows.
    """
    def __init__(self, adb_path=None):
        QMainWindow.__init__(self)
        Ui_NetworkUI.__init__(self)
        self.os = System()
        self.setupUi(self)
        adb.path = adb_path
        self.nm = NetworkManager()

    def init(self):
        """
        Connect buttons to sig
        :return:
        """
        self.nm_connect.pressed.connect(self.connect)
        if self.os.system() == 'Windows':
            # FIXME: Port scanning is not working on Windows at the moment.
            self.nm_det.setText(
                "Enter the IP address in the text box and press connect")
            self.nm_refresh.setEnabled(False)
        else:
            self.nm_refresh.pressed.connect(self.refresh)
            self.nm_det.setText("Click Refresh to load IP addresses")
        self.tcpip.pressed.connect(self.tcpip_launch)

    def tcpip_launch(self):
        adb.command(adb.path, '-d tcpip 5555')
        self.nm_det.setText(
            "Now disconnect your device, and enter the IP address, and connect"
        )
        return

    def connect(self):
        try:
            ip = self.listView.currentItem().text()
        except AttributeError:
            # The IP Address in the ListView has precedence over the IP address
            # in the text box
            if not self.lineEdit.text().strip().isspace() or len(
                    self.lineEdit.text().strip()) != 0:
                if self.lineEdit.text().count('.') == 3:
                    ip = self.lineEdit.text().strip().lower()
                else:
                    self.nm_det.setText("Invalid IP address in text box")
                    return
            else:
                if self.os.system() == 'Windows':
                    self.nm_det.setText(
                        "Please enter an IP address in the text box")
                else:
                    self.nm_det.setText(
                        "Please enter an IP address in the text box. / "
                        "Click refresh")
                return

        sp = adb.command(adb.path, 'connect {}:5555'.format(ip))
        count = 0
        while True:
            count += 1
            readout = sp.stdout.readline().decode()
            if 'failed' in readout:
                self.nm_det.setText(
                    'Device failed to get connected (is it an Android dev?')
                return
            if 'connected' in readout:
                print(readout)
                break
            if count > 30:
                self.nm_det.setText('Device connect failed: Timeout')
            else:
                time.sleep(1)
        self.nm_det.setText("Connected to IP:{}:{}".format(
            ip, self.spinBox.value()))

    def refresh(self):
        self.listView.clear()
        self.listView.addItems(self.nm.map_network())
Ejemplo n.º 5
0
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.
"""

import logging
from subprocess import Popen, PIPE, call, TimeoutExpired

from guiscrcpy.lib.utils import decode_process, check_existence, shellify as _
from guiscrcpy.platform.platform import System

environment = System()


def get(ls, idx, default=""):
    try:
        return ls[idx]
    except IndexError:
        return default


def _get_dimension_raw_noexcept(path, device_id=None):
    if device_id:
        shell_adb = Popen(_("{} -s {} shell wm size".format(path, device_id)),
                          stdout=PIPE,
                          stderr=PIPE)
    else:
Ejemplo n.º 6
0
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.
"""
import hashlib
import logging
import os

from guiscrcpy.lib.check import adb
from guiscrcpy.platform.platform import System

if System.system() == "Windows":
    try:
        import pyautogui as auto
        from pygetwindow import getWindowsWithTitle
    except ModuleNotFoundError as e:
        logging.debug("pygetwindow, pyautogui "
                      "failed with error code {}".format(e))
        auto = None
        getWindowsWithTitle = None
else:
    auto = None
    getWindowsWithTitle = None


class UXMapper:
    def __init__(self, device_id=None):