Пример #1
0
    def startDrag(self, supportedActions):

        item = self.currentIndex()

        itemData = QtCore.QByteArray()
        dataStream = QtCore.QDataStream(itemData, QtCore.QIODevice.WriteOnly)
        pixmap = QtGui.QPixmap(":/icons/ccmime.png")

        l = self.model().datapool.keys()
        l.sort()
        name = l[item.row()]

        dataStream.writeSting(name)

        mimeData = QtCore.QMimeData()
        mimeData.setData("openalea/data_instance", itemData)

        linecode = cli.get_datapool_code(name)
        mimeData.setText(linecode)

        drag = QtGui.QDrag(self)
        drag.setMimeData(mimeData)
        drag.setHotSpot(QtCore.QPoint(pixmap.width()/2, pixmap.height()/2))
        drag.setPixmap(pixmap)

        drag.start(QtCore.Qt.MoveAction)
Пример #2
0
 def draw(self):
     if self.isEnabled():
         self.setBackgroundColor(self.defaultColor)
     else:
         self.setBackgroundColor(QtGui.QColor(150, 150, 150))
     self.start = self.pointOnEditionPlane(
         QtCore.QPoint(0,
                       self.height() - 1))
     self.end = self.pointOnEditionPlane(QtCore.QPoint(self.width() - 1, 0))
     self.sphere.radius = (self.end[0] - self.start[0]) / 80
     self.discretizer.clear()
     self.curveshape.apply(self.renderer)
     glColor4f(0.5, 0.5, 0.0, 0.0)
     self.curveshape.apply(self.ctrlrenderer)
     self.ctrlpts.apply(self.renderer)
     self.drawGrid()
Пример #3
0
 def draw(self):
     if self.isEnabled():
         if self.bgimage == False:
             self.setBackgroundColor(self.defaultColor)
         else:
             self.drawBackground()
     else:
         self.setBackgroundColor(self.disabledBGColor)
     self.start = self.pointOnEditionPlane(QtCore.QPoint(0,self.height()-1))
     self.end = self.pointOnEditionPlane(QtCore.QPoint(self.width()-1,0))
     self.sphere.radius = (self.end[0]-self.start[0])/80
     self.discretizer.clear()
     self.curveshape.apply(self.renderer)
     try:    glColor4fv(self.ctrlCurveColor)
     except: pass
     self.curveshape.apply(self.ctrlrenderer)
     self.ctrlpts.apply(self.renderer)
     self.drawGrid()
Пример #4
0
    def startDrag(self, supportedActions):
        index = self.getIndex()
        item = self.getItem()
        data = self._model.projectdata(index)
        if data is None:
            return
        category, name = data
        # Check item in src
        # TODO move this part in dragEnterEvent with mimetype
        obj = self._model._project.get(category, name)
        if category in ['src', 'model']:
            # Read file and parse model to get inputs, outputs, doc that may be
            # useful once dropped.
            obj.read()
            text = item.text()

            # name_without_ext = ".".join(text.split(".")[:-1])
            name_without_ext = text
            name_without_space = "_".join(name_without_ext.split())
            for sym in ["-", "+", "*", "/", "\"", "."]:
                name_without_space = "_".join(name_without_space.split(sym))

            python_call_string = '%s = Model("%s")' % (name_without_space,
                                                       name_without_ext)
            icon = item.icon()
            pixmap = icon.pixmap(20, 20)

            itemData = QtCore.QByteArray()
            dataStream = QtCore.QDataStream(itemData,
                                            QtCore.QIODevice.WriteOnly)
            model_id = name_without_ext
            dataStream.writeString(str(python_call_string))
            dataStream.writeString(str(model_id))

            mimeData = QtCore.QMimeData()
            mimeData.setText(python_call_string)
            mimeData.setData("openalealab/model", itemData)

            drag = QtGui.QDrag(self)
            drag.setMimeData(mimeData)
            drag.setHotSpot(
                QtCore.QPoint(pixmap.width() / 2,
                              pixmap.height() / 2))
            drag.setPixmap(pixmap)

            drag.start(QtCore.Qt.CopyAction)

        elif category == 'data':
            p = '%s/%r' % (category, str(obj.filename))
            mimetype, mimedata = encode(obj, mimetype='openalealab/data')
            qmime_data = QtCore.QMimeData()
            qmime_data.setData(mimetype, mimedata)
            qmime_data.setText(p)
            drag = QtGui.QDrag(self)
            drag.setMimeData(qmime_data)
            drag.start()
Пример #5
0
    def paintEvent(self, event):
        painter = QtGui.QStylePainter(self)

        # ticks
        opt = QtGui.QStyleOptionSlider()
        self.initStyleOption(opt)
        # opt.subControls = QtGui.QStyle.SC_SliderTickmarks
        painter.drawComplexControl(QtGui.QStyle.CC_Slider, opt)

        # groove
        opt.sliderPosition = 20
        opt.sliderValue = 0
        opt.subControls = QtGui.QStyle.SC_SliderGroove
        painter.drawComplexControl(QtGui.QStyle.CC_Slider, opt)

        # handle rects
        opt.sliderPosition = self.lowerPos
        lr = self.style().subControlRect(QtGui.QStyle.CC_Slider, opt, QtGui.QStyle.SC_SliderHandle, self)
        lrv = self.pick(lr.center())
        opt.sliderPosition = self.upperPos
        ur = self.style().subControlRect(QtGui.QStyle.CC_Slider, opt, QtGui.QStyle.SC_SliderHandle, self)
        urv = self.pick(ur.center())

        # span
        minv = min(lrv, urv)
        maxv = max(lrv, urv)
        c = self.style().subControlRect(QtGui.QStyle.CC_Slider, opt, QtGui.QStyle.SC_SliderGroove, self).center()
        spanRect = QtCore.QRect(QtCore.QPoint(c.x() - 2, minv), QtCore.QPoint(c.x() + 1, maxv))
        if self.orientation() == QtCore.Qt.Horizontal:
            spanRect = QtCore.QRect(QtCore.QPoint(minv, c.y() - 2), QtCore.QPoint(maxv, c.y() + 1))
        self.drawSpan(painter, spanRect)

        # handles
        if self.lastPressed == QSpanSlider.LowerHandle:
            self.drawHandle(painter, QSpanSlider.UpperHandle)
            self.drawHandle(painter, QSpanSlider.LowerHandle)
        else:
            self.drawHandle(painter, QSpanSlider.LowerHandle)
            self.drawHandle(painter, QSpanSlider.UpperHandle)
Пример #6
0
 def paintEvent(self, paintEvent):
     if self.showLines:
         maxheight = self.editor.viewport().height()
         maxline = self.editor.document().blockCount()
         painter = QtGui.QPainter(self)
         painter.setPen(QtGui.QPen(QtGui.QColor(100, 100, 100)))
         h = 0
         line = -1
         while h < maxheight and line < maxline:
             cursor = self.editor.cursorForPosition(QtCore.QPoint(1, h))
             nline = cursor.blockNumber() + 1
             rect = self.editor.cursorRect(cursor)
             if nline > line:
                 line = nline
                 painter.drawText(
                     0,
                     rect.top() + 2, 40,
                     rect.height() + 2,
                     QtCore.Qt.AlignHCenter | QtCore.Qt.AlignTop, str(line))
             h = rect.top() + rect.height() + 1
         painter.end()