Search code examples
python-2.7wxpythonthumbnailssplitter

Thumbnailctrl size (trying to get it to fullscreen)


I've been trying to insert two Thubmnailctrl under a Multisplitter, I have managed to put them in there, but I can't manage to make them ocuppy the full space. On thumbnailctrl.py I've seen that on the the maximum size it can be is 350x280:

def SetThumbSize(self, width, height, border=6):
"""
Sets the thumbnail size as width, height and border.

:param `width`: the desired thumbnail width;
:param `height`: the desired thumbnail height;
:param `border`: the spacing between thumbnails.
"""

if width > 350 or height > 280:
    return

self._tWidth = width 
self._tHeight = height
self._tBorder = border
self.SetScrollRate((self._tWidth + self._tBorder)/4,
                   (self._tHeight + self._tBorder)/4)
self.SetSizeHints(self._tWidth + self._tBorder*2 + 16,
                  self._tHeight + self._tBorder*2 + 8)

But on the other hand on the demo under ThumbnailCtrl, it uses an Splitter to create a Thumbnailctrl as big as you want, so I don't know if I'm doing something wrong (maybe with Sizers) or is some feature from Splitter (totally diferent than multisplitter) that allows the Thumbnailctrl to occupy it's full space.

Thumbnailctrl + Splitter Demo:

import wx
import os
import sys

try:
    dirName = os.path.dirname(os.path.abspath(__file__))
except:
    dirName = os.path.dirname(os.path.abspath(sys.argv[0]))

sys.path.append(os.path.split(dirName)[0])

try:
    from agw import thumbnailctrl as TC
except ImportError:  # if it's not there locally, try the wxPython lib.
import wx.lib.agw.thumbnailctrl as TC


class MainFrame(wx.Frame):
def __init__(self, redirect=False, filename=None):
    wx.Frame.__init__(self, None, title="Elephant")

    # self.SetMenuBar(self.CreateMenuBar())

    splitter = wx.SplitterWindow(self, -1, style=wx.CLIP_CHILDREN | wx.SP_3D | wx.WANTS_CHARS | wx.SP_LIVE_UPDATE)
    self.panel = wx.Panel(splitter, -1)

    sizer = wx.BoxSizer(wx.HORIZONTAL)
    scroll = TC.ThumbnailCtrl(splitter, -1, imagehandler=TC.NativeImageHandler)

    scroll.ShowFileNames()
    if os.path.isdir("../bitmaps"):
        scroll.ShowDir(os.path.normpath(os.getcwd() + "/../bitmaps"))
    else:
        scroll.ShowDir(os.getcwd())

    self.TC = scroll

    splitter.SplitVertically(scroll, self.panel, 180)

    splitter.SetMinimumPaneSize(140)
    self.SetMinSize((700, 590))
    self.CenterOnScreen()

if __name__ == "__main__":
    app = wx.App(False)
    frame = MainFrame()
    # import wx.lib.inspection
    # wx.lib.inspection.InspectionTool().Show()
    app.MainLoop()

My attempt at a Multisplitter with two thumbnails (and when that works a third panel with text and stuff):

import wx
import os
import cv2
import ctypes
from PIL import Image
from wx.lib.splitter import MultiSplitterWindow

try:
    from agw import thumbnailctrl as TC
except ImportError:  # if it's not there locally, try the wxPython lib.
    import wx.lib.agw.thumbnailctrl as TC


class SamplePane(wx.Panel):
def __init__(self, parent):
    wx.Panel.__init__(self, parent)

    self.thumbnail11 = TC.ThumbnailCtrl(self, imagehandler=TC.NativeImageHandler, thumboutline=4)
    self.thumbnail11.EnableDragging(True)
    # self.thumbnail11.SetThumbSize(350, screensize[0] / 15, 25)  # For images -> Max values 350,280

    # ################VID################ #

    topmostSizer = wx.BoxSizer(wx.VERTICAL)

    topmostSizer.Add(self.thumbnail11, proportion=0, flag=wx.EXPAND)

    self.SetSizer(topmostSizer)
    self.MaxSize
    # topmostSizer.Fit(self)


class MainFrame(wx.Frame):
""""""

    def __init__(self):
        """Constructor"""
        wx.Frame.__init__(self, None, title="Elephant")

        splitter = MultiSplitterWindow(self, style=wx.SP_LIVE_UPDATE)
        # t1Sizer = wx.BoxSizer(wx.VERTICAL)
        # self.thumbnail11 = TC.ThumbnailCtrl(splitter, imagehandler=TC.NativeImageHandler, thumboutline=4)
        panel = SamplePane(splitter)
        splitter.AppendWindow(panel)
        panel2 = SamplePane(splitter)
        splitter.AppendWindow(panel2)
        # t1Sizer.Add(panel, proportion=0, flag=wx.EXPAND)
        self.Show()

if __name__ == "__main__":
    app = wx.App(False)

    frame = MainFrame()
    # import wx.lib.inspection
    # wx.lib.inspection.InspectionTool().Show()
    app.MainLoop()

As you can see there are two thumbnails and they expand left to right, but they are capped at a maximum height.

Thanks a lot for the help!


Solution

  • Not 100% sure what it is that you're trying achieve with this but I suspect that your problem is with the topmostSizer's proportion attribute.
    Try:

    topmostSizer.Add(self.thumbnail11, proportion=1, flag=wx.EXPAND)
    

    From the manual:

    proportion - Although the meaning of this parameter is undefined in wx.Sizer, it is used in wx.BoxSizer to indicate if a child of a sizer can change its size in the main orientation of the wx.BoxSizer - where 0 stands for not changeable and a value of more than zero is interpreted relative (a proportion of the total) to the value of other children of the same wx.BoxSizer.

    In this case, you have defined topmostSizer as VERTICAL