Strange behavior

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Strange behavior

Jeffrey Spies
Administrator
Hi all,

I'm still having problems with moving a wx.Window, so, until I figure
out what's wrong with that, I thought I'd try making my test class a
wx.PyControl.

If I only instantiate one class:

Test(self, -1, 100, 100)

It doesn't work.  However, if I instantiate two classes:

Test(self, -1, 200, 10)

it works just fine.  Is this is a bug?  Am I running into the
boundaries of what wxPython can do on the Mac?  Or am I just missing
something important about how custom windows work?  Appended below is
some basic code of what I'm talking about.

Any and all help would be appreciated,

Jeff.

# BEGIN CODE

import wx

class Test(wx.PyControl):
        def __init__(self, parent, id, x, y):
                wx.PyControl.__init__(self, parent, id)
                self.DoMoveWindow(x,y, 200,200)
                self.Bind(wx.EVT_PAINT, self.OnPaint)
               
        def OnPaint(self,evt):
                dc = wx.PaintDC(self)
                dc.Clear()
                dc.SetPen(wx.Pen("Black", 1))
                dc.DrawLine(0,0,200,200)

class Frame(wx.Frame):
        def __init__(self, parent=None, id=-1, pos=wx.DefaultPosition,
title='Iconic') :
                """docstring for __init__"""
                wx.Frame.__init__(self, parent, id, title, pos, size=(500,500))
                Test(self, -1, 100, 100)
                Test(self, -1, 200, 10)
                pass

class App(wx.App):
        def OnInit(self):
                self.frame = Frame(parent=None, title='Main')
                self.frame.Show()
                return True

def main():
        app = App()
        app.MainLoop()

if __name__ == '__main__':
        main()

# END CODE
_______________________________________________
wxpython-users mailing list
[hidden email]
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
Reply | Threaded
Open this post in threaded view
|

Re: Strange behavior

Chris Barker - NOAA Federal
Jeffrey Spies wrote:
> If I only instantiate one class:
>
> Test(self, -1, 100, 100)
>
> It doesn't work.  However, if I instantiate two classes:
>
> Test(self, -1, 200, 10)
>
> it works just fine.  Is this is a bug?

no
 >  Am I running into the boundaries of what wxPython can do on the Mac?

no
 >  Or am I just missing
> something important about how custom windows work?

almost -- the problem is that when a wx.Frame only has one child, it
automatically re-sizes it to fit the frame. If you put your ccustom
windows on a Panel, and the Panel in the frame, then it works fine.

I'd go back to deriving from wx.Window (though I don't know your
ultimate goals)

Also, I'd stick with the usual wx.Window methods for setting size and
placement, then you'll end up with something that can be used just like
any other Window (in Sizers, etc, etc.)

I've enclosed a version that works, with some style differences that I
suggest, as well.

-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

import wx

class Test(wx.Window):
    def __init__(self, *args, **kwargs):
        wx.Window.__init__(self, *args, **kwargs)
        self.Size=(200,200)
        self.Bind(wx.EVT_PAINT, self.OnPaint)
       
    def OnPaint(self,evt):
        dc = wx.PaintDC(self)
        dc.SetBackground(wx.RED_BRUSH)
        dc.Clear()
        dc.SetPen(wx.Pen("Black", 1))
        dc.DrawLine(0,0,200,200)



class TestPanel(wx.Panel):
    def __init__(self, *args, **kwargs):
        """docstring for __init__"""
        wx.Panel.__init__(self, *args, **kwargs)
        Test(self, pos=(100,100))
        Test(self, pos=(200, 10))
        pass

class App(wx.App):
    def OnInit(self):
        self.frame = wx.Frame(parent=None, title='Main', size=(500,500))
        self.Panel=TestPanel(self.frame, size=(500,500))
        self.frame.Show()
        return True

def main():
    app = App(False)
    app.MainLoop()

if __name__ == '__main__':
    main()

_______________________________________________
wxpython-users mailing list
[hidden email]
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
Reply | Threaded
Open this post in threaded view
|

Re: Strange behavior

Chris Barker - NOAA Federal
Jeffrey Robert Spies wrote:
> You don't know how much I appreciate the help on this.

you're welcome.

> I've been trying
> for days now to get wx.Window to work: with panels, without panels,
> using pos=, using MoveXY, etc, etc, etc.  I was just about to go back to
> Java Swing with my head held low....

So is some version my example working for you now?

By the way, what is it you're trying to do? It strikes me that you may
not really want a wx.Window subclass after all...

-Chris



--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

[hidden email]
_______________________________________________
wxpython-users mailing list
[hidden email]
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
Reply | Threaded
Open this post in threaded view
|

Re: Strange behavior

Jeffrey Spies
Administrator
Your example did work, but I'm starting to question whether this is
what I want or not as well.

So, I would like to draw a bunch of "icons" (basically, 2d line
drawings) on the screen and be able to select them individually and
drag them around, and then update all of the drawings on the fly based
on options presented to the user.  I would also like to be able to
generate PDFs or images from the composite of the organized icons.

What do you think?  To wx.Window or not to wx.Window?  That is the quesiton....

Jeff.

On Mon, Jun 16, 2008 at 1:36 PM, Christopher Barker
<[hidden email]> wrote:

> Jeffrey Robert Spies wrote:
>>
>> You don't know how much I appreciate the help on this.
>
> you're welcome.
>
>> I've been trying for days now to get wx.Window to work: with panels,
>> without panels, using pos=, using MoveXY, etc, etc, etc.  I was just about
>> to go back to Java Swing with my head held low....
>
> So is some version my example working for you now?
>
> By the way, what is it you're trying to do? It strikes me that you may not
> really want a wx.Window subclass after all...
>
> -Chris
>
>
>
> --
> Christopher Barker, Ph.D.
> Oceanographer
>
> Emergency Response Division
> NOAA/NOS/OR&R            (206) 526-6959   voice
> 7600 Sand Point Way NE   (206) 526-6329   fax
> Seattle, WA  98115       (206) 526-6317   main reception
>
> [hidden email]
> _______________________________________________
> wxpython-users mailing list
> [hidden email]
> http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
>
_______________________________________________
wxpython-users mailing list
[hidden email]
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
Reply | Threaded
Open this post in threaded view
|

Re: Strange behavior

Chris Barker - NOAA Federal
Jeffrey Spies wrote:

> Your example did work, but I'm starting to question whether this is
> what I want or not as well.
>
> So, I would like to draw a bunch of "icons" (basically, 2d line
> drawings) on the screen and be able to select them individually and
> drag them around, and then update all of the drawings on the fly based
> on options presented to the user.  I would also like to be able to
> generate PDFs or images from the composite of the organized icons.
>
> What do you think?  To wx.Window or not to wx.Window?  That is the quesiton....

I don't think I'd wx.Window. Among other things, you may have trouble
getting Some options:

1) Just do all the drawing yourself, though that is a fair bit of code
to write. Take a look at the demo under Using Images => DragImage, and
in the Wiki: search for "graphics".

2) Use OGL

3) Use wx.lib.FloatCanvas

FloatCanvas is my baby, so I know more about it than OGL. It doesn't
directly support all of what you want, but does provide a nice framework
for doing a lot of it. It also provides zooming and panning -- if you
want those, it's a good way to go. Do take a look at the demos in the
source:

http://svn.wxwidgets.org/viewvc/wx/wxPython/3rdParty/FloatCanvas/Demos/

There are some "drag things around" demos in there.

Hint: your "icons" will be custom DrawObjects -- look in
floatcanvas/FloatCanvas.py (and some of the demos, and
floatcanvas/SpecialObjects/) to see how DrawObjects are created.

-Chris

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

[hidden email]
_______________________________________________
wxpython-users mailing list
[hidden email]
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users