-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
73 lines (57 loc) · 2.33 KB
/
main.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
# import libraries
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
import wikipedia
class Window(Gtk.Window):
def __init__(self):
super().__init__(title="Wikipedia")
self.set_border_width(10)
self.set_default_size(600, 350)
hbox = Gtk.Box()
grid = Gtk.Grid()
box_fatter = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=20)
hbox_left = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=10)
hbox.pack_start(box_fatter, True, True, 0)
self.lbl_query = Gtk.Label()
self.lbl_query.set_text("Buscar en Wikipedia: ")
self.lbl_query.set_justify(Gtk.Justification.LEFT)
hbox_left.pack_start(self.lbl_query, True, True, 0)
self.query = Gtk.Entry()
self.query.set_text("")
hbox_left.pack_start(self.query, True, True, 0)
scrolledwindow = Gtk.ScrolledWindow()
scrolledwindow.set_hexpand(True)
scrolledwindow.set_vexpand(True)
grid.attach(scrolledwindow, 0, 1, 10, 1)
self.textview = Gtk.TextView()
self.output = self.textview.get_buffer()
self.output.set_text("Resultado de busqueda....")
scrolledwindow.add(self.textview)
button = Gtk.Button(label="buscar")
button.connect("clicked", self.getQuery)
hbox_left.pack_start(button, True, True, 0)
box_fatter.pack_start(hbox_left, False, False, 0)
box_fatter.pack_start(grid, True, True, 0)
self.add(hbox)
def getQuery(self,button):
"""
Get query of wikipedia
"""
wikipedia.set_lang("es")
query = self.query.get_text()
if query != "":
try:
result = wikipedia.summary(query, sentences=1)
self.output.set_text("Resultado de busqueda\n"+result)
except wikipedia.exceptions.PageError as e:
self.output.set_text("'¡algo salio mal! \n"+str(e))
except wikipedia.exceptions.DisambiguationError as e:
self.output.set_text("'¡algo salio mal! \n"+str(e))
else:
self.output.set_text("¡campo vacío!\nNo hay resultados")
if __name__ == "__main__":
win = Window()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()