Add debug message and better error handling for buy list dialog
This commit is contained in:
1 parent
3f377e165d
commit
2da02dc7df
1 file changed
+57
-50
+57
-50
@@ -454,74 +454,81 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
def show_buy_list(self):
|
def show_buy_list(self):
|
||||||
"""Show the Amazon buy list dialog with interactive features"""
|
"""Show the Amazon buy list dialog with interactive features"""
|
||||||
|
QMessageBox.information(self, "Debug", "Show buy list called")
|
||||||
try:
|
try:
|
||||||
with open('amazon_buy_list.txt', 'r') as f:
|
with open('amazon_buy_list.txt', 'r') as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
QMessageBox.information(self, "No Buy List", "No buy list available. Run an update to generate the list.")
|
QMessageBox.information(self, "No Buy List", "No buy list available. Run an update to generate the list.")
|
||||||
return
|
return
|
||||||
|
except Exception as e:
|
||||||
|
QMessageBox.critical(self, "Error", f"Failed to read buy list file: {e}")
|
||||||
|
return
|
||||||
|
|
||||||
# Parse content to get songs
|
try:
|
||||||
lines = content.split('\n')
|
# Parse content to get songs
|
||||||
songs = []
|
lines = content.split('\n')
|
||||||
i = 0
|
songs = []
|
||||||
while i < len(lines):
|
i = 0
|
||||||
if lines[i].startswith('Songs not in your library'):
|
while i < len(lines):
|
||||||
i += 2 # Skip header
|
if lines[i].startswith('Songs not in your library'):
|
||||||
continue
|
i += 2 # Skip header
|
||||||
if lines[i].strip() and not lines[i].startswith('http'):
|
continue
|
||||||
artist_title = lines[i].strip()
|
if lines[i].strip() and not lines[i].startswith('http'):
|
||||||
if i + 1 < len(lines) and lines[i + 1].startswith('http'):
|
artist_title = lines[i].strip()
|
||||||
url = lines[i + 1].strip()
|
if i + 1 < len(lines) and lines[i + 1].startswith('http'):
|
||||||
songs.append((artist_title, url))
|
url = lines[i + 1].strip()
|
||||||
i += 3 # Skip blank line
|
songs.append((artist_title, url))
|
||||||
|
i += 3 # Skip blank line
|
||||||
|
else:
|
||||||
|
i += 1
|
||||||
else:
|
else:
|
||||||
i += 1
|
i += 1
|
||||||
else:
|
|
||||||
i += 1
|
|
||||||
|
|
||||||
dialog = QDialog(self)
|
dialog = QDialog(self)
|
||||||
dialog.setWindowTitle("Amazon Buy List")
|
dialog.setWindowTitle("Amazon Buy List")
|
||||||
dialog.setModal(True)
|
dialog.setModal(True)
|
||||||
dialog.resize(600, 400)
|
dialog.resize(600, 400)
|
||||||
|
|
||||||
layout = QVBoxLayout()
|
layout = QVBoxLayout()
|
||||||
|
|
||||||
# Search box
|
# Search box
|
||||||
search_layout = QHBoxLayout()
|
search_layout = QHBoxLayout()
|
||||||
search_layout.addWidget(QLabel("Search:"))
|
search_layout.addWidget(QLabel("Search:"))
|
||||||
self.search_input = QLineEdit()
|
self.search_input = QLineEdit()
|
||||||
self.search_input.textChanged.connect(lambda: self.filter_buy_list(songs))
|
self.search_input.textChanged.connect(lambda: self.filter_buy_list(songs))
|
||||||
search_layout.addWidget(self.search_input)
|
search_layout.addWidget(self.search_input)
|
||||||
layout.addLayout(search_layout)
|
layout.addLayout(search_layout)
|
||||||
|
|
||||||
# List widget
|
# List widget
|
||||||
self.buy_list_widget = QListWidget()
|
self.buy_list_widget = QListWidget()
|
||||||
self.populate_buy_list(songs)
|
self.populate_buy_list(songs)
|
||||||
layout.addWidget(QLabel(f"Found {len(songs)} songs to buy:"))
|
layout.addWidget(QLabel(f"Found {len(songs)} songs to buy:"))
|
||||||
layout.addWidget(self.buy_list_widget)
|
layout.addWidget(self.buy_list_widget)
|
||||||
|
|
||||||
# Buttons
|
# Buttons
|
||||||
button_layout = QHBoxLayout()
|
button_layout = QHBoxLayout()
|
||||||
open_button = QPushButton("Open Selected")
|
open_button = QPushButton("Open Selected")
|
||||||
open_button.clicked.connect(self.open_selected_buy_items)
|
open_button.clicked.connect(self.open_selected_buy_items)
|
||||||
button_layout.addWidget(open_button)
|
button_layout.addWidget(open_button)
|
||||||
|
|
||||||
remove_button = QPushButton("Remove Selected")
|
remove_button = QPushButton("Remove Selected")
|
||||||
remove_button.clicked.connect(lambda: self.remove_selected_buy_items(songs, dialog))
|
remove_button.clicked.connect(lambda: self.remove_selected_buy_items(songs, dialog))
|
||||||
button_layout.addWidget(remove_button)
|
button_layout.addWidget(remove_button)
|
||||||
|
|
||||||
close_button = QPushButton("Close")
|
close_button = QPushButton("Close")
|
||||||
close_button.clicked.connect(dialog.close)
|
close_button.clicked.connect(dialog.close)
|
||||||
button_layout.addWidget(close_button)
|
button_layout.addWidget(close_button)
|
||||||
|
|
||||||
layout.addLayout(button_layout)
|
layout.addLayout(button_layout)
|
||||||
|
|
||||||
dialog.setLayout(layout)
|
dialog.setLayout(layout)
|
||||||
dialog.show()
|
dialog.show()
|
||||||
dialog.raise_()
|
dialog.raise_()
|
||||||
dialog.activateWindow()
|
dialog.activateWindow()
|
||||||
dialog.exec()
|
dialog.exec()
|
||||||
|
except Exception as e:
|
||||||
|
QMessageBox.critical(self, "Error", f"Failed to show buy list dialog: {e}")
|
||||||
|
|
||||||
def populate_buy_list(self, songs):
|
def populate_buy_list(self, songs):
|
||||||
"""Populate the buy list widget"""
|
"""Populate the buy list widget"""
|
||||||
|
|||||||
Reference in new issue
Block a user