diff --git a/Server/config_editor.py b/Server/config_editor.py new file mode 100644 index 0000000..ecad213 --- /dev/null +++ b/Server/config_editor.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'config_editor.ui' +# +# Created by: PyQt5 UI code generator 5.13.0 +# +# WARNING! All changes made in this file will be lost! + + +from PyQt5 import QtCore, QtGui, QtWidgets + + +class Ui_Dialog(object): + def setupUi(self, Dialog): + Dialog.setObjectName("Dialog") + Dialog.resize(268, 247) + Dialog.setModal(False) + self.gridLayout = QtWidgets.QGridLayout(Dialog) + self.gridLayout.setObjectName("gridLayout") + self.treeView = QtWidgets.QTreeView(Dialog) + self.treeView.setObjectName("treeView") + self.gridLayout.addWidget(self.treeView, 0, 0, 1, 1) + self.gridLayout_2 = QtWidgets.QGridLayout() + self.gridLayout_2.setObjectName("gridLayout_2") + self.pushButton = QtWidgets.QPushButton(Dialog) + self.pushButton.setObjectName("pushButton") + self.gridLayout_2.addWidget(self.pushButton, 0, 0, 1, 1) + self.checkBox = QtWidgets.QCheckBox(Dialog) + self.checkBox.setObjectName("checkBox") + self.gridLayout_2.addWidget(self.checkBox, 1, 0, 1, 1) + self.buttonBox = QtWidgets.QDialogButtonBox(Dialog) + self.buttonBox.setOrientation(QtCore.Qt.Horizontal) + self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Save) + self.buttonBox.setCenterButtons(False) + self.buttonBox.setObjectName("buttonBox") + self.gridLayout_2.addWidget(self.buttonBox, 1, 1, 1, 1) + self.gridLayout.addLayout(self.gridLayout_2, 1, 0, 1, 1) + + self.retranslateUi(Dialog) + self.buttonBox.accepted.connect(Dialog.accept) + self.buttonBox.rejected.connect(Dialog.reject) + QtCore.QMetaObject.connectSlotsByName(Dialog) + + def retranslateUi(self, Dialog): + _translate = QtCore.QCoreApplication.translate + Dialog.setWindowTitle(_translate("Dialog", "Config Editor")) + self.pushButton.setText(_translate("Dialog", "Delete")) + self.pushButton.setShortcut(_translate("Dialog", "Del")) + self.checkBox.setText(_translate("Dialog", "Restart")) + self.checkBox.setShortcut(_translate("Dialog", "R")) + + +if __name__ == "__main__": + import sys + app = QtWidgets.QApplication(sys.argv) + Dialog = QtWidgets.QDialog() + ui = Ui_Dialog() + ui.setupUi(Dialog) + Dialog.show() + sys.exit(app.exec_()) diff --git a/Server/config_editor.ui b/Server/config_editor.ui new file mode 100644 index 0000000..dc3b4f5 --- /dev/null +++ b/Server/config_editor.ui @@ -0,0 +1,97 @@ + + + Dialog + + + + 0 + 0 + 268 + 247 + + + + Config Editor + + + false + + + + + + + + + + + Delete + + + Del + + + + + + + Restart + + + R + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Save + + + false + + + + + + + + + + + buttonBox + accepted() + Dialog + accept() + + + 260 + 237 + + + 157 + 246 + + + + + buttonBox + rejected() + Dialog + reject() + + + 260 + 239 + + + 267 + 246 + + + + + diff --git a/Server/config_editor_models.py b/Server/config_editor_models.py new file mode 100644 index 0000000..1a82ea3 --- /dev/null +++ b/Server/config_editor_models.py @@ -0,0 +1,113 @@ +import config_editor +from PyQt5 import QtCore, QtGui, QtWidgets +from PyQt5.QtCore import Qt as Qt + + +class ConfigModelItem: + def __init__(self, data: list, parent=None): + self.parentItem = parent + self.itemData = data + self.childItems = [] + + def appendChild(self, item): + self.childItems.append(item) + + def child(self, row): + return self.childItems[row] + + def childCount(self): + return len(self.childItems) + + def columnCount(self): + return len(self.itemData) + + def data(self, column): + try: + return self.itemData[column] + except IndexError: + return None + + def parent(self): + return self.parentItem + + def row(self): + if self.parentItem: + return self.parentItem.childItems.index(self) + + return 0 + +class ConfigModel(QtCore.QAbstractItemModel): + def __init__(self, data, parent=None): + super(ConfigModel, self).__init__(parent) + + self.rootItem = ConfigModelItem(("Option", "Value")) + #self.setupModelData(data.split('\n'), self.rootItem) + self.rootItem.appendChild(ConfigModelItem(("1314", "345"))) + + def headerData(self, section, orientation, role): + if role == Qt.DisplayRole and orientation == Qt.Horizontal: + return self.rootItem.data(section) + + def columnCount(self, parent): + if parent.isValid(): + return parent.internalPointer().columnCount() + else: + return self.rootItem.columnCount() + + def rowCount(self, parent): + if parent.column() > 0: + return 0 + + if not parent.isValid(): + parentItem = self.rootItem + else: + parentItem = parent.internalPointer() + + return parentItem.childCount() + + def index(self, row, column, parent): + if not self.hasIndex(row, column, parent): + return QtCore.QModelIndex() + + if not parent.isValid(): + parentItem = self.rootItem + else: + parentItem = parent.internalPointer() + + childItem = parentItem.child(row) + + if childItem: + return self.createIndex(row, column, childItem) + else: + return QtCore.QModelIndex() + + def parent(self, index): + if not index.isValid(): + return QtCore.QModelIndex() + + childItem = index.internalPointer() + parentItem = childItem.parent() + + if parentItem == self.rootItem or parentItem is None: + return QtCore.QModelIndex() + + return self.createIndex(parentItem.row(), 0, parentItem) + +if __name__ == '__main__': + import sys + + + def except_hook(cls, exception, traceback): + sys.__excepthook__(cls, exception, traceback) + + sys.excepthook = except_hook + + m = ConfigModel([12313, 123]) + + app = QtWidgets.QApplication(sys.argv) + Dialog = QtWidgets.QDialog() + ui = config_editor.Ui_Dialog() + ui.setupUi(Dialog) + ui.treeView.setModel(m) + Dialog.show() + sys.exit(app.exec_()) diff --git a/Server/copter_table_models.py b/Server/copter_table_models.py index 977cdfc..184ed78 100644 --- a/Server/copter_table_models.py +++ b/Server/copter_table_models.py @@ -177,9 +177,8 @@ class CopterDataModel(QtCore.QAbstractTableModel): return len(self.headers) def headerData(self, section, orientation, role=Qt.DisplayRole): - if role == Qt.DisplayRole: - if orientation == Qt.Horizontal: - return self.headers[section] + if role == Qt.DisplayRole and orientation == Qt.Horizontal: + return self.headers[section] def data(self, index, role=Qt.DisplayRole): row = index.row() diff --git a/Server/default.txt b/Server/default.txt new file mode 100644 index 0000000..9492303 --- /dev/null +++ b/Server/default.txt @@ -0,0 +1,41 @@ + +Getting Started How to familiarize yourself with Qt Designer + Launching Designer Running the Qt Designer application + The User Interface How to interact with Qt Designer + +Designing a Component Creating a GUI for your application + Creating a Dialog How to create a dialog + Composing the Dialog Putting widgets into the dialog example + Creating a Layout Arranging widgets on a form + Signal and Slot Connections Making widget communicate with each other + +Using a Component in Your Application Generating code from forms + The Direct Approach Using a form without any adjustments + The Single Inheritance Approach Subclassing a form's base class + The Multiple Inheritance Approach Subclassing the form itself + Automatic Connections Connecting widgets using a naming scheme + A Dialog Without Auto-Connect How to connect widgets without a naming scheme + A Dialog With Auto-Connect Using automatic connections + +Form Editing Mode How to edit a form in Qt Designer + Managing Forms Loading and saving forms + Editing a Form Basic editing techniques + The Property Editor Changing widget properties + The Object Inspector Examining the hierarchy of objects on a form + Layouts Objects that arrange widgets on a form + Applying and Breaking Layouts Managing widgets in layouts + Horizontal and Vertical Layouts Standard row and column layouts + The Grid Layout Arranging widgets in a matrix + Previewing Forms Checking that the design works + +Using Containers How to group widgets together + General Features Common container features + Frames QFrame + Group Boxes QGroupBox + Stacked Widgets QStackedWidget + Tab Widgets QTabWidget + Toolbox Widgets QToolBox + +Connection Editing Mode Connecting widgets together with signals and slots + Connecting Objects Making connections in Qt Designer + Editing Connections Changing existing connections \ No newline at end of file diff --git a/Server/test.py b/Server/test.py new file mode 100644 index 0000000..1735972 --- /dev/null +++ b/Server/test.py @@ -0,0 +1,174 @@ +from PyQt5.QtCore import QAbstractItemModel, QFile, QIODevice, QModelIndex, Qt +from PyQt5.QtWidgets import QApplication, QTreeView + + +class TreeItem: + def __init__(self, data: list, parent=None): + self.parentItem = parent + self.itemData = data + self.childItems = [] + + def appendChild(self, item): + self.childItems.append(item) + + def child(self, row): + return self.childItems[row] + + def childCount(self): + return len(self.childItems) + + def columnCount(self): + return len(self.itemData) + + def data(self, column): + try: + return self.itemData[column] + except IndexError: + return None + + def parent(self): + return self.parentItem + + def row(self): + if self.parentItem: + return self.parentItem.childItems.index(self) + + return 0 + + +class TreeModel(QAbstractItemModel): + def __init__(self, data, parent=None): + super(TreeModel, self).__init__(parent) + + self.rootItem = TreeItem(("Title", "Summary")) + self.setupModelData(data.split('\n'), self.rootItem) + self.rootItem.child(1).appendChild(TreeItem(("1314", "345"))) + + def columnCount(self, parent): + if parent.isValid(): + return parent.internalPointer().columnCount() + else: + return self.rootItem.columnCount() + + def data(self, index, role): + if not index.isValid(): + return None + + if role != Qt.DisplayRole: + return None + + item = index.internalPointer() + + return item.data(index.column()) + + def flags(self, index): + if not index.isValid(): + return Qt.NoItemFlags + + return Qt.ItemIsEnabled | Qt.ItemIsSelectable + + def headerData(self, section, orientation, role): + if orientation == Qt.Horizontal and role == Qt.DisplayRole: + return self.rootItem.data(section) + + return None + + def index(self, row, column, parent): + if not self.hasIndex(row, column, parent): + return QModelIndex() + + if not parent.isValid(): + parentItem = self.rootItem + else: + parentItem = parent.internalPointer() + + childItem = parentItem.child(row) + if childItem: + return self.createIndex(row, column, childItem) + else: + return QModelIndex() + + def parent(self, index): + if not index.isValid(): + return QModelIndex() + + childItem = index.internalPointer() + parentItem = childItem.parent() + + if parentItem == self.rootItem or parentItem is None: + return QModelIndex() + + return self.createIndex(parentItem.row(), 0, parentItem) + + def rowCount(self, parent): + if parent.column() > 0: + return 0 + + if not parent.isValid(): + parentItem = self.rootItem + else: + parentItem = parent.internalPointer() + + return parentItem.childCount() + + def setupModelData(self, lines, parent): + parents = [parent] + indentations = [0] + + number = 0 + + while number < len(lines): + position = 0 + while position < len(lines[number]): + if lines[number][position] != ' ': + break + position += 1 + + lineData = lines[number][position:].trimmed() + + if lineData: + # Read the column data from the rest of the line. + columnData = [s for s in lineData.split('\t') if s] + + if position > indentations[-1]: + # The last child of the current parent is now the new + # parent unless the current parent has no children. + + if parents[-1].childCount() > 0: + parents.append(parents[-1].child(parents[-1].childCount() - 1)) + indentations.append(position) + + else: + while position < indentations[-1] and len(parents) > 0: + parents.pop() + indentations.pop() + + # Append a new item to the current parent's list of children. + parents[-1].appendChild(TreeItem(columnData, parents[-1])) + + number += 1 + + + +def except_hook(cls, exception, traceback): + sys.__excepthook__(cls, exception, traceback) + + +if __name__ == '__main__': + + import sys + + sys.excepthook = except_hook + + app = QApplication(sys.argv) + + f = QFile('default.txt') + f.open(QIODevice.ReadOnly) + model = TreeModel(f.readAll()) + f.close() + + view = QTreeView() + view.setModel(model) + view.setWindowTitle("Simple Tree Model") + view.show() + sys.exit(app.exec_()) \ No newline at end of file