def image(self, attrs): if self.in_defs: id = attrs.get('id', '') if id: self.named_objects[id] = ('object', 'image', attrs) return href = as_latin1(attrs['xlink:href']) image = load_image(os.path.join(self.loader.directory, href)).image if attrs.has_key('x'): x = attrs['x'] else: x = '0' if attrs.has_key('y'): y = attrs['y'] else: y = '0' x, y = self.user_point(x, y) width = self.user_length(attrs['width']) scalex = width / image.size[0] height = self.user_length(attrs['height']) scaley = -height / image.size[1] style = attrs.get('style', '') if style: self.parse_style(style) self.set_loader_style() t = self.trafo(Trafo(scalex, 0, 0, scaley, x, y + height)) self._print('image', t) self.loader.image(image, t)
def load_image(self): dir = config.preferences.pattern_dir filename = self.main_window.GetOpenImageFilename(no_eps = 1, initialdir = dir) if not filename: return try: tile = load_image(filename) except IOError, value: if type(value) == type(()): value = value[1] basename = os.path.split(filename)[1] self.main_window.application.MessageBox(title = _("Load Image"), message=_("Cannot load %(filename)s:\n" "%(message)s") \ % {'filename':`basename`, 'message':value}, icon = 'warning')
def __init__(self, master, main_window, **kw): apply(PatternFrame.__init__, (self, master), kw) self.main_window = main_window button = UpdatedButton(self, text = _("Load Image..."), command = self.load_image) button.pack(side = TOP, fill = X) button = UpdatedButton(self, text = _("Pick Image..."), command = self.pick_image) button.pack(side = TOP, fill = X) file = os.path.join(config.std_res_dir, config.preferences.pattern) try: file = open(file) tile = load_image(file) except: warn_tb(INTERNAL, "Cannot load %s", file) return self.SetPattern(ImageTilePattern(tile))