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 :

images du presse papier


Sujet :

wxPython

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    262
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2005
    Messages : 262
    Points : 93
    Points
    93
    Par défaut images du presse papier
    Bonjour à tous,

    J'essaie de comprendre le fonctionnement du presse-papier. Voici un script pour expliquer ce que je ne comprend pas :

    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
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    # !/usr/bin/python
    # -*- coding:Latin-1 -*-
     
    import wx
    import wx.richtext as rt
     
    class Fentre_prin(wx.Frame):
        def __init__(self, parent, title): 
            wx.Frame.__init__(self, parent, -1, title,size=(800,600))
     
    	self.MonMenu()
     
    	ma_scroll_window = wx.ScrolledWindow(self)
    	ma_scroll_window.SetBackgroundColour(wx.WHITE)
    	ma_scroll_window.SetScrollbars(20, 20, 55, 40)
     
    	### bouton :
            b1 = wx.Button(ma_scroll_window, -1, u"Récupérer le texte sélectionné")
            self.Bind(wx.EVT_BUTTON, self.presse_papier1, b1)
    	b2 = wx.Button(ma_scroll_window, -1, u"Récupérer l'image sélectionnée")
            self.Bind(wx.EVT_BUTTON, self.presse_papier2, b2)
    	b3 = wx.Button(ma_scroll_window, -1, u"Récupérer autre image")
            self.Bind(wx.EVT_BUTTON, self.presse_papier3, b3)
    	### richtext :
    	self.ma_RichText= rt.RichTextCtrl(ma_scroll_window, -1, "",size=(700,400))
    	self.ma_RichText.WriteText('Bonjour ')
    	###  Image de départ :
    	image1=wx.Image("chien.jpg")
    	self.ma_RichText.WriteImage(image1)
            self.ma_RichText.Layout()
     
    	# Création du sizer et positionnement des wigets :
    	sizer = wx.BoxSizer(wx.VERTICAL)
            sizer.Add(b1, 0, wx.ALL, 5)
    	sizer.Add(b2, 0, wx.ALL, 5)
    	sizer.Add(b3, 0, wx.ALL, 5)
    	sizer.Add(self.ma_RichText, 0, wx.ALL, 5)
           	# Le sizer est lié au conteneur :
            ma_scroll_window.SetSizer(sizer)
            ma_scroll_window.Layout()
     
        def MonMenu(self):
    	'''   Crée un Menu et ses sous-menu.   '''
    	def doBind(item, handler, updateUI=None):
    	    self.Bind(wx.EVT_MENU, handler, item)
    	    if updateUI is not None:
    		self.Bind(wx.EVT_UPDATE_UI, updateUI, item)
     
    	### Menu Edition :
    	menuEdition = wx.Menu()
    	doBind( menuEdition.Append(wx.ID_CUT, "Couper\tCtrl+X"),
    		self.suivi_des_evenements, self.suivi_des_evenements )
    	doBind( menuEdition.Append(wx.ID_COPY, "&Copier\tCtrl+C"),
    		self.suivi_des_evenements, self.suivi_des_evenements)
    	doBind( menuEdition.Append(wx.ID_PASTE, "&Coller\tCtrl+V"),
    		self.suivi_des_evenements, self.suivi_des_evenements)
     
    	### Titres des menus
    	BarreTitreDesMenus= wx.MenuBar()
    	BarreTitreDesMenus.Append(menuEdition, "&Edition")
    	self.SetMenuBar(BarreTitreDesMenus)
     
        def suivi_des_evenements(self, evt):
    	self.ma_RichText.ProcessEvent(evt)
     
     
        def presse_papier1(self, evt):
    	wx.TheClipboard.Open()
    	data=wx.TextDataObject()
    	wx.TheClipboard.GetData(data)
    	wx.TheClipboard.Close()
    	texte=data.GetText()
    	print'texte : ',texte
    	self.ma_RichText.WriteText(texte)
    	print'Le contenu est de type :',type(texte) ###  <type 'unicode'>
     
        def presse_papier2(self, evt):
    	wx.TheClipboard.Open()    
    	data=wx.BitmapDataObject()
    	wx.TheClipboard.GetData(data)
    	imageBMP=data.GetBitmap()
    	print'imageBMP : ',imageBMP
    	print'Le contenu est de type :',type(imageBMP) ### <class 'wx._gdi.Bitmap'>
    	imageIMG=imageBMP.ConvertToImage()
     
        def presse_papier3(self, evt):
    	### Charement d'1 image et convertion de celle-ci en Bitmap :
    	imageIMG1=wx.Image("chien.jpg")
    	imageBMP= wx.BitmapFromImage(imageIMG1)
    	### L'image est chargée dans le presse-papier :
    	wx.TheClipboard.SetData(wx.BitmapDataObject(imageBMP))
    	wx.TheClipboard.Close()
    	### L'image est lu depuis le presse-papier :	
    	data=wx.BitmapDataObject()
    	wx.TheClipboard.GetData(data)
    	wx.TheClipboard.Close()
    	contenu=data.GetBitmap()
    	print'contenu : ',contenu ###  <wx._gdi.Bitmap; proxy of <Swig Object of type 'wxBitmap *' at 0x164a1a8> >
    	print'Le contenu est de type :',type(contenu) ### <class 'wx._gdi.Bitmap'>
    	imageIMG2=contenu.ConvertToImage()
    	print'contenu : ',contenu 
    	print'Le contenu est de type :',type(contenu)
    	self.ma_RichText.WriteImage(imageIMG2)
     
     
    class MyApp(wx.App):
        def OnInit(self):
            frame = Fentre_prin(None, u"Début")
            self.SetTopWindow(frame)
            frame.Show(True)
            return True
     
    try:
    	app = MyApp()
     
    except:
    	app = MyApp(redirect=True)
     
    app.MainLoop()
    La méthode presse_papier1 fonctionne et me permet de récupérer le texte auparavant copier dans le presse papier.

    La méthode presse_papier2 ne fonctionne pas. La ligne :
    imageIMG=imageBMP.ConvertToImage() renvoie un message d'erreur invalid bitmap. Alors que la méthode presse_papier3 utilise la même image et les mêmes formats.
    Voici le Traceback :
    """
    Traceback (most recent call last):
    File "version simplifiee.py", line 84, in presse_papier2
    imageIMG=imageBMP.ConvertToImage()
    File "C:\Python24\lib\site-packages\wx-2.8-msw-unicode\wx\_gdi.py", line 587, in ConvertToImage
    return _gdi_.Bitmap_ConvertToImage(*args, **kwargs)
    wx._core.PyAssertionError: C++ assertion "bmp.Ok()" failed at ..\..\src\msw\dib.cpp(148) in wxDIB::Create(): wxDIB::Create(): invalid bitmap


    D'avance merci à qui pourra m'aider.

  2. #2
    Membre régulier
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    262
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2005
    Messages : 262
    Points : 93
    Points
    93
    Par défaut
    ...Toujours mon problème d'image :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    def clipboard2(self, evt):
    	### L'image est lu depuis le presse-papier :
    	data=wx.PyBitmapDataObject ()	
    	wx.TheClipboard.GetData(data) 
    	wx.TheClipboard.Close()
    	contenu=data.GetBitmap()
    	imageBMP=data.GetBitmap()  
    	print'Width :', imageBMP.GetWidth()
    	print'True if bitmap data is present :', imageBMP.IsOk()
    J'ai bien:
    imageBMP : <wx._gdi.Bitmap; proxy of <Swig Object of type 'wxBitmap *' at 0x164a2e8> >
    mais :
    True if bitmap data is present : False

    Ce qui explique, je suppose le message d'erreur :
    ConvertToImage
    return _gdi_.Bitmap_ConvertToImage(*args, **kwargs)
    wx._core.PyAssertionError: C++ assertion "bmp.Ok()" failed at ..\..\src\msw\dib.cpp(148) in wxDIB::Create(): wxDIB::Create(): invalid bitmap

    lorsque j'utilise :
    imageIMG=imageBMP.ConvertToImage()

    Il semble que je recupère un bitmap mais sans les données... Merci à qui pourra m'aiguiller car je sèche...

Discussions similaires

  1. [AC-2007] Sauvegarder en VBA une image du Presse-papier dans un fichier
    Par Triton972 dans le forum IHM
    Réponses: 2
    Dernier message: 01/05/2011, 19h11
  2. Applet de récupération d'image en presse papier
    Par aelmalki dans le forum Applets
    Réponses: 2
    Dernier message: 25/03/2010, 11h50
  3. copier une image du presse papier dans un flash ?
    Par Fritzoune dans le forum Flash
    Réponses: 1
    Dernier message: 17/03/2010, 12h32
  4. Copie image dans presse-papier
    Par axel119 dans le forum Servlets/JSP
    Réponses: 1
    Dernier message: 25/11/2007, 23h57
  5. récupérer une image du presse papier
    Par amelhog dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 09/08/2005, 10h18

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