Add network printer detection on Windows: support printers from print servers
This commit is contained in:
@@ -39,8 +39,8 @@ echo.
|
|||||||
|
|
||||||
REM Install dependencies
|
REM Install dependencies
|
||||||
echo [3/5] Installing dependencies...
|
echo [3/5] Installing dependencies...
|
||||||
echo Installing: python-barcode, pillow, reportlab, kivy, pyinstaller...
|
echo Installing: python-barcode, pillow, reportlab, kivy, pyinstaller, pywin32, wmi...
|
||||||
pip install python-barcode pillow reportlab kivy==2.3.1 pyinstaller==6.18.0
|
pip install python-barcode pillow reportlab kivy==2.2.1 pyinstaller==6.1.0 pywin32 wmi
|
||||||
if errorlevel 1 (
|
if errorlevel 1 (
|
||||||
echo ERROR: Failed to install dependencies
|
echo ERROR: Failed to install dependencies
|
||||||
pause
|
pause
|
||||||
|
|||||||
@@ -38,8 +38,8 @@ if ($LASTEXITCODE -ne 0) {
|
|||||||
Write-Host ""
|
Write-Host ""
|
||||||
|
|
||||||
Write-Host "[3/5] Installing dependencies..." -ForegroundColor Cyan
|
Write-Host "[3/5] Installing dependencies..." -ForegroundColor Cyan
|
||||||
Write-Host "Installing: python-barcode, pillow, reportlab, kivy, pyinstaller..."
|
Write-Host "Installing: python-barcode, pillow, reportlab, kivy, pyinstaller, pywin32, wmi..."
|
||||||
pip install python-barcode pillow reportlab kivy==2.3.1 pyinstaller==6.18.0
|
pip install python-barcode pillow reportlab kivy==2.2.1 pyinstaller==6.1.0 pywin32 wmi
|
||||||
if ($LASTEXITCODE -ne 0) {
|
if ($LASTEXITCODE -ne 0) {
|
||||||
Write-Host "ERROR: Failed to install dependencies" -ForegroundColor Red
|
Write-Host "ERROR: Failed to install dependencies" -ForegroundColor Red
|
||||||
Read-Host "Press Enter to exit"
|
Read-Host "Press Enter to exit"
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ SYSTEM = platform.system() # 'Linux', 'Windows', 'Darwin'
|
|||||||
def get_available_printers():
|
def get_available_printers():
|
||||||
"""
|
"""
|
||||||
Get list of available printers (cross-platform).
|
Get list of available printers (cross-platform).
|
||||||
|
Includes both local and network printers on Windows.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list: List of available printer names, with "PDF" as fallback
|
list: List of available printer names, with "PDF" as fallback
|
||||||
@@ -40,14 +41,46 @@ def get_available_printers():
|
|||||||
return list(printers.keys()) if printers else ["PDF"]
|
return list(printers.keys()) if printers else ["PDF"]
|
||||||
|
|
||||||
elif SYSTEM == "Windows":
|
elif SYSTEM == "Windows":
|
||||||
# Windows: Try win32print first
|
# Windows: Get both local and network printers
|
||||||
try:
|
try:
|
||||||
printers = []
|
printers = []
|
||||||
for printer_name in win32print.EnumPrinters(win32print.PRINTER_ENUM_LOCAL):
|
|
||||||
printers.append(printer_name[2])
|
# Get local printers
|
||||||
return printers if printers else ["PDF"]
|
try:
|
||||||
|
for printer_info in win32print.EnumPrinters(win32print.PRINTER_ENUM_LOCAL):
|
||||||
|
printer_name = printer_info[2]
|
||||||
|
if printer_name and printer_name not in printers:
|
||||||
|
printers.append(printer_name)
|
||||||
except:
|
except:
|
||||||
# Fallback for Windows if win32print fails
|
pass
|
||||||
|
|
||||||
|
# Get network printers from print server
|
||||||
|
try:
|
||||||
|
for printer_info in win32print.EnumPrinters(win32print.PRINTER_ENUM_NETWORK):
|
||||||
|
printer_name = printer_info[2]
|
||||||
|
if printer_name and printer_name not in printers:
|
||||||
|
printers.append(printer_name)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Get connected printers (alternative method using WMI)
|
||||||
|
try:
|
||||||
|
import wmi
|
||||||
|
c = wmi.WMI()
|
||||||
|
for printer in c.Win32_Printer():
|
||||||
|
printer_name = printer.Name
|
||||||
|
if printer_name and printer_name not in printers:
|
||||||
|
printers.append(printer_name)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Add PDF as fallback option
|
||||||
|
if "PDF" not in printers:
|
||||||
|
printers.append("PDF")
|
||||||
|
|
||||||
|
return printers if printers else ["PDF"]
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error getting Windows printers: {e}")
|
||||||
return ["PDF"]
|
return ["PDF"]
|
||||||
|
|
||||||
elif SYSTEM == "Darwin":
|
elif SYSTEM == "Darwin":
|
||||||
|
|||||||
@@ -3,3 +3,5 @@ pillow
|
|||||||
kivy>=2.1.0
|
kivy>=2.1.0
|
||||||
reportlab
|
reportlab
|
||||||
pyinstaller>=6.0.0
|
pyinstaller>=6.0.0
|
||||||
|
pywin32
|
||||||
|
wmi
|
||||||
|
|||||||
Reference in New Issue
Block a user