wxSizer and wxLayaoutConstraints Problem

Hi!

I have a problem using the layour constraints. I created a wxWindow, then i inserted a wxButton. After that, i want to create a wxStaticText that is NOT overlapping with the wxButton. But i cant get it working.

Here is the code that should (as far as i understand) proce a static_text and button that are not overlapping. I would aprettiate if anyone could show me whats wrong in my understanding of LayoutConstraints so i can fix it.

  # create expand button
         b = wxButton(self.panelA, 1010, "")
         lc = wxLayoutConstraints()
         lc.top.SameAs(self.panelA, wxTop)
         lc.bottom.SameAs(self.panelA, wxBottom)
         lc.left.SameAs(self.panelA, wxLeft)
         lc.width.Absolute(15)
         b.SetConstraints(lc)

         # create frame title
         lc = wxLayoutConstraints()
         lc.top.SameAs(self.panelA, wxTop)
         #lc.bottom.SameAs(self.panelA, wxBottom)
         lc.left.SameAs(b, wxRight)
         lc.right.SameAs(self.panelA, wxRight)
         #lc.width.Absolute(15)
         l = wxStaticText(self.panelA, -1, "class name")
         l.SetConstraints(lc)

(See attached file for complete source)

Another problem i had is that i could not get a wxWindow/wxPanel to show if i put it inside a wxBoxSizer. How should i solve this?

Thanks a lot!

Lucio

test.py (2.63 KB)

Hi all,

I have a little app that makes a movie of sorts by using a wxClientDC to
draw new stuff to the screen inside a loop. I want to be able to allow
the user to pause the movie by clicking a button. I have the button set
an attribute, and inside the drawing loop I check that attribute and
break out of the loop if it has been set.

Unfortunately, the GUI is locked up while inside the loop, so I put in a
wxYield, but it still doesn't work. I can get it to work by putting a
time.sleep() call in there, but it only works reliably if I sleep for at
least .1 seconds, which gives me a max frame rate or 10fps, which is too
slow. This should be possible. What am I doing wrong??

(Python 2.1 wxPython 2.3.3.1 wxGTK)

-Chris

Below is the relevant code:

    def Pause(self,event): # this is called when the "pause" button is
pushed
        self.Pause = 1

    def Play(self,event):
        if self.LE_movie: # no point in doing anything is there is no
movie
            self.Pause = 0
            Num_times = len(self.LE_movie)
            while ( not self.Pause ) and ( self.TimeStep <
len(self.LE_movie) ):
                # this sets the data for the next frame
               
self.LEsObjects[-1].SetPoints(self.LE_movie[self.TimeStep])
                # this updates the screen by drawing to wxClientDC
                self.Canvas.Draw()
                sleep(.01) #this seems to be rquired to unlock the GUI
                #wxSafeYield()# this made the screen flash...why?
                wxYield()
                self.TimeStep += 1

···

--
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

Dont worry Lucio, i can solve your problems. If you dont constrain Al four sides somehow, the layout algorithm will place your windows at 0,0. Use side.AsIs() if you want to keep the original size or position.

Thanks to myself!

Lucio Torre wrote:

···

Hi!

I have a problem using the layour constraints. I created a wxWindow, then i inserted a wxButton. After that, i want to create a wxStaticText that is NOT overlapping with the wxButton. But i cant get it working.

Here is the code that should (as far as i understand) proce a static_text and button that are not overlapping. I would aprettiate if anyone could show me whats wrong in my understanding of LayoutConstraints so i can fix it.

    # create expand button
        b = wxButton(self.panelA, 1010, "")
        lc = wxLayoutConstraints()
        lc.top.SameAs(self.panelA, wxTop)
        lc.bottom.SameAs(self.panelA, wxBottom)
        lc.left.SameAs(self.panelA, wxLeft)
        lc.width.Absolute(15)
        b.SetConstraints(lc)

        # create frame title
        lc = wxLayoutConstraints()
        lc.top.SameAs(self.panelA, wxTop)
        #lc.bottom.SameAs(self.panelA, wxBottom)
        lc.left.SameAs(b, wxRight)
        lc.right.SameAs(self.panelA, wxRight)
        #lc.width.Absolute(15)
        l = wxStaticText(self.panelA, -1, "class name")
        l.SetConstraints(lc)

(See attached file for complete source)

Another problem i had is that i could not get a wxWindow/wxPanel to show if i put it inside a wxBoxSizer. How should i solve this?

Thanks a lot!

Lucio

------------------------------------------------------------------------

from wxPython.wx import *
import os
from wxPython.html import *
import wxPython.lib.wxpTag
from wxPython.wx import *
from wxPython.lib.layoutf import Layoutf

ID_ABOUT = wxNewId()
ID_EXIT = wxNewId()
ID_Timer = wxNewId()

class xml_edit_panel(wxPanel):
   def __init__(self, parent, frame, log):
       wxPanel.__init__(self, parent, -1)
       self.SetBackgroundColour(wxWHITE)
              self.SetAutoLayout(true)

       self.panelA = wxWindow(self, -1, wxPyDefaultPosition, wxPyDefaultSize, wxSIMPLE_BORDER)
       self.panelA.SetBackgroundColour(wxBLUE) self.panelA.SetConstraints(Layoutf('t=t#1;l=l#1;b=b#1;r=r#1',(self,)))

       # create expand button
       b = wxButton(self.panelA, 1010, "")
       lc = wxLayoutConstraints()
       lc.top.SameAs(self.panelA, wxTop)
       lc.bottom.SameAs(self.panelA, wxBottom)
       lc.left.SameAs(self.panelA, wxLeft)
       lc.width.Absolute(15)
       b.SetConstraints(lc)

       # create frame title
       lc = wxLayoutConstraints()
       lc.top.SameAs(self.panelA, wxTop)
       #lc.bottom.SameAs(self.panelA, wxBottom)
       lc.left.SameAs(b, wxRight)
       lc.right.SameAs(self.panelA, wxRight)
       #lc.width.Absolute(15)
       l = wxStaticText(self.panelA, -1, "class name")
       l.SetConstraints(lc)
       
class MyFrame(wxFrame):
   def __init__(self, parent, ID, title):
       wxFrame.__init__(self, parent, ID, title,
                        wxDefaultPosition, wxSize(200, 150))

       self.CreateStatusBar()
       self.SetStatusText("This is the statusbar")
       menu = wxMenu()
       menu.Append(ID_ABOUT, "&About",
                   "More information about this program")
       menu.AppendSeparator()
       menu.Append(ID_EXIT, "E&xit", "Terminate the program")
       menuBar = wxMenuBar()
       menuBar.Append(menu, "&File");
       self.SetMenuBar(menuBar)

       self.edit_panel = xml_edit_panel(self,self, 1)
       EVT_MENU(self, ID_ABOUT, self.OnAbout)
       EVT_MENU(self, ID_EXIT, self.TimeToQuit)

   def OnAbout(self, event):
       dlg = wxMessageDialog(self, "This sample program shows off\n"
                             "frames, menus, statusbars, and this\n"
                             "message dialog.",
                             "About Me", wxOK | wxICON_INFORMATION)
       dlg.ShowModal()
       dlg.Destroy()

   def TimeToQuit(self, event):
       self.Close(true)

class MyApp(wxApp):
   def OnInit(self):
       frame = MyFrame(NULL, -1, "Hello from wxPython")
       frame.Show(true)
       self.SetTopWindow(frame)
       return true

app = MyApp(0)
app.MainLoop()

------------------------------------------------------------------------

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

It looks like you're trying to play all of the frames off of one event,
which means that the message loop never runs, so the button never has a
chance to fire. If you play frames one at a time, using posted messages
(or RunAfter, which amounts to the same thing), then other messages have a
chance to get processed. If there aren't any other messages to be
processed, the delay should be very small (i.e., unnoticeable).

  /cco

The code would look something like this:

def Pause(self,event):
  self.Pause = 1

def Play(self,event):
  if self.LE_movie:
    self.Pause = 0
    # post an event to paint the next frame
    evt = FrameEvent()
    wxPostEvent(self, evt)

def ShowFrame(self, event):
  if ( not self.Pause ) and ( self.TimeStep < len(self.LE_movie) ):
    # this sets the data for the next frame
    self.LEsObjects[-1].SetPoints(self.LE_movie[self.TimeStep])

    # this updates the screen by drawing to wxClientDC
    self.Canvas.Draw()
    self.TimeStep += 1
    # post an event to paint the next frame
    evt = FrameEvent()
    wxPostEvent(self, evt)

···

On Fri, 10 Jan 2003, Chris Barker wrote:

I have a little app that makes a movie of sorts by using a wxClientDC to
draw new stuff to the screen inside a loop. I want to be able to allow
the user to pause the movie by clicking a button. I have the button set
an attribute, and inside the drawing loop I check that attribute and
break out of the loop if it has been set.

Unfortunately, the GUI is locked up while inside the loop, so I put in a
wxYield, but it still doesn't work. I can get it to work by putting a
time.sleep() call in there, but it only works reliably if I sleep for at
least .1 seconds, which gives me a max frame rate or 10fps, which is too
slow. This should be possible. What am I doing wrong??

Chris Barker wrote:

Hi all,

I have a little app that makes a movie of sorts by using a wxClientDC to
draw new stuff to the screen inside a loop. I want to be able to allow
the user to pause the movie by clicking a button. I have the button set
an attribute, and inside the drawing loop I check that attribute and
break out of the loop if it has been set.

Unfortunately, the GUI is locked up while inside the loop, so I put in a
wxYield, but it still doesn't work. I can get it to work by putting a
time.sleep() call in there, but it only works reliably if I sleep for at
least .1 seconds, which gives me a max frame rate or 10fps, which is too
slow. This should be possible. What am I doing wrong??

Take a look at the Throbber demo and library module. It uses threads to run the "loop" and threading.Events to signal when to stop.

···

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