-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrowser.py
More file actions
93 lines (76 loc) · 2.83 KB
/
Browser.py
File metadata and controls
93 lines (76 loc) · 2.83 KB
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
import customtkinter
import tkinter
from Tab import Tab
from Chrome import Chrome
import globals
class Browser:
def __init__(self, tags):
self.tags = tags
self.tabs = []
self.links = []
self.active_tab = None
self.initialize()
self.window.bind("<MouseWheel>", self.handle_scroll)
self.window.bind("<Configure>", self.resize)
self.window.bind("<Button-1>", self.handle_click)
self.window.bind("<Key>", self.handle_key)
self.window.bind("<BackSpace>", self.handle_backspace)
self.window.bind("<Return>", self.handle_enter)
self.window.bind("<Button-2>", self.handle_middle_click)
self.chrome = Chrome(self)
def initialize(self):
self.window = customtkinter.CTk()
self.window.geometry("%dx%d" % (1000, 1000))
self.window.after(0, lambda: self.window.state("zoomed"))
self.canvas = tkinter.Canvas(self.window, bg="white")
self.canvas.pack(fill="both", expand=True)
self.window.update_idletasks()
screen_width = self.window.winfo_screenwidth() + 400 # bad fix, but it works
screen_height = self.window.winfo_screenheight() + 125
globals.update_globals(screen_width, screen_height)
def new_tab(self, url):
new_tab = Tab(globals.SCheight - self.chrome.bottom)
new_tab.load(url)
self.active_tab = new_tab
self.tabs.append(new_tab)
self.draw()
def draw(self):
self.canvas.delete("all")
self.active_tab.draw(self.canvas, self.chrome.bottom)
for command in self.chrome.paint():
command.execute(0, self.canvas)
def handle_scroll(self, e):
self.active_tab.scroll_window(e)
self.draw()
def handle_middle_click(self, e):
tab_y = e.y - self.chrome.bottom
res = self.active_tab.click(e.x, tab_y, True)
if res:
self.new_tab(res)
def handle_click(self, e):
if e.y < self.chrome.bottom:
self.focus = None
self.chrome.click(e.x, e.y)
else:
self.focus = "content"
self.chrome.blur()
tab_y = e.y - self.chrome.bottom
self.active_tab.click(e.x, tab_y, False)
self.draw()
def handle_backspace(self, e):
self.chrome.keypress("BACKSPACE")
self.draw()
def handle_key(self, e):
if len(e.char) == 0: return
if not (0x20 <= ord(e.char) < 0x7f): return
if self.chrome.keypress(e.char):
self.draw()
elif self.focus == "content":
self.active_tab.keypress(e.char)
self.draw()
def handle_enter(self, e):
self.chrome.enter()
self.draw()
def resize(self, e):
globals.update_globals(e.width, e.height)
self.draw()