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

Commit

Permalink
Update version
Browse files Browse the repository at this point in the history
  • Loading branch information
srevinsaju committed Jul 21, 2020
1 parent b292572 commit 29a7dc2
Show file tree
Hide file tree
Showing 7 changed files with 548 additions and 318 deletions.
2 changes: 1 addition & 1 deletion guiscrcpy.desktop
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Desktop Entry]
Version=4.0.alpha1
Version=4.0.a3
Name=guiscrcpy
GenericName=guiscrcpy
Comment=Open Source Android Screen Mirroring System
Expand Down
49 changes: 40 additions & 9 deletions guiscrcpy/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import hashlib
import logging
import os
import subprocess
import sys
import time
import webbrowser
Expand Down Expand Up @@ -347,10 +348,31 @@
sys.exit(1)

if args.mapper:
from guiscrcpy.lib import mapper
if not args.mapper_device_id:
print("Please pass the --mapper-device-id <device_id> to initialize "
"the mapper")
sys.exit(1)
from guiscrcpy.lib.mapper.mapper import Mapper
# Initialize the mapper if it is called.
print('Initializing guiscrcpy mapper v3.5-')
mapper.file_check()
mp = Mapper(args.mapper_device_id)
if not os.path.exists(
os.path.join(cfgmgr.get_cfgpath(), 'guiscrcpy.mapper.json')):
print("guiscrcpy.mapper.json does not exist. ")
print("Initializing Mapper Configuration for the first time use.")
mp.initialize(initialize_qt=True)
print("Keys registered.")
print('Please run this command again to listen to map keys')
else:
print("guiscrcpy.mapper.json found. Starting the mapper...")
print("Your keyboard is being listened by guiscrcpy-mapper")
print("pressing any key will trigger the position.")
print()
print('If you would like to register new keys, pass --mapper-reset')
print("\nInitializing\n\n")
mp.listen_keypress()
print("Done!")

sys.exit(0)

logger.debug("Importing modules...")
Expand Down Expand Up @@ -518,25 +540,30 @@ def network_mgr(self):
self.nm.show()

def bootstrap_mapper(self):

if (os.path.exists(
os.path.join(cfgmgr.get_cfgpath() + "guiscrcpy.mapper.json"))):
from guiscrcpy.lib import mapper
mapper.file_check()
from guiscrcpy.lib.mapper.mapper import MapperAsync
_, identifier = self.current_device_identifier()
self.mp = MapperAsync(self, identifier, initialize=False)
self.mp.start()
self.private_message_box_adb.setText(
"guiscrcpy-mapper has started"
)
else:
message_box = QMessageBox()
message_box.setText(
"guiscrcpy mapper is not initialized yet."
"Would you like to initialize it now? "
"Please initialize guiscrcpy by running : "
"'guiscrcpy --mapper' on the command line"
)
message_box.setInformativeText(
"Before you initialize, make sure your phone is connected and "
"the display is switched on to map the points."
)
message_box.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
message_box.setStandardButtons(QMessageBox.Ok)
user_message_box_response = message_box.exec()
return
if user_message_box_response == QMessageBox.Ok:
self.private_message_box_adb.setText(
"Initializing mapper in 5 seconds")
Expand All @@ -554,7 +581,8 @@ def bootstrap_mapper(self):
"reset, reset and reset again! :D"
)
print()
mapper.file_check()
_, identifier = self.current_device_identifier()


@staticmethod
def launch_usb_audio():
Expand Down Expand Up @@ -606,12 +634,15 @@ def reset(self):
message_box.addButton("OK", self.quit_window)
message_box.show()

@staticmethod
def quit_window():
def quit_window(self):
"""
A method to quit the main window
:return:
"""
try:
self.mp.exit()
except (AttributeError, KeyboardInterrupt):
pass
sys.exit()

def forget_paired_device(self):
Expand Down
166 changes: 166 additions & 0 deletions guiscrcpy/lib/mapper/ux.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import json
import uuid
import time

from qtpy import QtGui, QtCore, QtWidgets
from qtpy.QtCore import Qt, QThread
from qtpy.QtGui import QPixmap
from guiscrcpy.lib.check import adb


class MapperUI(QtWidgets.QWidget):
"""
Guiscrcpy Mapper User Interface
configuration an button
mapping
"""
def __init__(self, core, screenshot_path, dimensions,
fixed_pos=[0.0, 0.0], final_pos=[0.0, 0.0]):
self.fixed_pos = fixed_pos
self.final_pos = final_pos
self.core = core
self.last_found_point = None
self.image = None
QtWidgets.QWidget.__init__(self)
self.build_user_interface()
self.screenshot_path = screenshot_path
self.dimensions = dimensions
self.set_screenshot_to_label(self.screenshot_path)

def build_user_interface(self):
self.label = QtWidgets.QLabel(self)
self.drawing = False
self.widget = QtWidgets.QWidget(self)
self.widget.setGeometry(QtCore.QRect(0, 0, 351, 34))
self.widget.setObjectName("widget")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.widget)
self.horizontalLayout.setSizeConstraint(
QtWidgets.QLayout.SetMaximumSize)
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout.setObjectName("horizontalLayout")
self.lineEdit = QtWidgets.QLineEdit(self.widget)
size_policy = QtWidgets.QSizePolicy(
QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed)
size_policy.setHorizontalStretch(0)
size_policy.setVerticalStretch(0)
size_policy.setHeightForWidth(
self.lineEdit.sizePolicy().hasHeightForWidth())
self.lineEdit.setSizePolicy(size_policy)
self.lineEdit.setMinimumSize(QtCore.QSize(25, 25))
self.lineEdit.setMaximumSize(QtCore.QSize(25, 16777215))
self.lineEdit.setMaxLength(1)
self.lineEdit.setObjectName("lineEdit")
self.horizontalLayout.addWidget(self.lineEdit)
self.pushButton = QtWidgets.QPushButton(self.widget)
self.pushButton.setMaximumSize(QtCore.QSize(50, 16777215))
self.pushButton.setObjectName("pushButton")
self.horizontalLayout.addWidget(self.pushButton)
self.label0 = QtWidgets.QLabel(self.widget)
self.label0.setMinimumSize(QtCore.QSize(25, 25))
self.label0.setStyleSheet(
"color: rgb(0, 0, 0);\n"
"border-radius: 10px;\n"
"background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, "
"y2:1, stop:0 rgba(61, 255, 0, 255), stop:1 rgba(226, 255, 0, "
"255));\n "
)
self.label0.setAlignment(QtCore.Qt.AlignCenter)
self.label0.setObjectName("label")
self.horizontalLayout.addWidget(self.label0)
self.pushButton.pressed.connect(self.register_key)
self.label.setSizePolicy(
QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Ignored
)
self.label.resize(800, 600)
self.setContentsMargins(0, 0, 0, 0)
self.label.setContentsMargins(0, 0, 0, 0)

def set_screenshot_to_label(self, screenshot_path):
"""
Sets the pixmap of a QLabel to the path provided by the screenshot path
:param screenshot_path: the full path to the screenshot file (*.png)
:type screenshot_path: str
:return: None
:rtype: None
"""
self.pixmap = QtGui.QPixmap(screenshot_path)
self.label.resize(
int(0.5 * self.pixmap.width()),
int(0.5 * self.pixmap.height())
)
self.resize(
int(0.5 * self.pixmap.width()),
int(0.5 * self.pixmap.height())
)

self.show()
self.resize(self.label.size())
self.label.setPixmap(self.pixmap)
self.label.setMinimumSize(1, 1)
self.label.setMaximumSize(
int(0.5 * self.pixmap.width()), int(0.5 * self.pixmap.height())
)
self.setMaximumSize(
int(0.5 * self.pixmap.width()),
int(0.5 * self.pixmap.height())
)
self.label.installEventFilter(self)
layout = QtWidgets.QVBoxLayout(self)
layout.addWidget(self.label)
self.pushButton.setText("OK")
self.label0.setWordWrap(True)
self.label0.setText(
"Click the point, and enter char in textbox and "
"press OK to continue."
)

def register_key(self):
relx = self.fixed_pos[0] / self.label.width()
rely = self.fixed_pos[1] / self.label.height()
fixx = relx * int(self.dimensions[0])
fixy = rely * int(self.dimensions[1])
char = self.lineEdit.text()[:1]
print("Successfully registered {ch} "
"with position ({x}, {y})".format(ch=char, x=fixx, y=fixy))
self.core.add_position(char, (fixx, fixy))
self.label0.setText(
"SUCCESS! "
"Add a new point and enter char; "
"close the window to finish adding."
)

def eventFilter(self, source, event):
if source is self.label and event.type() == QtCore.QEvent.Resize:
self.label.setPixmap(
self.pixmap.scaled(self.label.size(),
QtCore.Qt.KeepAspectRatio)
)
return super(MapperUI, self).eventFilter(source, event)

def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.last_found_point = event.pos()
self.fixed_pos[0] = int(event.pos().x())
self.fixed_pos[1] = int(event.pos().y())
print(self.last_found_point, "LAST")
self.last_found_point = self.label.mapFromParent(
event.pos()) # this is working fine now
# self.label.setPixmap(QPixmap.fromImage(self.image))

def mouseMoveEvent(self, event):
if event.buttons() & Qt.LeftButton:
# painter.setPen(QPen(self.brushColor,
# self.brushSize, Qt.SolidLine, Qt.RoundCap,Qt.RoundJoin))
# painter.drawLine(
# self.label.mapFromParent(event.pos()),self.last_found_point)
self.last_found_point = self.label.mapFromParent(
event.pos()) # this is working fine now
print(self.last_found_point, "MOVE")
self.fixed_pos[0] = int(event.pos().x())
self.fixed_pos[1] = int(event.pos().y())
# self.label.setPixmap(QPixmap.fromImage(self.image))

def mouseReleaseEvent(self, event):
if event.button == Qt.LeftButton:
# self.drawing = False
self.label.setPixmap(QPixmap.fromImage(self.image))
Loading

0 comments on commit 29a7dc2

Please sign in to comment.