-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.py
83 lines (62 loc) · 2.6 KB
/
application.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
# Import the required libraries
import traceback
import webview
import time
import os
HOME_PATH = os.path.expanduser('~')
class Browser:
def __init__(self, title):
try:
# LEEMOS EL CACHE CON LAS URLS DE NAVEGACIÓN
furl = open(f"{HOME_PATH}/elearner.txt", "r")
urls = furl.readlines()
# OBTENEMOS LA ÚLTIMA URL DEL CACHE
url_cache = urls[0]
self.window = webview.create_window(title, url_cache, min_size=(450, 700), height=700, width=450, confirm_close=True, resizable=False,text_select=True)
except Exception as exp:
url_cache = "https://rust-book.cs.brown.edu/"
# ABRIMOS LA URL ÚLTIMA
self.window = webview.create_window(title, url_cache, min_size=(450, 700), height=700, width=450, confirm_close=True, resizable=False, text_select=True)
def get_window(self):
return self.window
def on_closed(self):
print('pywebview window is closed')
def on_closing(self):
print('pywebview window is closing')
def on_shown(self):
print('pywebview window shown')
def on_minimized(self):
print('pywebview window minimized')
def on_restored(self):
print('pywebview window restored')
def on_maximized(self):
print('pywebview window maximized')
def on_loaded(self):
print('Elearner - Page Loaded.')
url = self.window.get_current_url()
# REMEMBER THE PATH
fcache = open(f"{HOME_PATH}/elearner.txt", "w")
fcache.write(url)
fcache.close()
def on_resized(self, width, height):
print('pywebview window is resized. new dimensions are {width} x {height}'.format(width=width, height=height))
def on_moved(self, x, y):
print('pywebview window is moved. new coordinates are x: {x}, y: {y}'.format(x=x, y=y))
def start(self):
try:
print("Window Loading.")
self.window.events.closed += self.on_closed
self.window.events.closing += self.on_closing
self.window.events.shown += self.on_shown
self.window.events.loaded += self.on_loaded
self.window.events.minimized += self.on_minimized
self.window.events.maximized += self.on_maximized
self.window.events.restored += self.on_restored
self.window.events.resized += self.on_resized
self.window.events.moved += self.on_moved
webview.start()
except Exception as exp:
traceback.print_exc()
if __name__ == '__main__':
owindow = Browser("Aprendiendo Rust!")
owindow.start()