def refresh(self):
l = list(list_ports.comports())
new_ports = [Port(p) for p in l]
old_ports = self.getPortList()
# Add new ports to list
for p in new_ports:
if p not in self.getPortList():
self.list_w.addItem(p)
# Remove disappeared ports from list
for i in range(self.list_w.count()):
if(self.list_w.item(i) is not None):
p = self.list_w.item(i)
if p not in new_ports:
p.close()
self.list_w.takeItem(i)
评论列表
文章目录