Hallo,
Ich möchte gerne Icons in eine DLL-Datei packen? Sozusagen eine DLL-Icon-Bibliothek erstellen.
Weiß jemand wie das geht?
Danke!
Icons in DLL packen
Also ich kann mit dem Visual Studio icons in die DLL laden. ICh nehme mal an, dass Du die Möglichkeit haben möchtest, Deine Anwendung immer mit neuen/aktuellen Icons updaten möchtest. Also ich arbeite immer so, dass sämtl. Bilder ,Icons oder was an Grafiken auch immer anliegt, als PNG Sourcen in ein Script hintelege. Das kompiliere ich dann immer mit in die exe. Aber Du kannst auch (glaube ich) Deine Anwendung schreiben, die dann auf die externe Pyc Datei zugreift.
Vielleicht ist das was für Dich?
Greetz from 2bock
Vielleicht ist das was für Dich?
Greetz from 2bock

Um Icons in eine .DLL zu packen, musst du eine Resource Datei schreiben. Dazu kannst du dir ein Tutorial anschaunen, oder gleich einen Resourceeditor nehmen. Zum schluss hast du eine .RES Datei, die du noch in eine .DLL linken musst.
Hallo,
Danke für eure Beiträge. Ich habe mir in der Zwischenzeit eine eigene Icon-Bibliothek gebastelt. Die Icons werden per zipfile in eine einzelne Bibliotheksdatei gepackt und können daraus gut weiterverwendet werden.
Für die Klasse Read und die Klasse Test ist wxPython notwendig.
Funktioniert sehr gut.
Hier der Code:
Danke für eure Beiträge. Ich habe mir in der Zwischenzeit eine eigene Icon-Bibliothek gebastelt. Die Icons werden per zipfile in eine einzelne Bibliotheksdatei gepackt und können daraus gut weiterverwendet werden.
Für die Klasse Read und die Klasse Test ist wxPython notwendig.
Funktioniert sehr gut.
Hier der Code:
Code: Alles auswählen
# -*- coding: iso-8859-1 -*-
"""
----------------------------------------------------------------------------
Name: hhIconLib.py
Purpose: Create an IconLibrary about zipfile and StringIO in
connection with wxPython
Created: 16-Jun-2005
Copyright: No
Licence: No
----------------------------------------------------------------------------
"""
import wx
import os
import zipfile
import zlib
import fnmatch
from cStringIO import StringIO
class Create:
def __init__(self, librarypath):
""" icons = The library path and name """
self.librarypath = librarypath
def __PackIcons(self, icons, relativ_path = ""):
""" icons = The icons to pack in library
relativ_path = All foldersnames started from this path
"""
zlib.Z_DEFAULT_COMPRESSION = 9
ziparchiv = zipfile.ZipFile(self.librarypath, "w", zipfile.ZIP_DEFLATED)
l = len(relativ_path)
for icon in icons:
ziparchiv.write(os.path.normcase(icon), os.path.normcase(icon[l:]))
ziparchiv.close()
def PackIconsRecursive(self, path):
""" path = Path that contains icons will be search recursive and all
founded icons will be add to the library.
"""
icons = []
for root, dirs, files in os.walk(path):
files = fnmatch.filter(files, "*.ico")
for f in files:
f = os.path.join(root, f)
icons.append(f)
self.__PackIcons(icons, "\\%s" % path)
def PackIcons(self, icons):
""" icons = The icons to pack in library """
self.__PackIcons(icons)
class Read:
def __init__(self, librarypath):
""" icons = The library path and name """
self.librarypath = librarypath
self.library = self.__OpenLibrary()
def __OpenLibrary(self):
""" Open the library """
ziparchiv = zipfile.ZipFile(self.librarypath, "r")
iconlist = ziparchiv.namelist()
library = {}
for icon in iconlist:
buf = StringIO(ziparchiv.read(icon))
buf.seek(0)
name = os.path.splitext(os.path.normcase(icon))[0]
library[name] = buf
ziparchiv.close()
return library
def __Return_Icon_from_Image(self, img):
""" Convert image to icon """
bmp = wx.BitmapFromImage(img)
icon = wx.EmptyIcon()
icon.CopyFromBitmap(bmp)
return icon
def __Return_Bitmap_from_Image(self, img):
""" Convert image to bitmap """
bmp = wx.BitmapFromImage(img)
return bmp
def __Get_Icon_From_Library_As_Image(self, name, iconNumber_or_iconSize):
""" Return the image from the library """
icon_data = self.library[name]
img = None
if type(iconNumber_or_iconSize) == int:
img = wx.ImageFromStream(icon_data, wx.BITMAP_TYPE_ICO, iconNumber_or_iconSize)
if not img.Ok():
img = None
else:
for num in xrange(50):
img = wx.ImageFromStream(icon_data, wx.BITMAP_TYPE_ICO, num)
if img.Ok():
size = (img.GetWidth(), img.GetHeight())
if size == iconNumber_or_iconSize:
break
else:
img = None
break
return img
def GetImage(self, name, iconNumber_or_iconSize = (16, 16)):
""" Return an image from the library """
img = self.__Get_Icon_From_Library_As_Image(os.path.normcase(name), iconNumber_or_iconSize)
if img:
return img
def GetIcon(self, name, iconNumber_or_iconSize = (16, 16)):
""" Return an icon from the library """
img = self.__Get_Icon_From_Library_As_Image(os.path.normcase(name), iconNumber_or_iconSize)
if img:
return self.__Return_Icon_from_Image(img)
def GetBitmap(self, name, iconNumber_or_iconSize = (16, 16)):
""" Return an bitmap from the library """
img = self.__Get_Icon_From_Library_As_Image(os.path.normcase(name), iconNumber_or_iconSize)
if img:
return self.__Return_Bitmap_from_Image(img)
def GetIconNameList(self):
""" Return the icon names from the library as python list """
icon_namelist = self.library.keys()
icon_namelist.sort()
return icon_namelist
def GetIconNameDataDict(self):
""" Return the library as python dictionary (name : data) """
return self.library
class Test(wx.Frame):
def __init__(self, parent=None):
wx.Frame.__init__(self, parent, wx.ID_ANY)
#Lib erzeugen
self.CreateLib()
#Bitmap laden
path = r"C:\Dokumente und Einstellungen\hh16534\Eigene Dateien\2-Eigene_Programme\Icons\icon.lib"
icon_lib = Read(path)
bmp = icon_lib.GetBitmap(r"image\header")
icon = icon_lib.GetIcon(r"image\header")
self.SetIcon(icon)
#Bitmap anzeigen
self.staticbmp = wx.StaticBitmap(self, -1, bmp, (-1, -1), (bmp.GetWidth(), bmp.GetHeight()))
self.Box1000 = wx.BoxSizer(wx.HORIZONTAL)
self.Box1000.Add(self.staticbmp, -1, wx.EXPAND|wx.ALL, 30)
self.SetAutoLayout(True)
self.SetSizer(self.Box1000)
self.Layout()
self.Fit()
self.Centre()
def CreateLib(self):
path = r"C:\Dokumente und Einstellungen\hh16534\Eigene Dateien\2-Eigene_Programme\Icons\icon.lib"
lib = Create(path)
lib.PackIconsRecursive(os.path.dirname(path))
if __name__ == '__main__':
app = wx.App(redirect=False)
frame = Test()
frame.Show(True)
app.MainLoop()
Gruß, Harry