88
99import re , os , sys , datetime , sqlite3
1010import pyperclip as pc
11- from PyQt5 import QtGui
12- from PyQt5 import QtCore
13- from PyQt5 .QtGui import *
14- from PyQt5 .QtCore import *
15- from PyQt5 .QtWidgets import *
11+ from PyQt5 import QtGui , QtCore
12+ from PyQt5 .QtGui import QIcon , QFont , QPainter , QPixmap
13+ from PyQt5 .QtCore import QUrl , QObject , pyqtSlot , QEventLoop , QPointF , Qt , QSize
14+ from PyQt5 .QtWidgets import (QTabWidget , QLineEdit , QLabel , QToolBar , QMessageBox , QDialogButtonBox ,
15+ QDialog , QProgressDialog , QProgressBar , QWidget , QPushButton , QListWidget , QGridLayout ,
16+ QMainWindow , QVBoxLayout , QShortcut , QMenu , QAction , QFileDialog , QApplication )
1617from PyQt5 .QtWebEngineWidgets import *
17- from PyQt5 .QtPrintSupport import *
18+ from PyQt5 .QtPrintSupport import QPrinter , QPrintDialog , QPrintPreviewDialog
1819
1920
2021
@@ -118,61 +119,91 @@ class HistoryWindow(QWidget):
118119 def __init__ (self ):
119120 super ().__init__ ()
120121
121- titleFont = QFont ("sans-serif" , 16 )
122+ titleFont = QFont ("PT Sans" , 16 )
123+ btnFont = QFont ("Roboto" , 0 )
124+
122125 titleLbl = QLabel ("History" )
123126 titleLbl .setStyleSheet ("""
124- margin:5px 5px 5px 5px ;
127+ margin-top:7px ;
125128 """ )
126129 titleLbl .setFont (titleFont )
127130
128131 clearBtn = QPushButton ("Clear" )
129132 clearBtn .setObjectName ("ClearButnHistory" )
130- clearBtn .setFont (textFont )
133+ clearBtn .setFont (btnFont )
131134 clearBtn .setStyleSheet (
132135 """
133136 QPushButton#ClearButnHistory{
134137 border:1px solid transparent;
135138 border-radius: 7px;
136- background-color: #C9D2F1;
137- padding: 2px 5px 5px 2px;
138- margin-top:5px;
139+ border-color:#ccc;
140+ margin-top:6px;
139141 margin-left:80px;
140142 margin-right:10px;
141- margin-bottom: 5px;
143+ padding: 5px 5px 5px 5px;
142144 font-size:12pt;
143- font-family:sans-serif;
145+ color:#000;
146+ background-color:transparent;
144147 }
148+
145149 QPushButton#ClearButnHistory:hover{
146- background-color:#ced3e2;
150+ background-color:#2681f2;
151+ border-color:#dae0e5;
152+ color: #fff;
147153 }
154+
148155 QPushButton#ClearButnHistory:pressed{
149- background-color:#ccc;
150- }
151-
156+ background-color:#0c63ce;
157+ }
152158 """
153159 )
154160 clearBtn .clicked .connect (self .clearHistory )
155161
156162 self .historyList = QListWidget ()
157- self .historyList .verticalScrollBar ().setEnabled (False )
163+ self .historyList .horizontalScrollBar ().setEnabled (False )
164+ self .historyList .verticalScrollBar ().setStyleSheet (
165+ """
166+ QScrollBar:vertical {
167+ background: transparent;
168+ width:8px;
169+ }
170+
171+ QScrollBar::handle:vertical {
172+ background: gray;
173+ min-width: 5px;
174+ border: 1px solid gray;
175+ border-radius: 4px;
176+ }
177+ QScrollBar::add-line:vertical{
178+ background:none;
179+ }
180+ QScrollBar::sub-line:vertical{
181+ background:none;
182+ }
183+ """
184+ )
158185
159186 self .fillHistoryList ()
160187
161188 self .historyList .itemClicked .connect (self .goClickedLink )
162189 self .historyList .setStyleSheet (
163190 """
164191 QListWidget::item{
165- padding-top: 5px;
166- padding-bottom: 5px;
192+ padding-top: 8px;
193+ padding-bottom: 8px;
194+ margin-top: 2px;
195+ margin-bottom: 2px;
167196 }
168197
169198 QListWidget::item:hover{
170- background-color:#ccc ;
199+ background-color:#E5E5E5 ;
171200 }
172201
173202 QListWidget{
174203 border: 1px solid transparent;
175204 border-top: 1px solid gray;
205+ padding-left:5px;
206+ padding-right:5px;
176207 }
177208 """ )
178209
@@ -253,6 +284,7 @@ def initAddressBar(self):
253284class SSLIcon (QLabel ):
254285 def __init__ (self ):
255286 super ().__init__ ()
287+ self .InitSSLIcon ()
256288
257289 def InitSSLIcon (self ):
258290 self .setObjectName ("SSLIcon" )
@@ -430,7 +462,6 @@ def __init__(self, *args, **kwargs):
430462
431463 # Shows ssl security icon
432464 self .httpsicon = SSLIcon ()
433- self .httpsicon .InitSSLIcon ()
434465
435466 # Add http icon to the navbar bar
436467 self .navbar .addWidget (self .httpsicon )
@@ -470,6 +501,11 @@ def __init__(self, *args, **kwargs):
470501 newTabAction .setToolTip ("Add a new tab" )
471502 context_menu .addAction (newTabAction )
472503
504+ # New window action
505+ newWindowAction = QAction ("New window" , self )
506+ newWindowAction .triggered .connect (self .CreateNewWindow )
507+ context_menu .addAction (newWindowAction )
508+
473509 # Close tab action
474510 CloseTabAction = QAction ("Close tab" , self )
475511 CloseTabAction .setIcon (QIcon (os .path .join ("Images" , "closetab.png" )))
@@ -664,6 +700,10 @@ def NavigateDuckDuckGo(self):
664700 self .add_new_tab (QtCore .QUrl ("https://www.duckduckgo.com/" ), "DuckDuckGo" )
665701
666702
703+ # Define open a new window
704+ def CreateNewWindow (self ):
705+ window = mainWindow ()
706+ window .show ()
667707
668708 # Copy url of currently viewed page to clipboard
669709 def CopySiteLink (self ):
@@ -956,8 +996,8 @@ def updateHistory(self):
956996
957997 def openHistory (self ):
958998 self .historyWindow = HistoryWindow ()
959- self .historyWindow .setWindowFlags (Qt .FramelessWindowHint | Qt .Popup )
960- self .historyWindow .setGeometry (self .tabs .currentWidget ().frameGeometry ().width ()/ 2 + 300 , 87 , 500 , 500 )
999+ self .historyWindow .setWindowFlags (Qt .FramelessWindowHint | Qt .Popup )
1000+ self .historyWindow .setGeometry (int ( self .tabs .currentWidget ().frameGeometry ().width ()/ 2 + 300 ) , 87 , 500 , 500 )
9611001 radiusx = 10.0
9621002 radiusy = 5.0
9631003 path = QtGui .QPainterPath ()
@@ -968,12 +1008,12 @@ def openHistory(self):
9681008
9691009 self .historyWindow .setStyleSheet (
9701010 """
971- background-color:#fff;
972- """ )
1011+ background-color:#fdfdfd;
1012+ """
1013+ )
9731014 self .historyWindow .show ()
9741015
9751016 def openSiteHistoryClicked (self , url ,* args ):
976- # self.add_new_tab(url, title)
9771017 self .tabs .currentWidget ().load (url )
9781018
9791019
@@ -1010,14 +1050,15 @@ def __init__(self, parent=None, *args, **kwargs):
10101050
10111051def main ():
10121052 app = QApplication (sys .argv )
1053+
1054+ # Disable shortcut in context menu
10131055 app .styleHints ().setShowShortcutsInContextMenus (False )
10141056
10151057 # Set the window name
10161058 QApplication .setApplicationName ("Simple Web Browser" )
10171059
10181060 # Set the window icon
10191061 QApplication .setWindowIcon (QIcon (os .path .join ("Icons" , "browser.png" )))
1020- app .styleHints ().showShortcutsInContextMenus ()
10211062
10221063 # App styles
10231064 app .setStyleSheet ("""
@@ -1239,11 +1280,9 @@ def main():
12391280
12401281 """ )
12411282
1242-
1243-
1244- #e6e6e6 background color
12451283 window = mainWindow ()
12461284 window .show ()
1285+
12471286 try :
12481287 sys .exit (app .exec_ ())
12491288
0 commit comments