summaryrefslogtreecommitdiff
path: root/portato/gui/qt/tree.py
blob: fd616b6b3f97d9bc0dd16777e8af32ea6800a478 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# -*- coding: utf-8 -*-
#
# File: portato/gui/qt/tree.py
# This file is part of the Portato-Project, a graphical portage-frontend.
#
# Copyright (C) 2007 René 'Necoro' Neumann
# This is free software.  You may redistribute copies of it under the terms of
# the GNU General Public License version 2.
# There is NO WARRANTY, to the extent permitted by law.
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>

from PyQt4 import QtGui, QtCore
from portato.gui.wrapper import Tree
 
class QtTree (Tree):

	def __init__ (self, treeWidget, col = 0):

		self.tree = treeWidget
		self.col = col
		
		self.emergeIt = QtGui.QTreeWidgetItem(self.tree, ["Emerge", ""])
		self.unmergeIt = QtGui.QTreeWidgetItem(self.tree, ["Unmerge", ""])

	def build_append_value (self, cpv, oneshot = False, update = False, version = None):
		string = ""

		if oneshot:
			string += "(oneshot)"
			if update: string += "; "

		if update:
			string += "(updating"
			if version is not None:
				string += " from version %s" % version
			string += ")"

		return [cpv, string]

	def get_emerge_it (self):
		return self.emergeIt

	def get_unmerge_it (self):
		return self.unmergeIt

	def is_in_emerge (self, it):
		while self.iter_has_parent(it):
			it = self.parent_iter(it)
		return (it == self.emergeIt)

	def is_in_unmerge (self, it):
		return not self.is_in_emerge(it)

	def iter_has_parent (self, it):
		return (it.parent() != None)

	def parent_iter (self, it):
		return it.parent()

	def first_child_iter (self, it):
		return it.child(0)

	def iter_has_children (self, it):
		return (it.childCount() > 0)

	def next_iter (self, it):
		iter = QtGui.QTreeWidgetItemIterator(it)
		iter += 1 # next iter ...
		return iter.value()

	def get_value (self, it, column):
		return str(it.text(column))

	def append (self, parent = None, values = None):
		if values is None:
			values = ["",""]
		else:
			for i in range(len(values)):
				if values[i] is None:
					values[i] = ""

		if parent is None:
			parent = self.tree

		return QtGui.QTreeWidgetItem(parent, values)

	def remove (self, it):
		# a somehow strange approach ;) - go to the parent and delete the child
		parent = it.parent()
		index = parent.indexOfChild(it)
		parent.takeChild(index)

	def get_original (self):
		return self.tree

	def get_cpv_column (self):
		return self.col