mirror of
https://github.com/Afacanc38/browser.git
synced 2024-09-20 22:19:34 +03:00
78 lines
2.9 KiB
Python
Executable file
78 lines
2.9 KiB
Python
Executable file
#!/usr/bin/env python3
|
||
import gi, os, sys
|
||
gi.require_version("Gtk", "4.0")
|
||
gi.require_version("Adw", "1")
|
||
gi.require_version("WebKit", "6.0")
|
||
from gi.repository import Gtk, Adw, GLib, GLib, WebKit
|
||
|
||
class MyWindow(Adw.Window):
|
||
def __init__(self, *args, **kwargs):
|
||
super().__init__(*args, **kwargs)
|
||
self.set_title("Tarayıcı")
|
||
GLib.set_application_name("Tarayıcı")
|
||
GLib.set_prgname('Tarayıcı')
|
||
self.set_default_size(900, 600)
|
||
|
||
self.main_box = Gtk.Box(
|
||
orientation = Gtk.Orientation.VERTICAL
|
||
)
|
||
self.set_content(self.main_box)
|
||
self.hb = Adw.HeaderBar()
|
||
self.inp_url = Gtk.Entry(
|
||
width_request = 370
|
||
)
|
||
self.scroll = Gtk.ScrolledWindow()
|
||
self.web = WebKit.WebView(
|
||
vexpand = True
|
||
)
|
||
self.web.load_uri("https://duckduckgo.com")
|
||
self.inp_url.set_placeholder_text("Web'de arayın veya URL adresi girin...")
|
||
self.web.connect('notify::estimated-load-progress', self.change_url)
|
||
self.inp_url.connect("activate", self.on_inp_url_activate)
|
||
self.btn_prev = Gtk.Button()
|
||
self.btn_prev = Gtk.Button.new_from_icon_name("go-previous-symbolic")
|
||
self.btn_prev.connect("clicked", self.on_btn_prev_clicked)
|
||
self.btn_next = Gtk.Button()
|
||
self.btn_next = Gtk.Button.new_from_icon_name("go-next-symbolic")
|
||
self.btn_next.connect("clicked", self.on_btn_next_clicked)
|
||
self.btn_box = Gtk.Box(
|
||
spacing = 6
|
||
)
|
||
self.btn_box.append(self.btn_prev)
|
||
self.btn_box.append(self.btn_next)
|
||
self.btn_ref = Gtk.Button()
|
||
self.btn_ref = Gtk.Button.new_from_icon_name("view-refresh-symbolic")
|
||
self.btn_next.connect("clicked", self.on_btn_ref_clicked)
|
||
self.hb.pack_start(self.btn_box)
|
||
self.hb.pack_start(self.btn_ref)
|
||
self.hb.set_title_widget(self.inp_url)
|
||
self.main_box.append(self.hb)
|
||
self.scroll.set_child(self.web)
|
||
self.main_box.append(self.scroll)
|
||
def on_btn_next_clicked(self, widget):
|
||
self.web.go_forward()
|
||
def on_btn_prev_clicked(self, widget):
|
||
self.web.go_back()
|
||
def on_inp_url_activate(self, widget):
|
||
url_text = self.inp_url.get_text()
|
||
if "https://" in url_text:
|
||
self.web.load_uri(url_text)
|
||
else:
|
||
self.web.load_uri(f"https://duckduckgo.com/?q={url_text}")
|
||
def on_btn_ref_clicked(self, widget):
|
||
self.web.reload()
|
||
def change_url(self, widget, frame):
|
||
url_text = self.web.get_uri()
|
||
self.inp_url.set_text(url_text)
|
||
|
||
class MyApp(Adw.Application):
|
||
def __init__(self, **kwargs):
|
||
super().__init__(**kwargs)
|
||
self.connect('activate', self.on_activate)
|
||
|
||
def on_activate(self, app):
|
||
self.win = MyWindow(application=app)
|
||
self.win.present()
|
||
|
||
app = MyApp(application_id="io.github.afacanc38.browser")
|
||
app.run(sys.argv)
|