-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearchBox.py
More file actions
93 lines (76 loc) · 2.94 KB
/
searchBox.py
File metadata and controls
93 lines (76 loc) · 2.94 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#This class represents a searchBox object.
#It is used when the user wishes to search for a streamer
#either by name or by URL
import gtk,sys,streamViewer,search,streamer,searchResults
class Main():
def __init__(self):
#Create the main window
self.searchWindow = gtk.Window()
self.searchWindow.set_position(gtk.WIN_POS_CENTER)
self.searchBox = gtk.VBox()
self.searchBar = gtk.Entry()
self.searchBox.pack_start(self.searchBar)
#Create buttons
self.searchBar.set_text("Enter Search Query")
self.searchButton = gtk.Button('Search By User')
self.searchButton3 = gtk.Button('View by URL')
#Add buttons
self.searchBox.add(self.searchButton)
self.searchBox.add(self.searchButton3)
#Set button onClick
self.searchButton.connect('clicked', self.searchForStream)
self.searchButton3.connect('clicked', self.viewByUrl)
self.searchWindow.set_default_size(300,300)
self.searchWindow.set_title("Search")
self.searchWindow.add(self.searchBox)
self.searchWindow.show_all()
#Function checks if the user provided URL is valid, and creates a
#new streamViewer.Main(URL) instance.
def viewByUrl(self, object):
#Get whatever URL the user entered
stream = self.searchBar.get_text()
#Make sure it starts with http://, more validity checking done in
#streamViewer
if stream.startswith("http://"):
view = streamViewer.Main()
view.viewByUrl(stream)
else:
stream = "http://" + stream
view = streamViewer.Main()
view.viewByUrl(stream)
#Calls instance of search function, with string to be searched for.
def searchForStream(self, object):
if self.searchBar.get_text() == "":
md = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT,
gtk.MESSAGE_QUESTION,gtk.BUTTONS_CLOSE,"Invalid Search Query")
md.run()
md.destroy()
return
if self.searchBar.get_text() == "Enter Search Query":
md = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT,
gtk.MESSAGE_QUESTION,gtk.BUTTONS_CLOSE,"Invalid Search Query")
md.run()
md.destroy()
return
searcher = search.Main()
#See if we can find the streamer they're looking for
streamDetails = searcher.findStreamer(self.searchBar.get_text())
#Streamer not found
if streamDetails == None:
self.showNotFound()
else:
#Streamer found
#Popup box to see if the user wants to view said stream.
pop = searchResults.Main()
pop.singleStreamer(streamDetails)
#Popup box to inform the user that the streamer wasn't found.
def showNotFound(self):
md = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT,
gtk.MESSAGE_QUESTION,gtk.BUTTONS_CLOSE,"Streamer not found!\nYou may have" +
" spelled something wrong, or that streamer may be offline!")
md.run()
md.destroy()
if __name__ == '__main__':
sys.exit()