Working with QTableWidget on PySide

def createTable(self):
   # Create table
    self.tableWidget = QTableWidget()
    self.tableWidget.setRowCount(4)
    self.tableWidget.setColumnCount(2)
    self.tableWidget.setItem(0,0, QTableWidgetItem("Cell (1,1)"))
    self.tableWidget.setItem(0,1, QTableWidgetItem("Cell (1,2)"))
    self.tableWidget.setItem(1,0, QTableWidgetItem("Cell (2,1)"))
    self.tableWidget.setItem(1,1, QTableWidgetItem("Cell (2,2)"))
    self.tableWidget.setItem(2,0, QTableWidgetItem("Cell (3,1)"))
    self.tableWidget.setItem(2,1, QTableWidgetItem("Cell (3,2)"))
    self.tableWidget.setItem(3,0, QTableWidgetItem("Cell (4,1)"))
    self.tableWidget.setItem(3,1, QTableWidgetItem("Cell (4,2)"))
    self.tableWidget.move(0,0)

    # table selection change
    self.tableWidget.doubleClicked.connect(self.on_click)

@pyqtSlot()
def on_click(self):
    print("\n")
    for currentQTableWidgetItem in self.tableWidget.selectedItems():
        print(currentQTableWidgetItem.row(), currentQTableWidgetItem.column(), currentQTableWidgetItem.text())

References
https://pythonspot.com/pyqt5-table/

Delete Data in Python SQLite

def delete_task(conn, id):
    """
    Delete a task by task id
    :param conn:  Connection to the SQLite database
    :param id: id of the task
    :return:
    """
    sql = 'DELETE FROM tasks WHERE id=?'
    cur = conn.cursor()
    cur.execute(sql, (id,))
    conn.commit()
def delete_all_tasks(conn):
    """
    Delete all rows in the tasks table
    :param conn: Connection to the SQLite database
    :return:
    """
    sql = 'DELETE FROM tasks'
    cur = conn.cursor()
    cur.execute(sql)
    conn.commit()

References
https://www.sqlitetutorial.net/sqlite-python/delete/

Show MessageBox on PySide

def showdialog():
   msg = QMessageBox()
   msg.setIcon(QMessageBox.Information)

   msg.setText("This is a message box")
   msg.setInformativeText("This is additional information")
   msg.setWindowTitle("MessageBox demo")
   msg.setDetailedText("The details are as follows:")
   msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
   msg.buttonClicked.connect(msgbtn)
  
   retval = msg.exec_()
   print "value of pressed message box button:", retval
  
def msgbtn(i):
   print "Button pressed is:",i.text()

References
https://pythonbasics.org/pyqt-qmessagebox/
https://www.tutorialspoint.com/pyqt/pyqt_qmessagebox.htm

Querying Data in Python SQLite

def select_all_tasks(conn):
    """
    Query all rows in the tasks table
    :param conn: the Connection object
    :return:
    """
    cur = conn.cursor()
    cur.execute("SELECT * FROM tasks")

    rows = cur.fetchall()

    for row in rows:
        print(row)
def select_task_by_priority(conn, priority):
    """
    Query tasks by priority
    :param conn: the Connection object
    :param priority:
    :return:
    """
    cur = conn.cursor()
    cur.execute("SELECT * FROM tasks WHERE priority=?", (priority,))

    rows = cur.fetchall()

    for row in rows:
        print(row)

References
https://www.sqlitetutorial.net/sqlite-python/sqlite-python-select/