当前位置: 首页>>代码示例>>Python>>正文


Python sip.cast函数代码示例

本文整理汇总了Python中sip.cast函数的典型用法代码示例。如果您正苦于以下问题:Python cast函数的具体用法?Python cast怎么用?Python cast使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了cast函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: layout_item

def layout_item(layout, item_id, item_class):
    """Fetch a specific item according to its type in a layout.

    There's some sip casting conversion issues with QgsLayout::itemById.
    Don't use it, and use this function instead.
    See https://github.com/inasafe/inasafe/issues/4271

    :param layout: The layout to look in.
    :type layout: QgsLayout

    :param item_id: The ID of the item to look for.
    :type item_id: basestring

    :param item_class: The expected class name.
    :type item_class: cls

    :return: The layout item, inherited class of QgsLayoutItem.
    """
    item = layout.itemById(item_id)
    if item is None:
        # no match!
        return item

    if issubclass(item_class, QgsLayoutMultiFrame):
        # finding a multiframe by frame id
        frame = sip.cast(item, QgsLayoutFrame)
        multi_frame = frame.multiFrame()
        return sip.cast(multi_frame, item_class)
    else:
        # force sip to correctly cast item to required type
        return sip.cast(item, item_class)
开发者ID:inasafe,项目名称:inasafe,代码行数:31,代码来源:default.py

示例2: gradient_darker

def gradient_darker(grad, factor):
    """Return a copy of the QGradient darkened by factor.

    .. note:: Only QLinearGradeint and QRadialGradient are supported.

    """
    if type(grad) is QGradient:
        if grad.type() == QGradient.LinearGradient:
            grad = sip.cast(grad, QLinearGradient)
        elif grad.type() == QGradient.RadialGradient:
            grad = sip.cast(grad, QRadialGradient)

    if isinstance(grad, QLinearGradient):
        new_grad = QLinearGradient(grad.start(), grad.finalStop())
    elif isinstance(grad, QRadialGradient):
        new_grad = QRadialGradient(grad.center(), grad.radius(),
                                   grad.focalPoint())
    else:
        raise TypeError

    new_grad.setCoordinateMode(grad.coordinateMode())

    for pos, color in grad.stops():
        new_grad.setColorAt(pos, color.darker(factor))

    return new_grad
开发者ID:RachitKansal,项目名称:orange3,代码行数:26,代码来源:utils.py

示例3: QGraphicsItem_itemChange

 def QGraphicsItem_itemChange(self, change, value):
     if change in changeset:
         if isinstance(value, QGraphicsItem):
             value = sip.cast(value, QGraphicsItem)
         rval = QGraphicsItem_itemChange_old(self, change, value)
         if isinstance(rval, QGraphicsItem):
             rval = sip.cast(rval, QGraphicsItem)
         return rval
     else:
         return QGraphicsItem_itemChange_old(self, change, value)
开发者ID:ales-erjavec,项目名称:anyqt,代码行数:10,代码来源:_fixes.py

示例4: __init__

    def __init__(self, _model, parent):
        """
        Connect to all of the models signals, Whenever anything happens recheck everything.
        """
        QtCore.QObject.__init__(self,parent)
        self._model = _model
        self.model = sip.cast(_model, QtCore.QAbstractItemModel)
        self.insert = []
        self.remove = []
        self.fetchingMore = False
        assert(self.model)

        self.connect( self.model, QtCore.SIGNAL("columnsAboutToBeInserted(const QModelIndex&, int, int)"), self.runAllTests)
        self.connect( self.model, QtCore.SIGNAL("columnsAboutToBeRemoved(const QModelIndex&, int, int)"), self.runAllTests)
        self.connect( self.model, QtCore.SIGNAL("columnsBeInserted(const QModelIndex&, int, int)"), self.runAllTests)
        self.connect( self.model, QtCore.SIGNAL("columnsRemoved(const QModelIndex&, int, int)"), self.runAllTests)
        self.connect( self.model, QtCore.SIGNAL("dataChanged(const QModelIndex&, const QModelIndex&)"), self.runAllTests)
        self.connect( self.model, QtCore.SIGNAL("headerDataChanged(Qt::Orientation, int, int)"), self.runAllTests)
        self.connect( self.model, QtCore.SIGNAL("layoutAboutToBeChanged()"), self.runAllTests)
        self.connect( self.model, QtCore.SIGNAL("layoutChanged()"), self.runAllTests)
        self.connect( self.model, QtCore.SIGNAL("modelReset()"), self.runAllTests)
        self.connect( self.model, QtCore.SIGNAL("rowsAboutToBeInserted(const QModelIndex&, int, int)"), self.runAllTests)
        self.connect( self.model, QtCore.SIGNAL("rowsAboutToBeRemoved(const QModelIndex&, int, int)"), self.runAllTests)
        self.connect( self.model, QtCore.SIGNAL("rowsBeInserted(const QModelIndex&, int, int)"), self.runAllTests)
        self.connect( self.model, QtCore.SIGNAL("rowsRemoved(const QModelIndex&, int, int)"), self.runAllTests)

        # Special checks for inserting/removing
        self.connect( self.model, QtCore.SIGNAL("rowsAboutToBeInserted(const QModelIndex&, int, int)"), self.rowsAboutToBeInserted)
        self.connect( self.model, QtCore.SIGNAL("rowsAboutToBeRemoved(const QModelIndex&, int, int)"), self.rowsAboutToBeRemoved)
        self.connect( self.model, QtCore.SIGNAL("rowsBeInserted(const QModelIndex&, int, int)"), self.rowsInserted)
        self.connect( self.model, QtCore.SIGNAL("rowsRemoved(const QModelIndex&, int, int)"), self.rowsRemoved)
        self.runAllTests()
开发者ID:velorientc,项目名称:git_test7,代码行数:32,代码来源:modeltest.py

示例5: itemChange

    def itemChange(self, change, value):
        if change == QtGui.QGraphicsItem.ItemPositionChange and self.scene():

            # If Left mouse + alt is pressed then don't snap
            button = QtGui.QApplication.mouseButtons() == QtCore.Qt.LeftButton
            modifier = QtGui.QApplication.keyboardModifiers() == QtCore.Qt.AltModifier

            if button and modifier:
                self.position_changed.emit(value)
                return super(CoordinateSnapMixin, self).itemChange(change, value)

            # Get all items under the mouse
            # TODO: Use try instead of isinstance
            # TODO: Add priority
            # TODO: Use childItems
            items = [x for x in self.scene().items(value) if isinstance(x, SnapsCoordinates) and x.parentItem() is not self]

            for item in items:
                value = item.snap_coordinate(value)

            self.position_changed.emit(value)

        # itemChange and setParentItem causes error in PyQt4
        # TODO: Test with PySide and PyQt5
        # See http://www.riverbankcomputing.com/pipermail/pyqt/2012-August/031818.html
        result =  super(CoordinateSnapMixin, self).itemChange(change, value)
        if isinstance(result, QtGui.QGraphicsItem):
            result = sip.cast(result, QtGui.QGraphicsItem)
        return result
开发者ID:chrisbura,项目名称:pythoncad-qt,代码行数:29,代码来源:scene_item.py

示例6: __init__

    def __init__(self, _model, verbose=True, parent=None):
        """
        Connect to all of the models signals, Whenever anything happens recheck everything.
        """
        QtCore.QObject.__init__(self,parent)
        self._model = _model
        self.model = sip.cast(_model, QtCore.QAbstractItemModel)
        self.insert = []
        self.remove = []
        self.fetchingMore = False
        self._verbose = verbose
        assert(self.model)

        self.model.columnsAboutToBeInserted.connect(self.runAllTests)
        self.model.columnsAboutToBeRemoved.connect(self.runAllTests)
        self.model.columnsInserted.connect(self.runAllTests)
        self.model.columnsRemoved.connect(self.runAllTests)
        self.model.dataChanged.connect(self.runAllTests)
        self.model.headerDataChanged.connect(self.runAllTests)
        self.model.layoutAboutToBeChanged.connect(self.runAllTests)
        self.model.layoutChanged.connect(self.runAllTests)
        self.model.modelReset.connect(self.runAllTests)
        self.model.rowsAboutToBeInserted.connect(self.runAllTests)
        self.model.rowsAboutToBeRemoved.connect(self.runAllTests)
        self.model.rowsInserted.connect(self.runAllTests)
        self.model.rowsRemoved.connect(self.runAllTests)

        # Special checks for inserting/removing
        self.model.rowsAboutToBeInserted.connect(self.rowsAboutToBeInserted)
        self.model.rowsAboutToBeRemoved.connect(self.rowsAboutToBeRemoved)
        self.model.rowsInserted.connect(self.rowsInserted)
        self.model.rowsRemoved.connect(self.rowsRemoved)
        self.runAllTests()
开发者ID:The-Compiler,项目名称:PyQt5_modeltest,代码行数:33,代码来源:modeltest.py

示例7: supercast

def supercast(obj):
    """
    cast a QObject subclass to the best known wrapped super class
    """
    if not qtclasses:
        # To get really all Qt classes I would have to 
        # import QtNetwork, QtXml, QtSvg and QtScript, too.
        import PyQt4
        qtclasses.update(
            dict([(key, value) \
                for key, value in PyQt4.QtCore.__dict__.items() + PyQt4.QtGui.__dict__.items() \
                if hasattr(value, "__subclasses__") and issubclass(value, QObject)])
        )
    try:
        if not issubclass(value, QObject):
            return obj
    except TypeError: 
        # no class - no cast...
        return obj
    mo = obj.metaObject()
    while mo:
        cls = qtclasses.get(str(mo.className()))
        if cls:
            return sip.cast(obj, cls)
        mo = mo.superClass()
    # This should never be reached
    return obj
开发者ID:Fahad-Alsaidi,项目名称:scribus-svn,代码行数:27,代码来源:mikro.py

示例8: registerObject

 def registerObject(cls, obj):
     """
     Workaround for PyQt bug in qgraphicsscene.items()
     All subclasses of QGraphicsObject must register themselves with this function.
     (otherwise, mouse interaction with those objects will likely fail)
     """
     if HAVE_SIP and isinstance(obj, sip.wrapper):
         cls._addressCache[sip.unwrapinstance(sip.cast(obj, QtGui.QGraphicsItem))] = obj
开发者ID:Rareson,项目名称:LammpsRelated,代码行数:8,代码来源:GraphicsScene.py

示例9: __init__

    def __init__(self, brush, matrix, pdf, pixel_page_width, pixel_page_height):
        self.matrix = (matrix.m11(), matrix.m12(), matrix.m21(), matrix.m22(),
                       matrix.dx(), matrix.dy())
        gradient = sip.cast(brush.gradient(), QLinearGradient)

        start, stop, stops = self.spread_gradient(gradient, pixel_page_width,
                                                  pixel_page_height, matrix)

        # TODO: Handle colors with different opacities
        self.const_opacity = stops[0].color[-1]

        funcs = Array()
        bounds = Array()
        encode = Array()

        for i, current_stop in enumerate(stops):
            if i < len(stops) - 1:
                next_stop = stops[i+1]
                func = Dictionary({
                    'FunctionType': 2,
                    'Domain': Array([0, 1]),
                    'C0': Array(current_stop.color[:3]),
                    'C1': Array(next_stop.color[:3]),
                    'N': 1,
                })
                funcs.append(func)
                encode.extend((0, 1))
                if i+1 < len(stops) - 1:
                    bounds.append(next_stop.t)

        func = Dictionary({
            'FunctionType': 3,
            'Domain': Array([stops[0].t, stops[-1].t]),
            'Functions': funcs,
            'Bounds': bounds,
            'Encode': encode,
        })

        shader = Dictionary({
            'ShadingType': 2,
            'ColorSpace': Name('DeviceRGB'),
            'AntiAlias': True,
            'Coords': Array([start.x(), start.y(), stop.x(), stop.y()]),
            'Function': func,
            'Extend': Array([True, True]),
        })

        Dictionary.__init__(self, {
            'Type': Name('Pattern'),
            'PatternType': 2,
            'Shading': shader,
            'Matrix': Array(self.matrix),
        })

        self.cache_key = (self.__class__.__name__, self.matrix,
                          tuple(shader['Coords']), stops)
开发者ID:AEliu,项目名称:calibre,代码行数:56,代码来源:gradients.py

示例10: testCopyPaste

    def testCopyPaste(self):
        p = QgsProject()
        l = QgsLayout(p)

        # clear clipboard
        mime_data = QMimeData()
        mime_data.setData("text/xml", QByteArray())
        clipboard = QApplication.clipboard()
        clipboard.setMimeData(mime_data)

        # add an item
        item1 = QgsLayoutItemLabel(l)
        item1.setText('label 1')
        l.addLayoutItem(item1)
        item1.setSelected(True)
        item2 = QgsLayoutItemLabel(l)
        item2.setText('label 2')
        l.addLayoutItem(item2)
        item2.setSelected(True)

        view = QgsLayoutView()
        view.setCurrentLayout(l)
        self.assertFalse(view.hasItemsInClipboard())

        view.copySelectedItems(QgsLayoutView.ClipboardCopy)
        self.assertTrue(view.hasItemsInClipboard())

        pasted = view.pasteItems(QgsLayoutView.PasteModeCursor)
        self.assertEqual(len(pasted), 2)
        self.assertIn(pasted[0], l.items())
        self.assertIn(pasted[1], l.items())
        self.assertIn(sip.cast(pasted[0], QgsLayoutItemLabel).text(), ('label 1', 'label 2'))
        self.assertIn(sip.cast(pasted[1], QgsLayoutItemLabel).text(), ('label 1', 'label 2'))

        # copy specific item
        view.copyItems([item2], QgsLayoutView.ClipboardCopy)
        l2 = QgsLayout(p)
        view2 = QgsLayoutView()
        view2.setCurrentLayout(l2)
        pasted = view2.pasteItems(QgsLayoutView.PasteModeCursor)
        self.assertEqual(len(pasted), 1)
        self.assertIn(pasted[0], l2.items())
        self.assertEqual(sip.cast(pasted[0], QgsLayoutItemLabel).text(), 'label 2')
开发者ID:cz172638,项目名称:QGIS,代码行数:43,代码来源:test_qgslayoutview.py

示例11: itemChange

    def itemChange(self, change, value):
        if change == QtGui.QGraphicsItem.ItemPositionHasChanged and self.scene():
            self.parentItem().update()

        # itemChange and setParentItem causes error in PyQt4
        # TODO: Test with PySide and PyQt5
        # See http://www.riverbankcomputing.com/pipermail/pyqt/2012-August/031818.html
        result =  super(SegmentEndPointSceneItem, self).itemChange(change, value)
        if isinstance(result, QtGui.QGraphicsItem):
            result = sip.cast(result, QtGui.QGraphicsItem)
        return result
开发者ID:chrisbura,项目名称:pythoncad-qt,代码行数:11,代码来源:segment_scene_item.py

示例12: itemChange

 def itemChange(self, change, value):
     ret = GraphicsObject.itemChange(self, change, value)
         
     ## workaround for pyqt bug:
     ## http://www.riverbankcomputing.com/pipermail/pyqt/2012-August/031818.html
     if change == self.ItemParentChange and isinstance(ret, QtGui.QGraphicsItem):
         ret = sip.cast(ret, QtGui.QGraphicsItem)
     
     if change == self.ItemScenePositionHasChanged:
         self.setNewBounds()
     return ret
开发者ID:ZhuangER,项目名称:robot_path_planning,代码行数:11,代码来源:UIGraphicsItem.py

示例13: onViewChanged

 def onViewChanged(self):
     try:
       doc = sip.cast(kate.activeDocument(), KateDocument)
     except kate.api.NoActiveView:
       return
   
     self.act.blockSignals(True)
     if doc.property('AutoReload'):
         self.act.setChecked(True)
     else:
         self.act.setChecked(False)
     self.act.blockSignals(False)
开发者ID:LarsBV,项目名称:kate_reload,代码行数:12,代码来源:kate_reload.py

示例14: extension

    def extension(self, extension, info=None, errorPage=None):
        if extension == QWebPage.ErrorPageExtension:
            # catch the error, populate self.errorInfo and return an error page

            info = sip.cast(info, QWebPage.ErrorPageExtensionOption)

            domain = 'Unknown'
            if info.domain == QWebPage.QtNetwork:
                domain = 'Network'
            elif info.domain == QWebPage.Http:
                domain = 'HTTP'
            elif info.domain == QWebPage.WebKit:
                domain = 'WebKit'

            self.error_info = RenderErrorInfo(
                domain,
                int(info.error),
                unicode(info.errorString),
                unicode(info.url.toString())
            )

            # XXX: this page currently goes nowhere
            content = u"""
                <html><head><title>Failed loading page</title></head>
                <body>
                    <h1>Failed loading page ({0.text})</h1>
                    <h2>{0.url}</h2>
                    <p>{0.type} error #{0.code}</p>
                </body></html>""".format(self.error_info)

            errorPage = sip.cast(errorPage, QWebPage.ErrorPageExtensionReturn)
            errorPage.content = QByteArray(content.encode('utf-8'))
            return True

        # XXX: this method always returns True, even if we haven't
        # handled the extension. Is it correct? When can this method be
        # called with extension which is not ErrorPageExtension if we
        # are returning False in ``supportsExtension`` for such extensions?
        return True
开发者ID:brandontheis,项目名称:splash,代码行数:39,代码来源:qwebpage.py

示例15: pageTitleChanged

 def pageTitleChanged(self, title):
     widget = self.sender()
     if widget and isinstance(widget, PyMultiPageWidget):
         page = widget.widget(widget.getCurrentIndex())
         form = QtDesigner.QDesignerFormWindowInterface.findFormWindow(widget)
         if form:
             editor = form.core()
             manager = editor.extensionManager()
             sheet = manager.extension(page, Q_TYPEID["QPyDesignerPropertySheetExtension"])
             # This explicit cast is necessary here
             sheet = sip.cast(sheet, QtDesigner.QPyDesignerPropertySheetExtension)
             propertyIndex = sheet.indexOf("windowTitle")
             sheet.setChanged(propertyIndex, True)
开发者ID:RedEyedDog,项目名称:PyQt4,代码行数:13,代码来源:multipagewidgetplugin.py


注:本文中的sip.cast函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。