dev 02011812
This commit is contained in:
@@ -4,7 +4,9 @@ from util_func import (
|
||||
get_win_installed_software,
|
||||
extract_win_icon_from_file,
|
||||
)
|
||||
from global_vars import SoftwareStatusRole
|
||||
from global_vars import (
|
||||
SoftwareStatusRole,
|
||||
)
|
||||
|
||||
|
||||
class UiWgSoftware(object):
|
||||
@@ -21,14 +23,10 @@ class UiWgSoftware(object):
|
||||
self.cbx_safe.setChecked(True)
|
||||
self.cbx_unsafe.setChecked(True)
|
||||
self.cbx_unknown.setChecked(True)
|
||||
self.pbn_import_filter = QtWidgets.QPushButton("导入过滤文件", window)
|
||||
self.pbn_export_unknown = QtWidgets.QPushButton("导出未知", window)
|
||||
self.hly_top.addWidget(self.cbx_safe)
|
||||
self.hly_top.addWidget(self.cbx_unsafe)
|
||||
self.hly_top.addWidget(self.cbx_unknown)
|
||||
self.hly_top.addStretch(1)
|
||||
self.hly_top.addWidget(self.pbn_import_filter)
|
||||
self.hly_top.addWidget(self.pbn_export_unknown)
|
||||
|
||||
self.lv_software = QtWidgets.QListView(window)
|
||||
self.vly_m.addWidget(self.lv_software)
|
||||
@@ -38,16 +36,30 @@ class SoftwareListModel(QtCore.QAbstractListModel):
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.all_software = {} # type: dict[str, str]
|
||||
self.names = [] # type: list[str]
|
||||
self.icons = {} # type: dict[str, QtGui.QIcon]
|
||||
self.safe_info = {}
|
||||
self.blank_icon = QtGui.QIcon(":/images/blank_128.png")
|
||||
self.update()
|
||||
|
||||
def update(self):
|
||||
self.all_software.clear()
|
||||
self.names.clear()
|
||||
self.icons.clear()
|
||||
|
||||
self.all_software = get_win_installed_software()
|
||||
self.all_software_wz_qic = {}
|
||||
blank_icon = QtGui.QIcon(":/images/blank_128.png")
|
||||
for s in self.all_software:
|
||||
self.all_software_wz_qic[s] = extract_win_icon_from_file(
|
||||
self.names.append(s)
|
||||
self.icons[s] = extract_win_icon_from_file(
|
||||
self.all_software[s],
|
||||
blank_icon
|
||||
self.blank_icon
|
||||
)
|
||||
self.names = sorted(self.all_software.keys(), key=lambda x: x.lower())
|
||||
self.filter_dict = {}
|
||||
self.names.sort(key=lambda x: x.lower())
|
||||
|
||||
def update_safe_info(self, safe_info: dict):
|
||||
self.safe_info.clear()
|
||||
self.safe_info = safe_info
|
||||
|
||||
def rowCount(self, parent: QtCore.QModelIndex = ...):
|
||||
return len(self.names)
|
||||
@@ -59,12 +71,20 @@ class SoftwareListModel(QtCore.QAbstractListModel):
|
||||
if role == QtCore.Qt.ItemDataRole.DisplayRole:
|
||||
return name
|
||||
if role == QtCore.Qt.ItemDataRole.DecorationRole:
|
||||
return self.all_software_wz_qic[name]
|
||||
if role == SoftwareStatusRole:
|
||||
if name not in self.filter_dict:
|
||||
return -1
|
||||
return self.icons[name]
|
||||
if role == QtCore.Qt.ItemDataRole.BackgroundRole:
|
||||
is_safe = self.data(index, SoftwareStatusRole)
|
||||
if is_safe is True:
|
||||
return QtGui.QBrush(QtGui.QColor("lightgreen"))
|
||||
elif is_safe is False:
|
||||
return QtGui.QBrush(QtGui.QColor("lightpink"))
|
||||
else:
|
||||
return self.filter_dict[name]["safe"]
|
||||
return QtGui.QBrush(QtCore.Qt.BrushStyle.NoBrush)
|
||||
if role == SoftwareStatusRole:
|
||||
if name not in self.safe_info:
|
||||
return None
|
||||
else:
|
||||
return self.safe_info[name]["safe"]
|
||||
|
||||
|
||||
class WgSoftware(QtWidgets.QWidget):
|
||||
@@ -76,18 +96,36 @@ class WgSoftware(QtWidgets.QWidget):
|
||||
self.software_list_model = SoftwareListModel(self)
|
||||
self.ui.lv_software.setModel(self.software_list_model)
|
||||
|
||||
# self.ui.pbn_export_unknown.clicked.connect(self.on_pbn_export_unknown_clicked)
|
||||
self.ui.cbx_safe.clicked.connect(self.on_cbx_safe_clicked)
|
||||
self.ui.cbx_unsafe.clicked.connect(self.on_cbx_unsafe_clicked)
|
||||
self.ui.cbx_unknown.clicked.connect(self.on_cbx_unknown_clicked)
|
||||
|
||||
def on_pbn_export_unknown_clicked(self):
|
||||
unknown_software = {}
|
||||
sl_model = self.ui.lv_software.model() # type: SoftwareListModel
|
||||
for r in range(sl_model.rowCount()):
|
||||
idx = sl_model.index(r)
|
||||
name = sl_model.data(idx, QtCore.Qt.ItemDataRole.DisplayRole)
|
||||
safe = sl_model.data(idx, SoftwareStatusRole)
|
||||
if safe == -1:
|
||||
unknown_software[name] = {"safe": -1}
|
||||
def filters_clicked(self, safe_mark: bool | None, checked: bool):
|
||||
for row in range(self.software_list_model.rowCount()):
|
||||
idx = self.software_list_model.index(row)
|
||||
is_safe = self.software_list_model.data(idx, SoftwareStatusRole)
|
||||
if is_safe is safe_mark:
|
||||
self.ui.lv_software.setRowHidden(row, not checked)
|
||||
|
||||
|
||||
def on_cbx_safe_clicked(self, checked: bool):
|
||||
self.filters_clicked(True, checked)
|
||||
|
||||
def on_cbx_unsafe_clicked(self, checked: bool):
|
||||
self.filters_clicked(False, checked)
|
||||
|
||||
def on_cbx_unknown_clicked(self, checked: bool):
|
||||
self.filters_clicked(None, checked)
|
||||
|
||||
def update_safe(self, safe_info: dict):
|
||||
self.software_list_model.update_safe_info(safe_info)
|
||||
|
||||
def export_unknown(self) -> list[str]:
|
||||
unknown_software = []
|
||||
for row in range(self.software_list_model.rowCount()):
|
||||
idx = self.software_list_model.index(row)
|
||||
is_safe = self.software_list_model.data(idx, SoftwareStatusRole)
|
||||
if is_safe is None:
|
||||
name = self.software_list_model.data(idx, QtCore.Qt.ItemDataRole.DisplayRole)
|
||||
unknown_software.append(name)
|
||||
|
||||
return unknown_software
|
||||
|
||||
Reference in New Issue
Block a user