def __init__(self, session=None, campo_retorno=None): if session is None: self.session = Entidades.Init.Session() else: self.session = session self.handlers = { 'search_volumen': self.search_volumen, 'search_editorial': self.search_editorial, 'click_lookup_editorial': self.click_lookup_editorial, 'seleccion_volumen': self.seleccion_volumen, 'click_boton_aceptar': self.click_boton_aceptar, 'gtk_tree_view_volumen_double_click': self.gtk_tree_view_volumen_double_click, 'combobox_change': self.combobox_change, 'foco_busquedas': self.foco_busquedas } self.builder = Gtk.Builder() self.builder.add_from_file("../Glade_files/Volumen_lookup_gtk.glade") self.builder.connect_signals(self.handlers) self.window = self.builder.get_object("Volumen_lookup_gtk") self.window.set_icon_from_file('../iconos/BabelComic.png') self.search_entry_editorial = self.builder.get_object( "search_entry_editorial") self.imagen_cover_volumen = self.builder.get_object( "imagen_cover_volumen") self.gtk_tree_view_volumen = self.builder.get_object( 'gtk_tree_view_volumen') self.listmodel_volumens = self.builder.get_object("listmodel_volumens") self.label_nombre_editorial = self.builder.get_object( "label_nombre_editorial") self.volumens = self.session.query(Volume).all() self.search_entry_volumen = self.builder.get_object( 'search_entry_volumen') self.search_entry_editorial = self.builder.get_object( 'search_entry_editorial') self.volumens_manager = Volumens(session=self.session) self.volumens_manager.set_order(Volume.nombre) self.combobox_orden = self.builder.get_object("combobox_orden") self.liststore_combobox = self.builder.get_object("liststore_combobox") self._load_data() if campo_retorno is None: print("error campo retorno requerido") self.campo_retorno = campo_retorno self.publisher = None self.volume = None
def __init__(self, session=None): if session is not None: self.session = session else: self.session = Entidades.Init.Session() self.handlers = { 'getFirst': self.getFirst, 'getLast': self.getLast, 'getPrev': self.getPrev, 'getNext': self.getNext, 'getLast': self.getLast, 'boton_cargar_desde_web_click': self.boton_cargar_desde_web_click, 'click_lookup_volume': self.click_lookup_volume, 'change_id_volume': self.change_id_volume, 'click_nuevo': self.click_nuevo, 'combobox_change': self.combobox_change, 'selecion_pagina': self.selecion_pagina, 'click_guardar': self.click_guardar, 'evento': self.evento, 'click_eliminar': self.click_eliminar, 'click_derecho': self.click_derecho, 'click_lookup_editorial': self.click_lookup_editorial, 'pop_up_menu': self.pop_up_menu, 'abrir_covers': self.abrir_covers } self.builder = Gtk.Builder() self.builder.add_from_file("../Glade_files/Volumen.glade") self.builder.connect_signals(self.handlers) self.window = self.builder.get_object("Volume_gtk") self.window.set_icon_from_file('../iconos/BabelComic.png') self.stack = self.builder.get_object("stack") self.lista_items = [ self.builder.get_object("item_0"), self.builder.get_object("item_1") ] self.index = 0 self.list_entry_id = [ self.builder.get_object("entry_id"), self.builder.get_object("entry_id1") ] self.list_entry_nombre = [ self.builder.get_object("entry_nombre"), self.builder.get_object("entry_nombre1") ] self.list_label_url = [ self.builder.get_object("label_url"), self.builder.get_object("label_url1") ] print(type(self.list_entry_id[self.index])) self.list_label_api_url = [ self.builder.get_object("label_api_url"), self.builder.get_object("label_api_url1") ] self.list_label_cover_url = [ self.builder.get_object("label_cover_url"), self.builder.get_object("label_cover_url1") ] self.list_entry_id_editorial = [ self.builder.get_object("entry_id_editorial"), self.builder.get_object("entry_id_editorial1") ] self.list_volumen_logo_image = [ self.builder.get_object("volumen_logo_image"), self.builder.get_object("volumen_logo_image1") ] # self.volumen_logo_image = self.builder.get_object("volumen_logo_image") self.list_label_nombre_editorial = [ self.builder.get_object("label_nombre_editorial"), self.builder.get_object("label_nombre_editorial1") ] self.list_entry_anio_inicio = [ self.builder.get_object("entry_anio_inicio"), self.builder.get_object("entry_anio_inicio1") ] self.list_entry_cantidad_numeros = [ self.builder.get_object("entry_cantidad_numeros"), self.builder.get_object("entry_cantidad_numeros1") ] self.list_liststore_combobox = [ self.builder.get_object("liststore_combobox"), self.builder.get_object("liststore_combobox1") ] self.list_resumen_volumen = [ self.builder.get_object("resumen_volumen"), self.builder.get_object("resumen_volumen1") ] self.list_liststore_comics_in_volume = [ self.builder.get_object("liststore_comics_in_volume"), self.builder.get_object("liststore_comics_in_volume1") ] self.list_treeview_comics_in_volumen = [ self.builder.get_object("treeview_comics_in_volumen"), self.builder.get_object("treeview_comics_in_volumen1") ] self.list_progressbar_procentaje_completado = [ self.builder.get_object("progressbar_procentaje_completado"), self.builder.get_object("progressbar_procentaje_completado1") ] self.list_label_cantidad_comics_asociados = [ self.builder.get_object("label_cantidad_comics_asociados"), self.builder.get_object("label_cantidad_comics_asociados1") ] self.volumens_manager = Volumens(session=self.session) self.volume = None # print(self.volume) # if self.volume is not None: # self.loadVolume(self.volume) self.getFirst(None) # self.combobox_orden = self.builder.get_object("combobox_orden") self.offset = 0 self.cantidadRegistros = self.volumens_manager.get_count() self.pagina_actual = 0 self.menu = self.builder.get_object("menu")
class VolumeGuiGtk(): # todo implementar los botones de limpiar, guardar y borrar # todo clase que administre el comportamiento completo de alta, baja mdoficacion navegacion y borrado def __init__(self, session=None): if session is not None: self.session = session else: self.session = Entidades.Init.Session() self.handlers = { 'getFirst': self.getFirst, 'getLast': self.getLast, 'getPrev': self.getPrev, 'getNext': self.getNext, 'getLast': self.getLast, 'boton_cargar_desde_web_click': self.boton_cargar_desde_web_click, 'click_lookup_volume': self.click_lookup_volume, 'change_id_volume': self.change_id_volume, 'click_nuevo': self.click_nuevo, 'combobox_change': self.combobox_change, 'selecion_pagina': self.selecion_pagina, 'click_guardar': self.click_guardar, 'evento': self.evento, 'click_eliminar': self.click_eliminar, 'click_derecho': self.click_derecho, 'click_lookup_editorial': self.click_lookup_editorial, 'pop_up_menu': self.pop_up_menu, 'abrir_covers': self.abrir_covers } self.builder = Gtk.Builder() self.builder.add_from_file("../Glade_files/Volumen.glade") self.builder.connect_signals(self.handlers) self.window = self.builder.get_object("Volume_gtk") self.window.set_icon_from_file('../iconos/BabelComic.png') self.stack = self.builder.get_object("stack") self.lista_items = [ self.builder.get_object("item_0"), self.builder.get_object("item_1") ] self.index = 0 self.list_entry_id = [ self.builder.get_object("entry_id"), self.builder.get_object("entry_id1") ] self.list_entry_nombre = [ self.builder.get_object("entry_nombre"), self.builder.get_object("entry_nombre1") ] self.list_label_url = [ self.builder.get_object("label_url"), self.builder.get_object("label_url1") ] print(type(self.list_entry_id[self.index])) self.list_label_api_url = [ self.builder.get_object("label_api_url"), self.builder.get_object("label_api_url1") ] self.list_label_cover_url = [ self.builder.get_object("label_cover_url"), self.builder.get_object("label_cover_url1") ] self.list_entry_id_editorial = [ self.builder.get_object("entry_id_editorial"), self.builder.get_object("entry_id_editorial1") ] self.list_volumen_logo_image = [ self.builder.get_object("volumen_logo_image"), self.builder.get_object("volumen_logo_image1") ] # self.volumen_logo_image = self.builder.get_object("volumen_logo_image") self.list_label_nombre_editorial = [ self.builder.get_object("label_nombre_editorial"), self.builder.get_object("label_nombre_editorial1") ] self.list_entry_anio_inicio = [ self.builder.get_object("entry_anio_inicio"), self.builder.get_object("entry_anio_inicio1") ] self.list_entry_cantidad_numeros = [ self.builder.get_object("entry_cantidad_numeros"), self.builder.get_object("entry_cantidad_numeros1") ] self.list_liststore_combobox = [ self.builder.get_object("liststore_combobox"), self.builder.get_object("liststore_combobox1") ] self.list_resumen_volumen = [ self.builder.get_object("resumen_volumen"), self.builder.get_object("resumen_volumen1") ] self.list_liststore_comics_in_volume = [ self.builder.get_object("liststore_comics_in_volume"), self.builder.get_object("liststore_comics_in_volume1") ] self.list_treeview_comics_in_volumen = [ self.builder.get_object("treeview_comics_in_volumen"), self.builder.get_object("treeview_comics_in_volumen1") ] self.list_progressbar_procentaje_completado = [ self.builder.get_object("progressbar_procentaje_completado"), self.builder.get_object("progressbar_procentaje_completado1") ] self.list_label_cantidad_comics_asociados = [ self.builder.get_object("label_cantidad_comics_asociados"), self.builder.get_object("label_cantidad_comics_asociados1") ] self.volumens_manager = Volumens(session=self.session) self.volume = None # print(self.volume) # if self.volume is not None: # self.loadVolume(self.volume) self.getFirst(None) # self.combobox_orden = self.builder.get_object("combobox_orden") self.offset = 0 self.cantidadRegistros = self.volumens_manager.get_count() self.pagina_actual = 0 self.menu = self.builder.get_object("menu") # # inicializamos el modelo con rotulos del manager # self.liststore_combobox.clear() # for clave in self.volumens_manager.lista_opciones.keys(): # self.liststore_combobox.append([clave]) # self.combobox_orden.set_active(0) # self.getFirst("") def abrir_covers(self, widget): bc = Comicbooks_info_gtk( volumen_id=self.volumens_manager.entidad.id_volume) bc.window.show() self.menu.popdown() def pop_up_menu(self, widget): # self.popover.set_relative_to(button) self.menu.show_all() self.menu.popup() def getFirst(self, widget): volume = self.volumens_manager.getFirst() print(volume) # self.index = (self.index + 1)%2 self.stack.set_transition_type(Gtk.StackTransitionType.SLIDE_RIGHT) if volume is not None: self.loadVolume(volume) # self.index=self.index-1 # self.label_siguiente.set_text("label "+ str(self.index)) # # print(self.label_siguiente.get_text()) # self.stack.set_visible_child(self.label_siguiente) # # aux = self.label_actual # self.label_actual = self.label_siguiente # self.label_siguiente = aux def getLast(self, widget): volume = self.volumens_manager.getLast() print('volume') print(volume) self.stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT) self.loadVolume(volume) def getNext(self, widget): volume = self.volumens_manager.getNext() print('volume') print(volume) self.stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT) self.loadVolume(volume) def getPrev(self, widget): volume = self.volumens_manager.getPrev() self.stack.set_transition_type(Gtk.StackTransitionType.SLIDE_RIGHT) self.loadVolume(volume) def evento(self, widget, args): print(args.keyval) if args.keyval == Gdk.KEY_Escape: self.window.close() def click_derecho(self, widget, event): print("ACA ESTAMOS {}".format(event.get_click_count())) if event.get_click_count()[1] == 2: cbi = Comicbook_Info_Gtk() #seteamos el volumen para poder navegar entre los comicbooks info cbi.set_volume(self.volumens_manager.entidad.id_volume) model, treeiter = self.list_treeview_comics_in_volumen[ self.index].get_selection().get_selected() cbi.set_comicbook(model[treeiter][4]) cbi.window.show_all() def selecion_pagina(self, widget, page, page_num): self.pagina_actual = page_num if page_num == 1: comicbooks_in_volumen = self.volumens_manager.get_comicbook_info_by_volume( ) self.list_liststore_comics_in_volume[self.index].clear() for comicbook in comicbooks_in_volumen: #print(comicbook.id_comicbook_info, type(comicbook.id_comicbook_info)) self.list_liststore_comics_in_volume[self.index].append([ comicbook.numero, comicbook.titulo, comicbook.cantidad, comicbook.cantidad, comicbook.id_comicbook_info, comicbook.orden ]) def combobox_change(self, widget): if widget.get_active_iter() is not None: self.volumens_manager.set_order( self.volumens_manager.lista_opciones[widget.get_model()[ widget.get_active_iter()][0]]) def boton_cargar_desde_web_click(self, widget): volumen_vine_search = Volumen_vine_search_Gtk(self.session) volumen_vine_search.window.show() def click_lookup_volume(self, widget): lookup = Volume_lookup_gtk(self.session, self.return_lookup) lookup.window.show() def click_lookup_editorial(self, widget): print("Holaaaaaaaa") lookup = Publisher_lookup_gtk(self.session, self.return_lookup) lookup.window.show() def change_id_volume(self, widget, event): self.editorial = None self.set_volumen_id(self.list_entry_id[self.index].get_text()) def set_volumen_id(self, volumen_id): print(volumen_id) if (self.list_entry_id[self.index].get_text() != ''): volume = self.volumens_manager.get(volumen_id) self.loadVolume(volume) def return_lookup(self, id_volume): if id_volume != '': self.goto(id_volume) def return_lookup_editorial(self, id_editorial): if id_editorial != '': self.volumens_manager.entidad.id_publisher = id_editorial def goto(self, id_volume): self.list_entry_id[self.index].set_text(str(id_volume)) volume = self.volumens_manager.get( self.list_entry_id[self.index].get_text()) self.loadVolume(volume) def loadVolume(self, volumen): if self.volume is not None: if volumen == self.volume: print("SON IGUALES") return else: print("NO SON IGUALES") self.volume = volumen self.clear() print("dasdasdasdas") if self.volumens_manager.entidad is not None: #print("Volumen {}".format(self.volume)) self.index += 1 self.index %= 2 self.list_entry_id[self.index].set_text(str(volumen.id_volume)) self.list_entry_nombre[self.index].set_text(volumen.nombre) if len(volumen.url) >= 50: self.list_label_url[self.index].set_label(volumen.url[:50] + "...") else: self.list_label_url[self.index].set_label(volumen.url) self.list_label_url[self.index].set_uri(volumen.url) if len(volumen.get_api_url()) >= 50: self.list_label_api_url[self.index].set_label( volumen.get_api_url()[:50] + "...") else: self.list_label_api_url[self.index].set_label( volumen.get_api_url()) self.list_label_api_url[self.index].set_uri(volumen.get_api_url()) if len(volumen.image_url) >= 50: self.list_label_cover_url[self.index].set_label( volumen.image_url[:50] + "...") else: self.list_label_cover_url[self.index].set_label( volumen.image_url) self.list_label_cover_url[self.index].set_uri(volumen.image_url) # self.list_entry_id_editorial[self.index].set_text( volumen.id_publisher) self.list_label_nombre_editorial[self.index].set_text( volumen.publisher_name) self.list_entry_anio_inicio[self.index].set_text( str(volumen.anio_inicio)) self.list_entry_cantidad_numeros[self.index].set_text( str(volumen.cantidad_numeros)) self.list_resumen_volumen[self.index].set_text(volumen.descripcion) if volumen.cantidad_numeros > 0: self.list_progressbar_procentaje_completado[ self.index].set_fraction( self.volumens_manager.get_volume_status() / volumen.cantidad_numeros) else: self.list_progressbar_procentaje_completado[ self.index].set_fraction(0) self.list_label_cantidad_comics_asociados[self.index].set_text( str(self.volumens_manager. get_cantidad_comics_asociados_al_volumen())) print("PATH: {}".format(volumen.getImagePath())) pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale( filename=volumen.getImagePath(), width=250, height=250, preserve_aspect_ratio=True) # # print(self.volumen_logo_image) self.list_volumen_logo_image[self.index].set_from_pixbuf(pixbuf) comicbooks_in_volumen = self.volumens_manager.get_comicbook_info_by_volume( ) print(self.list_liststore_comics_in_volume) self.list_liststore_comics_in_volume[0].clear() for comicbook in comicbooks_in_volumen: # print(comicbook.id_comicbook_info, type(comicbook.id_comicbook_info)) self.list_liststore_comics_in_volume[0].append([ comicbook.numero, comicbook.titulo, comicbook.cantidad, comicbook.cantidad, comicbook.id_comicbook_info, comicbook.orden ]) self.stack.set_visible_child(self.lista_items[self.index]) # if self.pagina_actual == 1: # self.selecion_pagina(None, None, 1) def click_eliminar(self, widget): self.volumens_manager.rm() def clear(self): print(type(self.list_entry_id[self.index])) self.list_entry_id[self.index].set_text('') print(type(self.list_entry_id[self.index])) # self.entry_nombre.set_text('') # self.label_url.set_uri('') # self.list_label_api_url[self.index].set_uri('') # self.label_cover_url.set_uri('') # self.entry_id_editorial.set_text('') # self.label_nombre_editorial.set_text('') # self.entry_anio_inicio.set_text('') # self.entry_cantidad_numeros.set_text('') pass def copyFromWindowsToEntity(self): self.volumens_manager.entidad.nombre = self.list_entry_nombre[ self.index].get_text() #self.volume.deck = self..get() # self.volumens_manager.entidad.descripcion = self.entradaId.get() self.volumens_manager.entidad.url = self.list_label_url[ self.index].get_uri() self.volumens_manager.entidad.image_url = self.list_label_cover_url[ self.index].get_uri() self.volumens_manager.entidad.anio_inicio = self.list_entry_anio_inicio[ self.index].get_text() self.volumens_manager.entidad.cantidad_numeros = self.list_entry_cantidad_numeros[ self.index].get_text() def click_guardar(self, widget): self.copyFromWindowsToEntity() self.volumens_manager.save() # self.session.add(self.volumens_manager.entidad) # self.session.commit() def click_nuevo(self, widget): self.volumens_manager.new_record() print(self.volumens_manager.entidad) self.loadVolume(self.volumens_manager.entidad)
def set_volume(self, id_volume): self.comicbooks_manager.set_volume(id_volume=id_volume) volume_mamange = Volumens(session=self.session) volume = volume_mamange.get(id_volume) self.label_nombre_volumen.set_text(volume.nombre)
class Volume_lookup_gtk(): def __init__(self, session=None, campo_retorno=None): if session is None: self.session = Entidades.Init.Session() else: self.session = session self.handlers = { 'search_volumen': self.search_volumen, 'search_editorial': self.search_editorial, 'click_lookup_editorial': self.click_lookup_editorial, 'seleccion_volumen': self.seleccion_volumen, 'click_boton_aceptar': self.click_boton_aceptar, 'gtk_tree_view_volumen_double_click': self.gtk_tree_view_volumen_double_click, 'combobox_change': self.combobox_change, 'foco_busquedas': self.foco_busquedas } self.builder = Gtk.Builder() self.builder.add_from_file("../Glade_files/Volumen_lookup_gtk.glade") self.builder.connect_signals(self.handlers) self.window = self.builder.get_object("Volumen_lookup_gtk") self.window.set_icon_from_file('../iconos/BabelComic.png') self.search_entry_editorial = self.builder.get_object( "search_entry_editorial") self.imagen_cover_volumen = self.builder.get_object( "imagen_cover_volumen") self.gtk_tree_view_volumen = self.builder.get_object( 'gtk_tree_view_volumen') self.listmodel_volumens = self.builder.get_object("listmodel_volumens") self.label_nombre_editorial = self.builder.get_object( "label_nombre_editorial") self.volumens = self.session.query(Volume).all() self.search_entry_volumen = self.builder.get_object( 'search_entry_volumen') self.search_entry_editorial = self.builder.get_object( 'search_entry_editorial') self.volumens_manager = Volumens(session=self.session) self.volumens_manager.set_order(Volume.nombre) self.combobox_orden = self.builder.get_object("combobox_orden") self.liststore_combobox = self.builder.get_object("liststore_combobox") self._load_data() if campo_retorno is None: print("error campo retorno requerido") self.campo_retorno = campo_retorno self.publisher = None self.volume = None def foco_busquedas(self, widget): print("foco ganado") def combobox_change(self, widget): if widget.get_active_iter() is not None: self.volumens_manager.set_order( self.volumens_manager.lista_opciones[widget.get_model()[ widget.get_active_iter()][0]]) self._load_data() def gtk_tree_view_volumen_double_click(self, widget, event): if event.get_click_count()[1] == 2: self.click_boton_aceptar(widget) def search_volumen(self, widget): self.gtk_tree_view_volumen.get_selection().unselect_all() self.gtk_tree_view_volumen.get_selection().set_mode(0) self.volumens_manager.clear_filtro() if self.search_entry_volumen.get_text() == '': self.volumens_manager.clear_filtro() if self.publisher: self.volumens_manager.set_filtro( Volume.id_publisher == self.publisher.id_publisher) if self.search_entry_volumen.get_text() != '': self.volumens_manager.set_filtro( Volume.nombre.like('%{}%'.format( self.search_entry_volumen.get_text()))) self.volumens = self.volumens_manager.getList() self._load_data() self.gtk_tree_view_volumen.get_selection().set_mode(1) def search_editorial(self, widget): self.gtk_tree_view_volumen.get_selection().unselect_all() if self.search_entry_editorial.get_text() == '': self.publisher = None else: self.publisher = self.session.query(Publisher).filter( Publisher.id_publisher == self.search_entry_editorial.get_text()).first() if self.publisher: self.label_nombre_editorial.set_text(self.publisher.name) self.search_volumen(widget) def click_lookup_editorial(self, widget): lookup = Publisher_lookup_gtk(self.session, self.return_lookup_editorial) lookup.window.show() def _load_data(self): self.listmodel_volumens.clear() for index, volume in enumerate(self.volumens): self.listmodel_volumens.append([ volume.nombre, volume.cantidad_numeros, volume.publisher_name, volume.anio_inicio, index, volume.id_volume ]) self.gtk_tree_view_volumen.set_model(self.listmodel_volumens) def getSerie(self): print('retornando serie: ' + self.serie.nombre) return self.serie def seleccion_volumen(self, selection): (model, iter) = selection.get_selected() if iter is not None: self.volume = self.volumens[self.listmodel_volumens[iter][4]] pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale( filename=self.volume.getImagePath(), width=250, height=250, preserve_aspect_ratio=True) self.imagen_cover_volumen.set_from_pixbuf(pixbuf) def return_lookup_editorial(self, id_editorial): if id_editorial != '': self.search_entry_editorial.set_text(str(id_editorial)) def click_boton_aceptar(self, widget): self.campo_retorno(self.volume.id_volume) self.window.close()
def __init__(self, session=None, volumen_id=None): ImageFile.LOAD_TRUNCATED_IMAGES = True if session is None: self.session = Entidades.Init.Session() else: self.session = session self.volumens_manager = Volumens(session) #Nos posicionamos en algun volumen ya se el pasado por parametro si existo o el primero if volumen_id is None: self.volumens_manager.getFirst() else: volumen = self.volumens_manager.get(volumen_id) if volumen is None: self.volumens_manager.getFirst() self.load_setup() self.handlers = {'click_derecho': self.click_derecho, 'cambio_seleccion': self.cambio_seleccion, 'get_prev_cover': self.get_prev_cover, 'get_next_cover': self.get_next_cover} self.cataloged_pix = Pixbuf.new_from_file_at_size('../iconos/Cataloged.png', 32, 32) self.builder = Gtk.Builder() self.builder.add_from_file("../Glade_files/Comicbooks_info.glade") self.builder.connect_signals(self.handlers) self.window = self.builder.get_object("Comicbooks_info") self.menu = self.builder.get_object("menu") self.window.set_title("Comicbooks info") self.app_icon = Pixbuf.new_from_file_at_size('../iconos/iconoBabelComics-buuf.png', 32, 32) self.window.set_icon_from_file('../iconos/iconoBabelComics-buuf.png') self.window.set_default_icon_list([self.app_icon]) self.iconview_Comicbooks_info = self.builder.get_object('iconview_Comicbooks_info') self.thread_creacion_thumnails = None self.lista_comics_esperando_por_thumnail=[] self.updating_gui = False self.salir_thread = False self.liststore = self.builder.get_object('liststore') self.lista_pendientes = [] self.filtro = '' self.limit = self.session.query(Setup).first().cantidadComicsPorPagina self.offset = 0 self.query = None self.comicbooks_info_manager = {} self.dictionary = {} self.cantidad_thumnails_pendiente = 0 #self.search_change(None) self.iconview_Comicbooks_info.set_pixbuf_column(0) self.iconview_Comicbooks_info.set_text_column(1) self.iconview_Comicbooks_info.set_text_column(2) self.iconview_Comicbooks_info.set_column_spacing(-1) self.iconview_Comicbooks_info.set_item_padding(10) self.iconview_Comicbooks_info.set_item_width(1) self.iconview_Comicbooks_info.set_spacing(30) self.load_comicbooks_info() screen = Gdk.Screen.get_default() self.window.set_default_size(screen.width(), self.window.get_size()[1])
class Comicbooks_info_gtk(): def __init__(self, session=None, volumen_id=None): ImageFile.LOAD_TRUNCATED_IMAGES = True if session is None: self.session = Entidades.Init.Session() else: self.session = session self.volumens_manager = Volumens(session) #Nos posicionamos en algun volumen ya se el pasado por parametro si existo o el primero if volumen_id is None: self.volumens_manager.getFirst() else: volumen = self.volumens_manager.get(volumen_id) if volumen is None: self.volumens_manager.getFirst() self.load_setup() self.handlers = {'click_derecho': self.click_derecho, 'cambio_seleccion': self.cambio_seleccion, 'get_prev_cover': self.get_prev_cover, 'get_next_cover': self.get_next_cover} self.cataloged_pix = Pixbuf.new_from_file_at_size('../iconos/Cataloged.png', 32, 32) self.builder = Gtk.Builder() self.builder.add_from_file("../Glade_files/Comicbooks_info.glade") self.builder.connect_signals(self.handlers) self.window = self.builder.get_object("Comicbooks_info") self.menu = self.builder.get_object("menu") self.window.set_title("Comicbooks info") self.app_icon = Pixbuf.new_from_file_at_size('../iconos/iconoBabelComics-buuf.png', 32, 32) self.window.set_icon_from_file('../iconos/iconoBabelComics-buuf.png') self.window.set_default_icon_list([self.app_icon]) self.iconview_Comicbooks_info = self.builder.get_object('iconview_Comicbooks_info') self.thread_creacion_thumnails = None self.lista_comics_esperando_por_thumnail=[] self.updating_gui = False self.salir_thread = False self.liststore = self.builder.get_object('liststore') self.lista_pendientes = [] self.filtro = '' self.limit = self.session.query(Setup).first().cantidadComicsPorPagina self.offset = 0 self.query = None self.comicbooks_info_manager = {} self.dictionary = {} self.cantidad_thumnails_pendiente = 0 #self.search_change(None) self.iconview_Comicbooks_info.set_pixbuf_column(0) self.iconview_Comicbooks_info.set_text_column(1) self.iconview_Comicbooks_info.set_text_column(2) self.iconview_Comicbooks_info.set_column_spacing(-1) self.iconview_Comicbooks_info.set_item_padding(10) self.iconview_Comicbooks_info.set_item_width(1) self.iconview_Comicbooks_info.set_spacing(30) self.load_comicbooks_info() screen = Gdk.Screen.get_default() self.window.set_default_size(screen.width(), self.window.get_size()[1]) def get_prev_cover(self, wiget): self.cambio_cover(False) def get_next_cover(self, wiget): self.cambio_cover(True) def cambio_cover(self, siguiente): selected_list = self.iconview_Comicbooks_info.get_selected_items() if len(selected_list) == 1: if siguiente: image = Image.open(self.comicbooks_info_manager[str(selected_list[0])].get_next_cover_complete_path()).convert("RGB") self.update_cover(str(selected_list[0]), image) else: image = Image.open(self.comicbooks_info_manager[str(selected_list[0])].get_prev_cover_complete_path()).convert("RGB") self.update_cover(str(selected_list[0]), image) def cambio_seleccion(self, widget): print('dsdhskdhsd') selected_list = widget.get_selected_items() if len(selected_list) == 1: print("Nombre :", self.comicbooks_info_manager[str(selected_list[0])].lista_covers) def click_derecho(self, widget, event): if event.button == 3: rect = Gdk.Rectangle() rect.height = 10 rect.width = 10 rect.x = int(event.x) #por bug o funciona asi pero el click en iconview trae las coordenadas sin tener en cuenta que es una scroll #como resultado si no ajustamos se correr el popup rect.y = int(event.y-self.iconview_Comicbooks_info.get_vadjustment().get_value()) #usamos las coordenadas del evento para saber donde estamos detro de la scroll. p = self.iconview_Comicbooks_info.get_path_at_pos(event.x, event.y) if p is not None: self.iconview_Comicbooks_info.select_path(p) self.menu.set_pointing_to(rect) self.menu.set_position(3) self.menu.set_relative_to(widget) self.menu.popup() def doble_click(self, widget, event): print(event.get_click_count()) if event.get_click_count().click_count == 2: pass def image2pixbuf(self, im): """Convert Pillow image to GdkPixbuf""" data = im.tobytes() w, h = im.size data = GLib.Bytes.new(data) pix = GdkPixbuf.Pixbuf.new_from_bytes(data, GdkPixbuf.Colorspace.RGB, False, 8, w, h, w * 3) return pix def create_grey_tumnails(self, lista): img = Image.new("RGB", (self.ancho_thumnail, int(self.ancho_thumnail*1.3)), (150, 150, 150)) for i in range(0, len(lista)): img_aux = img.copy() d1 = ImageDraw.Draw(img_aux) font = ImageFont.truetype('../Extras/fonts/Comic Book.otf', 26) d1.text(((self.ancho_thumnail/2)-20, self.ancho_thumnail/2), str(i), font=font, fill=(255, 255, 255)) d1.polygon([(0, 0), (self.ancho_thumnail, 0), (self.ancho_thumnail, self.ancho_thumnail*2), (0, self.ancho_thumnail*2)], outline=(0, 0, 0)) gdkpixbuff_thumnail = self.image2pixbuf(img_aux) # print(lista[i].titulo, lista[i].id_volume) GLib.idle_add(self.update_progess2, gdkpixbuff_thumnail, lista[i].titulo, lista[i].id_comicbook_info) def update_progess2(self, gdkpixbuff_thumnail, archivo_nombre, id_volume): self.liststore.append([gdkpixbuff_thumnail, archivo_nombre, id_volume]) def load_setup(self): self.pahThumnails = self.session.query(Setup).first().directorioBase + os.path.sep + "images" + os.path.sep + "coverIssuesThumbnails" + os.path.sep self.ancho_thumnail = self.session.query(Setup).first().anchoThumnail def load_comicbooks_info(self): self.liststore.clear() comicbook_info_manager = Comicbooks_Info(self.session) comicbook_info_manager.set_filtro(Comicbook_Info.id_volume == self.volumens_manager.entidad.id_volume) comicbook_info_manager.set_order(Comicbook_Info.orden) lista = comicbook_info_manager.getList() # print(lista) self.create_grey_tumnails(lista) t = threading.Thread(target=self.load_comicbooks_info_second_part, args=(lista,)) t.start() def load_comicbooks_info_second_part(self, lista): for index, comicbook_info in enumerate(lista): self.comicbooks_info_manager[str(index)] = Comicbooks_Info(self.session) t = threading.Thread(target=self.load_comicbook_info_cover, args=(comicbook_info, index,)) t.start() def seleccion_volumen(self, widget): selected_list = widget.get_selected_items() if len(selected_list) == 1: print("Nombre :", str(self.liststore[selected_list[0]][2])) def load_comicbook_info_cover(self, comicbook_info, index): #se hace local el manager para que casa hilo pueda buscar la info sin compartir el manager de comicbooks_info self.comicbooks_info_manager[str(index)].get(comicbook_info.id_comicbook_info) image = Image.open(self.comicbooks_info_manager[str(index)].get_first_cover_complete_path()).convert("RGB") GLib.idle_add(self.update_cover, index, image) def update_cover(self, index, image): size = (self.ancho_thumnail, int(image.size[1] * self.ancho_thumnail / image.size[0])) image.thumbnail(size, 3, 3) img_aux = image.copy() d1 = ImageDraw.Draw(img_aux) d1.rectangle([(0, 0), (size[0] - 1, size[1] - 1)], outline=(0, 0, 0), width=3) d1.rectangle([(0, 0), (size[0] - 1, size[1] - 1)], outline=(0, 0, 0), width=3) new_image = Image.new(mode='RGB', size=(img_aux.size[0], img_aux.size[1] + 50)) d1 = ImageDraw.Draw(new_image) # pregunto por el ancho para saber si puedo poner o no todo el contenido if size[0] > 120: font = ImageFont.truetype('/home/pedro/PycharmProjects/BabelComic-II/Extras/fonts/Comic Book.otf', 26) d1.text((10, 10), "{}/{}".format(self.comicbooks_info_manager[str(index)].entidad.numero, self.volumens_manager.entidad.cantidad_numeros), font=font, fill=(200, 200, 200)) font = ImageFont.truetype('/home/pedro/PycharmProjects/BabelComic-II/Extras/fonts/Comic Book.otf', 18) d1.text((size[0] - 35, 10), "{}/{}".format(self.comicbooks_info_manager[str(index)].index_lista_covers+1, len(self.comicbooks_info_manager[str(index)].lista_covers)), font=font, fill=(200, 200, 200)) new_image.paste(img_aux, (0, 50)) gdkpixbuff_thumnail = self.image2pixbuf(new_image) self.liststore[index][0] = gdkpixbuff_thumnail def activar_busqueda(self, widget, event): self.barra_busqueda.set_search_mode(True) self.volumen_search_entry.grab_focus() def entrada_teclado_barra_busqueda(self, widget, event): if event.keyval == Gdk.KEY_Escape: self.barra_busqueda.set_search_mode(False) self.volumen_search_entry.set_text('') self.iconview_volumens.grab_focus() def evento_busqueda(self, event): self.manager.set_filtro(Volume.nombre.like('%{}%'.format(self.volumen_search_entry.get_text()))) self.load_volumens()