def __init__(self, mainWindow): super(tabDownloaded, self).__init__(mainWindow) self.mainWindow = mainWindow self.Ui_tabDownloaded = Ui_tabDownloaded() self.Ui_tabDownloaded.setupUi(self) self.show() self.Ui_tabDownloaded.btn_open.setIcon(QtGui.QIcon(resource_path('open.png'))) self.Ui_tabDownloaded.btn_open.setIconSize(QtCore.QSize(24, 24)) self.Ui_tabDownloaded.btn_open.clicked.connect(self.openFolder) self.Ui_tabDownloaded.btn_delete.setIcon(QtGui.QIcon(resource_path('delete.png'))) self.Ui_tabDownloaded.btn_delete.setIconSize(QtCore.QSize(24, 24)) self.Ui_tabDownloaded.btn_delete.clicked.connect(self.delete) self.Ui_tabDownloaded.btn_delete_all.setIcon(QtGui.QIcon(resource_path('delete_all.png'))) self.Ui_tabDownloaded.btn_delete_all.setIconSize(QtCore.QSize(24, 24)) self.con = sqlite3.connect('data.db') self.model = QtSql.QSqlTableModel(self) self.model.setTable("Downloaded") self.model.select() self.Ui_tabDownloaded.tableView.setModel(self.model) self.Ui_tabDownloaded.tableView.setSelectionBehavior(Qt.QAbstractItemView.SelectRows) self.Ui_tabDownloaded.tableView.resizeColumnsToContents() self.Ui_tabDownloaded.tableView.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers) self.Ui_tabDownloaded.tableView.show()
class tabDownloaded(QtWidgets.QWidget): downloadStart = pyqtSignal(str, str, str) downloadDone = pyqtSignal(str) def __init__(self, mainWindow): super(tabDownloaded, self).__init__(mainWindow) self.mainWindow = mainWindow self.Ui_tabDownloaded = Ui_tabDownloaded() self.Ui_tabDownloaded.setupUi(self) self.show() self.Ui_tabDownloaded.btn_open.setIcon(QtGui.QIcon(resource_path('open.png'))) self.Ui_tabDownloaded.btn_open.setIconSize(QtCore.QSize(24, 24)) self.Ui_tabDownloaded.btn_open.clicked.connect(self.openFolder) self.Ui_tabDownloaded.btn_delete.setIcon(QtGui.QIcon(resource_path('delete.png'))) self.Ui_tabDownloaded.btn_delete.setIconSize(QtCore.QSize(24, 24)) self.Ui_tabDownloaded.btn_delete.clicked.connect(self.delete) self.Ui_tabDownloaded.btn_delete_all.setIcon(QtGui.QIcon(resource_path('delete_all.png'))) self.Ui_tabDownloaded.btn_delete_all.setIconSize(QtCore.QSize(24, 24)) self.con = sqlite3.connect('data.db') self.model = QtSql.QSqlTableModel(self) self.model.setTable("Downloaded") self.model.select() self.Ui_tabDownloaded.tableView.setModel(self.model) self.Ui_tabDownloaded.tableView.setSelectionBehavior(Qt.QAbstractItemView.SelectRows) self.Ui_tabDownloaded.tableView.resizeColumnsToContents() self.Ui_tabDownloaded.tableView.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers) self.Ui_tabDownloaded.tableView.show() def cellClicked(self, qmodelindex): self.item = qmodelindex.data(QtCore.Qt.DisplayRole).toString() print(self.item) def delete(self): self.model.removeRow(self.Ui_tabDownloaded.tableView.currentIndex().row()) self.update_all() def update_all(self): self.model.select() self.model.submitAll() def openFolder(self): path = [] indexes = self.Ui_tabDownloaded.tableView.selectionModel().selectedRows() for index in indexes: ids = self.model.index(index.row(), 2).data() idx = str(ids.toString()) path.append(idx) if len(path) == 0: self.msg = QtWidgets.QMessageBox() self.msg.setText('Please choose row !') self.msg.show() return False else: d = path[0] if sys.platform == 'win32': subprocess.Popen(['start', d], shell=True) elif sys.platform == 'darwin': subprocess.Popen(['open', d]) else: subprocess.Popen(['xdg-open', d]) return True def insertRow(self, path, link_download): cursors = self.con.cursor() file_name = link_download.split('/').pop().split('#')[0] cursors.execute('INSERT INTO Downloaded(filename, location, addtime, finishtime) VALUES (?, ? ,? , ?);', (str(file_name), str(path), str())) pass def shutDown(self, linkDownload): # TODO: Add shutdown signal finish_time = datetime.now().strftime('%H:%M:%S %d-%m-%Y') pass