Mercurial > hg > pub > prymula > scripts
view postagelabels/postagelabels.py @ 24:02409f02eea6
bing4desktop-0.240208-0
author | prymula <prymula76@outlook.com> |
---|---|
date | Thu, 08 Feb 2024 11:37:04 +0100 |
parents | dcd610585610 |
children |
line wrap: on
line source
#!/usr/bin/env python3 # Postage Labels - aplikacja do aranżacji wydruków etykiet pocztowych # autor: Przemysław R. Pietraszczyk # licencja: GPL # data 20-IX-2021 # edytor: Geany import sys import cairo import gi, os gi.require_version("Gtk", "3.0") from gi.repository import Gtk, GdkPixbuf, Gdk from gi.repository.GdkPixbuf import Pixbuf UI_INFO = """ <ui> <menubar name='MenuBar'> <menu action='FileMenu'> <menu action='FileLoad'> <menuitem action='NewTemplate' /> <menuitem action='LoadImg' /> <menuitem action='Composite' /> </menu> <menuitem action='FilePrint' /> <separator /> <menuitem action='FileQuit' /> </menu> <menu action='InfoMenu'> <menuitem action='Help'/> <menuitem action='About'/> </menu> </menubar> </ui> """ grid = Gtk.Grid() file_img_selected="" file_label_save="" new_pixbuf="" list_labels = [] label_limits = [] print_limits = [] #label_selected = "" BLANK_W = 1134 BLANK_H = 496 def get_resource_path(rel_path): dir_of_py_file = os.path.dirname(__file__) rel_path_to_resource = os.path.join(dir_of_py_file, rel_path) abs_path_to_resource = os.path.abspath(rel_path_to_resource) return abs_path_to_resource class DialogCompositor(Gtk.Dialog): def __init__(self, parent): global new_pixbuf Gtk.Dialog.__init__(self, title="Kompozytor", transient_for=parent, flags=0) self.props.border_width = 20 self.add_buttons( Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.OK, ) self.compos = Gtk.Grid() file_img_composite=get_resource_path("/usr/share/postagelabels/blank_small.png") new_pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale( filename=file_img_composite, width=500, height=250, preserve_aspect_ratio=True) self.add(self.compos) self.compos.set_row_spacing(10) self.compos.set_column_spacing(10) #self.compos.set_column_homogeneous(True) # rozszerza kontrolke na resztę okna # potrzebne do wyśwetlenia tekstu self.surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, new_pixbuf.get_width(), new_pixbuf.get_height()) self.context = cairo.Context(self.surface) Gdk.cairo_set_source_pixbuf(self.context, new_pixbuf, 0, 0) self.context.paint() #paint the pixbuf self.fontsize= 25 box = self.get_content_area() self.com_first = Gtk.Image.new_from_pixbuf(new_pixbuf) self.compos.attach(self.com_first,0,0,1,3) self.entry1 = Gtk.Entry() self.entry1.set_text("Hello World") self.compos.attach(self.entry1,1,0,1,1) self.entry2 = Gtk.Entry() self.entry2.set_text("Hello World") self.compos.attach(self.entry2,1,1,1,1) self.entry3 = Gtk.Entry() self.entry3.set_text("Hello World") self.compos.attach(self.entry3,1,2,1,1) self.entry4 = Gtk.Entry() self.entry4.set_text("Hello World") self.compos.attach(self.entry4,1,3,1,1) button1 = Gtk.Button.new_with_label("Aktualizuj") button1.connect("clicked", self.actualization1) self.compos.attach(button1,2,0,1,1) button2 = Gtk.Button.new_with_label("Aktualizuj") button2.connect("clicked", self.actualization2) self.compos.attach(button2,2,1,1,1) button3 = Gtk.Button.new_with_label("Aktualizuj") button3.connect("clicked", self.actualization3) self.compos.attach(button3,2,2,1,1) button4 = Gtk.Button.new_with_label("Aktualizuj") button4.connect("clicked", self.actualization4) self.compos.attach(button4,2,3,1,1) button_clear = Gtk.Button.new_with_label("Wyczyść") button_clear.connect("clicked", self.entry_clear) self.compos.attach(button_clear,3,0,1,4) box.add(self.compos) self.show_all() def entry_clear(self, button): global new_pixbuf file_img_selected=get_resource_path("/usr/share/postagelabels/blank_small.png") new_pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale( filename=file_img_selected, width=500, height=250, preserve_aspect_ratio=True) if self.com_first != None: self.compos.remove(self.com_first) self.com_first=None else: self.compos.remove(self.com_new) # czyści etykiete self.surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, new_pixbuf.get_width(), new_pixbuf.get_height()) self.context = cairo.Context(self.surface) Gdk.cairo_set_source_pixbuf(self.context, new_pixbuf, 0, 0) self.context.paint() #paint the pixbuf self.com_new = Gtk.Image.new_from_pixbuf(new_pixbuf) self.compos.attach(self.com_new,0,0,1,3) self.show_all() def actualization1(self, button): global new_pixbuf self.context.move_to(15, 20+self.fontsize) self.context.set_font_size(self.fontsize) self.context.set_source_rgba(0,0,0,1) self.context.show_text(self.entry1.get_text()) #get the resulting pixbuf self.surface= self.context.get_target() new_pixbuf= Gdk.pixbuf_get_from_surface(self.surface, 0, 0, self.surface.get_width(), self.surface.get_height()) if self.com_first != None: self.compos.remove(self.com_first) self.com_first=None else: self.compos.remove(self.com_new) self.com_new = Gtk.Image.new_from_pixbuf(new_pixbuf) self.compos.attach(self.com_new,0,0,1,3) self.show_all() def actualization2(self, button): global new_pixbuf self.context.move_to(15, 20+self.fontsize+self.fontsize+15) self.context.set_font_size(self.fontsize) self.context.set_source_rgba(0,0,0,1) self.context.show_text(self.entry2.get_text()) #get the resulting pixbuf self.surface= self.context.get_target() new_pixbuf= Gdk.pixbuf_get_from_surface(self.surface, 0, 0, self.surface.get_width(), self.surface.get_height()) if self.com_first != None: self.compos.remove(self.com_first) self.com_first=None else: self.compos.remove(self.com_new) self.com_new = Gtk.Image.new_from_pixbuf(new_pixbuf) self.compos.attach(self.com_new,0,0,1,3) self.show_all() def actualization3(self, button): global new_pixbuf self.context.move_to(15, 20+self.fontsize+self.fontsize+self.fontsize+30) self.context.set_font_size(self.fontsize) self.context.set_source_rgba(0,0,0,1) self.context.show_text(self.entry3.get_text()) #get the resulting pixbuf self.surface= self.context.get_target() new_pixbuf= Gdk.pixbuf_get_from_surface(self.surface, 0, 0, self.surface.get_width(), self.surface.get_height()) if self.com_first != None: self.compos.remove(self.com_first) self.com_first=None else: self.compos.remove(self.com_new) self.com_new = Gtk.Image.new_from_pixbuf(new_pixbuf) self.compos.attach(self.com_new,0,0,1,3) self.show_all() def actualization4(self, button): global new_pixbuf self.context.move_to(15, 20+self.fontsize+self.fontsize+self.fontsize+self.fontsize+50) self.context.set_font_size(self.fontsize) self.context.set_source_rgba(0,0,0,1) self.context.show_text(self.entry4.get_text()) #get the resulting pixbuf self.surface= self.context.get_target() new_pixbuf= Gdk.pixbuf_get_from_surface(self.surface, 0, 0, self.surface.get_width(), self.surface.get_height()) if self.com_first != None: self.compos.remove(self.com_first) self.com_first=None else: self.compos.remove(self.com_new) self.com_new = Gtk.Image.new_from_pixbuf(new_pixbuf) self.compos.attach(self.com_new,0,0,1,3) self.show_all() class DialogHelp(Gtk.Dialog): def __init__(self, parent): Gtk.Dialog.__init__(self, title="Pomoc", transient_for=parent, flags=0) self.props.border_width = 20 self.add_buttons( Gtk.STOCK_OK, Gtk.ResponseType.OK ) self.set_default_size(150, 100) label1 = Gtk.Label(label="Aplikacja służąca do aranżacji wydruku etykiet pocztowych.\nMożna zrówno tworzyć jak i wczytywać gotowe etykiety,\n a następnie umieszczać jena siatce.\nAplikacja bierze poprawkę dla drukarki Epson serii L,\nz ramką wokół wydruku.\n") label2 = Gtk.Label(label="Pojedyńcza etykieta powinna mieć wymiary: 1134x496 px.\nKomptabilny papier pochodzi z zasobów \'Galerii Papieru\'\n\nNa siatce etykiete dodajemy \'lpm\', a usuwamy \'ppm\'.\n\nAplikacja na ekranach HD Ready będzie zachowywać się\nniestabilnie! Zalecany ekran to Full HD.") box = self.get_content_area() box.add(label1) box.add(label2) self.show_all() class DialogAbout(Gtk.Dialog): def __init__(self, parent): Gtk.Dialog.__init__(self, title="O Programie", transient_for=parent, flags=0) self.props.border_width = 20 self.add_buttons( Gtk.STOCK_OK, Gtk.ResponseType.OK ) self.set_default_size(150, 100) label = Gtk.Label(label="\tAplikacja napisana na podstawie:\n\nhttps://python-gtk-3-tutorial.readthedocs.io/\n\n\t\tWersja: 0.220120-2\n\n\t\tPrzemysław R. Pietraszczyk\n\n\t\t\tWrzesień 2021\n\t\t\tLicencja: GPL\n\n") box = self.get_content_area() box.add(label) button = Gtk.LinkButton("http://www.prp.xlx.pl", label="Strona Domowa") box.add(button) self.show_all() class DialogMessage(Gtk.Dialog): def __init__(self, parent): super().__init__(title="Błąd zaznaczenia", transient_for=parent, flags=0) self.add_buttons( Gtk.STOCK_OK, Gtk.ResponseType.OK ) self.set_default_size(150, 100) label = Gtk.Label(label="Powinieneś najperw zaznaczyć etykiete,\nz listy dostępnych etykiet.") box = self.get_content_area() box.add(label) self.show_all() class FileChooserIMG(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="Wybór plików graficznych") global file_img_selected dialog = Gtk.FileChooserDialog(title="Please choose a file", parent=self, action=Gtk.FileChooserAction.OPEN) dialog.add_buttons( Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK, ) self.add_filters(dialog) response = dialog.run() if response == Gtk.ResponseType.OK: print("Open clicked") print("File selected: " + dialog.get_filename()) file_img_selected=dialog.get_filename() list_labels.append(file_img_selected) elif response == Gtk.ResponseType.CANCEL: print("Cancel clicked") dialog.destroy() def add_filters(self, dialog): filter_png = Gtk.FileFilter() filter_png.set_name("Pliki PNG") filter_png.add_mime_type("image/png") dialog.add_filter(filter_png) filter_jpeg = Gtk.FileFilter() filter_jpeg.set_name("Pliki JPEG") filter_jpeg.add_mime_type("image/jpeg") dialog.add_filter(filter_jpeg) class FileChooserLabel(Gtk.Window): def __init__(self, this): global glob_liststore Gtk.Window.__init__(self, title="Zapis etykiety") global file_label_save dialog = Gtk.FileChooserDialog(title="Please choose a file", parent=self, action=Gtk.FileChooserAction.SAVE) dialog.add_buttons( Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.OK, ) self.add_filters(dialog) response = dialog.run() if response == Gtk.ResponseType.OK: print("Open clicked") print("File selected: " + dialog.get_filename()) file_label_save=dialog.get_filename() pixbuf2 = new_pixbuf.scale_simple(1134, 496, GdkPixbuf.InterpType.BILINEAR) pixbuf2.savev(file_label_save,"png", ["quality"], ["100"]) this.available_labels(file_label_save) elif response == Gtk.ResponseType.CANCEL: print("Cancel clicked") dialog.destroy() def add_filters(self, dialog): filter_png = Gtk.FileFilter() filter_png.set_name("Pliki PNG") filter_png.add_mime_type("image/png") dialog.add_filter(filter_png) """ filter_jpeg = Gtk.FileFilter() filter_jpeg.set_name("Pliki JPEG") filter_jpeg.add_mime_type("image/jpeg") dialog.add_filter(filter_jpeg) """ class MyWindow(Gtk.Window): def __init__(self): super().__init__() self.init_ui() def refresh_label_view(self): if self.image2 != None: grid.remove(self.image2) self.image2=None else: grid.remove(self.image_new) pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale( filename=self.label_selected, width=500, height=250, preserve_aspect_ratio=True) self.image_new = Gtk.Image.new_from_pixbuf(pixbuf) grid.attach(self.image_new,0,1,1,1) self.show_all() def on_menu_file_new_template(self, widget): n = 0 file_img_selected=get_resource_path("/usr/share/postagelabels/blank_small.png") pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale( filename=file_img_selected, width=250, height=117, #125, preserve_aspect_ratio=True) for l in label_limits: print ("IMAGE2: "+str(pixbuf)) if pixbuf is not None: self.image_template[n].set_from_pixbuf(pixbuf) print_limits[n][2] = None n += 1 self.show_all() # najprawdopodobnie wymagane po pakietowaniu def on_menu_file_load_img_generic(self, widget): global grid filename=FileChooserIMG() if len(file_img_selected) != 0: if self.image2 != None: grid.remove(self.image2) self.image2=None else: grid.remove(self.image_new) pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale( filename=file_img_selected, width=500, height=250, preserve_aspect_ratio=True) self.image_new = Gtk.Image.new_from_pixbuf(pixbuf) grid.attach(self.image_new,0,1,1,1) self.scrolled_window.remove(self.treeview) grid.remove(self.scrolled_window) self.liststore = Gtk.ListStore(str, str) self.treeview.remove_column(self.column_text) for o in list_labels: self.liststore.append([o,""]) self.scrolled_window = Gtk.ScrolledWindow () self.scrolled_window.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self.treeview = Gtk.TreeView(model=self.liststore) self.renderer_text = Gtk.CellRendererText() self.column_text = Gtk.TreeViewColumn("Dostępne etykiety", self.renderer_text, text=0) self.treeview.append_column(self.column_text) self.treeview.connect("button_release_event", self.mouse_selected) self.scrolled_window.add (self.treeview) grid.attach(self.scrolled_window,0,2,1,6) self.show_all() def on_menu_composite_generic(self, widget): dialog = DialogCompositor(self) response = dialog.run() if response == Gtk.ResponseType.OK: print("Save clicked") dialog_file_label=FileChooserLabel(self) elif response == Gtk.ResponseType.CANCEL: print("Cancel clicked") dialog.destroy() def on_menu_file_quit(self, widget): Gtk.main_quit() def on_menu_help(self, widget): dialog = DialogHelp(self) response = dialog.run() dialog.destroy() def on_menu_about(self, widget): dialog = DialogAbout(self) response = dialog.run() dialog.destroy() def add_info_menu_actions(self, action_group): action_info_menu = Gtk.Action(name="InfoMenu", label="Info") action_group.add_action(action_info_menu) action_new = Gtk.Action( name="Help", label="Pomoc", tooltip="Create a new file", ) action_new.connect("activate", self.on_menu_help) action_group.add_action_with_accel(action_new, None) action_new = Gtk.Action( name="About", label="O Programie", tooltip="Create a new file", ) action_new.connect("activate", self.on_menu_about) action_group.add_action_with_accel(action_new, None) def add_file_menu_actions(self, action_group): action_filemenu = Gtk.Action(name="FileMenu", label="Plik") action_group.add_action(action_filemenu) action_fileloadmenu = Gtk.Action(name="FileLoad", stock_id=Gtk.STOCK_NEW) action_group.add_action(action_fileloadmenu) action_new = Gtk.Action( name="LoadImg", label="Załaduj etykiete", tooltip="Wczytuje etykiete", ) action_new.connect("activate", self.on_menu_file_load_img_generic) action_group.add_action_with_accel(action_new, None) action_new = Gtk.Action( name="NewTemplate", label="Nowy szablon", tooltip="Tworzy szablon na nowo", ) action_new.connect("activate", self.on_menu_file_new_template) action_group.add_action_with_accel(action_new, None) action_new = Gtk.Action( name="Composite", label="Kompozytor", tooltip="Tworzy nową etykiete", ) action_new.connect("activate", self.on_menu_composite_generic) action_group.add_action_with_accel(action_new, None) action_print = Gtk.Action(name="FilePrint", stock_id=Gtk.STOCK_PRINT) action_print.connect("activate", self.print_image) action_group.add_action(action_print) action_filequit = Gtk.Action(name="FileQuit", stock_id=Gtk.STOCK_QUIT) action_filequit.connect("activate", self.on_menu_file_quit) action_group.add_action(action_filequit) # tworzy menu bar def create_ui_manager(self): uimanager = Gtk.UIManager() # Throws exception if something went wrong uimanager.add_ui_from_string(UI_INFO) # Add the accelerator group to the toplevel window accelgroup = uimanager.get_accel_group() self.add_accel_group(accelgroup) return uimanager def mouse_selected(self, tv, event): if event.button == 1: # Begin added code pthinfo = self.treeview.get_path_at_pos(event.x, event.y) if pthinfo != None: path,col,cellx,celly = pthinfo self.treeview.grab_focus() self.treeview.set_cursor(path,col,0) # End added code selection = self.treeview.get_selection() (model, iter) = selection.get_selected() print(model[iter][0]) self.label_selected = model[iter][0] self.refresh_label_view() def onclick_in_pixbuf (self, box, event): if event.button == 1: try: print ("\nKliknieto na pozycji") print (event.x, event.y) print ("\n") e = [int(event.x), int(event.y)] n = 0 pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale( filename=self.label_selected, width=250, height=117, #125, preserve_aspect_ratio=True) for l in label_limits: x, y = l[:] e_x, e_y = e[:] if e_x >= x and e_y >= y and e_x <= x+250 and e_y <= y+117: if pixbuf is not None: self.image_template[n].set_from_pixbuf(pixbuf) print_limits[n][2] = self.label_selected break n += 1 except AttributeError: dialog = DialogMessage(self) response = dialog.run() dialog.destroy() if event.button == 3: e = [int(event.x), int(event.y)] n = 0 file_img_selected=get_resource_path("/usr/share/postagelabels/blank_small.png") pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale( filename=file_img_selected, width=250, height=117, #125, preserve_aspect_ratio=True) for l in label_limits: x, y = l[:] e_x, e_y = e[:] if e_x >= x and e_y >= y and e_x <= x+250 and e_y <= y+117: print ("IMAGE2: "+str(pixbuf)) if pixbuf is not None: self.image_template[n].set_from_pixbuf(pixbuf) print_limits[n][2] = None break n += 1 self.show_all() # najprawdopodobnie wymagane po pakietowaniu def on_mouse_move_in_pixbuf (self, box, event): e = [int(event.x), int(event.y)] n = 0 for l in label_limits: x, y = l[:] e_x, e_y = e[:] if e_x >= x and e_y >= y and e_x <= x+200 and e_y <= y+92: pass # dnae dla wydruku def set_print_limits(self): start_x = 0 start_y = 0 end_x = BLANK_W * 2 #1234*2 end_y = BLANK_H * 6 #3508 cols = 2 rows = 6 width = BLANK_W #1234 height = BLANK_H #585 for j in range (start_y, end_y, height): for i in range (start_x, end_x, width): print_limits.append([i, j, None]) print ("PRINT LIMIST") print (print_limits) # dane dla siatki def set_label_limits(self): start_x = 0 start_y = 0 end_x = 500 end_y = 104 * 6 #117 * 6 #700 cols = 2 rows = 6 width = 250 height = 104 #117 for j in range (start_y, end_y, height): for i in range (start_x, end_x, width): label_limits.append([i, j]) def print_page(self, operation=None, context=None, page_nr=None): ctx = context.get_cairo_context() # make cairo ImageSurface from the png file surface = cairo.ImageSurface.create_from_png('/tmp/postagelabels.png') #ctx.set_operator(cairo.OPERATOR_SOURCE) ctx.set_source_surface(surface) ctx.paint () #ctx.set_operator(cairo.OPERATOR_OVER) os.remove("/tmp/postagelabels.png"); #page = self.doc.get_page(page_nr) #page.render(ctx) def print_image(self, widget): print ("PRINT LIMITS") print (print_limits) page_width = 210 page_height = 297 #page_margin_top = 20 dpi = 600 #_mm_dpi = 72 / 25.4 pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size('/usr/share/postagelabels/szablon.png', 2480, 3508) for i in range (12): if print_limits[i][2] != None: if i%2 == 1: center_beam = 24 else: center_beam = 0 label = GdkPixbuf.Pixbuf.new_from_file_at_size(print_limits[i][2], BLANK_W, BLANK_H) #self.freeze_child_notify() label.composite(pixbuf, print_limits[i][0]+89+center_beam, print_limits[i][1]+237, label.get_width(), label.get_height(), print_limits[i][0]+89+center_beam, print_limits[i][1]+237, 1, 1, GdkPixbuf.InterpType.NEAREST, 255) #self.thaw_child_notify() # z orginalnymi wielkościami nie chce drukowac pixbuf2 = pixbuf.scale_simple(600, 855, GdkPixbuf.InterpType.BILINEAR) pixbuf2.savev("/tmp/postagelabels.png","png", ["quality"], ["100"]) """ paper_size = Gtk.PaperSize.new_custom("1.0x", "2480 x 3508", 2480, 3508, Gtk.Unit.POINTS) page_setup = Gtk.PageSetup() page_setup.set_paper_size(paper_size) pd = Gtk.PrintOperation() #pd.set_embed_page_setup(True) pd.set_default_page_setup(page_setup) #pd.set_unit(Gtk.Unit.POINTS) pd.set_n_pages(1) pd.connect("draw_page", self.print_page) result = pd.run(Gtk.PrintOperationAction.PRINT_DIALOG, None) # window zamisat None print(result) # handle errors etc. """ #ps= Gtk.PaperSize.new_custom("1.0x", "2480 x 3508", 2480, 3508, Gtk.Unit.POINTS) ps = Gtk.PaperSize.new_custom("1.0x", "cc", page_width, page_height, Gtk.Unit.MM) print_settings = Gtk.PrintSettings() print_settings.set_resolution(dpi) page_setup = Gtk.PageSetup() page_setup.set_paper_size(ps) page_setup.set_bottom_margin(0.0, Gtk.Unit.MM) page_setup.set_left_margin(0.0, Gtk.Unit.MM) page_setup.set_right_margin(0.0, Gtk.Unit.MM) page_setup.set_top_margin(0.0, Gtk.Unit.MM) page_setup.set_orientation(Gtk.PageOrientation.PORTRAIT) print_operation = Gtk.PrintOperation() print_operation.set_n_pages(1) print_operation.set_default_page_setup(page_setup) print_operation.set_print_settings(print_settings) print_operation.connect("draw_page", self.print_page) #print_operation.set_export_filename("example.pdf") result = print_operation.run(Gtk.PrintOperationAction.PRINT_DIALOG, None) # window zamisat None #result = print_operation.run(Gtk.PrintOperationAction.PREVIEW, None) print(result) def available_labels(self, name): self.scrolled_window.remove(self.treeview) grid.remove(self.scrolled_window) self.liststore = Gtk.ListStore(str, str) self.treeview.remove_column(self.column_text) list_labels.append(name) for o in list_labels: self.liststore.append([o,""]) self.scrolled_window = Gtk.ScrolledWindow () self.scrolled_window.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self.treeview = Gtk.TreeView(model=self.liststore) self.renderer_text = Gtk.CellRendererText() self.column_text = Gtk.TreeViewColumn("Dostępne etykiety", self.renderer_text, text=0) self.treeview.append_column(self.column_text) self.treeview.connect("button_release_event", self.mouse_selected) self.scrolled_window.add (self.treeview) grid.attach(self.scrolled_window,0,2,1,6) self.show_all() def init_ui(self): global grid self.image_new=None self.props.border_width = 20 self.add(grid) grid.set_row_spacing(10) grid.set_column_spacing(10) grid.set_column_homogeneous(True) # rozszerza kontrolke z utworami na resztę okna action_group = Gtk.ActionGroup(name="my_actions") self.add_file_menu_actions(action_group) self.add_info_menu_actions(action_group) uimanager = self.create_ui_manager() uimanager.insert_action_group(action_group) menubar = uimanager.get_widget("/MenuBar") box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) box.pack_start(menubar, False, False, 0) grid.attach(box, 0, 0, 2, 1) event_box = Gtk.EventBox () event_box.connect ('button-press-event', self.onclick_in_pixbuf) event_box.connect("motion-notify-event", self.on_mouse_move_in_pixbuf) event_box.add_events(Gdk.EventMask.POINTER_MOTION_MASK) self.set_label_limits() self.set_print_limits() frame = Gtk.Frame() file_img_selected=get_resource_path("/usr/share/postagelabels/blank_small.png") pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale( filename=file_img_selected, width=250, height=117, #125 preserve_aspect_ratio=True) self.all_img_template = Gtk.Grid() self.image_template = [] self.image_template= [0 for i in range(12)] left = 0 top = 1 top_next=False multiplier = 0 n_multi = 1; first = False n = 2 for i in range(12): print ("left: "+str(left)+" top: "+str(top)) if left == 2: left = 0; n_multi += 1 print ("multi: " +str(n_multi)+" %"+ str(n_multi%4)) if n_multi%2== 0: if first == False: multiplier = 1 first = True multiplier += n n *= 2 self.image_template[i] = Gtk.Image.new_from_pixbuf(pixbuf) self.all_img_template.attach(self.image_template[i], left, top+multiplier, 1 , top+multiplier) left += 1 if top_next == False: top_next = True pass else: top_next = False top +=1 event_box.add(self.all_img_template) frame.add(event_box) grid.attach(frame,1,1,1,6) # powiększenie etykiety po lewej stronie file_img_selected=get_resource_path("/usr/share/postagelabels/blank_small.png") pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale( filename=file_img_selected, width=500, height=250, preserve_aspect_ratio=True) self.image2 = Gtk.Image.new_from_pixbuf(pixbuf) grid.attach(self.image2,0,1,1,1) self.liststore = Gtk.ListStore(str, str) self.treeview = Gtk.TreeView(model=self.liststore) self.treeview.connect("button_release_event", self.mouse_selected) self.renderer_text = Gtk.CellRendererText() self.column_text = Gtk.TreeViewColumn("Dostępne etykiety", self.renderer_text, text=0) self.treeview.append_column(self.column_text) self.scrolled_window = Gtk.ScrolledWindow () self.scrolled_window.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self.scrolled_window.add (self.treeview) grid.attach(self.scrolled_window,0,2,1,6) self.set_border_width(10) self.set_title("Naklejki Pocztowe") self.set_default_size(1000, 655) self.connect("destroy", Gtk.main_quit) win = MyWindow() win.show_all() Gtk.main()