-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdining.py
More file actions
152 lines (121 loc) · 5.54 KB
/
dining.py
File metadata and controls
152 lines (121 loc) · 5.54 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
'''
dining.py
TMWRK
Open browser with the top rated restaurants per yelp.com
'''
import json
import os
import urllib
from PyQt5.QtGui import QColor, QIcon, QPixmap
import qtawesome
from yelpapi import YelpAPI
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QFrame, QGraphicsDropShadowEffect, QGridLayout, QLabel, QMainWindow, QDialog, QDialogButtonBox, QHBoxLayout, QMainWindow, QMessageBox, QPushButton, QScrollArea, QVBoxLayout
from qt_material import apply_stylesheet
from tabs import Tabs
YELP_API_KEY = "iHXQoOowzlqjKNzSBSAGkPZ0bfJIjzGRyOgsdXX4E7wU8Q9yrqmEePkxSThIRUdqZFUbAdM_DKVB7lUeV_x5Ao0NFY40d0721MMO9aCWHh-Kzk2Po0gs24QQUk6AYXYx"
class Dining(QDialog, QMainWindow):
def __init__(self, window, location):
super(Dining, self).__init__(window)
# don't allow user to interact with parent window
self.setWindowModality(Qt.ApplicationModal)
# but parent window can reflect changes when applying settings like theme
self.book = window
self.error = False
self.diningLayout = DiningDisplay(location)
self.setFixedHeight(600)
self.setFixedWidth(600)
self.setLayout(self.diningLayout)
class DiningDisplay(QGridLayout):
def __init__(self, location):
super(DiningDisplay, self).__init__()
try:
self.response = self.search(location)
except Exception as e:
self.showErrorMessage(e)
else:
self.diningDisplayBox = QVBoxLayout()
self.diningFrame = QFrame()
self.oneDiningLayout = QGridLayout()
self.diningDisplay(self.response)
def diningDisplay(self, response):
numbusinesses = len(response['businesses'])
for i in range(numbusinesses):
self.oneDiningLayout = QGridLayout()
oneDiningFrame = QFrame()
# add shadow for elegance
self.oneDiningLayout.shadow = QGraphicsDropShadowEffect()
self.oneDiningLayout.shadow.setColor(QColor(0,0,0,127))
self.oneDiningLayout.shadow.setBlurRadius(8)
self.oneDiningLayout.shadow.setXOffset(5)
self.oneDiningLayout.shadow.setYOffset(5)
oneDiningFrame.setGraphicsEffect(self.oneDiningLayout.shadow)
oneDiningFrame.setMaximumHeight(75)
oneDiningFrame.setMinimumWidth(450)
oneDiningFrame.setFrameStyle(QFrame.StyledPanel)
oneDiningFrame.setStyleSheet('''
QFrame {
background-color: rgb(150, 150, 150);
border: none;
color: #fff;
font-family: "FontAwesome";
}
QLabel {
background: none;
}
QLabel#heading {
font-size: 15pt;
}
QLabel#hour_temper {
font-size: 25pt;
}
''')
hyperlink = response['businesses'][i]['url']
self.oneDiningLayout.nameLabel = QLabel(response['businesses'][i]['name'])
self.oneDiningLayout.nameLabel.setWordWrap(True)
self.oneDiningLayout.nameLabel.setObjectName('heading')
self.oneDiningLayout.nameLabel.setToolTip(response['businesses'][i]['name'])
self.oneDiningLayout.ratingLabel = QLabel('Rating: ' + str(response['businesses'][i]['rating']) + " " + chr(0xf005))
self.oneDiningLayout.ratingLabel.setObjectName('heading')
self.oneDiningLayout.ratingLabel.setToolTip('Yelp rating of ' + response['businesses'][i]['name'])
self.oneDiningLayout.linkLabel = QLabel('<a href=\"{hyperlink}\"style=\"color: white;\">Yelp Page</a>'.format(hyperlink=hyperlink))
self.oneDiningLayout.linkLabel.setOpenExternalLinks(True)
self.oneDiningLayout.linkLabel.setAlignment(Qt.AlignRight)
self.oneDiningLayout.addWidget(self.oneDiningLayout.nameLabel, 0, 0, 1, 2)
self.oneDiningLayout.addWidget(self.oneDiningLayout.ratingLabel, 0, 8, 1, 2)
self.oneDiningLayout.addWidget(self.oneDiningLayout.linkLabel, 0, 8, 1, 2)
oneDiningFrame.setLayout(self.oneDiningLayout)
self.diningDisplayBox.addWidget(oneDiningFrame)
# make scrollable
scrollArea = QScrollArea()
scrollArea.setWidgetResizable(True)
scrollArea.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
scrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
scrollArea.setFixedHeight(600)
scrollArea.setWidget(self.diningFrame)
scrollArea.grabGesture
self.addWidget(scrollArea)
self.diningFrame.setLayout(self.diningDisplayBox)
self.addWidget(self.diningFrame)
def search(self, location):
self.yelp_api = YelpAPI(YELP_API_KEY)
response = self.yelp_api.search_query(categories='Restaurants', location=location, sort_by='rating')
return response
def showErrorMessage(self, error):
self.errorLabel = QLabel(error.args[0])
self.errorLabel.setStyleSheet('''
QLabel {
background-color: rgb(150, 150, 150);
border: none;
color: #fff;
font-family: "FontAwesome";
font-size: 20pt;
}
''')
self.errorLabel.setAlignment(Qt.AlignCenter)
self.errorLabel.setAlignment(Qt.AlignTop)
self.errorLabel.setMaximumHeight(75)
self.errorLabel.setMinimumWidth(450)
self.errorLabel.adjustSize()
self.errorLabel.setWordWrap(True)
self.addWidget(self.errorLabel, 0, 0, 1, 2, alignment=Qt.AlignTop)