simon před 10 měsíci
rodič
revize
7e7acc25bd

+ 339 - 0
.vscode/PythonImportHelper-v2-Completion.json

@@ -1043,6 +1043,14 @@
         "documentation": {}
     },
     {
+        "label": "QMainWindow",
+        "importPath": "PyQt5.QtWidgets",
+        "description": "PyQt5.QtWidgets",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtWidgets",
+        "documentation": {}
+    },
+    {
         "label": "QApplication",
         "importPath": "PyQt5.QtWidgets",
         "description": "PyQt5.QtWidgets",
@@ -1051,6 +1059,102 @@
         "documentation": {}
     },
     {
+        "label": "QLabel",
+        "importPath": "PyQt5.QtWidgets",
+        "description": "PyQt5.QtWidgets",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtWidgets",
+        "documentation": {}
+    },
+    {
+        "label": "QMainWindow",
+        "importPath": "PyQt5.QtWidgets",
+        "description": "PyQt5.QtWidgets",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtWidgets",
+        "documentation": {}
+    },
+    {
+        "label": "QApplication",
+        "importPath": "PyQt5.QtWidgets",
+        "description": "PyQt5.QtWidgets",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtWidgets",
+        "documentation": {}
+    },
+    {
+        "label": "QLabel",
+        "importPath": "PyQt5.QtWidgets",
+        "description": "PyQt5.QtWidgets",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtWidgets",
+        "documentation": {}
+    },
+    {
+        "label": "QApplication",
+        "importPath": "PyQt5.QtWidgets",
+        "description": "PyQt5.QtWidgets",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtWidgets",
+        "documentation": {}
+    },
+    {
+        "label": "QMainWindow",
+        "importPath": "PyQt5.QtWidgets",
+        "description": "PyQt5.QtWidgets",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtWidgets",
+        "documentation": {}
+    },
+    {
+        "label": "QLabel",
+        "importPath": "PyQt5.QtWidgets",
+        "description": "PyQt5.QtWidgets",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtWidgets",
+        "documentation": {}
+    },
+    {
+        "label": "QMainWindow",
+        "importPath": "PyQt5.QtWidgets",
+        "description": "PyQt5.QtWidgets",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtWidgets",
+        "documentation": {}
+    },
+    {
+        "label": "QVBoxLayout",
+        "importPath": "PyQt5.QtWidgets",
+        "description": "PyQt5.QtWidgets",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtWidgets",
+        "documentation": {}
+    },
+    {
+        "label": "QLabel",
+        "importPath": "PyQt5.QtWidgets",
+        "description": "PyQt5.QtWidgets",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtWidgets",
+        "documentation": {}
+    },
+    {
+        "label": "QPushButton",
+        "importPath": "PyQt5.QtWidgets",
+        "description": "PyQt5.QtWidgets",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtWidgets",
+        "documentation": {}
+    },
+    {
+        "label": "QWidget",
+        "importPath": "PyQt5.QtWidgets",
+        "description": "PyQt5.QtWidgets",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtWidgets",
+        "documentation": {}
+    },
+    {
         "label": "QMainWindow",
         "importPath": "PyQt5.QtWidgets",
         "description": "PyQt5.QtWidgets",
@@ -1059,6 +1163,14 @@
         "documentation": {}
     },
     {
+        "label": "QVBoxLayout",
+        "importPath": "PyQt5.QtWidgets",
+        "description": "PyQt5.QtWidgets",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtWidgets",
+        "documentation": {}
+    },
+    {
         "label": "QLabel",
         "importPath": "PyQt5.QtWidgets",
         "description": "PyQt5.QtWidgets",
@@ -1067,6 +1179,22 @@
         "documentation": {}
     },
     {
+        "label": "QPushButton",
+        "importPath": "PyQt5.QtWidgets",
+        "description": "PyQt5.QtWidgets",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtWidgets",
+        "documentation": {}
+    },
+    {
+        "label": "QWidget",
+        "importPath": "PyQt5.QtWidgets",
+        "description": "PyQt5.QtWidgets",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtWidgets",
+        "documentation": {}
+    },
+    {
         "label": "QApplication",
         "importPath": "PyQt5.QtWidgets",
         "description": "PyQt5.QtWidgets",
@@ -1883,6 +2011,86 @@
         "documentation": {}
     },
     {
+        "label": "Qt",
+        "importPath": "PyQt5.QtCore",
+        "description": "PyQt5.QtCore",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtCore",
+        "documentation": {}
+    },
+    {
+        "label": "Qt",
+        "importPath": "PyQt5.QtCore",
+        "description": "PyQt5.QtCore",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtCore",
+        "documentation": {}
+    },
+    {
+        "label": "QRunnable",
+        "importPath": "PyQt5.QtCore",
+        "description": "PyQt5.QtCore",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtCore",
+        "documentation": {}
+    },
+    {
+        "label": "pyqtSlot",
+        "importPath": "PyQt5.QtCore",
+        "description": "PyQt5.QtCore",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtCore",
+        "documentation": {}
+    },
+    {
+        "label": "QThreadPool",
+        "importPath": "PyQt5.QtCore",
+        "description": "PyQt5.QtCore",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtCore",
+        "documentation": {}
+    },
+    {
+        "label": "QTimer",
+        "importPath": "PyQt5.QtCore",
+        "description": "PyQt5.QtCore",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtCore",
+        "documentation": {}
+    },
+    {
+        "label": "QRunnable",
+        "importPath": "PyQt5.QtCore",
+        "description": "PyQt5.QtCore",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtCore",
+        "documentation": {}
+    },
+    {
+        "label": "pyqtSlot",
+        "importPath": "PyQt5.QtCore",
+        "description": "PyQt5.QtCore",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtCore",
+        "documentation": {}
+    },
+    {
+        "label": "QThreadPool",
+        "importPath": "PyQt5.QtCore",
+        "description": "PyQt5.QtCore",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtCore",
+        "documentation": {}
+    },
+    {
+        "label": "QTimer",
+        "importPath": "PyQt5.QtCore",
+        "description": "PyQt5.QtCore",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtCore",
+        "documentation": {}
+    },
+    {
         "label": "QSize",
         "importPath": "PyQt5.QtCore",
         "description": "PyQt5.QtCore",
@@ -2187,6 +2395,38 @@
         "documentation": {}
     },
     {
+        "label": "QPainter",
+        "importPath": "PyQt5.QtGui",
+        "description": "PyQt5.QtGui",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtGui",
+        "documentation": {}
+    },
+    {
+        "label": "QPixmap",
+        "importPath": "PyQt5.QtGui",
+        "description": "PyQt5.QtGui",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtGui",
+        "documentation": {}
+    },
+    {
+        "label": "QPixmap",
+        "importPath": "PyQt5.QtGui",
+        "description": "PyQt5.QtGui",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtGui",
+        "documentation": {}
+    },
+    {
+        "label": "QPainter",
+        "importPath": "PyQt5.QtGui",
+        "description": "PyQt5.QtGui",
+        "isExtraImport": true,
+        "detail": "PyQt5.QtGui",
+        "documentation": {}
+    },
+    {
         "label": "QColor",
         "importPath": "PyQt5.QtGui",
         "description": "PyQt5.QtGui",
@@ -2340,6 +2580,15 @@
         "documentation": {}
     },
     {
+        "label": "time",
+        "kind": 6,
+        "isExtraImport": true,
+        "importPath": "time",
+        "description": "time",
+        "detail": "time",
+        "documentation": {}
+    },
+    {
         "label": "QSqlDatabase",
         "importPath": "PyQt5.QtSql",
         "description": "PyQt5.QtSql",
@@ -3523,6 +3772,60 @@
     {
         "label": "MainWindow",
         "kind": 6,
+        "importPath": "bitmap.paint_line",
+        "description": "bitmap.paint_line",
+        "peekOfCode": "class MainWindow(QMainWindow):\n    def __init__(self):\n        super().__init__()\n        self.label = QLabel()\n        canvas = QPixmap(400, 300)\n        canvas.fill(Qt.white)\n        self.label.setPixmap(canvas)\n        self.setCentralWidget(self.label)\n        self.last_x, self.last_y = None, None\n    def mouseMoveEvent(self, e):",
+        "detail": "bitmap.paint_line",
+        "documentation": {}
+    },
+    {
+        "label": "app",
+        "kind": 5,
+        "importPath": "bitmap.paint_line",
+        "description": "bitmap.paint_line",
+        "peekOfCode": "app = QApplication(sys.argv)\nwindow = MainWindow()\nwindow.show()\napp.exec_()",
+        "detail": "bitmap.paint_line",
+        "documentation": {}
+    },
+    {
+        "label": "window",
+        "kind": 5,
+        "importPath": "bitmap.paint_line",
+        "description": "bitmap.paint_line",
+        "peekOfCode": "window = MainWindow()\nwindow.show()\napp.exec_()",
+        "detail": "bitmap.paint_line",
+        "documentation": {}
+    },
+    {
+        "label": "MainWindow",
+        "kind": 6,
+        "importPath": "bitmap.paint_start",
+        "description": "bitmap.paint_start",
+        "peekOfCode": "class MainWindow(QMainWindow):\n    def __init__(self):\n        super().__init__()\n        self.label = QLabel()\n        canvas = QPixmap(400, 300)\n        canvas.fill(Qt.white)\n        self.label.setPixmap(canvas)\n        self.setCentralWidget(self.label)\n    def mouseMoveEvent(self, e):\n        painter = QPainter(self.label.pixmap())",
+        "detail": "bitmap.paint_start",
+        "documentation": {}
+    },
+    {
+        "label": "app",
+        "kind": 5,
+        "importPath": "bitmap.paint_start",
+        "description": "bitmap.paint_start",
+        "peekOfCode": "app = QApplication(sys.argv)\nwindow = MainWindow()\nwindow.show()\napp.exec_()",
+        "detail": "bitmap.paint_start",
+        "documentation": {}
+    },
+    {
+        "label": "window",
+        "kind": 5,
+        "importPath": "bitmap.paint_start",
+        "description": "bitmap.paint_start",
+        "peekOfCode": "window = MainWindow()\nwindow.show()\napp.exec_()",
+        "detail": "bitmap.paint_start",
+        "documentation": {}
+    },
+    {
+        "label": "MainWindow",
+        "kind": 6,
         "importPath": "bitmap.stub",
         "description": "bitmap.stub",
         "peekOfCode": "class MainWindow(QMainWindow):\n    def __init__(self):\n        super().__init__()\n        self.initUI()\n    def initUI(self):\n        self.label = QLabel()\n        canvas = QPixmap(400, 300)\n        canvas.fill(Qt.white)\n        self.label.setPixmap(canvas)\n        self.setCentralWidget(self.label)",
@@ -3530,6 +3833,42 @@
         "documentation": {}
     },
     {
+        "label": "Worker",
+        "kind": 6,
+        "importPath": "concurrent.qrunnable_1",
+        "description": "concurrent.qrunnable_1",
+        "peekOfCode": "class Worker(QRunnable):\n    \"\"\"\n    Worker thread\n    \"\"\"\n    @pyqtSlot()\n    def run(self):\n        \"\"\"\n        Your code goes in this function\n        \"\"\"\n        print(\"Thread start\")",
+        "detail": "concurrent.qrunnable_1",
+        "documentation": {}
+    },
+    {
+        "label": "MainWindow",
+        "kind": 6,
+        "importPath": "concurrent.qrunnable_1",
+        "description": "concurrent.qrunnable_1",
+        "peekOfCode": "class MainWindow(QMainWindow):\n    def __init__(self):\n        super().__init__()\n        self.counter = 0\n        self.threadpool = QThreadPool()\n        print(\"Multithreading with maximum %d threads\" %\n              self.threadpool.maxThreadCount())\n        self.ui()\n    def ui(self):\n        layout = QVBoxLayout()",
+        "detail": "concurrent.qrunnable_1",
+        "documentation": {}
+    },
+    {
+        "label": "Worker",
+        "kind": 6,
+        "importPath": "concurrent.qrunnable_start_2",
+        "description": "concurrent.qrunnable_start_2",
+        "peekOfCode": "class Worker(QRunnable):\n    \"\"\"\n    Worker thread\n    \"\"\"\n    @pyqtSlot()\n    def run(self):\n        \"\"\"\n        Your code goes in this function\n        \"\"\"\n        print(\"Thread start\")",
+        "detail": "concurrent.qrunnable_start_2",
+        "documentation": {}
+    },
+    {
+        "label": "MainWindow",
+        "kind": 6,
+        "importPath": "concurrent.qrunnable_start_2",
+        "description": "concurrent.qrunnable_start_2",
+        "peekOfCode": "class MainWindow(QMainWindow):\n    def __init__(self):\n        super().__init__()\n        self.counter = 0\n        self.threadpool = QThreadPool()\n        print(\"Multithreading with maximum %d threads\" %\n              self.threadpool.maxThreadCount())\n        self.ui()\n    def ui(self):\n        layout = QVBoxLayout()",
+        "detail": "concurrent.qrunnable_start_2",
+        "documentation": {}
+    },
+    {
         "label": "MainWindow",
         "kind": 6,
         "importPath": "databases.tableview",

+ 43 - 0
bitmap/paint_line.py

@@ -0,0 +1,43 @@
+import sys
+from PyQt5.QtWidgets import QMainWindow, QApplication, QLabel
+from PyQt5.QtGui import QPixmap, QPainter
+from PyQt5.QtCore import Qt
+
+
+class MainWindow(QMainWindow):
+
+    def __init__(self):
+        super().__init__()
+
+        self.label = QLabel()
+        canvas = QPixmap(400, 300)
+        canvas.fill(Qt.white)
+        self.label.setPixmap(canvas)
+        self.setCentralWidget(self.label)
+
+        self.last_x, self.last_y = None, None
+
+    def mouseMoveEvent(self, e):
+        if self.last_x is None:
+            self.last_x = e.x()
+            self.last_y = e.y()
+            return
+
+        painter = QPainter(self.label.pixmap())
+        painter.drawLine(self.last_x, self.last_y, e.x(), e.y())
+        painter.end()
+        self.update()
+
+        # Update the origin for next time
+        self.last_x = e.x()
+        self.last_y = e.y()
+
+    def mouseReleaseEvent(self, e):
+        self.last_x = None
+        self.last_y = None
+
+
+app = QApplication(sys.argv)
+window = MainWindow()
+window.show()
+app.exec_()

+ 28 - 0
bitmap/paint_start.py

@@ -0,0 +1,28 @@
+from PyQt5.QtWidgets import QMainWindow, QApplication, QLabel
+from PyQt5.QtGui import QPainter, QPixmap
+from PyQt5.QtCore import Qt
+import sys
+
+
+class MainWindow(QMainWindow):
+
+    def __init__(self):
+        super().__init__()
+
+        self.label = QLabel()
+        canvas = QPixmap(400, 300)
+        canvas.fill(Qt.white)
+        self.label.setPixmap(canvas)
+        self.setCentralWidget(self.label)
+
+    def mouseMoveEvent(self, e):
+        painter = QPainter(self.label.pixmap())
+        painter.drawPoint(e.x(), e.y())
+        painter.end()
+        self.update()
+
+
+app = QApplication(sys.argv)
+window = MainWindow()
+window.show()
+app.exec_()

+ 75 - 0
concurrent/qrunnable_1.py

@@ -0,0 +1,75 @@
+from PyQt5.QtCore import QRunnable, pyqtSlot, QThreadPool, QTimer
+from PyQt5.QtWidgets import (QMainWindow, QVBoxLayout, QLabel, QPushButton,
+                             QWidget)
+import time
+
+
+class Worker(QRunnable):
+    """
+    Worker thread
+    """
+
+    @pyqtSlot()
+    def run(self):
+        """
+        Your code goes in this function
+        """
+        print("Thread start")
+        time.sleep(5)
+        print("Thread complete")
+        return
+
+
+class MainWindow(QMainWindow):
+
+    def __init__(self):
+        super().__init__()
+
+        self.counter = 0
+
+        self.threadpool = QThreadPool()
+        print("Multithreading with maximum %d threads" %
+              self.threadpool.maxThreadCount())
+
+        self.ui()
+
+    def ui(self):
+        layout = QVBoxLayout()
+        self.label = QLabel("Start")
+        b = QPushButton("DANGER!")
+        b.pressed.connect(self.no_no)
+
+        layout.addWidget(self.label)
+        layout.addWidget(b)
+
+        w = QWidget()
+        w.setLayout(layout)
+        self.setCentralWidget(w)
+
+        self.timer = QTimer()
+        self.timer.setInterval(1000)
+        self.timer.timeout.connect(self.recurring_timer)
+        self.timer.start()
+
+    def no_no(self):
+        self.threadpool.start(self.do_some_work)
+
+    @pyqtSlot()
+    def do_some_work(self):
+        print("Thread start")
+        time.sleep(5)
+        print("Thread complete")
+
+    def recurring_timer(self):
+        self.counter += 1
+        self.label.setText("Counter: %d" % self.counter)
+
+
+if __name__ == '__main__':
+    import sys
+    from PyQt5.QtWidgets import QApplication
+
+    app = QApplication(sys.argv)
+    window = MainWindow()
+    window.show()
+    sys.exit(app.exec_())

+ 74 - 0
concurrent/qrunnable_start_2.py

@@ -0,0 +1,74 @@
+from PyQt5.QtCore import QRunnable, pyqtSlot, QThreadPool, QTimer
+from PyQt5.QtWidgets import (QMainWindow, QVBoxLayout, QLabel, QPushButton,
+                             QWidget)
+import time
+
+
+class Worker(QRunnable):
+    """
+    Worker thread
+    """
+
+    @pyqtSlot()
+    def run(self):
+        """
+        Your code goes in this function
+        """
+        print("Thread start")
+        time.sleep(5)
+        print("Thread complete")
+        return
+
+
+class MainWindow(QMainWindow):
+
+    def __init__(self):
+        super().__init__()
+
+        self.counter = 0
+
+        self.threadpool = QThreadPool()
+        print("Multithreading with maximum %d threads" %
+              self.threadpool.maxThreadCount())
+
+        self.ui()
+
+    def ui(self):
+        layout = QVBoxLayout()
+        self.label = QLabel("Start")
+        b = QPushButton("DANGER!")
+        b.pressed.connect(self.no_no)
+
+        layout.addWidget(self.label)
+        layout.addWidget(b)
+
+        w = QWidget()
+        w.setLayout(layout)
+        self.setCentralWidget(w)
+
+        self.timer = QTimer()
+        self.timer.setInterval(1000)
+        self.timer.timeout.connect(self.recurring_timer)
+        self.timer.start()
+
+    def no_no(self):
+        self.threadpool.start(self.do_some_work)
+
+    def do_some_work(self):
+        print("Thread start")
+        time.sleep(5)
+        print("Thread complete")
+
+    def recurring_timer(self):
+        self.counter += 1
+        self.label.setText("Counter: %d" % self.counter)
+
+
+if __name__ == '__main__':
+    import sys
+    from PyQt5.QtWidgets import QApplication
+
+    app = QApplication(sys.argv)
+    window = MainWindow()
+    window.show()
+    sys.exit(app.exec_())