From a84731da30039da7a594641e67a0fa305d955172 Mon Sep 17 00:00:00 2001 From: flatberg Date: Mon, 17 Dec 2007 18:52:49 +0000 Subject: [PATCH] Support for icon assignment based on introspection --- fluents/fluents.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/fluents/fluents.py b/fluents/fluents.py index cb57ec6..78465f9 100644 --- a/fluents/fluents.py +++ b/fluents/fluents.py @@ -13,7 +13,7 @@ import gnome import gnome.ui import scipy import pango -import project, workflow, dataset, view, navigator, dialogs, selections, main +import project, workflow, dataset, view, navigator, dialogs, selections, plots, main from logger import logger, LogView @@ -22,6 +22,10 @@ VERSION = '0.1.0' DATADIR = os.path.dirname(sys.modules['fluents'].__file__) ICONDIR = os.path.join(DATADIR,"..","icons") GLADEFILENAME = os.path.join(DATADIR, 'fluents.glade') +_icon_mapper = {dataset.Dataset: 'dataset', + dataset.CategoryDataset: 'category_dataset', + dataset.GraphDataset: 'graph_dataset', + plots.Plot: 'line_plot'} class IconFactory: """Factory for icons that ensures that each icon is only loaded once.""" @@ -33,7 +37,13 @@ class IconFactory: def get(self, iconname): """Returns the gdk loaded PixBuf for the given icon. Reads the icon from file if necessary.""" - + + # if iconname isnt a string, try to autoconvert + if not isinstance(iconname, str): + for cls in _icon_mapper.keys(): + if isinstance(iconname, cls): + iconname = _icon_mapper[cls] + if self._icons.has_key(iconname): return self._icons[iconname]