Skip to content

Commit

Permalink
v1.1.0 WiFi linux; open website in browser
Browse files Browse the repository at this point in the history
  • Loading branch information
emendir committed Jan 26, 2023
1 parent 731b47f commit 36d045b
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 128 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# v1.1.0 (2023-01-26)
- auto-connect to wifi networks now works on linux (provided that the nmcli tool is installed)
- automatically open scanned http and https URLs in a browser
84 changes: 40 additions & 44 deletions QR-ScanGen.spec
Original file line number Diff line number Diff line change
@@ -1,44 +1,40 @@
# -*- mode: python ; coding: utf-8 -*-


block_cipher = None


a = Analysis(
['__main__.py'],
pathex=[],
binaries=[],
datas=[('Icon.svg', '.')],
hiddenimports=['pywifi', 'pyzbar', 'qrcode'],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

exe = EXE(
pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='QR-ScanGen',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=False,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)
# -*- mode: python ; coding: utf-8 -*-


block_cipher = None


a = Analysis(['__main__.py'],
pathex=[],
binaries=[('C:\\Users\\weden\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\pyzbar\\libiconv.dll', '.'), ('C:\\Users\\weden\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\pyzbar\\libzbar-64.dll', '.')],
datas=[('Icon.svg', '.')],
hiddenimports=['pywifi', 'pyzbar', 'qrcode'],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)

exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='QR-ScanGen',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=False,
disable_windowed_traceback=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None )
143 changes: 72 additions & 71 deletions ScanGen.py
Original file line number Diff line number Diff line change
@@ -1,71 +1,72 @@
# -*- coding: utf-8 -*-

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


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName("verticalLayout")
self.images_frm = QtWidgets.QFrame(self.centralwidget)
self.images_frm.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.images_frm.setFrameShadow(QtWidgets.QFrame.Raised)
self.images_frm.setObjectName("images_frm")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.images_frm)
self.horizontalLayout.setObjectName("horizontalLayout")
self.scanner_video_lbl = QtWidgets.QLabel(self.images_frm)
self.scanner_video_lbl.setText("")
self.scanner_video_lbl.setObjectName("scanner_video_lbl")
self.horizontalLayout.addWidget(self.scanner_video_lbl)
self.right_frame = QtWidgets.QFrame(self.images_frm)
self.right_frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.right_frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.right_frame.setObjectName("right_frame")
self.right_frame_lyt = QtWidgets.QVBoxLayout(self.right_frame)
self.right_frame_lyt.setObjectName("right_frame_lyt")
self.qr_code_lbl = QtWidgets.QLabel(self.right_frame)
self.qr_code_lbl.setText("")
self.qr_code_lbl.setObjectName("qr_code_lbl")
self.right_frame_lyt.addWidget(self.qr_code_lbl)
self.label = QtWidgets.QLabel(self.right_frame)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth())
self.label.setSizePolicy(sizePolicy)
self.label.setMaximumSize(QtCore.QSize(16777215, 30))
self.label.setObjectName("label")
self.right_frame_lyt.addWidget(self.label)
self.horizontalLayout.addWidget(self.right_frame)
self.verticalLayout.addWidget(self.images_frm)
self.text_txbx = QtWidgets.QPlainTextEdit(self.centralwidget)
self.text_txbx.setMaximumSize(QtCore.QSize(16777215, 200))
self.text_txbx.setObjectName("text_txbx")
self.verticalLayout.addWidget(self.text_txbx)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)

self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.label.setText(_translate("MainWindow", "Available Cameras:"))
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file '.\ScanGen.ui'
#
# Created by: PyQt5 UI code generator 5.15.6
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName("verticalLayout")
self.images_frm = QtWidgets.QFrame(self.centralwidget)
self.images_frm.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.images_frm.setFrameShadow(QtWidgets.QFrame.Raised)
self.images_frm.setObjectName("images_frm")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.images_frm)
self.horizontalLayout.setObjectName("horizontalLayout")
self.scanner_video_lbl = QtWidgets.QLabel(self.images_frm)
self.scanner_video_lbl.setText("")
self.scanner_video_lbl.setObjectName("scanner_video_lbl")
self.horizontalLayout.addWidget(self.scanner_video_lbl)
self.right_frame = QtWidgets.QFrame(self.images_frm)
self.right_frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.right_frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.right_frame.setObjectName("right_frame")
self.right_frame_lyt = QtWidgets.QVBoxLayout(self.right_frame)
self.right_frame_lyt.setObjectName("right_frame_lyt")
self.qr_code_lbl = QtWidgets.QLabel(self.right_frame)
self.qr_code_lbl.setText("")
self.qr_code_lbl.setObjectName("qr_code_lbl")
self.right_frame_lyt.addWidget(self.qr_code_lbl)
self.label = QtWidgets.QLabel(self.right_frame)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth())
self.label.setSizePolicy(sizePolicy)
self.label.setMaximumSize(QtCore.QSize(16777215, 30))
self.label.setObjectName("label")
self.right_frame_lyt.addWidget(self.label)
self.horizontalLayout.addWidget(self.right_frame)
self.verticalLayout.addWidget(self.images_frm)
self.text_txbx = QtWidgets.QPlainTextEdit(self.centralwidget)
self.text_txbx.setMaximumSize(QtCore.QSize(16777215, 200))
self.text_txbx.setObjectName("text_txbx")
self.verticalLayout.addWidget(self.text_txbx)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)

self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.label.setText(_translate("MainWindow", "Available Cameras:"))
51 changes: 39 additions & 12 deletions __main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import time
import os
import pyperclip
import webbrowser
import platform

if __file__ and os.path.exists(__file__):
os.chdir(os.path.dirname(__file__))
Expand All @@ -32,10 +34,6 @@ def QR_Decoder(image):
return {"image": image, "type": obj.type, "data": obj.data}


def GenerateQrCode(text):
return qrcode.make(text)


if os.path.exists('ScanGen.ui'):
Ui_MainWindow, QMainWindow = loadUiType('ScanGen.ui')
else:
Expand Down Expand Up @@ -70,7 +68,8 @@ def __init__(self, ):
print("ready")

def UpdateQrCode(self):
qr_code = GenerateQrCode(self.data)
qr_code = self.GenerateQrCode(self.data)

image = ImageQt(qr_code)
self.qr_code_lbl.setPixmap(QtGui.QPixmap.fromImage(image))

Expand Down Expand Up @@ -173,9 +172,9 @@ def RunScanner(self):

self.data = self.text_txbx.toPlainText()
self.update_qr_code.emit()
image = QtGui.QImage(
self.camera_image = QtGui.QImage(
frame.data, frame.shape[1], frame.shape[0], QtGui.QImage.Format_RGB888).rgbSwapped()
self.scanner_video_lbl.setPixmap(QtGui.QPixmap.fromImage(image))
self.scanner_video_lbl.setPixmap(QtGui.QPixmap.fromImage(self.camera_image))

code = cv2.waitKey(10)
if code == ord('q'):
Expand Down Expand Up @@ -216,17 +215,45 @@ def AnalyseCode(self):
# profile.cipher = pywifi.const.CIPHER_TYPE_CCMP
profile.key = password

wifi = pywifi.PyWiFi()
iface = wifi.interfaces()[0]
profile = iface.add_network_profile(profile)
iface.connect(profile)
# ERROR permission denied on ubuntu
try:
wifi = pywifi.PyWiFi()
iface = wifi.interfaces()[0]
profile = iface.add_network_profile(profile)
iface.connect(profile)
except PermissionError:
# handling permission denied error on linux
if platform.system() == 'Linux':
os.system(f"nmcli dev wifi connect '{ssid}' password '{password}'")

if IsWebsite(self.data):
webbrowser.open_new_tab(self.data)

def GenerateQrCode(self, text):
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=3,
border=4, # number of pixels is this * box_size
)
qr.add_data(text) # give QRCode object our text to encode
qr.make(fit=True) # generate QR code from our text
# we would like our QR code to be about as high as the camera image displayed
desired_height = self.camera_image.height()
# get the number of squares along an edge of the QR code
qr_height_squares = len(qr.get_matrix())
# calculate how many pixels should be used to display one square of the QR code
qr.box_size = int((desired_height)/(qr_height_squares+2*qr.border))
return qr.make_image() # generate and return QR code image

def closeEvent(self, event):
self.closing = True
event.accept()


def IsWebsite(text):
return text.startswith("https://") or text.startswith("http://")


if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
Expand Down
2 changes: 1 addition & 1 deletion __project__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
project_name = "QR-ScanGen"
version = "1.0.0"
version = "1.1.0"

0 comments on commit 36d045b

Please sign in to comment.