diff --git a/apps/icons/__init__.py b/apps/icons/__init__.py index d4e3be3e5e..2350021044 100644 --- a/apps/icons/__init__.py +++ b/apps/icons/__init__.py @@ -1,8 +1,22 @@ from __future__ import absolute_import -#from django.utils.translation import ugettext_lazy as _ -#from django.conf import settings +import inspect +import os +import glob -from .classes import Icon -#from storage.backends.filebasedstorage import FileBasedStorage -#afrom app_registry.models import App +from django.utils.importlib import import_module +from django.conf import settings as django_settings + +from .classes import Icon, IconSetBase + +for app_name in django_settings.INSTALLED_APPS: + try: + sets_top = import_module('%s.iconsets' % app_name) + except ImportError: + pass + else: + for icon_set_name in [os.path.basename(f)[:-3] for f in glob.glob(os.path.dirname(sets_top.__file__)+"/*.py")][1:]: + icon_set_module = import_module('%s.iconsets.%s' % (app_name, icon_set_name)) + klass = getattr(icon_set_module, 'IconSet', None) + if klass: + klass() diff --git a/apps/icons/classes.py b/apps/icons/classes.py index 8c6b4b6ef7..75deff7244 100644 --- a/apps/icons/classes.py +++ b/apps/icons/classes.py @@ -5,37 +5,23 @@ import os from django.utils.safestring import mark_safe from django.conf import settings -from .settings import ICON_SET -from .sets import ICON_THEMES -from .literals import ERROR - -SIZE_SMALL = '16x16' -SIZE_BIG = '32x32' +from .literals import ERROR, SIZE_SMALL, SIZE_BIG class Icon(object): _registry = {} - def __init__(self, literal, icon_set=None): - self.literal = literal + def __init__(self, id, icon_set=None): + self.id = id self.icon_set = icon_set - self.__class__._registry[literal] = self + self.__class__._registry[id] = self - def get_file_name(self, size): - # TODO: Move name + size resolution to sets to support size/name and - # name_size filename conventions - try: - if self.icon_set: - return '%s/%s/%s' % (ICON_THEMES[self.icon_set].PATH, size, ICON_THEMES[self.icon_set].DICTIONARY[self.literal]) - else: - return '%s/%s/%s' % (ICON_THEMES[ICON_SET].PATH, size, ICON_THEMES[ICON_SET].DICTIONARY[self.literal]) - except KeyError: - return '%s/%s/%s' % (ICON_THEMES[ICON_SET].PATH, size, ICON_THEMES[ICON_SET].DICTIONARY[ERROR]) - except AttributeError: - pass + def get_url(self, size): + from .settings import ICON_SET + return IconSetBase.get_by_name(self.icon_set or ICON_SET).get_url(self, size) def display(self, size): # TODO: move to widgets? - return mark_safe(u'' % (settings.STATIC_URL, self.get_file_name(size))) + return mark_safe(u'' % (settings.STATIC_URL, self.get_url(size))) def display_small(self): return self.display(SIZE_SMALL) @@ -43,8 +29,30 @@ class Icon(object): def display_big(self): return self.display(SIZE_BIG) - def get_filepath(self): - if settings.DEVELOPMENT: - return os.path.join(settings.PROJECT_ROOT, 'apps', 'icons', 'static', 'icons', self.get_file_name(SIZE_BIG)) - else: - return os.path.join(settings.STATIC_ROOT, self.get_file_name(SIZE_BIG)) + #def get_filepath(self): + # if settings.DEVELOPMENT: + # return os.path.join(settings.PROJECT_ROOT, 'apps', 'icons', 'static', 'icons', self.get_file_name(SIZE_BIG)) + # else: + # return os.path.join(settings.STATIC_ROOT, self.get_file_name(SIZE_BIG)) + + +class IconSetBase(object): + _registry = {} + + @classmethod + def get_all(cls): + return cls._registry.values() + + @classmethod + def get_by_name(cls, name): + return cls._registry.get(name) + + def __init__(self): + self.__class__._registry[self.name] = self + + def get_filename(self, icon, size): + return os.path.join([self.path, size, self.dictionary.get(icon.id, ERROR)]) + + def get_url(self, icon, size): + return '%s/%s/%s' % (self.path, size, self.dictionary.get(icon.id, ERROR)) + diff --git a/apps/icons/iconsets/__init__.py b/apps/icons/iconsets/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/apps/icons/iconsets/custom.py b/apps/icons/iconsets/custom.py new file mode 100644 index 0000000000..e15ef371d4 --- /dev/null +++ b/apps/icons/iconsets/custom.py @@ -0,0 +1,14 @@ +from django.utils.translation import ugettext_lazy as _ + +from icons.literals import * +from icons.classes import IconSetBase + + +class IconSet(IconSetBase): + path = 'custom' + name = 'custom' + label = _(u'Custom') + dictionary = { + FILE_EXTENSION_ERROR: 'file_extension_error.png', + FILE_EXTENSION_UNKNOWN: 'file_extension_unknown.png' + } diff --git a/apps/icons/iconsets/fat_cow.py b/apps/icons/iconsets/fat_cow.py new file mode 100644 index 0000000000..82d604fcc2 --- /dev/null +++ b/apps/icons/iconsets/fat_cow.py @@ -0,0 +1,109 @@ +from django.utils.translation import ugettext_lazy as _ + +from icons.literals import * +from icons.classes import IconSetBase + + +class IconSet(IconSetBase): + name='fat_cow' + label=_(u'Fat cow') + path='fat_cow' + dictionary={ + ADD: 'add.png', + APPLICATION_VIEW_ICONS: 'application_view_icons.png', + BLACKBOARD_SUM: 'blackboard_sum.png', + BOOK: 'book.png', + BOOK_GO: 'book_go.png', + BOOK_OPEN: 'book_open.png', + CAMERA_DELETE: 'camera_delete.png', + CD_BURN: 'cd_burn.png', + COG: 'cog.png', + COG_ADD: 'cog_add.png', + COG_EDIT: 'cog_edit.png', + COG_DELETE: 'cog_delete.png', + COMPUTER_KEY: 'computer_key.png', + CROSS: 'cross.png', + DELETE: 'delete.png', + DRAW_AIRBRUSH: 'draw_airbrush.png', + DOCUMENT_SIGNATURE: 'document_signature.png', + ERROR: 'error.png', + FOLDER: 'folder.png', + FOLDERS: 'folders.png', + FOLDER_ADD: 'folder_add.png', + FOLDER_EDIT: 'folder_edit.png', + FOLDER_DELETE: 'folder_delete.png', + FOLDER_GO: 'folder_go.png', + FOLDER_USER: 'folder_user.png', + GROUP: 'group.png', + GROUP_ADD: 'group_add.png', + GROUP_EDIT: 'group_edit.png', + GROUP_DELETE: 'group_delete.png', + GROUP_KEY: 'group_key.png', + GROUP_LINK: 'group_link.png', + INFORMATION: 'information.png', + KEY: 'key.png', + KEY_GO: 'key_go.png', + KEY_ADD: 'key_add.png', + KEY_DELETE: 'key_delete.png', + KEYBOARD: 'keyboard.png', + LAYOUT: 'layout.png', + LIGHTNING: 'lightning.png', + LINK: 'link.png', + LINK_ADD: 'link_add.png', + LINK_EDIT: 'link_edit.png', + LINK_DELETE: 'link_delete.png', + LOCK: 'lock.png', + LOCK_EDIT: 'lock_edit.png', + MAGNIFIER: 'magnifier.png', + MEDAL_GOLD: 'medal_gold_1.png', + MEDAL_GOLD_ADD: 'medal_gold_add.png', + MEDAL_GOLD_DELETE: 'medal_gold_delete.png', + PAGE: 'page.png', + PAGE_COPY: 'page_copy.png', + PAGE_GEAR:'page_gear.png', + PAGE_GO: 'page_go.png', + PAGE_DELETE: 'page_delete.png', + PAGE_EDIT: 'page_edit.png', + PAGE_LINK: 'page_link.png', + PAGE_REFRESH: 'page_refresh.png', + PAGE_SAVE: 'page_save.png', + PAGE_WHITE_COPY: 'page_white_copy.png', + PAGE_WHITE_CSHARP: 'page_white_csharp.png', + PAGE_WORLD: 'page_world.png', + PICTURES: 'pictures.png', + PILL: 'pill.png', + PLUGIN: 'plugin.png', + PRINTER: 'printer.png', + RAINBOW: 'rainbow.png', + ROUTING_TURNAROUND_RIGHT: 'routing_turnaround_right.png', + SCRIPT: 'script.png', + SERVER: 'server.png', + STORAGE: 'storage.png', + TABLE: 'table.png', + TABLE_ADD: 'table_add.png', + TABLE_EDIT: 'table_edit.png', + TABLE_DELETE: 'table_delete.png', + TABLE_REFRESH: 'table_refresh.png', + TABLE_RELATIONSHIP: 'table_relationship.png', + TAG_BLUE: 'tag_blue.png', + TAG_BLUE_ADD: 'tag_blue_add.png', + TAG_BLUE_DELETE: 'tag_blue_delete.png', + TAG_BLUE_EDIT: 'tag_blue_edit.png', + TEXT_DROPCAPS: 'text_dropcaps.png', + TEXT_STRIKETHROUGH: 'text_strikethrough.png', + TICK: 'tick.png', + TIME: 'time.png', + TIMELINE_MARKER: 'timeline_marker.png', + USER: 'user.png', + USER_ADD:'user_add.png', + USER_EDIT: 'user_edit.png', + USER_DELETE: 'user_delete.png', + VCARD: 'vcard.png', + VCARD_EDIT: 'vcard_edit.png', + WRENCH: 'wrench.png', + XHTML: 'xhtml.png', + XHTML_GO: 'xhtml_go.png', + XHTML_ADD: 'xhtml_add.png', + XHTML_DELETE: 'xhtml_delete.png', + ZOOM: 'zoom.png', + } diff --git a/apps/icons/literals.py b/apps/icons/literals.py index ee456e547f..d75ea0ef81 100644 --- a/apps/icons/literals.py +++ b/apps/icons/literals.py @@ -1,8 +1,5 @@ -#from icons.sets import fat_cow, famfamfam - -#DEFAULT_ICON_SET = fat_cow.ID -ICON_SET_FAT_COW = 'fat_cow' -ICON_SET_CUSTOM = 'custom' +SIZE_SMALL = '16x16' +SIZE_BIG = '32x32' DEFAULT_ICON_SET = 'fat_cow' @@ -26,7 +23,14 @@ DOCUMENT_SIGNATURE = 'document_signature' ERROR = 'error' FILE_EXTENSION_ERROR = 'file_extension_error' FILE_EXTENSION_UNKNOWN = 'file_extension_unknown' -GROUP = 'user', +FOLDER = 'folder' +FOLDERS = 'folders' +FOLDER_ADD = 'folder_add' +FOLDER_EDIT = 'folder_edit' +FOLDER_DELETE = 'folder_delete' +FOLDER_GO = 'folder_go' +FOLDER_USER = 'folder_user' +GROUP = 'user' GROUP_ADD = 'group_add' GROUP_EDIT = 'group_edit' GROUP_DELETE = 'group_delete'