Beispiel #1
0
 def createContextMenu(self):
     self.menu = QMenu("Scalar Edit", self)
     self.menu.addAction("New Integer", self.newScalar)
     self.menu.addAction("New Float", self.newFloatScalar)
     self.menu.addAction("New Boolean", self.newBoolScalar)
     self.menu.addSeparator()
     self.menu.addAction("New Category", self.newCategoryScalar)
     self.menu.addSeparator()
     self.deleteAction = self.menu.addAction("Delete", self.deleteScalars)
     self.editAction = self.menu.addAction("Edit", self.editMetaScalar)
Beispiel #2
0
 def contextMenuEvent(self, event):
     self.menuselection = self.selectedColor(event.x(), event.y())
     if self.lenSelection() > 0:
         if not self.isInSelection(self.menuselection):
             self.setSelection(self.menuselection)
             self.updateGL()
     else:
         self.setSelection(self.menuselection)
         self.updateGL()
     menu = QMenu("Color Edit", self)
     menu.addAction("Copy", self.copymaterial)
     menu.addAction("Cut", self.cutmaterial)
     action = menu.addAction("Paste", self.pastematerial)
     if self.clipboard is None:
         action.setEnabled(False)
     action = menu.addAction("Load texture", self.loadtexture)
     if self.lenSelection() > 1:
         action.setEnabled(False)
     if self.lenSelection() == 1 and self.getMaterial(
             self.getSelection()[0]).isTexture():
         menu.addAction("Open repository", self.opentexturerepository)
     menu.addAction("Remove", self.removematerial)
     action = menu.addAction("Interpolate", self.interpolatematerial)
     if self.lenSelection() < 3:
         action.setEnabled(False)
     menu.exec_(event.globalPos())
Beispiel #3
0
class ScalarEditor(QTreeView):
    valueChanged = pyqtSignal()
    itemValueChanged = pyqtSignal('PyQt_PyObject')

    def __init__(self, parent):
        QTreeView.__init__(self, parent)
        self.scalars = []
        self.scalarmap = {}
        self.initTable()
        self.scalarDelegate = ScalarEditorDelegate(self)
        self.setItemDelegateForColumn(1, self.scalarDelegate)
        self.createContextMenu()
        self.metaIntEdit = ScalarDialog(self)
        self.metaFloatEdit = FloatScalarDialog(self)
        self.setItemsExpandable(False)
        self.setIndentation(0)

    def initTable(self):
        self.scalarModel = MyItemModel(0, 1, self.scalarmap)
        self.scalarModel.itemChanged.connect(
            self.internalItemChanged
        )  # QObject.connect(self.scalarModel,SIGNAL('itemChanged(QStandardItem*)'),self.internalItemChanged)
        self.scalarModel.moveRequest.connect(
            self.moveItem
        )  # QObject.connect(self.scalarModel,SIGNAL('moveRequest(int,int)'),self.moveItem)
        self.scalarModel.setHorizontalHeaderLabels(["Parameter", "Value"])
        self.setModel(self.scalarModel)

    def contextMenuEvent(self, event):
        items = self.selection()
        self.deleteAction.setEnabled(len(items) > 0)
        self.editAction.setEnabled(
            len(items) == 1 and not (self.scalars[items[0]].isCategory()
                                     or self.scalars[items[0]].isBool()))
        self.menu.exec_(event.globalPos())

    def createContextMenu(self):
        self.menu = QMenu("Scalar Edit", self)
        self.menu.addAction("New Integer", self.newScalar)
        self.menu.addAction("New Float", self.newFloatScalar)
        self.menu.addAction("New Boolean", self.newBoolScalar)
        self.menu.addSeparator()
        self.menu.addAction("New Category", self.newCategoryScalar)
        self.menu.addSeparator()
        self.deleteAction = self.menu.addAction("Delete", self.deleteScalars)
        self.editAction = self.menu.addAction("Edit", self.editMetaScalar)

    def selection(self):
        items = list(set([i.row() for i in self.selectedIndexes()]))
        items.sort(key=lambda x: -x)
        return items

    def deleteScalars(self):
        for i in self.selection():
            self.scalarModel.removeRow(i)
            del self.scalars[i]
        self.valueChanged.emit()

    def editMetaScalar(self):
        item = self.selection()[0]
        v = self.scalars[item]
        sc = self.visualEditMetaScalar(v)
        if sc and v != sc:
            v.importValue(sc)
            v.si_name.setText(v.name)
            v.si_value.setText(str(v.value))
            self.itemValueChanged.emit(
                v
            )  # self.emit(SIGNAL('itemValueChanged(PyQt_PyObject)'),v) # AUTO SIGNAL TRANSLATION
            self.valueChanged.emit()

    def visualEditMetaScalar(self, scalar):
        metaEdit = self.metaIntEdit
        if scalar.isFloat():
            metaEdit = self.metaFloatEdit
        metaEdit.setScalar(scalar)
        res = metaEdit.exec_()
        if res: return metaEdit.getScalar()

    def getItems(self, scalar):
        si_name = QStandardItem(scalar.name)
        si_name.setEditable(True)
        #si_name.setData(scalar)
        si_name.scalar = scalar
        si_name.nameEditor = True
        if scalar.isCategory():
            b = QBrush(QColor(255, 255, 255))
            si_name.setForeground(b)
            b = QBrush(QColor(0, 0, 0))
            si_name.setBackground(b)
            return [si_name]
            si_value = QStandardItem()
            si_value.setEditable(False)
            si_value.setBackground(b)
        elif scalar.isBool():
            si_value = QStandardItem()
            si_value.setCheckable(True)
            si_value.setCheckState(
                Qt.Checked if scalar.value else Qt.Unchecked)
            si_value.stdEditor = True
        else:
            si_value = QStandardItem(str(scalar.value))
        si_value.scalar = scalar
        scalar.si_name = si_name
        scalar.si_value = si_value
        self.scalarmap[scalar.name] = (scalar, si_name, si_value)
        return [si_name, si_value]

    def newScalar(self):
        s = self.visualEditMetaScalar(IntegerScalar('default_scalar'))
        if s:
            self.scalars.append(s)
            self.scalarModel.appendRow(self.getItems(s))
            self.internalValueChanged(s)

    def newFloatScalar(self):
        s = self.visualEditMetaScalar(FloatScalar('default_scalar'))
        if s:
            self.scalars.append(s)
            self.scalarModel.appendRow(self.getItems(s))
            self.internalValueChanged(s)

    def newBoolScalar(self):
        s = BoolScalar('default_bool', True)
        self.scalars.append(s)
        self.scalarModel.appendRow(self.getItems(s))
        self.internalValueChanged(s)

    def newCategoryScalar(self):
        s = CategoryScalar('new category')
        self.scalars.append(s)
        ri = self.scalarModel.indexFromItem(
            self.scalarModel.invisibleRootItem())
        self.scalarModel.appendRow(self.getItems(s))
        self.setFirstColumnSpanned(len(self.scalars) - 1, ri, True)
        self.internalValueChanged(s)

    def setScalars(self, values):
        self.scalars = values
        self.replotScalars()

    def getScalars(self):
        return self.scalars

    def replotScalars(self):
        self.initTable()
        ri = self.scalarModel.indexFromItem(
            self.scalarModel.invisibleRootItem())
        for i, sc in enumerate(self.scalars):
            self.scalarModel.appendRow(self.getItems(sc))
            if sc.isCategory():
                self.setFirstColumnSpanned(i, ri, True)

    def internalValueChanged(self, scalar):
        self.itemValueChanged.emit(
            scalar
        )  # self.emit(SIGNAL('itemValueChanged(PyQt_PyObject)'),scalar) # AUTO SIGNAL TRANSLATION
        self.valueChanged.emit()

    def internalItemChanged(self, item):
        if hasattr(item, 'nameEditor'):
            item.scalar.name = str(item.text())
            self.valueChanged.emit()
        elif hasattr(item, 'stdEditor'):
            item.scalar.value = item.checkState() == Qt.Checked
            self.valueChanged.emit()

    def moveItem(self, r0, r1):
        item = self.scalars.pop(r0)
        if r1 == -1:
            self.scalars.append(item)
        else:
            self.scalars.insert(r1, item)
        self.replotScalars()
        self.valueChanged.emit()
Beispiel #4
0
 def contextMenuEvent(self,event):
     self.selection = self.tabAt(event.pos())
     if self.selection != -1:
         menu = QMenu(self)
         action = menu.addAction('Close')
         action.triggered.connect(self.close)
         action = menu.addAction('Close all except this ')
         action.triggered.connect(self.closeAllExcept)
         menu.addSeparator()
         if self.lpystudio.simulations[self.selection].readonly:
             action = menu.addAction('Remove Readonly ')
             action.triggered.connect(self.removeReadOnly)
         else:
             action = menu.addAction('Set Readonly ')
             action.triggered.connect(self.setReadOnly)
         menu.addSeparator()
         action = menu.addAction('Copy filename ')
         action.triggered.connect(self.copyFilename)
         action = menu.addAction('Open folder')
         action.triggered.connect(self.openFolder)
         action = menu.addAction('Open terminal')
         action.triggered.connect(self.openTerminalAtFolder)
         fname = self.lpystudio.simulations[self.selection].fname
         if fname and svnmanip.hasSvnSupport() :
             if svnmanip.isSvnFile(fname):
                 menu.addSeparator()
                 status = svnmanip.svnFileTextStatus(fname)
                 if status != svnmanip.added:
                     action = menu.addAction('SVN Update')
                     action.triggered.connect(self.svnUpdate)
                 if status in  [svnmanip.added,svnmanip.modified]:
                     action = menu.addAction('SVN Commit')
                     action.triggered.connect(self.svnCommit)
                 if status != svnmanip.normal:
                     action = menu.addAction('SVN Revert')
                     action.triggered.connect(self.svnRevert)
                 if status != svnmanip.added:
                     menu.addSeparator()
                     action = menu.addAction('Is Up-to-date ?')
                     action.triggered.connect(self.svnIsUpToDate)
             elif svnmanip.isSvnFile(os.path.dirname(fname)):
                 menu.addSeparator()
                 action = menu.addAction('SVN Add')
                 action.triggered.connect(self.svnAdd)
         menu.exec_(event.globalPos())