1
+ from PyQt5 .QtCore import QUrl
2
+ from PyQt5 .QtGui import QDesktopServices
1
3
from PyQt5 .QtWidgets import QTextBrowser
2
4
3
5
import g
4
6
from utils .string_util import wildcard_match_check
5
7
6
8
9
+ def handle_links (url ):
10
+ if not url .scheme ():
11
+ url = QUrl .fromLocalFile (url .toString ())
12
+ QDesktopServices .openUrl (url )
13
+
14
+
7
15
class CustomQTextBrowser (QTextBrowser ):
8
16
9
17
def __init__ (self , parent_app ):
10
18
super ().__init__ (parent_app )
11
19
self .parent_app = parent_app
12
20
21
+ # 设置使用外部程序打开链接
22
+ self .setOpenLinks (False )
23
+ self .anchorClicked .connect (handle_links )
24
+
13
25
def filter_type_hint (self ):
14
26
# 过滤输入提示
15
27
include_text = g .data_list [self .parent_app .tableWidget .currentItem ().row ()][2 ]
16
28
exclude_text = g .data_list [self .parent_app .tableWidget .currentItem ().row ()][3 ]
17
29
type_hints = self .parent_app .tableWidget .type_hints
30
+ article_details = self .parent_app .tableWidget .article_details
18
31
# 清空
19
32
self .parent_app .text_browser .clear ()
20
33
if include_text .strip () == '' and exclude_text .strip () == '' :
21
34
# 特殊处理 为空则匹配所有
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>""" )
23
39
else :
24
40
# 保留匹配的
25
41
filtered_hints = []
26
- for type_hint in type_hints :
42
+ for i , type_hint in enumerate ( type_hints ) :
27
43
# 包含关键字
28
44
flag1 = False
29
45
# 不包含关键字
@@ -35,8 +51,13 @@ def filter_type_hint(self):
35
51
# flag2 = all(x.lower() in type_hint.lower() for x in exclude_text.split(' '))
36
52
flag2 = wildcard_match_check (type_hint , exclude_text )
37
53
if flag1 and not flag2 :
38
- filtered_hints .append (type_hint )
54
+ # filtered_hints.append(type_hint)
55
+ filtered_hints .append (i )
39
56
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
+
41
62
else :
42
- self .parent_app .text_browser .append ('暂时没有找到相关的feed' )
63
+ self .parent_app .text_browser .append ('<p> 暂时没有找到相关的feed</p> ' )
0 commit comments