def _getSettings(self, iniline, xfactor, yfactor): """Load the image and read the settings Argument iniline -- a line of text describing a transparent button xfactor -- horizontal scaling yfactor -- vertical scaling """ inilist = iniline.split(ini.delimiter) image = Image.open(ini.getPath(inilist[0])) self._insleft = int(inilist[1]) self._instop = int(inilist[2]) self._textleft = int(inilist[3]) self._texttop = int(inilist[4]) self._activecolor = inilist[5] self._inactivecolor = inilist[6] #Scale image and values if any scaling shall be performed if(xfactor != 1 or yfactor != 1): (w, h) = image.size w = int(w * xfactor + 0.5) h = int(h * yfactor + 0.5) image = image.resize((w, h), Image.ANTIALIAS ) self._insleft = int(self._insleft * xfactor + 0.5) self._instop = int(self._instop * yfactor + 0.5) self._textleft = int(self._textleft * xfactor + 0.5) self._texttop = int(self._texttop * yfactor + 0.5) self._imageobj = ImageTk.PhotoImage(image)
def _setupDisplay(self, root, config): """Set screen size and add background image root -- the Tk instance of the application config -- ConfigParser containing application settings """ fullscreen = config.getboolean(ini.general, ini.fullscreen) bgimage = ini.getPath(config.get(ini.general, ini.bgimage)) image = Image.open(bgimage) backgroundIm = ImageTk.PhotoImage(image) if(fullscreen): screenwidth = root.winfo_screenwidth() screenheight = root.winfo_screenheight() (w, h) = image.size self._scalefactor = (screenwidth / float(w), screenheight / float(h)) image = image.resize((screenwidth, screenheight)) else: (screenwidth, screenheight) = image.size self._scalefactor = (1, 1) geom = "{}x{}+{}+{}".format(screenwidth, screenheight, 0, 0) root.geometry(geom) root.overrideredirect(1) background = Canvas(root, width = screenwidth, height = screenheight) self._canvas = background background.pack() backgroundIm = ImageTk.PhotoImage(image) self._backgroundIm = backgroundIm background.create_image(0,0, image = backgroundIm, anchor = NW)