Browse Source

pyqt5 start

subDesTagesMitExtraKaese 5 years ago
parent
commit
8eb4105427
7 changed files with 216 additions and 0 deletions
  1. 1 0
      .gitignore
  2. 23 0
      software/appWindow.py
  3. 41 0
      software/install.md
  4. 17 0
      software/main.py
  5. 9 0
      software/ui/main.py
  6. 52 0
      software/ui/main_ui.py
  7. 73 0
      software/ui/main_ui.ui

+ 1 - 0
.gitignore

@@ -1 +1,2 @@
 *.code-workspace
+__pycache__/

+ 23 - 0
software/appWindow.py

@@ -0,0 +1,23 @@
+#!/usr/bin/python3
+# -*- coding: utf-8 -*-
+
+from PyQt5.QtWidgets import *
+from PyQt5.QtCore import (QSettings, QThread, pyqtSignal, pyqtSlot)
+
+import sys
+sys.path.insert(1, 'ui')
+from main_ui import Ui_MainWindow
+
+class AppWindow(QMainWindow):
+
+  def __init__(self):
+    super().__init__()
+    self.ui = Ui_MainWindow()
+    self.ui.setupUi(self)
+    self.ui.saveButton.clicked.connect(self.save_pressed)
+
+    self.show()
+
+  def save_pressed(self):
+    print("Hello World!")
+

+ 41 - 0
software/install.md

@@ -0,0 +1,41 @@
+# Installation
+
+## PyQt5 [Tutorial](https://likegeeks.com/pyqt5-tutorial/)
+
+on Ubuntu / Debian
+
+``` bash
+sudo apt update
+sudo apt upgrade -y
+sudo apt install python3 python3-pip
+python3 -m pip install PyQt5 PyQt5-tools
+```
+
+## Modifying UI with PyQt5 designer
+
+Location of PyQt5 designer on Windows
+> C:\Program Files\Python36\Lib\site-packages\pyqt5-tools\
+
+or
+
+> C:\Users\\\<User>\AppData\Local\Programs\Python\\\<version>\Lib\site-packages\pyqt5-tools\
+
+## Regenerate UI
+
+on Linux
+
+```bash
+python3 -m PyQt5.uic.pyuic youruifile -o yourpyfile -x
+```
+
+on Windows
+
+```cmd
+pyuic5 youruifile -o yourpyfile -x
+```
+
+## Running
+
+```bash
+python3 main.py
+```

+ 17 - 0
software/main.py

@@ -0,0 +1,17 @@
+#!/usr/bin/python3
+# -*- coding: utf-8 -*-
+
+import sys
+
+from PyQt5.QtWidgets import *
+from PyQt5.QtCore import (QThread, pyqtSignal, pyqtSlot)
+
+from appWindow import AppWindow
+
+
+
+qApp = QApplication(sys.argv)
+w = AppWindow()
+ret = qApp.exec_()
+
+sys.exit(ret)

+ 9 - 0
software/ui/main.py

@@ -0,0 +1,9 @@
+# -*- coding: utf-8 -*-
+
+# Form implementation generated from reading ui file 'ui\main.ui'
+#
+# Created by: PyQt5 UI code generator 5.14.1
+#
+# WARNING! All changes made in this file will be lost!
+
+

+ 52 - 0
software/ui/main_ui.py

@@ -0,0 +1,52 @@
+# -*- coding: utf-8 -*-
+
+# Form implementation generated from reading ui file 'ui\main_ui.ui'
+#
+# Created by: PyQt5 UI code generator 5.14.1
+#
+# WARNING! All changes made in this file will be lost!
+
+
+from PyQt5 import QtCore, QtGui, QtWidgets
+
+
+class Ui_MainWindow(object):
+    def setupUi(self, MainWindow):
+        MainWindow.setObjectName("MainWindow")
+        MainWindow.resize(927, 476)
+        self.centralwidget = QtWidgets.QWidget(MainWindow)
+        self.centralwidget.setObjectName("centralwidget")
+        self.saveButton = QtWidgets.QPushButton(self.centralwidget)
+        self.saveButton.setGeometry(QtCore.QRect(824, 410, 71, 23))
+        self.saveButton.setObjectName("saveButton")
+        self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
+        self.textEdit.setGeometry(QtCore.QRect(20, 20, 621, 411))
+        self.textEdit.setObjectName("textEdit")
+        MainWindow.setCentralWidget(self.centralwidget)
+        self.menubar = QtWidgets.QMenuBar(MainWindow)
+        self.menubar.setGeometry(QtCore.QRect(0, 0, 927, 21))
+        self.menubar.setObjectName("menubar")
+        self.menuFile = QtWidgets.QMenu(self.menubar)
+        self.menuFile.setObjectName("menuFile")
+        self.menuEdit = QtWidgets.QMenu(self.menubar)
+        self.menuEdit.setObjectName("menuEdit")
+        self.menuView = QtWidgets.QMenu(self.menubar)
+        self.menuView.setObjectName("menuView")
+        MainWindow.setMenuBar(self.menubar)
+        self.statusbar = QtWidgets.QStatusBar(MainWindow)
+        self.statusbar.setObjectName("statusbar")
+        MainWindow.setStatusBar(self.statusbar)
+        self.menubar.addAction(self.menuFile.menuAction())
+        self.menubar.addAction(self.menuEdit.menuAction())
+        self.menubar.addAction(self.menuView.menuAction())
+
+        self.retranslateUi(MainWindow)
+        QtCore.QMetaObject.connectSlotsByName(MainWindow)
+
+    def retranslateUi(self, MainWindow):
+        _translate = QtCore.QCoreApplication.translate
+        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
+        self.saveButton.setText(_translate("MainWindow", "save"))
+        self.menuFile.setTitle(_translate("MainWindow", "File"))
+        self.menuEdit.setTitle(_translate("MainWindow", "Edit"))
+        self.menuView.setTitle(_translate("MainWindow", "View"))

+ 73 - 0
software/ui/main_ui.ui

@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>927</width>
+    <height>476</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <widget class="QWidget" name="centralwidget">
+   <widget class="QPushButton" name="saveButton">
+    <property name="geometry">
+     <rect>
+      <x>824</x>
+      <y>410</y>
+      <width>71</width>
+      <height>23</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>save</string>
+    </property>
+   </widget>
+   <widget class="QTextEdit" name="textEdit">
+    <property name="geometry">
+     <rect>
+      <x>20</x>
+      <y>20</y>
+      <width>621</width>
+      <height>411</height>
+     </rect>
+    </property>
+   </widget>
+  </widget>
+  <widget class="QMenuBar" name="menubar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>927</width>
+     <height>21</height>
+    </rect>
+   </property>
+   <widget class="QMenu" name="menuFile">
+    <property name="title">
+     <string>File</string>
+    </property>
+   </widget>
+   <widget class="QMenu" name="menuEdit">
+    <property name="title">
+     <string>Edit</string>
+    </property>
+   </widget>
+   <widget class="QMenu" name="menuView">
+    <property name="title">
+     <string>View</string>
+    </property>
+   </widget>
+   <addaction name="menuFile"/>
+   <addaction name="menuEdit"/>
+   <addaction name="menuView"/>
+  </widget>
+  <widget class="QStatusBar" name="statusbar"/>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>