def itemClicked(self, event): if (self.grillaComics.selection): item = self.grillaComics.item(self.grillaComics.selection()) cnf = Config(self.session) cv = ComicVineSearcher(cnf.getClave('issues'), session=self.session) cv.setEntidad('issues') print(item['values'][2]) cv.addFilter("id:"+str(item['values'][2])) cv.vineSearch() webImage = cv.listaBusquedaVine[0].thumb_url nombreImagen = webImage[webImage.rindex('/') + 1:] print(webImage) print(nombreImagen) path = self.setup.directorioBase + os.sep + "images" + os.sep + "searchCache" + os.sep if not (os.path.isfile(path + nombreImagen)): print('no existe') print(nombreImagen) # path = setup.directorioBase + os.sep + "images"+ os.sep+"searchCache" + os.sep jpg = urllib.request.urlopen(webImage) jpgImage = jpg.read() fImage = open(path + nombreImagen, 'wb') fImage.write(jpgImage) fImage.close() fImage = open(path + nombreImagen, 'rb') im = Image.open(fImage) # print(item['values'][8],item['values'][4]) self.comicBookVine = ComicBook() self.comicBookVine.path = 'Path' self.comicBookVine.titulo = str(item['values'][1]) self.comicBookVine.volumeId = self.entrySerie.get() self.comicBookVine.numero = item['values'][0] #self.comicBookVine.fechaTapa = item['values'][0] #self.comicBookVine.resumen = item['values'][2] self.comicBookVine.idExterno = item['values'][2] self.panelVineComic = self.__createPanelComic__(self, self.comicBookVine, im.resize(self.size), 'Vine Info') self.panelVineComic.grid(column=2, row=0, sticky=(N, S, E, W))
class PublisherVineGui(Frame): def __init__(self, parent, session=None, cnf={}, **kw): Frame.__init__(self, parent, cnf, **kw) config = Config() self.iconos = Iconos() if session is None: self.session = Entidades.Init.Session() else: self.session = session self.comicVineSearcher = ComicVineSearcher( config.getClave('publishers'), session=self.session) self.comicVineSearcher.setEntidad("publishers") self.labelId = Label(self, text="Nombre Editorial: ") self.labelId.grid(row=0, column=0, sticky=W, padx=5, pady=5) self.entradaNombreEditorial = Entry(self, width=50) self.varID = StringVar() self.entradaNombreEditorial.grid(row=0, column=1, sticky=W + E, padx=5, pady=5, columnspan=2) self.botonLookupPublisher = Button(self, command=self.buscar) self.botonLookupPublisher.grid(row=0, column=3) self.pilImagenLookup = self.iconos.pilImagenLookup self.imageLookup = PIL.ImageTk.PhotoImage(self.pilImagenLookup) self.botonLookupPublisher.config(image=self.imageLookup) self.labelImagen = Label(self, text="logo edtorial") self.coverSize = (150, 150) self.labelImagen.grid(column=4, row=1) ##config grilla series self.panelGrilla = Frame(self) self.panelGrilla.grid(column=0, row=1, columnspan=3, sticky=(N, S, E, W), padx=5) self.grillaPublishers = ttk.Treeview(self.panelGrilla, columns=('Id', 'Nombre'), displaycolumns=('Id', 'Nombre')) self.grillaPublishers.grid(column=0, row=0, columnspan=3, sticky=(N, S, E, W)) self.grillaPublishers.bind( '<<TreeviewSelect>>', self.itemClicked) # the item clicked can be found via tree.focus() scrollGrid = ttk.Scrollbar(self.panelGrilla, orient=VERTICAL, command=self.grillaPublishers.yview) scrollGrid.grid(column=3, row=0, sticky=(N, S)) self.grillaPublishers.configure(yscrollcommand=scrollGrid.set) self.grillaPublishers.heading('Id', text='Id') self.grillaPublishers.heading('Nombre', text='Nombre') self.grillaPublishers.config(show='headings') # tree, headings self.botonLookupPublisher = Button(self, text="agregar", command=self.agregarEditorial) self.botonLookupPublisher.grid(row=2, column=3, pady=3, sticky=(E)) def agregarEditorial(self): self.session.add(self.publisher) self.session.commit() def buscar(self): if (self.entradaNombreEditorial.get() != ''): self.comicVineSearcher.clearFilter() self.comicVineSearcher.addFilter("name:" + self.entradaNombreEditorial.get()) self.comicVineSearcher.vineSearch(0) self.cargarResultado(self.comicVineSearcher.listaBusquedaVine) def itemClicked(self, event): if (self.grillaPublishers.selection()): seleccion = self.grillaPublishers.selection() self.publisher = self.comicVineSearcher.listaBusquedaVine[ self.grillaPublishers.index(seleccion[0])] self.grillaPublishers.index(seleccion[0]) imagen = self.publisher.getImageCover() self.cover = ImageTk.PhotoImage(imagen.resize(self.coverSize)) self.labelImagen['image'] = self.cover def cargarResultado(self, listaPublishers): for item in self.grillaPublishers.get_children(): self.grillaPublishers.delete(item) for idx, publisher in enumerate(listaPublishers): self.grillaPublishers.insert('', 'end', str(idx), text='', values=(publisher.id_publisher, publisher.name))
class Publisher_vine_search_gtk(): # todo implementar icono de progreso def __init__(self, session=None): config = Config() if session is not None: self.session = session else: self.session = Entidades.Init.Session() self.comicVineSearcher = ComicVineSearcher( config.getClave('publishers'), session=self.session) self.comicVineSearcher.setEntidad("publishers") self.handlers = { 'click_boton_buscar_mas': self.click_boton_buscar_mas, 'selection': self.selection, 'click_boton_aceptar': self.click_boton_aceptar, 'click_boton_buscar': self.click_boton_buscar } self.builder = Gtk.Builder() self.builder.add_from_file( "../Glade_files/Publisher_vine_search_gtk.glade") self.builder.connect_signals(self.handlers) self.window = self.builder.get_object("Publisher_vine_search_Gtk") self.window.set_icon_from_file('../iconos/BabelComic.png') self.entry_nombre = self.builder.get_object('entry_nombre') self.spinner = self.builder.get_object('spinner') self.publisher_logo_image = self.builder.get_object( 'publisher_logo_image') self.listmodel_publishers = Gtk.ListStore(str, str) self.gtk_tree_view_publisher = self.builder.get_object( 'gtk_tree_view_publisher') def selection(self, selection): (model, iter) = selection.get_selected() if iter: self.publisher = self.comicVineSearcher.listaBusquedaVine[int( model[iter][0])] self.spinner.start() self.publisher.getImageCover() self.spinner.stop() self.publisher.localLogoImagePath = self.publisher.getImageCoverPath( ) if self.publisher.localLogoImagePath[-3].lower() == 'gif': gif = GdkPixbuf.PixbufAnimation.new_from_file( self.publisher.localLogoImagePath).get_static_image() self.publisher_logo_image.set_from_pixbuf( gif.scale_simple(250, 250, 3)) else: print(self.publisher.getImageCoverPath()) pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale( filename=self.publisher.getImageCoverPath(), width=250, height=250, preserve_aspect_ratio=True) self.publisher_logo_image.set_from_pixbuf(pixbuf) def _start(self): print("iniciando") def _buscar(self): if self.entry_nombre.get_text() != '': self.comicVineSearcher.clearFilter() self.comicVineSearcher.addFilter("name:" + self.entry_nombre.get_text()) self.comicVineSearcher.vineSearch(0) self.cargarResultado(self.comicVineSearcher.listaBusquedaVine) self.spinner.stop() def start(self): GLib.idle_add(self.spinner.start) def click_boton_buscar(self, widget): self.spinner.start() t = threading.Thread(target=self._buscar) t.start() #GLib.idle_add(self._buscar) def agregarEditorial(self): # self.session.add(self.publisher) # self.session.commit() self._stop() def search_changed(self, widget): print('buscando') # if (self.entradaNombreEditorial.get()!=''): # self.comicVineSearcher.clearFilter() # self.comicVineSearcher.addFilter("name:"+self.entradaNombreEditorial.get()) # self.comicVineSearcher.vineSearch(0) # self.cargarResultado(self.comicVineSearcher.listaBusquedaVine) def click_boton_buscar_mas(self, widget): self._start() # # if (self.entradaNombreEditorial.get()!=''): # self.comicVineSearcher.clearFilter() # self.comicVineSearcher.addFilter("name:"+self.entradaNombreEditorial.get()) # self.comicVineSearcher.vineSearch(0) # self.cargarResultado(self.comicVineSearcher.listaBusquedaVine) def click_boton_aceptar(self, widget): if self.publisher: self.session.add(self.publisher) self.session.commit() # self.window.close() def cargarResultado(self, listaPublishers): self.listmodel_publishers.clear() for index, publisher in enumerate(listaPublishers): self.listmodel_publishers.append([str(index), publisher.name]) self.gtk_tree_view_publisher.set_model(self.listmodel_publishers)
class VolumeVineGui(Frame): def __init__(self, parent, session=None, cnf={}, **kw): Frame.__init__(self, parent, cnf, **kw) config = Config() iconos = Iconos.Iconos() self.pilImagenLookup = iconos.pilImagenLookup self.imageLookup = PIL.ImageTk.PhotoImage(self.pilImagenLookup) self.offset = 0 self.frameParametros = Frame(self) self.frameParametros.grid(row=0, column=0, sticky=(W, E, N, S)) self.listaFiltrada = [] if session is None: self.session = Entidades.Init.Session() else: self.session = session self.comicVineSearcher = ComicVineSearcher(config.getClave('volumes'), session=self.session) self.comicVineSearcher.setEntidad("volumes") self.labelId = Label(self.frameParametros, text="Nombre Volumen: ") self.labelId.grid(row=0, column=0, sticky=(W, E), padx=5, pady=5) self.entradaNombreVolume = Entry(self.frameParametros, width=70) self.entradaNombreVolume.grid(column=1, row=0) Label(self.frameParametros, text="Editorial: ").grid(row=1, column=0, sticky=W, padx=5, pady=5) self.varID = StringVar() self.entradaNombreEditorial = Entry(self.frameParametros, width=30) self.entradaNombreEditorial.grid(row=1, column=1, sticky=W + E, padx=5, pady=5) self.botonBuscar = Button(self.frameParametros, text='buscar', command=self.buscar) self.botonBuscar.grid(row=0, column=3) self.botonBuscar = Button(self.frameParametros, text='buscar mas', command=self.buscarMas) self.botonBuscar.grid(row=0, column=4) self.botonLookupPublisher = Button(self.frameParametros, image=self.imageLookup, command=self.openLookupPublisher) self.botonLookupPublisher.grid(row=1, column=3) self.labelImagen = Label(self, text="cover volumen") self.coverSize = (150, 250) self.labelImagen.grid(column=4, row=1) self.volume = None self.publisher = None # # ##config grilla series self.panelGrilla = Frame(self) self.panelGrilla.grid(column=0, row=1, sticky=(N, S, E, W), padx=5) self.grillaVolumes = ttk.Treeview( self.panelGrilla, columns=('name', 'count_of_issues', 'description', 'Id', 'image', 'publisher', 'start_year'), displaycolumns=('Id', 'name', 'count_of_issues', 'publisher', 'start_year')) self.grillaVolumes.grid(column=0, row=0, columnspan=3, sticky=(N, S, E, W)) self.grillaVolumes.bind( '<<TreeviewSelect>>', self.itemClicked) # the item clicked can be found via tree.focus() scrollGrid = ttk.Scrollbar(self.panelGrilla, orient=VERTICAL, command=self.grillaVolumes.yview) scrollGrid.grid(column=3, row=0, sticky=(N, S, E, W), columnspan=2) self.grillaVolumes.configure(yscrollcommand=scrollGrid.set) self.grillaVolumes.heading('Id', text='Id', command=lambda: self.treeview_sort_column( self.grillaVolumes, 'Id', False)) self.grillaVolumes.heading('name', text='Nombre', command=lambda: self.treeview_sort_column( self.grillaVolumes, 'name', False)) self.grillaVolumes.heading( 'count_of_issues', text='Numeros', command=lambda: self.treeview_sort_column( self.grillaVolumes, 'count_of_issues', False)) self.grillaVolumes.heading('publisher', text='Editorial', command=lambda: self.treeview_sort_column( self.grillaVolumes, 'publisher', False)) self.grillaVolumes.heading( 'start_year', text='Año', command=lambda: self.treeview_sort_column(self.grillaVolumes, 'start_year', False)) self.grillaVolumes.config(show='headings') # tree, headings self.botonLookupPublisher = Button(self, text="agregar", command=self.agregarVolumen) self.botonLookupPublisher.grid(row=0, column=4, pady=3, sticky=(E, W)) self.statusBar = Label(self, text='status', relief=GROOVE, anchor=E) self.statusBar.grid(column=0, row=4, sticky=(E, W), columnspan=5) def int(self, t): if t[0].isdigit(): return (int(t[0])) return 0 def treeview_sort_column(self, tv, col, reverse): l = [(tv.set(k, col), k) for k in tv.get_children('')] if col in ['count_of_issues', 'start_year']: l.sort(reverse=reverse, key=self.int) else: l.sort(reverse=reverse) # rearrange items in sorted positions for index, (val, k) in enumerate(l): tv.move(k, '', index) # reverse sort next time tv.heading( col, command=lambda: self.treeview_sort_column(tv, col, not reverse)) def agregarVolumen(self): cnf = Config(self.session) cv = ComicVineSearcher(cnf.getClave('volume'), self.session) cv.entidad = 'volume' volumenAndIssues = cv.getVineEntity(self.volume.id) self.session.query(ComicInVolumes).filter( ComicInVolumes.volumeId == self.volume.id).delete() for index, numeroComic in enumerate(volumenAndIssues[1], start=0): numeroComic.offset = int(index / 100) self.session.add(numeroComic) self.session.add(volumenAndIssues[0]) self.session.commit() def openLookupPublisher(self): window = Toplevel() self.publisher = Publisher() lk = PublisherLookupGui(window, self.publisher) lk.grid(sticky=(E, W, S, N)) window.columnconfigure(0, weight=1) window.rowconfigure(0, weight=1) window.geometry("+0+0") window.wm_title(string="Editoriales") self.wait_window(window) self.publisher = lk.getPublisher() self.entradaNombreEditorial.insert(0, self.publisher.name) def buscarMas(self): self.comicVineSearcher.vineSearchMore() self.cargarResultado(self.comicVineSearcher.listaBusquedaVine) def __buscar__(self): print("buscando....") if (self.entradaNombreVolume.get() != ''): print("BUSCANDO....") self.cargarResultado(self.comicVineSearcher.listaBusquedaVine) def buscar(self): self.offset = 0 self.comicVineSearcher.clearFilter() self.comicVineSearcher.addFilter("name:" + self.entradaNombreVolume.get()) self.comicVineSearcher.vineSearch(self.offset) self.cargarResultado(self.comicVineSearcher.listaBusquedaVine) # self.cargarResultado('') def itemClicked(self, event): if (self.grillaVolumes.selection()): seleccion = self.grillaVolumes.selection() id = self.grillaVolumes.item(seleccion, 'values')[3] for volume in self.comicVineSearcher.listaBusquedaVine: if volume.id == id: self.volume = volume break self.grillaVolumes.index(seleccion[0]) imagen = self.volume.getImageCover() self.cover = ImageTk.PhotoImage( imagen.resize(self.coverSize, Image.BICUBIC)) self.labelImagen['image'] = self.cover def cargarResultado(self, listavolumes): for item in self.grillaVolumes.get_children(): self.grillaVolumes.delete(item) self.listaFiltrada.clear() for volume in listavolumes: if self.publisher is not None: if self.publisher.id_publisher == volume.publisherId: self.listaFiltrada.append(volume) else: self.listaFiltrada.append(volume) for idx, volume in enumerate(self.listaFiltrada): print(volume) self.grillaVolumes.insert( '', 'end', str(idx), text='', values=(volume.nombre, volume.cantidad_numeros, volume.descripcion, volume.id, volume.image_url, volume.publisher_name, str(idx))) self.statusBar.config( text= "Cantidad Resultados: %d - Cantidad Resultados sin filtro: %d- Cantidad Total de Resultados en ComicVine: %d" % (len(self.listaFiltrada), len(self.comicVineSearcher.listaBusquedaVine), self.comicVineSearcher.cantidadResultados))