wxpython - repositioning help

Reply

Join Date: Jul 2008
Posts: 53
Reputation: flipjoebanana is an unknown quantity at this point 
Solved Threads: 0
flipjoebanana flipjoebanana is offline Offline
Junior Poster in Training

wxpython - repositioning help

 
0
  #1
Jul 31st, 2009
Hello,
My problem is is that I have an area in the window for an image that is sized relative to that window. I want to place a panel below that image a certain distance from the top based on the height of image after resizing the window occurs(on idle event). So is there a way to reposition a panel, say x pixels(the new height of the image after resize) from the top and do this? I've tried doing some things but I get odd results. Or possible other methods?
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 1,016
Reputation: Paul Thompson has a spectacular aura about Paul Thompson has a spectacular aura about Paul Thompson has a spectacular aura about 
Solved Threads: 165
Paul Thompson's Avatar
Paul Thompson Paul Thompson is offline Offline
Veteran Poster

Re: wxpython - repositioning help

 
0
  #2
Jul 31st, 2009
If you use sizers you should be able to let the sizers automatically resize themselves so that the image will always have enough space and that the other panel will shrink to accommodate for it.

Have a look at them here:
http://wiki.wxpython.org/UsingSizers
Make it idiot-proof, and someone will just make a better idiot
Check out my Site | and join us on IRC | Python Specific IRC
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 53
Reputation: flipjoebanana is an unknown quantity at this point 
Solved Threads: 0
flipjoebanana flipjoebanana is offline Offline
Junior Poster in Training

Re: wxpython - repositioning help

 
0
  #3
Jul 31st, 2009
I tried using sizers but the panel wouldn't shift upon resizing the window. I have something like:

  1. class PlotPanel (wx.Panel):
  2. def __init__( self, parent, **kwargs ):
  3.  
  4. vbox = wx.BoxSizer(wx.VERTICAL)
  5. vbox.Add(initial_fig, 0, flags) #add image already specified
  6. vbox.Add(any widget) #adding widget/panel already specified
  7.  
  8. self.SetSizer(vbox)
  9. self.show(True)
  10.  
  11. self.Bind(wx.EVT_IDLE, self._onIdle)
  12. self.Bind(wx.EVT_SIZE, self._onSize)
  13.  
  14. def _onIdle(self, event):
  15. #new image w/ new size stored after resize here
  16.  
  17. def_onSize(self,event):
  18. #store final window size..

It works fine on initial everything in right place, but after the resize the image changes to right size fine but the lower widget/panel I'm trying to add is in the wrong position.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,895
Reputation: evstevemd is a jewel in the rough evstevemd is a jewel in the rough evstevemd is a jewel in the rough 
Solved Threads: 172
evstevemd's Avatar
evstevemd evstevemd is offline Offline
Posting Virtuoso

Re: wxpython - repositioning help

 
0
  #4
Aug 2nd, 2009
can you post your code? I cannot understand what you posted.
From my little experience, one of common problems is specifying different parent to which the sizer is set. If you use one panel as parent to your widgets then you must use that panel's SetSizer() method. DON'T use panel as parent and use self (which is probably a wx.Frame) to set a sizer.

Wait for your code
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
"Try to be expert in everything and you become expert in nothing" - Me
---------------------------------
Windows Vista Home Premium SP2| MINGW 4.4.0|PHP 5.3.1|Python 2.6.4|JDK 1.6
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 53
Reputation: flipjoebanana is an unknown quantity at this point 
Solved Threads: 0
flipjoebanana flipjoebanana is offline Offline
Junior Poster in Training

Re: wxpython - repositioning help

 
0
  #5
Aug 3rd, 2009
I have pasted below a similar example of what I'm trying to do that I found from here: http://www.scipy.org/Matplotlib_figure_in_a_wx_panel

Here the figure re-sizes itself based upon the client window size. How would I add a widget below the figure that works upon re-size.

  1. #!/usr/bin/env python
  2.  
  3. """
  4. New version based on the original by Edward Abraham, incorporating some
  5. forum discussion, minor bugfixes, and working for Python 2.5.2,
  6. wxPython 2.8.7.1, and Matplotlib 0.98.3.
  7.  
  8. I haven't found an advantage to using the NoRepaintCanvas, so it's removed.
  9.  
  10. John Bender, CWRU, 10 Sep 08
  11. """
  12.  
  13. import matplotlib
  14. matplotlib.interactive( True )
  15. matplotlib.use( 'WXAgg' )
  16.  
  17. import numpy as num
  18. import wx
  19.  
  20. class PlotPanel (wx.Panel):
  21. """The PlotPanel has a Figure and a Canvas. OnSize events simply set a
  22. flag, and the actual resizing of the figure is triggered by an Idle event."""
  23. def __init__( self, parent, color=None, dpi=None, **kwargs ):
  24. from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
  25. from matplotlib.figure import Figure
  26.  
  27. # initialize Panel
  28. if 'id' not in kwargs.keys():
  29. kwargs['id'] = wx.ID_ANY
  30. if 'style' not in kwargs.keys():
  31. kwargs['style'] = wx.NO_FULL_REPAINT_ON_RESIZE
  32. wx.Panel.__init__( self, parent, **kwargs )
  33.  
  34. # initialize matplotlib stuff
  35. self.figure = Figure( None, dpi )
  36. self.canvas = FigureCanvasWxAgg( self, -1, self.figure )
  37. self.SetColor( color )
  38.  
  39. self._SetSize()
  40. self.draw()
  41.  
  42. self._resizeflag = False
  43.  
  44. self.Bind(wx.EVT_IDLE, self._onIdle)
  45. self.Bind(wx.EVT_SIZE, self._onSize)
  46.  
  47. def SetColor( self, rgbtuple=None ):
  48. """Set figure and canvas colours to be the same."""
  49. if rgbtuple is None:
  50. rgbtuple = wx.SystemSettings.GetColour( wx.SYS_COLOUR_BTNFACE ).Get()
  51. clr = [c/255. for c in rgbtuple]
  52. self.figure.set_facecolor( clr )
  53. self.figure.set_edgecolor( clr )
  54. self.canvas.SetBackgroundColour( wx.Colour( *rgbtuple ) )
  55.  
  56. def _onSize( self, event ):
  57. self._resizeflag = True
  58.  
  59. def _onIdle( self, evt ):
  60. if self._resizeflag:
  61. self._resizeflag = False
  62. self._SetSize()
  63.  
  64. def _SetSize( self ):
  65. pixels = tuple( self.parent.GetClientSize() )
  66. self.SetSize( pixels )
  67. self.canvas.SetSize( pixels )
  68. self.figure.set_size_inches( float( pixels[0] )/self.figure.get_dpi(),
  69. float( pixels[1] )/self.figure.get_dpi() )
  70.  
  71. def draw(self): pass # abstract, to be overridden by child classes
  72.  
  73. if __name__ == '__main__':
  74. class DemoPlotPanel (PlotPanel):
  75. """Plots several lines in distinct colors."""
  76. def __init__( self, parent, point_lists, clr_list, **kwargs ):
  77. self.parent = parent
  78. self.point_lists = point_lists
  79. self.clr_list = clr_list
  80.  
  81. # initiate plotter
  82. PlotPanel.__init__( self, parent, **kwargs )
  83. self.SetColor( (255,255,255) )
  84.  
  85. def draw( self ):
  86. """Draw data."""
  87. if not hasattr( self, 'subplot' ):
  88. self.subplot = self.figure.add_subplot( 111 )
  89.  
  90. for i, pt_list in enumerate( self.point_lists ):
  91. plot_pts = num.array( pt_list )
  92. clr = [float( c )/255. for c in self.clr_list[i]]
  93. self.subplot.plot( plot_pts[:,0], plot_pts[:,1], color=clr )
  94.  
  95. theta = num.arange( 0, 45*2*num.pi, 0.02 )
  96.  
  97. rad0 = (0.8*theta/(2*num.pi) + 1)
  98. r0 = rad0*(8 + num.sin( theta*7 + rad0/1.8 ))
  99. x0 = r0*num.cos( theta )
  100. y0 = r0*num.sin( theta )
  101.  
  102. rad1 = (0.8*theta/(2*num.pi) + 1)
  103. r1 = rad1*(6 + num.sin( theta*7 + rad1/1.9 ))
  104. x1 = r1*num.cos( theta )
  105. y1 = r1*num.sin( theta )
  106.  
  107. points = [[(xi,yi) for xi,yi in zip( x0, y0 )],
  108. [(xi,yi) for xi,yi in zip( x1, y1 )]]
  109. clrs = [[225,200,160], [219,112,147]]
  110.  
  111. app = wx.PySimpleApp( 0 )
  112. frame = wx.Frame( None, wx.ID_ANY, 'WxPython and Matplotlib', size=(300,300) )
  113. panel = DemoPlotPanel( frame, points, clrs )
  114. frame.Show()
  115. app.MainLoop()
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,895
Reputation: evstevemd is a jewel in the rough evstevemd is a jewel in the rough evstevemd is a jewel in the rough 
Solved Threads: 172
evstevemd's Avatar
evstevemd evstevemd is offline Offline
Posting Virtuoso

Re: wxpython - repositioning help

 
0
  #6
Aug 4th, 2009
I think you need to brush your knowledge here:
http://zetcode.com/wxpython
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
"Try to be expert in everything and you become expert in nothing" - Me
---------------------------------
Windows Vista Home Premium SP2| MINGW 4.4.0|PHP 5.3.1|Python 2.6.4|JDK 1.6
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 53
Reputation: flipjoebanana is an unknown quantity at this point 
Solved Threads: 0
flipjoebanana flipjoebanana is offline Offline
Junior Poster in Training

Re: wxpython - repositioning help

 
0
  #7
Aug 4th, 2009
Well.. canvas figure is based upon window size, and if there is a widget below it, it would cause the figure to increase size while idle. Adding the figure simply to a sizer rather than basing it upon window size doesn't seem to work either. The figure appears but can't be shrunk less than original declared size. It also slow because matplotlib is memory intensive. I can get a widget to appear below using setposition/move by height offset of figure but when I try doing the exact same thing with a subpanel it doesn't seem to work. I'm not sure what else is needed.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 302 | Replies: 6
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC