Problem: wx.ComboBox and wx.Button.SetDefault

Hello,

I have a dialog with a combobox and a button.
I use button.SetDefault to trigger a certain action
with the enter key.

So far so good.
But if I want to select an entry from the combobox
and usually pressing enter key, the focus should
jump to the next control and don't start the
default button action.

But: This selects the combobox entry AND starts the default button
action.

I tried in ComboBox in Kill Focus:
button.SetDefault ()

I would like to set on GetFocus in combobox no default button,
but I didn't find a way to set "no default button"

any other workaround?

Thank you in advance!

···

--
Franz Steinhaeusler

Franz Steinhäusler <franz.steinhaeusler@gmx.at> writes:

I have a dialog with a combobox and a button.
I use button.SetDefault to trigger a certain action
with the enter key.

So far so good.
But if I want to select an entry from the combobox
and usually pressing enter key, the focus should
jump to the next control and don't start the
default button action.

You mean the action should be something like what you get with a TAB,
selecting the button but not activating it?

But: This selects the combobox entry AND starts the default button
action.

How are you handling the EVT_COMBOBOX and EVT_TEXT_ENTER events?

I tried in ComboBox in Kill Focus:
button.SetDefault ()

It only works when you leave the control. If you leave the control, you
go to the next control -- probably -- and pressing ENTER you activate
it.

I would like to set on GetFocus in combobox no default button,
but I didn't find a way to set "no default button"

any other workaround?

Can you paste your code? I think there is some event / handler logic
error.

Be seeing you,

···

--
Godoy. <godoy@ieee.org>

Hi to all,
I've three (probably really) basic questions about this piece of code:

import wx
from random import *

class MyButt(wx.Button):
     def __init__(self, parent, panel):
         wx.Button.__init__(self, parent, -1, label="butt")
         self.Bind(wx.EVT_BUTTON, self.OnPaint)

     def OnPaint(self, event):
         ## dc.BeginDrawing()
         dc = wx.PaintDC(panel)
         a = randint(0, 50)
         b = randint (0, 50)
         dc.DrawRectangle(a, b, 30,30)
         ## dc.EndDrawing()

class MySlid(wx.Slider):
     def __init__(self, parent):
         wx.Slider.__init__(self, parent, -1, 50, 0, 100)
         self.Bind(wx.EVT_SCROLL, self.move)

     def move(self, evt):
         print self.GetValue()

class MyPanel(wx.Panel):
     def __init__(self, parent):
         wx.Panel.__init__(self, parent, -1, size=(200, 200))

if __name__ == '__main__':
     app = wx.App(0)
     frame = wx.Frame(None, -1, "test", size = (500, 200))
     panel = MyPanel(frame)
     sizer = wx.BoxSizer(wx.HORIZONTAL)
     sizer.Add(panel)
     ms = MySlid(frame)
     mb = MyButt(frame, panel)
     sizer.Add(ms)
     sizer.Add(mb)
     frame.SetSizer(sizer)
     frame.Show()
     app.MainLoop()

i) I'm on Mac. Do I need to use PaintDC.BeginDrawing() and PaintDC.EndDrawing()? (I commented them out) To do what?
ii) If I comment out the two lines in main related to the MySlid object ( "ms = MySlid(frame)" and "sizer.Add(ms)") the MyButt object does not display anything at all. Why?
iii) What have I to do to make the MyButt action repaint the rectangle and not paint i t over the preceding ones?

Thanks a lot for your kindness

-a-

I'm really sorry for the mistaken subject in my previous post. Too fast clicking while the phone is ringing.
I post it again.
-a-

···

Hi to all,
I've three (probably really) basic questions about this piece of code:

import wx
from random import *

class MyButt(wx.Button):
    def __init__(self, parent, panel):
        wx.Button.__init__(self, parent, -1, label="butt")
        self.Bind(wx.EVT_BUTTON, self.OnPaint)

    def OnPaint(self, event):
        ## dc.BeginDrawing()
        dc = wx.PaintDC(panel)
        a = randint(0, 50)
        b = randint (0, 50)
        dc.DrawRectangle(a, b, 30,30)
        ## dc.EndDrawing()

class MySlid(wx.Slider):
    def __init__(self, parent):
        wx.Slider.__init__(self, parent, -1, 50, 0, 100)
        self.Bind(wx.EVT_SCROLL, self.move)

    def move(self, evt):
        print self.GetValue()

class MyPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1, size=(200, 200))

if __name__ == '__main__':
    app = wx.App(0)
    frame = wx.Frame(None, -1, "test", size = (500, 200))
    panel = MyPanel(frame)
    sizer = wx.BoxSizer(wx.HORIZONTAL)
    sizer.Add(panel)
    ms = MySlid(frame)
    mb = MyButt(frame, panel)
    sizer.Add(ms)
    sizer.Add(mb)
    frame.SetSizer(sizer)
    frame.Show()
    app.MainLoop()

i) I'm on Mac. Do I need to use PaintDC.BeginDrawing() and PaintDC.EndDrawing()? (I commented them out) To do what?
ii) If I comment out the two lines in main related to the MySlid object ( "ms = MySlid(frame)" and "sizer.Add(ms)") the MyButt object does not display anything at all. Why?
iii) What have I to do to make the MyButt action repaint the rectangle and not paint i t over the preceding ones?

Thanks a lot for your kindness

-a-

Hello Jorge,

thank you for your reply.

Franz Steinhäusler <franz.steinhaeusler@gmx.at> writes:

I have a dialog with a combobox and a button.
I use button.SetDefault to trigger a certain action
with the enter key.

So far so good.
But if I want to select an entry from the combobox
and usually pressing enter key, the focus should
jump to the next control and don't start the
default button action.

You mean the action should be something like what you get with a TAB,

yes

selecting the button but not activating it?

no, only selecting the next field (the same, as when you press the
TAB key)

But: This selects the combobox entry AND starts the default button
action.

Can you paste your code? I think there is some event / handler logic
error.

Be seeing you,

I attach a small example.
(in my app, I have much more controls)

So: I want to change the content of the combobox by typing
a new text or choose one of the history entries.
After ENTER, the focus should be in the txtCtrl
(like moving with TAB key), in all other cases, the
Button OnClick should be activated.

···

On Mon, 18 Oct 2004 08:20:40 -0300, Jorge Godoy <godoy@ieee.org> wrote:

--
Franz Steinhaeusler

begin 644 cb.py
M:6UP;W)T("!W>`T*#0IC;VUB;U]V86QU97,@/2!;)T]P=&EO;C$G+"`G3W!T
M:6]N,B==#0H-"F-L87-S($UY0V]M8F]";W@@*'=X+D-O;6)O0F]X*3H-"B`@
M("!D968@7U]I;FET7U\@*'-E;&8L('!A<F5N="P@:60L(',L(%]S='EL92P@
M7VYA;64I.@T*("`@("`@("!W>"Y#;VUB;T)O>"Y?7VEN:71?7R`H<V5L9BP@
M<&%R96YT+"!I9"P@<RP@<W1Y;&4@/2!?<W1Y;&4L(&YA;64@/2!?;F%M92D-
M"@T*8VQA<W,@37E&<F%M92AW>"Y&<F%M92DZ#0H@("`@9&5F(%]?:6YI=%]?
M*'-E;&8L('!A<F5N="P@:60L('1I=&QE+"!P;W,@/2!W>"Y$969A=6QT4&]S
M:71I;VXL('-I>F4@/2!W>"Y3:7IE*#@P,"PV,#`I+`T*("`@("`@("`@("`@
M("`@("!S='EL92`]('=X+D1%1D%53%1?1E)!345?4U193$4@?'=X+E=!3E13
M7T-(05)3("P@;F%M93TB=&5S="(I.@T*("`@("`@("!W>"Y&<F%M92Y?7VEN
M:71?7RAS96QF+"!P87)E;G0L(&ED+"!T:71L92P@<&]S+"!S:7IE+"!S='EL
M92P@;F%M92D-"@T*("`@("`@("!P<VEZ97(@/2!W>"Y";WA3:7IE<BAW>"Y(
M3U))6D].5$%,*0T*("`@("`@("!P(#T@=W@N4&%N96PH<V5L9BP@+3$I#0H-
M"B`@("`@("`@<V5L9BYC(#T@37E#;VUB;T)O>"AP+"`M,2P@(B(L('=X+D-"
M7T123U!$3U=.+"`B;F%M95]T:71L92(I#0H@("`@("`@('-E;&8N="`]('=X
M+E1E>'1#=')L*'`L("TQ+"!S:7IE/7=X+E-I>F4H,C(U+"TQ*2P@;F%M93TB
M;6ES8U]B=7-I;F5S<U]U<FPB*0T*("`@("`@("!S96QF+F(@/2!W>"Y"=71T
M;VXH<"P@+3$L(")#;&EC:R(I#0H-"B`@("`@("`@<'-I>F5R+D%D9"AS96QF
M+F,I#0H@("`@("`@('!S:7IE<BY!9&0H<V5L9BYT*0T*("`@("`@("!P<VEZ
M97(N061D*'-E;&8N8BD-"@T*("`@("`@("!S96QF+F(N0FEN9"AW>"Y%5E1?
M0E545$].+"!S96QF+D]N0VQI8VLI#0H@("`@("`@('`N4V5T075T;TQA>6]U
M="@Q*0T*("`@("`@("!P+E-E=%-I>F5R06YD1FET*'!S:7IE<BD-"@T*("`@
M("`@("!F;W(@;W!T:6]N(&EN(&-O;6)O7W9A;'5E<SH-"B`@("`@("`@("`@
M('-E;&8N8RY!<'!E;F0H;W!T:6]N*0T*#0H@("`@("`@('-E;&8N8RY39716
M86QU92@G3W!T:6]N,2<I#0H@("`@("`@('-E;&8N8BY3971$969A=6QT*"D-
M"@T*("`@(&1E9B!/;D-L:6-K*'-E;&8L(&5V96YT*3H-"B`@("`@("`@<')I
M;G0@(F-L:6-K(@T*#0II9B!?7VYA;65?7R`]/2`G7U]M86EN7U\G.@T*#0H@
M("!C;&%S<R!!<'`H=W@N07!P*3H-"B`@("`@("!D968@3VY);FET*'-E;&8I
M.@T*("`@("`@("`@("!S96QF+F9R86UE(#T@37E&<F%M92A.;VYE+"`M,2P@
M(E1E<W0B*0T*("`@("`@("`@("!S96QF+F9R86UE+E-H;W<H*0T*("`@("`@
M("`@("!R971U<FX@5')U90T*#0H@("!A<'`@/2!!<'`H,"D-"B`@(&%P<"Y-
-86EN3&]O<"@I#0H-"G)U
`
end

here is a hackish solution :slight_smile:

     def OnClick(self, event):
         if self.FindFocus() is self.c:
             print "Combo"
             self.t.SetFocus()
         elif self.FindFocus() is self.t or self.b:
             print "click"

play with if-elif-else and FindFocus/SetFocus :slight_smile:

···

On Mon, 18 Oct 2004 15:07:21 +0200, Franz Steinhäusler <franz.steinhaeusler@gmx.at> wrote:

So: I want to change the content of the combobox by typing
a new text or choose one of the history entries.
After ENTER, the focus should be in the txtCtrl
(like moving with TAB key), in all other cases, the
Button OnClick should be activated.

--
Peter Damoc
Hacker Wannabe

Hello Peter,

perfect, works great,
thank you very much!

···

On Mon, 18 Oct 2004 16:38:55 +0300, "Peter Damoc" <pdamoc@gmx.net> wrote:

here is a hackish solution :slight_smile:

    def OnClick(self, event):
        if self.FindFocus() is self.c:
            print "Combo"
            self.t.SetFocus()
        elif self.FindFocus() is self.t or self.b:
            print "click"

play with if-elif-else and FindFocus/SetFocus :slight_smile:

--
Franz Steinhaeusler

Dear all,
I'm testing this very simple piece of code in order to obtain a rectangle:

import wx
import wx.lib.ogl as ogl

class RoundedRectangleShape(ogl.RectangleShape):
     def __init__(self, w=10.0, h=10.0):
         ogl.RectangleShape.__init__(self, w, h)
         self.SetCornerRadius(-0.3)

class TestWindow(ogl.ShapeCanvas):
     def __init__(self, parent):
         ogl.ShapeCanvas.__init__(self, parent)
         rect = RoundedRectangleShape()
         maxWidth = 300
         maxHeight = 300
         self.SetBackgroundColour("LIGHT BLUE") #wx.WHITE)
         self.diagram = ogl.Diagram()
         self.SetDiagram(self.diagram)
         self.diagram.SetCanvas(self)
         self.diagram.AddShape(rect)

if __name__ == '__main__':
     app = wx.App(0)
     frame = wx.Frame(None, -1, "test", size = (400, 400))
     test = TestWindow(frame)
     frame.Show()
     app.MainLoop()

But I have this (strange) error:
   File "/Users/apple/Desktop/pythontests/ogltest.py", line 24, in ?
     test = TestWindow(frame)
   File "/Users/apple/Desktop/pythontests/ogltest.py", line 12, in __init__
     rect = RoundedRectangleShape()
   File "/Users/apple/Desktop/pythontests/ogltest.py", line 6, in __init__
     ogl.RectangleShape.__init__(self, w, h)
   File "//Library/Python/2.3/wx/lib/ogl/_basic.py", line 2303, in __init__
     Shape.__init__(self)
   File "//Library/Python/2.3/wx/lib/ogl/_basic.py", line 274, in __init__
     region = ShapeRegion()
   File "//Library/Python/2.3/wx/lib/ogl/_basic.py", line 2967, in __init__
     self._font = NormalFont
NameError: global name 'NormalFont' is not defined

i) What does it mean?
ii) What have I to do to draw a rectangle with ogl?

Thanks a lot
Any help is much appreciated

-a-

Andrea Valle
Laboratorio multimediale "G. Quazza"
Facoltà di Scienze della Formazione
Università degli Studi di Torino
andrea.valle@unito.it

andrea valle wrote:
[...]

i) I'm on Mac. Do I need to use PaintDC.BeginDrawing() and PaintDC.EndDrawing()? (I commented them out) To do what?

No, but it doesn't hurt to leave them there. They are meant to be a place that the various ports of wxWidgets could do some platform specific drawing optimizations if any were available for that platform or perhaps for specific DC types. I think most (all?) current ports don't have an implementation for them at the moment.

ii) If I comment out the two lines in main related to the MySlid object ( "ms = MySlid(frame)" and "sizer.Add(ms)") the MyButt object does not display anything at all. Why?

I have no idea, but if you change it to correclty use a wx.ClientDC then it does work. wx.PaintDC is supposed to be used only from EVT_PAINT event handlers.

iii) What have I to do to make the MyButt action repaint the rectangle and not paint i t over the preceding ones?

Clear() the DC before drawing the rectangle. Be careful with this though because with more complex drawing operations there can be some flicker. (Although the mac is pretty much immune to this because it is double buffering drawing operations itself.)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

andrea valle wrote:

  File "//Library/Python/2.3/wx/lib/ogl/_basic.py", line 2967, in __init__
    self._font = NormalFont
NameError: global name 'NormalFont' is not defined

i) What does it mean?

You need to call OGLInitialize.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

It means that OGL was not initialized, so NormalFont is not
recognized. Try this:

class TestWindow(ogl.ShapeCanvas):
     def __init__(self, parent):
         ogl.OGLInitialize() ## initialize here first
         ogl.ShapeCanvas.__init__(self, parent)
         rect = RoundedRectangleShape()
         # ... and so on

My guess is that this is still not exactly what you wanted, but at
least the error and traceback should go away.

Regards,
Donnal Walter
Arkansas Children's Hospital

···

--- andrea valle <andrea.valle@unito.it> wrote:

Dear all,
I'm testing this very simple piece of code in order to obtain a
rectangle:

import wx
import wx.lib.ogl as ogl

class RoundedRectangleShape(ogl.RectangleShape):
     def __init__(self, w=10.0, h=10.0):
         ogl.RectangleShape.__init__(self, w, h)
         self.SetCornerRadius(-0.3)

class TestWindow(ogl.ShapeCanvas):
     def __init__(self, parent):
         ogl.ShapeCanvas.__init__(self, parent)
         rect = RoundedRectangleShape()
         maxWidth = 300
         maxHeight = 300
         self.SetBackgroundColour("LIGHT BLUE") #wx.WHITE)
         self.diagram = ogl.Diagram()
         self.SetDiagram(self.diagram)
         self.diagram.SetCanvas(self)
         self.diagram.AddShape(rect)

if __name__ == '__main__':
     app = wx.App(0)
     frame = wx.Frame(None, -1, "test", size = (400, 400))
     test = TestWindow(frame)
     frame.Show()
     app.MainLoop()

But I have this (strange) error:
     self._font = NormalFont
NameError: global name 'NormalFont' is not defined

i) What does it mean?

Thanks a lot
sorry to bother you with this: but now I have a nice light blue canvas, but I do not see the rectangle. Evidently, I'm missing something.
What have I to do?

Thanks for your attention

-a-

···

On 19 Oct 2004, at 02:08, Donnal Walter wrote:

--- andrea valle <andrea.valle@unito.it> wrote:

Dear all,
I'm testing this very simple piece of code in order to obtain a
rectangle:

import wx
import wx.lib.ogl as ogl

class RoundedRectangleShape(ogl.RectangleShape):
     def __init__(self, w=10.0, h=10.0):
         ogl.RectangleShape.__init__(self, w, h)
         self.SetCornerRadius(-0.3)

class TestWindow(ogl.ShapeCanvas):
     def __init__(self, parent):
         ogl.ShapeCanvas.__init__(self, parent)
         rect = RoundedRectangleShape()
         maxWidth = 300
         maxHeight = 300
         self.SetBackgroundColour("LIGHT BLUE") #wx.WHITE)
         self.diagram = ogl.Diagram()
         self.SetDiagram(self.diagram)
         self.diagram.SetCanvas(self)
         self.diagram.AddShape(rect)

if __name__ == '__main__':
     app = wx.App(0)
     frame = wx.Frame(None, -1, "test", size = (400, 400))
     test = TestWindow(frame)
     frame.Show()
     app.MainLoop()

But I have this (strange) error:
     self._font = NormalFont
NameError: global name 'NormalFont' is not defined

i) What does it mean?

It means that OGL was not initialized, so NormalFont is not
recognized. Try this:

class TestWindow(ogl.ShapeCanvas):
     def __init__(self, parent):
         ogl.OGLInitialize() ## initialize here first
         ogl.ShapeCanvas.__init__(self, parent)
         rect = RoundedRectangleShape()
         # ... and so on

My guess is that this is still not exactly what you wanted, but at
least the error and traceback should go away.

Regards,
Donnal Walter
Arkansas Children's Hospital

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Andrea Valle
Laboratorio multimediale "G. Quazza"
Facoltà di Scienze della Formazione
Università degli Studi di Torino
andrea.valle@unito.it

andrea valle <andrea.valle@unito.it> writes:

> Thanks a lot
> sorry to bother you with this: but now I have a nice light blue canvas,
> but I do not see the rectangle. Evidently, I'm missing something.
> What have I to do?
>
After self.diagram.AddShape(rect)
add rect.Show(True)

···

--
  Pierre Hjälm - Who is thinking about how to get rid of OGLInitialize

The idea was: press the button, clear the drawing space and generate a new rectangle with random position.
I changed PaintDC with ClientDC but it seems I didn't solve the problem.
If I put the line "self.dc = wx.ClientDC(panel)" in the __init__ of the Button I obtain nothing, if I put it in the OnPaint def I obtain the same result as before.
I suppose there's (also) a design error.
Any help is much appreciated
Best

-a-

import wx
from random import *

class MyButt(wx.Button):
     def __init__(self, parent, panel):
         wx.Button.__init__(self, parent, -1, label="butt")
         self.Bind(wx.EVT_BUTTON, self.OnPaint)
         self.dc = wx.ClientDC(panel)

     def OnPaint(self, event):
         ## dc.BeginDrawing()
         self.dc.Clear()
         a = randint(0, 50)
         b = randint (0, 50)
         self.dc.DrawRectangle(a, b, 30,30)
         ## dc.EndDrawing()

class MyPanel(wx.Panel):
     def __init__(self, parent):
         wx.Panel.__init__(self, parent, -1, size=(200, 200))

if __name__ == '__main__':
     app = wx.App(0)
     frame = wx.Frame(None, -1, "test", size = (500, 500))
     panel = MyPanel(frame)
     mb = MyButt(frame, panel)
     mb.SetPosition((210, 210))
     frame.Show()
     app.MainLoop()

andrea valle wrote:

The idea was: press the button, clear the drawing space and generate a new rectangle with random position.

OK, got it.

I changed PaintDC with ClientDC but it seems I didn't solve the problem.
If I put the line "self.dc = wx.ClientDC(panel)" in the __init__ of the Button I obtain nothing,

you don't want to store a DC like that anyway, you need to create it when you need it.

if I put it in the OnPaint def I obtain the

same result as before.
I suppose there's (also) a design error.

Yes, that's your core problem. You don't' need a custom button class, you need a custom wx.Panel(or a wx.Window would do), to do the drawing in, and a custom wx.Frame to put the button and Panel on.

I've enclosed a version that I think does what you want. I totally re-structured it, and I took the liberty of laying things out with a Sizer, I NEVER use explicit positioning.

Make sure you look in the Wiki at:

http://wiki.wxpython.org/index.cgi/RecipesImagesAndGraphics

(and everywhere else, there's a lot of info in there)

Also, if you need to draw stuff like this, and don't want to deal with all the wx.PaintDCs and all, check out the FloatCanvas, it's in the demo in recent releases.

-Chris

PaintDemo.py (1.23 KB)

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Thanks Chris,
but:
i) I have no module fixdc. Anycase I elimited it and suppose it works the same.
ii) In one of my indecent designs I obtained a similar result. Now, apart from design, how can I delete the previous rectangle and have *only one* rect at time on the screen? The idea effectively was: you press the button and the rect change position.

Thanks
Best
-a-

···

On 19 Oct 2004, at 18:47, Chris Barker wrote:

andrea valle wrote:

The idea was: press the button, clear the drawing space and generate a new rectangle with random position.

OK, got it.

I changed PaintDC with ClientDC but it seems I didn't solve the problem.
If I put the line "self.dc = wx.ClientDC(panel)" in the __init__ of the Button I obtain nothing,

you don't want to store a DC like that anyway, you need to create it when you need it.

if I put it in the OnPaint def I obtain the

same result as before.
I suppose there's (also) a design error.

Yes, that's your core problem. You don't' need a custom button class, you need a custom wx.Panel(or a wx.Window would do), to do the drawing in, and a custom wx.Frame to put the button and Panel on.

I've enclosed a version that I think does what you want. I totally re-structured it, and I took the liberty of laying things out with a Sizer, I NEVER use explicit positioning.

Make sure you look in the Wiki at:

http://wiki.wxpython.org/index.cgi/RecipesImagesAndGraphics

(and everywhere else, there's a lot of info in there)

Also, if you need to draw stuff like this, and don't want to deal with all the wx.PaintDCs and all, check out the FloatCanvas, it's in the demo in recent releases.

-Chris

--
Christopher Barker, Ph.D.
Oceanographer
                                        
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov
#!/usr/bin/python2.3

import fixdc
import wx
from random import *

class MyPanel(wx.Panel):
    def __init__(self, parent, size, position):
        wx.Panel.__init__(self, parent, -1, size=size, pos=position)
        self.NewRect()

        self.Bind(wx.EVT_PAINT, self.OnPaint)

    def OnPaint(self, event):
        dc = wx.PaintDC(self)
        dc.Clear()
        dc.DrawRectangle(*self.rect)

    def NewRect(self):
        self.rect = (randint(0, 300), randint(0, 300), 50, 50)

    def DrawRect(self):
        self.NewRect()
        dc = wx.ClientDC(self)
        dc.Clear()
        dc.DrawRectangle(*self.rect)

class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1,"test", size = (500, 500))
        button = wx.Button(self, -1, label="butt")
        button.Bind(wx.EVT_BUTTON, self.UpdatePanel)

        self.Panel = MyPanel(self, (200,200), (100,250))

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(button,0,wx.ALIGN_CENTER | wx.ALL, 10)
        sizer.Add(self.Panel,1,wx.EXPAND)

        self.SetSizer(sizer)

    def UpdatePanel(self,event):
        self.Panel.DrawRect()

if __name__ == '__main__':
    app = wx.App(0)
    frame = MyFrame()
    frame.Show()
    app.MainLoop()

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Andrea Valle
Laboratorio multimediale "G. Quazza"
Facoltà di Scienze della Formazione
Università degli Studi di Torino
andrea.valle@unito.it

andrea valle wrote:

Thanks Chris,

you're welcome.

i) I have no module fixdc. Anycase I elimited it and suppose it works the same.

somewhere in the middle of the 2.5 development series the DC sapi changed, then changed back. fixdc makes all versions work the same, but you only need it for the "weird" version of wxPython, which I happen to be running. Time for me to upgrade and get rid of that dependency.

ii) In one of my indecent designs I obtained a similar result. Now, apart from design, how can I delete the previous rectangle and have *only one* rect at time on the screen? The idea effectively was: you press the button and the rect change position.

DC.Clear should do it. I think it's working that way in my code. If you want to be really efficient, and/or you get some flashing, you can draw the old rectangle again, in the background color, but that's probably overkill for this.

By the way, you could certainly accomplich the same thing with fewer classes, but I'm imagining that this will grow into something more complex, in which case the structure will become important.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov