def __setitem__(self, i, item): if isinstance(i, slice): start, stop, step = i.indices(len(self)) items = item if self.__class__.is_heading(items): items = (items, ) items = flatten_list(items) for head in items: if not self.__class__.is_heading(head): raise ValueError( u'List contains items that are not a heading!') self._add_to_deleted_headings(self[i]) self._associate_heading( items, self[start - 1] if start - 1 >= 0 else None, self[stop] if stop < len(self) else None) MultiPurposeList.__setitem__(self, i, items) else: if not self.__class__.is_heading(item): raise ValueError(u'Item is not a heading!') if item in self: raise ValueError(u'Heading is already part of this list!') self._add_to_deleted_headings(self[i]) self._associate_heading(item, self[i - 1] if i - 1 >= 0 else None, self[i + 1] if i + 1 < len(self) else None) MultiPurposeList.__setitem__(self, i, item)
def __setitem__(self, i, item): if isinstance(i, slice): start, stop, step = i.indices(len(self)) items = item if self.__class__.is_heading(items): items = (items, ) items = flatten_list(items) for head in items: if not self.__class__.is_heading(head): raise ValueError(u'List contains items that are not a heading!') self._add_to_deleted_headings(self[i]) self._associate_heading( items, self[start - 1] if start - 1 >= 0 else None, self[stop] if stop < len(self) else None) MultiPurposeList.__setitem__(self, i, items) else: if not self.__class__.is_heading(item): raise ValueError(u'Item is not a heading!') if item in self: raise ValueError(u'Heading is already part of this list!') self._add_to_deleted_headings(self[i]) self._associate_heading( item, self[i - 1] if i - 1 >= 0 else None, self[i + 1] if i + 1 < len(self) else None) MultiPurposeList.__setitem__(self, i, item)
def __setitem__(self, i, item): if isinstance(i, slice): o = item if self.__class__.is_domobj(o): o = (o,) o = flatten_list(o) for item in o: if not self.__class__.is_domobj(item): raise ValueError(u'List contains items that are not a Dom obj!') # self._add_to_deleted_domobjs(self[i:j]) # self._associate_domobj(o, \ # self[i - 1] if i - 1 >= 0 and i < len(self) else None, \ # self[j] if j >= 0 and j < len(self) else None) MultiPurposeList.__setitem__(self, i, o) else: if not self.__class__.is_domobj(item): raise ValueError(u'Item is not a Dom obj!') if item in self: raise ValueError(u'Dom obj is already part of this list!') # self._add_to_deleted_domobjs(self[i]) # self._associate_domobj(item, \ # self[i - 1] if i - 1 >= 0 else None, \ # self[i + 1] if i + 1 < len(self) else None) MultiPurposeList.__setitem__(self, i, item)
def insert(self, i, item, taint=True): self._associate_heading( item, self[i - 1] if i - 1 >= 0 and i - 1 < len(self) else None, self[i] if i >= 0 and i < len(self) else None, taint=taint) MultiPurposeList.insert(self, i, item)
def __setitem__(self, i, item): if isinstance(i, slice): o = item if self.__class__.is_domobj(o): o = (o, ) o = flatten_list(o) for item in o: if not self.__class__.is_domobj(item): raise ValueError(u'List contains items that are not a Dom obj!') # self._add_to_deleted_domobjs(self[i:j]) # self._associate_domobj(o, \ # self[i - 1] if i - 1 >= 0 and i < len(self) else None, \ # self[j] if j >= 0 and j < len(self) else None) MultiPurposeList.__setitem__(self, i, o) else: if not self.__class__.is_domobj(item): raise ValueError(u'Item is not a Dom obj!') if item in self: raise ValueError(u'Dom obj is already part of this list!') # self._add_to_deleted_domobjs(self[i]) # self._associate_domobj(item, \ # self[i - 1] if i - 1 >= 0 else None, \ # self[i + 1] if i + 1 < len(self) else None) MultiPurposeList.__setitem__(self, i, item)
def append(self, item, taint=True): if not self.__class__.is_heading(item): raise ValueError(u"Item is not a heading!") if item in self: raise ValueError(u"Heading is already part of this list!") self._associate_heading(item, self[-1] if len(self) > 0 else None, None, taint=taint) MultiPurposeList.append(self, item)
def __init__(self, level=1, title=u'', body=None): u""" :level: Level of the dom object :title: Title of the dom object :body: Body of the dom object """ object.__init__(self) self._document = None self._parent = None self._previous_sibling = None self._next_sibling = None self._children = MultiPurposeList() self._orig_start = None self._orig_len = 0 self._level = level # title self._title = u'' if title: self.title = title # body self._dirty_body = False self._body = MultiPurposeList(on_change=self.set_dirty_body) if body: self.body = body
def insert(self, i, item, taint=True): self._associate_heading( item, self[i - 1] if i - 1 >= 0 and i - 1 < len(self) else None, self[i] if i >= 0 and i < len(self) else None, taint=taint, ) MultiPurposeList.insert(self, i, item)
def append(self, item, taint=True): if not self.__class__.is_heading(item): raise ValueError(u'Item is not a heading!') if item in self: raise ValueError(u'Heading is already part of this list!') self._associate_heading(item, self[-1] if len(self) > 0 else None, \ None, taint=taint) MultiPurposeList.append(self, item)
def __delitem__(self, i): item = self[i] if item.previous_sibling: item.previous_sibling._next_sibling = item.next_sibling if item.next_sibling: item.next_sibling._previous_sibling = item.previous_sibling self._add_to_deleted_headings(item) MultiPurposeList.__delitem__(self, i)
def reverse(self): MultiPurposeList.reverse(self) prev_h = None for h in self: h._previous_sibling = prev_h h._next_sibling = None prev_h._next_sibling = h h.set_dirty() prev_h = h
def extend(self, other): o = other if self.__class__.is_heading(o): o = (o, ) for item in o: if not self.__class__.is_heading(item): raise ValueError(u'List contains items that are not a heading!') self._associate_heading(o, self[-1] if len(self) > 0 else None, None) MultiPurposeList.extend(self, o)
def __setitem__(self, i, item): if not self.__class__.is_heading(item): raise ValueError(u"Item is not a heading!") if item in self: raise ValueError(u"Heading is already part of this list!") self._add_to_deleted_headings(self[i]) self._associate_heading(item, self[i - 1] if i - 1 >= 0 else None, self[i + 1] if i + 1 < len(self) else None) MultiPurposeList.__setitem__(self, i, item)
def sort(self, *args, **kwds): MultiPurposeList.sort(*args, **kwds) prev_h = None for h in self: h._previous_sibling = prev_h h._next_sibling = None prev_h._next_sibling = h h.set_dirty() prev_h = h
def extend(self, other): o = other if self.__class__.is_domobj(o): o = (o, ) for item in o: if not self.__class__.is_domobj(item): raise ValueError(u'List contains items that are not a heading!') # self._associate_domobj(o, self[-1] if len(self) > 0 else None, None) MultiPurposeList.extend(self, o)
def append(self, item, taint=True): if not self.__class__.is_domobj(item): raise ValueError(u'Item is not a heading!') if item in self: raise ValueError(u'Heading is already part of this list!') # self._associate_domobj( # item, self[-1] if len(self) > 0 else None, # None, taint=taint) MultiPurposeList.append(self, item)
def __delitem__(self, i, taint=True): item = self[i] if item.previous_sibling: item.previous_sibling._next_sibling = item.next_sibling if item.next_sibling: item.next_sibling._previous_sibling = item.previous_sibling if taint: self._add_to_deleted_headings(item) MultiPurposeList.__delitem__(self, i)
def __setitem__(self, i, item): if not self.__class__.is_heading(item): raise ValueError(u'Item is not a heading!') if item in self: raise ValueError(u'Heading is already part of this list!') self._add_to_deleted_headings(self[i]) self._associate_heading(item, self[i - 1] if i - 1 >= 0 else None, self[i + 1] if i + 1 < len(self) else None) MultiPurposeList.__setitem__(self, i, item)
def __delitem__(self, i, taint=True): item = self[i] if item.previous_sibling: item.previous_sibling._next_sibling = item.next_sibling if item.next_sibling: item.next_sibling._previous_sibling = item.previous_sibling # if taint: # self._add_to_deleted_domobjs(item) MultiPurposeList.__delitem__(self, i)
def __setitem__(self, i, item): if not self.__class__.is_domobj(item): raise ValueError(u'Item is not a Dom obj!') if item in self: raise ValueError(u'Dom obj is already part of this list!') # self._add_to_deleted_domobjs(self[i]) # self._associate_domobj(item, \ # self[i - 1] if i - 1 >= 0 else None, \ # self[i + 1] if i + 1 < len(self) else None) MultiPurposeList.__setitem__(self, i, item)
def __delslice__(self, i, j): i = max(i, 0) j = max(j, 0) items = self[i:j] if items: first = items[0] last = items[-1] if first.previous_sibling: first.previous_sibling._next_sibling = last.next_sibling if last.next_sibling: last.next_sibling._previous_sibling = first.previous_sibling self._add_to_deleted_headings(items) MultiPurposeList.__delslice__(self, i, j)
def __delslice__(self, i, j, taint=True): i = max(i, 0) j = max(j, 0) items = self[i:j] if items: first = items[0] last = items[-1] if first.previous_sibling: first.previous_sibling._next_sibling = last.next_sibling if last.next_sibling: last.next_sibling._previous_sibling = first.previous_sibling # if taint: # self._add_to_deleted_domobjs(items) MultiPurposeList.__delslice__(self, i, j)
def __delslice__(self, i, j, taint=True): i = max(i, 0) j = max(j, 0) items = self[i:j] if items: first = items[0] last = items[-1] if first.previous_sibling: first.previous_sibling._next_sibling = last.next_sibling if last.next_sibling: last.next_sibling._previous_sibling = first.previous_sibling if taint: self._add_to_deleted_headings(items) MultiPurposeList.__delslice__(self, i, j)
def __setslice__(self, i, j, other): o = other if self.__class__.is_heading(o): o = (o, ) o = flatten_list(o) for item in o: if not self.__class__.is_heading(item): raise ValueError(u'List contains items that are not a heading!') i = max(i, 0) j = max(j, 0) self._add_to_deleted_headings(self[i:j]) self._associate_heading(o, \ self[i - 1] if i - 1 >= 0 and i < len(self) else None, \ self[j] if j >= 0 and j < len(self) else None) MultiPurposeList.__setslice__(self, i, j, o)
def __init__(self, level=1, title=u'', tags=None, todo=None, body=None, active_date=None): u""" :level: Level of the heading :title: Title of the heading :tags: Tags of the heading :todo: Todo state of the heading :body: Body of the heading :active_date: active date that is used in the agenda """ object.__init__(self) self._document = None self._parent = None self._previous_sibling = None self._next_sibling = None self._children = HeadingList(obj=self) self._orig_start = None self._orig_len = 0 self._dirty_heading = False self._level = level # todo self._todo = None if todo: self.todo = todo # tags self._tags = MultiPurposeList(on_change=self.set_dirty_heading) if tags: self.tags = tags # title self._title = u'' if title: self.title = title # body self._dirty_body = False self._body = MultiPurposeList(on_change=self.set_dirty_body) if body: self.body = body # active date self._active_date = active_date if active_date: self.active_date = active_date
def __init__(self, level=1, title=u'', tags=None, todo=None, body=None, active_date=None): u""" :level: Level of the heading :title: Title of the heading :tags: Tags of the heading :todo: Todo state of the heading :body: Body of the heading :active_date: active date that is used in the agenda """ DomObj.__init__(self, level=level, title=title, body=body) self._children = HeadingList(obj=self) self._dirty_heading = False # todo self._todo = None if todo: self.todo = todo # tags self._tags = MultiPurposeList(on_change=self.set_dirty_heading) if tags: self.tags = tags # active date self._active_date = active_date if active_date: self.active_date = active_date # checkboxes self._checkboxes = CheckboxList(obj=self) self._cached_checkbox = None self._logbook = Logbook(obj=self)
def __init__(self): u""" Don't call this constructor directly but use one of the concrete implementations. TODO: what are the concrete implementatiions? """ object.__init__(self) # is a list - only the Document methods should work on this list! self._content = None self._dirty_meta_information = False self._dirty_document = False self._meta_information = MultiPurposeList( on_change=self.set_dirty_meta_information) self._orig_meta_information_len = None self._headings = HeadingList(obj=self) self._deleted_headings = [] # settings needed to align tags properly self._tabstop = 8 self._tag_column = 77 # TODO this doesn't differentiate between ACTIVE and FINISHED todo's self.todo_states = [u'TODO', u'DONE']
def __init__(self, initlist=None, obj=None): """ :initlist: Initial data :obj: Link to a concrete Heading or Document object """ # it's not necessary to register a on_change hook because the heading # list will itself take care of marking headings dirty or adding # headings to the deleted headings list MultiPurposeList.__init__(self) self._obj = obj # initialization must be done here, because # self._document is not initialized when the # constructor of MultiPurposeList is called if initlist: self.extend(initlist)
def __iadd__(self, other): o = other if self.__class__.is_domobj(o): o = (o, ) for item in flatten_list(o): if not self.__class__.is_domobj(item): raise ValueError(u'List contains items that are not a Dom obj!') # self._associate_domobj(o, self[-1] if len(self) > 0 else None, None) return MultiPurposeList.__iadd__(self, o)
def __iadd__(self, other): o = other if self.__class__.is_heading(o): o = (o, ) for item in flatten_list(o): if not self.__class__.is_heading(item): raise ValueError(u'List contains items that are not a heading!') self._associate_heading(o, self[-1] if len(self) > 0 else None, None) return MultiPurposeList.__iadd__(self, o)
def __setitem__(self, i, item): # TODO rewrite this so that it can work when item is a tuple and i is slice # it should be made to work with any item that is iterable # It is also very poor design to just check for tuple and not raise any # errors otherwise or implement list also # TODO slice must differentiate between couple of cases: # slice(None,None) # slice(int, None) # slice(None, int) # this must be done because of _associate_heading and other methods # that dont take into account slicing if isinstance(i, slice): # TODO fix this mess it is only copy pasted from setslice sl = i o = item if self.__class__.is_heading(o): o = (o, ) o = flatten_list(o) for head in o: if not self.__class__.is_heading(head): raise ValueError(u'List contains items that are not a heading!') i = sl.start if sl.start is not None else 0 j = sl.stop if sl.stop is not None else len(self) - 1 self._add_to_deleted_headings(self[sl]) self._associate_heading( o, self[i - 1] if i - 1 >= 0 and i < len(self) else None, self[j] if j >= 0 and j < len(self) else None) MultiPurposeList.__setitem__(self, sl, o) else: if not self.__class__.is_heading(item): raise ValueError(u'Item is not a heading!') if item in self: raise ValueError(u'Heading is already part of this list!') self._add_to_deleted_headings(self[i]) self._associate_heading( item, self[i - 1] if i - 1 >= 0 else None, self[i + 1] if i + 1 < len(self) else None) MultiPurposeList.__setitem__(self, i, item)
def __setitem__(self, i, item): # TODO rewrite this so that it can work when item is a tuple and i is slice # it should be made to work with any item that is iterable # It is also very poor design to just check for tuple and not raise any # errors otherwise or implement list also # TODO slice must differentiate between couple of cases: # slice(None,None) # slice(int, None) # slice(None, int) # this must be done because of _associate_heading and other methods # that dont take into account slicing if isinstance(i, slice): # TODO fix this mess it is only copy pasted from setslice sl = i o = item if self.__class__.is_heading(o): o = (o, ) o = flatten_list(o) for head in o: if not self.__class__.is_heading(head): raise ValueError( u'List contains items that are not a heading!') i = sl.start if sl.start is not None else 0 j = sl.stop if sl.stop is not None else len(self) - 1 self._add_to_deleted_headings(self[sl]) self._associate_heading( o, self[i - 1] if i - 1 >= 0 and i < len(self) else None, self[j] if j >= 0 and j < len(self) else None) MultiPurposeList.__setitem__(self, sl, o) else: if not self.__class__.is_heading(item): raise ValueError(u'Item is not a heading!') if item in self: raise ValueError(u'Heading is already part of this list!') self._add_to_deleted_headings(self[i]) self._associate_heading(item, self[i - 1] if i - 1 >= 0 else None, self[i + 1] if i + 1 < len(self) else None) MultiPurposeList.__setitem__(self, i, item)
def __delitem__(self, i, taint=True): if isinstance(i, slice): items = self[i] if items: first = items[0] last = items[-1] if first.previous_sibling: first.previous_sibling._next_sibling = last.next_sibling if last.next_sibling: last.next_sibling._previous_sibling = first.previous_sibling # if taint: # self._add_to_deleted_domobjs(items) else: item = self[i] if item.previous_sibling: item.previous_sibling._next_sibling = item.next_sibling if item.next_sibling: item.next_sibling._previous_sibling = item.previous_sibling # if taint: # self._add_to_deleted_domobjs(item) MultiPurposeList.__delitem__(self, i)
def __delitem__(self, i, taint=True): # TODO refactor this item, it works the same in dom_obj except taint? if isinstance(i, slice): items = self[i] if items: first = items[0] last = items[-1] if first.previous_sibling: first.previous_sibling._next_sibling = last.next_sibling if last.next_sibling: last.next_sibling._previous_sibling = first.previous_sibling if taint: self._add_to_deleted_headings(items) MultiPurposeList.__delitem__(self, i) else: item = self[i] if item.previous_sibling: item.previous_sibling._next_sibling = item.next_sibling if item.next_sibling: item.next_sibling._previous_sibling = item.previous_sibling if taint: self._add_to_deleted_headings(item) MultiPurposeList.__delitem__(self, i)
def __delitem__(self, i, taint=True): # TODO this method needs more work if isinstance(i, slice): items = self[i] if items: first = items[0] last = items[-1] if first.previous_sibling: first.previous_sibling._next_sibling = last.next_sibling if last.next_sibling: last.next_sibling._previous_sibling = first.previous_sibling if taint: self._add_to_deleted_headings(items) MultiPurposeList.__delitem__(self, i) else: item = self[i] if item.previous_sibling: item.previous_sibling._next_sibling = item.next_sibling if item.next_sibling: item.next_sibling._previous_sibling = item.previous_sibling if taint: self._add_to_deleted_headings(item) MultiPurposeList.__delitem__(self, i)
def insert(self, i, item, taint=True): # self._associate_domobj( # item, # self[i - 1] if i - 1 >= 0 and i - 1 < len(self) else None, # self[i] if i >= 0 and i < len(self) else None, taint=taint) MultiPurposeList.insert(self, i, item)
def __imul__(self, n): # TODO das müsste eigentlich ein klonen von objekten zur Folge haben return MultiPurposeList.__imul__(self, n)