aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFulgen301 <tokmajigeorge@gmail.com>2017-03-15 11:24:33 +0100
committerFulgen301 <tokmajigeorge@gmail.com>2017-07-11 11:10:29 +0200
commitee160e0f3c577bed459739ea1f89d83cc3e43cb9 (patch)
tree94a6673ff058374330bc8ce35d95c48fafc96363
parent70b936e279154bc802ae05f4eb265ef1f4e22528 (diff)
downloadpycrctrl-ee160e0f3c577bed459739ea1f89d83cc3e43cb9.tar.gz
pycrctrl-ee160e0f3c577bed459739ea1f89d83cc3e43cb9.zip
Extend QList()
-rw-r--r--pycrctrl.py21
1 files 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