def getImage(imageName, imgDict=None, tkImage=True, percent=100, maxheight=None): """ Search for the image in the RESOURCES path list. """ if imageName is None: return None if imgDict is not None and imageName in imgDict: return imgDict[imageName] if not os.path.isabs(imageName): imagePath = findResource(imageName) else: imagePath = imageName image = None if imagePath: from PIL import Image image = Image.open(imagePath) w, h = image.size newSize = None if percent != 100: # Display image with other dimensions fp = float(percent)/100.0 newSize = int(fp * w), int(fp * h) elif maxheight and h > maxheight: newSize = int(w * float(maxheight)/h), maxheight if newSize: image.thumbnail(newSize, Image.ANTIALIAS) if tkImage: from PIL import ImageTk image = ImageTk.PhotoImage(image) if imgDict is not None: imgDict[imageName] = image return image
def getImage(imageName, imgDict=None, tkImage=True, percent=100, maxheight=None): """ Search for the image in the RESOURCES path list. """ if imageName is None: return None if imgDict is not None and imageName in imgDict: return imgDict[imageName] if not os.path.isabs(imageName): imagePath = findResource(imageName) else: imagePath = imageName image = None if imagePath: from PIL import Image image = Image.open(imagePath) w, h = image.size newSize = None if percent != 100: # Display image with other dimensions fp = float(percent) / 100.0 newSize = int(fp * w), int(fp * h) elif maxheight and h > maxheight: newSize = int(w * float(maxheight) / h), maxheight if newSize: image.thumbnail(newSize, Image.ANTIALIAS) if tkImage: from PIL import ImageTk image = ImageTk.PhotoImage(image) if imgDict is not None: imgDict[imageName] = image return image
def __init__(self, title='', masterWindow=None, weight=True, minsize=(500, 300), icon=None, **kwargs): """Create a Tk window. title: string to use as title for the windows. master: if not provided, the windows create will be the principal one weight: if true, the first col and row will be configured with weight=1 minsize: a minimum size for height and width icon: if not None, set the windows icon """ if masterWindow is None: Window._root = self self.root = tk.Tk() self._images = {} else: self.root = tk.Toplevel(masterWindow.root) self._images = masterWindow._images self.root.withdraw() self.root.title(title) if weight: configureWeigths(self.root) if not minsize is None: self.root.minsize(minsize[0], minsize[1]) if not icon is None: path = findResource(icon) abspath = os.path.abspath(path) self.root.iconbitmap("@" + abspath) self.root.protocol("WM_DELETE_WINDOW", self._onClosing) self._w, self._h, self._x, self._y = 0, 0, 0, 0 self.root.bind("<Configure>", self._configure) self.master = masterWindow setCommonFonts(self) if kwargs.get('enableQueue', False): self.queue = Queue.Queue(maxsize=0) else: self.queue = None