-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from Carifio24/local-qr-code
Add tool for displaying local QR code for AR view
- Loading branch information
Showing
14 changed files
with
260 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import os | ||
from io import BytesIO | ||
from PIL import Image | ||
import socket | ||
import segno | ||
|
||
|
||
GLUE_LOGO = os.path.abspath(os.path.join(os.path.dirname(__file__), "logo.png")) | ||
GLUE_RED = "#eb1c24" | ||
|
||
|
||
def get_local_ip(): | ||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | ||
s.settimeout(0) | ||
try: | ||
# doesn't even have to be reachable | ||
s.connect(('10.254.254.254', 1)) | ||
IP = s.getsockname()[0] | ||
except Exception: | ||
IP = '127.0.0.1' | ||
finally: | ||
s.close() | ||
return IP | ||
|
||
|
||
def create_qr(url): | ||
qr = segno.make_qr(url) | ||
out = BytesIO() | ||
qr.save(out, kind="png", scale=7, dark=GLUE_RED, light="white") | ||
out.seek(0) | ||
img = Image.open(out) | ||
img = img.convert("RGB") | ||
width, height = img.size | ||
logo_max_size = height // 3 | ||
logo_img = Image.open(GLUE_LOGO) | ||
# Resize the logo to logo_max_size | ||
logo_img.thumbnail((logo_max_size, logo_max_size), Image.Resampling.LANCZOS) | ||
# Calculate the center of the QR code | ||
box = ((width - logo_img.size[0]) // 2, (height - logo_img.size[1]) // 2) | ||
img.paste(logo_img, box) | ||
return img | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from os.path import dirname | ||
|
||
from PIL.ImageQt import ImageQt | ||
from glue_qt.utils import load_ui | ||
from qtpy.QtWidgets import QDialog, QSizePolicy | ||
from qtpy.QtGui import QPixmap | ||
|
||
|
||
class QRDialog(QDialog): | ||
|
||
def __init__(self, parent=None, img=None): | ||
|
||
super(QRDialog, self).__init__(parent=parent) | ||
|
||
self.img = ImageQt(img) | ||
self.pix = QPixmap.fromImage(self.img) | ||
self.ui = load_ui("qr_dialog.ui", self, directory=dirname(__file__)) | ||
self.ui.label_image.setPixmap(self.pix) | ||
self.setFixedSize(300, 325) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>Dialog</class> | ||
<widget class="QDialog" name="Dialog"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>315</width> | ||
<height>351</height> | ||
</rect> | ||
</property> | ||
<property name="sizePolicy"> | ||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> | ||
<horstretch>0</horstretch> | ||
<verstretch>0</verstretch> | ||
</sizepolicy> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>View in AR</string> | ||
</property> | ||
<widget class="QLabel" name="label_message"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>9</x> | ||
<y>9</y> | ||
<width>300</width> | ||
<height>32</height> | ||
</rect> | ||
</property> | ||
<property name="sizePolicy"> | ||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> | ||
<horstretch>0</horstretch> | ||
<verstretch>0</verstretch> | ||
</sizepolicy> | ||
</property> | ||
<property name="text"> | ||
<string>Note: This QR code will only work for devices | ||
connected to the same network as this computer</string> | ||
</property> | ||
</widget> | ||
<widget class="QLabel" name="label_image"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>10</x> | ||
<y>50</y> | ||
<width>300</width> | ||
<height>300</height> | ||
</rect> | ||
</property> | ||
<property name="sizePolicy"> | ||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> | ||
<horstretch>0</horstretch> | ||
<verstretch>0</verstretch> | ||
</sizepolicy> | ||
</property> | ||
<property name="text"> | ||
<string/> | ||
</property> | ||
</widget> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from os.path import split | ||
|
||
from http.server import SimpleHTTPRequestHandler | ||
from socketserver import TCPServer | ||
|
||
def create_handler(directory): | ||
|
||
class ARHttpRequestHandler(SimpleHTTPRequestHandler): | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, directory=directory, **kwargs) | ||
|
||
return ARHttpRequestHandler | ||
|
||
|
||
def run_ar_server(port, directory): | ||
handler_cls = create_handler(directory) | ||
server = TCPServer(("", port), handler_cls) | ||
return server |
Oops, something went wrong.