def setMediaPath(file=None): global mediaFolder if (file == None): FileChooser.pickMediaPath() else: FileChooser.setMediaPath(file) mediaFolder = getMediaPath() return mediaFolder
def setMediaPath(self, directory): """Method to set the directory for the media Parameters ---------- directory : str the directory to use for the media path """ FileChooser.setMediaPath(directory)
def pickAFolder(): # Note: this needs to be done in a threadsafe manner, see FileChooser # for details how this is accomplished. dir = FileChooser.pickADirectory() if (dir != None): return str(dir + os.sep) return None
def getMediaPath(self, fileName): """Method to get the directory for the media Parameters ---------- fileName : str the fileName the base file name to use Returns ------- str the full path name by appending the file name to the media directory """ return FileChooser.getMediaPath(fileName)
def __init__(self, *args, **kwargs): """Initializer for Picture class """ self.filename = self.title = 'None' if len(args) == 0: # no parameters, make 100x200 picture with white background self.image = PIL.Image.new("RGB", (200, 100), (255, 255, 255)) elif len(args) == 1: if isinstance(args[0], str): self.filename = self.title = args[0] # Assume 'we've been passed a filename if not os.path.isfile(self.filename): # File not found, try prepending media path filepath = FileChooser.getMediaPath(self.filename) if os.path.isfile(filepath): self.filename = self.title = filepath try: self.image = PIL.Image.open(self.filename) except: self.image = PIL.Image.new("RGB", (600, 200)) draw = PIL.ImageDraw.Draw(self.image) draw.text((0, 100), "Couldn't load " + self.filename) elif isinstance(args[0], Picture): # We've been passed a Picture object self.image = args[0].image.copy() self.filename = args[0].filename self.title = args[0].title elif isinstance(args[0], PIL.Image.Image): # We've been passed a PIL image object self.image = args[0] try: self.filename = self.title = args[0].filename except AttributeError: pass elif len(args) == 2 or len(args) == 3: # We've been passed width and height, and possibly a color size = (int(args[0]), int(args[1])) c = Color(255, 255, 255) if len(args) == 2 else args[2] self.image = PIL.Image.new("RGB", size, c.color) else: print("Could not construct Picture object")
def getMediaPath(filename=""): return str(FileChooser.getMediaPath(filename))
def pickAFile(): # Note: this needs to be done in a threadsafe manner, see FileChooser # for details how this is accomplished. return str(FileChooser.pickAFile())