def delete(self, index): if index == ALL: self.entry = 0 self.root.children = [] self.entries = {} self.execute('delete', ('1.0', END)) else: eraseRoot = True # print index if isstr(index): indices = index.split('.') if indices[-1] == ALL: eraseRoot = False index = '.'.join(indices[:-1]) node = self.get_node(index) if self.node_visibility(node): self.erase_branch(node, eraseRoot) def delete_node(node): del self.entries[node.entry] if isinstance(node, TreeGroup): for child in node.children: delete_node(child) if eraseRoot: node.parent.children.remove(node) delete_node(node) else: # for child in node.children: while node.children: child = node.children[0] delete_node(child) del node.children[0]
def insert(self, index, text, tags=None): if index == END: index = -1 e = 'entry%s' % self.entry self.text.tag_bind(e, '<Button-1>', lambda e, i=e: self.doselect(i, 0)) self.text.tag_bind(e, '<DoubleButton-1>', self.doubleclick) self.text.tag_bind(e, '<Button-3>', lambda e, i=e: self.popup(e, i)) self.text.tag_bind(e, '<Shift-Button-1>', lambda e, i=e: self.doselect(i, 1)) self.text.tag_bind(e, '<Control-Button-1>', lambda e, i=e: self.doselect(i, 2)) if tags == None: tags = e elif isstr(tags): tags = '%s %s' % (e, tags) else: tags = '%s %s' % (e, ' '.join(tags)) if self.entries: i = 'entry%s.last +1l' % self.entries[index] else: i = END if index == -1 or index == len(self.entries) - 1: self.entries.append(self.entry) else: self.entries.insert(index + 1, self.entry) self.entry += 1 self.execute('insert', (i, text, tags)) self.execute('insert', (i + ' lineend', '\n'))
def insert(self, index, text, tags=None): if index == END: index = -1 e = 'entry%s' % self.entry self.text.tag_bind(e, '<Button-1>', lambda e,i=e: self.doselect(i,0)) self.text.tag_bind(e, '<DoubleButton-1>', self.doubleclick) self.text.tag_bind(e, '<Button-3>', lambda e,i=e: self.popup(e,i)) self.text.tag_bind(e, '<Shift-Button-1>', lambda e,i=e: self.doselect(i,1)) self.text.tag_bind(e, '<Control-Button-1>', lambda e,i=e: self.doselect(i,2)) if tags == None: tags = e elif isstr(tags): tags = '%s %s' % (e,tags) else: tags = '%s %s' % (e,' '.join(tags)) if self.entries: i = 'entry%s.last +1l' % self.entries[index] else: i = END if index == -1 or index == len(self.entries)-1: self.entries.append(self.entry) else: self.entries.insert(index+1, self.entry) self.entry += 1 self.execute('insert',(i, text, tags)) self.execute('insert',(i + ' lineend', '\n'))
def insert(self, index, text): if isstr(text): text = [text] if len(text) < len(self.columns): for _ in range(len(self.columns) - len(text)): text.append('') for c,t in zip(self.columns,text): c[1].insert(index, t)
def insert(self, index, text): if isstr(text): text = [text] if len(text) < len(self.columns): for _ in range(len(self.columns) - len(text)): text.append('') for c, t in zip(self.columns, text): c[1].insert(index, t)
def get_node(self, index): # print ('Get',index) node = None if isinstance(index, int): node = self.entries[index] elif isstr(index): node = self.root if index: indices = [int(i) for i in index.split('.')] while indices: node = node.children[indices[0]] del indices[0] return node
def index(self, entry): index = None if isstr(entry) and entry.startswith('@'): entries = [int(n[5:]) for n in self.text.tag_names(entry) if n.startswith('entry')] if entries: entry = entries[0] if isinstance(entry, int): node = self.entries[entry] if node: index = '' while node != self.root: index = '%d%s%s' % (node.parent.children.index(node),'.' if index else '',index) node = node.parent return index
def index(self, entry): index = None if isstr(entry) and entry.startswith('@'): entries = [ int(n[5:]) for n in self.text.tag_names(entry) if n.startswith('entry') ] if entries: entry = entries[0] if isinstance(entry, int): node = self.entries[entry] if node: index = '' while node != self.root: index = '%d%s%s' % (node.parent.children.index(node), '.' if index else '', index) node = node.parent return index
def insert(self, index, text, tags=None): if index == END: index = -1 e = 'entry%s' % self.entry self.text.tag_bind(e, '<Button-1>', self.select) if tags == None: tags = e elif isstr(tags): tags = '%s %s' % (e,tags) else: tags = '%s %s' % (e,' '.join(tags)) if self.entries: i = 'entry%s.last +1l' % self.entries[index] else: i = END if index == -1 or index == len(self.entries)-1: self.entries.append(self.entry) else: self.entries.insert(index+1, self.entry) self.entry += 1 return self.execute('insert',(i, '%s\n' % text, tags))
def insert(self, index, text, tags=None): if index == END: index = -1 e = 'entry%s' % self.entry self.text.tag_bind(e, '<Button-1>', self.select) if tags == None: tags = e elif isstr(tags): tags = '%s %s' % (e, tags) else: tags = '%s %s' % (e, ' '.join(tags)) if self.entries: i = 'entry%s.last +1l' % self.entries[index] else: i = END if index == -1 or index == len(self.entries) - 1: self.entries.append(self.entry) else: self.entries.insert(index + 1, self.entry) self.entry += 1 return self.execute('insert', (i, '%s\n' % text, tags))
def test_isstr(self): false = utils.isstr("123.45") true = utils.isstr('"hey"') self.assertTrue(true) self.assertFalse(false)
def create_logger(instance): if utils.isstr(instance): return logging.getLogger(instance) else: return logging.getLogger("%s.%s" % (instance.__module__, instance.__class__.__name__))