mirror of
https://github.com/CopterExpress/clever-show.git
synced 2026-05-26 07:07:58 +00:00
Added context menu with config dialog!
Tested and working for now
This commit is contained in:
@@ -746,6 +746,19 @@ class ConfigDialog(QtWidgets.QDialog):
|
||||
else:
|
||||
return True
|
||||
|
||||
def call_copter_dialog(self, client, value):
|
||||
config_dict, spec_dict = value["config"], value["configspec"]
|
||||
cfg = config.ConfigManager()
|
||||
cfg.load_from_dict(config_dict, spec_dict)
|
||||
|
||||
self.setupModel(config_dict)
|
||||
if not self.validation_loop(cfg, spec_dict):
|
||||
return False
|
||||
|
||||
edited_dict = self.model.to_config_dict()
|
||||
client.send_message("config", {"config": edited_dict, "mode": "rewrite"})
|
||||
return True
|
||||
|
||||
def call_standalone_dialog(self):
|
||||
path = QFileDialog.getOpenFileName(self, "Select configuration or specification file",
|
||||
filter="Config and spec files (*.ini)")[0]
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from functools import partial
|
||||
|
||||
from PyQt5 import QtWidgets, QtCore, QtGui
|
||||
from PyQt5.QtCore import Qt as Qt
|
||||
from PyQt5.QtCore import pyqtSlot
|
||||
@@ -5,13 +7,17 @@ from PyQt5.QtGui import QCursor
|
||||
from PyQt5.QtWidgets import QTableView, QMessageBox, QMenu, QAction, QWidgetAction, QListWidget, \
|
||||
QAbstractItemView, QListWidgetItem
|
||||
|
||||
from config_editor_models import ConfigDialog
|
||||
import copter_table_models as table
|
||||
|
||||
|
||||
class CopterTableWidget(QTableView):
|
||||
def __init__(self, model, data_model=table.StatedCopterData):
|
||||
config_dialog_signal = QtCore.pyqtSignal(object, object)
|
||||
|
||||
def __init__(self, model, window, data_model=table.StatedCopterData):
|
||||
QTableView.__init__(self)
|
||||
|
||||
self._window = window
|
||||
self.model = model
|
||||
self._data_model = data_model
|
||||
|
||||
@@ -29,6 +35,10 @@ class CopterTableWidget(QTableView):
|
||||
header.setContextMenuPolicy(Qt.CustomContextMenu)
|
||||
header.customContextMenuRequested.connect(self.showHeaderMenu)
|
||||
|
||||
self.setContextMenuPolicy(Qt.CustomContextMenu)
|
||||
self.customContextMenuRequested.connect(self.open_menu)
|
||||
|
||||
self.signal_connection = None
|
||||
# self.horizontalHeader().contextMenuEvent = self.headercontextMenuEvent
|
||||
|
||||
# Adjust properties
|
||||
@@ -74,11 +84,30 @@ class CopterTableWidget(QTableView):
|
||||
menu.addAction(action)
|
||||
menu.exec_(QCursor.pos())
|
||||
|
||||
def contextMenuEvent(self, event):
|
||||
@pyqtSlot(QtCore.QPoint)
|
||||
def open_menu(self, point):
|
||||
menu = QMenu(self)
|
||||
index = self.indexAt(point)
|
||||
item = self.model.get_row_data(index)
|
||||
# print(item, index.row(), index.column())
|
||||
|
||||
menu.addAction("action")
|
||||
# menu.exec_(QCursor.pos())
|
||||
edit_config = QAction("Edit config")
|
||||
edit_config.triggered.connect(partial(self.edit_config, item))
|
||||
menu.addAction(edit_config)
|
||||
|
||||
if item is None:
|
||||
edit_config.setDisabled(True)
|
||||
|
||||
menu.exec_(QCursor.pos())
|
||||
|
||||
@pyqtSlot()
|
||||
def edit_config(self, copter):
|
||||
if self.signal_connection is not None:
|
||||
self.config_dialog_signal.disconnect(self.signal_connection)
|
||||
|
||||
call = ConfigDialog(self._window).call_copter_dialog
|
||||
self.signal_connection = self.config_dialog_signal.connect(call)
|
||||
copter.client.get_response("config", self.config_dialog_signal.emit)
|
||||
|
||||
# def _selfcheck_shortener(self, data): # TODO!!!
|
||||
# shortened = []
|
||||
|
||||
@@ -422,6 +422,17 @@ class CopterDataModel(QtCore.QAbstractTableModel):
|
||||
contents = contents or self.data_contents
|
||||
return filter(calibration_ready_check, contents)
|
||||
|
||||
def get_row_data(self, index):
|
||||
row = index.row()
|
||||
if row == -1:
|
||||
return None
|
||||
try:
|
||||
data = self.data_contents[row]
|
||||
except IndexError:
|
||||
return None
|
||||
else:
|
||||
return data
|
||||
|
||||
def get_row_index(self, row_data):
|
||||
try:
|
||||
index = self.data_contents.index(row_data)
|
||||
|
||||
Reference in New Issue
Block a user