def on_open_image2(self, widget, path, img_pop): # paths = self.get_selected_items() model = self.get_model() # if paths: # path = paths[0] iter = model.get_iter(path) pixbuf_format, width, height = Pixbuf.get_file_info(model[iter][0]) if height > 1080 or width > 1900: pixbuf = Pixbuf.new_from_file_at_scale(model[iter][0], 1900, 1080, True) else: pixbuf = Pixbuf.new_from_file(model[iter][0]) # img = Gtk.Image.new_from_pixbuf(pixbuf) # img.show_all() # pb = img.get_pixbuf() # if pb.get_height() > 1080 # scroll = Gtk.ScrolledWindow() # scroll.set_pre # scroll.add(img) # pop = Gtk.Window.new(1) # pop.add(img) # pop.set_position(3) # pop.show_all() # pop.connect('button-release-event', self.on_pop_click) # self.img_menu_item.set_image(img) img_pop.set_pixbuf(pixbuf) img_pop.popup()
def new_from_file(cls, path): try: pixbuf = Pixbuf.new_from_file(path) except GLib.GError: return None format, width, height = Pixbuf.get_file_info(path) if 'image/gif' in format.get_mime_types(): # In case of GIF images, buffer is image raw data with open(path, 'rb') as fp: buffer = fp.read() else: buffer = pixbuf return cls(path, buffer, width, height)
def thread_fun(self, caller_slot, fns_lock, str_path, imgs_max_num, img_wh, caller_img_paths, caller_img_pixbufs): list_fns = [] for parent, dirnames, filenames in os.walk(str_path): for filename in filenames: list_fns.append(filename) str_iexs = [".jpg", ".png", ".jpeg", ".JPG", ".PNG", ".JPEG"] list_img_fns = [] for fn in list_fns: #{ for str_ex in str_iexs: idx = fn.rfind(str_ex) if (idx > 0 and len(str_ex) + idx == len(fn)): str_img_fn = str_path + "/" + fn img_fat, w, h = Pixbuf.get_file_info(str_img_fn) if (img_fat != None and w >= img_wh and h >= img_wh): list_img_fns.append(fn) break if (len(list_img_fns) >= imgs_max_num): break #} n = imgs_max_num idx = 0 if (n > len(list_img_fns) - idx): n = len(list_img_fns) - idx for i in range(n): fn = list_img_fns[idx + i] fns_lock.acquire() img_fn = str_path + "/" + fn pixbuf = Pixbuf.new_from_file_at_size(img_fn, img_wh, img_wh) caller_img_pixbufs.append(pixbuf) fns_lock.release() for fn in list_img_fns: fns_lock.acquire() img_fn = str_path + "/" + fn caller_img_paths.append(img_fn) fns_lock.release() GLib.idle_add(caller_slot, "img_fns ok")