searchnarwhal 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- searchnarwhal/__init__.py +0 -0
- searchnarwhal/browser.py +119 -0
- searchnarwhal/download.py +33 -0
- searchnarwhal/localres.py +5 -0
- searchnarwhal/web.py +16 -0
- searchnarwhal-0.1.0.dist-info/LICENSE +8 -0
- searchnarwhal-0.1.0.dist-info/METADATA +23 -0
- searchnarwhal-0.1.0.dist-info/RECORD +10 -0
- searchnarwhal-0.1.0.dist-info/WHEEL +5 -0
- searchnarwhal-0.1.0.dist-info/top_level.txt +1 -0
File without changes
|
searchnarwhal/browser.py
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
# searchnarwhal/browser.py
|
2
|
+
|
3
|
+
import os
|
4
|
+
import tkinter as tk
|
5
|
+
from tkinterweb import HtmlFrame
|
6
|
+
from tkinter import messagebox
|
7
|
+
from . import localres # Absolute import
|
8
|
+
from . import download
|
9
|
+
|
10
|
+
print ("SearchNarwhal Browser Engine 1.0")
|
11
|
+
print ("Origanlly Developed by Zohan Haque")
|
12
|
+
print ("Browser is starting.")
|
13
|
+
print (" ")
|
14
|
+
|
15
|
+
class Browser(tk.Frame):
|
16
|
+
def __init__(self, parent):
|
17
|
+
super().__init__(parent)
|
18
|
+
self.html = HtmlFrame(self)
|
19
|
+
self.html.pack(fill="both", expand=True)
|
20
|
+
|
21
|
+
# Path to resources
|
22
|
+
self.resource_dir = os.path.dirname(os.path.abspath(__file__))
|
23
|
+
|
24
|
+
# Navigation history
|
25
|
+
self.history = []
|
26
|
+
self.history_index = -1
|
27
|
+
|
28
|
+
# Buttons for navigation
|
29
|
+
self.nav_frame = tk.Frame(self)
|
30
|
+
self.nav_frame.pack(fill="x")
|
31
|
+
|
32
|
+
self.back_button = tk.Button(self.nav_frame, text="Back", command=self.go_back)
|
33
|
+
self.back_button.pack(side="left", padx=5, pady=5)
|
34
|
+
|
35
|
+
self.forward_button = tk.Button(self.nav_frame, text="Forward", command=self.go_forward)
|
36
|
+
self.forward_button.pack(side="left", padx=5, pady=5)
|
37
|
+
|
38
|
+
self.reload_button = tk.Button(self.nav_frame, text="Reload", command=self.reload_page)
|
39
|
+
self.reload_button.pack(side="left", padx=5, pady=5)
|
40
|
+
|
41
|
+
# Initialize navigation
|
42
|
+
self.load_newtab()
|
43
|
+
|
44
|
+
def load_url(self, url):
|
45
|
+
if url.startswith("http://") or url.startswith("https://"):
|
46
|
+
try:
|
47
|
+
self.html.load_website(url)
|
48
|
+
self.add_to_history(url)
|
49
|
+
except:
|
50
|
+
self.load_error_page("err_internet_disconnected.html")
|
51
|
+
elif url.startswith("localres:"):
|
52
|
+
local_path = localres.convert_to_path(url)
|
53
|
+
if os.path.exists(local_path):
|
54
|
+
self.html.load_file(local_path)
|
55
|
+
self.add_to_history(url)
|
56
|
+
else:
|
57
|
+
self.load_error_page("notvalidurl.html")
|
58
|
+
elif url.strip() == "":
|
59
|
+
self.load_newtab()
|
60
|
+
else:
|
61
|
+
self.load_error_page("unknown.html")
|
62
|
+
|
63
|
+
def load_newtab(self):
|
64
|
+
path = os.path.join(self.resource_dir, "newtab.html")
|
65
|
+
self._safe_load_file(path)
|
66
|
+
self.add_to_history("newtab.html")
|
67
|
+
|
68
|
+
def load_error_page(self, filename):
|
69
|
+
path = os.path.join(self.resource_dir, filename)
|
70
|
+
self._safe_load_file(path)
|
71
|
+
|
72
|
+
def _safe_load_file(self, path):
|
73
|
+
if os.path.exists(path):
|
74
|
+
self.html.load_file(path)
|
75
|
+
else:
|
76
|
+
self.html.set_content(f"<h1>Error</h1><p>Missing resource: {os.path.basename(path)}</p>")
|
77
|
+
|
78
|
+
def add_to_history(self, url):
|
79
|
+
if self.history_index != len(self.history) - 1:
|
80
|
+
self.history = self.history[:self.history_index + 1]
|
81
|
+
self.history.append(url)
|
82
|
+
self.history_index += 1
|
83
|
+
self.update_navigation_buttons()
|
84
|
+
|
85
|
+
def go_back(self):
|
86
|
+
if self.history_index > 0:
|
87
|
+
self.history_index -= 1
|
88
|
+
url = self.history[self.history_index]
|
89
|
+
self.load_url(url)
|
90
|
+
self.update_navigation_buttons()
|
91
|
+
|
92
|
+
def go_forward(self):
|
93
|
+
if self.history_index < len(self.history) - 1:
|
94
|
+
self.history_index += 1
|
95
|
+
url = self.history[self.history_index]
|
96
|
+
self.load_url(url)
|
97
|
+
self.update_navigation_buttons()
|
98
|
+
|
99
|
+
def reload_page(self):
|
100
|
+
current_url = self.history[self.history_index]
|
101
|
+
self.load_url(current_url)
|
102
|
+
|
103
|
+
def update_navigation_buttons(self):
|
104
|
+
if self.history_index > 0:
|
105
|
+
self.back_button.config(state="normal")
|
106
|
+
else:
|
107
|
+
self.back_button.config(state="disabled")
|
108
|
+
|
109
|
+
if self.history_index < len(self.history) - 1:
|
110
|
+
self.forward_button.config(state="normal")
|
111
|
+
else:
|
112
|
+
self.forward_button.config(state="disabled")
|
113
|
+
|
114
|
+
def get_html_frame(self):
|
115
|
+
return self.html
|
116
|
+
|
117
|
+
def download_file(self, url):
|
118
|
+
download.download(url)
|
119
|
+
messagebox.showinfo("Download", f"Download started for {url}")
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# searchnarwhal/download.py
|
2
|
+
|
3
|
+
import os
|
4
|
+
import requests
|
5
|
+
from tkinter import messagebox
|
6
|
+
|
7
|
+
# Get the user's Downloads folder
|
8
|
+
def get_download_folder():
|
9
|
+
home_dir = os.path.expanduser("~")
|
10
|
+
download_folder = os.path.join(home_dir, "Downloads")
|
11
|
+
return download_folder
|
12
|
+
|
13
|
+
def download(url):
|
14
|
+
try:
|
15
|
+
# Create the downloads folder if it doesn't exist
|
16
|
+
download_folder = get_download_folder()
|
17
|
+
if not os.path.exists(download_folder):
|
18
|
+
os.makedirs(download_folder)
|
19
|
+
|
20
|
+
# Get the filename from the URL (last part of the URL)
|
21
|
+
filename = url.split("/")[-1]
|
22
|
+
file_path = os.path.join(download_folder, filename)
|
23
|
+
|
24
|
+
# Download the file
|
25
|
+
response = requests.get(url)
|
26
|
+
response.raise_for_status() # Will raise an exception for HTTP errors
|
27
|
+
|
28
|
+
with open(file_path, 'wb') as file:
|
29
|
+
file.write(response.content)
|
30
|
+
|
31
|
+
messagebox.showinfo("Download Complete", f"File downloaded to: {file_path}")
|
32
|
+
except requests.exceptions.RequestException as e:
|
33
|
+
messagebox.showerror("Download Error", f"Error downloading {url}: {e}")
|
searchnarwhal/web.py
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# web.py
|
2
|
+
from tkinter import Tk
|
3
|
+
|
4
|
+
def run_browser():
|
5
|
+
# Import Browser here to avoid circular import issues
|
6
|
+
from searchnarwhal.browser import Browser # Import inside the function
|
7
|
+
root = Tk()
|
8
|
+
root.title("SearchNarwhal")
|
9
|
+
root.geometry("1024x768")
|
10
|
+
app = Browser(root)
|
11
|
+
app.pack(fill="both", expand=True)
|
12
|
+
root.mainloop()
|
13
|
+
|
14
|
+
if __name__ == "__main__":
|
15
|
+
run_browser()
|
16
|
+
|
@@ -0,0 +1,8 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
Copyright © 2025 Zohan Haque
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
5
|
+
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
7
|
+
|
8
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Metadata-Version: 2.2
|
2
|
+
Name: searchnarwhal
|
3
|
+
Version: 0.1.0
|
4
|
+
Summary: a browser engine built in python
|
5
|
+
Home-page: https://github.com/zohanhaqu/searchnarwhal
|
6
|
+
Author: Zohan Haque
|
7
|
+
Author-email: zohanuhaque@gmail.com
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
10
|
+
Classifier: Operating System :: OS Independent
|
11
|
+
Requires-Python: >=3.13
|
12
|
+
Description-Content-Type: text/markdown
|
13
|
+
License-File: LICENSE
|
14
|
+
Dynamic: author
|
15
|
+
Dynamic: author-email
|
16
|
+
Dynamic: classifier
|
17
|
+
Dynamic: description
|
18
|
+
Dynamic: description-content-type
|
19
|
+
Dynamic: home-page
|
20
|
+
Dynamic: requires-python
|
21
|
+
Dynamic: summary
|
22
|
+
|
23
|
+
SearchNarwhal is a browser engine written in python and it does have navigation and is freely customizable
|
@@ -0,0 +1,10 @@
|
|
1
|
+
searchnarwhal/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
searchnarwhal/browser.py,sha256=3bsb-MFEnvxJ0nrlz9hrhCa8v1ZOVsKa_nuZch-jDKQ,4109
|
3
|
+
searchnarwhal/download.py,sha256=VAq8yBV1ajvFWGBwjT416sQdylFsba_40tN2eVhMLlI,1142
|
4
|
+
searchnarwhal/localres.py,sha256=Ay5hs3FIopa5Un0sDj9ldGaae8Am7of5z1PIYUu1UNk,148
|
5
|
+
searchnarwhal/web.py,sha256=bH-202AhA1DysvCPSZUOkP2wz7GYryxO12XufTBk8dQ,410
|
6
|
+
searchnarwhal-0.1.0.dist-info/LICENSE,sha256=l61hl_3LTngI4BmepYFRdza5N3wwEeING7lGn3TnVX0,1090
|
7
|
+
searchnarwhal-0.1.0.dist-info/METADATA,sha256=3lvbgwE-79ON5wmqbusbJAJEbwjciHeEK0I2kDt0U20,746
|
8
|
+
searchnarwhal-0.1.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
9
|
+
searchnarwhal-0.1.0.dist-info/top_level.txt,sha256=Y-DVsCDN_0RuK3RW_0eaXhKnhUn2mjWZ7M9YGuKm-lw,14
|
10
|
+
searchnarwhal-0.1.0.dist-info/RECORD,,
|
@@ -0,0 +1 @@
|
|
1
|
+
searchnarwhal
|