除一部分外,我的SwapImage函数在我的脚本的5个区域中均能完美工作。
当调用“ CompileImages”时,它开始处理图像。我想在调用该函数的之前行中切换图像,但它似乎立即锁定了界面,并且不切换它。
是否有一种方法可以强制它在切换图像功能继续前进(并锁定)之前运行它?
#the button I’m using…
genButton = wx.lib.buttons.GenButton(panel2, -1, label='Generate', pos=(8, 66), size=(136, 26))
genButton.Bind(wx.EVT_BUTTON, self.RunCompileFunction)
#… calls this function
def RunCompileFunction(self, event):
self.SwapImage(image_fileprogress)
self.CompileImages(self)
#this SwapImage function works at every other point EXCEPT in the above function, it seems to skip over it as if it has more important things to do.
#Curiously if I comment out the call to CompileImages function it DOES swap the image.
def SwapImage(self, imagename):
self.bitmap1 = wx.StaticBitmap(panel1, -1, imagename, (0, 0))
backgroundimage = imagename
#This function just starts processing images and causes the interface lockup
def CompileImages(self, event):
if len(MyFrame.filenames) > 8 and len(MyFrame.maskfiles) <= 2:
print("Ensure you've dropped your mask files too!")
#myCursor = wx.StockCursor(wx.CURSOR_WAIT)
#frame.SetCursor(myCursor)
global coloralphareq
global opacityalphareq
# get first image size and save to variable
getsize = Image.open(MyFrame.filenames[0])
mwidth, mheight = getsize.size
# get its .extension format
# imgformat = str(x)[-3:]
# imgformat = (str(MyFrame.filenames[0].format))
# print(imgformat)
# for each image in the list...
for map in maptypes:
# print(map)
# files = any file with the current mapname in it
files = [s for s in MyFrame.filenames if map in s]
# print(files)
if len(files) > 0:
map = map[:-1]
# remove names that are clashing
if map == "Normal": self.RemoveFiles(files, "Normal_OpenGL.")
if map == "Normal_OpenGL": self.RemoveFiles(files, "Normal.")
if map == "AO": self.RemoveFiles(files, "Mixed_AO.")
if map == "Metallic": self.RemoveFiles(files, "MetallicSmoothness.")
if map == "MetallicSmoothness": self.RemoveFiles(files, "Metallic.")
if len(files) > 0:
# find mode, format, size
# choose the background alphaColor
if map == "Base_Color" or map == "BaseColor" or map == "Diffuse":
if self.coloralphareq == 1:
self.CompileTheseImagesRGBA(map, files, (0, 0, 0, 0), 'RGBA', 0, (0, 0, 0, 0), mwidth,
mheight)
elif self.coloralphareq == 0:
self.CompileTheseImagesRGB(map, files, (0, 0, 0))
elif map == "Opacity":
if self.opacityalphareq == 1:
self.CompileTheseImagesRGBA(map, files, (0, 0, 0, 0), 'RGBA', 0, (0, 0, 0, 0), mwidth,
mheight)
elif self.opacityalphareq == 0:
self.CompileTheseImagesRGB(map, files, (256, 256, 256))
elif map == "Normal_OpenGL" or map == "Normal":
self.CompileTheseImagesRGB(map, files, (128, 128, 255))
elif map == "AlbedoTransparency" or map == "MetallicSmoothness" or map == "SpecularSmoothness":
self.CompileTheseImagesRGB(map, files, (0, 0, 0, 0))
elif map == "Height":
self.CompileTheseImagesRGB(map, files, (128, 128, 128))
elif map == "Roughness":
self.CompileTheseImagesRGB(map, files, (136, 136, 136))
elif map == "Mixed_AO" or map == "Reflection" or map == "AO":
self.CompileTheseImagesRGB(map, files, (256, 256, 256))
elif map == "Glossiness" or map == "f0" or map == "ior":
self.CompileTheseImagesRGB(map, files, (187, 187, 187))
else:
self.CompileTheseImagesRGBA(map, files, (0, 0, 0, 0), 'RGBA', 0, (0, 0, 0, 0), mwidth, mheight)