Example #1
0
    def __init__(self, parent=None):
        super(RadarScenesPanel, self).__init__(" Scenes", parent)
        self.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea | QtCore.Qt.RightDockWidgetArea)
        containerWidget = QtGui.QWidget(self)
        self.form = radarSelectSceneForm.Ui_Form()
        self.form.setupUi(containerWidget)
        self.setWidget(containerWidget)
        self.setWidget(containerWidget)
        self.radarDbHandle = MongoSceneHandle()
        self.radarDbHandle.getScenes()

        self._model = SceneFilterProxyMode(self)
        self._model.setSourceModel(RadarScenesTableModel(self))
        self.form.tableView_radarScenes.setModel(self._model)
        self.form.tableView_radarScenes.resizeColumnsToContents()
        self._model.setFilterKeyColumn(self.sourceModel.columns.index('name'))
        self.form.lineEdit_filter.textChanged.connect(self._model.setFilterRegExp)

        self.form.tableView_radarScenes.customContextMenuRequested.connect(self.showRMBMenu)
        self.form.checkBox.toggled.connect(self._model.setShowOnlyMySubscriptions)

        # hide columns we are not interested in sorting or displaying
        for cIndex in self._model.sourceModel().hiddenColumns:
            self.form.tableView_radarScenes.setColumnHidden(cIndex, True)

        # connect signals
        self.form.pushButton_new.clicked.connect(self._model.sourceModel().addNewRadar)
        self.form.tableView_radarScenes.doubleClicked.connect(self.radarDoubleClicked)

        self.createActions()
        self.createMenus()
Example #2
0
 def inviteUser(self):
     radar = self.radarFromSelected()
     text, state = QtGui.QInputDialog.getText(self, 'Invite User', "User name:")
     if state:
         scene = MongoSceneHandle(radar)
         scene.addSubscription(text)
Example #3
0
class RadarScenesPanel(QtGui.QDockWidget):

    radarSelectionChanged = Signal(dict)
    radarSceneDeleted = Signal(str)

    def __init__(self, parent=None):
        super(RadarScenesPanel, self).__init__(" Scenes", parent)
        self.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea | QtCore.Qt.RightDockWidgetArea)
        containerWidget = QtGui.QWidget(self)
        self.form = radarSelectSceneForm.Ui_Form()
        self.form.setupUi(containerWidget)
        self.setWidget(containerWidget)
        self.setWidget(containerWidget)
        self.radarDbHandle = MongoSceneHandle()
        self.radarDbHandle.getScenes()

        self._model = SceneFilterProxyMode(self)
        self._model.setSourceModel(RadarScenesTableModel(self))
        self.form.tableView_radarScenes.setModel(self._model)
        self.form.tableView_radarScenes.resizeColumnsToContents()
        self._model.setFilterKeyColumn(self.sourceModel.columns.index('name'))
        self.form.lineEdit_filter.textChanged.connect(self._model.setFilterRegExp)

        self.form.tableView_radarScenes.customContextMenuRequested.connect(self.showRMBMenu)
        self.form.checkBox.toggled.connect(self._model.setShowOnlyMySubscriptions)

        # hide columns we are not interested in sorting or displaying
        for cIndex in self._model.sourceModel().hiddenColumns:
            self.form.tableView_radarScenes.setColumnHidden(cIndex, True)

        # connect signals
        self.form.pushButton_new.clicked.connect(self._model.sourceModel().addNewRadar)
        self.form.tableView_radarScenes.doubleClicked.connect(self.radarDoubleClicked)

        self.createActions()
        self.createMenus()

    @property
    def sourceModel(self):
        return self._model.sourceModel()

    def getSourceModel(self):
        return self._model.sourceModel()

    def createMenus(self):
        self.rmbMenu = QtGui.QMenu()
        self.rmbMenu.addAction(self.deleteRadarAction)
        self.rmbMenu.addAction(self.inviteUserAction)

    def createActions(self):
        self.deleteRadarAction = QtGui.QAction(self.tr("Delete Scene"), self)
        self.deleteRadarAction.setStatusTip(self.tr("Delete a Radar Scene"))
        self.deleteRadarAction.triggered.connect(self.doSceneDelete)

        self.inviteUserAction = QtGui.QAction(self.tr("Invite User"), self)
        self.inviteUserAction.setStatusTip(self.tr("Invite a user by username to the scene"))
        self.inviteUserAction.triggered.connect(self.inviteUser)

    def inviteUser(self):
        radar = self.radarFromSelected()
        text, state = QtGui.QInputDialog.getText(self, 'Invite User', "User name:")
        if state:
            scene = MongoSceneHandle(radar)
            scene.addSubscription(text)

    def doSceneDelete(self):
        radar = self.radarFromSelected()
        result = QtGui.QMessageBox.warning(self, "Delete Radar Scene",
                        "Are you sure you want to delete {}".format(radar["name"]),
                        QtGui.QMessageBox.Ok, QtGui.QMessageBox.Cancel)
        if result == QtGui.QMessageBox.Ok:
            idx = radar["_id"]
            self._model.sourceModel().deleteRadar(idx)
            self.radarSceneDeleted.emit(idx)

    def selectedToSource(self):
        modelIndex = self.form.tableView_radarScenes.selectionModel().selectedIndexes()[0]
        sourceIndex = self._model.mapToSource(modelIndex)
        sourceModel = self._model.sourceModel()
        return sourceModel, sourceIndex

    def radarFromSelected(self):
        sourceModel, sourceIndex = self.selectedToSource()
        radar = sourceModel.radarFromRow(sourceIndex.row())
        return radar

    def showRMBMenu(self, position):
        self.rmbMenu.move(self.form.tableView_radarScenes.mapToGlobal(position))
        self.rmbMenu.show()

    def radarDoubleClicked(self, index):
        modelIndex = self._model.mapToSource(index)
        row = modelIndex.row()
        data = self._model.sourceModel().radarFromRow(row)
        self.radarSelectionChanged.emit(data)