summaryrefslogtreecommitdiff
path: root/portato/gui/gtk/usetips.py
blob: 69e9f9aa181e4bd5e3deae4f7756a107209d4644 (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
100
101
# -*- coding: utf-8 -*-
#
# File: portato/gui/gtk/usetips.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 __future__ import absolute_import

from ...backend import system
from ...backend.flags import invert_use_flag

from .TreeViewTooltips import TreeViewTooltips

class UseTips (TreeViewTooltips):
	"""This class handles the display of the so called use-tips,
	i.e. the tooltips showing the actual use-flags."""

	def __init__ (self, colno, cfg = None):
		"""Constructor.

		@param colno: the number of the column to check
		@type colno: int
		@param cfg: a config to look in, whether we should show the tips or not
		@type cfg: Config"""

		self.colno = colno
		self.cfg = cfg

		TreeViewTooltips.__init__(self)

	def get_tooltip(self, view, column, path):
		
		# check config
		if self.cfg is not None:
			if not self.cfg.get_boolean("useTips", "GTK"):
				return None
		
		store = view.get_model()
		it = store.get_iter(path)

		if store.iter_parent(it) is not None:
			return self.__get_flags(store.get_value(it, self.colno))
		else: # top items - ignore them
			return None

	def __get_flags(self, cpv):
		pkg = system.new_package(cpv)
		enabled = []
		disabled = []
		expanded = set()

		pkg_flags = pkg.get_iuse_flags()
		if not pkg_flags: # no flags - stop here
			return None
		
		pkg_flags.sort()
		actual = pkg.get_actual_use_flags()
		
		if pkg.is_installed():
			installed = pkg.get_installed_use_flags()
		else:
			inst = system.find_installed_packages(pkg.get_slot_cp())
			if inst:
				installed = inst[0].get_installed_use_flags()
			else:
				installed = []

		for use in pkg_flags:
			exp = pkg.use_expanded(use)
			if exp:
				expanded.add(exp)
			
			else:
				useStr = use
				if installed and ((use in actual) != (use in installed)):
					useStr += " %"
				if use in actual:
					enabled.append(useStr)
				else:
					disabled.append(useStr)
		
		string = ""
		
		if enabled:
			string = "<b>+%s</b>" % ("\n+".join(enabled),)
			if len(disabled) > 0:
				string = string + "\n"
		
		if disabled:
			string = string+"<i>- %s</i>" % ("\n- ".join(disabled),)

		if expanded:
			string = string+"\n\n"+"\n".join(expanded)

		return string
el?h=1.7.4&id=648e53b8249bd9d81814bc1a8bd1d0fe6f72d31f&follow=1'>Make edit helper function name consistent with other helpersSvend Sorensen1-1/+1 2014-05-07Factor out password completing-read functionSvend Sorensen1-4/+8 2014-05-07Add dash to Package-RequiresSvend Sorensen1-1/+1 2014-05-06Force sane sort order.Jason A. Donenfeld1-2/+2 2014-05-06generate: add --in-place optionJason A. Donenfeld4-9/+33