QAbstractItemModel method implementation
13056
def data(self, index, role):
        
        if role == Qt.DisplayRole and \
           index.row() < len(self.words):
            text = self.words[index.row()]
            typed = text[:len(self._typedText)]
            canComplete = text[len(self._typedText):len(self._typedText) + len(self.canCompleteText)]
            rest = text[len(self._typedText) + len(self.canCompleteText):]
            if canComplete:
                # NOTE foreground colors are hardcoded, but I can't set background color of selected item (Qt bug?)
                # might look bad on some color themes
                return '<html>' \
                            '%s' \
                            '<font color="#e80000">%s</font>' \
                            '%s' \
                        '</html>' % (typed, canComplete, rest)
            else:
                return typed + rest
        else:
            return None
925648
def _get_acorn(self, method, *items):
    
    #IMPORTANT!! I lost two hours because the ndarray becomes unstable if you
    #don't call the original method first. Somehow passing the array instance to
    #other methods changed its internal representation and made it unusable by
    #the original numpy functions. Putting them first makes it work.
    
    # Because we had to subclass numpy.ndarray, the original methods get
    # stuck in an infinite loop (max. recursion depth exceeded errors). So,
    # we instead grab the reference to the original ndarray object.
    if method == "slice":
        r = np.ndarray.__acornext__.__getslice__(self, *items)
    else:
        r = np.ndarray.__acornext__.__getitem__(self, *items)
        
    if not (decorating or streamlining):
        from acorn.logging.decoration import (pre, post, _fqdn)
        if method == "slice":
            fqdn = "numpy.ndarray.__getslice__"
        else:
            fqdn = "numpy.ndarray.__getitem__"
        preres = pre(fqdn, np.ndarray, 5, self, *items)
        entry, bound, ekey = preres
        # This method can trick acorn into thinking that it is a bound
        # method. We want it to behave like it's not.
        post(fqdn, "numpy", r, entry, np.ndarray, ekey)
    return r
1179469
def _update_model(self, completions):
        
        # build the completion model
        cc_model = QtGui.QStandardItemModel()
        self._tooltips.clear()
        for completion in completions:
            name = completion['name']
            item = QtGui.QStandardItem()
            item.setData(name, QtCore.Qt.DisplayRole)
            if 'tooltip' in completion and completion['tooltip']:
                self._tooltips[name] = completion['tooltip']
            if 'icon' in completion:
                icon = completion['icon']
                if isinstance(icon, list):
                    icon = QtGui.QIcon.fromTheme(icon[0], QtGui.QIcon(icon[1]))
                else:
                    icon = QtGui.QIcon(icon)
                item.setData(QtGui.QIcon(icon),
                             QtCore.Qt.DecorationRole)
            cc_model.appendRow(item)
        try:
            self._completer.setModel(cc_model)
        except RuntimeError:
            self._create_completer()
            self._completer.setModel(cc_model)
        return cc_model
733048
def add_item(self, item):
        

        self.beginInsertRows(QtCore.QModelIndex(),
                             self.rowCount(),
                             self.rowCount())

        item["parent"] = self
        item = Item(**item)
        self.items.append(item)
        self.endInsertRows()

        item.__datachanged__.connect(self._dataChanged)

        return item
627661
def cast_item(cls, item):
        """"""
        if not isinstance(item, cls.subtype):
            incompatible = isinstance(item, Base) and not any(
                issubclass(cls.subtype, tag_type) and isinstance(item, tag_type)
                for tag_type in cls.all_tags.values()
            )
            if incompatible:
                raise IncompatibleItemType(item, cls.subtype)

            try:
                return cls.subtype(item)
            except EndInstantiation:
                raise ValueError('List tags without an explicit subtype must '
                                 'either be empty or instantiated with '
                                 'elements from which a subtype can be '
                                 'inferred') from None
            except (IncompatibleItemType, CastError):
                raise
            except Exception as exc:
                raise CastError(item, cls.subtype) from exc
        return item
262268
@Override
    public ITemplate __cloneMe(RythmEngine engine, ITemplate caller) {
        if (null == engine) throw new NullPointerException();
        TemplateBase tmpl = __internalClone();
        if (tmpl.__parent != null) {
            tmpl.__parent = (TemplateBase) tmpl.__parent.__cloneMe(engine, caller);
        }
        tmpl.__engine = engine;
        //tmpl.__templateClass = __templateClass;
        tmpl.__ctx = new __Context();
        //if (null != buffer) tmpl.__buffer = buffer;
        if (null != __buffer) tmpl.__buffer = new StringBuilder();
        tmpl.__renderArgs = new HashMap<String, Object>(__renderArgs.size());
        //tmpl.layoutContent = "";
        tmpl.layoutSections = new HashMap<String, String>();
        tmpl.layoutSections0 = new HashMap<String, String>();
        tmpl.renderProperties = new HashMap<String, Object>();
        //tmpl.section = null;
        //tmpl.tmpCaller = null;
        //tmpl.tmpOut = null;
        //tmpl.__logTime = __logTime;
        //tmpl.w = null;
        //tmpl.os = null;
        if (null != caller) {
            tmpl.__caller = (TextBuilder) caller;
            Map<String, Object> callerRenderArgs = new HashMap<String, Object>(((TemplateBase) caller).__renderArgs);
            Map<String, Class> types = tmpl.__renderArgTypeMap();
            for (Map.Entry<String, Object> entry : callerRenderArgs.entrySet()) {
                if (tmpl.__renderArgs.containsKey(entry.getKey())) continue;
                Object o = entry.getValue();
                if (null == o || __isDefVal(o)) continue;
                Class<?> c = types.get(entry.getKey());

                if (null == c || c.isAssignableFrom(o.getClass())) {
                    tmpl.__setRenderArg(entry.getKey(), o);
                }
            }
        }
        tmpl.__setUserContext(engine.renderSettings.userContext());
        return tmpl;
    }
363645
function(oldItem, newItem) {
      if(data.operations) {
        for(var i = 0; i < data.operations.length; i++) {
          var operation = data.operations[i];
          if(newItem && newItem[operation.field] !== undefined || oldItem && oldItem[operation.field] !== undefined) {
            opsToolbox[operation.operation].recompute(operations[operation.field], operation, oldItem, newItem);
          }
        }
      }
    }
269209
public static MethodInstance getMethodInstanceEL(Object objMaybeNull, Class clazz, Collection.Key methodName, Object[] args) {
	checkAccessibility(objMaybeNull, clazz, methodName);
	args = cleanArgs(args);

	Method[] methods = mStorage.getMethods(clazz, methodName, args.length);// getDeclaredMethods(clazz);

	if (methods != null) {
	    Class[] clazzArgs = getClasses(args);
	    // exact comparsion
	    // print.e("exact:"+methodName);
	    outer: for (int i = 0; i < methods.length; i++) {
		if (methods[i] != null) {
		    Class[] parameterTypes = methods[i].getParameterTypes();
		    for (int y = 0; y < parameterTypes.length; y++) {
			if (toReferenceClass(parameterTypes[y]) != clazzArgs[y]) continue outer;
		    }
		    return new MethodInstance(methods[i], args);
		}
	    }
	    // like comparsion
	    // MethodInstance mi=null;
	    // print.e("like:"+methodName);
	    outer: for (int i = 0; i < methods.length; i++) {
		if (methods[i] != null) {
		    Class[] parameterTypes = methods[i].getParameterTypes();
		    for (int y = 0; y < parameterTypes.length; y++) {
			if (!like(clazzArgs[y], toReferenceClass(parameterTypes[y]))) continue outer;
		    }
		    return new MethodInstance(methods[i], args);
		}
	    }

	    // convert comparsion
	    // print.e("convert:"+methodName);
	    MethodInstance mi = null;
	    int _rating = 0;
	    outer: for (int i = 0; i < methods.length; i++) {
		if (methods[i] != null) {
		    RefInteger rating = (methods.length > 1) ? new RefIntegerImpl(0) : null;
		    Class[] parameterTypes = methods[i].getParameterTypes();
		    Object[] newArgs = new Object[args.length];
		    for (int y = 0; y < parameterTypes.length; y++) {
			try {
			    newArgs[y] = convert(args[y], toReferenceClass(parameterTypes[y]), rating);
			}
			catch (PageException e) {
			    continue outer;
			}
		    }
		    if (mi == null || rating.toInt() > _rating) {
			if (rating != null) _rating = rating.toInt();
			mi = new MethodInstance(methods[i], newArgs);
		    }
		    // return new MethodInstance(methods[i],newArgs);
		}
	    }
	    return mi;
	}
	return null;
    }
541332
def fromSchemaItem(self, item):
        
        if item.isElement() is False or item.isLocal() is True:
            raise TypeError, 'expecting global element declaration: %s' %item.getItemTrace()

        local = False
        qName = item.getAttribute('type')
        if not qName:
            etp = item.content
            local = True
        else:
            etp = item.getTypeDefinition('type')
            
        if etp is None:
            if local is True: 
                self.content = ElementLocalComplexTypeContainer(do_extended=self.do_extended)
            else: 
                self.content = ElementSimpleTypeContainer()
        elif etp.isLocal() is False:
            self.content = ElementGlobalDefContainer()
        elif etp.isSimple() is True: 
            self.content = ElementLocalSimpleTypeContainer()
        elif etp.isComplex():
            self.content = ElementLocalComplexTypeContainer(do_extended=self.do_extended)
        else:
            raise Wsdl2PythonError, "Unknown element declaration: %s" %item.getItemTrace()

        self.logger.debug('ElementWriter setUp container "%r", Schema Item "%s"' %(
            self.content, item.getItemTrace()))
        
        self.content.setUp(item)
864655
def addMenuItem( self, newItem, atItem ):
        
        tree = self.uiMenuTREE
        
        if ( not atItem ):
            tree.addTopLevelItem(newItem)
            
        elif ( atItem.data(0, Qt.UserRole) == 'menu' ):
            atItem.addChild(newItem)
        
        elif ( atItem.parent() ):
            index = atItem.parent().indexOfChild(atItem)
            atItem.parent().insertChild(index + 1, newItem)
        
        else:
            index = tree.indexOfTopLevelItem(atItem)
            tree.insertTopLevelItem(index + 1, newItem)
402199
function (item, itemIndex, then, complete, arrayWeTraverse) {
            $assert (item === data[itemIndex])
            $assert (itemIndex === currentIndex++)
            $assert (arrayWeTraverse === data)

            $assert (_.isFunction (then))
            $assert (_.isFunction (complete))

            then () }
280036
def check(self):
        """"""
        for name, valItem, dtype in self.values:
            val = valItem.text()
            if dtype:
                try:
                    val = dtype(val)
                except:
                    msgBox = QtWidgets.QMessageBox()
                    msgBox.setText(
                        'attribute %s has not the right dtype(%s)' %
                        (name, str(dtype)))
                    msgBox.exec_()
            self.args[name] = val
        self.accept()
255475
def fix_pyqt5_QGraphicsItem_itemChange():
    
    from PyQt5.QtWidgets import QGraphicsObject, QGraphicsItem

    class Obj(QGraphicsObject):
        def itemChange(self, change, value):
            return QGraphicsObject.itemChange(self, change, value)

    obj = Obj()
    parent = Obj()
    obj.setParentItem(parent)

    if obj.parentItem() is None:
        # There was probably already some signal defined using QObject's
        # subclass from QtWidgets.
        # We will monkey patch the QGraphicsItem.itemChange and explicitly
        # sip.cast all input and output QGraphicsItem instances
        import sip
        QGraphicsItem_itemChange_old = QGraphicsItem.itemChange

        # All the QGraphicsItem.ItemChange flags which accept/return
        # a QGraphicsItem
        changeset = {
            QGraphicsItem.ItemParentChange,
            QGraphicsItem.ItemParentHasChanged,
            QGraphicsItem.ItemChildAddedChange,
            QGraphicsItem.ItemChildRemovedChange,
        }

        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)

        QGraphicsItem.itemChange = QGraphicsItem_itemChange
        warnings.warn("Monkey patching QGraphicsItem.itemChange",
                      RuntimeWarning)
558862
def dimod_object_hook(obj):
    
    if _is_sampleset_v2(obj):
        # in the future we could handle subtypes but right now we just have the
        # one
        return SampleSet.from_serializable(obj)
    elif _is_bqm_v2(obj):
        # in the future we could handle subtypes but right now we just have the
        # one
        return BinaryQuadraticModel.from_serializable(obj)
    return obj
386885
def getPaintItems(self, root=None):
        """"""
        if root is None:
            root = self.item
        preItems = []
        postItems = []
        if isinstance(root, QtGui.QGraphicsScene):
            childs = [i for i in root.items() if i.parentItem() is None]
            rootItem = []
        else:
            # CHANGE: For GraphicsLayouts, there is no function for childItems(), so I just
            # replaced it with .items()
            try:
                childs = root.childItems()
            except:
                childs = root.items()
            rootItem = [root]
        childs.sort(key=lambda a: a.zValue())
        while len(childs) > 0:
            ch = childs.pop(0)
            tree = self.getPaintItems(ch)

            if int(ch.flags() & ch.ItemStacksBehindParent) > 0 or (
                    ch.zValue() < 0 and int(ch.flags() & ch.ItemNegativeZStacksBehindParent) > 0):
                preItems.extend(tree)
            else:
                postItems.extend(tree)
        return preItems + rootItem + postItems
913632
protected ListSetItem<T> newItem(IModel<T> itemModel)
	{
		ListSetItem<T> item = new ListSetItem<T>(Integer.toString(counter++), itemModel);
		populateItem(item);
		return item;
	}
639105
def add(self, item):
        
        if self._is_stringable(item) or self._is_qstring(item):
            self.items.append(PlainText(item))
        elif isinstance(item, MessageElement):
            self.items.append(item)
        elif item is None or (hasattr(item, 'isNull') and item.isNull()):
            self.items.append(PlainText(
                tr('Null (None) found from the data.')))
        elif isinstance(item, tuple) or isinstance(item, list):
            for i in item:
                # Recursive call
                self.add(i)
        else:
            raise InvalidMessageItemError(item, item.__class__)