时隔一个月,使用PyQt5开发了一款浏览器,不但能满足日常网页浏览,还支持一些辅助功能,例如:截图、收藏网址、查看浏览历史、主题颜色设置…来吧~
pyqt5是一套Python绑定Digia QT5应用的框架。它可用于Python 2和3。本教程使用Python 3。Qt库是最强大的GUI库之一。pyqt5的官方网站
https://doc.qt.io/qtforpython-5/
。
pyqt5做为Python的一个模块,它有620多个类和6000个函数和方法。这是一个跨平台的工具包,它可以运行在所有主要的操作系统,包括UNIX,Windows,Mac OS。pyqt5是双重许可。开发者可以在GPL和商业许可之间进行选择。安装:
pip install PyQt5
PyQt5官方文档:
https://doc.qt.io/qtforpython-5
pyqt5 已经抛弃 QtWebKit和QtWebKitWidgets,而使用最新的QtWebEngineWidgets。QtWebEngineWidgets,是基于chrome浏览器内核引擎的。安装:
pip install PyQtWebEngine
QWebEngineView官方文档:
https://doc.qt.io/qtforpython-5/PySide2/QtWebEngineWidgets/QWebEngineView.html
PyQt5-tools里面包含了一系列QT开发的GUI工具,能有效减少代码量。
在PyQt中编写UI界面可以直接通过代码来实现,也可以通过Qt Designer来完成。Qt Designer的设计符合MVC的架构,其实现了视图和逻辑的分离,从而实现了开发的便捷。Qt Designer中的操作方式十分灵活,其通过拖拽的方式放置控件可以随时查看控件效果。Qt Designer生成的.ui文件(实质上是XML格式的文件)也可以通过pyuic5工具转换成.py文件。
Qt Designer随PyQt5-tools包一起安装,其安装路径在 “Python安装路径\Lib\site-packages\pyqt5-tools”下。
若要启动Qt Designer可以直接到上述目录下,双击designer.exe打开Qt Designer;或将上述路径加入环境变量,在命令行输入designer打开;或在PyCharm中将其配置为外部工具打开。
通过调用自带的API实现网页截图。
点击收藏,将网页收藏到我的收藏。
复制当前浏览器网页链接地址到剪切板。
通过点击工具栏按钮和设置中的组合栏对浏览器网页进行缩放操作,同时显示当前浏览器放大比例。
在隐私设置中,可以清理浏览历史记录、cookie、设置文件下载路径、截图保存路径
1.设置-基本
使用QSS,设置浏览器整体颜色风格,设置控件边框颜色、边框角度等视觉展示效果,首次启动默认使用此颜色作为主题颜色。
import os
import re
import sys
from webbrowser import open_new_tab
from utils import Util
from PyQt5.uic import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWebEngineWidgets import QWebEngineView,QWebEngineSettings,QWebEnginePage
# from get_input_suggests import get_suggests
from history import History_Ui_Form
from liulanqi import Web_browser_Ui_MainWindow
from main_set import Main_set_Ui_Dialog
from my_favourite import Favourite_Ui_Form
from about_author import About_author_Ui_Dialog
from window_zoom import Ui_Form
"""
网页缩放弹出当前缩放系数
QWebEngineSettings
QWebEngineDownloadItem
QWebEngineProfile
QWebEnginePage
从页面保存东西还是存在问题
"""
class History_Window(QWidget,History_Ui_Form):
def __init__(self):
super().__init__()
self.setupUi(self)
class Favourite_Window(QWidget,Favourite_Ui_Form):
def __init__(self):
super().__init__()
self.setupUi(self)
class Main_set_Window(QWidget,Main_set_Ui_Dialog):
def __init__(self):
super().__init__()
self.setupUi(self)
class About_author_Window(QWidget,About_author_Ui_Dialog):
def __init__(self):
super().__init__()
self.setupUi(self)
class Main_Window(QMainWindow,Web_browser_Ui_MainWindow):
def __init__(self):
super().__init__()
# self.setupUi(self)
class Message_Window(QWidget,Ui_Form):
zoom_change_single=pyqtSignal(str)
show_set_change_message_single=pyqtSignal(str)
main_ui_size_change_single=pyqtSignal(int,int)
color_set_single=pyqtSignal(str)
def __init__(self):
super().__init__()
self.setupUi(self)
self.setStyleSheet("""QLabel{
color: rgb(255, 170, 255);
}""")
self.setAttribute(Qt.WA_TranslucentBackground) # 窗体背景透明
self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint | Qt.Tool) # 窗口置顶,无边框,在任务栏不显示图标
self.zoom_change_single.connect(self.change_zoom_text)
self.show_set_change_message_single.connect(self.show_set_change_message)
self.main_ui_size_change_single.connect(self.set_window_location)
self.color_set_single.connect(self.change_theme_color)
def set_window_location(self,x,y):
self.move(x,y)
def change_theme_color(self,color):
self.setStyleSheet("""QLabel{
color: {my_color};
}""".replace("{my_color}",color))
@pyqtSlot(str)
def change_zoom_text(self,zoom_factor):
self.label.setText(f'当前缩放比例{
zoom_factor}
')
@pyqtSlot(str)
def show_set_change_message(self,message):
self.label.setText(f'{
message}
')
@pyqtSlot(int,int)
def set_window_loaction(self,center_x,center_y):
pass
class My_Web_View(QWebEngineView):
# 重写createwindow()
def createWindow(self,QWebEnginePage_WebWindowType):
page = My_Web_View(self)
page.setPage(CustomWebEnginePage())
page.urlChanged.connect(self.on_url_changed)
return page
def on_url_changed(self,url):
self.setUrl(url)
#0927 这里有点问题
My_Web_Broswer().ui.action_houtui.setEnabled(True)
class CustomWebEnginePage(QWebEnginePage):
def __init__(self):
super().__init__()
def certificateError(self,QWebEngineCertificateError):
"""
屏蔽ssl证书错误警告
:param QWebEngineCertificateError:
:return:
"""
return True
class My_Web_Broswer(QMainWindow):
def __init__(self):
super().__init__()
self.u=Util()
self.zoom_factor=1.0
self.default_screenshot_save_path=os.path.expanduser('~')
self.message_ui=Message_Window()
self.ui=Main_Window()
self.ui.setupUi(self)#此处很关键
self.his_ui=History_Window()
self.collect_ui=Favourite_Window()
self.main_set_ui=Main_set_Window()
self.about_author_ui=About_author_Window()
self.collection_txt='./my_favourite.txt'
self.homepage_url="https://www.baidu.com/"
self.search_engine_base_url="https://www.baidu.com/s?wd="
self.theme_color="#ff55ff"
self.WebEngineView=My_Web_View()
self.setWindowTitle('正在加载...')
self.Layout = QHBoxLayout(self.ui.frame)
self.Layout.setContentsMargins(0, 0, 0, 0)
self.Layout.addWidget(self.WebEngineView)
self.ui.progressBar_download_progress.hide()
self.ui.action_qianjin.setEnabled(False)
self.ui.action_houtui.setEnabled(False)
self.ui.lineEdit.returnPressed.connect(self.do_enter)
self.ui.action_houtui.triggered.connect(lambda: self.WebEngineView.back())
self.ui.action_qianjin.triggered.connect(lambda: self.WebEngineView.forward())
self.ui.action_shuaxin.triggered.connect(lambda: self.WebEngineView.reload())
self.ui.action_tingzhi.triggered.connect(lambda: self.WebEngineView.stop())
self.ui.action_screen_shot.triggered.connect(self.do_screen_shot)
self.ui.action_about_author.triggered.connect(lambda: self.about_author_ui.show())
self.ui.action_about_software.triggered.connect(lambda:QMessageBox.information(self,"提示",'Design By QT'))
self.ui.action_about_qt.triggered.connect(self.show_qt)
self.ui.action_main_set.triggered.connect(self.main_set_init)
self.ui.action_tuichu.triggered.connect(self.close)
self.ui.action_daozhuye.triggered.connect(lambda :self.WebEngineView.setUrl(QUrl(self.homepage_url)))
self.ui.action_guanyv.triggered.connect(lambda :self.about_author_ui.show())
self.ui.action_fangda.triggered.connect(self.do_zoom_webview)
self.ui.action_suoxiao.triggered.connect(self.do_zoom_webview)
self.ui.action_copy_current_link.triggered.connect(self.copy_current_link)
self.ui.action_lishi.triggered.connect(self.show_history)
self.ui.action_my_collection.triggered.connect(self.show_my_favourite)
self.ui.action_collect.triggered.connect(self.do_collcet)
self.WebEngineView.urlChanged.connect(self.show_jump_url)
self.WebEngineView.loadProgress.connect(self.show_load_progress)
self.WebEngineView.loadFinished.connect(self.change_history_state)
self.WebEngineView.iconChanged.connect(lambda icon:self.setWindowIcon(icon))
self.WebEngineView.page().profile().downloadRequested.connect(self.select_save_dir)
# self.WebEngineView.setContextMenuPolicy(Qt.CustomContextMenu) # 将浏览器右键菜单设置为用户自定义菜单
self.WebEngineView.page().settings().setAttribute(QWebEngineSettings.LocalContentCanAccessFileUrls, True)
self.WebEngineView.settings().setAttribute(QWebEngineSettings.FullScreenSupportEnabled, True)
self.WebEngineView.settings().setAttribute(QWebEngineSettings.JavascriptEnabled, True)
self.WebEngineView.page().settings().setAttribute(QWebEngineSettings.LocalStorageEnabled, True)
self.WebEngineView.page().settings().setAttribute(QWebEngineSettings.PluginsEnabled, True)
self.WebEngineView.page().settings().setAttribute(QWebEngineSettings.AutoLoadImages, True)
self.WebEngineView.page().settings().setAttribute(QWebEngineSettings.FocusOnNavigationEnabled, True)
self.WebEngineView.page().settings().setAttribute(QWebEngineSettings.ScreenCaptureEnabled, True)
self.WebEngineView.load(QUrl(self.homepage_url))
# self.ui.lineEdit.textEdited.connect(self.show_suggest_words) #输入建议
self.ui.lineEdit.textEdited.connect(self.judge_input) #输入建议
self.ui.pushButton.clicked.connect(self.do_enter)
self.WebEngineView.page().fullScreenRequested.connect(self._fullScreenRequested)
self.init_collections()
def do_screen_shot(self):
if self.is_load_finish_flag:
time_string = self.u.get_time_string().replace(" ", '').replace("-", '').replace(":", '')
save_screen_shot_file_name = "网页截图_" + time_string + ".png"
file_name=f"{
self.default_screenshot_save_path}\{
save_screen_shot_file_name}"
self.WebEngineView.grab().save(file_name, b'PNG')
ret=QMessageBox.information(self,"提示",f"截图成功,是否打开此截图?",QMessageBox.Yes|QMessageBox.No,QMessageBox.Yes)
if ret==QMessageBox.Yes:
os.startfile(file_name)
else:
QMessageBox.warning(self,"警告","请等待网页加载完成")
def show_qt(self):
QMessageBox.aboutQt(self, "关于QT")
def do_zoom_webview(self):
text=self.sender().text()
if "缩小" in text:
self.zoom_factor=self.WebEngineView.zoomFactor() - 0.1
elif "放大"in text:
self.zoom_factor=self.WebEngineView.zoomFactor() + 0.1
self.message_ui.zoom_change_single.emit(str(int(self.zoom_factor*100))+"%")
self.message_ui.show()
self.WebEngineView.setZoomFactor(self.zoom_factor)
#---设置---
def main_set_init(self):
self.zoom_factor_str_list=["30%","50%","80%","100%","120%","150%","180%","200%","250%","300%","400%","500%"]
self.main_set_ui.tabWidget.setCurrentIndex(0)
self.ua_list=['Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.15.2 Chrome/83.0.4103.122 Safari/537.36','Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Mobile Safari/537.36','Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1','Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1']
#设置代理
# print(self.WebEngineView.page().profile().httpUserAgent())
# self.WebEngineView.page().profile().setHttpUserAgent("Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Mobile Safari/537.36")
# self.main_set_ui.tabWidget.setTabEnabled(3,False) #设置指定页面可用
self.main_set_ui.label_13.setText(f"一共产生了{
self.u.format_size(self.WebEngineView.page().profile().httpCacheMaximumSize())}缓存文件")
self.main_set_ui.label_15.setText(f"一共产生了{
self.WebEngineView.history().count()}个历史记录")
# print(self.WebEngineView.page().devToolsPage())
self.main_set_ui.pushButton_5.clicked.connect(self.delete_cache)
self.main_set_ui.pushButton_6.clicked.connect(self.delete_cookies)
self.main_set_ui.pushButton_7.clicked.connect(self.delete_session_cookie)
self.main_set_ui.pushButton_4.clicked.connect(self.clear_history_record)
self.main_set_ui.lineEdit.setText(self.homepage_url)
default_down_dir=self.WebEngineView.page().profile().downloadPath()
default_UA=self.WebEngineView.page().profile().httpUserAgent() #默认UA
if "Windows NT" in default_UA:
self.main_set_ui.comboBox_2.setCurrentIndex(0)
elif "Android" in default_UA:
self.main_set_ui.comboBox_2.setCurrentIndex(1)
elif "iPhone" in default_UA:
self.main_set_ui.comboBox_2.setCurrentIndex(2)
elif "ipad" in default_UA:
self.main_set_ui.comboBox_2.setCurrentIndex(3)
self.main_set_ui.comboBox_2.currentIndexChanged[int].connect(self.change_ua)
self.main_set_ui.comboBox.currentIndexChanged.connect(self.change_search_engine)
self.main_set_ui.comboBox_2.setToolTip(self.main_set_ui.comboBox_2.currentText())
self.main_set_ui.lineEdit_2.setText(default_down_dir)
self.main_set_ui.checkBox_2.stateChanged.connect(lambda : self.WebEngineView.page().settings().setAttribute(QWebEngineSettings.SpatialNavigationEnabled, True)if self.main_set_ui.checkBox_2.isChecked()else self.WebEngineView.page().settings().setAttribute(QWebEngineSettings.SpatialNavigationEnabled, False))
self.main_set_ui.checkBox_4.stateChanged.connect(lambda : self.WebEngineView.page().settings().setAttribute(QWebEngineSettings.AllowGeolocationOnInsecureOrigins, True)if self.main_set_ui.checkBox_4.isChecked()else self.WebEngineView.page().settings().setAttribute(QWebEngineSettings.AllowGeolocationOnInsecureOrigins, False))
self.main_set_ui.checkBox_6.stateChanged.connect(self.process_debug)
self.main_set_ui.pushButton_3.clicked.connect(self.select_download_base_dir)
self.main_set_ui.comboBox_4.currentIndexChanged.connect(lambda :self.WebEngineView.page().settings().setDefaultTextEncoding(self.main_set_ui.comboBox_2.currentText()))#改变当前编码
zoom_factor_str=str(int(self.zoom_factor * 100))+"%"
if zoom_factor_str in self.zoom_factor_str_list:
self.main_set_ui.comboBox_5.setCurrentText(zoom_factor_str)
else:
self.main_set_ui.comboBox_5.addItem(zoom_factor_str) #这里可能产生溢出)
self.main_set_ui.comboBox_5.setCurrentText(zoom_factor_str)
self.main_set_ui.comboBox_5.currentIndexChanged.connect(self.change_zoom_factor)#改变当前放大倍数
self.main_set_ui.checkBox.stateChanged.connect(lambda :self.WebEngineView.page().profile().setSpellCheckEnabled(True) if self.main_set_ui.checkBox.isChecked() else self.WebEngineView.page().profile().setSpellCheckEnabled(False))
self.main_set_ui.checkBox_3.stateChanged.connect(lambda :self.WebEngineView.page().profile().setUseForGlobalCertificateVerification(True) if self.main_set_ui.checkBox_3.isChecked() else self.WebEngineView.page().profile().setUseForGlobalCertificateVerification(False) )
self.main_set_ui.lineEdit.editingFinished.connect(self.change_homepage_url)
self.main_set_ui.pushButton_2.clicked.connect(self.change_theme_color)
self.main_set_ui.lineEdit_3.setText(self.default_screenshot_save_path)
self.main_set_ui.pushButton_10.clicked.connect(self.set_default_screenshot_dir)
self.main_set_ui.checkBox_7.stateChanged.connect(self.do_process_proxy)
self.main_set_ui.show()
def do_process_proxy(self):
if self.main_set_ui.checkBox_7.isChecked():
self.main_set_ui.lineEdit_6.setEnabled(True)
self.main_set_ui.lineEdit_7.setEnabled(True)
else:
self.main_set_ui.lineEdit_6.setEnabled(False)
self.main_set_ui.lineEdit_7.setEnabled(False)
def set_default_screenshot_dir(self):
dir=QFileDialog.getExistingDirectory(self,'.')
if dir:
self.main_set_ui.lineEdit_3.setText(dir)
self.default_screenshot_save_path=dir
def change_ua(self,index):
current_ua=self.main_set_ui.comboBox_2.currentText()
self.WebEngineView.page().profile().setHttpUserAgent(self.ua_list[index])
self.message_ui.show_set_change_message_single.emit(f"当前UA为:{
current_ua}")
self.main_set_ui.comboBox_2.setToolTip(current_ua)
self.message_ui.show()
@pyqtSlot()
def change_theme_color(self):
color=QColorDialog.getColor()
if color.isValid():
rgb_str=f"rgb({
color.red()},{
color.green()},{
color.blue()})"
self.theme_color=rgb_str
if rgb_str=="rgb(0,0,0)":
return
new_qss_style="""
QProgressBar {
text-align: center;
border: 2px solid grey;
border-radius: 5px;
background-color: #FFFFFF;}
QProgressBar::chunk {
background-color: {rgb_str};
width: 1px;
}
QPushButton {
border: 1px solid ;
border-radius: 4px;
padding: 1px 4px;
min-width: 80px;
min-height: 20px;
}
QPushButton:hover{
background-color:rgb(255, 255, 255);
border-color:{rgb_str};
}
QCheckBox:hover{
background-color:{rgb_str};
}
QLineEdit{
border: 1px solid ;
border-radius: 4px;
selection-background-color:{rgb_str};
border: 1px solid;
border-style: inset;
}
QLineEdit:hover{
border-color:{rgb_str};
}
QLineEdit:focus{
border-color: {rgb_str};
}
QLabel {
background: transparent;
border: 1px solid transparent;
padding: 1px;
}
QComboBox{
margin:2px;
border: 1px solid ;
border-radius: 4px;
background-color:rgb(255, 255, 255);
border-color:rgb(0, 0, 0);
min-width: 60px;
min-height: 23px;
max-width: 200px;
max-height: 23px;
}
QComboBox:hover{
background-color:rgb(255, 255, 255);
border-color:{rgb_str};
}
QToolBar{
margin:2px;
border: 1px solid ;
border-radius: 4px;
background-color:rgb(255, 255, 255);
border-color: rgb(0, 0, 0);
}
QToolBar:hover{
background-color:rgb(255, 255, 255);
border-color:{rgb_str};
}
QGroupBox {
background-color: rgb(255, 255, 255);
border: 1px solid ;
border-radius: 4px;
margin-top:1em;
}
QGroupBox::title {
subcontrol-origin: margin;
subcontrol-position: top left;
top: 0.1em;
background-color: {rgb_str};
font-size:10px
}""".replace("{rgb_str}",rgb_str)
self.setStyleSheet(new_qss_style)
self.main_set_ui.setStyleSheet(new_qss_style)
self.about_author_ui.setStyleSheet(new_qss_style)
self.main_set_ui.label_7.setText(f"{
rgb_str}>主题颜色")
self.main_set_ui.label_13.setText(f"一共产生了{
rgb_str}>{
self.u.format_size(self.WebEngineView.page().profile().httpCacheMaximumSize())}缓存文件")
self.main_set_ui.label_15.setText(f"一共产生了{
rgb_str}>{
self.WebEngineView.history().count()}个历史记录")
self.his_ui.label.setText(f'一共有{
rgb_str}>{
self.WebEngineView.page().history().count()}个历史记录,双击跳转')
self.collect_ui.label.setText(f'一共有{
rgb_str}>{
len(self.collections)}个收藏,双击跳转')
self.message_ui.color_set_single.emit(rgb_str)
def change_zoom_factor(self):
current_zoom_factor_str=self.main_set_ui.comboBox_5.currentText()
zoom_factor=float(int(current_zoom_factor_str.split("%")[0])/100)
self.zoom_factor=zoom_factor
self.WebEngineView.page().setZoomFactor(zoom_factor)
zoom_factor_precent=int(self.zoom_factor * 100) #这里可能产生溢出
if str(zoom_factor_precent).endswith("9"):
zoom_factor_precent+=1
self.message_ui.zoom_change_single.emit(str(zoom_factor_precent)+"%")
self.message_ui.show()
def change_homepage_url(self):
user_input=self.main_set_ui.lineEdit.text()
if user_input.startswith("https://") or user_input.startswith("http://"):
self.homepage_url =user_input
else:
self.message_ui.show_set_change_message_single.emit("主页输入有误,请检查!")
#QMessageBox.warning(self,"警告",'主页输入有误,请检查!')
self.message_ui.show()
def process_debug(self):
if self.main_set_ui.checkBox_6.isChecked():
self.main_set_ui.lineEdit_5.setEnabled(True)
self.main_set_ui.pushButton_8.setEnabled(True)
port=self.main_set_ui.lineEdit_5.text()
debug_url='http://127.0.0.1:%s' % port
os.environ["QTWEBENGINE_REMOTE_DEBUGGING"] = port
self.main_set_ui.pushButton_8.clicked.connect(lambda :open_new_tab(debug_url))
else :
self.main_set_ui.lineEdit_5.setEnabled(False)
self.main_set_ui.pushButton_8.setEnabled(False)
def delete_cache(self):
self.WebEngineView.page().profile().clearHttpCache()
self.message_ui.show_set_change_message_single.emit("缓存已清空!")
# QMessageBox.information(self,"提示","缓存已清空!")
self.message_ui.show()
def delete_cookies(self):
self.WebEngineView.page().profile().cookieStore().deleteAllCookies()
self.message_ui.show_set_change_message_single.emit("cookie已清空!")
# QMessageBox.information(self,"提示","cookie已清空!")
self.message_ui.show()
def clear_history_record(self):
self.WebEngineView.page().history().clear()
self.message_ui.show_set_change_message_single.emit("历史浏览记录已清理!")
# QMessageBox.information(self,"提示","历史浏览记录已清空!")
self.main_set_ui.label_15.setText(f"一共产生了{
self.theme_color}>{
self.WebEngineView.history().count()}个历史记录")
self.message_ui.show()
def delete_session_cookie(self):
self.WebEngineView.page().profile().cookieStore().deleteSessionCookies()
self.message_ui.show_set_change_message_single.emit("会话cookie已清空!")
# QMessageBox.information(self,"提示","会话cookie已清空!")
self.message_ui.show()
def select_download_base_dir(self):
dir=QFileDialog.getExistingDirectory(None,"选择默认文件下载目录",'.')
if dir :
self.main_set_ui.lineEdit_2.setText(dir)
else:
pass
def change_search_engine(self):
#改变搜索引擎
current_select=self.main_set_ui.comboBox.currentText()
if current_select=="百度":
self.search_engine_base_url='https://www.baidu.com?wd='
elif current_select=="搜狗":
self.search_engine_base_url='https://www.sogou.com/web?query='
elif current_select=="Google":
self.search_engine_base_url='https://www.google.com.hk/search?q=%E5%8A%A0%E6%B2%B9'
elif current_select=="360":
self.search_engine_base_url='https://www.so.com/s?ie=utf-8&fr=none&src=360sou_newhome&q='
elif current_select=="Bing":
self.search_engine_base_url='https://www.bing.com/search?q='
else:
pass
self.message_ui.show_set_change_message_single.emit(f"当前搜索引擎为:{
current_select}")
self.message_ui.show()
#---我的收藏---
def init_collections(self):
try:
collections=self.u.read_txt(self.collection_txt)
collections.reverse()
self.collections=collections
except AttributeError:
self.collections=[]
def do_collcet(self):
try:
time_string=self.u.get_time_string()
url=self.WebEngineView.url().toString()
self.init_collections()
if url not in [url.split('\t')[1] for url in self.collections]:
title=self.WebEngineView.title()
data=time_string+'\t'+url+'\t'+title+'\n'
self.u.write_to_txt(self.collection_txt,data)
QMessageBox.information(self,"提示",'收藏成功!')
else:
QMessageBox.warning(self, '警告', '此网站已被收藏,请勿重复收藏!')
except Exception as e:
QMessageBox.critical(self,'错误','收藏失败!')
def show_my_favourite(self):
self.init_collections()
self.collect_ui.tableWidget.clear()
self.collect_ui.tableWidget.setHorizontalHeaderLabels(['时间','地址'])
if self.collections:
collections_num=len(self.collections)
self.collect_ui.tableWidget.setRowCount(collections_num)
self.collect_url_list=[]
for index,line in enumerate(self.collections):
time_string,url,title=line.strip().split('\t')
new_table_widget_item1 = QTableWidgetItem(time_string)
new_table_widget_item2 = QTableWidgetItem(title)
new_table_widget_item2.setToolTip(title)
self.collect_url_list.append(url)
new_table_widget_item1.setIcon(QtGui.QIcon(QtGui.QPixmap('./icons/shoucang.png')))
self.collect_ui.tableWidget.setItem(index, 0, new_table_widget_item1)
self.collect_ui.tableWidget.setItem(index, 1, new_table_widget_item2)
self.collect_ui.label.setText(f'一共有{
self.theme_color}>{
collections_num}个收藏,双击跳转')
self.collect_ui.tableWidget.cellDoubleClicked.connect(self.jump_url_by_collect)
self.collect_ui.tableWidget.customContextMenuRequested.connect(self.show_collect_menu)
else:
self.collect_ui.label.setText('您还没有收藏,快去收藏吧!')
self.collect_ui.show()
def show_collect_menu(self,pos):
menu = QMenu()
item1 = menu.addAction("访问")
item2 = menu.addAction("移除")
screenPos = self.collect_ui.tableWidget.mapToGlobal(pos)
# 被阻塞
action = menu.exec(screenPos)
current_row = self.collect_ui.tableWidget.currentRow()
if action==item1:
self.jump_url_by_collect(current_row)
elif action==item2:
collections=self.u.read_txt(self.collection_txt)
collections.reverse()
del collections[current_row]
del self.collect_url_list[current_row]
row_new_num=len(collections)
os.remove(self.collection_txt)
self.collect_ui.tableWidget.clear()
self.collect_ui.tableWidget.setRowCount(row_new_num)
self.collect_ui.tableWidget.setHorizontalHeaderLabels(['时间','地址'])
for index,collection in enumerate(collections):
self.u.write_to_txt(self.collection_txt,collection)#逐行写入
time_string, url, title = collection.strip().split('\t')
new_table_widget_item1 = QTableWidgetItem(time_string)
new_table_widget_item2 = QTableWidgetItem(title)
new_table_widget_item2.setToolTip(title)
self.collect_url_list.append(url)
new_table_widget_item1.setIcon(QtGui.QIcon(QtGui.QPixmap('./icons/shoucang.png')))
self.collect_ui.tableWidget.setItem(index, 0, new_table_widget_item1)
self.collect_ui.tableWidget.setItem(index, 1, new_table_widget_item2)
self.collect_ui.label.setText(f'一共有{
self.theme_color}>{
row_new_num}个收藏,双击跳转')
else:
pass
def jump_url_by_collect(self,row):
current_url=self.collect_url_list[row]
self.WebEngineView.setUrl(QUrl(current_url))
self.collect_ui.hide()
def judge_input(self,text):
pattern = re.compile(
r'^(([a-zA-Z]{1})|([a-zA-Z]{1}[a-zA-Z]{1})|'
r'([a-zA-Z]{1}[0-9]{1})|([0-9]{1}[a-zA-Z]{1})|'
r'([a-zA-Z0-9][-_.a-zA-Z0-9]{0,61}[a-zA-Z0-9])).'
r'([a-zA-Z]{2,13}|[a-zA-Z0-9-]{2,30}.[a-zA-Z]{2,3})$'
)
if re.match(pattern,text) or text.startswith('https://') or text.startswith('http://'):
self.ui.pushButton.setText('转到')
else:
self.ui.pushButton.setText('搜索')
#---收藏end---
#---下载----
def select_save_dir(self,download):
"""
选择下载文件地址 这个函数存在问题
:param download:
:return:
"""
download.finished.connect(self._finished)
the_sourceFile = os.path.join(self.WebEngineView.page().profile().downloadPath(), download.suggestedFileName())
download.setPath(the_sourceFile)
download.accept()
def _finished(self):
self.message_ui.show_set_change_message_single.emit("一个文件下载完成!")
def show_jump_url(self,url):
self.ui.progressBar_load_progress.show()
self.ui.lineEdit.setText(url.toString())
def do_enter(self):
"""
对输入进行校验,如果为域名,则转到对应http网站
否则,视为百度
:return:
"""
user_input=self.ui.lineEdit.text()
pattern = re.compile(
r'^(([a-zA-Z]{1})|([a-zA-Z]{1}[a-zA-Z]{1})|'
r'([a-zA-Z]{1}[0-9]{1})|([0-9]{1}[a-zA-Z]{1})|'
r'([a-zA-Z0-9][-_.a-zA-Z0-9]{0,61}[a-zA-Z0-9])).'
r'([a-zA-Z]{2,13}|[a-zA-Z0-9-]{2,30}.[a-zA-Z]{2,3})$'
)
q=QUrl(user_input)
if re.match(pattern,user_input) or user_input.startswith('https://') or user_input.startswith('http://'):
q.setScheme('http')
else:
q = QUrl(self.search_engine_base_url+user_input)
self.WebEngineView.setUrl(q)
def show_load_progress(self,progress):
"""
网页加载时,进度条、状态栏显示加载进度
:param progress:
:return:
"""
if progress==100:
self.statusBar().showMessage('完成',2000)
self.ui.progressBar_load_progress.hide()
self.is_load_finish_flag=True
self.ui.action_tingzhi.setEnabled(False)
title = self.WebEngineView.page().title()
self.setWindowTitle(title)
else:
self.statusBar().showMessage(str(progress)+'%')
self.is_load_finish_flag=False
self.ui.action_tingzhi.setEnabled(True)
title = self.WebEngineView.page().title()
if title.startswith('http') or title.startswith('https'):
title = '正在加载...'
self.setWindowTitle(title)
self.ui.progressBar_load_progress.setValue(progress)
def do_set_homepage(self):
"""
设置浏览器主页
:return:
"""
if self.is_load_finish_flag:
self.homepage_url=self.WebEngineView.page().url()
current_url_title=self.WebEngineView.page().title()
QMessageBox.information(self,'提示',f'主页已设置为:{
current_url_title}')
self.ui.action_daozhuye.setToolTip(current_url_title)
else:
QMessageBox.warning(self,'警告','请等待网页加载完成!')
def change_history_state(self):
"""
当网页开始加载时,tabname定义为“正在加载...”
:return:
"""
if self.WebEngineView.history().canGoBack():
self.ui.action_houtui.setEnabled(True)
else:
self.ui.action_houtui.setEnabled(False)
if self.WebEngineView.history().canGoForward():
self.ui.action_qianjin.setEnabled(True)
else:
self.ui.action_qianjin.setEnabled(False)
back_url_title=self.WebEngineView.history().backItem().title()
self.ui.action_houtui.setToolTip(back_url_title)
forward_url_title=self.WebEngineView.history().forwardItem().title()
self.ui.action_qianjin.setToolTip(forward_url_title)
def copy_current_link(self):
clipbord = QApplication.clipboard() # 操作剪切板
clipbord.setText(self.WebEngineView.page().url().toString())
QMessageBox.information(self,'提示','网址已经复制')
#---历史记录---
def show_history(self):
items=self.WebEngineView.history().items()
self.his_ui.tableWidget.clear()
self.url_list=[]
row_num =len(items)
self.his_ui.tableWidget.setRowCount(row_num)
self.his_ui.tableWidget.setHorizontalHeaderLabels(['地址'])
items.reverse()
for index,item in enumerate(items):
url=item.url().toString()
self.url_list.append(url)
title=item.title()
if title=='':
#获取不到title的网站返回url
title=url
# icon=item.iconUrl()#加载Icon没思路
# print(icon)
# ico=QtGui.QIcon()
new_table_widget_item = QTableWidgetItem(title)
new_table_widget_item.setToolTip(title)
# new_table_widget_item.setIcon(QtGui.QIcon())
self.his_ui.tableWidget.setItem(index, 0, new_table_widget_item)
self.his_ui.tableWidget.cellDoubleClicked.connect(self.jump_url_by_his)
self.his_ui.label.setText(f'一共有{
self.theme_color}>{
row_num}个历史记录,双击跳转')
self. his_ui.show()
# @pyqtSignal
def jump_url_by_his(self,row,_):
current_url=self.url_list[row]
self.WebEngineView.setUrl(QUrl(current_url))
self.his_ui.hide()
def _fullScreenRequested(self,request):
# self.WebEngineView.setParent(None, QtCore.Qt.Window)
request.accept()
self.WebEngineView.showFullScreen()
#---历史记录end---
#---主窗口事件
def resizeEvent(self,event):
x=self.geometry().x()+355
y=self.geometry().y()+248
if self.geometry().x()==0:
self.message_ui.main_ui_size_change_single.emit(780, 412)
else:
self.message_ui.main_ui_size_change_single.emit(x,y)
def moveEvent(self,event):
x=self.geometry().x()+355
y=self.geometry().y()+248
if self.geometry().x()==0:
self.message_ui.main_ui_size_change_single.emit(780, 412)
else:
self.message_ui.main_ui_size_change_single.emit(x,y)
def closeEvent(self, event):
ret =QMessageBox.question(self,'退出','您确定要退出吗?',QMessageBox.Yes|QMessageBox.No,QMessageBox.Yes)
if ret==QMessageBox.Yes:
event.accept()
else:
event.ignore()
if __name__ == '__main__':
#需要单独打开一个浏览器
#os.environ["QTWEBENGINE_REMOTE_DEBUGGING"] = "9000"
os.environ['QTWEBKIT_PLUGIN_PATH'] = os.path.abspath('Data')
app=QApplication(sys.argv)
ui=My_Web_Broswer()
ui.show()
sys.exit(app.exec_())
# -*- coding: utf-8 -*-
from PyQt5 import QtCore, QtGui, QtWidgets
class Web_browser_Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1107, 754)
MainWindow.setStyleSheet("QProgressBar { \n"
"text-align: center;\n"
"border: 2px solid grey; \n"
"border-radius: 5px; \n"
"background-color: #FFFFFF;}\n"
"QProgressBar::chunk { \n"
"background-color: #007FFF;\n"
"width: 1px;\n"
"background-color:rgb(255, 0, 255);\n"
"}\n"
"QPushButton {\n"
" border: 1px solid ;\n"
" border-radius: 4px;\n"
" padding: 1px 4px;\n"
" min-width: 80px;\n"
" min-height: 20px;\n"
"}\n"
"\n"
"QPushButton:hover{\n"
" border-color:rgb(255, 170, 255);\n"
"\n"
"}\n"
"\n"
"QCheckBox:hover{\n"
" background-colorrgb(255, 170, 255);\n"
"\n"
"}\n"
"\n"
"QLineEdit{\n"
" border: 1px solid ;\n"
" border-radius: 4px;\n"
" selection-background-color:rgb(255, 170, 127);\n"
" border: 1px solid;\n"
" border-style: inset;\n"
"}\n"
"QLineEdit:hover{\n"
" border-color:rgb(255, 170, 255);\n"
"}\n"
"QLineEdit:focus{\n"
" border-color: rgb(0, 170, 255);\n"
"}\n"
"\n"
"QLabel {\n"
" background: transparent;\n"
" border: 1px solid transparent;\n"
" padding: 1px;\n"
"}\n"
"QComboBox{\n"
" margin:2px;\n"
" border: 1px solid ;\n"
" border-radius: 4px;\n"
" background-color:rgb(255, 255, 255);\n"
" border-color:rgb(0, 0, 0);\n"
" min-width: 60px;\n"
" min-height: 23px;\n"
" max-width: 200px;\n"
" max-height: 23px;\n"
"}\n"
"QComboBox:hover{\n"
" background-color:rgb(255, 255, 255);\n"
" border-color:rgb(255, 170, 255);\n"
"\n"
"}\n"
"QToolBar{\n"
" margin:2px;\n"
" border: 1px solid ;\n"
" border-radius: 4px;\n"
" background-color:rgb(255, 255, 255);\n"
" border-color: rgb(0, 0, 0);\n"
"\n"
"}\n"
"QToolBar:hover{\n"
" background-color:rgb(255, 255, 255);\n"
" border-color:rgb(255, 170, 255);\n"
"\n"
"}\n"
"\n"
"\n"
"QGroupBox {\n"
" background-color: rgb(255, 255, 255);\n"
" border: 1px solid ;\n"
" border-radius: 4px;\n"
" margin-top:1em;\n"
"}\n"
"QGroupBox::title {\n"
" subcontrol-origin: margin;\n"
" subcontrol-position: top left;\n"
" top: 0.1em;\n"
" background-color: rgb(255, 170, 255);\n"
"font-size:10px\n"
"}\n"
"")
MainWindow.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setObjectName("lineEdit")
self.horizontalLayout.addWidget(self.lineEdit)
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setObjectName("pushButton")
self.horizontalLayout.addWidget(self.pushButton)
self.verticalLayout.addLayout(self.horizontalLayout)
self.progressBar_load_progress = QtWidgets.QProgressBar(self.centralwidget)
self.progressBar_load_progress.setMaximumSize(QtCore.QSize(16777215, 5))
self.progressBar_load_progress.setStyleSheet("")
self.progressBar_load_progress.setProperty("value", 0)
self.progressBar_load_progress.setTextVisible(False)
self.progressBar_load_progress.setFormat("")
self.progressBar_load_progress.setObjectName("progressBar_load_progress")
self.verticalLayout.addWidget(self.progressBar_load_progress)
self.frame = QtWidgets.QFrame(self.centralwidget)
self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame.setObjectName("frame")
self.verticalLayout.addWidget(self.frame)
self.progressBar_download_progress = QtWidgets.QProgressBar(self.centralwidget)
self.progressBar_download_progress.setMaximumSize(QtCore.QSize(16777215, 10))
self.progressBar_download_progress.setStyleSheet("QProgressBar { \n"
"text-align: center;\n"
"border: 2px solid grey; \n"
"border-radius: 5px; \n"
"background-color: #FFFFFF;}\n"
"QProgressBar::chunk { \n"
"background-color: #007FFF;\n"
"width: 5px;\n"
"background-color:rgb(179, 243, 83);\n"
"}")
self.progressBar_download_progress.setProperty("value", 0)
self.progressBar_download_progress.setTextVisible(False)
self.progressBar_download_progress.setFormat("")
self.progressBar_download_progress.setObjectName("progressBar_download_progress")
self.verticalLayout.addWidget(self.progressBar_download_progress)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1107, 26))
self.menubar.setObjectName("menubar")
self.menu = QtWidgets.QMenu(self.menubar)
self.menu.setObjectName("menu")
self.menu_2 = QtWidgets.QMenu(self.menubar)
self.menu_2.setObjectName("menu_2")
self.menu_3 = QtWidgets.QMenu(self.menubar)
self.menu_3.setObjectName("menu_3")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.toolBar = QtWidgets.QToolBar(MainWindow)
self.toolBar.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
self.toolBar.setObjectName("toolBar")
MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar)
self.action_houtui = QtWidgets.QAction(MainWindow)
self.action_houtui.setCheckable(False)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("icons/houtui.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action_houtui.setIcon(icon)
self.action_houtui.setObjectName("action_houtui")
self.action_qianjin = QtWidgets.QAction(MainWindow)
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap("icons/qianjin.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action_qianjin.setIcon(icon1)
self.action_qianjin.setObjectName("action_qianjin")
self.action_shuaxin = QtWidgets.QAction(MainWindow)
icon2 = QtGui.QIcon()
icon2.addPixmap(QtGui.QPixmap("icons/shuaxin.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action_shuaxin.setIcon(icon2)
self.action_shuaxin.setObjectName("action_shuaxin")
self.action_tingzhi = QtWidgets.QAction(MainWindow)
icon3 = QtGui.QIcon()
icon3.addPixmap(QtGui.QPixmap("icons/tingzhi.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action_tingzhi.setIcon(icon3)
self.action_tingzhi.setObjectName("action_tingzhi")
self.action_tuichu = QtWidgets.QAction(MainWindow)
icon4 = QtGui.QIcon()
icon4.addPixmap(QtGui.QPixmap("icons/quit.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action_tuichu.setIcon(icon4)
self.action_tuichu.setObjectName("action_tuichu")
self.action_about_author = QtWidgets.QAction(MainWindow)
icon5 = QtGui.QIcon()
icon5.addPixmap(QtGui.QPixmap("icons/about_author.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action_about_author.setIcon(icon5)
self.action_about_author.setObjectName("action_about_author")
self.action_about_software = QtWidgets.QAction(MainWindow)
icon6 = QtGui.QIcon()
icon6.addPixmap(QtGui.QPixmap("icons/about_software.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action_about_software.setIcon(icon6)
self.action_about_software.setObjectName("action_about_software")
self.action_daozhuye = QtWidgets.QAction(MainWindow)
icon7 = QtGui.QIcon()
icon7.addPixmap(QtGui.QPixmap("icons/zhuye.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action_daozhuye.setIcon(icon7)
self.action_daozhuye.setObjectName("action_daozhuye")
self.action_collect = QtWidgets.QAction(MainWindow)
icon8 = QtGui.QIcon()
icon8.addPixmap(QtGui.QPixmap("icons/shoucang.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action_collect.setIcon(icon8)
self.action_collect.setObjectName("action_collect")
self.action_lishi = QtWidgets.QAction(MainWindow)
icon9 = QtGui.QIcon()
icon9.addPixmap(QtGui.QPixmap("icons/lishi.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action_lishi.setIcon(icon9)
self.action_lishi.setObjectName("action_lishi")
self.action_main_set = QtWidgets.QAction(MainWindow)
icon10 = QtGui.QIcon()
icon10.addPixmap(QtGui.QPixmap("icons/shezhi.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action_main_set.setIcon(icon10)
self.action_main_set.setObjectName("action_main_set")
self.action_guanyv = QtWidgets.QAction(MainWindow)
icon11 = QtGui.QIcon()
icon11.addPixmap(QtGui.QPixmap("icons/xinxi.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action_guanyv.setIcon(icon11)
self.action_guanyv.setObjectName("action_guanyv")
self.action_fangda = QtWidgets.QAction(MainWindow)
icon12 = QtGui.QIcon()
icon12.addPixmap(QtGui.QPixmap("icons/fangda.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action_fangda.setIcon(icon12)
self.action_fangda.setObjectName("action_fangda")
self.action_suoxiao = QtWidgets.QAction(MainWindow)
icon13 = QtGui.QIcon()
icon13.addPixmap(QtGui.QPixmap("icons/suoxiao.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action_suoxiao.setIcon(icon13)
self.action_suoxiao.setObjectName("action_suoxiao")
self.action_copy_current_link = QtWidgets.QAction(MainWindow)
icon14 = QtGui.QIcon()
icon14.addPixmap(QtGui.QPixmap("icons/copy_link.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action_copy_current_link.setIcon(icon14)
self.action_copy_current_link.setObjectName("action_copy_current_link")
self.action_my_collection = QtWidgets.QAction(MainWindow)
icon15 = QtGui.QIcon()
icon15.addPixmap(QtGui.QPixmap("icons/my_collection.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action_my_collection.setIcon(icon15)
self.action_my_collection.setObjectName("action_my_collection")
self.action_about_qt = QtWidgets.QAction(MainWindow)
icon16 = QtGui.QIcon()
icon16.addPixmap(QtGui.QPixmap("icons/qt_logo.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action_about_qt.setIcon(icon16)
self.action_about_qt.setObjectName("action_about_qt")
self.action_screen_shot = QtWidgets.QAction(MainWindow)
icon17 = QtGui.QIcon()
icon17.addPixmap(QtGui.QPixmap("icons/screen_shot.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action_screen_shot.setIcon(icon17)
self.action_screen_shot.setObjectName("action_screen_shot")
self.menu.addSeparator()
self.menu.addAction(self.action_tuichu)
self.menu_2.addAction(self.action_daozhuye)
self.menu_3.addAction(self.action_about_author)
self.menu_3.addAction(self.action_about_software)
self.menu_3.addAction(self.action_about_qt)
self.menubar.addAction(self.menu.menuAction())
self.menubar.addAction(self.menu_2.menuAction())
self.menubar.addAction(self.menu_3.menuAction())
self.toolBar.addAction(self.action_houtui)
self.toolBar.addAction(self.action_qianjin)
self.toolBar.addAction(self.action_shuaxin)
self.toolBar.addAction(self.action_tingzhi)
self.toolBar.addAction(self.action_daozhuye)
self.toolBar.addSeparator()
self.toolBar.addAction(self.action_main_set)
self.toolBar.addAction(self.action_copy_current_link)
self.toolBar.addAction(self.action_screen_shot)
self.toolBar.addAction(self.action_fangda)
self.toolBar.addAction(self.action_suoxiao)
self.toolBar.addAction(self.action_collect)
self.toolBar.addAction(self.action_my_collection)
self.toolBar.addAction(self.action_lishi)
self.toolBar.addAction(self.action_guanyv)
self.toolBar.addSeparator()
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "转到"))
self.menu.setTitle(_translate("MainWindow", "开始"))
self.menu_2.setTitle(_translate("MainWindow", "操作"))
self.menu_3.setTitle(_translate("MainWindow", "关于"))
self.toolBar.setWindowTitle(_translate("MainWindow", "toolBar"))
self.toolBar.setToolTip(_translate("MainWindow", "百度一下,你就知道"))
self.action_houtui.setText(_translate("MainWindow", "后退"))
self.action_qianjin.setText(_translate("MainWindow", "前进"))
self.action_shuaxin.setText(_translate("MainWindow", "刷新"))
self.action_tingzhi.setText(_translate("MainWindow", "停止"))
self.action_tuichu.setText(_translate("MainWindow", "退出"))
self.action_about_author.setText(_translate("MainWindow", "关于作者"))
self.action_about_author.setIconText(_translate("MainWindow", "关于作者"))
self.action_about_software.setText(_translate("MainWindow", "关于软件"))
self.action_daozhuye.setText(_translate("MainWindow", "主页"))
self.action_daozhuye.setToolTip(_translate("MainWindow", "到主页"))
self.action_collect.setText(_translate("MainWindow", "收藏"))
self.action_collect.setToolTip(_translate("MainWindow", "收藏"))
self.action_lishi.setText(_translate("MainWindow", "历史"))
self.action_lishi.setToolTip(_translate("MainWindow", "浏览历史"))
self.action_main_set.setText(_translate("MainWindow", "设置"))
self.action_main_set.setIconText(_translate("MainWindow", "设置"))
self.action_guanyv.setText(_translate("MainWindow", "关于"))
self.action_fangda.setText(_translate("MainWindow", "网页放大"))
self.action_suoxiao.setText(_translate("MainWindow", "网页缩小"))
self.action_copy_current_link.setText(_translate("MainWindow", "复制链接"))
self.action_my_collection.setText(_translate("MainWindow", "我的收藏"))
self.action_about_qt.setText(_translate("MainWindow", "关于QT"))
self.action_screen_shot.setText(_translate("MainWindow", "网页截图"))
self.action_screen_shot.setToolTip(_translate("MainWindow", "网页截图"))
import main_resource
# -*- coding: utf-8 -*-
from PyQt5 import QtCore, QtGui, QtWidgets
class Main_set_Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.setWindowModality(QtCore.Qt.ApplicationModal)
Dialog.resize(723, 551)
Dialog.setStyleSheet("QPushButton {\n"
" border: 1px solid ;\n"
" border-radius: 4px;\n"
" padding: 1px 4px;\n"
" min-width: 80px;\n"
" min-height: 20px;\n"
"}\n"
"\n"
"QPushButton:hover{\n"
" border-color:rgb(255, 170, 255);\n"
"\n"
"}\n"
"\n"
"QCheckBox:hover{\n"
" background-color:rgb(255, 170, 255);\n"
"\n"
"}\n"
"\n"
"QLineEdit{\n"
" border: 1px solid ;\n"
" border-radius: 4px;\n"
" selection-background-color:rgb(255, 170, 127);\n"
" border: 1px solid;\n"
" border-style: inset;\n"
"}\n"
"QLineEdit:hover{\n"
" border-color:rgb(255, 170, 255);\n"
"}\n"
"QLineEdit:focus{\n"
" border-color: rgb(0, 170, 255);\n"
"}\n"
"\n"
"QLabel {\n"
" background: transparent;\n"
" border: 1px solid transparent;\n"
" padding: 1px;\n"
"}\n"
"QComboBox{\n"
" margin:2px;\n"
" border: 1px solid ;\n"
" border-radius: 4px;\n"
" background-color:rgb(255, 255, 255);\n"
" border-color:rgb(0, 0, 0);\n"
" min-width: 60px;\n"
" min-height: 23px;\n"
" max-width: 200px;\n"
" max-height: 23px;\n"
"}\n"
"QComboBox:hover{\n"
" background-color:rgb(255, 255, 255);\n"
" border-color:rgb(255, 170, 255);\n"
"\n"
"}\n"
"QToolBar{\n"
" margin:2px;\n"
" border: 1px solid ;\n"
" border-radius: 4px;\n"
" background-color:rgb(255, 255, 255);\n"
" border-color: rgb(0, 0, 0);\n"
"\n"
"}\n"
"QToolBar:hover{\n"
" background-color:rgb(255, 255, 255);\n"
" border-color:rgb(255, 170, 255);\n"
"\n"
"}\n"
"\n"
"\n"
"QGroupBox {\n"
" background-color: rgb(255, 255, 255);\n"
" border: 1px solid ;\n"
" border-radius: 4px;\n"
" margin-top:1em;\n"
"}\n"
"QGroupBox::title {\n"
" subcontrol-origin: margin;\n"
" subcontrol-position: top left;\n"
" top: 0.1em;\n"
" background-color: rgb(255, 170, 255);\n"
"font-size:10px\n"
"}\n"
"")
self.horizontalLayout_14 = QtWidgets.QHBoxLayout(Dialog)
self.horizontalLayout_14.setObjectName("horizontalLayout_14")
self.tabWidget = QtWidgets.QTabWidget(Dialog)
self.tabWidget.setEnabled(True)
self.tabWidget.setAcceptDrops(False)
self.tabWidget.setStyleSheet("")
self.tabWidget.setTabPosition(QtWidgets.QTabWidget.West)
self.tabWidget.setElideMode(QtCore.Qt.ElideLeft)
self.tabWidget.setObjectName("tabWidget")
self.tab = QtWidgets.QWidget()
self.tab.setObjectName("tab")
self.verticalLayout = QtWidgets.QVBoxLayout(self.tab)
self.verticalLayout.setObjectName("verticalLayout")
self.groupBox_2 = QtWidgets.QGroupBox(self.tab)
self.groupBox_2.setObjectName("groupBox_2")
self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.groupBox_2)
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.label_3 = QtWidgets.QLabel(self.groupBox_2)
self.label_3.setObjectName("label_3")
self.horizontalLayout.addWidget(self.label_3)
self.lineEdit = QtWidgets.QLineEdit(self.groupBox_2)
self.lineEdit.setObjectName("lineEdit")
self.horizontalLayout.addWidget(self.lineEdit)
self.horizontalLayout_4.addLayout(self.horizontalLayout)
self.verticalLayout.addWidget(self.groupBox_2)
self.groupBox = QtWidgets.QGroupBox(self.tab)
self.groupBox.setObjectName("groupBox")
self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.groupBox)
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.label = QtWidgets.QLabel(self.groupBox)
self.label.setObjectName("label")
self.horizontalLayout_2.addWidget(self.label)
self.comboBox = QtWidgets.QComboBox(self.groupBox)
self.comboBox.setObjectName("comboBox")
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("icons/baidu_logo.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.comboBox.addItem(icon, "")
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap("icons/sougou_logo.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.comboBox.addItem(icon1, "")
icon2 = QtGui.QIcon()
icon2.addPixmap(QtGui.QPixmap("icons/google_logo.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.comboBox.addItem(icon2, "")
icon3 = QtGui.QIcon()
icon3.addPixmap(QtGui.QPixmap("icons/360_logo.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.comboBox.addItem(icon3, "")
icon4 = QtGui.QIcon()
icon4.addPixmap(QtGui.QPixmap("icons/bing_logo.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.comboBox.addItem(icon4, "")
self.horizontalLayout_2.addWidget(self.comboBox)
self.horizontalLayout_3.addLayout(self.horizontalLayout_2)
self.verticalLayout.addWidget(self.groupBox)
self.groupBox_12 = QtWidgets.QGroupBox(self.tab)
self.groupBox_12.setObjectName("groupBox_12")
self.horizontalLayout_15 = QtWidgets.QHBoxLayout(self.groupBox_12)
self.horizontalLayout_15.setObjectName("horizontalLayout_15")
self.horizontalLayout_20 = QtWidgets.QHBoxLayout()
self.horizontalLayout_20.setObjectName("horizontalLayout_20")
self.label_4 = QtWidgets.QLabel(self.groupBox_12)
self.label_4.setObjectName("label_4")
self.horizontalLayout_20.addWidget(self.label_4)
self.comboBox_5 = QtWidgets.QComboBox(self.groupBox_12)
self.comboBox_5.setObjectName("comboBox_5")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.horizontalLayout_20.addWidget(self.comboBox_5)
self.horizontalLayout_15.addLayout(self.horizontalLayout_20)
self.verticalLayout.addWidget(self.groupBox_12)
self.verticalLayout.setStretch(0, 2)
self.verticalLayout.setStretch(1, 2)
self.verticalLayout.setStretch(2, 4)
self.tabWidget.addTab(self.tab, "")
self.tab_2 = QtWidgets.QWidget()
self.tab_2.setObjectName("tab_2")
self.verticalLayout_6 = QtWidgets.QVBoxLayout(self.tab_2)
self.verticalLayout_6.setObjectName("verticalLayout_6")
self.groupBox_3 = QtWidgets.QGroupBox(self.tab_2)
self.groupBox_3.setObjectName("groupBox_3")
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.groupBox_3)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.horizontalLayout_6 = QtWidgets.QHBoxLayout()
self.horizontalLayout_6.setObjectName("horizontalLayout_6")
self.label_6 = QtWidgets.QLabel(self.groupBox_3)
self.label_6.setObjectName("label_6")
self.horizontalLayout_6.addWidget(self.label_6)
self.label_7 = QtWidgets.QLabel(self.groupBox_3)
self.label_7.setObjectName("label_7")
self.horizontalLayout_6.addWidget(self.label_7)
self.pushButton_2 = QtWidgets.QPushButton(self.groupBox_3)
self.pushButton_2.setObjectName("pushButton_2")
self.horizontalLayout_6.addWidget(self.pushButton_2)
self.verticalLayout_2.addLayout(self.horizontalLayout_6)
self.verticalLayout_6.addWidget(self.groupBox_3)
self.groupBox_8 = QtWidgets.QGroupBox(self.tab_2)
self.groupBox_8.setObjectName("groupBox_8")
self.horizontalLayout_13 = QtWidgets.QHBoxLayout(self.groupBox_8)
self.horizontalLayout_13.setObjectName("horizontalLayout_13")
self.comboBox_2 = QtWidgets.QComboBox(self.groupBox_8)
self.comboBox_2.setMinimumSize(QtCore.QSize(66, 29))
self.comboBox_2.setMaximumSize(QtCore.QSize(206, 29))
self.comboBox_2.setStyleSheet("")
self.comboBox_2.setObjectName("comboBox_2")
icon5 = QtGui.QIcon()
icon5.addPixmap(QtGui.QPixmap("icons/windows_nt_logo.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.comboBox_2.addItem(icon5, "")
icon6 = QtGui.QIcon()
icon6.addPixmap(QtGui.QPixmap("icons/android_logo.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.comboBox_2.addItem(icon6, "")
icon7 = QtGui.QIcon()
icon7.addPixmap(QtGui.QPixmap("icons/iphone_logo.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.comboBox_2.addItem(icon7, "")
icon8 = QtGui.QIcon()
icon8.addPixmap(QtGui.QPixmap("icons/ipad_logo.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.comboBox_2.addItem(icon8, "")
self.horizontalLayout_13.addWidget(self.comboBox_2)
self.verticalLayout_6.addWidget(self.groupBox_8)
self.groupBox_5 = QtWidgets.QGroupBox(self.tab_2)
self.groupBox_5.setObjectName("groupBox_5")
self.verticalLayout_4 = QtWidgets.QVBoxLayout(self.groupBox_5)
self.verticalLayout_4.setObjectName("verticalLayout_4")
self.horizontalLayout_8 = QtWidgets.QHBoxLayout()
self.horizontalLayout_8.setObjectName("horizontalLayout_8")
self.label_9 = QtWidgets.QLabel(self.groupBox_5)
self.label_9.setObjectName("label_9")
self.horizontalLayout_8.addWidget(self.label_9)
self.comboBox_3 = QtWidgets.QComboBox(self.groupBox_5)
self.comboBox_3.setObjectName("comboBox_3")
self.comboBox_3.addItem("")
self.comboBox_3.addItem("")
self.horizontalLayout_8.addWidget(self.comboBox_3)
self.verticalLayout_4.addLayout(self.horizontalLayout_8)
self.horizontalLayout_16 = QtWidgets.QHBoxLayout()
self.horizontalLayout_16.setObjectName("horizontalLayout_16")
self.label_16 = QtWidgets.QLabel(self.groupBox_5)
self.label_16.setObjectName("label_16")
self.horizontalLayout_16.addWidget(self.label_16)
self.comboBox_4 = QtWidgets.QComboBox(self.groupBox_5)
self.comboBox_4.setObjectName("comboBox_4")
self.comboBox_4.addItem("")
self.comboBox_4.addItem("")
self.horizontalLayout_16.addWidget(self.comboBox_4)
self.verticalLayout_4.addLayout(self.horizontalLayout_16)
self.verticalLayout_6.addWidget(self.groupBox_5)
self.groupBox_9 = QtWidgets.QGroupBox(self.tab_2)
self.groupBox_9.setObjectName("groupBox_9")
self.verticalLayout_9 = QtWidgets.QVBoxLayout(self.groupBox_9)
self.verticalLayout_9.setObjectName("verticalLayout_9")
self.horizontalLayout_5 = QtWidgets.QHBoxLayout()
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
self.checkBox = QtWidgets.QCheckBox(self.groupBox_9)
self.checkBox.setObjectName("checkBox")
self.horizontalLayout_5.addWidget(self.checkBox)
self.checkBox_2 = QtWidgets.QCheckBox(self.groupBox_9)
self.checkBox_2.setObjectName("checkBox_2")
self.horizontalLayout_5.addWidget(self.checkBox_2)
self.checkBox_3 = QtWidgets.QCheckBox(self.groupBox_9)
self.checkBox_3.setObjectName("checkBox_3")
self.horizontalLayout_5.addWidget(self.checkBox_3)
self.checkBox_4 = QtWidgets.QCheckBox(self.groupBox_9)
self.checkBox_4.setObjectName("checkBox_4")
self.horizontalLayout_5.addWidget(self.checkBox_4)
self.verticalLayout_9.addLayout(self.horizontalLayout_5)
self.verticalLayout_5 = QtWidgets.QVBoxLayout()
self.verticalLayout_5.setObjectName("verticalLayout_5")
self.checkBox_5 = QtWidgets.QCheckBox(self.groupBox_9)
self.checkBox_5.setObjectName("checkBox_5")
self.verticalLayout_5.addWidget(self.checkBox_5)
self.verticalLayout_9.addLayout(self.verticalLayout_5)
self.groupBox_10 = QtWidgets.QGroupBox(self.groupBox_9)
self.groupBox_10.setObjectName("groupBox_10")
self.horizontalLayout_18 = QtWidgets.QHBoxLayout(self.groupBox_10)
self.horizontalLayout_18.setObjectName("horizontalLayout_18")
self.checkBox_6 = QtWidgets.QCheckBox(self.groupBox_10)
self.checkBox_6.setObjectName("checkBox_6")
self.horizontalLayout_18.addWidget(self.checkBox_6)
self.label_18 = QtWidgets.QLabel(self.groupBox_10)
self.label_18.setObjectName("label_18")
self.horizontalLayout_18.addWidget(self.label_18)
self.lineEdit_5 = QtWidgets.QLineEdit(self.groupBox_10)
self.lineEdit_5.setEnabled(False)
self.lineEdit_5.setMinimumSize(QtCore.QSize(80, 0))
self.lineEdit_5.setMaximumSize(QtCore.QSize(80, 16777215))
self.lineEdit_5.setObjectName("lineEdit_5")
self.horizontalLayout_18.addWidget(self.lineEdit_5)
self.pushButton_8 = QtWidgets.QPushButton(self.groupBox_10)
self.pushButton_8.setEnabled(False)
self.pushButton_8.setObjectName("pushButton_8")
self.horizontalLayout_18.addWidget(self.pushButton_8)
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_18.addItem(spacerItem)
self.verticalLayout_9.addWidget(self.groupBox_10)
self.groupBox_11 = QtWidgets.QGroupBox(self.groupBox_9)
self.groupBox_11.setObjectName("groupBox_11")
self.horizontalLayout_19 = QtWidgets.QHBoxLayout(self.groupBox_11)
self.horizontalLayout_19.setObjectName("horizontalLayout_19")
self.checkBox_7 = QtWidgets.QCheckBox(self.groupBox_11)
self.checkBox_7.setObjectName("checkBox_7")
self.horizontalLayout_19.addWidget(self.checkBox_7)
self.label_20 = QtWidgets.QLabel(self.groupBox_11)
self.label_20.setObjectName("label_20")
self.horizontalLayout_19.addWidget(self.label_20)
self.lineEdit_6 = QtWidgets.QLineEdit(self.groupBox_11)
self.lineEdit_6.setEnabled(False)
self.lineEdit_6.setMinimumSize(QtCore.QSize(80, 0))
self.lineEdit_6.setMaximumSize(QtCore.QSize(80, 16777215))
self.lineEdit_6.setObjectName("lineEdit_6")
self.horizontalLayout_19.addWidget(self.lineEdit_6)
self.label_22 = QtWidgets.QLabel(self.groupBox_11)
self.label_22.setObjectName("label_22")
self.horizontalLayout_19.addWidget(self.label_22)
self.lineEdit_7 = QtWidgets.QLineEdit(self.groupBox_11)
self.lineEdit_7.setEnabled(False)
self.lineEdit_7.setMinimumSize(QtCore.QSize(80, 0))
self.lineEdit_7.setMaximumSize(QtCore.QSize(80, 16777215))
self.lineEdit_7.setObjectName("lineEdit_7")
self.horizontalLayout_19.addWidget(self.lineEdit_7)
spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_19.addItem(spacerItem1)
self.verticalLayout_9.addWidget(self.groupBox_11)
self.verticalLayout_6.addWidget(self.groupBox_9)
self.verticalLayout_6.setStretch(0, 1)
self.verticalLayout_6.setStretch(1, 1)
self.verticalLayout_6.setStretch(2, 2)
self.verticalLayout_6.setStretch(3, 3)
self.tabWidget.addTab(self.tab_2, "")
self.tab_3 = QtWidgets.QWidget()
self.tab_3.setObjectName("tab_3")
self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.tab_3)
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.groupBox_6 = QtWidgets.QGroupBox(self.tab_3)
self.groupBox_6.setObjectName("groupBox_6")
self.verticalLayout_8 = QtWidgets.QVBoxLayout(self.groupBox_6)
self.verticalLayout_8.setObjectName("verticalLayout_8")
self.horizontalLayout_9 = QtWidgets.QHBoxLayout()
self.horizontalLayout_9.setObjectName("horizontalLayout_9")
self.label_2 = QtWidgets.QLabel(self.groupBox_6)
self.label_2.setObjectName("label_2")
self.horizontalLayout_9.addWidget(self.label_2)
self.label_15 = QtWidgets.QLabel(self.groupBox_6)
self.label_15.setObjectName("label_15")
self.horizontalLayout_9.addWidget(self.label_15)
self.pushButton_4 = QtWidgets.QPushButton(self.groupBox_6)
self.pushButton_4.setObjectName("pushButton_4")
self.horizontalLayout_9.addWidget(self.pushButton_4)
self.verticalLayout_8.addLayout(self.horizontalLayout_9)
self.horizontalLayout_10 = QtWidgets.QHBoxLayout()
self.horizontalLayout_10.setObjectName("horizontalLayout_10")
self.label_10 = QtWidgets.QLabel(self.groupBox_6)
self.label_10.setObjectName("label_10")
self.horizontalLayout_10.addWidget(self.label_10)
self.label_13 = QtWidgets.QLabel(self.groupBox_6)
self.label_13.setObjectName("label_13")
self.horizontalLayout_10.addWidget(self.label_13)
self.pushButton_5 = QtWidgets.QPushButton(self.groupBox_6)
self.pushButton_5.setObjectName("pushButton_5")
self.horizontalLayout_10.addWidget(self.pushButton_5)
self.verticalLayout_8.addLayout(self.horizontalLayout_10)
self.groupBox_7 = QtWidgets.QGroupBox(self.groupBox_6)
self.groupBox_7.setObjectName("groupBox_7")
self.verticalLayout_7 = QtWidgets.QVBoxLayout(self.groupBox_7)
self.verticalLayout_7.setObjectName("verticalLayout_7")
self.horizontalLayout_11 = QtWidgets.QHBoxLayout()
self.horizontalLayout_11.setObjectName("horizontalLayout_11")
self.label_11 = QtWidgets.QLabel(self.groupBox_7)
self.label_11.setObjectName("label_11")
self.horizontalLayout_11.addWidget(self.label_11)
self.pushButton_6 = QtWidgets.QPushButton(self.groupBox_7)
self.pushButton_6.setObjectName("pushButton_6")
self.horizontalLayout_11.addWidget(self.pushButton_6)
self.verticalLayout_7.addLayout(self.horizontalLayout_11)
self.horizontalLayout_12 = QtWidgets.QHBoxLayout()
self.horizontalLayout_12.setObjectName("horizontalLayout_12")
self.label_12 = QtWidgets.QLabel(self.groupBox_7)
self.label_12.setObjectName("label_12")
self.horizontalLayout_12.addWidget(self.label_12)
self.pushButton_7 = QtWidgets.QPushButton(self.groupBox_7)
self.pushButton_7.setObjectName("pushButton_7")
self.horizontalLayout_12.addWidget(self.pushButton_7)
self.verticalLayout_7.addLayout(self.horizontalLayout_12)
self.verticalLayout_8.addWidget(self.groupBox_7)
self.verticalLayout_3.addWidget(self.groupBox_6)
self.groupBox_4 = QtWidgets.QGroupBox(self.tab_3)
self.groupBox_4.setObjectName("groupBox_4")
self.horizontalLayout_21 = QtWidgets.QHBoxLayout(self.groupBox_4)
self.horizontalLayout_21.setObjectName("horizontalLayout_21")
self.horizontalLayout_7 = QtWidgets.QHBoxLayout()
self.horizontalLayout_7.setObjectName("horizontalLayout_7")
self.label_8 = QtWidgets.QLabel(self.groupBox_4)
self.label_8.setObjectName("label_8")
self.horizontalLayout_7.addWidget(self.label_8)
self.lineEdit_2 = QtWidgets.QLineEdit(self.groupBox_4)
self.lineEdit_2.setReadOnly(True)
self.lineEdit_2.setObjectName("lineEdit_2")
self.horizontalLayout_7.addWidget(self.lineEdit_2)
self.pushButton_3 = QtWidgets.QPushButton(self.groupBox_4)
self.pushButton_3.setObjectName("pushButton_3")
self.horizontalLayout_7.addWidget(self.pushButton_3)
self.horizontalLayout_21.addLayout(self.horizontalLayout_7)
self.verticalLayout_3.addWidget(self.groupBox_4)
self.groupBox_13 = QtWidgets.QGroupBox(self.tab_3)
self.groupBox_13.setObjectName("groupBox_13")
self.horizontalLayout_22 = QtWidgets.QHBoxLayout(self.groupBox_13)
self.horizontalLayout_22.setObjectName("horizontalLayout_22")
self.horizontalLayout_23 = QtWidgets.QHBoxLayout()
self.horizontalLayout_23.setObjectName("horizontalLayout_23")
self.label_21 = QtWidgets.QLabel(self.groupBox_13)
self.label_21.setObjectName("label_21")
self.horizontalLayout_23.addWidget(self.label_21)
self.lineEdit_3 = QtWidgets.QLineEdit(self.groupBox_13)
self.lineEdit_3.setReadOnly(True)
self.lineEdit_3.setObjectName("lineEdit_3")
self.horizontalLayout_23.addWidget(self.lineEdit_3)
self.pushButton_10 = QtWidgets.QPushButton(self.groupBox_13)
self.pushButton_10.setObjectName("pushButton_10")
self.horizontalLayout_23.addWidget(self.pushButton_10)
self.horizontalLayout_22.addLayout(self.horizontalLayout_23)
self.verticalLayout_3.addWidget(self.groupBox_13)
self.tabWidget.addTab(self.tab_3, "")
self.tab_4 = QtWidgets.QWidget()
self.tab_4.setObjectName("tab_4")
self.layoutWidget = QtWidgets.QWidget(self.tab_4)
self.layoutWidget.setGeometry(QtCore.QRect(80, 170, 431, 211))
self.layoutWidget.setObjectName("layoutWidget")
self.horizontalLayout_17 = QtWidgets.QHBoxLayout(self.layoutWidget)
self.horizontalLayout_17.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_17.setObjectName("horizontalLayout_17")
self.label_14 = QtWidgets.QLabel(self.layoutWidget)
self.label_14.setText("")
self.label_14.setPixmap(QtGui.QPixmap("icons/head_img.png"))
self.label_14.setObjectName("label_14")
self.horizontalLayout_17.addWidget(self.label_14)
self.label_17 = QtWidgets.QLabel(self.layoutWidget)
self.label_17.setStyleSheet("QLabel{\n"
" \n"
" font: 16pt \"Arial\";\n"
"}")
self.label_17.setTextFormat(QtCore.Qt.MarkdownText)
self.label_17.setOpenExternalLinks(True)
self.label_17.setObjectName("label_17")
self.horizontalLayout_17.addWidget(self.label_17)
self.label_19 = QtWidgets.QLabel(self.tab_4)
self.label_19.setGeometry(QtCore.QRect(60, 30, 461, 131))
self.label_19.setObjectName("label_19")
self.tabWidget.addTab(self.tab_4, "")
self.horizontalLayout_14.addWidget(self.tabWidget)
self.retranslateUi(Dialog)
self.tabWidget.setCurrentIndex(0)
self.comboBox_5.setCurrentIndex(3)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "设置"))
self.groupBox_2.setTitle(_translate("Dialog", "主页"))
self.label_3.setText(_translate("Dialog", "主页地址"))
self.groupBox.setTitle(_translate("Dialog", "搜索引擎"))
self.label.setText(_translate("Dialog", "地址栏中的搜索引擎"))
self.comboBox.setItemText(0, _translate("Dialog", "百度"))
self.comboBox.setItemText(1, _translate("Dialog", "搜狗"))
self.comboBox.setItemText(2, _translate("Dialog", "Google"))
self.comboBox.setItemText(3, _translate("Dialog", "360"))
self.comboBox.setItemText(4, _translate("Dialog", "Bing"))
self.groupBox_12.setTitle(_translate("Dialog", "网页缩放"))
self.label_4.setText(_translate("Dialog", "网页缩放比例"))
self.comboBox_5.setCurrentText(_translate("Dialog", "100%"))
self.comboBox_5.setItemText(0, _translate("Dialog", "30%"))
self.comboBox_5.setItemText(1, _translate("Dialog", "50%"))
self.comboBox_5.setItemText(2, _translate("Dialog", "80%"))
self.comboBox_5.setItemText(3, _translate("Dialog", "100%"))
self.comboBox_5.setItemText(4, _translate("Dialog", "120%"))
self.comboBox_5.setItemText(5, _translate("Dialog", "150%"))
self.comboBox_5.setItemText(6, _translate("Dialog", "180%"))
self.comboBox_5.setItemText(7, _translate("Dialog", "200%"))
self.comboBox_5.setItemText(8, _translate("Dialog", "250%"))
self.comboBox_5.setItemText(9, _translate("Dialog", "300%"))
self.comboBox_5.setItemText(10, _translate("Dialog", "400%"))
self.comboBox_5.setItemText(11, _translate("Dialog", "500%"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("Dialog", "基本"))
self.groupBox_3.setTitle(_translate("Dialog", "颜色"))
self.label_6.setText(_translate("Dialog", "主题颜色"))
self.label_7.setText(_translate("Dialog", "主题颜色
"))
self.pushButton_2.setText(_translate("Dialog", "更改颜色"))
self.groupBox_8.setTitle(_translate("Dialog", "UA"))
self.comboBox_2.setItemText(0, _translate("Dialog", "Windows电脑"))
self.comboBox_2.setItemText(1, _translate("Dialog", "安卓手机"))
self.comboBox_2.setItemText(2, _translate("Dialog", "苹果手机"))
self.comboBox_2.setItemText(3, _translate("Dialog", "IPad"))
self.groupBox_5.setTitle(_translate("Dialog", "语言"))
self.label_9.setText(_translate("Dialog", "系统语言(未实现)"))
self.comboBox_3.setItemText(0, _translate("Dialog", "Chinese(简体中文)"))
self.comboBox_3.setItemText(1, _translate("Dialog", "English"))
self.label_16.setText(_translate("Dialog", "编码"))
self.comboBox_4.setItemText(0, _translate("Dialog", "iso-8859-1"))
self.comboBox_4.setItemText(1, _translate("Dialog", "utf-8"))
self.groupBox_9.setTitle(_translate("Dialog", "其他"))
self.checkBox.setText(_translate("Dialog", "启用拼写检查"))
self.checkBox_2.setText(_translate("Dialog", "启用空间导航"))
self.checkBox_3.setText(_translate("Dialog", "启用全局证书验证"))
self.checkBox_4.setText(_translate("Dialog", "允许非安全来源访问地理定位"))
self.checkBox_5.setText(_translate("Dialog", "忽略证书错误(不安全)"))
self.groupBox_10.setTitle(_translate("Dialog", "调试"))
self.checkBox_6.setText(_translate("Dialog", "启用调试(未实现)"))
self.label_18.setText(_translate("Dialog", "调试端口:"))
self.lineEdit_5.setText(_translate("Dialog", "6688"))
self.pushButton_8.setText(_translate("Dialog", "打开调试页面"))
self.groupBox_11.setTitle(_translate("Dialog", "代理"))
self.checkBox_7.setText(_translate("Dialog", "启用代理(未实现)"))
self.label_20.setText(_translate("Dialog", "IP:"))
self.lineEdit_6.setText(_translate("Dialog", "127.0.0.1"))
self.label_22.setText(_translate("Dialog", "端口:"))
self.lineEdit_7.setText(_translate("Dialog", "6688"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("Dialog", "个性"))
self.groupBox_6.setTitle(_translate("Dialog", "清理记录"))
self.label_2.setText(_translate("Dialog", "浏览历史"))
self.label_15.setText(_translate("Dialog", "一共存在个历史记录"))
self.pushButton_4.setText(_translate("Dialog", "清空浏览记录"))
self.label_10.setText(_translate("Dialog", "缓存"))
self.label_13.setText(_translate("Dialog", "一共产生了M的缓存"))
self.pushButton_5.setText(_translate("Dialog", "清空缓存"))
self.groupBox_7.setTitle(_translate("Dialog", "cookie"))
self.label_11.setText(_translate("Dialog", "cookie"))
self.pushButton_6.setText(_translate("Dialog", "清空cookie"))
self.label_12.setText(_translate("Dialog", "会话cookie"))
self.pushButton_7.setText(_translate("Dialog", "清空会话cookie"))
self.groupBox_4.setTitle(_translate("Dialog", "下载"))
self.label_8.setText(_translate("Dialog", "默认下载位置"))
self.pushButton_3.setText(_translate("Dialog", "更改位置"))
self.groupBox_13.setTitle(_translate("Dialog", "截图"))
self.label_21.setText(_translate("Dialog", "截图保存位置"))
self.pushButton_10.setText(_translate("Dialog", "更改位置"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_3), _translate("Dialog", "隐私"))
self.label_17.setText(_translate("Dialog", "作者:懷淰メ
By:PyQt5
"))
self.label_19.setText(_translate("Dialog", "青青子衿,悠悠我心。
但为君故,沉吟至今。
"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_4), _translate("Dialog", "关于"))
import main_resource
from PyQt5 import QtCore, QtGui, QtWidgets
class History_Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.setWindowModality(QtCore.Qt.ApplicationModal)
Form.resize(450, 600)
Form.setMaximumSize(QtCore.QSize(450, 600))
Form.setStyleSheet("")
self.verticalLayout = QtWidgets.QVBoxLayout(Form)
self.verticalLayout.setObjectName("verticalLayout")
self.tableWidget = QtWidgets.QTableWidget(Form)
self.tableWidget.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.tableWidget.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
self.tableWidget.setGridStyle(QtCore.Qt.DashLine)
self.tableWidget.setWordWrap(False)
self.tableWidget.setObjectName("tableWidget")
self.tableWidget.setColumnCount(1)
self.tableWidget.setRowCount(0)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(0, item)
self.tableWidget.horizontalHeader().setDefaultSectionSize(50)
self.tableWidget.horizontalHeader().setStretchLastSection(True)
self.tableWidget.verticalHeader().setVisible(True)
self.tableWidget.verticalHeader().setStretchLastSection(False)
self.verticalLayout.addWidget(self.tableWidget)
self.label = QtWidgets.QLabel(Form)
self.label.setText("")
self.label.setOpenExternalLinks(True)
self.label.setObjectName("label")
self.verticalLayout.addWidget(self.label)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "历史记录"))
item = self.tableWidget.horizontalHeaderItem(0)
item.setText(_translate("Form", "地址"))
# -*- coding: utf-8 -*-
from PyQt5 import QtCore, QtGui, QtWidgets
class Favourite_Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.setWindowModality(QtCore.Qt.ApplicationModal)
Form.resize(550, 600)
Form.setMaximumSize(QtCore.QSize(550, 600))
Form.setStyleSheet("")
self.verticalLayout = QtWidgets.QVBoxLayout(Form)
self.verticalLayout.setObjectName("verticalLayout")
self.tableWidget = QtWidgets.QTableWidget(Form)
self.tableWidget.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.tableWidget.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
self.tableWidget.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
self.tableWidget.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
self.tableWidget.setGridStyle(QtCore.Qt.DashLine)
self.tableWidget.setWordWrap(False)
self.tableWidget.setObjectName("tableWidget")
self.tableWidget.setColumnCount(2)
self.tableWidget.setRowCount(0)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(0, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(1, item)
self.tableWidget.horizontalHeader().setDefaultSectionSize(200)
self.tableWidget.horizontalHeader().setStretchLastSection(True)
self.tableWidget.verticalHeader().setVisible(True)
self.tableWidget.verticalHeader().setStretchLastSection(False)
self.verticalLayout.addWidget(self.tableWidget)
self.label = QtWidgets.QLabel(Form)
self.label.setText("")
self.label.setOpenExternalLinks(True)
self.label.setObjectName("label")
self.verticalLayout.addWidget(self.label)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "我的收藏"))
item = self.tableWidget.horizontalHeaderItem(0)
item.setText(_translate("Form", "时间"))
item = self.tableWidget.horizontalHeaderItem(1)
item.setText(_translate("Form", "地址"))
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(400, 300)
self.verticalLayout = QtWidgets.QVBoxLayout(Form)
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.label = QtWidgets.QLabel(Form)
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
self.horizontalLayout.addWidget(self.label)
self.verticalLayout.addLayout(self.horizontalLayout)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
self.timer = QTimer(self) # 初始化一个定时器
self.timer.timeout.connect(self.close) # 计时结束调用operate()方法
self.timer.start(3000) # 设置计时间隔并启动 3s后关闭窗口
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.label.setText(_translate("Form", "当前缩放比例
"))
import os
import time
class Util:
def read_txt(self,txt_file):
try:
with open(txt_file,'r',encoding='utf-8')as f:
data=f.readlines()
return data
except:
open(txt_file,'w',encoding='utf-8')
def get_time_string(self):
"""
获取时间字符串
:return: 时间字符串
"""
timestamp = time.time()
timestruct = time.localtime(timestamp)
time_string = time.strftime('%Y-%m-%d %H:%M:%S', timestruct)
return time_string
def write_to_txt(self,txt_file,line):
try:
with open(txt_file,'a',encoding='utf-8')as f:
f.write(line)
except:
return False
def format_size(self, bytes):
try:
bytes = float(bytes)
kb = bytes / 1024
if kb > 1024:
mb = kb / 1024
if mb > 1024:
gb = mb / 1024
return '%.2fGB' % gb
else:
return '%.2fMB' % mb
else:
return '%.2fKB' % kb
except:
return 'error'
<RCC>
<qresource prefix="action_icon">
<file>icons/screen_shot.ico</file>
<file>icons/about_author.ico</file>
<file>icons/about_software.ico</file>
<file>icons/quit.ico</file>
<file>icons/xinxi.png</file>
<file>icons/copy_link.ico</file>
<file>icons/fangda.ico</file>
<file>icons/houtui.png</file>
<file>icons/my_collection.ico</file>
<file>icons/qianjin.png</file>
<file>icons/shezhi.png</file>
<file>icons/shoucang.png</file>
<file>icons/shuaxin.png</file>
<file>icons/suoxiao.ico</file>
<file>icons/tingzhi.png</file>
<file>icons/xinxi.png</file>
<file>icons/zhuye.png</file>
</qresource>
<qresource prefix="combobox_icon">
<file>icons/android_logo.ico</file>
<file>icons/iphone_logo.ico</file>
<file>icons/windows_nt_logo.ico</file>
<file>icons/ipad_logo.ico</file>
<file>icons/360_logo.ico</file>
<file>icons/android_logo.ico</file>
<file>icons/baidu_logo.ico</file>
<file>icons/bing_logo.ico</file>
<file>icons/google_logo.ico</file>
<file>icons/iphone_logo.ico</file>
<file>icons/sougou_logo.ico</file>
<file>icons/windows_nt_logo.ico</file>
</qresource>
<qresource prefix="author_img">
<file>icons/head_img.png</file>
</qresource>
</RCC>
本次使用PyQt5制作了一款浏览器,基本实现了一般浏览器的功能,不过还是存在一些不足,例如:
1.所有网页跳转均在主窗口中进行,不支持多页显示和操作
2.不支持视频播放
3.设置里面的部分内容没有实现,比如:语言切换
4.网页收藏格式过于简单,只是文本文件操作,可以使用html格式,便于规范
在此,提出我的解决问题方案:
1.PyQt5中使用QTabwidget标签页,网页跳转时,创建新的标签页。可参考:
python PyQt QtWebEngine实现本窗口跳转+ 新窗口跳转
2.重新编译QtWebEngine。可参考:
解决QtWebEngine无法播放H5中的mp4
3.使用QtLinguist,逐个翻译。可参考:
PyQt5 pycharm配置(2)语言家QtLinguist
4.这个简单,使用Python自带的字符串处理函数,将title放在a标签里,将链接地址放在href中,最后存为.html格式
程序打包好放在了百度云中(密码:8888),欢迎各位使用、测试。思路、代码方面有什么不足欢迎各位大佬指正、批评!能点个赞给我个鼓励吗?
2021-10-10
1.设计UI界面,用浏览器填充整个窗口,设计菜单栏、工具栏
2.绑定浏览器事件以及对应函数
(1)urlChanged:->show_jump_url(url) 展示“加载”进度条、将URL显示在输入框中
(2)loadProgress:->show_load_progress(progress) 显示加载进度,设置窗口标题
(3)loadFinished:->change_history_state() 改变“前进”,“后退”按钮状态
(4)iconChanged:->lambda icon:self.setWindowIcon(icon) 设置窗口图标
2021-10-18
1.输入时,判断输入类型,根据输入类型改变按钮标题为“转到”或“搜索” textEdited:->judge_input(text)
2.尝试调用X度搜索建议,但是界面会闪退
2021-10-19
1.历史记录URL、title,绑定双击事件、清理缓存
2.收藏记录
2021-10-21
QSS整体主题皮肤设置
2021-10-23
设置
1.主页、默认搜索引擎
2.默认下载位置
3.UA
4.拼写检查、空间导航、全局证书验证
5.编码
6.调试
2021-10-24
1.主题颜色自定义
2.自定义窗口放大比例
2021-10-25
1.网页窗口截图
2.解决子窗口居中问题
3.解决两个标签颜色问题、进度条颜色问题
2021-10-30
1.下载功能