Server: Create new emergency land dialog

This commit is contained in:
Ilya
2019-06-14 16:59:05 +03:00
parent f9fd81da1f
commit 63b67a14bb
3 changed files with 203 additions and 74 deletions

View File

@@ -1,34 +1,82 @@
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'emergency.ui'
#
# Created by: PyQt5 UI code generator 5.11.3
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
import os
import glob
from PyQt5 import QtWidgets
from PyQt5.QtGui import QStandardItemModel, QStandardItem
from PyQt5.QtCore import Qt, pyqtSlot
from PyQt5.QtWidgets import QFileDialog, QMessageBox
from PyQt5 import QtCore, QtGui, QtWidgets
from server import *
from PyQt5.QtCore import Qt, pyqtSlot, pyqtSignal, QObject
from PyQt5.QtWidgets import QDialog
# Importing gui form
from server_qt import *
from server import *
class Ui_Dialog(object):
def __init__(self):
self.Dialog = None
def setupUi(self, Dialog):
self.Dialog = Dialog
Dialog.setObjectName("Dialog")
Dialog.resize(632, 214)
self.pushButton_2 = QtWidgets.QPushButton(Dialog)
self.pushButton_2.setGeometry(QtCore.QRect(470, 110, 121, 61))
self.pushButton_2.setSizeIncrement(QtCore.QSize(16, 16))
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_3 = QtWidgets.QPushButton(Dialog)
self.pushButton_3.setGeometry(QtCore.QRect(40, 100, 121, 61))
self.pushButton_3.setSizeIncrement(QtCore.QSize(16, 16))
self.pushButton_3.setObjectName("pushButton_3")
self.pushButton_2.clicked.connect(self.btn_2)
self.pushButton_3.clicked.connect(self.btn_3)
Dialog.resize(746, 620)
Dialog.setStyleSheet("QDialog{\n"
"background-color: #fffdd0;\n"
"}")
self.two_button = QtWidgets.QPushButton(Dialog)
self.two_button.setGeometry(QtCore.QRect(420, 120, 231, 171))
self.two_button.setSizeIncrement(QtCore.QSize(16, 16))
self.two_button.setStyleSheet("QPushButton{\n"
"color: white;\n"
"font-weight: 600;\n"
"font-size: 25pt;\n"
"background-color: red;\n"
"}")
self.two_button.setObjectName("two_button")
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(40, 40, 561, 51))
self.label.setGeometry(QtCore.QRect(90, 30, 561, 51))
font = QtGui.QFont()
font.setPointSize(16)
self.label.setFont(font)
self.label.setObjectName("label")
self.one_button = QtWidgets.QPushButton(Dialog)
self.one_button.setGeometry(QtCore.QRect(90, 120, 231, 171))
self.one_button.setSizeIncrement(QtCore.QSize(16, 16))
self.one_button.setStyleSheet("QPushButton{\n"
"color: white;\n"
"font-weight: 600;\n"
"font-size: 25pt;\n"
"background-color: RGB(118, 255, 122);\n"
"}")
self.one_button.setObjectName("one_button")
self.land_emergency_button = QtWidgets.QPushButton(Dialog)
self.land_emergency_button.setGeometry(QtCore.QRect(90, 340, 561, 81))
self.land_emergency_button.setStyleSheet("QPushButton{\n"
"font-weight: 600;\n"
"font-size: 25pt;\n"
"background-color: white;\n"
"}")
self.land_emergency_button.setObjectName("land_emergency_button")
self.disarm_emergency_button = QtWidgets.QPushButton(Dialog)
self.disarm_emergency_button.setGeometry(QtCore.QRect(90, 460, 561, 81))
self.disarm_emergency_button.setStyleSheet("QPushButton{\n"
"font-weight: 600;\n"
"font-size: 25pt;\n"
"background-color: white;\n"
"}")
self.disarm_emergency_button.setObjectName("disarm_emergency_button")
self.one_button.clicked.connect(self.one_button_click)
self.two_button.clicked.connect(self.two_button_click)
self.land_emergency_button.clicked.connect(self.land_emergency_click)
self.disarm_emergency_button.clicked.connect(self.disarm_emergency_click)
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
@@ -36,23 +84,22 @@ class Ui_Dialog(object):
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.pushButton_2.setText(_translate("Dialog", "PushButton"))
self.pushButton_3.setText(_translate("Dialog", "PushButton"))
self.two_button.setText(_translate("Dialog", "2"))
self.label.setText(_translate("Dialog", "\n"
"Select a group in which the drone does not work correctly"))
def btn_2(self):
for row_num in range(model.rowCount()):
item = model.item(row_num, 0)
if item.isCheckable() and item.checkState() == Qt.Checked:
copter = Client.get_by_id(item.text())
copter.send_message("green")
def btn_3(self):
for row_num in range(model.rowCount()):
item = model.item(row_num, 0)
if item.isCheckable() and item.checkState() == Qt.Checked:
copter = Client.get_by_id(item.text())
copter.send_message("red")
self.one_button.setText(_translate("Dialog", "1"))
self.land_emergency_button.setText(_translate("Dialog", "Land"))
self.disarm_emergency_button.setText(_translate("Dialog", "Disarm"))
def one_button_click(self):
self.Dialog.done(1)
def two_button_click(self):
self.Dialog.done(2)
def land_emergency_click(self):
self.Dialog.done(3)
def disarm_emergency_click(self):
self.Dialog.done(4)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)

View File

@@ -6,20 +6,25 @@
<rect>
<x>0</x>
<y>0</y>
<width>632</width>
<height>214</height>
<width>746</width>
<height>620</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QPushButton" name="pushButton_2">
<property name="styleSheet">
<string notr="true">QDialog{
background-color: #fffdd0;
}</string>
</property>
<widget class="QPushButton" name="two_button">
<property name="geometry">
<rect>
<x>470</x>
<y>110</y>
<width>121</width>
<height>61</height>
<x>420</x>
<y>120</y>
<width>231</width>
<height>171</height>
</rect>
</property>
<property name="sizeIncrement">
@@ -28,34 +33,23 @@
<height>16</height>
</size>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_3">
<property name="geometry">
<rect>
<x>40</x>
<y>100</y>
<width>121</width>
<height>61</height>
</rect>
</property>
<property name="sizeIncrement">
<size>
<width>16</width>
<height>16</height>
</size>
<property name="styleSheet">
<string notr="true">QPushButton{
color: white;
font-weight: 600;
font-size: 25pt;
background-color: red;
}</string>
</property>
<property name="text">
<string>PushButton</string>
<string>2</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>40</x>
<y>40</y>
<x>90</x>
<y>30</y>
<width>561</width>
<height>51</height>
</rect>
@@ -70,6 +64,73 @@
Select a group in which the drone does not work correctly</string>
</property>
</widget>
<widget class="QPushButton" name="one_button">
<property name="geometry">
<rect>
<x>90</x>
<y>120</y>
<width>231</width>
<height>171</height>
</rect>
</property>
<property name="sizeIncrement">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">QPushButton{
color: white;
font-weight: 600;
font-size: 25pt;
background-color: RGB(118, 255, 122);
}</string>
</property>
<property name="text">
<string>1</string>
</property>
</widget>
<widget class="QPushButton" name="land_emergency_button">
<property name="geometry">
<rect>
<x>90</x>
<y>340</y>
<width>561</width>
<height>81</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">QPushButton{
font-weight: 600;
font-size: 25pt;
background-color: white;
}</string>
</property>
<property name="text">
<string>Land</string>
</property>
</widget>
<widget class="QPushButton" name="disarm_emergency_button">
<property name="geometry">
<rect>
<x>90</x>
<y>460</y>
<width>561</width>
<height>81</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">QPushButton{
font-weight: 600;
font-size: 25pt;
background-color: white;
}</string>
</property>
<property name="text">
<string>Disarm</string>
</property>
</widget>
</widget>
<resources/>
<connections/>

View File

@@ -3,7 +3,7 @@ import glob
from PyQt5 import QtWidgets
from PyQt5.QtGui import QStandardItemModel, QStandardItem
from PyQt5.QtCore import Qt, pyqtSlot
from PyQt5.QtCore import Qt, pyqtSlot, pyqtSignal, QObject
from PyQt5.QtWidgets import QFileDialog, QMessageBox
@@ -13,7 +13,6 @@ from server_gui import Ui_MainWindow
from server import *
from emergency import *
# noinspection PyArgumentList,PyCallByClass
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
@@ -43,6 +42,8 @@ class MainWindow(QtWidgets.QMainWindow):
# Initing table and table model
self.ui.tableView.setModel(model)
self.ui.tableView.horizontalHeader().setStretchLastSection(True)
# self.ui = Communicate()
# self.ui.button.connect(self.button1)
@pyqtSlot()
def check_selected(self):
@@ -196,17 +197,40 @@ class MainWindow(QtWidgets.QMainWindow):
copter.send_message("service_restart", {"name": "clever"})
@pyqtSlot()
def emergency(self):
for row_num in range(model.rowCount()):
item = model.item(row_num, 0)
if item.isCheckable() and item.checkState() == Qt.Checked:
copter = Client.get_by_id(item.text())
copter.send_message("emergency")
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
Dialog.exec_()
client_row_min = 0
client_row_max = model.rowCount()
result = 0
while (client_row_min != client_row_max) and (result != 3) and (result != 4):
# light_green_red(min, max)
client_row_mid = (client_row_max-client_row_min) / 2
for row_mun in range(client_row_min, client_row_mid):
copter = Client.get_by_id(item.text())
copter.send_message("led_fill", {"red": 255})
for row_num in range(client_row_mid, client_row_max):
copter = Client.get_by_id(item.text())
copter.send_message("led_fill", {"green": 255})
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
result = Dialog.exec()
if (result == 1):
client_row_max = client_row_mid
elif (result == 2):
client_row_min = client_row_mid
if result == 3:
for row_num in range(client_row_min, client_row_max):
item = model.item(row_num, 0)
copter = Client.get_by_id(item.text())
copter.send_message("land")
elif result == 4:
for row_num in range(client_row_min, client_row_max):
item = model.item(row_num, 0)
copter = Client.get_by_id(item.text())
copter.send_message("disarm")
@pyqtSlot()
def flip(self):
reply = QMessageBox.question(
@@ -225,9 +249,6 @@ class MainWindow(QtWidgets.QMainWindow):
else:
print("Cancelled")
pass
model = QStandardItemModel()
model.setHorizontalHeaderLabels(
('copter ID', 'animation ID', 'battery V', 'battery %', 'selfcheck', 'time UTC')