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

Commit

Permalink
Add support for typing manual ip adress instead of portscanning
Browse files Browse the repository at this point in the history
  • Loading branch information
srevinsaju committed Apr 18, 2020
1 parent c1f86bd commit 6d09c7d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 29 deletions.
55 changes: 30 additions & 25 deletions guiscrcpy/ui/network.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'network.ui'
# Form implementation generated from reading ui file 'guiscrcpy/ui/network.ui'
#
# Created by: PyQt5 UI code generator 5.14.1
# Created by: PyQt5 UI code generator 5.14.2
#
# WARNING! All changes made in this file will be lost!

Expand All @@ -14,29 +14,29 @@ class Ui_NetworkUI(object):
def setupUi(self, NetworkUI):
NetworkUI.setObjectName("NetworkUI")
NetworkUI.setWindowModality(QtCore.Qt.ApplicationModal)
NetworkUI.resize(328, 337)
NetworkUI.resize(374, 414)
self.centralwidget = QtWidgets.QWidget(NetworkUI)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(2, 5, 143, 18))
self.label.setObjectName("label")
self.widget = QtWidgets.QWidget(self.centralwidget)
self.widget.setGeometry(QtCore.QRect(2, 29, 321, 281))
self.widget.setGeometry(QtCore.QRect(2, 5, 371, 381))
self.widget.setObjectName("widget")
self.gridLayout = QtWidgets.QGridLayout(self.widget)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout = QtWidgets.QVBoxLayout(self.widget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout")
self.label = QtWidgets.QLabel(self.widget)
self.label.setObjectName("label")
self.verticalLayout.addWidget(self.label)
self.gridLayout = QtWidgets.QGridLayout()
self.gridLayout.setObjectName("gridLayout")
self.listView = QtWidgets.QListWidget(self.widget)
self.listView.setObjectName("listView")
self.gridLayout.addWidget(self.listView, 0, 0, 1, 2)
self.nm_refresh = QtWidgets.QPushButton(self.widget)
self.nm_refresh.setObjectName("nm_refresh")
self.gridLayout.addWidget(self.nm_refresh, 4, 0, 1, 1)
self.nm_det = QtWidgets.QPushButton(self.widget)
self.nm_det.setEnabled(False)
self.nm_det.setText("")
self.nm_det.setObjectName("nm_det")
self.gridLayout.addWidget(self.nm_det, 1, 0, 1, 2)
self.gridLayout.addWidget(self.nm_refresh, 5, 0, 1, 1)
self.tcpip = QtWidgets.QPushButton(self.widget)
self.tcpip.setObjectName("tcpip")
self.gridLayout.addWidget(self.tcpip, 4, 1, 1, 1)
self.spinBox = QtWidgets.QSpinBox(self.widget)
font = QtGui.QFont()
font.setBold(True)
Expand All @@ -47,13 +47,19 @@ def setupUi(self, NetworkUI):
self.spinBox.setMaximum(9999)
self.spinBox.setProperty("value", 5555)
self.spinBox.setObjectName("spinBox")
self.gridLayout.addWidget(self.spinBox, 3, 0, 1, 1)
self.gridLayout.addWidget(self.spinBox, 4, 0, 1, 1)
self.nm_connect = QtWidgets.QPushButton(self.widget)
self.nm_connect.setObjectName("nm_connect")
self.gridLayout.addWidget(self.nm_connect, 4, 1, 1, 1)
self.tcpip = QtWidgets.QPushButton(self.widget)
self.tcpip.setObjectName("tcpip")
self.gridLayout.addWidget(self.tcpip, 3, 1, 1, 1)
self.gridLayout.addWidget(self.nm_connect, 5, 1, 1, 1)
self.nm_det = QtWidgets.QPushButton(self.widget)
self.nm_det.setEnabled(False)
self.nm_det.setText("")
self.nm_det.setObjectName("nm_det")
self.gridLayout.addWidget(self.nm_det, 2, 0, 1, 2)
self.lineEdit = QtWidgets.QLineEdit(self.widget)
self.lineEdit.setObjectName("lineEdit")
self.gridLayout.addWidget(self.lineEdit, 1, 0, 1, 2)
self.verticalLayout.addLayout(self.gridLayout)
NetworkUI.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(NetworkUI)
self.statusbar.setObjectName("statusbar")
Expand All @@ -66,12 +72,11 @@ def retranslateUi(self, NetworkUI):
_translate = QtCore.QCoreApplication.translate
NetworkUI.setWindowTitle(_translate("NetworkUI", "Network Manager"))
self.label.setText(_translate("NetworkUI", "List of Network Devices"))
self.nm_refresh.setStatusTip(_translate(
"NetworkUI", "Refresh Devices list"))
self.nm_refresh.setStatusTip(_translate("NetworkUI", "Refresh Devices list"))
self.nm_refresh.setText(_translate("NetworkUI", "REFRESH"))
self.tcpip.setText(_translate("NetworkUI", "TCPIP"))
self.spinBox.setToolTip(_translate("NetworkUI", "Port number"))
self.spinBox.setStatusTip(_translate("NetworkUI", "Port number"))
self.nm_connect.setStatusTip(_translate(
"NetworkUI", "Establish connection"))
self.nm_connect.setStatusTip(_translate("NetworkUI", "Establish connection"))
self.nm_connect.setText(_translate("NetworkUI", "CONNECT"))
self.tcpip.setText(_translate("NetworkUI", "TCPIP"))
self.lineEdit.setPlaceholderText(_translate("NetworkUI", "Cannot find your IP address? Enter it manually here"))
36 changes: 32 additions & 4 deletions guiscrcpy/ux/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,39 @@
import time

from PyQt5.QtWidgets import QMainWindow

from guiscrcpy.platform.platform import System
from guiscrcpy.network.network import NetworkManager
from guiscrcpy.ui.network import Ui_NetworkUI
from guiscrcpy.lib.check import adb


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)
self.nm_refresh.pressed.connect(self.refresh)
self.nm_det.setText("Click Refresh to load IP addresses")
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):
Expand All @@ -49,7 +64,20 @@ def connect(self):
try:
ip = self.listView.currentItem().text()
except AttributeError:
return
# 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:
Expand Down

0 comments on commit 6d09c7d

Please sign in to comment.