From ee160e0f3c577bed459739ea1f89d83cc3e43cb9 Mon Sep 17 00:00:00 2001 From: Fulgen301 Date: Wed, 15 Mar 2017 11:24:33 +0100 Subject: Extend QList() --- pycrctrl.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/pycrctrl.py b/pycrctrl.py index 6935512..c54d147 100644 --- a/pycrctrl.py +++ b/pycrctrl.py @@ -74,13 +74,27 @@ class QList(QObject): if type(name) != int: raise ValueError("Wrong datatype for name!") else: - return self.list[name] + try: + return self.list[name] + except IndexError as e: + raise IndexError(e.args[0]) from None def __lshift__(self, other): if self.typeclass and not isinstance(other, self.typeclass): raise ValueError("Wrong datatype") else: self.list.append(other) + return self + + def __rshift__(self, other): + if isinstance(other, list) or isinstance(other, QList): + item = self.list[-1] + try: + other.append(item) + self.list.pop() + except Exception: + raise TypeError("Cannot pass item to {}!".format(other)) from None + def __call__(self): return self.list @@ -89,13 +103,16 @@ class QList(QObject): return len(self.list) def __repr__(self): - return "{}({})".format(self.__name__, self.list) + return "{}({})".format(self.__class__.__name__, self.list) # Methods def isEmpty(self): return len(self.list) == 0 + def append(self, item): + return self.__lshift__(item) + class QStringList(QList): typeclass = str -- cgit v1.2.3-54-g00ecf