-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyleaf.pyw
233 lines (188 loc) · 7.31 KB
/
pyleaf.pyw
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# This is a Python PySide6 GUI app that displays information about cannabis strains.
# This script comes to you without any warranty whatsoever. Use at your own risk. Qu GitHub.
# The data used in this app was obtained from Kaggle:
# https://www.kaggle.com/datasets/kingburrito666/cannabis-strains/
# License: MIT License (do whatever you want with it)
from PySide6.QtWidgets import QApplication, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QComboBox, QLineEdit, QPushButton, QFrame, QListWidget, QTextEdit, QSizePolicy, QMessageBox
from PySide6.QtCore import Qt
from PySide6.QtGui import QDesktopServices, QIcon, QFont
import sqlite3
import sys
# SQLite database, complete with full path
db_path = 'pyleafdata.db'
# Function to populate details
def display_details(current_item):
if current_item:
selected_strain = current_item.text()
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
query = "SELECT * FROM cannabis WHERE Strain = ?"
cursor.execute(query, (selected_strain,))
result = cursor.fetchone()
if result:
strain_text.setText(result[0])
type_text.setText(result[1])
rating_text.setText(str(result[2]))
effects_list.clear()
effects_list.addItems(result[3].split(","))
flavor_list.clear()
flavor_list.addItems(result[4].split(","))
description_text.setText(result[5])
conn.close()
# App Setup
app = QApplication(sys.argv)
window = QWidget()
window.setWindowTitle("PyLeaf")
window.setWindowIcon(QIcon("resources/leaf.png"))
main_layout = QVBoxLayout()
header_label = QLabel(" \nPyLeaf: Cannabis Strain Information\n ")
font = QFont()
font.setBold(True)
header_label.setFont(font)
header_label.setAlignment(Qt.AlignCenter)
main_layout.addWidget(header_label)
search_layout = QHBoxLayout()
combo_box = QComboBox()
combo_box.addItems(["Strain", "Type", "Rating", "Effects", "Flavor", "Description"])
search_layout.addWidget(combo_box)
search_text = QLineEdit()
search_layout.addWidget(search_text)
search_button = QPushButton("Search")
search_layout.addWidget(search_button)
clear_button = QPushButton("Clear")
search_layout.addWidget(clear_button)
main_layout.addLayout(search_layout)
divider = QFrame()
divider.setFrameShape(QFrame.HLine)
divider.setFrameShadow(QFrame.Sunken)
main_layout.addWidget(divider)
results_details_layout = QHBoxLayout()
results_list = QListWidget()
results_details_layout.addWidget(results_list)
details_layout = QVBoxLayout()
details_top_layout = QHBoxLayout()
strain_text = QLineEdit()
strain_text.setReadOnly(True)
strain_text.setMinimumWidth(200)
strain_label = QLabel("Strain:")
details_top_layout.addWidget(strain_label)
details_top_layout.addWidget(strain_text)
type_text = QLineEdit()
type_text.setReadOnly(True)
type_text.setMaximumWidth(150)
type_label = QLabel("Type:")
details_top_layout.addWidget(type_label)
details_top_layout.addWidget(type_text)
rating_text = QLineEdit()
rating_text.setReadOnly(True)
rating_text.setMaximumWidth(50)
rating_text.setAlignment(Qt.AlignCenter)
rating_label = QLabel("Rating:")
details_top_layout.addWidget(rating_label)
details_top_layout.addWidget(rating_text)
details_layout.addLayout(details_top_layout)
divider2 = QFrame()
divider2.setFrameShape(QFrame.HLine)
divider2.setFrameShadow(QFrame.Sunken)
details_layout.addWidget(divider2)
effects_list = QListWidget()
effects_list.setFixedHeight(100)
effects_list.setFixedWidth(150)
effects_list.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
effects_label = QLabel("Effects:")
effects_label.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
flavor_list = QListWidget()
flavor_list.setFixedHeight(100)
flavor_list.setFixedWidth(150)
flavor_list.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
flavor_label = QLabel("Flavor:")
flavor_label.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
about_button = QPushButton("About")
about_button.setFixedWidth(150)
# Function to display app info message box
def show_about_info():
msg = QMessageBox()
msg.setWindowIcon(QIcon("resources/leaf.png"))
msg.setWindowTitle("About PyLeaf")
msg.setText('<div style="text-align: center;"><strong>PyLeaf: Cannabis Strain Information</strong<br><br>v1.0<br><br>by Quantum Pixelator<br><br>'
'The data used is from Kaggle:<br>'
'<a href="https://www.kaggle.com/datasets/kingburrito666/cannabis-strains/">Cannabis Strains from Kaggle</a><br><br>'
'License: MIT<br><br>Latest source code available on <a href="https://github.com/QuantumPixelator/PyLeaf">GitHub</a></div>')
# Enable link interaction.
msg.setTextInteractionFlags(Qt.TextBrowserInteraction)
# Open the link in an external browser when the user clicks the OK button.
msg.buttonClicked.connect(lambda button: QDesktopServices.openUrl("https://www.kaggle.com/datasets/kingburrito666/cannabis-strains/") if button == QMessageBox.Ok else None)
msg.exec()
about_button.clicked.connect(show_about_info)
effects_flavor_layout = QVBoxLayout()
effects_flavor_layout.addWidget(effects_label)
effects_flavor_layout.addWidget(effects_list)
effects_flavor_layout.addWidget(flavor_label)
effects_flavor_layout.addWidget(flavor_list)
effects_flavor_layout.addStretch(1)
effects_flavor_layout.addWidget(about_button)
description_text = QTextEdit()
description_text.setReadOnly(True)
description_text.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
description_label = QLabel("Description:")
description_layout = QVBoxLayout()
description_layout.addWidget(description_label)
description_layout.addWidget(description_text)
effects_flavor_description_layout = QHBoxLayout()
effects_flavor_description_layout.addLayout(effects_flavor_layout)
effects_flavor_description_layout.addLayout(description_layout)
details_layout.addLayout(effects_flavor_description_layout)
results_details_layout.addLayout(details_layout)
main_layout.addLayout(results_details_layout)
window.setLayout(main_layout)
stylesheet = """
QWidget {
font-family: Arial;
font-size: 14px;
}
QLabel {
color: green;
}
QPushButton {
background-color: lightgreen;
border: 2px solid green;
border-radius: 5px;
}
QPushButton:hover {
background-color: green;
color: white;
}
QLineEdit, QTextEdit, QListWidget, QComboBox {
background-color: lightyellow;
border: 2px solid green;
border-radius: 5px;
}
"""
def perform_search():
search_column = combo_box.currentText()
search_value = search_text.text()
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
query = f"SELECT * FROM cannabis WHERE {search_column} LIKE ?"
cursor.execute(query, (f"%{search_value}%",))
results = cursor.fetchall()
results_list.clear()
for result in results:
results_list.addItem(result[0])
conn.close()
def clear_results():
search_text.clear()
results_list.clear()
strain_text.clear()
type_text.clear()
rating_text.clear()
effects_list.clear()
flavor_list.clear()
description_text.clear()
search_button.clicked.connect(perform_search)
clear_button.clicked.connect(clear_results)
results_list.currentItemChanged.connect(lambda current_item: display_details(current_item))
app.setStyleSheet(stylesheet)
window.resize(700, 600)
window.show()
app.exec()