Fix asyncio issue while searching for printers
This commit is contained in:
@@ -41,29 +41,21 @@ class PrinterScanner:
|
||||
except socket.herror:
|
||||
hostname = "Unknown"
|
||||
|
||||
printer_name = self.get_printer_name(ip)
|
||||
if printer_name:
|
||||
return {
|
||||
"ip": ip,
|
||||
"hostname": hostname,
|
||||
"name": printer_name
|
||||
}
|
||||
else:
|
||||
return {
|
||||
"ip": ip,
|
||||
"hostname": hostname,
|
||||
"name": "Unknown"
|
||||
}
|
||||
return {
|
||||
"ip": ip,
|
||||
"hostname": hostname,
|
||||
}
|
||||
return None
|
||||
|
||||
def get_all_printers(self, ip_addr="", local=False):
|
||||
if ip_addr:
|
||||
result = self.scan_ip(ip_addr)
|
||||
if result:
|
||||
result["name"] = self.get_printer_name(result['ip'])
|
||||
return [result]
|
||||
local_device_ip_list = socket.gethostbyname_ex(socket.gethostname())[2]
|
||||
if local:
|
||||
return local_device_ip_list
|
||||
return local_device_ip_list # IP list
|
||||
printers = []
|
||||
for local_device_ip in local_device_ip_list:
|
||||
if ip_addr and not local_device_ip.startswith(ip_addr):
|
||||
@@ -85,6 +77,8 @@ class PrinterScanner:
|
||||
for thread in threads:
|
||||
thread.join()
|
||||
|
||||
for i in printers:
|
||||
i["name"] = self.get_printer_name(i['ip'])
|
||||
return printers
|
||||
|
||||
|
||||
|
||||
3
ui.py
3
ui.py
@@ -37,7 +37,7 @@ from find_printers import PrinterScanner
|
||||
from text_console import TextConsole
|
||||
|
||||
|
||||
VERSION = "6.0.1"
|
||||
VERSION = "6.0.2"
|
||||
|
||||
NO_CONF_ERROR = (
|
||||
" Please select a printer model and a valid IP address,"
|
||||
@@ -3102,6 +3102,7 @@ Web site: https://github.com/Ircama/epson_print_conf
|
||||
self.detect_button.config(state=tk.DISABLED) # disable button while processing
|
||||
self.show_status_text_view()
|
||||
try:
|
||||
# [{'ip': '...', 'hostname': '...', 'name': '...'}]
|
||||
printers = self.printer_scanner.get_all_printers(
|
||||
self.ip_var.get().strip()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user