Slowness to create widgets

Hello!

A help please.

In the example below because creating controls is much faster than the frame on the page of the book?

thank you

( python 2.7 and wx.python 2.8 )

import wx

import wx.lib.scrolledpanel as scrolled

import wx.lib.agw.flatnotebook as fnb

import wx.lib.agw.aui as aui

class TestFrame(wx.Frame):

def init( self ):

wx.Frame.init(self, None, -1, “Test Frame”, size=(640,480))

self.paneldados = wx.Panel( self )

sizer = wx.BoxSizer(wx.VERTICAL)

self.primarybook = fnb.FlatNotebook( self.paneldados , wx.ID_ANY )

self.primarybook.SetAGWWindowStyleFlag( fnb.FNB_VC8|fnb.FNB_NO_NAV_BUTTONS )

self.primarybook.AddPage( self.createpanel( self.primarybook ) , “first book” )

sizer.Add( self.primarybook , 1, wx.EXPAND )

self.paneldados.SetSizer( sizer )

self.Maximize(True)

def createpanel( self , primarybook ):

self.secondBook = aui.AuiNotebook( primarybook , agwStyle=wx.DOUBLE_BORDER )

panel = wx.Panel( self.secondBook )

sizer = wx.BoxSizer( wx.VERTICAL )

a = wx.Button( panel, -1, “second pag with Widgets”, ( 200, 30 ))

self.Bind( wx.EVT_BUTTON, self.pagewithwidgets, a )

sizer.Add( a )

b = wx.Button( panel, -1, “frame with Widgets”, ( 200, 30 ))

self.Bind( wx.EVT_BUTTON, self.framewithwidgets, b )

sizer.Add( b )

panel.SetSizer( sizer )

self.secondBook.AddPage( panel , “first page - second book” )

return self.secondBook

def pagewithwidgets( self , event ):

panel = scrolled.ScrolledPanel( self.secondBook , -1 , style=wx.SUNKEN_BORDER )

sizer = wx.BoxSizer( wx.VERTICAL )

lbox = wx.StaticBox( panel, -1, ‘’ )

lsizer = wx.StaticBoxSizer( lbox, wx.HORIZONTAL )

lsizer.Add( self.createwidgets( panel ) , 1, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER, 10 )

sizer.Add( lsizer ,0, wx.ALL | wx.ALIGN_CENTER, 5 )

panel.SetSizer( sizer )

panel.SetupScrolling()

self.secondBook.AddPage( panel , “second page - second book” )

self.secondBook.SetSelection(1)

def framewithwidgets( self , event ):

frm = wx.Frame(None, -1, “Teste”, size=(640,480) )

panel = scrolled.ScrolledPanel( frm , -1 , style=wx.SUNKEN_BORDER )

sizer = wx.BoxSizer( wx.VERTICAL )

lbox = wx.StaticBox( panel, -1, ‘’ )

lsizer = wx.StaticBoxSizer( lbox, wx.HORIZONTAL )

lsizer.Add( self.createwidgets( panel ) , 1, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER, 10 )

sizer.Add( lsizer ,0, wx.ALL | wx.ALIGN_CENTER, 5 )

panel.SetSizer( sizer )

panel.SetupScrolling()

frm.Show()

def createwidgets( self , oParent ):

lsizer = wx.BoxSizer( wx.VERTICAL )

for item in range( 0 ,70):

lbl = wx.StaticText( oParent, -1, “Test” )

lsizer.Add( lbl )

textedit = wx.TextCtrl( oParent, -1, “” , size=( 200, 22 ) )

lsizer.Add( textedit )

return lsizer

if name == ‘main’:

import sys,os

app = wx.PySimpleApp()

frame = TestFrame()

frame.Show(True)

app.MainLoop()

The slowness in the creation of wx.TextCtrl also occurs using wx.Notebook.

Could someone help me?

···

Em quarta-feira, 26 de março de 2014 10h57min36s UTC-3, EdsonSil Sil escreveu:

Hello!

A help please.

In the example below because creating controls is much faster than the frame on the page of the book?

thank you

( python 2.7 and wx.python 2.8 )

import wx

import wx.lib.scrolledpanel as scrolled

import wx.lib.agw.flatnotebook as fnb

import wx.lib.agw.aui as aui

class TestFrame(wx.Frame):

def init( self ):

wx.Frame.init(self, None, -1, “Test Frame”, size=(640,480))

self.paneldados = wx.Panel( self )

sizer = wx.BoxSizer(wx.VERTICAL)

self.primarybook = fnb.FlatNotebook( self.paneldados , wx.ID_ANY )

self.primarybook.SetAGWWindowStyleFlag( fnb.FNB_VC8|fnb.FNB_NO_NAV_BUTTONS )

self.primarybook.AddPage( self.createpanel( self.primarybook ) , “first book” )

sizer.Add( self.primarybook , 1, wx.EXPAND )

self.paneldados.SetSizer( sizer )

self.Maximize(True)

def createpanel( self , primarybook ):

self.secondBook = aui.AuiNotebook( primarybook , agwStyle=wx.DOUBLE_BORDER )

panel = wx.Panel( self.secondBook )

sizer = wx.BoxSizer( wx.VERTICAL )

a = wx.Button( panel, -1, “second pag with Widgets”, ( 200, 30 ))

self.Bind( wx.EVT_BUTTON, self.pagewithwidgets, a )

sizer.Add( a )

b = wx.Button( panel, -1, “frame with Widgets”, ( 200, 30 ))

self.Bind( wx.EVT_BUTTON, self.framewithwidgets, b )

sizer.Add( b )

panel.SetSizer( sizer )

self.secondBook.AddPage( panel , “first page - second book” )

return self.secondBook

def pagewithwidgets( self , event ):

panel = scrolled.ScrolledPanel( self.secondBook , -1 , style=wx.SUNKEN_BORDER )

sizer = wx.BoxSizer( wx.VERTICAL )

lbox = wx.StaticBox( panel, -1, ‘’ )

lsizer = wx.StaticBoxSizer( lbox, wx.HORIZONTAL )

lsizer.Add( self.createwidgets( panel ) , 1, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER, 10 )

sizer.Add( lsizer ,0, wx.ALL | wx.ALIGN_CENTER, 5 )

panel.SetSizer( sizer )

panel.SetupScrolling()

self.secondBook.AddPage( panel , “second page - second book” )

self.secondBook.SetSelection(1)

def framewithwidgets( self , event ):

frm = wx.Frame(None, -1, “Teste”, size=(640,480) )

panel = scrolled.ScrolledPanel( frm , -1 , style=wx.SUNKEN_BORDER )

sizer = wx.BoxSizer( wx.VERTICAL )

lbox = wx.StaticBox( panel, -1, ‘’ )

lsizer = wx.StaticBoxSizer( lbox, wx.HORIZONTAL )

lsizer.Add( self.createwidgets( panel ) , 1, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER, 10 )

sizer.Add( lsizer ,0, wx.ALL | wx.ALIGN_CENTER, 5 )

panel.SetSizer( sizer )

panel.SetupScrolling()

frm.Show()

def createwidgets( self , oParent ):

lsizer = wx.BoxSizer( wx.VERTICAL )

for item in range( 0 ,70):

lbl = wx.StaticText( oParent, -1, “Test” )

lsizer.Add( lbl )

textedit = wx.TextCtrl( oParent, -1, “” , size=( 200, 22 ) )

lsizer.Add( textedit )

return lsizer

if name == ‘main’:

import sys,os

app = wx.PySimpleApp()

frame = TestFrame()

frame.Show(True)

app.MainLoop()

Hi,

The slowness in the creation of wx.TextCtrl also occurs using wx.Notebook.

Don't understand why it is that much slower, but adding a Freeze/Thaw helped a lot:
2.9.5.0
Frame: 0.0499999523163
Page: 0.0560002326965

Before I had 2.5 something for the Page.

Attached the modified version.

By the way PySimpleApp() is deprecated in Phoenix and not really needed in recent wxPython versions, so either use just wx.App or the WIT -http://wiki.wxpython.org/Widget%20Inspection%20Tool.

Werner

SlowTCcreate.py (3.16 KB)

···

On 4/30/2014 14:15, 'EdsonSil Sil' via wxPython-users wrote:

Hello Werner,

Improved with the Freeze / Thaw.

Another interesting detail is that if you add the attribute pos = (200,100) in wx.TextCtrl (oParent, -1, “”, (200, 100), size = (200, 22)), also accelerates the creation.

···

Em quarta-feira, 30 de abril de 2014 11h18min42s UTC-3, werner escreveu:

Hi,

On 4/30/2014 14:15, ‘EdsonSil Sil’ via wxPython-users wrote:

The slowness in the creation of wx.TextCtrl also occurs using wx.Notebook.

Don’t understand why it is that much slower, but adding a Freeze/Thaw
helped a lot:

2.9.5.0

Frame: 0.0499999523163

Page: 0.0560002326965

Before I had 2.5 something for the Page.

Attached the modified version.

By the way PySimpleApp() is deprecated in Phoenix and not really needed
in recent wxPython versions, so either use just wx.App or the WIT
-http://wiki.wxpython.org/Widget%20Inspection%20Tool.

Werner

Hey Werner, how did you profile just adding the page? (or both, really).

Thanks,
Che

···

On Wed, Apr 30, 2014 at 10:18 AM, Werner <wernerfbd@gmx.ch> wrote:

Hi,

On 4/30/2014 14:15, 'EdsonSil Sil' via wxPython-users wrote:

The slowness in the creation of wx.TextCtrl also occurs using wx.Notebook.

Don't understand why it is that much slower, but adding a Freeze/Thaw
helped a lot:
2.9.5.0
Frame: 0.0499999523163
Page: 0.0560002326965

Before I had 2.5 something for the Page.

Hi,

···

On 4/30/2014 19:02, 'EdsonSil Sil' via wxPython-users wrote:

Hello Werner,

Improved with the Freeze / Thaw.
Another interesting detail is that if you add the attribute pos = (200,100) in wx.TextCtrl (oParent, -1, "", (200, 100), size = (200, 22)), also accelerates the creation.

That's weird as this means that it has to work even more, i.e. you position it and then the sizer kicks in and does its work, i.e. it most likely moves it again.

Werner

Nothing fancy just a timeit call around the method call.
Werner

···

Hi Che,

  On 4/30/2014 20:29, C M wrote:
        On Wed, Apr 30, 2014 at 10:18 AM,

Werner wernerfbd@gmx.ch
wrote:

Hi,

            On 4/30/2014 14:15, 'EdsonSil Sil' via wxPython-users

wrote:

              The slowness in the creation of wx.TextCtrl also

occurs using wx.Notebook.

          Don't understand why it is that much slower, but adding a

Freeze/Thaw helped a lot:

          2.9.5.0

          Frame: 0.0499999523163

          Page: 0.0560002326965


          Before I had 2.5 something for the Page.
          Hey Werner, how did you profile just adding the page? 

(or both, really).

Hi Werner,

Puts the pos in your example and compares the creation time. Is incredibly faster.

thank you

···

Em quarta-feira, 30 de abril de 2014 15h41min47s UTC-3, werner escreveu:

Hi Che,

  On 4/30/2014 20:29, C M wrote:
        On Wed, Apr 30, 2014 at 10:18 AM, > > Werner <wern...@gmx.ch> > >             wrote:

Hi,

            On 4/30/2014 14:15, 'EdsonSil Sil' via wxPython-users > > > wrote:
              The slowness in the creation of wx.TextCtrl also

occurs using wx.Notebook.

          Don't understand why it is that much slower, but adding a

Freeze/Thaw helped a lot:

          2.9.5.0

          Frame: 0.0499999523163

          Page: 0.0560002326965


          Before I had 2.5 something for the Page.
          Hey Werner, how did you profile just adding the page? 

(or both, really).

Nothing fancy just a timeit call around the method call.

Werner