def test_image_resource( self, path='www/test_image.jpg', module='Products.product1'): from Globals import ImageResource img = ImageResource(path, module=module) self.assertEqual(img.content_type, 'image/jpeg') expected = pkg_resources.resource_string(module, path) self.assertEqual(img.read(), expected)
def register_icon(self, icon_path, productname, cname): name = os.path.basename(icon_path) icon = ImageResource(icon_path, self.package.__dict__) icon.__roles__ = None if not hasattr(OFS.misc_.misc_, productname): setattr(OFS.misc_.misc_, productname, OFS.misc_.Misc_(productname, {})) getattr(OFS.misc_.misc_, productname)[name] = icon
def test_image_resource(self, path='www/test_image.jpg', module='Products.product1'): from Globals import ImageResource img = ImageResource(path, module=module) self.assertEqual(img.content_type, 'image/jpeg') expected = pkg_resources.resource_string(module, path) self.assertEqual(img.read(), expected)
def initialize(self, context): # Add only one meta type to the folder add list. try: productObject = context._ProductContext__prod except AttributeError: productObject = context.product self.product_name = pid = productObject.id productGlobals = context._ProductContext__pack.__dict__ context.registerClass( meta_type = self.meta_type, # This is a little sneaky: we add self to the # FactoryDispatcher under the name "toolinit". # manage_addTool() can then grab it. constructors = (manage_addToolForm, manage_addTool, self,), #icon = self.icon ) # Lifted from ProductContext.registerClass, to avoid ImageFile if self.icon: icon_res = ImageResource(self.icon, productGlobals) icon_name = os_path.split(self.icon)[1] if not hasattr(misc_images, pid): setattr(misc_images, pid, MiscImage(pid, {})) getattr(misc_images, pid)[icon_name] = icon_res icon = os_path.split(self.icon)[1] for tool in self.tools: tool.__factory_meta_type__ = self.meta_type if self.icon: tool.icon = 'misc_/%s/%s' % (self.product_name, icon_name)
def registerIcon(klass, iconspec, _prefix=None): """ Make an icon available for a given class. o 'klass' is the class being decorated. o 'iconspec' is the path within the product where the icon lives. """ modname = klass.__module__ pid = modname.split('.')[1] name = os_path.split(iconspec)[1] klass.icon = 'misc_/%s/%s' % (pid, name) icon = ImageResource(iconspec, _prefix) icon.__roles__=None if not hasattr(misc_images, pid): setattr(misc_images, pid, MiscImage(pid, {})) getattr(misc_images, pid)[name]=icon
# FOR A PARTICULAR PURPOSE. # ############################################################################## # Zope External Editor Product by Casey Duncan from Globals import ImageResource from Globals import DTMLResource from OFS.ObjectManager import ObjectManager from OFS.FindSupport import FindSupport from App.Management import Tabs from ExternalEditor import ExternalEditor, EditLink # Add the icon and the edit method to the misc_ namespace misc_ = {'edit_icon': ImageResource('edit_icon.gif', globals())} # Insert the global external editor resources methods = {'externalEdit_': ExternalEditor(), 'externalEditLink_': EditLink} # Monkey patch in our manage_main for Object Manager ObjectManager.manage_main = DTMLResource('manage_main', globals()) # Add our patch for the find results template FindSupport.manage_findResult=DTMLResource('findResult', globals(), management_view='Find') # Add external editor icon in breadcrumbs under tabs Tabs.manage_tabs = DTMLResource('manage_tabs', globals())