wx.Window position

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

wx.Window position

Jeffrey Spies
Administrator
Hi all,

I'm having some problems:

I need a bunch of custom widgets--basically line drawings--dynamically
created.  They need to be able to respond to mouse input, be moved,
etc.  Attached below is a test of what I'm trying to do, but I've
gotten stuck at simply placing the wx.Window (Test) somewhere other
than (-1,-1) in the frame.  Can this be done?  And can I then call
Test(self, -1, pos...) multiple times?  I've discovered another class
that I'll be looking into for custom controls, but I would still like
to know what I'm doing wrong (plus, there's a good chance that won't
work either).

Thanks for the help,

Jeff.

# BEGIN CODE

import wx

class Test(wx.Window):
        def __init__(self, parent, id, pos):
                wx.Window.__init__(self, parent, id, pos=pos)
                self.SetMaxSize((200,200))
                self.SetBackgroundColour("White")
                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__"""
                size = (600, 600)
                wx.Frame.__init__(self, parent, id, title, pos, size)
                Test(self, -1, pos=(100,100))
                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

Reply | Threaded
Open this post in threaded view
|

Re: wx.Window position

Raffaello
Any wx.Window can be placed and replaced any time you wish with:
Move(point) Accepts a wxPoint
MoveXY(x, y) Accepts a pair of integers


2008/6/14 Jeffrey Spies <[hidden email]>:
Hi all,

I'm having some problems:

I need a bunch of custom widgets--basically line drawings--dynamically
created.  They need to be able to respond to mouse input, be moved,
etc.  Attached below is a test of what I'm trying to do, but I've
gotten stuck at simply placing the wx.Window (Test) somewhere other
than (-1,-1) in the frame.  Can this be done?  And can I then call
Test(self, -1, pos...) multiple times?  I've discovered another class
that I'll be looking into for custom controls, but I would still like
to know what I'm doing wrong (plus, there's a good chance that won't
work either).

Thanks for the help,

Jeff.

# BEGIN CODE

import wx

class Test(wx.Window):
       def __init__(self, parent, id, pos):
               wx.Window.__init__(self, parent, id, pos=pos)
               self.SetMaxSize((200,200))
               self.SetBackgroundColour("White")
               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__"""
               size = (600, 600)
               wx.Frame.__init__(self, parent, id, title, pos, size)
               Test(self, -1, pos=(100,100))
               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: wx.Window position

Jeffrey Spies
Administrator
I had tried this to no avail.  I'm wondering if this is a system issue
(OSX 10.5).  Does anyone have a working example that I could give a
try w/ my setup?

Jeff.

On Sat, Jun 14, 2008 at 4:01 AM, raffaello <[hidden email]> wrote:

> Any wx.Window can be placed and replaced any time you wish with:
> Move(point) Accepts a wxPoint
> MoveXY(x, y) Accepts a pair of integers
>
> 2008/6/14 Jeffrey Spies <[hidden email]>:
>>
>> Hi all,
>>
>> I'm having some problems:
>>
>> I need a bunch of custom widgets--basically line drawings--dynamically
>> created.  They need to be able to respond to mouse input, be moved,
>> etc.  Attached below is a test of what I'm trying to do, but I've
>> gotten stuck at simply placing the wx.Window (Test) somewhere other
>> than (-1,-1) in the frame.  Can this be done?  And can I then call
>> Test(self, -1, pos...) multiple times?  I've discovered another class
>> that I'll be looking into for custom controls, but I would still like
>> to know what I'm doing wrong (plus, there's a good chance that won't
>> work either).
>>
>> Thanks for the help,
>>
>> Jeff.
>>
>> # BEGIN CODE
>>
>> import wx
>>
>> class Test(wx.Window):
>>        def __init__(self, parent, id, pos):
>>                wx.Window.__init__(self, parent, id, pos=pos)
>>                self.SetMaxSize((200,200))
>>                self.SetBackgroundColour("White")
>>                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__"""
>>                size = (600, 600)
>>                wx.Frame.__init__(self, parent, id, title, pos, size)
>>                Test(self, -1, pos=(100,100))
>>                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
>
>
> _______________________________________________
> wxpython-users mailing list
> [hidden email]
> http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
>
>

Reply | Threaded
Open this post in threaded view
|

Re: wx.Window position

Robin Dunn
In reply to this post by Jeffrey Spies
Jeffrey Spies wrote:

> Hi all,
>
> I'm having some problems:
>
> I need a bunch of custom widgets--basically line drawings--dynamically
> created.  They need to be able to respond to mouse input, be moved,
> etc.  Attached below is a test of what I'm trying to do, but I've
> gotten stuck at simply placing the wx.Window (Test) somewhere other
> than (-1,-1) in the frame.  Can this be done?  And can I then call
> Test(self, -1, pos...) multiple times?  I've discovered another class
> that I'll be looking into for custom controls, but I would still like
> to know what I'm doing wrong (plus, there's a good chance that won't
> work either).

wx.Frame has a feature where if there is only one child then it will
automatically resize the single child to fill the frame.  If you don't
want it to do that then you can catch the EVT_SIZE event and do whatever
you want to do there, (or nothing.)  Another alternative is to put some
other window in your frame, and make your movable windows be children of
that window.



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

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