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 Volumen_vine_search_Gtk(): def __init__(self, session=None): config = Config() 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.publishers_manager = Publishers() self.handlers = { 'click_lookup_editorial': self.click_lookup_editorial, 'click_buscar_serie': self.click_buscar_serie, 'click_buscar_mas_serie': self.click_buscar_mas_serie, 'click_aceptar': self.click_aceptar, 'entry_id_editorial_change': self.entry_id_editorial_change, 'seleccion': self.seleccion, 'click_detener': self.click_detener, 'intro_detection': self.intro_detection } self.builder = Gtk.Builder() self.builder.add_from_file( "../Glade_files/Volumen_vine_search_gtk.glade") self.builder.connect_signals(self.handlers) self.window = self.builder.get_object("Volumen_vine_search_Gtk") self.window.set_icon_from_file('../iconos/BabelComic.png') self.entry_serie_nombre = self.builder.get_object("entry_serie_nombre") self.label_descripcion_editorial = self.builder.get_object( "label_descripcion_editorial") self.entry_id_editorial = self.builder.get_object("entry_id_editorial") self.gtk_tree_view_volumens = self.builder.get_object( "gtk_tree_view_volumens") self.listmodel_volumenes = self.builder.get_object( 'listmodel_volumenes') self.listmodel_volumenes.clear() self.label_status = self.builder.get_object("label_status") self.volume_logo_image = self.builder.get_object("volumen_logo_image") self.spinner = self.builder.get_object("spinner") self.volume = None self.publisher = None self.cargarResultado(self.listmodel_volumenes) # self.entry_id_editorial.set_text('2707') # self.entry_serie_nombre.set_text('iron man') def intro_detection(self, widget, event): if event.keyval == Gdk.KEY_Return: self.click_buscar_serie(None) def click_detener(self, widget): self.comicVineSearcher.detener = True for hilo in self.comicVineSearcher.lista_hilos_ejecucion.items(): print(hilo) hilo[1].join(1) self.comicVineSearcher.lock.acquire(True) self.comicVineSearcher.cantidad_hilos -= 1 self.comicVineSearcher.lock.release() def _copy_to_window(self): if self.publisher: self.entry_id_editorial.set_text(str(self.publisher.id_publisher)) self.label_descripcion_editorial.set_text(self.publisher.name) else: self.label_descripcion_editorial.set_text('') def entry_id_editorial_change(self, widget): self.publisher = None self.publisher = self.publishers_manager.get( self.entry_id_editorial.get_text()) self._copy_to_window() if self.publisher is not None or self.entry_id_editorial.get_text( ) == '': self.cargarResultado(self.comicVineSearcher.listaBusquedaVine) print("Publisher recueperado") print(self.publisher) def click_lookup_editorial(self, widget): lookup = Publisher_lookup_gtk(self.session, self.return_lookup_editorial) lookup.window.show() def return_lookup_editorial(self, id_publisher): if id_publisher is not None: self.publisher = None self.publisher = self.publishers_manager.get(id_publisher) self._copy_to_window() if self.publisher is not None or self.entry_id_editorial.get_text( ) == '': self.cargarResultado(self.comicVineSearcher.listaBusquedaVine) print("Publisher recueperado") def _buscarMas(self): self.comicVineSearcher.vineSearchMore() GLib.idle_add(self.cargarResultado, self.comicVineSearcher.listaBusquedaVine) # print(self.comicVineSearcher.listaBusquedaVine) def click_buscar_mas_serie(self, widget): self.spinner.start() for i in range(self.comicVineSearcher.cantidadPaginas - 4): print("buscando mas") self.hilo1 = threading.Thread(target=self._buscarMas) self.hilo1.start() time.sleep(1) def _buscar(self): self.offset = 0 self.comicVineSearcher.clearFilter() self.comicVineSearcher.setEntidad("volumes") lista_palabras = '+'.join( str(palabra) for palabra in self.entry_serie_nombre.get_text().split(' ')) self.comicVineSearcher.addFilter("name:" + lista_palabras) self.comicVineSearcher.vine_Search_all() GLib.idle_add(self.cargarResultado, self.comicVineSearcher.listaBusquedaVine) def click_buscar_serie(self, widget): self.spinner.start() self.listmodel_volumenes.clear() self.hilo1 = threading.Thread(target=self._buscar) self.hilo1.start() def cargar_mensaje_status(self, mensaje): self.label_status.set_text(mensaje) def hilo_cargar_volume(self, id_volume_externo): self.comicVineSearcher.entidad = 'volume' volumen = self.comicVineSearcher.getVineEntity(id_volume_externo) # recuperamos los isseues del volumen estan en una lista de comic_vine_searcher self.comicVineSearcher.cargar_comicbook_info(volumen) while self.comicVineSearcher.porcentaje_procesado != 100 and not self.comicVineSearcher.detener: time.sleep(2) GLib.idle_add( self.cargar_mensaje_status, "Porcentaje completado {}%".format( self.comicVineSearcher.porcentaje_procesado)) if self.comicVineSearcher.detener: GLib.idle_add(self.cargar_mensaje_status, "Proceso de descarga detenido") print("Proceso de descarga detenido") return volumen_in_db = self.session.query(Volume).filter( Volume.id_volume == volumen.id_volume).first() if volumen_in_db is not None: # actualizo la cantidad de ejemplares nada mas print(volumen) volumen_in_db.actualizar_con(volumen) volumen = volumen_in_db self.session.add(volumen) self.session.commit() #print(volumen) for comicbook_info in self.comicVineSearcher.lista_comicbooks_info: cbi_db = self.session.query( Entidades.Agrupado_Entidades.Comicbook_Info).get( comicbook_info.id_comicbook_info) if cbi_db is not None and not cbi_db.actualizado_externamente: self.session.query(Comicbook_Info).filter( Comicbook_Info.id_comicbook_info == comicbook_info.id_comicbook_info).delete() self.session.commit() self.session.add(comicbook_info) elif cbi_db is not None and cbi_db.actualizado_externamente: print("Actualizando info de comicbook_info DATOS A ACTUALIZAR") cbi_db.numero = comicbook_info.numero cbi_db.fecha_tapa = comicbook_info.fecha_tapa cbi_db.orden = comicbook_info.orden cbi_db.url = comicbook_info.url cbi_db.api_detail_url = comicbook_info.api_detail_url for url_cover in comicbook_info.thumbs_url: copiar_cover = True for url_cover_cbi in cbi_db.thumbs_url: if url_cover.thumb_url == url_cover_cbi.thumb_url: copiar_cover = False break if copiar_cover: cbi_db.thumbs_url.append(url_cover) # cbi_db.thumbs_url = comicbook_info.thumbs_url print(cbi_db) else: print("agregando comic por primera vez") print(cbi_db) self.session.add(comicbook_info) self.session.commit() lista_arcos = [] for arco in self.comicVineSearcher.lista_arcos: arco_db = self.session.query(Arco_Argumental).filter( Arco_Argumental.id_arco_argumental == arco.id_arco_argumental).first() if arco_db is not None: lista_arcos.append(arco_db) arco_db.lista_ids_comicbook_info_para_procesar = arco.lista_ids_comicbook_info_para_procesar else: self.session.add(arco) lista_arcos.append(arco) self.session.commit() # reemplazo todos los arcos por los que estan la base o los que acabo de guardar self.comicVineSearcher.lista_arcos = lista_arcos # construimos la relacion para cada arco con la lista de comics. for arco in self.comicVineSearcher.lista_arcos: try: print("Lista de arcos de cv {}".format( arco.lista_ids_comicbook_info_para_procesar)) except Exception: print("Arco con error {}".format(arco)) raise for comicbook_info in self.comicVineSearcher.lista_comicbooks_info: for pos, arco_comicbook_info in enumerate( arco.lista_ids_comicbook_info_para_procesar): # print("Comic Info {} tipo {} comic info arco {} tipo {}".format(comicbook_info.id_comicbook_info, # type(comicbook_info.id_comicbook_info), # arco_comicbook_info, # type(arco_comicbook_info))) if int(comicbook_info.id_comicbook_info ) == arco_comicbook_info: comicbook_info_db = self.session.query( Comicbook_Info).get( comicbook_info.id_comicbook_info) rel = self.session.query( Arcos_Argumentales_Comics_Reference).get( (comicbook_info.id_comicbook_info, arco.id_arco_argumental)) if rel is None: print("El comic book_info {} pertenece al arco {}". format(comicbook_info.id_comicbook_info, arco.id_arco_argumental)) arco_argumental_comicsbook_reference = Arcos_Argumentales_Comics_Reference( ) arco_argumental_comicsbook_reference.orden = pos arco_argumental_comicsbook_reference.ids_arco_argumental = arco print("COMIC A RELACIONAR") print(type(comicbook_info)) print(type(comicbook_info_db)) if comicbook_info_db is not None: arco_argumental_comicsbook_reference.ids_comicbooks_info = comicbook_info_db else: arco_argumental_comicsbook_reference.ids_comicbooks_info = comicbook_info self.session.add( arco_argumental_comicsbook_reference) self.session.commit() # Descargamos los covers de los issues del volumen for comicbook_info in self.comicVineSearcher.lista_comicbooks_info: print('Bajando covers {}'.format(comicbook_info.id_comicbook_info)) # comicbook_info.get_first_cover_complete_path() comicbooks_info_manager = Comicbooks_Info(session=self.session) comicbooks_info_manager.get(comicbook_info.id_comicbook_info) print(comicbooks_info_manager.get) threading.Thread(target=comicbooks_info_manager. get_first_cover_complete_path).start() def click_aceptar(self, widget): self.comicVineSearcher.detener = False threading.Thread(target=self.hilo_cargar_volume, args=[self.volume.id_volume]).start() # 86343 - 5868-106705-18216- # 32561 - Brightest Day # 32562 - The flash vol3 # 18127 - Justice League of America # 4363 - green lantern vol 3 # 18058 - detective comics106705 # 18216 - green lantern vol 4 # 6498 - birdth of prey # 773 - superman Vol2 # threading.Thread(target=self.hilo_cargar_volume, args=['3816']).start() # threading.Thread(target=self.hilo_cargar_volume, args=['18216']).start() # threading.Thread(target=self.hilo_cargar_volume, args=['25372']).start() # threading.Thread(target=self.hilo_cargar_volume, args=['25543']).start() # threading.Thread(target=self.hilo_cargar_volume, args=['18058']).start() # threading.Thread(target=self.hilo_cargar_volume, args=['7300']).start() #threading.Thread(target=self.hilo_cargar_volume, args=['4740']).start() # threading.Thread(target=self.hilo_cargar_volume, args=['106705']).start() #4740 # 25543 # # self.hilo_cargar_volume('6498') # self.hilo_cargar_volume('18216') def _seleccion(self): self.volume.localLogoImagePath = self.volume.getImageCover() pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale( filename=self.volume.getImagePath(), width=250, height=250, preserve_aspect_ratio=True) self.spinner.stop() GLib.idle_add(self.volume_logo_image.set_from_pixbuf, pixbuf) # self.volume_logo_image.set_from_pixbuf(pixbuf) def seleccion(self, selection): self.spinner.start() GLib.idle_add(self.cargar_mensaje_status, "") (model, iter) = selection.get_selected() if iter: self.volume = self.listaFiltrada[int(model[iter][0])] self.hilo1 = threading.Thread(target=self._seleccion) self.hilo1.start() def cargarResultado(self, listavolumes): self.listmodel_volumenes.clear() self.listaFiltrada.clear() for volume in listavolumes: if self.publisher is not None: print("Editorial de fitro: {} Editorial Comics: {}".format( self.publisher.id_publisher, volume.id_publisher)) if self.publisher.id_publisher == volume.id_publisher: self.listaFiltrada.append(volume) else: self.listaFiltrada.append(volume) print("Longitud: {}".format(len(self.listaFiltrada))) if len(self.listaFiltrada) > 1400: self.label_status.set_text( "La cantidad de registros es mayor a 1400. Trate de filtrar la consulta." ) return for idx, volume in enumerate(self.listaFiltrada): nombre = '' cantidad_numeros = 0 anio = 0 publisher_name = "" if volume.nombre is not None: nombre = volume.nombre if volume.anio_inicio is not None: if str.isdigit(volume.anio_inicio): anio = int(volume.anio_inicio) if str.isdigit(volume.cantidad_numeros): cantidad_numeros = int(volume.cantidad_numeros) if volume.publisher_name is not None: publisher_name = volume.publisher_name print("cargand el volumen {}".format(str(idx) + " " + nombre)) self.listmodel_volumenes.append( [str(idx), nombre, cantidad_numeros, publisher_name, anio]) self.label_status.set_text( "Cantidad Resultados: {} - Cantidad Resultados sin filtro: {}- Cantidad Total de Res" "ultados en ComicVine: {}".format( len(self.listaFiltrada), len(self.comicVineSearcher.listaBusquedaVine), self.comicVineSearcher.cantidadResultados)) self.spinner.stop()
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))