Draw lines on sizers

I thought I remembered how to do this but I can't find it...

Is there any code I could add that would cause a given sizer to draw borders and gridlines so I can see where things are going wrong on the layout?

Thannks,
Michael

Sizers are not based on wx.Window, so they cannot have borders.

If you use the Widget Inspection Tool, you can see the borders, for sizers.

http://wiki.wxpython.org/Widget%20Inspection%20Tool

Josh

···

On Fri, Aug 20, 2010 at 1:46 PM, Michael Hipp <Michael@hipp.com> wrote:

I thought I remembered how to do this but I can't find it...

Is there any code I could add that would cause a given sizer to draw borders
and gridlines so I can see where things are going wrong on the layout?

Thannks,
Michael

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

--
Josh English
Joshua.R.English@gmail.com

Hi Michael,

I thought I remembered how to do this but I can’t find it…

Is there any code I could add that would cause a given sizer to draw borders and gridlines so I can see where things are going wrong on the layout?

I think the WIT can help you on that. Otherwise, I found this little piece of code (not-runnable as it stands) from my application SizerHack (that no one uses :slight_smile: ):

def Flash(self, dc):

if self._window:

x1, y1 = self._window.GetPosition()

size = self._window.GetSize()

sizer = self._window.GetContainingSizer()

if not sizer:

direction = wx.VERTICAL

else:

direction = sizer.GetOrientation()

size = wx.Size(size.x+1, size.y+1)

else:

x1, y1 = self._sizer.GetPosition()

size = self._sizer.GetSize()

direction = self._sizer.GetOrientation()

self.DrawOnDC(dc, size, x1, y1, direction)

def DrawOnDC(self, dc, size, x1, y1, direction):

“”" Actually draws on the wx.ScreenDC. “”"

dc.SetBrush(wx.TRANSPARENT_BRUSH)

pen = wx.Pen(wx.BLUE, 2)

if direction == wx.VERTICAL:

pen.SetColour(wx.RED)

if self.IsWindow():

pen.SetStyle(wx.SHORT_DASH)

dc.SetPen(pen)

dc.DrawRectangle(x1, y1, size.GetWidth(), size.GetHeight())

HTH.

Andrea.

“Imagination Is The Only Weapon In The War Against Reality.”
http://xoomer.alice.it/infinity77/

==> Never EVER use RemovalGroup for your house removal. You’ll regret it forever.
http://thedoomedcity.blogspot.com/2010/03/removal-group-nightmare.html <==

···

On 20 August 2010 23:46, Michael Hipp wrote:

Andrea,

That's clever.

Josh

···

On Fri, Aug 20, 2010 at 1:51 PM, Andrea Gavana <andrea.gavana@gmail.com> wrote:

def Flash\(self, dc\):
    if self\.\_window:
        x1, y1 = self\.\_window\.GetPosition\(\)
        size = self\.\_window\.GetSize\(\)
        sizer = self\.\_window\.GetContainingSizer\(\)
        if not sizer:
            direction = wx\.VERTICAL
        else:
            direction = sizer\.GetOrientation\(\)
        size = wx\.Size\(size\.x\+1, size\.y\+1\)
    else:
        x1, y1 = self\.\_sizer\.GetPosition\(\)
        size = self\.\_sizer\.GetSize\(\)
        direction = self\.\_sizer\.GetOrientation\(\)
    self\.DrawOnDC\(dc, size, x1, y1, direction\)

def DrawOnDC\(self, dc, size, x1, y1, direction\):
    &quot;&quot;&quot; Actually draws on the wx\.ScreenDC\. &quot;&quot;&quot;
    dc\.SetBrush\(wx\.TRANSPARENT\_BRUSH\)
    pen = wx\.Pen\(wx\.BLUE, 2\)
    if direction == wx\.VERTICAL:
        pen\.SetColour\(wx\.RED\)
    if self\.IsWindow\(\):
        pen\.SetStyle\(wx\.SHORT\_DASH\)

    dc\.SetPen\(pen\)
    dc\.DrawRectangle\(x1, y1, size\.GetWidth\(\), size\.GetHeight\(\)\)

--
Josh English
Joshua.R.English@gmail.com

I've been using the WIT and it can be a real help, but it has some problems that severely limit its practical utility:

- Doesn't work on modal dialog boxes.
- Sizer outlining only flashes on the screen for a brief moment, not enough time to study the problem.
- Doesn't preserve state between runs (have to dig thru it every run to get to the item of interest).
- Crashes if you hit the wrong button at the wrong time.

Michael

···

On 8/20/2010 3:51 PM, Josh English wrote:

Sizers are not based on wx.Window, so they cannot have borders.

If you use the Widget Inspection Tool, you can see the borders, for sizers.

http://wiki.wxpython.org/Widget%20Inspection%20Tool

Thanks, Andrea. If I understand what I'm reading in that code, it would only outline the outer edge of the sizer, not the individual cells. Correct?

Thanks,
Michael

···

On 8/20/2010 3:51 PM, Andrea Gavana wrote:

Hi Michael,

On 20 August 2010 23:46, Michael Hipp wrote:

    I thought I remembered how to do this but I can't find it...

    Is there any code I could add that would cause a given sizer to draw
    borders and gridlines so I can see where things are going wrong on
    the layout?

I think the WIT can help you on that. Otherwise, I found this little
piece of code (not-runnable as it stands) from my application SizerHack
(that no one uses :slight_smile: ):

     def Flash(self, dc):

         if self._window:

             x1, y1 = self._window.GetPosition()
             size = self._window.GetSize()
             sizer = self._window.GetContainingSizer()
             if not sizer:
                 direction = wx.VERTICAL
             else:
                 direction = sizer.GetOrientation()
             size = wx.Size(size.x+1, size.y+1)
         else:

             x1, y1 = self._sizer.GetPosition()
             size = self._sizer.GetSize()
             direction = self._sizer.GetOrientation()

         self.DrawOnDC(dc, size, x1, y1, direction)

     def DrawOnDC(self, dc, size, x1, y1, direction):
""" Actually draws on the wx.ScreenDC. """

         dc.SetBrush(wx.TRANSPARENT_BRUSH)

         pen = wx.Pen(wx.BLUE, 2)
         if direction == wx.VERTICAL:
             pen.SetColour(wx.RED)
         if self.IsWindow():
             pen.SetStyle(wx.SHORT_DASH)
         dc.SetPen(pen)
         dc.DrawRectangle(x1, y1, size.GetWidth(), size.GetHeight())

That's built into Dabo, and it is one of the many things that make
programming in Dabo so much more productive than raw wxPython.

If you don't want to switch to Dabo and get all the benefits, the code
is fully open, and you could "borrow" the routine that they use. The
code is in the 'drawOutline()' method in this script:
http://trac.dabodev.com/browser/trunk/dabo/ui/uiwx/dSizerMixin.py

···

On Fri, Aug 20, 2010 at 4:46 PM, Michael Hipp <Michael@hipp.com> wrote:

I thought I remembered how to do this but I can't find it...

Is there any code I could add that would cause a given sizer to draw borders
and gridlines so I can see where things are going wrong on the layout?

--

# p.d.

Sizers are not based on wx.Window, so they cannot have borders.

If you use the Widget Inspection Tool, you can see the borders, for
sizers.

http://wiki.wxpython.org/Widget%20Inspection%20Tool

I've been using the WIT and it can be a real help, but it has some
problems that severely limit its practical utility:

- Doesn't work on modal dialog boxes.

See my other mail.

- Sizer outlining only flashes on the screen for a brief moment, not
enough time to study the problem.

You can change the timeout before the Refresh() is done by setting wx.lib.inspection._InspectionHighlighter.highlightTime to the number of milliseconds to wait. The default is 3000. You can even set it from within the PyCrust in the WIT if you don't already have it set in your code someplace

- Doesn't preserve state between runs (have to dig thru it every run to
get to the item of interest).

You should be able to get the object of interest selected in the tree with just 2 clicks. Click the Find button on the WIT's toolbar, and then click the widget in your UI that you want to examine. If the WIT's widget tree is out of date from the UI (new UI elements have been created or old ones closed for example) then you may need to click the Refresh button on the toolbar first.

- Crashes if you hit the wrong button at the wrong time.

Please let me know how to reliably reproduce this.

···

On 8/20/10 2:44 PM, Michael Hipp wrote:

On 8/20/2010 3:51 PM, Josh English wrote:

--
Robin Dunn
Software Craftsman

- Sizer outlining only flashes on the screen for a brief moment, not
enough time to study the problem.

You can change the timeout before the Refresh() is done by setting
wx.lib.inspection._InspectionHighlighter.highlightTime to the number of
milliseconds to wait. The default is 3000. You can even set it from
within the PyCrust in the WIT if you don't already have it set in your
code someplace

Thank you!

- Doesn't preserve state between runs (have to dig thru it every run to
get to the item of interest).

You should be able to get the object of interest selected in the tree
with just 2 clicks. Click the Find button on the WIT's toolbar, and then
click the widget in your UI that you want to examine. If the WIT's
widget tree is out of date from the UI (new UI elements have been
created or old ones closed for example) then you may need to click the
Refresh button on the toolbar first.

Thanks, that will help. Any chance there is something I could call from within my code to get the WIT to focus on the widget or sizer that I'm working on ... wx.WIT.FindThis(ctrl) or HighlightThis(sizer) or somesuch?

- Crashes if you hit the wrong button at the wrong time.

Please let me know how to reliably reproduce this.

Run the app that brings up the WIT. Click the 'Highlight' button. Observe traceback.

(Yes, I know I'm supposed to select something first. But when I'm engaged in a fight to the death with some rogue sizer, I fear my patience wears thin and I fire at the first thing that wanders into my sights. I probably crashed it 100 times over the last 24 hours in just such a scenario.)

Thanks for all your help,
Michael

···

On 8/20/2010 7:39 PM, Robin Dunn wrote:

On 8/20/10 2:44 PM, Michael Hipp wrote:

Is there any way to Find a *sizer* in this manner?

Thanks,
Michael

···

On 8/20/2010 7:39 PM, Robin Dunn wrote:

On 8/20/10 2:44 PM, Michael Hipp wrote:
You should be able to get the object of interest selected in the tree
with just 2 clicks. Click the Find button on the WIT's toolbar, and then
click the widget in your UI that you want to examine.

- Sizer outlining only flashes on the screen for a brief moment, not
enough time to study the problem.

You can change the timeout before the Refresh() is done by setting
wx.lib.inspection._InspectionHighlighter.highlightTime to the number of
milliseconds to wait. The default is 3000. You can even set it from
within the PyCrust in the WIT if you don't already have it set in your
code someplace

Thank you!

- Doesn't preserve state between runs (have to dig thru it every run to
get to the item of interest).

You should be able to get the object of interest selected in the tree
with just 2 clicks. Click the Find button on the WIT's toolbar, and then
click the widget in your UI that you want to examine. If the WIT's
widget tree is out of date from the UI (new UI elements have been
created or old ones closed for example) then you may need to click the
Refresh button on the toolbar first.

Thanks, that will help. Any chance there is something I could call from
within my code to get the WIT to focus on the widget or sizer that I'm
working on ... wx.WIT.FindThis(ctrl) or HighlightThis(sizer) or somesuch?

  InspectionTool().Show(ctrl)

BTW, if you use the hot-key method to open the WIT then it will attempt to preselect the widget under the mouse cursor.

- Crashes if you hit the wrong button at the wrong time.

Please let me know how to reliably reproduce this.

Run the app that brings up the WIT. Click the 'Highlight' button.
Observe traceback.

Ok. That's not really a crash though since you can just continue on after it prints the traceback. OTOH, when Show is called without an object to preselect it will try to preselect wx.GetApp().GetTopWindow() instead, so if you have already created your main frame or whatever before the first time the WIT is launched then it should not have this traceback unless you explicitly select the tree root.

···

On 8/20/10 6:38 PM, Michael Hipp wrote:

On 8/20/2010 7:39 PM, Robin Dunn wrote:

On 8/20/10 2:44 PM, Michael Hipp wrote:

--
Robin Dunn
Software Craftsman

Click on an object in the sizer and then move up one level in the widget tree.

···

On 8/20/10 6:46 PM, Michael Hipp wrote:

On 8/20/2010 7:39 PM, Robin Dunn wrote:

On 8/20/10 2:44 PM, Michael Hipp wrote:
You should be able to get the object of interest selected in the tree
with just 2 clicks. Click the Find button on the WIT's toolbar, and then
click the widget in your UI that you want to examine.

Is there any way to Find a *sizer* in this manner?

--
Robin Dunn
Software Craftsman