I’m having trouble with thumbnail1, thumbnail2 and thumbnail3, they are too small and I’ve been changing the flags from the sizer trying to enlarge them but I’m been unable to do so.
I have no trouble if I get rid of t2Sizer and t1Sizer and put them directly on topmostSizer, but I don’t want that, so what am I missing?
Here is the working code, you just have to change the paths:
from argparse import _AppendAction
import wx
import wx.lib.agw.thumbnailctrl as TC
import cv2
import os
import glob
import wx.stc as stc
from time import sleep
class MyForm(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, title='Test')
# Add a panel so it looks correct on all platforms
self.panel = wx.Panel(self, wx.ID_ANY)
bmp = wx.Image("#PATH_TO_IMAGE\\test.png", wx.BITMAP_TYPE_PNG).ConvertToBitmap()
inputTxtOne = wx.TextCtrl(self.panel, wx.LEFT, '', size=(1500, 50))
inputTxtOne.SetFont(wx.Font(15, wx.SWISS, wx.NORMAL, wx.NORMAL)) # Font & size ARIAL
thumbnail1 = TC.ThumbnailCtrl(self.panel, imagehandler=TC.NativeImageHandler)
thumbnail2 = TC.ThumbnailCtrl(self.panel, imagehandler=TC.NativeImageHandler)
thumbnail3 = TC.ThumbnailCtrl(self.panel, imagehandler=TC.NativeImageHandler)
thumbnail1.EnableDragging(True)
thumbnail2.EnableDragging(True)
thumbnail3.EnableDragging(True)
thumbnail1.ShowDir("XXXX") #Link to image folder
# ################VID################ #
fr = 150
v_files = glob.glob(os.path.abspath(
os.path.join("#PATH" + "\\Videos", "#FolderName", '*.mp4'))) # Example: C\Folder1\Folder\Videos\FolderName
for i in range(len(v_files)):
cap = cv2.VideoCapture(v_files[i])
total_frames = cap.get(7)
cap.set(1, fr)
ret, frame = cap.read()
cv2.imwrite(v_files[i].split(".")[0] + '.mp4.jpg', frame)
# print thumbnail.GetZoomFactor()
# TODO On the receiving end, when I read a jpg file which does not exist I have to search for the mp4
thumbnail3.SetZoomFactor(1.8)
thumbnail3.ShowDir("#PATH") #C\Folder1\Folder\Videos\FolderName
topmostSizer = wx.BoxSizer(wx.VERTICAL)
topSizer = wx.BoxSizer(wx.HORIZONTAL)
t1Sizer = wx.BoxSizer(wx.VERTICAL)
#t2Sizer = wx.BoxSizer(wx.VERTICAL)
self.image = wx.StaticBitmap(self.panel, -1, bmp)
topmostSizer.AddSpacer(20)
topmostSizer.Add(self.image, proportion=0, flag=wx.ALIGN_CENTER)
topmostSizer.AddSpacer(20)
topmostSizer.Add(inputTxtOne, proportion=0, flag=wx.ALIGN_CENTER)
topmostSizer.AddSpacer(20)
topmostSizer.Add(topSizer, proportion=0, flag=wx.ALIGN_CENTER)
t1Sizer.Add(thumbnail1, proportion=0)
#t1Sizer.Add(thumbnail2, proportion=0, flag=wx.ALIGN_LEFT | wx.SHAPED | wx.EXPAND)
#t1Sizer.Add(thumbnail3, proportion=0, flag=wx.ALIGN_LEFT | wx.SHAPED | wx.EXPAND)
topSizer.Add(t1Sizer, proportion=0)
sleep(0.8)
for i in range(len(v_files)):
os.remove(v_files[i].split(".")[0] + '.mp4.jpg')
self.panel.SetSizer(topmostSizer)
self.panel.MaxSize
topmostSizer.Fit(self)
self.Maximize(True)
def onOK(self, event):
# Do something
print 'onOK handler'
def onCancel(self, event):
self.closeProgram()
def closeProgram(self):
self.Close()
class Log(stc.StyledTextCtrl):
"""
Subclass the StyledTextCtrl to provide additions
and initializations to make it useful as a log window.
"""
def __init__(self, parent, style=wx.SIMPLE_BORDER):
"""
Constructor
"""
stc.StyledTextCtrl.__init__(self, parent, style=style)
self._styles = [None] * 32
self._free = 1
def getStyle(self, c='black'):
"""
Returns a style for a given colour if one exists. If no style
exists for the colour, make a new style.
If we run out of styles, (only 32 allowed here) we go to the top
of the list and reuse previous styles.
"""
free = self._free
if c and isinstance(c, (str, unicode)):
c = c.lower()
else:
c = 'black'
try:
style = self._styles.index(c)
return style
except ValueError:
style = free
self._styles[style] = c
self.StyleSetForeground(style, wx.NamedColour(c))
free += 1
if free > 31:
free = 0
self._free = free
return style
def write(self, text, c=None):
"""
Add the text to the end of the control using colour c which
should be suitable for feeding directly to wx.NamedColour.
'text' should be a unicode string or contain only ascii data.
"""
style = self.getStyle(c)
lenText = len(text.encode('utf8'))
end = self.GetLength()
self.AddText(text)
self.StartStyling(end, 31)
self.SetStyling(lenText, style)
self.EnsureCaretVisible()
__call__ = write
class MyTextDropTarget(wx.TextDropTarget):
def __init__(self, window, log):
wx.TextDropTarget.__init__(self)
self.window = window
self.log = log
def OnDropText(self, x, y, text):
self.window.WriteText("(%d, %d)\n%s\n" % (x, y, text))
def OnDragOver(self, x, y, d):
return wx.DragCopy
class MyFileDropTarget(wx.FileDropTarget):
def __init__(self, window, log):
wx.FileDropTarget.__init__(self)
self.window = window
self.log = log
def OnDropFiles(self, x, y, filenames):
self.window.SetInsertionPointEnd()
self.window.WriteText("\n%d file(s) dropped at %d,%d:\n" %
(len(filenames), x, y))
for file in filenames:
self.window.WriteText(file + '\n')
class FileDropPanel(wx.Panel):
def __init__(self, parent, log):
wx.Panel.__init__(self, parent, -1)
# self.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False))
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(
wx.StaticText(self, -1, " \nDrag some files here:"),
0, wx.EXPAND | wx.ALL, 2
)
self.text = wx.TextCtrl(
self, -1, "",
style=wx.TE_MULTILINE | wx.HSCROLL | wx.TE_READONLY
)
dt = MyFileDropTarget(self, log)
self.text.SetDropTarget(dt)
sizer.Add(self.text, 1, wx.EXPAND)
sizer.Add(
wx.StaticText(self, -1, " \nDrag some text here:"),
0, wx.EXPAND | wx.ALL, 2
)
self.text2 = wx.TextCtrl(
self, -1, "",
style=wx.TE_MULTILINE | wx.HSCROLL | wx.TE_READONLY
)
dt = MyTextDropTarget(self.text2, log)
self.text2.SetDropTarget(dt)
sizer.Add(self.text2, 1, wx.EXPAND)
self.SetAutoLayout(True)
self.SetSizer(sizer)
def WriteText(self, text):
self.text.WriteText(text)
def SetInsertionPointEnd(self):
self.text.SetInsertionPointEnd()
# Run the program
if __name__ == '__main__':
app = wx.App(False)
frame = MyForm().Show()
#import wx.lib.inspection
#wx.lib.inspection.InspectionTool().Show()
app.MainLoop()
Thanks for the help!