Example #1
0
	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]
Example #2
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'))
Example #3
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'))
Example #4
0
    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]
Example #5
0
	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)
Example #6
0
 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)
Example #7
0
	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
Example #8
0
 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
Example #9
0
	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
Example #10
0
 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
Example #11
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>', 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))
Example #12
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>', 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))
Example #13
0
 def test_isstr(self):
     false = utils.isstr("123.45")
     true = utils.isstr('"hey"')
     self.assertTrue(true)
     self.assertFalse(false)
Example #14
0
 def create_logger(instance):
     if utils.isstr(instance):
         return logging.getLogger(instance)
     else:
         return logging.getLogger("%s.%s" % (instance.__module__, instance.__class__.__name__))