IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

wxPython Discussion :

Icone embarquée en Base64


Sujet :

wxPython

  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    13
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2007
    Messages : 13
    Par défaut Icone embarquée en Base64
    Bonjour à tous,
    je cherche comment intégrer une icone dans le code d'un programme. J'avais vu un programme en Tk qui le faisait en l'encodant en base64, est il possible de le faire en Wx ?

    J'ai trouvé une méthode qui consiste à reconstituer, à partir du string en base64, le fichier d'icône pour ensuite le charger mais est-il possible d'utiliser directement le string ?

  2. #2
    Membre confirmé Avatar de Mysti¢
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    155
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 155
    Par défaut
    Idem, j'ai essayé plusieurs chose avec l'encodage des fichiers icone en base64 mais j'ai pas réussi à les utiliser sans créer (sauvegarder) un fichier icone externe.
    J'ai déjà rencontré des programme qui utilisent un ffichier images.py qui lui contient des images sous la forme de chaines du genre:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    \x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00 \x00\x00\x00 \x08\x06\x00\
    \x00\x00szz\xf4\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\x00\x00qID\
    ATX\x85\xed\xd6;\n\x800\x10E\xd1{\xc5\x8d\xb9r\x97\x16\x0b\xad$\x8a\x82:\x16\
    o\xda\x84pB2\x1f\x81Fa\x8c\x9c\x08\x04Z{\xcf\xa72\xbcv\xfa\xc5\x08 \x80r\x80\
    \xfc\xa2\x0e\x1c\xe4\xba\xfaX\x1d\xd0\xde]S\x07\x02\xd8>\xe1wa-`\x9fQ\xe9\
    \x86\x01\x04\x10\x00\\(Dk\x1b-\x04\xdc\x1d\x07\x14\x98;\x0bS\x7f\x7f\xf9\x13\
    \x04\x10@\xf9X\xbe\x00\xc9 \x14K\xc1<={\x00\x00\x00\x00IEND\xaeB`\x82
    Je sais comment les exploiter, mais pas comment les générer :s
    Les seuls "chaines encodées" que j'ai su générer, c'est avec le script images2py.py (base64), mais j'arrive à les récupérer uniquement dans une fenêtre Pygame.

  3. #3
    Membre habitué
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    13
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2007
    Messages : 13
    Par défaut
    Ce code c'est les données brutes du fichier, même pas besoin d'encodage .
    Tu les obtiens comme ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    s = open('fichier.ext','rb').read()
    et le code est contenu dans le string 's'.

    Mais comment est-ce que tu l'utilise ?

  4. #4
    Membre chevronné
    Homme Profil pro
    Responsable du parc et des réseaux de télécommunication
    Inscrit en
    Mai 2003
    Messages
    290
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Responsable du parc et des réseaux de télécommunication
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2003
    Messages : 290
    Par défaut
    Bonjour,
    Je l'utiliserais comme ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    import wx
    import StringIO
     
    s='''\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00 \x00\x00\x00 \x08\x06\x00\
    \x00\x00szz\xf4\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\x00\x00qID\
    ATX\x85\xed\xd6;\n\x800\x10E\xd1{\xc5\x8d\xb9r\x97\x16\x0b\xad$\x8a\x82:\x16\
    o\xda\x84pB2\x1f\x81Fa\x8c\x9c\x08\x04Z{\xcf\xa72\xbcv\xfa\xc5\x08 \x80r\x80\
    \xfc\xa2\x0e\x1c\xe4\xba\xfaX\x1d\xd0\xde]S\x07\x02\xd8>\xe1wa-`\x9fQ\xe9\
    \x86\x01\x04\x10\x00\\(Dk\x1b-\x04\xdc\x1d\x07\x14\x98;\x0bS\x7f\x7f\xf9\x13\
    \x04\x10@\xf9X\xbe\x00\xc9 \x14K\xc1<={\x00\x00\x00\x00IEND\xaeB`\x82
    '''
    class MyFrame(wx.Frame):
     
        def __init__(self, parent, id, title):
            wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(150, 150))
            a=StringIO.StringIO(s)
            img=wx.BitmapFromImage(wx.ImageFromStream(a))
            image = wx.StaticBitmap(self, -1, img)
    class MyApp(wx.App):
     
        def OnInit(self):
            frame = MyFrame(None, -1, 'ImageFromStream')
            frame.Show(True)
            frame.Centre()
            return True
     
    app = MyApp(0)
    app.MainLoop()

  5. #5
    Membre Expert Avatar de pacificator
    Profil pro
    Inscrit en
    Août 2006
    Messages
    1 074
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 1 074
    Par défaut
    Bien vu pierjean .

    Reste à modifier
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
            image = wx.StaticBitmap(self, -1, img)
    par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
            icone = wx.EmptyIcon()
            icone.CopyFromBitmap(img)
            self.SetIcon(icone)
    et l'affaire est faite!

  6. #6
    Membre habitué
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    13
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2007
    Messages : 13
    Par défaut
    C'est exactement ce que voulais faire !
    Merci beaucoup

  7. #7
    Membre confirmé Avatar de Mysti¢
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    155
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 155
    Par défaut
    Et pour générer la chaine à partir d'une image svp?:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    s='''\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00 \x00\x00\x00 \x08\x06\x00\
    \x00\x00szz\xf4\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\x00\x00qID\
    ATX\x85\xed\xd6;\n\x800\x10E\xd1{\xc5\x8d\xb9r\x97\x16\x0b\xad$\x8a\x82:\x16\
    o\xda\x84pB2\x1f\x81Fa\x8c\x9c\x08\x04Z{\xcf\xa72\xbcv\xfa\xc5\x08 \x80r\x80\
    \xfc\xa2\x0e\x1c\xe4\xba\xfaX\x1d\xd0\xde]S\x07\x02\xd8>\xe1wa-`\x9fQ\xe9\
    \x86\x01\x04\x10\x00\\(Dk\x1b-\x04\xdc\x1d\x07\x14\x98;\x0bS\x7f\x7f\xf9\x13\
    \x04\x10@\xf9X\xbe\x00\xc9 \x14K\xc1<={\x00\x00\x00\x00IEND\xaeB`\x82
    '''
    J'ai fais un peu de recherche sur "cStringIO" et "StringIO" mais sans succès :/

  8. #8
    Membre Expert Avatar de pacificator
    Profil pro
    Inscrit en
    Août 2006
    Messages
    1 074
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 1 074
    Par défaut ..: faute de frappe :..
    Salut Mysti¢
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    >>> open('monImage.png', 'rb').read()
    '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\x00
    \x00\x00\x1f\xf3\xffa\x00\x00\x00\x01sRGB\x00\xae\xce\x1c\xe9\x00\x00\x00\x04gAM
    A\x00\x00\xb1\x8f\x0b\xfca\x05\x00\x00\x00 cHRM\x00\x00z&\x00\x00\x80\x84\x00\x0
    ...
    Si tu fais ca dans un interpreteur, cela affichera le contenu du fichier image sous forme de texte.

    StringIO.StringIO() sert à créer un pseudo-fichier, il prend en parametre une chaine de caractère et permet de l'utiliser comme un fichier ouvert, avec les mêmes methodes (read, write, seek, close, ...).

    Il est possible d'utiliser le modules base64 pour eviter les mauvaise surprise (on ne sait jamais...)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    >>> import base64
    >>> im = base64.encodestring(open('monImage.png', 'rb').read())
    >>> print im
    iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6Q
    AAAARnQU1BAACxjwv8YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAA
    DqYAAAOpgAABdwnLpRPAAAApFJREFUOE91k+tLU2Ecx8/0HwoqCprzxrSQXkQQ0
    ZsKi5KokC5YoERg4ZugqBdSy7VNmzpnJShmXpaNTfMy...
    a utiliser avec base64.decodestring()

  9. #9
    Membre confirmé Avatar de Mysti¢
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    155
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 155
    Par défaut
    Je vais essayer ça, merci

    Edit:
    Ca fonctionne, mais j'arrive à l'utiliser uniquement pour afficher une image, pas pour l'icone.

    Désolé pour la longue chaine en base64:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    import wx
    import StringIO
    import base64
    plus='''iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAAsTAAALEwEAmpwYAAAK
    T2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AU
    kSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXX
    Pues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgAB
    eNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAt
    AGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3
    AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dX
    Lh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+
    5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk
    5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJIEyXYFHBPjgwsz0TKUcz5IJhGLc5o9H/LcL//wd
    0yLESWK5WCoU41EScY5EmozzMqUiiUKSKcUl0v9k4t8s+wM+3zUAsGo+AXuRLahdYwP2SycQWHTA
    4vcAAPK7b8HUKAgDgGiD4c93/+8//UegJQCAZkmScQAAXkQkLlTKsz/HCAAARKCBKrBBG/TBGCzA
    BhzBBdzBC/xgNoRCJMTCQhBCCmSAHHJgKayCQiiGzbAdKmAv1EAdNMBRaIaTcA4uwlW4Dj1wD/ph
    CJ7BKLy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ZftJ+7P3P66Jqun4lvttXa1ObXHtxwPSA/0HIw6217nU1R3S
    PVRSj9Yr60cOxx++/p3vdy0NNg1VjZzG4iNwRHnk6fcJ3/ceDTradox7rOEH0x92HWcdL2pCmvKa
    RptTmvtbYlu6T8w+0dbq3nr8R9sfD5w0PFl5SvNUyWna6YLTk2fyz4ydlZ19fi753GDborZ752PO
    32oPb++6EHTh0kX/i+c7vDvOXPK4dPKy2+UTV7hXmq86X23qdOo8/pPTT8e7nLuarrlca7nuer21
    e2b36RueN87d9L158Rb/1tWeOT3dvfN6b/fF9/XfFt1+cif9zsu72Xcn7q28T7xf9EDtQdlD3YfV
    P1v+3Njv3H9qwHeg89HcR/cGhYPP/pH1jw9DBY+Zj8uGDYbrnjg+OTniP3L96fynQ89kzyaeF/6i
    /suuFxYvfvjV69fO0ZjRoZfyl5O/bXyl/erA6xmv28bCxh6+yXgzMV70VvvtwXfcdx3vo98PT+R8
    IH8o/2j5sfVT0Kf7kxmTk/8EA5jz/GMzLdsAAAAEZ0FNQQAAsY58+1GTAAAAIGNIUk0AAHolAACA
    gwAA+f8AAIDpAAB1MAAA6mAAADqYAAAXb5JfxUYAAAGKSURBVHjatJRbattQEIY/xXLsLjBLKV1B
    HrKWbqCLyJNxk4eAW0INLa6xY0lzbpKnDyPb0IBEa2lgGDhnzv/P7UymqowpeZ/D4wINEcSZlgKH
    AooK3gq4/0jW9f6mjyAm8MFUvBFUrS2lP4NeghDBBagcVHLRwQhcAOdBgkUuHkpnKn6AHpzAxYN4
    pXSWjQt2TncL+jM4gzu1DAK4aNbHAUrkI7igZ0AXzYYaYtNPkKkqyxc01tbQ07RUDsoKCoFClKKy
    0SzFrDjrSSXmXzfw95dafcmyHKA5Qqoh1uDTJVKXwCfFRzsPNexK2BcWQEhwPEKWwzTvaHJslNTY
    g5BaktSSRFhvlV9b2LXAJ5lMYdJdICNIbeQncJdge4DVWllv4Pf+8mQ2/49VEeqLHgS+fjfwXdGC
    frhyF4W2/qufsPym/NjY5e18oGUXa3h6hcVKOci/l6GX4HmtLF4Vfxwm6nf/oEvuHppOh8+fJtlV
    u+jajPoJZiMTTG9HJ9BxCfKxM8jzkcf0WvkzAHPJHent58K0AAAAAElFTkSuQmCC'''
    class MyFrame(wx.Frame):
        def __init__(self, parent, id, title):
            wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(150, 150))
            img2 = base64.decodestring(plus)
     
            a=StringIO.StringIO(img2)
     
            img=wx.BitmapFromImage(wx.ImageFromStream(a))
     
            image = wx.StaticBitmap(self, -1, img)
     
            icone = wx.EmptyIcon()
            icone.CopyFromBitmap(img)
            self.SetIcon(icone)	   
    class MyApp(wx.App):   
        def OnInit(self):
            frame = MyFrame(None, -1, 'ImageFromStream')
            frame.Show(True)  
            frame.Centre()  
            return True  
     
    app = MyApp(0) 
    app.MainLoop()

  10. #10
    Membre Expert Avatar de pacificator
    Profil pro
    Inscrit en
    Août 2006
    Messages
    1 074
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 1 074
    Par défaut
    Essaye de retailler ton image en 16*16 pixels.

  11. #11
    Membre confirmé Avatar de Mysti¢
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    155
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 155
    Par défaut
    Ca venait bien de la taille de l'image, j'ai modifié certaines variables pour la lisibilité :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    import wx
    import StringIO
    import base64
    add_png='''iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAAsTAAALEwEAmpwYAAAK
    T2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AU
    kSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXX
    Pues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgAB
    eNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAt
    AGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3
    AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dX
    Lh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+
    5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk
    5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJIEyXYFHBPjgwsz0TKUcz5IJhGLc5o9H/LcL//wd
    0yLESWK5WCoU41EScY5EmozzMqUiiUKSKcUl0v9k4t8s+wM+3zUAsGo+AXuRLahdYwP2SycQWHTA
    4vcAAPK7b8HUKAgDgGiD4c93/+8//UegJQCAZkmScQAAXkQkLlTKsz/HCAAARKCBKrBBG/TBGCzA
    BhzBBdzBC/xgNoRCJMTCQhBCCmSAHHJgKayCQiiGzbAdKmAv1EAdNMBRaIaTcA4uwlW4Dj1wD/ph
    CJ7BKLyBCQRByAgTYSHa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qun4lvttXa1ObXHtxwPSA/0HIw6217nU1R3S
    PVRSj9Yr60cOxx++/p3vdy0NNg1VjZzG4iNwRHnk6fcJ3/ceDTradox7rOEH0x92HWcdL2pCmvKa
    RptTmvtbYlu6T8w+0dbq3nr8R9sfD5w0PFl5SvNUyWna6YLTk2fyz4ydlZ19fi753GDborZ752PO
    32oPb++6EHTh0kX/i+c7vDvOXPK4dPKy2+UTV7hXmq86X23qdOo8/pPTT8e7nLuarrlca7nuer21
    e2b36RueN87d9L158Rb/1tWeOT3dvfN6b/fF9/XfFt1+cif9zsu72Xcn7q28T7xf9EDtQdlD3YfV
    P1v+3Njv3H9qwHeg89HcR/cGhYPP/pH1jw9DBY+Zj8uGDYbrnjg+OTniP3L96fynQ89kzyaeF/6i
    /suuFxYvfvjV69fO0ZjRoZfyl5O/bXyl/erA6xmv28bCxh6+yXgzMV70VvvtwXfcdx3vo98PT+R8
    IH8o/2j5sfVT0Kf7kxmTk/8EA5jz/GMzLdsAAAAEZ0FNQQAAsY58+1GTAAAAIGNIUk0AAHolAACA
    gwAA+f8AAIDpAAB1MAAA6mAAADqYAAAXb5JfxUYAAAGKSURBVHjatJRbattQEIY/xXLsLjBLKV1B
    HrKWbqCLyJNxk4eAW0INLa6xY0lzbpKnDyPb0IBEa2lgGDhnzv/P7UymqowpeZ/D4wINEcSZlgKH
    AooK3gq4/0jW9f6mjyAm8MFUvBFUrS2lP4NeghDBBagcVHLRwQhcAOdBgkUuHkpnKn6AHpzAxYN4
    pXSWjQt2TncL+jM4gzu1DAK4aNbHAUrkI7igZ0AXzYYaYtNPkKkqyxc01tbQ07RUDsoKCoFClKKy
    0SzFrDjrSSXmXzfw95dafcmyHKA5Qqoh1uDTJVKXwCfFRzsPNexK2BcWQEhwPEKWwzTvaHJslNTY
    g5BaktSSRFhvlV9b2LXAJ5lMYdJdICNIbeQncJdge4DVWllv4Pf+8mQ2/49VEeqLHgS+fjfwXdGC
    frhyF4W2/qufsPym/NjY5e18oGUXa3h6hcVKOci/l6GX4HmtLF4Vfxwm6nf/oEvuHppOh8+fJtlV
    u+jajPoJZiMTTG9HJ9BxCfKxM8jzkcf0WvkzAHPJHent58K0AAAAAElFTkSuQmCC'''
    class MyFrame(wx.Frame):
        def __init__(self, parent, id, title):
            wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(150, 150))
            src_image_b64 = base64.decodestring(add_png)
     
            src_img=StringIO.StringIO(src_image_b64)
     
            img=wx.BitmapFromImage(wx.ImageFromStream(src_img))
     
            icon = img.ConvertToImage()
            icon = icon.Scale(16, 16)
     
            icon = icon.ConvertToBitmap()		
            image = wx.StaticBitmap(self, -1, img)
     
            icone = wx.EmptyIcon()
            icone.CopyFromBitmap(icon)
            self.SetIcon(icone)	   
    class MyApp(wx.App):   
        def OnInit(self):
            frame = MyFrame(None, -1, 'ImageFromStream')
            frame.Show(True)  
            frame.Centre()  
            return True  
     
    app = MyApp(0) 
    app.MainLoop()
    Encore Merci

  12. #12
    Membre Expert Avatar de pacificator
    Profil pro
    Inscrit en
    Août 2006
    Messages
    1 074
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 1 074
    Par défaut
    Salut Mysti¢,

    Pour être plus explicite, je ferais:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
            string_png = base64.decodestring(add_png)
     
            stream_png = StringIO.StringIO(string_png)
     
            img = wx.ImageFromStream(stream_png)
            bitmap = wx.BitmapFromImage(img)
            image_icone = img.Scale(16, 16)
     
            static_bitmap = wx.StaticBitmap(self, -1, bitmap)
     
            icone = wx.EmptyIcon()
            icone.CopyFromBitmap(wx.BitmapFromImage(image_icone))
     
            self.SetIcon(icone)
    Qu'en penses-tu?

  13. #13
    Membre confirmé Avatar de Mysti¢
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    155
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 155
    Par défaut
    Ouep c'est encore plus explicite
    J'ai été un peu rapide mais c'était juste pour voir si ça fonctionnait (il devais être 2h40 ).
    Dans mon programme j'ai pas appelé les variables pareil.

  14. #14
    Membre Expert Avatar de pacificator
    Profil pro
    Inscrit en
    Août 2006
    Messages
    1 074
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 1 074
    Par défaut
    Pas de problème.

    Bonne continuation, bon python.

  15. #15
    Membre confirmé Avatar de Mysti¢
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    155
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 155
    Par défaut
    Merci, à toi aussi

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Kylix] Kylix embarqué sur PDA ?
    Par Anonymous dans le forum NoSQL
    Réponses: 10
    Dernier message: 29/11/2002, 13h59
  2. Main icon (16 bits)
    Par DR dans le forum C++Builder
    Réponses: 2
    Dernier message: 02/09/2002, 08h23
  3. Attribuer une icone à une application
    Par k_boy dans le forum x86 32-bits / 64-bits
    Réponses: 4
    Dernier message: 31/08/2002, 01h38
  4. [FORMS] Chemin des icones (intégré FAQ 150 QR)
    Par jerome62 dans le forum Forms
    Réponses: 2
    Dernier message: 30/07/2002, 08h32
  5. [Kylix] icone associée à un programme
    Par Anonymous dans le forum EDI
    Réponses: 1
    Dernier message: 22/03/2002, 09h43

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo