From 70e5e9ca4bb97feda6897cd40b3b5c97cc46f2ad Mon Sep 17 00:00:00 2001 From: necoro <> Date: Sun, 11 Feb 2007 01:14:30 +0000 Subject: Added usetips Should have fixed segfaults with popups --- portato/gui/gtk/usetips.py | 76 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 portato/gui/gtk/usetips.py (limited to 'portato/gui/gtk/usetips.py') diff --git a/portato/gui/gtk/usetips.py b/portato/gui/gtk/usetips.py new file mode 100644 index 0000000..6611e09 --- /dev/null +++ b/portato/gui/gtk/usetips.py @@ -0,0 +1,76 @@ +# -*- 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 + +from portato.backend import Package +from portato.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_opt", section = self.cfg.const["gtk_sec"]): + 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 = Package(cpv) + enabled = [] + disabled = [] + + pkg_flags = pkg.get_all_use_flags() + if len(pkg_flags) == 0: # no flags - stop here + return None + + pkg_flags.sort() + for use in pkg_flags: + if pkg.is_use_flag_enabled(use): + enabled.append(use) + else: + disabled.append(use) + + string = "" + + if len(enabled) > 0: + string = "+"+"\n+".join(enabled)+"" + if len(disabled) > 0: + string = string + "\n" + + if len(disabled) > 0: + string = string+"- " + "\n- ".join(disabled) + "" + + return string -- cgit v1.2.3-70-g09d2