Python
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   Web Development Archives Mailing Lists Python

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Web Development Archives Sponsor:
  #1  
Old June 3rd, 2008, 05:11 AM
mega_octet mega_octet is offline
Registered User
Dev Archives Newbie (0 - 499 posts)
 
Join Date: Jun 2008
Posts: 1 mega_octet User rank is Just a Lowly Private (1 - 20 Reputation Level)  
Time spent in forums: 39 m 32 sec
Reputation Power: 0
Python - How can I get an image from a wxRichTextCtrl ?

Hi,

Here is my script :

Code:
# !/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))
	### Menu :
	self.MyMenu()
	### Scroll window :
	ma_scroll_window = wx.ScrolledWindow(self)
	ma_scroll_window.SetBackgroundColour(wx.WHITE)
	ma_scroll_window.SetScrollbars(20, 20, 55, 40)
	### button :
        b1 = wx.Button(ma_scroll_window, -1, u"Get the selected text")
        self.Bind(wx.EVT_BUTTON, self.clipboard1, b1)
	b2 = wx.Button(ma_scroll_window, -1, u"Get the selected image")
        self.Bind(wx.EVT_BUTTON, self.clipboard2, b2)
	
	### richtext :
	self.ma_RichText= rt.RichTextCtrl(ma_scroll_window, -1, "",size=(700,400))
	self.ma_RichText.WriteText('Hello ')
		
	###  Image :
	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(self.ma_RichText, 0, wx.ALL, 5)
       	# Le sizer est lié au conteneur :
        ma_scroll_window.SetSizer(sizer)
        ma_scroll_window.Layout()
	
	
    	
    def MyMenu(self):
	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 clipboard1(self, evt):
        print'---- clipboard1() ----'
	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 clipboard2(self, evt):
	print' -------- clipboard2() -------'
	### L'image est lu depuis le presse-papier :	
	data=wx.BitmapDataObject()
	print'data :',data ###  <wx._misc.BitmapDataObject; proxy of <Swig Object of type 'wxBitmapDataObject *' at 0x1dda1e0> >
	wx.TheClipboard.GetData(data) 
	wx.TheClipboard.Close()
	contenu=data.GetBitmap()
	print'contenu :',contenu ### <wx._gdi.Bitmap; proxy of <Swig Object of type 'wxBitmap *' at 0x1c94c28> >
	
	
	imageBMP=data.GetBitmap()                ### <class 'wx._gdi.Bitmap'>
	print'imageBMP :',imageBMP  ### <wx._gdi.Bitmap; proxy of <Swig Object of type 'wxBitmap *' at 0x1c91e28> >
	print'Width of the bitmap :', imageBMP.GetWidth()
	print'True if bitmap data is present :', imageBMP.IsOk()
	imageBMP.SetHeight(50)
	
	#imageIMG=imageBMP.ConvertToImage()
	


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()


In fact, I would like to get the selected image.

How can I get an image from a RichTextCtrl ? (if this image is selected or not)



Thanks for any help...

Reply With Quote
Reply

Viewing: Web Development Archives Mailing Lists Python > Python - How can I get an image from a wxRichTextCtrl ?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek