-
Notifications
You must be signed in to change notification settings - Fork 0
/
qt.py
119 lines (92 loc) · 3.48 KB
/
qt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# from PyQt5 import QtWidgets
# # from mainwindow import Ui_MainWindow
#
# class Login(QtWidgets.QDialog):
# def __init__(self, parent=None):
# super(Login, self).__init__(parent)
# self.textName = QtWidgets.QLineEdit(self)
# self.textPass = QtWidgets.QLineEdit(self)
# self.buttonLogin = QtWidgets.QPushButton('Login', self)
# self.buttonLogin.clicked.connect(self.handleLogin)
# layout = QtWidgets.QVBoxLayout(self)
# layout.addWidget(self.textName)
# layout.addWidget(self.textPass)
# layout.addWidget(self.buttonLogin)
#
# def handleLogin(self):
# if (self.textName.text() == 'foo' and
# self.textPass.text() == 'bar'):
# self.accept()
# else:
# QtWidgets.QMessageBox.warning(
# self, 'Error', 'Bad user or password')
#
# class Window(QtWidgets.QMainWindow):
# def __init__(self, parent=None):
# super(Window, self).__init__(parent)
# # self.ui = Ui_MainWindow()
# # self.ui.setupUi(self)
#
# if __name__ == '__main__':
#
# import sys
# app = QtWidgets.QApplication(sys.argv)
# login = Login()
#
# if login.exec_() == QtWidgets.QDialog.Accepted:
# window = Window()
# window.show()
# sys.exit(app.exec_())
import sys
from PyQt5 import QtWidgets, QtSql
from PyQt5.QtGui import *
from PyQt5.QtCore import QModelIndex
from PyQt5.QtWidgets import *
import shutil
import os
class Window(QtWidgets.QMainWindow):
def __init__(self, parent = None):
QtWidgets.QMainWindow.__init__(self, parent)
self.model = QStandardItemModel(8, 4)
table = QtWidgets.QTableView()
table.setModel(self.model)
actionMenu = QtWidgets.QMenu(self.tr("&Actions"), self)
fillAction = actionMenu.addAction(self.tr("&Fill Selection"))
clearAction = actionMenu.addAction(self.tr("&Clear Selection"))
selectAllAction = actionMenu.addAction(self.tr("&Select All"))
self.menuBar().addMenu(actionMenu)
fillAction.triggered.connect(self.fillSelection)
clearAction.triggered.connect(self.clearSelection)
selectAllAction.triggered.connect(self.selectAll)
self.selectionModel = table.selectionModel()
self.statusBar()
self.setCentralWidget(table)
self.setWindowTitle(self.tr("Selected Items in a Table Model"))
def fillSelection(self):
indexes = self.selectionModel.selectedIndexes()
for index in indexes:
text = u"(%i,%i)" % (index.row(), index.column())
self.model.setData(index, text)
def clearSelection(self):
indexes = self.selectionModel.selectedIndexes()
for index in indexes:
self.model.setData(index, "")
def selectAll(self):
parent = QModelIndex()
topLeft = self.model.index(0, 0, parent)
bottomRight = self.model.index(
self.model.rowCount(parent) - 1,
self.model.columnCount(parent) - 1, parent)
selection = QtSql.QSqlTableModel.QItemSelection(topLeft, bottomRight)
self.selectionModel.select(selection, QModelIndex.QItemSelectionModel.Select)
def movF():
source = '/path/to/source_folder'
dest1 = '/path/to/dest_folder'
files = os.listdir(source)
for f in files:
shutil.move(source + f, dest1)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())