mirror of
https://github.com/CopterExpress/clever-show.git
synced 2026-05-26 23:19:33 +00:00
WIP
This commit is contained in:
60
Server/config_editor.py
Normal file
60
Server/config_editor.py
Normal file
@@ -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_())
|
||||
97
Server/config_editor.ui
Normal file
97
Server/config_editor.ui
Normal file
@@ -0,0 +1,97 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Dialog</class>
|
||||
<widget class="QDialog" name="Dialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>268</width>
|
||||
<height>247</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Config Editor</string>
|
||||
</property>
|
||||
<property name="modal">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTreeView" name="treeView"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>Delete</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Del</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="checkBox">
|
||||
<property name="text">
|
||||
<string>Restart</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>R</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set>
|
||||
</property>
|
||||
<property name="centerButtons">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>260</x>
|
||||
<y>237</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>246</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>260</x>
|
||||
<y>239</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>267</x>
|
||||
<y>246</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
113
Server/config_editor_models.py
Normal file
113
Server/config_editor_models.py
Normal file
@@ -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_())
|
||||
@@ -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()
|
||||
|
||||
41
Server/default.txt
Normal file
41
Server/default.txt
Normal file
@@ -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
|
||||
174
Server/test.py
Normal file
174
Server/test.py
Normal file
@@ -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_())
|
||||
Reference in New Issue
Block a user