ScrolledPanel size (?) problem

ScrolledPanel size (?) problem

Hi All,

I am trying to make a Dialog with fixed parts and a dynamical part. The dynamical part may grow so that the window no longer fits on the screeen. For that part I wish to use a ScrolledPanel. Both the horizontal and vertical sizes seem to go wrong, but I can not figure out how to get it right. I'll attach a stripped down version.

Using wx.Dialog I define a new class SDialog which only places 'okay' and 'cancel' buttons. On this dialog I put simple or compound items using 'NestPanel' derived form ScrolledPanel. NestPanel serves two purposes, one is to uniformize TextCtrl, Choice etc so that I can always use functions GetValue and SetValue. The second is to be able to build a compound item in which subitems can be added or deleted by the user. The idea is that NestPanels can be nested. Now I wish to be able to make a dynamical NestPanel, somewhere in between, scrollable. 'To scroll or not to scroll' is an argument of the init function of NestPanel. As long as I do not use scrolling, everything works fine (apart from possibly growing off the screen), but when I use scrolling the size of the scrolled panel is wrong, in particular too small. In the attached file the difference in scrolling or not is determined in 'NicknamesDialog' by (un)commenting the right lines.

Any help on this problem will be greatly appreciated. I've been struggling with it for quite some time. I also read many questions (and answers) about scrolling but it did not help me yet.

Some version details:

wxpython version: 2.9.4.0 osx-cocoa (classic)
python version: 2.7.2 (default, Oct 11 2012, 20:14:37)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)]
platform: darwin

Best regards, Igor

scrolltest.py (7.91 KB)

Igor Hoveijn wrote:

ScrolledPanel size (?) problem

Hi All,

I am trying to make a Dialog with fixed parts and a dynamical part. The dynamical part may grow so that the window no longer fits on the screeen. For that part I wish to use a ScrolledPanel. Both the horizontal and vertical sizes seem to go wrong, but I can not figure out how to get it right. I'll attach a stripped down version.

Using wx.Dialog I define a new class SDialog which only places 'okay' and 'cancel' buttons. On this dialog I put simple or compound items using 'NestPanel' derived form ScrolledPanel. NestPanel serves two purposes, one is to uniformize TextCtrl, Choice etc so that I can always use functions GetValue and SetValue. The second is to be able to build a compound item in which subitems can be added or deleted by the user. The idea is that NestPanels can be nested. Now I wish to be able to make a dynamical NestPanel, somewhere in between, scrollable. 'To scroll or not to scroll' is an argument of the init function of NestPanel. As long as I do not use scrolling, everything works fine (apart from possibly growing off the screen), but when I use scrolling the size of the scrolled panel is wrong, in particular too small. In the attached file the difference in scrolling or not is determined in 'NicknamesDialog' by (un)commenting the right lines.

Any help on this problem will be greatly appreciated. I've been struggling with it for quite some time. I also read many questions (and answers) about scrolling but it did not help me yet.

In case you still need help with this I've tweaked your sample to work like how I think you want it (attached). Basically I just fiddled with proportions, min sizes, default sizes, etc.

Here is a diff of the changes I made so you can easily see what is different.

--- scrolltest.py 2013-12-17 17:23:32.000000000 -0800
+++ scrolltest-1.py 2013-12-18 13:49:14.000000000 -0800
@@ -76,14 +76,14 @@
          self.SetSizer(self.vbox)

- def xAddChild(self, childclass, childkey = None):
+ def xAddChild(self, childclass, childkey = None, proportion=0):
          if childkey:
              key = childkey
          else:
              key = NewId(self.children.keys())
          child = childclass(self, key)
          self.children[key] = child
- self.vbox.Add(child, 0, wx.EXPAND|wx.ALL, 5)
+ self.vbox.Add(child, proportion, wx.EXPAND|wx.ALL, 5)
          self.xFit()
          return key

@@ -109,8 +109,8 @@
          if self.scrolled:
              self.Layout()
              self.SetupScrolling()
- self.vbox.Fit(self)
- self.parent.xFit()
+ #self.vbox.Fit(self)
+ #self.parent.xFit()

      def SetChildValue(self, key, value):
@@ -142,7 +142,7 @@
          self.vbox = wx.BoxSizer(wx.VERTICAL)

          self.editdialog = EDialog(self, name, nicknames, age)
- self.vbox.Add(self.editdialog, 0, wx.ALL, 5)
+ self.vbox.Add(self.editdialog, 1, wx.ALL|wx.EXPAND, 5)

          self.vbox.Add(wx.StaticLine(self), 0, wx.EXPAND|wx.ALL, 5)

@@ -178,8 +178,9 @@

          self.vbox.Add(wx.StaticLine(self), 0, wx.EXPAND|wx.ALL, 5)

- self.xAddChild(NicknamesDialog, NICKNAMES)
+ self.xAddChild(NicknamesDialog, NICKNAMES, 1)
          nicknames = self.children[NICKNAMES]
+ nicknames.SetMinSize((-1, 225))
          for s in self.nnames:
              key = nicknames.xAddChild(NicknameDialog)
              nicknames.SetChildValue(key, s)
@@ -245,8 +246,8 @@
  class NicknamesDialog(NestPanel):

      def __init__(self, parent, key = None):
-# NestPanel.__init__(self, parent, key, True) # to scroll
- NestPanel.__init__(self, parent, key, False) # or not to scroll
+ NestPanel.__init__(self, parent, key, True) # to scroll
+ #NestPanel.__init__(self, parent, key, False) # or not to scroll

@@ -258,12 +259,12 @@

      def __init__(self, parent, key = None):
          NestPanel.__init__(self, parent, key)
- self.entry = wx.TextCtrl(self, -1, '', size = (100, 25))
+ self.entry = wx.TextCtrl(self, -1, '', size = (100, -1))

          hbox = wx.BoxSizer(wx.HORIZONTAL)
          btn = wx.Button(self, -1, label = 'Del')
          btn.Bind(wx.EVT_BUTTON, self.OnDelete)
- hbox.Add(wx.StaticText(self, 0, 'Nickname:', size = (175, 25)), 0, wx.ALL, 2)
+ hbox.Add(wx.StaticText(self, 0, 'Nickname:'), 0, wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, 4)
          hbox.Add(self.entry, 0, wx.ALL, 2)
          hbox.Add(btn, 0, wx.ALL, 2)
          self.vbox.Add(hbox)

scrolltest-1.py (7.99 KB)

···

--
Robin Dunn
Software Craftsman

Hi Robin Dunn,

First of all I have to apologise for my late reaction. I had several other obligations… Anyway, thanks very much for your help. Your suggestions indeed solved my problem. I updated my application (scrolltest.py is a drastically trimmed down version) according to your changes and now it works as intended. I only wish I had some more documentation on functions like ‘Fit’, ‘Layout’, ‘SetAutoLayout’, ‘SetMinSize’ etc. I get the impression that they do not live on the same hierarchical level and they also seem to have nontrivial commutation relations. With a bit more understanding of the layout mechanisms I would not have to bother you experts. Nevertheless, thanks very much.

Best regards, Igor Hoveijn

···

Op donderdag 19 december 2013 02:19:16 UTC+1 schreef Robin Dunn:

Igor Hoveijn wrote:

ScrolledPanel size (?) problem

Hi All,

I am trying to make a Dialog with fixed parts and a dynamical part. The dynamical part may grow so that the window no longer fits on the screeen. For that part I wish to use a ScrolledPanel. Both the horizontal and vertical sizes seem to go wrong, but I can not figure out how to get it right. I’ll attach a stripped down version.

Using wx.Dialog I define a new class SDialog which only places ‘okay’ and ‘cancel’ buttons. On this dialog I put simple or compound items using ‘NestPanel’ derived form ScrolledPanel. NestPanel serves two purposes, one is to uniformize TextCtrl, Choice etc so that I can always use functions GetValue and SetValue. The second is to be able to build a compound item in which subitems can be added or deleted by the user. The idea is that NestPanels can be nested. Now I wish to be able to make a dynamical NestPanel, somewhere in between, scrollable. ‘To scroll or not to scroll’ is an argument of the init function of NestPanel. As long as I do not use scrolling, everything works fine (apart from possibly growing off the screen), but when I use scrolling the size of the scrolled panel is wrong, in particular too small. In the attached file the difference in scrolling or not is determined in ‘NicknamesDialog’ by (un)commenting the right lines.

Any help on this problem will be greatly appreciated. I’ve been struggling with it for quite some time. I also read many questions (and answers) about scrolling but it did not help me yet.

In case you still need help with this I’ve tweaked your sample to work
like how I think you want it (attached). Basically I just fiddled with
proportions, min sizes, default sizes, etc.

Here is a diff of the changes I made so you can easily see what is
different.

— scrolltest.py 2013-12-17 17:23:32.000000000 -0800

+++ scrolltest-1.py 2013-12-18 13:49:14.000000000 -0800

@@ -76,14 +76,14 @@

      self.SetSizer(self.vbox)
  • def xAddChild(self, childclass, childkey = None):
  • def xAddChild(self, childclass, childkey = None, proportion=0):

     if childkey:
    
         key = childkey
    
     else:
    
         key = NewId(self.children.keys())
    
     child = childclass(self, key)
    
     self.children[key] = child
    
  •    self.vbox.Add(child, 0, wx.EXPAND|wx.ALL, 5)
    
  •    self.vbox.Add(child, proportion, wx.EXPAND|wx.ALL, 5)
    
        self.xFit()
    
        return key
    

@@ -109,8 +109,8 @@

      if self.scrolled:

          self.Layout()

          self.SetupScrolling()
  •    self.vbox.Fit(self)
    
  •    self.parent.xFit()
    
  •    #self.vbox.Fit(self)
    
  •    #self.parent.xFit()
    
    
    
    
    
    def SetChildValue(self, key, value):
    

@@ -142,7 +142,7 @@

      self.vbox = wx.BoxSizer(wx.VERTICAL)



      self.editdialog = EDialog(self, name, nicknames, age)
  •    self.vbox.Add(self.editdialog, 0, wx.ALL, 5)
    
  •    self.vbox.Add(self.editdialog, 1, wx.ALL|wx.EXPAND, 5)
    
    
    
        self.vbox.Add(wx.StaticLine(self), 0, wx.EXPAND|wx.ALL, 5)
    

@@ -178,8 +178,9 @@

      self.vbox.Add(wx.StaticLine(self), 0, wx.EXPAND|wx.ALL, 5)
  •    self.xAddChild(NicknamesDialog, NICKNAMES)
    
  •    self.xAddChild(NicknamesDialog, NICKNAMES, 1)
    
        nicknames = self.children[NICKNAMES]
    
  •    nicknames.SetMinSize((-1, 225))
    
        for s in self.nnames:
    
            key = nicknames.xAddChild(NicknameDialog)
    
            nicknames.SetChildValue(key, s)
    

@@ -245,8 +246,8 @@

class NicknamesDialog(NestPanel):

  def __init__(self, parent, key = None):

-# NestPanel.init(self, parent, key, True) # to scroll

  •    NestPanel.__init__(self, parent, key, False)  # or not to scroll
    
  •    NestPanel.__init__(self, parent, key, True)   # to scroll
    
  •    #NestPanel.__init__(self, parent, key, False)  # or not to scroll
    

@@ -258,12 +259,12 @@

  def __init__(self, parent, key = None):

      NestPanel.__init__(self, parent, key)
  •    self.entry = wx.TextCtrl(self,  -1, '', size = (100, 25))
    
  •    self.entry = wx.TextCtrl(self,  -1, '', size = (100, -1))
    
    
    
        hbox = wx.BoxSizer(wx.HORIZONTAL)
    
        btn  = wx.Button(self, -1, label = 'Del')
    
        btn.Bind(wx.EVT_BUTTON, self.OnDelete)
    
  •    hbox.Add(wx.StaticText(self, 0, 'Nickname:', size = (175, 25)),
    
    0, wx.ALL, 2)
  •    hbox.Add(wx.StaticText(self, 0, 'Nickname:'),  0,
    

wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, 4)

      hbox.Add(self.entry, 0, wx.ALL, 2)

      hbox.Add(btn, 0, wx.ALL, 2)

      self.vbox.Add(hbox)


Robin Dunn

Software Craftsman

http://wxPython.org