Change QTableWidget header on PySide
# set headers self.tableWidgetEmulators.setHorizontalHeaderLabels(["name", "nox id"])
References
https://www.qtcentre.org/threads/21008-Change-QTableWidget-header-name-or-text
# set headers self.tableWidgetEmulators.setHorizontalHeaderLabels(["name", "nox id"])
References
https://www.qtcentre.org/threads/21008-Change-QTableWidget-header-name-or-text
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/
import subprocess DETACHED_PROCESS = 0x00000008 results = subprocess.Popen(['notepad.exe'], close_fds=True, creationflags=DETACHED_PROCESS) print(results.pid)
References
https://stackoverflow.com/questions/11585168/launch-an-independent-process-with-python
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/
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
def create_project(conn, project): """ Create a new project into the projects table :param conn: :param project: :return: project id """ sql = ''' INSERT INTO projects(name,begin_date,end_date) VALUES(?,?,?) ''' cur = conn.cursor() cur.execute(sql, project) conn.commit() return cur.lastrowid
References
https://www.sqlitetutorial.net/sqlite-python/insert/
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/
import sqlite3 from sqlite3 import Error def create_connection(db_file): """ create a database connection to a SQLite database """ conn = None try: conn = sqlite3.connect(db_file) print(sqlite3.version) except Error as e: print(e) finally: if conn: conn.close() if __name__ == '__main__': create_connection(r"C:\sqlite\db\pythonsqlite.db")
References
https://www.sqlitetutorial.net/sqlite-python/creating-database/
import os os.path.isdir('./final_data_folder')
References
https://careerkarma.com/blog/python-check-if-file-exists
from pathlib import Path home = str(Path.home())
C:\Users\Mahmood
References
https://stackoverflow.com/questions/4028904/how-to-get-the-home-directory-in-python