Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

Support for icon assignment based on introspection

This commit is contained in:
Arnar Flatberg 2007-12-17 18:52:49 +00:00
parent 163271fc17
commit a84731da30
1 changed files with 12 additions and 2 deletions

View File

@ -13,7 +13,7 @@ import gnome
import gnome.ui import gnome.ui
import scipy import scipy
import pango 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 from logger import logger, LogView
@ -22,6 +22,10 @@ VERSION = '0.1.0'
DATADIR = os.path.dirname(sys.modules['fluents'].__file__) DATADIR = os.path.dirname(sys.modules['fluents'].__file__)
ICONDIR = os.path.join(DATADIR,"..","icons") ICONDIR = os.path.join(DATADIR,"..","icons")
GLADEFILENAME = os.path.join(DATADIR, 'fluents.glade') 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: class IconFactory:
"""Factory for icons that ensures that each icon is only loaded once.""" """Factory for icons that ensures that each icon is only loaded once."""
@ -33,7 +37,13 @@ class IconFactory:
def get(self, iconname): def get(self, iconname):
"""Returns the gdk loaded PixBuf for the given icon. """Returns the gdk loaded PixBuf for the given icon.
Reads the icon from file if necessary.""" 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): if self._icons.has_key(iconname):
return self._icons[iconname] return self._icons[iconname]