473,839 Members | 1,395 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

draw an image in wx.BufferedDC onto the page created by AddPage of wx.Notebook

Hi everyone,
I have tried two days to figure out how to draw the image in
wx.BufferedDC on the page created by AddPage of wx.Notebook but still
got no clue.

The attached example works fine. If I click the menu "Draw" --"New
Drawing". The image with wx.BufferedDC/wx.BufferedPain tDC can move
around on the frame. But If I uncomment those three commented lines in
"class TestFrame" to add a new page (from wx.Notebook) with a tag and
modify the last line like
self.Window = DrawWindow(form 2)
I can not see the image from wx.BufferedDC anywhere and don't know what
is going on.

I need your help. Thanks a lot.
The attached example is based on the example on the site:

import wx
import random
import os,time


def opj(path):
"""Convert paths to the platform-specific separator"""
str = apply(os.path.j oin, tuple(path.spli t('/')))
# HACK: on Linux, a leading / gets lost...
if path.startswith ('/'):
str = '/' + str
return str
class BufferedWindow( wx.Window):
def __init__(self, parent, id,
pos = wx.DefaultPosit ion,
size = wx.DefaultSize,
wx.Window.__ini t__(self, parent, id, pos, size, style)

self.Bind(wx.EV T_PAINT, self.OnPaint)
self.Bind(wx.EV T_SIZE, self.OnSize)

self.bmp0 = wx.Image(opj('i mage.bmp'), wx.BITMAP_TYPE_ BMP)
self.bmp0.SetMa sk(True)
self.bmp = self.bmp0.Rotat e(1.1215, (50,10), True,None)
self.bmp = self.bmp.Conver tToBitmap()
self.x = 100
self.y = 100
self.angle = 0.0
self.OnSize(Non e)

def Draw(self,dc):

def OnPaint(self, event):
dc = wx.BufferedPain tDC(self, self._Buffer)
dc = wx.PaintDC(self )
dc.DrawBitmap(s elf._Buffer,0,0 )

def OnSize(self,eve nt):
self.Width, self.Height = self.GetClientS izeTuple()
self._Buffer = wx.EmptyBitmap( self.Width, self.Height)
self.UpdateDraw ing()

def SaveToFile(self ,FileName,FileT ype):
self._Buffer.Sa veFile(FileName ,FileType)

def UpdateDrawing(s elf):
dc = wx.BufferedDC(w x.ClientDC(self ), self._Buffer)
# update the buffer
dc = wx.MemoryDC()
dc.SelectObject (self._Buffer)

# update the screen
wx.ClientDC(sel f).Blit(0, 0, self.Width, self.Height, dc,
0, 0)

class DrawWindow(Buff eredWindow):
def __init__(self, parent, id = -1):
BufferedWindow. __init__(self, parent, id)

def Draw(self, dc):
dc.BeginDrawing ()
dc.SetBackgroun d( wx.Brush("White ") )
dc.Clear() # make sure you clear the bitmap!
bmp = self.bmp0.Rotat e(self.angle, (self.x,self.y) , True,None)
bmp = bmp.ConvertToBi tmap()
dc.DrawBitmap(b mp, self.x,self.y, True)

class TestFrame(wx.Fr ame):
def __init__(self):
wx.Frame.__init __(self, None, -1, "Double Buffered Test",
wx.DefaultPosit ion,

MenuBar = wx.MenuBar()
file_menu = wx.Menu()
ID_EXIT_MENU = wx.NewId()
file_menu.Appen d(ID_EXIT_MENU, "E&xit","Termin ate the program")
self.Bind(wx.EV T_MENU, self.OnQuit, id=ID_EXIT_MENU )
MenuBar.Append( file_menu, "&File")

draw_menu = wx.Menu()
ID_DRAW_MENU = wx.NewId()
draw_menu.Appen d(ID_DRAW_MENU, "&New Drawing","Updat e the
Drawing Data")
self.Bind(wx.EV T_MENU, self.NewDrawing , id=ID_DRAW_MENU )
BMP_ID = wx.NewId()
draw_menu.Appen d(BMP_ID,'&Save Drawing\tAlt-I','')
self.Bind(wx.EV T_MENU, self.SaveToFile , id=BMP_ID)
MenuBar.Append( draw_menu, "&Draw")

self.SetMenuBar (MenuBar)

#nb = wx.Notebook(sel f, -1)
#form2 = Form2(nb, -1)
#nb.AddPage(for m2, "Sizers")

self.Window = DrawWindow(self )

def OnQuit(self,eve nt):
self.Close(True )

def NewDrawing(self ,event):
if event==None:
self.Window.Upd ateDrawing()
self.Window.y = 100
for i in range(10):
self.Window.y = self.Window.y + 5
self.Window.ang le = self.Window.ang le+0.1*1
self.Window.Upd ateDrawing()

def SaveToFile(self ,event):
dlg = wx.FileDialog(s elf, "Choose a file name to save the image
as a PNG to",
defaultDir = "",
defaultFile = "",
wildcard = "*.png",
if dlg.ShowModal() == wx.ID_OK:
self.Window.Sav eToFile(dlg.Get Path(),wx.BITMA P_TYPE_PNG)

class Form2(wx.Panel) :
def __init__(self, parent, id):
wx.Panel.__init __(self, parent, -1)

class DemoApp(wx.App) :
def OnInit(self):
wx.InitAllImage Handlers() # called so a PNG can be saved
frame = TestFrame()
frame.Show(True )

frame.NewDrawin g(None)

self.SetTopWind ow(frame)

return True

if __name__ == "__main__":
app = DemoApp(0)

Aug 10 '06 #1
1 4354
zxo102 wrote:
Hi everyone,
I have tried two days to figure out how to draw the image in
wx.BufferedDC on the page created by AddPage of wx.Notebook but still
got no clue.

The attached example works fine. If I click the menu "Draw" --"New
Drawing". The image with wx.BufferedDC/wx.BufferedPain tDC can move
around on the frame. But If I uncomment those three commented lines in
"class TestFrame" to add a new page (from wx.Notebook) with a tag and
modify the last line like
self.Window = DrawWindow(form 2)
I can not see the image from wx.BufferedDC anywhere and don't know what
is going on.

I need your help. Thanks a lot.
Have you tried http://wiki.wxpython.org/index.cgi/Asking_For_Help


Aug 10 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: F. GEIGER | last post by:
Hi again, I'd like to rename a page of a notebook. Deleting the page and adding a new one is not really an option, because the page is filled with other controls already. So I looked into Pmw.Notebook. There are quite a few lists and dicts which were to be changed and I wasn't successful in the first try. However, if nobody has ever done this, I'd have to rebuild the whole page after deleting/adding. I really hope there's an other way...
by: DraguVaso | last post by:
Hi, I have an inherited DataGrid, that does lots of extra stuff. For exemple drawing a backgroundimage in every cell. The problem is that it's taking too much time (using gdi+), so I want to do it using DirectX. I downloaded already the DSK etc, but I can't find how I need to draw an image on a given position. I don't need stuff to write advanced 3D-games, just painting that image. Can anybody help me with this? I'm already looking for...
by: Young H. Rhiu | last post by:
See: http://hilug.org/img/app_layout.GIF I'm implementing an album-like application with wxpython but I'm new to wxPython though I know how to program with python. The problem is that it's not easy for me to deal with drawing layout stuff with wxpython. What layout I'm thinking of looks like the gif image above. The application is about saving some comments for each pictures on the filesystem. There are two windows. The above one is a...
by: Jheitmuller | last post by:
Hi, I would like to convert a VB.NET application from being a Windows app to an ASP.NET app. I'm new to web development, so this may be a simple question. Is it possible to render simple drawing commands in an ASP.NET application? Something line draw a line point to point, or draw a circle at this point. If so, can somebody point me toward the library or technique to use? I can figure it out if I can get pointed in the right...
by: Rob Willaar | last post by:
Hi All, I try to draw text on a picturebox. The text appears but it is drawn on top of the picture. when i try to save the result the text is gone.
by: news | last post by:
If anyone can recommend a more appropriate newsgroup for this question? We recently upgraded from php 4.1.2 to php 4.3.9 and ImageMagick 5.5.7 to version 6.2.5. I have a script that creates a random number image as a Turing Test, and without changing that, it's stopped working right after the upgrade. But, only part of the mogrify command. Here's the line I'm using:
by: mrajanikrishna | last post by:
Hello friends, I have developed an application using ASP.NET and SQL Server. Ours is a garment factory. I need to design another module in my application. I want to generate images on fly based on users selection(body, sleeve etc). Until here no problem. Coz we have only 2 types of bodies and 3 types of sleeves and 3 types of necks. I can design static images and save in
by: myjpa1 | last post by:
Hi, all, I want to draw image directly onto top of screen, which simulates the OSD(on screen display) effects. However, class Graphics must link to certain controls, that cannot be used to draw at an arbitary position. Does anyone know any approaches can perform this job? thanks,
by: benfly08 | last post by:
Hi, guys. I have a program to draw bar/pie chart based on the data i hard coded in it. However, my image comes with "BLACK" background color. I don't know how to fix this. The code snippet is below: chartGenerator.vb class: Imports System.Drawing.Imaging Public Class chartGenerator Private myImage As Bitmap
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.