wx.ScrolledWindow scrollbar is going to the top after closing subframe

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

wx.ScrolledWindow scrollbar is going to the top after closing subframe

Max

Hello!

In my app I need to make around 150 dynamically created panels with descriptions and buttons. 

Each button will show another url in new window. 

When you scroll main window for example to middle and click button on panel new frame with url shows. 

When you close it scrollbar goes to the top of main frame. 

How can I prevent that and keep scrollbar in main frame in same position like before opening subwindow?

Thank You for any help!


import wx
import wx.lib.scrolledpanel
import wx.html2

class Start ( wx.Frame ):
    def __init__( self, parent ):
        wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = 
        wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 800,800 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )

        self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
        self.SetBackgroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_HIGHLIGHT ) )
        bSizer23 = wx.BoxSizer( wx.VERTICAL )

        self.m_scrolledWindow2 = wx.ScrolledWindow( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.HSCROLL|wx.VSCROLL )
        self.m_scrolledWindow2.SetScrollRate( 5, 5 )
        bSizer24 = wx.BoxSizer( wx.VERTICAL )

        for x in range(100):
            self.m_panel1 = wx.Panel( self.m_scrolledWindow2, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
            self.m_panel1.SetBackgroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_INFOBK ) )

            bSizer25 = wx.BoxSizer( wx.VERTICAL )
            self.m_panel2 = wx.Panel( self.m_panel1, wx.ID_ANY, wx.DefaultPosition, wx.Size( 500,300 ), wx.TAB_TRAVERSAL )
            bSizer26 = wx.BoxSizer( wx.VERTICAL )

            #buttons
            bSizer12 = wx.BoxSizer( wx.HORIZONTAL )
            bSizer12 = wx.BoxSizer( wx.HORIZONTAL )
            self.strona_projektu_button = wx.Button( self.m_panel2, wx.ID_ANY, u"Button", wx.DefaultPosition, wx.DefaultSize, 0 )
            bSizer12.Add( self.strona_projektu_button, 0, wx.ALL, 5 )

            self.strona_projektu_button.Bind(wx.EVT_BUTTON, lambda evt, name='Button': self.show_web(evt,))

            self.m_panel2.SetSizer( bSizer26 )
            self.m_panel2.Layout()
            bSizer26.Fit( self.m_panel2 )
            bSizer25.Add( self.m_panel2, 1, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5 )

            self.m_panel1.SetSizer( bSizer25 )
            self.m_panel1.Layout()
            bSizer25.Fit( self.m_panel1 )
            bSizer24.Add( self.m_panel1, 1, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5 )

            self.m_scrolledWindow2.SetSizer( bSizer24 )
            self.m_scrolledWindow2.Layout()
            bSizer24.Fit( self.m_scrolledWindow2 )
            bSizer24.Layout()

        bSizer23.Add( self.m_scrolledWindow2, 1, wx.EXPAND |wx.ALL, 5 )
        self.SetSizer( bSizer23 )
        self.Layout()
        self.Centre( wx.BOTH )


    def show_web( self, event,  ):
        dialog = MyBrowser(None) 
        dialog.browser.LoadURL('https://google.com') 
        dialog.Show() 


class MyBrowser(wx.Frame): 
    def __init__(self, *args, **kwds): 
        wx.Frame.__init__(self, *args, **kwds) 
        self.Bind ( wx.EVT_CLOSE, self.on_close )
        sizer = wx.BoxSizer(wx.VERTICAL) 
        self.browser = wx.html2.WebView.New(self) 
        sizer.Add(self.browser, 1, wx.EXPAND, 10) 
        self.SetSizer(sizer) 
        self.SetSize((1000, 700)) 

    def on_close ( self, event ):    
        self.Destroy()

if __name__=='__main__':
    app = wx.App(0)
    frame = Start(None).Show()
    app.MainLoop()



--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Max
Reply | Threaded
Open this post in threaded view
|

Re: wx.ScrolledWindow scrollbar is going to the top after closing subframe

Max
Forget add system details: wxpython 4.0.1, Python 3.6.4, Mac OS Sierra 10.12.4 

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.