Refactor the code to use pyside6 instead of tkinter. Print the new code in full. Think…
- User
Refactor the code to use pyside6 instead of tkinter. Print the new code in full. Think step by step. Code: import tkinter as tk from tkinter import ttk import sqlite3
def run_query(query, parameters=()): with sqlite3.connect('media.db') as conn: cursor = conn.cursor() result = cursor.execute(query, parameters) if query.strip().lower().startswith("select"): return result.fetchall() conn.commit()
def create_tables(): create_movies_table_sql = ''' CREATE TABLE IF NOT EXISTS movies ( id INTEGER PRIMARY KEY AUTOINCREMENT, movie TEXT, year INTEGER, present BOOLEAN, watched BOOLEAN, notes TEXT ); ''' create_series_table_sql = ''' CREATE TABLE IF NOT EXISTS series ( id INTEGER PRIMARY KEY AUTOINCREMENT, series TEXT, seasons TEXT, year TEXT, present BOOLEAN, seasons_present TEXT, complete BOOLEAN, watched BOOLEAN, seasons_seen TEXT, notes TEXT ); ''' run_query(create_movies_table_sql) run_query(create_series_table_sql)
def load_data(): for row in movies_tree.get_children(): movies_tree.delete(row) for row in series_tree.get_children(): series_tree.delete(row)
Load data into the movies treeview
movies_data = run_query('SELECT * FROM movies') if not movies_data: # Adding an empty row if the table is empty run_query("INSERT INTO movies (movie, year, present, watched, notes) VALUES (?, ?, ?, ?, ?)", ('', None, None, None, '')) movies_data = run_query('SELECT * FROM movies')
for row in movies_data: movies_tree.insert('', 'end', iid=row[0], values=row[1:])
Load data into the series treeview
series_data = run_query('SELECT * FROM series') if not series_data: # Adding an empty row if the table is empty run_query("INSERT INTO series (series, seasons, year, present, seasons_present, complete, watched, seasons_seen, notes) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", ('', '', '', None, '', None, None, '', '')) series_data = run_query('SELECT * FROM series')
for row in series_data: series_tree.insert('', 'end', iid=row[0], values=row[1:])
def add_entry(tree): if tree == movies_tree: run_query("INSERT INTO movies (movie, year, present, watched, notes) VALUES (?, ?, ?, ?, ?)", ('', None, None, None, '')) elif tree == series_tree: run_query("INSERT INTO series (series, seasons, year, present, seasons_present, complete, watched, seasons_seen, notes) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", ('', '', '', None, '', None, None, '', ''))
load_data()
def delete_entry(tree, item): if not tree.exists(item): print(f"Item {item} not found in tree.") return item_values = tree.item(item, "values") if tree == movies_tree: run_query("DELETE FROM movies WHERE id = ?", (item,)) elif tree == series_tree: run_query("DELETE FROM series WHERE id = ?", (item,)) load_data()
def save_edit(tree, item, col, new_value): tree.set(item, column=col, value=new_value)
if tree == movies_tree: columns = ["movie", "year", "present", "watched", "notes"] values = movies_tree.item(item, 'values') run_query(f"UPDATE movies SET {columns[col]} = ? WHERE id = ?", (new_value, item)) elif tree == series_tree: columns = ["series", "seasons", "year", "present", "seasons_present", "complete", "watched", "seasons_seen", "notes"] values = series_tree.item(item, 'values') run_query(f"UPDATE series SET {columns[col]} = ? WHERE series = ? AND year = ?", (new_value, values[0], values[2]))
- Assistant
- User
Move the Movies and Series button to the top and also implement the + and - button like in the original it should be visible next to the table rows (create a little bit of space for them)
- Assistant
- User
no the series and Movies button should be in an extra spcae left of the rows not on top of them
- Assistant
- User
The Movies and Series button should be at the top of the bar not in the middle. Also the + and - buttons should be bewtween the bar with the movie and series button and the first column of the table
- Assistant
- User
Ok now the + and - button should just be a small + or minus symbol left to the first column of the table. And if i press the minus button it should delete the row it is next to the minus and plus button should move with the mouse and align to the row the mouse is on
- Assistant
- User
Traceback (most recent call last): File "D:\Bilder\Python\0. Code\Database 2 - Kopie.py", line 211, in tracker = MediaTracker() ^^^^^^^^^^^^^^ File "D:\Bilder\Python\0. Code\Database 2 - Kopie.py", line 95, in init self.setup_movie_table() File "D:\Bilder\Python\0. Code\Database 2 - Kopie.py", line 107, in setup_movie_table self.movies_table.enterEvent = self.table_hover_event ^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'MediaTracker' object has no attribute 'table_hover_event'
- Assistant
- User
Traceback (most recent call last): File "D:\Bilder\Python\0. Code\Database 2 - Kopie.py", line 210, in tracker = MediaTracker() ^^^^^^^^^^^^^^ File "D:\Bilder\Python\0. Code\Database 2 - Kopie.py", line 99, in init self.show_movies() File "D:\Bilder\Python\0. Code\Database 2 - Kopie.py", line 143, in show_movies self.movies_table.show() File "D:\Bilder\Python\0. Code\Database 2 - Kopie.py", line 185, in eventFilter if event.type() == event.MouseMove: ^^^^^^^^^^^^^^^ AttributeError: Error calling Python override of QMainWindow::eventFilter(): 'PySide6.QtCore.QEvent' object has no attribute 'MouseMove'
- Assistant
- User
I still does not show the + and - symbol make sure there is free space left of the first table column for them to be shown and then make sure to show them there
- Assistant
- User
The responsiveness is very bad of the showing of the button. Improve that at show the button automaticly next to the row when the user hovers the mouse offer the rows.
- Assistant
- User
i get this error: D:\Bilder\Python\0. Code\Database 3 - Kopie - Kopie.py:184: DeprecationWarning: Function: 'QMouseEvent.pos() const' is marked as deprecated, please check the documentation for more information. self.update_buttons_position(table, event.pos()) QWindowsWindow::setGeometry: Unable to set geometry 30x30+1835+993 (frame: 52x86+1824+948) on QWidgetWindow/"QPushButtonClassWindow" on "DELL S2721QS". Resulting geometry: 176x30+1835+993 (frame: 198x86+1824+948) margins: 11, 45, 11, 11 minimum size: 20x20 maximum size: 20x20 MINMAXINFO(maxSize=POINT(x=0, y=0), maxpos=POINT(x=0, y=0), maxtrack=POINT(x=52, y=86), mintrack=POINT(x=52, y=86))) QWindowsWindow::setGeometry: Unable to set geometry 30x30+1835+1023 (frame: 52x86+1824+978) on QWidgetWindow/"QPushButtonClassWindow" on "DELL S2721QS". Resulting geometry: 176x30+1835+1023 (frame: 198x86+1824+978) margins: 11, 45, 11, 11 minimum size: 20x20 maximum size: 20x20 MINMAXINFO(maxSize=POINT(x=0, y=0), maxpos=POINT(x=0, y=0), maxtrack=POINT(x=52, y=86), mintrack=POINT(x=52, y=86))) QWindowsWindow::setGeometry: Unable to set geometry 30x30+1689+993 (frame: 52x86+1678+948) on QWidgetWindow/"QPushButtonClassWindow" on "DELL S2721QS". Resulting geometry: 176x30+1689+993 (frame: 198x86+1678+948) margins: 11, 45, 11, 11 minimum size: 20x20 maximum size: 20x20 MINMAXINFO(maxSize=POINT(x=0, y=0), maxpos=POINT(x=0, y=0), maxtrack=POINT(x=52, y=86), mintrack=POINT(x=52, y=86))) QWindowsWindow::setGeometry: Unable to set geometry 30x30+1689+1023 (frame: 52x86+1678+978) on QWidgetWindow/"QPushButtonClassWindow" on "DELL S2721QS". Resulting geometry: 176x30+1689+1023 (frame: 198x86+1678+978) margins: 11, 45, 11, 11 minimum size: 20x20 maximum size: 20x20 MINMAXINFO(maxSize=POINT(x=0, y=0), maxpos=POINT(x=0, y=0), maxtrack=POINT(x=52, y=86), mintrack=POINT(x=52, y=86))) Also i want the + and - symbol to be shown left of the first column of the row not above it.
- Assistant
- User
It still shows weird windows and i get this error: QWindowsWindow::setGeometry: Unable to set geometry 30x30+2085+989 (frame: 52x86+2074+944) on QWidgetWindow/"QPushButtonClassWindow" on "DELL S2721QS". Resulting geometry: 176x30+2085+989 (frame: 198x86+2074+944) margins: 11, 45, 11, 11 minimum size: 20x20 maximum size: 20x20 MINMAXINFO(maxSize=POINT(x=0, y=0), maxpos=POINT(x=0, y=0), maxtrack=POINT(x=52, y=86), mintrack=POINT(x=52, y=86))) QWindowsWindow::setGeometry: Unable to set geometry 30x30+2085+1019 (frame: 52x86+2074+974) on QWidgetWindow/"QPushButtonClassWindow" on "DELL S2721QS". Resulting geometry: 176x30+2085+1019 (frame: 198x86+2074+974) margins: 11, 45, 11, 11 minimum size: 20x20 maximum size: 20x20 MINMAXINFO(maxSize=POINT(x=0, y=0), maxpos=POINT(x=0, y=0), maxtrack=POINT(x=52, y=86), mintrack=POINT(x=52, y=86))) QWindowsWindow::setGeometry: Unable to set geometry 30x30+1940+989 (frame: 52x86+1929+944) on QWidgetWindow/"QPushButtonClassWindow" on "DELL S2721QS". Resulting geometry: 176x30+1940+989 (frame: 198x86+1929+944) margins: 11, 45, 11, 11 minimum size: 20x20 maximum size: 20x20 MINMAXINFO(maxSize=POINT(x=0, y=0), maxpos=POINT(x=0, y=0), maxtrack=POINT(x=52, y=86), mintrack=POINT(x=52, y=86))) QWindowsWindow::setGeometry: Unable to set geometry 30x30+1940+1019 (frame: 52x86+1929+974) on QWidgetWindow/"QPushButtonClassWindow" on "DELL S2721QS". Resulting geometry: 176x30+1940+1019 (frame: 198x86+1929+974) margins: 11, 45, 11, 11 minimum size: 20x20 maximum size: 20x20 MINMAXINFO(maxSize=POINT(x=0, y=0), maxpos=POINT(x=0, y=0), maxtrack=POINT(x=52, y=86), mintrack=POINT(x=52, y=86))) QWindowsWindow::setGeometry: Unable to set geometry 30x30+2085+1034 (frame: 52x86+2074+989) on QWidgetWindow/"QPushButtonClassWindow" on "DELL S2721QS". Resulting geometry: 176x30+2085+1034 (frame: 198x86+2074+989) margins: 11, 45, 11, 11 minimum size: 20x20 maximum size: 20x20 MINMAXINFO(maxSize=POINT(x=0, y=0), maxpos=POINT(x=0, y=0), maxtrack=POINT(x=52, y=86), mintrack=POINT(x=52, y=86))) QWindowsWindow::setGeometry: Unable to set geometry 30x30+2085+1064 (frame: 52x86+2074+1019) on QWidgetWindow/"QPushButtonClassWindow" on "DELL S2721QS". Resulting geometry: 176x30+2085+1064 (frame: 198x86+2074+1019) margins: 11, 45, 11, 11 minimum size: 20x20 maximum size: 20x20 MINMAXINFO(maxSize=POINT(x=0, y=0), maxpos=POINT(x=0, y=0), maxtrack=POINT(x=52, y=86), mintrack=POINT(x=52, y=86))) I want the buttons to be shown in an small ampty bar beween the field with the table and the field with the movie, Series button.
- Assistant
- User
now i get this error: D:\Bilder\Python\0. Code\Database 3 - Kopie - Kopie.py:191: DeprecationWarning: Function: 'QMouseEvent.pos() const' is marked as deprecated, please check the documentation for more information. self.update_table_interaction(table, event.pos()
- Assistant
- User
now the buttons do not move with the mouse at all.
- Assistant
- User
Ok the movement works now. Now log the buttons to a free white bar between the first column of the table and the bar with the series and Movies button.
- Assistant
- User
good now put the + button left to the - button not above it
- Assistant
- User
Currently the minus button deletes all data within the whole tables but not the row. I want the minus button to only delete the row it is currently aligned with
- Assistant