1+ from PyQt5 .QtCore import QUrl
2+ from PyQt5 .QtGui import QDesktopServices
13from PyQt5 .QtWidgets import QTextBrowser
24
35import g
46from utils .string_util import wildcard_match_check
57
68
9+ def handle_links (url ):
10+ if not url .scheme ():
11+ url = QUrl .fromLocalFile (url .toString ())
12+ QDesktopServices .openUrl (url )
13+
14+
715class CustomQTextBrowser (QTextBrowser ):
816
917 def __init__ (self , parent_app ):
1018 super ().__init__ (parent_app )
1119 self .parent_app = parent_app
1220
21+ # 设置使用外部程序打开链接
22+ self .setOpenLinks (False )
23+ self .anchorClicked .connect (handle_links )
24+
1325 def filter_type_hint (self ):
1426 # 过滤输入提示
1527 include_text = g .data_list [self .parent_app .tableWidget .currentItem ().row ()][2 ]
1628 exclude_text = g .data_list [self .parent_app .tableWidget .currentItem ().row ()][3 ]
1729 type_hints = self .parent_app .tableWidget .type_hints
30+ article_details = self .parent_app .tableWidget .article_details
1831 # 清空
1932 self .parent_app .text_browser .clear ()
2033 if include_text .strip () == '' and exclude_text .strip () == '' :
2134 # 特殊处理 为空则匹配所有
22- self .parent_app .text_browser .append ('\n ' .join (type_hints ))
35+ # self.parent_app.text_browser.append('<br/>'.join(type_hints))
36+ for x in article_details :
37+ self .parent_app .text_browser .append (
38+ f"""<a style="color:#00a3a3">{ x ['source_name' ]} </a> { x ['title' ]} <a href="{ x ['url' ]} alt="{ x ['url' ]} "">链接</a>""" )
2339 else :
2440 # 保留匹配的
2541 filtered_hints = []
26- for type_hint in type_hints :
42+ for i , type_hint in enumerate ( type_hints ) :
2743 # 包含关键字
2844 flag1 = False
2945 # 不包含关键字
@@ -35,8 +51,13 @@ def filter_type_hint(self):
3551 # flag2 = all(x.lower() in type_hint.lower() for x in exclude_text.split(' '))
3652 flag2 = wildcard_match_check (type_hint , exclude_text )
3753 if flag1 and not flag2 :
38- filtered_hints .append (type_hint )
54+ # filtered_hints.append(type_hint)
55+ filtered_hints .append (i )
3956 if filtered_hints :
40- self .parent_app .text_browser .append ('\n ' .join (filtered_hints ))
57+ for i in filtered_hints :
58+ x = article_details [i ]
59+ self .parent_app .text_browser .append (
60+ f"""<a style="color:#00a3a3">{ x ['source_name' ]} </a> { x ['title' ]} <a href="{ x ['url' ]} " alt="{ x ['url' ]} ">链接</a>""" )
61+
4162 else :
42- self .parent_app .text_browser .append ('暂时没有找到相关的feed' )
63+ self .parent_app .text_browser .append ('<p> 暂时没有找到相关的feed</p> ' )
0 commit comments