11# importing required libraries
22from PyQt5 import QtCore , QtGui , QtWidgets
3- from PyQt5 import QtWidgets
3+ # from PyQt5 import QtWidgets
44from PyQt5 .QtCore import *
55from PyQt5 .QtWidgets import *
66from PyQt5 .QtGui import *
77from PyQt5 .QtWebEngineWidgets import *
88from PyQt5 .QtPrintSupport import *
9- from qtwidgets import Toggle , AnimatedToggle
109import os
1110import random
1211import sys
1514import datetime
1615import time
1716import io
17+ import webbrowser
1818
19+ build_version = "Version V:1.0.3.2-featured (Official build) (64-bit)"
1920
2021# main window
2122class BrowserWindow (QMainWindow ):
@@ -85,7 +86,7 @@ def initui(self):
8586
8687 # adding action to back button
8788 # making current tab to go back
88- back_btn .triggered .connect (lambda : self .tabs . currentWidget (). back () )
89+ back_btn .triggered .connect (self .tabback )
8990
9091 # adding this to the navigation tool bar
9192 navtb .addAction (back_btn )
@@ -94,14 +95,14 @@ def initui(self):
9495 next_btn = QAction (self )
9596 next_btn .setIcon (QIcon ("static/front.png" ))
9697 next_btn .setStatusTip ("Forward to next page" )
97- next_btn .triggered .connect (lambda : self .tabs . currentWidget (). forward () )
98+ next_btn .triggered .connect (self .tabforward )
9899 navtb .addAction (next_btn )
99100
100101 # similarly adding reload button
101102 reload_btn = QAction (self )
102103 reload_btn .setIcon (QIcon ("static/reload.png" ))
103104 reload_btn .setStatusTip ("Reload page" )
104- reload_btn .triggered .connect (lambda : self .tabs . currentWidget (). reload () )
105+ reload_btn .triggered .connect (self .tabReload )
105106 navtb .addAction (reload_btn )
106107
107108 # creating home action
@@ -126,18 +127,46 @@ def initui(self):
126127 # adding line edit to tool bar
127128 navtb .addWidget (self .urlbar )
128129
130+ # added download menu
131+ downMenu = QMenu ()
132+ downMenu .setStyleSheet (
133+ "background-color:rgb(80, 80, 80); width:400px; padding:20px; color:white; font-size:16px;" )
134+
135+ self .down = QAction (self )
136+
137+ self .down .setText ("no downloads" )
138+ self .down .setStatusTip ("Save current page as html" )
139+ self .down .triggered .connect (lambda : self .settingui (5 ))
140+ downMenu .addAction (self .down )
141+
142+ self .opend = QAction (self )
143+ self .opend .setText ("" )
144+ self .openpath = ""
145+
146+ self .opend .setStatusTip ("Save current page as html" )
147+ self .opend .triggered .connect (lambda : self .openloc ())
148+ downMenu .addAction (self .opend )
149+
150+ save_btn = QToolButton ()
151+ # tb_set.clicked.connect(self.on_click_set_value)
152+ save_btn .setIcon (QIcon ("static/save.png" ))
153+ # adding menu to nevbar
154+ save_btn .setMenu (downMenu )
155+ save_btn .setPopupMode (QToolButton .InstantPopup )
156+ navtb .addWidget (save_btn )
157+
129158 # adding bookmark btn
130159 mark_btn = QAction (self )
131160 mark_btn .setIcon (QIcon ("static/bookmark.png" ))
132161 mark_btn .setStatusTip ("bookmark" )
133- mark_btn .triggered .connect (lambda : self .tabs . currentWidget (). stop () )
162+ mark_btn .triggered .connect (self .loadstop )
134163 navtb .addAction (mark_btn )
135164
136165 # similarly adding stop action
137166 stop_btn = QAction (self )
138167 stop_btn .setIcon (QIcon ("static/close.png" ))
139168 stop_btn .setStatusTip ("Stop loading current page" )
140- stop_btn .triggered .connect (lambda : self .tabs . currentWidget (). stop () )
169+ stop_btn .triggered .connect (self .loadstop )
141170 navtb .addAction (stop_btn )
142171
143172 navtb .addSeparator ()
@@ -194,10 +223,8 @@ def initui(self):
194223 tool_btn .setPopupMode (QToolButton .InstantPopup )
195224 navtb .addWidget (tool_btn )
196225
197- navtb .addSeparator ()
198-
199226 # creating first tab
200- self .add_new_tab (QUrl ( 'http://www.google.com' ), 'Homepage' )
227+ self .add_new_tab (qurl = "None" , label = 'Homepage' )
201228
202229 # showing all the components
203230 self .show ()
@@ -243,6 +270,8 @@ def add_new_tab(self, qurl="None", label="Blank"):
243270
244271 browser .loadFinished .connect (lambda : self .savehistory (browser .page ().url (), browser .page ().title ()))
245272
273+ browser .page ().profile ().downloadRequested .connect (self ._downloadRequested )
274+
246275 # when double clicked is pressed on tabs
247276 def tab_open_doubleclick (self , i ):
248277
@@ -255,14 +284,17 @@ def tab_open_doubleclick(self, i):
255284 # wen tab is changed
256285 def current_tab_changed (self , i ):
257286
258- # get the curl
259- qurl = self .tabs .currentWidget ().url ()
287+ try :
288+ # get the curl
289+ qurl = self .tabs .currentWidget ().url ()
260290
261- # update the url
262- self .update_urlbar (qurl , self .tabs .currentWidget ())
291+ # update the url
292+ self .update_urlbar (qurl , self .tabs .currentWidget ())
263293
264- # update the title
265- self .update_title (self .tabs .currentWidget ())
294+ # update the title
295+ self .update_title (self .tabs .currentWidget ())
296+ except Exception :
297+ pass
266298
267299 # when tab is closed
268300 def close_current_tab (self , i ):
@@ -291,17 +323,20 @@ def update_title(self, browser):
291323
292324 # action to go to home
293325 def navigate_home (self ):
294- db_res = self .conn .execute ("select * from devsat where id=1" )
295- result = db_res .fetchall ()
296- self .db_result = result [0 ]
297- if self .db_result [4 ] == "google" :
298- # go to google
299- qurl = QUrl ('http://www.google.com' )
300- else :
301- # go to bing
302- qurl = QUrl ('http://www.bing.com' )
326+ try :
327+ db_res = self .conn .execute ("select * from devsat where id=1" )
328+ result = db_res .fetchall ()
329+ self .db_result = result [0 ]
330+ if self .db_result [4 ] == "google" :
331+ # go to google
332+ qurl = QUrl ('http://www.google.com' )
333+ else :
334+ # go to bing
335+ qurl = QUrl ('http://www.bing.com' )
303336
304- self .tabs .currentWidget ().setUrl (QUrl ("http://www.google.com" ))
337+ self .tabs .currentWidget ().setUrl (QUrl ("http://www.google.com" ))
338+ except :
339+ pass
305340
306341 # method for navigate to url
307342 def navigate_to_url (self ):
@@ -316,7 +351,10 @@ def navigate_to_url(self):
316351 q .setScheme ("https" )
317352
318353 # set the url
319- self .tabs .currentWidget ().setUrl (q )
354+ try :
355+ self .tabs .currentWidget ().setUrl (q )
356+ except :
357+ pass
320358
321359 # method to update the url
322360 def update_urlbar (self , q , browser = None ):
@@ -331,6 +369,30 @@ def update_urlbar(self, q, browser=None):
331369 # set cursor position
332370 self .urlbar .setCursorPosition (0 )
333371
372+ def tabReload (self ):
373+ try :
374+ self .tabs .currentWidget ().reload ()
375+ except :
376+ pass
377+
378+ def tabforward (self ):
379+ try :
380+ self .tabs .currentWidget ().forward ()
381+ except :
382+ pass
383+
384+ def tabback (self ):
385+ try :
386+ self .tabs .currentWidget ().back ()
387+ except :
388+ pass
389+
390+ def loadstop (self ):
391+ try :
392+ self .tabs .currentWidget ().stop ()
393+ except :
394+ pass
395+
334396 def savehistory (self , url , title ):
335397
336398 url = url .toString ()
@@ -372,29 +434,63 @@ def save_file(self):
372434 except Exception as e :
373435 print (e )
374436
375- def settingui (self ):
376- Dialog = QtWidgets .QDialog ()
437+ def _downloadRequested (self , item ): # QWebEngineDownloadItem
438+ try :
439+ initDownPath = os .path .join (os .getenv ('USERPROFILE' ), 'Downloads' )
440+
441+ my_dir = QFileDialog .getExistingDirectory (
442+ self ,
443+ "select a download location" ,
444+ initDownPath ,
445+ QFileDialog .ShowDirsOnly
446+ )
447+ # my_dir = my_dir.replace("/", "\\")
448+ # if my_dir[-1] != "\\":
449+ # my_dir = my_dir + "\\" + item.downloadFileName()
450+ # else:
451+ # my_dir = my_dir + item.downloadFileName()
452+ #
453+ # print(my_dir)
454+ # item.setPath(my_dir)
455+ print ('downloading to' , item .path ())
456+ item .accept ()
457+ self .down .setText ("downloaded... " + item .downloadFileName ())
458+ self .opend .setText ("show in folder" )
459+
460+ fpath = "/" .join (str (item .path ()).split ("/" )[:- 1 ])
461+ self .openpath = fpath
462+ item .finished .connect (self .download_finished )
463+ except Exception as e :
464+ print (str (e ))
465+
466+ def download_finished (self ):
467+ print ("successfully downloaded" )
468+
469+ def openloc (self ):
470+ if (self .openpath != "" ):
471+ webbrowser .open (self .openpath )
472+
473+ def settingui (self , index = 1 ):
474+
475+ Dialog = QtWidgets .QWidget ()
377476 ui = Ui_Dialog ()
378- ui .setupUi (Dialog , self )
379- Dialog .show ()
380- Dialog .exec_ ()
477+ if index > 0 :
478+ ui .setupUi (Dialog , self , index )
479+
480+ i = self .tabs .addTab (ui .thiswindow , "settings" )
481+ self .tabs .setCurrentIndex (i )
381482
382483
383484# settings dialog classes
384485
385486
386487class Ui_Dialog (object ):
387- def setupUi (self , Dialog , browser ):
388- Dialog .setObjectName ("Dialog" )
389- Dialog .resize (1000 , 600 )
390- Dialog .setMinimumSize (800 , 600 )
391- Dialog .setWindowTitle ("SETTINGS" )
392- Dialog .setWindowIcon (QIcon ("static/settings.png" ))
488+ def setupUi (self , Dialog , browser , tabindex = 1 ):
393489 self .tabWidget = QtWidgets .QTabWidget (Dialog )
394- self .tabWidget .setGeometry (QtCore .QRect (0 , 100 , 1000 , 500 ))
490+ self .tabWidget .setGeometry (QtCore .QRect (50 , 150 , 1200 , 600 ))
395491 self .tabWidget .setTabShape (QtWidgets .QTabWidget .Rounded )
396492 self .tabWidget .setObjectName ("tabWidget" )
397- self .tabWidget .setStyleSheet (u"background-color:rgb(60, 60, 60 ); color:white;" )
493+ self .tabWidget .setStyleSheet (u"background-color:rgb(50, 50, 50 ); color:white;" )
398494 self .browser = browser
399495 # loading css file
400496 f = open ("static/dialog.css" , "r" )
@@ -428,7 +524,7 @@ def setupUi(self, Dialog, browser):
428524
429525 # settings dialog heading
430526 self .set = QtWidgets .QLabel (Dialog )
431- self .set .setGeometry (30 , 65 , 200 , 30 )
527+ self .set .setGeometry (70 , 80 , 200 , 30 )
432528 self .set .setObjectName ("settings" )
433529 self .set .setText ("Settings" )
434530 self .set .setObjectName ("head" )
@@ -666,7 +762,7 @@ def setupUi(self, Dialog, browser):
666762 self .policy .setGeometry (210 , 130 , 500 , 60 )
667763 self .policy .setObjectName ("settings" )
668764 self .policy .setText (
669- "We will always protect and respect your privacy,\n while giving you the transparency and control you deserve." )
765+ "We always protect and respect your privacy,\n while giving you the transparency and control you deserve." )
670766 self .policy .setObjectName ("small" )
671767 self .policy .setStyleSheet ("color:white; letter-spacing:1px; font-size:14px" )
672768
@@ -718,7 +814,7 @@ def setupUi(self, Dialog, browser):
718814 self .version = QtWidgets .QLabel (self .about )
719815 self .version .setGeometry (100 , 110 , 500 , 20 )
720816 self .version .setObjectName ("settings" )
721- self .version .setText ("Version V:1.0.2.1 LTS (Official build) (64-bit)" )
817+ self .version .setText (build_version )
722818 self .version .setObjectName ("head" )
723819 self .version .setStyleSheet ("color:white; letter-spacing:1px; font-size:14px" )
724820
@@ -752,8 +848,6 @@ def setupUi(self, Dialog, browser):
752848 self .hislabel .setText ("History" )
753849 self .hislabel .setObjectName ("head" )
754850
755-
756-
757851 # scroll bar
758852 history = self .conn .execute ("select * from history;" )
759853 result = history .fetchall ()
@@ -819,8 +913,21 @@ def setupUi(self, Dialog, browser):
819913 # pushing history to widget
820914 self .tabWidget .addTab (self .history , "history" )
821915
916+ # adding download page
917+ self .download = QtWidgets .QWidget ()
918+ self .download .setObjectName ("download" )
919+ # adding head label
920+ self .dlabel = QtWidgets .QLabel (self .download )
921+ self .dlabel .setGeometry (50 , 20 , 300 , 40 )
922+ self .dlabel .setObjectName ("label" )
923+ self .dlabel .setText ("Downloads" )
924+ self .dlabel .setObjectName ("head" )
925+
926+ # pushing history to widget
927+ self .tabWidget .addTab (self .download , "Downloads" )
928+
822929 # self.retranslateUi(Dialog)
823- self .tabWidget .setCurrentIndex (1 )
930+ self .tabWidget .setCurrentIndex (tabindex )
824931 QtCore .QMetaObject .connectSlotsByName (Dialog )
825932
826933 # seting tab icon
@@ -850,7 +957,7 @@ def clsall(self, rowcount):
850957 self .conn .commit ()
851958 for i in range (rowcount ):
852959 self .formLayout .removeRow (i )
853- print ( i )
960+
854961 except :
855962 pass
856963
@@ -1078,14 +1185,14 @@ def __init__(self):
10781185
10791186 bar .setValue (x )
10801187 time .sleep (1 )
1081- self .close ()
10821188
10831189
10841190# creating a PyQt5 application
10851191app = QApplication (sys .argv )
10861192
10871193# setting name to the application
10881194welcome = welcome ()
1195+ welcome .close ()
10891196
10901197# creating MainWindow object
10911198window = BrowserWindow ()
0 commit comments