Reputation: 407
I am trying to build a code that would show the pdf files listed in a folder the way it appears in windows as thumbnails, I have an image (URL Below) that illustrates what I am trying to achieve.
https://scottiestech.info/wp-content/uploads/2012/10/unhappy_thumbnails.jpg
I understand there is the Thumbnailctrl widget that solves for this but I am trying to avoid using the widget..and to see if this can be achieved with wx.panel, wx.button etc..
I have a rough code but nothing seems to appear like the one in windows, had a tough time wrapping the text too..please help..
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(150,150))
self.rootPanel = wx.Panel(self)
innerPanel = wx.Panel(self.rootPanel,-1, size=(150,150), style=wx.ALIGN_CENTER)
innerPanel.SetBackgroundColour('WHITE')
hbox = wx.BoxSizer(wx.HORIZONTAL)
vbox = wx.BoxSizer(wx.VERTICAL)
innerBox = wx.BoxSizer(wx.VERTICAL)
buttonLabel = "Two this text was long so hence it was decided\n".center(5) + "Fox jumped over the river".center(5)
txt = wx.StaticText(innerPanel, id=-1, label=buttonLabel,style=wx.ALIGN_CENTER, name="")
bmp = wx.Bitmap("lion.jpg", wx.BITMAP_TYPE_ANY)
button = wx.BitmapButton(innerPanel, id=wx.ID_ANY, bitmap=bmp,size=(bmp.GetWidth()+10, bmp.GetHeight()+10))
innerBox.AddSpacer((150,75))
innerBox.Add(txt, 0, wx.CENTER)
innerBox.AddSpacer((150,75))
innerPanel.SetSizer(innerBox)
hbox.Add(innerPanel, 0, wx.ALL|wx.ALIGN_CENTER)
vbox.Add(hbox, 1, wx.ALL|wx.ALIGN_CENTER, 5)
self.rootPanel.SetSizer(vbox)
vbox.Fit(self)
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1, 'wxBoxSizer.py')
frame.Show(True)
frame.Center()
return True
app = MyApp(0)
app.MainLoop()
Upvotes: 0
Views: 187
Reputation: 6306
When you set the size of a widget with the size=
parameter in the constructor call, then it also sets the item's minimum size. The minimum size, if set, overrides the sizer's calculation of the best size of an item. So the first step is to remove the 2 instances of size=(150,150)
in your sample code.
The next issue is that you are not adding the bitmap button to the innerBox
sizer, so the layout of the button is not managed in any way, so it overlaps the static text.
Finally, using the Widget Inspection Tool is very helpful in debugging layout issues like this.
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)
self.rootPanel = wx.Panel(self)
innerPanel = wx.Panel(self.rootPanel,-1, style=wx.ALIGN_CENTER)
innerPanel.SetBackgroundColour('WHITE')
hbox = wx.BoxSizer(wx.HORIZONTAL)
vbox = wx.BoxSizer(wx.VERTICAL)
innerBox = wx.BoxSizer(wx.VERTICAL)
buttonLabel = "Two this text was long so hence it was decided\n".center(5) + "Fox jumped over the river".center(5)
txt = wx.StaticText(innerPanel, id=-1, label=buttonLabel,style=wx.ALIGN_CENTER, name="")
bmp = wx.Bitmap("pawprints.jpg", wx.BITMAP_TYPE_ANY)
button = wx.BitmapButton(innerPanel, id=wx.ID_ANY, bitmap=bmp,size=(bmp.GetWidth()+10, bmp.GetHeight()+10))
innerBox.AddSpacer((150,75))
innerBox.Add(txt)
innerBox.Add(button)
innerBox.AddSpacer((150,75))
innerPanel.SetSizer(innerBox)
hbox.Add(innerPanel, 0, wx.ALL|wx.ALIGN_CENTER)
vbox.Add(hbox, 1, wx.ALL|wx.ALIGN_CENTER, 5)
self.rootPanel.SetSizer(vbox)
vbox.Fit(self)
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1, 'wxBoxSizer.py')
frame.Show(True)
frame.Center()
return True
app = MyApp(0)
import wx.lib.inspection
wx.lib.inspection.InspectionTool().Show()
app.MainLoop()
Upvotes: 1