-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtabBar.py
172 lines (155 loc) · 4.87 KB
/
tabBar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
from guielements import *
from PyQt5.QtCore import QCoreApplication
import copy
class TabWidget(QTabWidget):
tabCount = 0
tabs = []
tabdump = []
def __init__(self, parent):
super().__init__()
self.home = None
with open('Home/google.html', 'r') as file:
self.home = file.read()
pass
hbox = QHBoxLayout()
hbox.setContentsMargins(0,0,0,0)
self.setLayout(hbox)
self.parent = parent
self.webhistory = self.parent.history
self.bookmarks = self.parent.bookmarks
self.controller = self.parent.nav
self.setTabsClosable(True)
home = Tab(self, html = self.home)
TabWidget.tabCount+=1
TabWidget.tabs.append(home)
if(home.URL is not None):
logger.log(home.URL, 2)
home.loadURL()
else:
home.showHome()
self.addTab(home, 'Home')
self.currentTabIndex = 0
self.currentTab = home
self.currentURL = ''
# self.setCornerWidget(self.controller.btn_pref)
self.tabController()
def onChange(self, i):
logger.log('TAB CHANGED')
self.currentTabIndex = i
self.currentTab = self.getCurrent()
self.currentURL = self.currentTab.URL
self.controller.URLinput.setText(self.currentURL)
# self.progressBar.update(self.currentTab.progress)
self.controller.URLinput.setCursorPos(6)
def checkBookmarks(self):
logger.log('CHECKING FOR BOOKMARKS', 1)
tab = self.currentTab
if tab.bookmarkStatus[1] == False:
logger.log('URL NOT CHECKED')
tab.bookmarkStatus = [self.bookmarks.find(tab.URL), True]
logger.log(tab.bookmarkStatus)
logger.log('TAB URL ' + tab.URL)
if tab.bookmarkStatus[0] == True:
logger.log('EXISTS IN BOOKMARKS')
self.controller.btn_bookmark.setIcon(QIcon('img/bookmarked.png'))
else:
logger.log('NOT IN BOOKMARKS')
self.controller.btn_bookmark.setIcon(QIcon('img/addtobookmark.png'))
@property
def current(self):
return self.currentTab
def tabController(self):
self.currentChanged.connect(self.onChange)
self.tabCloseRequested.connect(self.closeTab)
def getCurrent(self):
return TabWidget.tabs[self.currentTabIndex]
def tabIndex(self, tab):
return TabWidget.tabs.index(tab)
def getTab(self, tabid):
return TabWidget.tabs[tabid]
def updateIcon(self, thisTab):
logger.log('INSIDE FUNCTION UPDATE ICON')
tabid = self.tabIndex(thisTab)
self.setTabIcon(tabid, QIcon(thisTab.favicon))
# def updateProgress(self, tab, status=False):
# # print('INSIDE FUNCTION UPDATE PROGRESS')
# if self.tabIndex(tab) == self.currentTabIndex:
# self.progressBar.update(tab.progress, status)
def update(self, thisTab, complete = False):
logger.log('INSIDE FUNCTION UPDATE')
temptitle = ''
tabid = self.tabIndex(thisTab)
if len(thisTab.pageTitle) > 12:
temptitle = thisTab.pageTitle[:12]+'...'
else:
temptitle = thisTab.pageTitle[:12]
self.setTabText(tabid, temptitle)
self.setTabToolTip(tabid, thisTab.pageTitle)
if(self.current == thisTab):
logger.log('YES')
self.currentURL = thisTab.URL
self.controller.URLinput.setText(self.currentURL)
else:
logger.log("NO")
self.controller.URLinput.setCursorPos(0)
t = Thread(target = self.checkBookmarks)
t.start()
def closeTab(self, index=None):
logger.log('CLOSING TAB', 1)
if TabWidget.tabCount <= 1 :
QCoreApplication.quit()
return
if index == None:
index = self.currentTabIndex
TabWidget.tabCount-=1
tab = TabWidget.tabs.pop(index)
self.dumpTab(tab.history(), tab.URL)
tab.deleteLater()
self.removeTab(index)
def dumpTab(self, history, url):
TabWidget.tabdump.append((history, url))
if len(TabWidget.tabdump) > 10:
tabToDie = tabdump.pop(0)
def reopenTab(self):
if len(TabWidget.tabdump) > 0:
tabToRevive = TabWidget.tabdump.pop(-1)
self.addNewTab(url = tabToRevive[1], history = tabToRevive[0])
# TabWidget.tabCount+=1
# TabWidget.tabs.append(tabToRevive)
# if tabToRevive.URL is not None or tabToRevive.URL != 'about:blank':
# print(tabToRevive.URL)
# tabToRevive.loadURL()
# else:
# tabToRevive.showHome()
# self.currentTab = tabToRevive
# self.currentTabIndex = len(TabWidget.tabs)-1
# self.setCurrentIndex(self.currentTabIndex)
# self.setTabShape(1)
else:
logger.log("NO TAB TO REOPEN", 2)
def addNewTab(self, html=None, url=None, history = None):
newTab = Tab(self)
if html is not None:
newTab.html = html
else:
newTab.html = self.home
if url is not None:
newTab.URL = url
self.addTab(newTab, newTab.pageTitle)
TabWidget.tabCount+=1
TabWidget.tabs.append(newTab)
if history is not None:
self.history = history
if newTab.URL is not None:
newTab.loadURL()
else:
newTab.showHome()
self.currentTab = newTab
self.currentTabIndex = len(TabWidget.tabs)-1
self.setCurrentIndex(self.currentTabIndex)
logger.log(self.current, 2)
self.setTabShape(1)
def showHistory(self):
self.addNewTab(html = HTMLWriter().historyWriter(self.webhistory.Store))
def showBookmarks(self):
self.addNewTab(html = HTMLWriter().bookmarkWriter(self.bookmarks.Store))