annotate postagelabels/postagelabels.py @ 10:ed9556d0c5d7

bing4desktop-0.240205-4
author prymula <prymula76@outlook.com>
date Tue, 06 Feb 2024 00:30:36 +0100
parents dcd610585610
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
prymula <prymula76@outlook.com>
parents:
diff changeset
1 #!/usr/bin/env python3
prymula <prymula76@outlook.com>
parents:
diff changeset
2 # Postage Labels - aplikacja do aranżacji wydruków etykiet pocztowych
prymula <prymula76@outlook.com>
parents:
diff changeset
3 # autor: Przemysław R. Pietraszczyk
prymula <prymula76@outlook.com>
parents:
diff changeset
4 # licencja: GPL
prymula <prymula76@outlook.com>
parents:
diff changeset
5 # data 20-IX-2021
prymula <prymula76@outlook.com>
parents:
diff changeset
6 # edytor: Geany
prymula <prymula76@outlook.com>
parents:
diff changeset
7
prymula <prymula76@outlook.com>
parents:
diff changeset
8 import sys
prymula <prymula76@outlook.com>
parents:
diff changeset
9 import cairo
prymula <prymula76@outlook.com>
parents:
diff changeset
10 import gi, os
prymula <prymula76@outlook.com>
parents:
diff changeset
11 gi.require_version("Gtk", "3.0")
prymula <prymula76@outlook.com>
parents:
diff changeset
12 from gi.repository import Gtk, GdkPixbuf, Gdk
prymula <prymula76@outlook.com>
parents:
diff changeset
13 from gi.repository.GdkPixbuf import Pixbuf
prymula <prymula76@outlook.com>
parents:
diff changeset
14
prymula <prymula76@outlook.com>
parents:
diff changeset
15
prymula <prymula76@outlook.com>
parents:
diff changeset
16 UI_INFO = """
prymula <prymula76@outlook.com>
parents:
diff changeset
17 <ui>
prymula <prymula76@outlook.com>
parents:
diff changeset
18 <menubar name='MenuBar'>
prymula <prymula76@outlook.com>
parents:
diff changeset
19 <menu action='FileMenu'>
prymula <prymula76@outlook.com>
parents:
diff changeset
20 <menu action='FileLoad'>
prymula <prymula76@outlook.com>
parents:
diff changeset
21 <menuitem action='NewTemplate' />
prymula <prymula76@outlook.com>
parents:
diff changeset
22 <menuitem action='LoadImg' />
prymula <prymula76@outlook.com>
parents:
diff changeset
23 <menuitem action='Composite' />
prymula <prymula76@outlook.com>
parents:
diff changeset
24 </menu>
prymula <prymula76@outlook.com>
parents:
diff changeset
25 <menuitem action='FilePrint' />
prymula <prymula76@outlook.com>
parents:
diff changeset
26 <separator />
prymula <prymula76@outlook.com>
parents:
diff changeset
27 <menuitem action='FileQuit' />
prymula <prymula76@outlook.com>
parents:
diff changeset
28 </menu>
prymula <prymula76@outlook.com>
parents:
diff changeset
29 <menu action='InfoMenu'>
prymula <prymula76@outlook.com>
parents:
diff changeset
30 <menuitem action='Help'/>
prymula <prymula76@outlook.com>
parents:
diff changeset
31 <menuitem action='About'/>
prymula <prymula76@outlook.com>
parents:
diff changeset
32 </menu>
prymula <prymula76@outlook.com>
parents:
diff changeset
33 </menubar>
prymula <prymula76@outlook.com>
parents:
diff changeset
34
prymula <prymula76@outlook.com>
parents:
diff changeset
35 </ui>
prymula <prymula76@outlook.com>
parents:
diff changeset
36 """
prymula <prymula76@outlook.com>
parents:
diff changeset
37
prymula <prymula76@outlook.com>
parents:
diff changeset
38 grid = Gtk.Grid()
prymula <prymula76@outlook.com>
parents:
diff changeset
39 file_img_selected=""
prymula <prymula76@outlook.com>
parents:
diff changeset
40 file_label_save=""
prymula <prymula76@outlook.com>
parents:
diff changeset
41 new_pixbuf=""
prymula <prymula76@outlook.com>
parents:
diff changeset
42 list_labels = []
prymula <prymula76@outlook.com>
parents:
diff changeset
43 label_limits = []
prymula <prymula76@outlook.com>
parents:
diff changeset
44 print_limits = []
prymula <prymula76@outlook.com>
parents:
diff changeset
45 #label_selected = ""
prymula <prymula76@outlook.com>
parents:
diff changeset
46 BLANK_W = 1134
prymula <prymula76@outlook.com>
parents:
diff changeset
47 BLANK_H = 496
prymula <prymula76@outlook.com>
parents:
diff changeset
48
prymula <prymula76@outlook.com>
parents:
diff changeset
49
prymula <prymula76@outlook.com>
parents:
diff changeset
50 def get_resource_path(rel_path):
prymula <prymula76@outlook.com>
parents:
diff changeset
51 dir_of_py_file = os.path.dirname(__file__)
prymula <prymula76@outlook.com>
parents:
diff changeset
52 rel_path_to_resource = os.path.join(dir_of_py_file, rel_path)
prymula <prymula76@outlook.com>
parents:
diff changeset
53 abs_path_to_resource = os.path.abspath(rel_path_to_resource)
prymula <prymula76@outlook.com>
parents:
diff changeset
54 return abs_path_to_resource
prymula <prymula76@outlook.com>
parents:
diff changeset
55
prymula <prymula76@outlook.com>
parents:
diff changeset
56 class DialogCompositor(Gtk.Dialog):
prymula <prymula76@outlook.com>
parents:
diff changeset
57 def __init__(self, parent):
prymula <prymula76@outlook.com>
parents:
diff changeset
58 global new_pixbuf
prymula <prymula76@outlook.com>
parents:
diff changeset
59 Gtk.Dialog.__init__(self, title="Kompozytor", transient_for=parent, flags=0)
prymula <prymula76@outlook.com>
parents:
diff changeset
60 self.props.border_width = 20
prymula <prymula76@outlook.com>
parents:
diff changeset
61 self.add_buttons(
prymula <prymula76@outlook.com>
parents:
diff changeset
62 Gtk.STOCK_CANCEL,
prymula <prymula76@outlook.com>
parents:
diff changeset
63 Gtk.ResponseType.CANCEL,
prymula <prymula76@outlook.com>
parents:
diff changeset
64 Gtk.STOCK_SAVE,
prymula <prymula76@outlook.com>
parents:
diff changeset
65 Gtk.ResponseType.OK,
prymula <prymula76@outlook.com>
parents:
diff changeset
66 )
prymula <prymula76@outlook.com>
parents:
diff changeset
67 self.compos = Gtk.Grid()
prymula <prymula76@outlook.com>
parents:
diff changeset
68 file_img_composite=get_resource_path("/usr/share/postagelabels/blank_small.png")
prymula <prymula76@outlook.com>
parents:
diff changeset
69 new_pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
prymula <prymula76@outlook.com>
parents:
diff changeset
70 filename=file_img_composite,
prymula <prymula76@outlook.com>
parents:
diff changeset
71 width=500,
prymula <prymula76@outlook.com>
parents:
diff changeset
72 height=250,
prymula <prymula76@outlook.com>
parents:
diff changeset
73 preserve_aspect_ratio=True)
prymula <prymula76@outlook.com>
parents:
diff changeset
74
prymula <prymula76@outlook.com>
parents:
diff changeset
75 self.add(self.compos)
prymula <prymula76@outlook.com>
parents:
diff changeset
76
prymula <prymula76@outlook.com>
parents:
diff changeset
77 self.compos.set_row_spacing(10)
prymula <prymula76@outlook.com>
parents:
diff changeset
78 self.compos.set_column_spacing(10)
prymula <prymula76@outlook.com>
parents:
diff changeset
79 #self.compos.set_column_homogeneous(True) # rozszerza kontrolke na resztę okna
prymula <prymula76@outlook.com>
parents:
diff changeset
80
prymula <prymula76@outlook.com>
parents:
diff changeset
81 # potrzebne do wyśwetlenia tekstu
prymula <prymula76@outlook.com>
parents:
diff changeset
82 self.surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, new_pixbuf.get_width(), new_pixbuf.get_height())
prymula <prymula76@outlook.com>
parents:
diff changeset
83 self.context = cairo.Context(self.surface)
prymula <prymula76@outlook.com>
parents:
diff changeset
84
prymula <prymula76@outlook.com>
parents:
diff changeset
85 Gdk.cairo_set_source_pixbuf(self.context, new_pixbuf, 0, 0)
prymula <prymula76@outlook.com>
parents:
diff changeset
86 self.context.paint() #paint the pixbuf
prymula <prymula76@outlook.com>
parents:
diff changeset
87
prymula <prymula76@outlook.com>
parents:
diff changeset
88 self.fontsize= 25
prymula <prymula76@outlook.com>
parents:
diff changeset
89
prymula <prymula76@outlook.com>
parents:
diff changeset
90 box = self.get_content_area()
prymula <prymula76@outlook.com>
parents:
diff changeset
91
prymula <prymula76@outlook.com>
parents:
diff changeset
92 self.com_first = Gtk.Image.new_from_pixbuf(new_pixbuf)
prymula <prymula76@outlook.com>
parents:
diff changeset
93 self.compos.attach(self.com_first,0,0,1,3)
prymula <prymula76@outlook.com>
parents:
diff changeset
94
prymula <prymula76@outlook.com>
parents:
diff changeset
95
prymula <prymula76@outlook.com>
parents:
diff changeset
96 self.entry1 = Gtk.Entry()
prymula <prymula76@outlook.com>
parents:
diff changeset
97 self.entry1.set_text("Hello World")
prymula <prymula76@outlook.com>
parents:
diff changeset
98 self.compos.attach(self.entry1,1,0,1,1)
prymula <prymula76@outlook.com>
parents:
diff changeset
99
prymula <prymula76@outlook.com>
parents:
diff changeset
100
prymula <prymula76@outlook.com>
parents:
diff changeset
101 self.entry2 = Gtk.Entry()
prymula <prymula76@outlook.com>
parents:
diff changeset
102 self.entry2.set_text("Hello World")
prymula <prymula76@outlook.com>
parents:
diff changeset
103 self.compos.attach(self.entry2,1,1,1,1)
prymula <prymula76@outlook.com>
parents:
diff changeset
104
prymula <prymula76@outlook.com>
parents:
diff changeset
105 self.entry3 = Gtk.Entry()
prymula <prymula76@outlook.com>
parents:
diff changeset
106 self.entry3.set_text("Hello World")
prymula <prymula76@outlook.com>
parents:
diff changeset
107 self.compos.attach(self.entry3,1,2,1,1)
prymula <prymula76@outlook.com>
parents:
diff changeset
108
prymula <prymula76@outlook.com>
parents:
diff changeset
109 self.entry4 = Gtk.Entry()
prymula <prymula76@outlook.com>
parents:
diff changeset
110 self.entry4.set_text("Hello World")
prymula <prymula76@outlook.com>
parents:
diff changeset
111 self.compos.attach(self.entry4,1,3,1,1)
prymula <prymula76@outlook.com>
parents:
diff changeset
112
prymula <prymula76@outlook.com>
parents:
diff changeset
113 button1 = Gtk.Button.new_with_label("Aktualizuj")
prymula <prymula76@outlook.com>
parents:
diff changeset
114 button1.connect("clicked", self.actualization1)
prymula <prymula76@outlook.com>
parents:
diff changeset
115 self.compos.attach(button1,2,0,1,1)
prymula <prymula76@outlook.com>
parents:
diff changeset
116
prymula <prymula76@outlook.com>
parents:
diff changeset
117 button2 = Gtk.Button.new_with_label("Aktualizuj")
prymula <prymula76@outlook.com>
parents:
diff changeset
118 button2.connect("clicked", self.actualization2)
prymula <prymula76@outlook.com>
parents:
diff changeset
119 self.compos.attach(button2,2,1,1,1)
prymula <prymula76@outlook.com>
parents:
diff changeset
120
prymula <prymula76@outlook.com>
parents:
diff changeset
121 button3 = Gtk.Button.new_with_label("Aktualizuj")
prymula <prymula76@outlook.com>
parents:
diff changeset
122 button3.connect("clicked", self.actualization3)
prymula <prymula76@outlook.com>
parents:
diff changeset
123 self.compos.attach(button3,2,2,1,1)
prymula <prymula76@outlook.com>
parents:
diff changeset
124
prymula <prymula76@outlook.com>
parents:
diff changeset
125 button4 = Gtk.Button.new_with_label("Aktualizuj")
prymula <prymula76@outlook.com>
parents:
diff changeset
126 button4.connect("clicked", self.actualization4)
prymula <prymula76@outlook.com>
parents:
diff changeset
127 self.compos.attach(button4,2,3,1,1)
prymula <prymula76@outlook.com>
parents:
diff changeset
128
prymula <prymula76@outlook.com>
parents:
diff changeset
129
prymula <prymula76@outlook.com>
parents:
diff changeset
130 button_clear = Gtk.Button.new_with_label("Wyczyść")
prymula <prymula76@outlook.com>
parents:
diff changeset
131 button_clear.connect("clicked", self.entry_clear)
prymula <prymula76@outlook.com>
parents:
diff changeset
132 self.compos.attach(button_clear,3,0,1,4)
prymula <prymula76@outlook.com>
parents:
diff changeset
133 box.add(self.compos)
prymula <prymula76@outlook.com>
parents:
diff changeset
134
prymula <prymula76@outlook.com>
parents:
diff changeset
135 self.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
136
prymula <prymula76@outlook.com>
parents:
diff changeset
137 def entry_clear(self, button):
prymula <prymula76@outlook.com>
parents:
diff changeset
138 global new_pixbuf
prymula <prymula76@outlook.com>
parents:
diff changeset
139 file_img_selected=get_resource_path("/usr/share/postagelabels/blank_small.png")
prymula <prymula76@outlook.com>
parents:
diff changeset
140 new_pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
prymula <prymula76@outlook.com>
parents:
diff changeset
141 filename=file_img_selected,
prymula <prymula76@outlook.com>
parents:
diff changeset
142 width=500,
prymula <prymula76@outlook.com>
parents:
diff changeset
143 height=250,
prymula <prymula76@outlook.com>
parents:
diff changeset
144 preserve_aspect_ratio=True)
prymula <prymula76@outlook.com>
parents:
diff changeset
145
prymula <prymula76@outlook.com>
parents:
diff changeset
146
prymula <prymula76@outlook.com>
parents:
diff changeset
147 if self.com_first != None:
prymula <prymula76@outlook.com>
parents:
diff changeset
148 self.compos.remove(self.com_first)
prymula <prymula76@outlook.com>
parents:
diff changeset
149 self.com_first=None
prymula <prymula76@outlook.com>
parents:
diff changeset
150 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
151 self.compos.remove(self.com_new)
prymula <prymula76@outlook.com>
parents:
diff changeset
152
prymula <prymula76@outlook.com>
parents:
diff changeset
153 # czyści etykiete
prymula <prymula76@outlook.com>
parents:
diff changeset
154 self.surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, new_pixbuf.get_width(), new_pixbuf.get_height())
prymula <prymula76@outlook.com>
parents:
diff changeset
155 self.context = cairo.Context(self.surface)
prymula <prymula76@outlook.com>
parents:
diff changeset
156 Gdk.cairo_set_source_pixbuf(self.context, new_pixbuf, 0, 0)
prymula <prymula76@outlook.com>
parents:
diff changeset
157 self.context.paint() #paint the pixbuf
prymula <prymula76@outlook.com>
parents:
diff changeset
158
prymula <prymula76@outlook.com>
parents:
diff changeset
159
prymula <prymula76@outlook.com>
parents:
diff changeset
160 self.com_new = Gtk.Image.new_from_pixbuf(new_pixbuf)
prymula <prymula76@outlook.com>
parents:
diff changeset
161 self.compos.attach(self.com_new,0,0,1,3)
prymula <prymula76@outlook.com>
parents:
diff changeset
162
prymula <prymula76@outlook.com>
parents:
diff changeset
163 self.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
164
prymula <prymula76@outlook.com>
parents:
diff changeset
165
prymula <prymula76@outlook.com>
parents:
diff changeset
166 def actualization1(self, button):
prymula <prymula76@outlook.com>
parents:
diff changeset
167 global new_pixbuf
prymula <prymula76@outlook.com>
parents:
diff changeset
168 self.context.move_to(15, 20+self.fontsize)
prymula <prymula76@outlook.com>
parents:
diff changeset
169 self.context.set_font_size(self.fontsize)
prymula <prymula76@outlook.com>
parents:
diff changeset
170 self.context.set_source_rgba(0,0,0,1)
prymula <prymula76@outlook.com>
parents:
diff changeset
171 self.context.show_text(self.entry1.get_text())
prymula <prymula76@outlook.com>
parents:
diff changeset
172
prymula <prymula76@outlook.com>
parents:
diff changeset
173 #get the resulting pixbuf
prymula <prymula76@outlook.com>
parents:
diff changeset
174 self.surface= self.context.get_target()
prymula <prymula76@outlook.com>
parents:
diff changeset
175 new_pixbuf= Gdk.pixbuf_get_from_surface(self.surface, 0, 0, self.surface.get_width(), self.surface.get_height())
prymula <prymula76@outlook.com>
parents:
diff changeset
176
prymula <prymula76@outlook.com>
parents:
diff changeset
177 if self.com_first != None:
prymula <prymula76@outlook.com>
parents:
diff changeset
178 self.compos.remove(self.com_first)
prymula <prymula76@outlook.com>
parents:
diff changeset
179 self.com_first=None
prymula <prymula76@outlook.com>
parents:
diff changeset
180 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
181 self.compos.remove(self.com_new)
prymula <prymula76@outlook.com>
parents:
diff changeset
182
prymula <prymula76@outlook.com>
parents:
diff changeset
183
prymula <prymula76@outlook.com>
parents:
diff changeset
184 self.com_new = Gtk.Image.new_from_pixbuf(new_pixbuf)
prymula <prymula76@outlook.com>
parents:
diff changeset
185 self.compos.attach(self.com_new,0,0,1,3)
prymula <prymula76@outlook.com>
parents:
diff changeset
186
prymula <prymula76@outlook.com>
parents:
diff changeset
187 self.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
188
prymula <prymula76@outlook.com>
parents:
diff changeset
189 def actualization2(self, button):
prymula <prymula76@outlook.com>
parents:
diff changeset
190 global new_pixbuf
prymula <prymula76@outlook.com>
parents:
diff changeset
191 self.context.move_to(15, 20+self.fontsize+self.fontsize+15)
prymula <prymula76@outlook.com>
parents:
diff changeset
192 self.context.set_font_size(self.fontsize)
prymula <prymula76@outlook.com>
parents:
diff changeset
193 self.context.set_source_rgba(0,0,0,1)
prymula <prymula76@outlook.com>
parents:
diff changeset
194 self.context.show_text(self.entry2.get_text())
prymula <prymula76@outlook.com>
parents:
diff changeset
195
prymula <prymula76@outlook.com>
parents:
diff changeset
196 #get the resulting pixbuf
prymula <prymula76@outlook.com>
parents:
diff changeset
197 self.surface= self.context.get_target()
prymula <prymula76@outlook.com>
parents:
diff changeset
198 new_pixbuf= Gdk.pixbuf_get_from_surface(self.surface, 0, 0, self.surface.get_width(), self.surface.get_height())
prymula <prymula76@outlook.com>
parents:
diff changeset
199
prymula <prymula76@outlook.com>
parents:
diff changeset
200 if self.com_first != None:
prymula <prymula76@outlook.com>
parents:
diff changeset
201 self.compos.remove(self.com_first)
prymula <prymula76@outlook.com>
parents:
diff changeset
202 self.com_first=None
prymula <prymula76@outlook.com>
parents:
diff changeset
203 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
204 self.compos.remove(self.com_new)
prymula <prymula76@outlook.com>
parents:
diff changeset
205
prymula <prymula76@outlook.com>
parents:
diff changeset
206
prymula <prymula76@outlook.com>
parents:
diff changeset
207 self.com_new = Gtk.Image.new_from_pixbuf(new_pixbuf)
prymula <prymula76@outlook.com>
parents:
diff changeset
208 self.compos.attach(self.com_new,0,0,1,3)
prymula <prymula76@outlook.com>
parents:
diff changeset
209
prymula <prymula76@outlook.com>
parents:
diff changeset
210 self.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
211 def actualization3(self, button):
prymula <prymula76@outlook.com>
parents:
diff changeset
212 global new_pixbuf
prymula <prymula76@outlook.com>
parents:
diff changeset
213 self.context.move_to(15, 20+self.fontsize+self.fontsize+self.fontsize+30)
prymula <prymula76@outlook.com>
parents:
diff changeset
214 self.context.set_font_size(self.fontsize)
prymula <prymula76@outlook.com>
parents:
diff changeset
215 self.context.set_source_rgba(0,0,0,1)
prymula <prymula76@outlook.com>
parents:
diff changeset
216 self.context.show_text(self.entry3.get_text())
prymula <prymula76@outlook.com>
parents:
diff changeset
217
prymula <prymula76@outlook.com>
parents:
diff changeset
218 #get the resulting pixbuf
prymula <prymula76@outlook.com>
parents:
diff changeset
219 self.surface= self.context.get_target()
prymula <prymula76@outlook.com>
parents:
diff changeset
220 new_pixbuf= Gdk.pixbuf_get_from_surface(self.surface, 0, 0, self.surface.get_width(), self.surface.get_height())
prymula <prymula76@outlook.com>
parents:
diff changeset
221
prymula <prymula76@outlook.com>
parents:
diff changeset
222 if self.com_first != None:
prymula <prymula76@outlook.com>
parents:
diff changeset
223 self.compos.remove(self.com_first)
prymula <prymula76@outlook.com>
parents:
diff changeset
224 self.com_first=None
prymula <prymula76@outlook.com>
parents:
diff changeset
225 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
226 self.compos.remove(self.com_new)
prymula <prymula76@outlook.com>
parents:
diff changeset
227
prymula <prymula76@outlook.com>
parents:
diff changeset
228
prymula <prymula76@outlook.com>
parents:
diff changeset
229 self.com_new = Gtk.Image.new_from_pixbuf(new_pixbuf)
prymula <prymula76@outlook.com>
parents:
diff changeset
230 self.compos.attach(self.com_new,0,0,1,3)
prymula <prymula76@outlook.com>
parents:
diff changeset
231
prymula <prymula76@outlook.com>
parents:
diff changeset
232 self.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
233
prymula <prymula76@outlook.com>
parents:
diff changeset
234 def actualization4(self, button):
prymula <prymula76@outlook.com>
parents:
diff changeset
235 global new_pixbuf
prymula <prymula76@outlook.com>
parents:
diff changeset
236 self.context.move_to(15, 20+self.fontsize+self.fontsize+self.fontsize+self.fontsize+50)
prymula <prymula76@outlook.com>
parents:
diff changeset
237 self.context.set_font_size(self.fontsize)
prymula <prymula76@outlook.com>
parents:
diff changeset
238 self.context.set_source_rgba(0,0,0,1)
prymula <prymula76@outlook.com>
parents:
diff changeset
239 self.context.show_text(self.entry4.get_text())
prymula <prymula76@outlook.com>
parents:
diff changeset
240
prymula <prymula76@outlook.com>
parents:
diff changeset
241 #get the resulting pixbuf
prymula <prymula76@outlook.com>
parents:
diff changeset
242 self.surface= self.context.get_target()
prymula <prymula76@outlook.com>
parents:
diff changeset
243 new_pixbuf= Gdk.pixbuf_get_from_surface(self.surface, 0, 0, self.surface.get_width(), self.surface.get_height())
prymula <prymula76@outlook.com>
parents:
diff changeset
244
prymula <prymula76@outlook.com>
parents:
diff changeset
245 if self.com_first != None:
prymula <prymula76@outlook.com>
parents:
diff changeset
246 self.compos.remove(self.com_first)
prymula <prymula76@outlook.com>
parents:
diff changeset
247 self.com_first=None
prymula <prymula76@outlook.com>
parents:
diff changeset
248 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
249 self.compos.remove(self.com_new)
prymula <prymula76@outlook.com>
parents:
diff changeset
250
prymula <prymula76@outlook.com>
parents:
diff changeset
251
prymula <prymula76@outlook.com>
parents:
diff changeset
252 self.com_new = Gtk.Image.new_from_pixbuf(new_pixbuf)
prymula <prymula76@outlook.com>
parents:
diff changeset
253 self.compos.attach(self.com_new,0,0,1,3)
prymula <prymula76@outlook.com>
parents:
diff changeset
254
prymula <prymula76@outlook.com>
parents:
diff changeset
255 self.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
256
prymula <prymula76@outlook.com>
parents:
diff changeset
257
prymula <prymula76@outlook.com>
parents:
diff changeset
258 class DialogHelp(Gtk.Dialog):
prymula <prymula76@outlook.com>
parents:
diff changeset
259 def __init__(self, parent):
prymula <prymula76@outlook.com>
parents:
diff changeset
260 Gtk.Dialog.__init__(self, title="Pomoc", transient_for=parent, flags=0)
prymula <prymula76@outlook.com>
parents:
diff changeset
261 self.props.border_width = 20
prymula <prymula76@outlook.com>
parents:
diff changeset
262 self.add_buttons(
prymula <prymula76@outlook.com>
parents:
diff changeset
263 Gtk.STOCK_OK, Gtk.ResponseType.OK
prymula <prymula76@outlook.com>
parents:
diff changeset
264 )
prymula <prymula76@outlook.com>
parents:
diff changeset
265
prymula <prymula76@outlook.com>
parents:
diff changeset
266 self.set_default_size(150, 100)
prymula <prymula76@outlook.com>
parents:
diff changeset
267 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")
prymula <prymula76@outlook.com>
parents:
diff changeset
268 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.")
prymula <prymula76@outlook.com>
parents:
diff changeset
269 box = self.get_content_area()
prymula <prymula76@outlook.com>
parents:
diff changeset
270 box.add(label1)
prymula <prymula76@outlook.com>
parents:
diff changeset
271 box.add(label2)
prymula <prymula76@outlook.com>
parents:
diff changeset
272 self.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
273
prymula <prymula76@outlook.com>
parents:
diff changeset
274 class DialogAbout(Gtk.Dialog):
prymula <prymula76@outlook.com>
parents:
diff changeset
275 def __init__(self, parent):
prymula <prymula76@outlook.com>
parents:
diff changeset
276 Gtk.Dialog.__init__(self, title="O Programie", transient_for=parent, flags=0)
prymula <prymula76@outlook.com>
parents:
diff changeset
277 self.props.border_width = 20
prymula <prymula76@outlook.com>
parents:
diff changeset
278 self.add_buttons(
prymula <prymula76@outlook.com>
parents:
diff changeset
279 Gtk.STOCK_OK, Gtk.ResponseType.OK
prymula <prymula76@outlook.com>
parents:
diff changeset
280 )
prymula <prymula76@outlook.com>
parents:
diff changeset
281
prymula <prymula76@outlook.com>
parents:
diff changeset
282 self.set_default_size(150, 100)
prymula <prymula76@outlook.com>
parents:
diff changeset
283
prymula <prymula76@outlook.com>
parents:
diff changeset
284 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")
prymula <prymula76@outlook.com>
parents:
diff changeset
285
prymula <prymula76@outlook.com>
parents:
diff changeset
286 box = self.get_content_area()
prymula <prymula76@outlook.com>
parents:
diff changeset
287 box.add(label)
prymula <prymula76@outlook.com>
parents:
diff changeset
288
prymula <prymula76@outlook.com>
parents:
diff changeset
289 button = Gtk.LinkButton("http://www.prp.xlx.pl", label="Strona Domowa")
prymula <prymula76@outlook.com>
parents:
diff changeset
290 box.add(button)
prymula <prymula76@outlook.com>
parents:
diff changeset
291
prymula <prymula76@outlook.com>
parents:
diff changeset
292 self.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
293
prymula <prymula76@outlook.com>
parents:
diff changeset
294
prymula <prymula76@outlook.com>
parents:
diff changeset
295
prymula <prymula76@outlook.com>
parents:
diff changeset
296
prymula <prymula76@outlook.com>
parents:
diff changeset
297 class DialogMessage(Gtk.Dialog):
prymula <prymula76@outlook.com>
parents:
diff changeset
298 def __init__(self, parent):
prymula <prymula76@outlook.com>
parents:
diff changeset
299 super().__init__(title="Błąd zaznaczenia", transient_for=parent, flags=0)
prymula <prymula76@outlook.com>
parents:
diff changeset
300 self.add_buttons(
prymula <prymula76@outlook.com>
parents:
diff changeset
301 Gtk.STOCK_OK, Gtk.ResponseType.OK
prymula <prymula76@outlook.com>
parents:
diff changeset
302
prymula <prymula76@outlook.com>
parents:
diff changeset
303 )
prymula <prymula76@outlook.com>
parents:
diff changeset
304
prymula <prymula76@outlook.com>
parents:
diff changeset
305 self.set_default_size(150, 100)
prymula <prymula76@outlook.com>
parents:
diff changeset
306
prymula <prymula76@outlook.com>
parents:
diff changeset
307 label = Gtk.Label(label="Powinieneś najperw zaznaczyć etykiete,\nz listy dostępnych etykiet.")
prymula <prymula76@outlook.com>
parents:
diff changeset
308
prymula <prymula76@outlook.com>
parents:
diff changeset
309 box = self.get_content_area()
prymula <prymula76@outlook.com>
parents:
diff changeset
310 box.add(label)
prymula <prymula76@outlook.com>
parents:
diff changeset
311 self.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
312
prymula <prymula76@outlook.com>
parents:
diff changeset
313
prymula <prymula76@outlook.com>
parents:
diff changeset
314
prymula <prymula76@outlook.com>
parents:
diff changeset
315
prymula <prymula76@outlook.com>
parents:
diff changeset
316 class FileChooserIMG(Gtk.Window):
prymula <prymula76@outlook.com>
parents:
diff changeset
317 def __init__(self):
prymula <prymula76@outlook.com>
parents:
diff changeset
318 Gtk.Window.__init__(self, title="Wybór plików graficznych")
prymula <prymula76@outlook.com>
parents:
diff changeset
319 global file_img_selected
prymula <prymula76@outlook.com>
parents:
diff changeset
320
prymula <prymula76@outlook.com>
parents:
diff changeset
321 dialog = Gtk.FileChooserDialog(title="Please choose a file", parent=self, action=Gtk.FileChooserAction.OPEN)
prymula <prymula76@outlook.com>
parents:
diff changeset
322 dialog.add_buttons(
prymula <prymula76@outlook.com>
parents:
diff changeset
323 Gtk.STOCK_CANCEL,
prymula <prymula76@outlook.com>
parents:
diff changeset
324 Gtk.ResponseType.CANCEL,
prymula <prymula76@outlook.com>
parents:
diff changeset
325 Gtk.STOCK_OPEN,
prymula <prymula76@outlook.com>
parents:
diff changeset
326 Gtk.ResponseType.OK,
prymula <prymula76@outlook.com>
parents:
diff changeset
327 )
prymula <prymula76@outlook.com>
parents:
diff changeset
328
prymula <prymula76@outlook.com>
parents:
diff changeset
329 self.add_filters(dialog)
prymula <prymula76@outlook.com>
parents:
diff changeset
330
prymula <prymula76@outlook.com>
parents:
diff changeset
331 response = dialog.run()
prymula <prymula76@outlook.com>
parents:
diff changeset
332 if response == Gtk.ResponseType.OK:
prymula <prymula76@outlook.com>
parents:
diff changeset
333 print("Open clicked")
prymula <prymula76@outlook.com>
parents:
diff changeset
334 print("File selected: " + dialog.get_filename())
prymula <prymula76@outlook.com>
parents:
diff changeset
335 file_img_selected=dialog.get_filename()
prymula <prymula76@outlook.com>
parents:
diff changeset
336 list_labels.append(file_img_selected)
prymula <prymula76@outlook.com>
parents:
diff changeset
337 elif response == Gtk.ResponseType.CANCEL:
prymula <prymula76@outlook.com>
parents:
diff changeset
338 print("Cancel clicked")
prymula <prymula76@outlook.com>
parents:
diff changeset
339
prymula <prymula76@outlook.com>
parents:
diff changeset
340 dialog.destroy()
prymula <prymula76@outlook.com>
parents:
diff changeset
341
prymula <prymula76@outlook.com>
parents:
diff changeset
342 def add_filters(self, dialog):
prymula <prymula76@outlook.com>
parents:
diff changeset
343 filter_png = Gtk.FileFilter()
prymula <prymula76@outlook.com>
parents:
diff changeset
344 filter_png.set_name("Pliki PNG")
prymula <prymula76@outlook.com>
parents:
diff changeset
345 filter_png.add_mime_type("image/png")
prymula <prymula76@outlook.com>
parents:
diff changeset
346 dialog.add_filter(filter_png)
prymula <prymula76@outlook.com>
parents:
diff changeset
347
prymula <prymula76@outlook.com>
parents:
diff changeset
348 filter_jpeg = Gtk.FileFilter()
prymula <prymula76@outlook.com>
parents:
diff changeset
349 filter_jpeg.set_name("Pliki JPEG")
prymula <prymula76@outlook.com>
parents:
diff changeset
350 filter_jpeg.add_mime_type("image/jpeg")
prymula <prymula76@outlook.com>
parents:
diff changeset
351 dialog.add_filter(filter_jpeg)
prymula <prymula76@outlook.com>
parents:
diff changeset
352
prymula <prymula76@outlook.com>
parents:
diff changeset
353
prymula <prymula76@outlook.com>
parents:
diff changeset
354
prymula <prymula76@outlook.com>
parents:
diff changeset
355
prymula <prymula76@outlook.com>
parents:
diff changeset
356 class FileChooserLabel(Gtk.Window):
prymula <prymula76@outlook.com>
parents:
diff changeset
357 def __init__(self, this):
prymula <prymula76@outlook.com>
parents:
diff changeset
358 global glob_liststore
prymula <prymula76@outlook.com>
parents:
diff changeset
359 Gtk.Window.__init__(self, title="Zapis etykiety")
prymula <prymula76@outlook.com>
parents:
diff changeset
360 global file_label_save
prymula <prymula76@outlook.com>
parents:
diff changeset
361
prymula <prymula76@outlook.com>
parents:
diff changeset
362 dialog = Gtk.FileChooserDialog(title="Please choose a file", parent=self, action=Gtk.FileChooserAction.SAVE)
prymula <prymula76@outlook.com>
parents:
diff changeset
363 dialog.add_buttons(
prymula <prymula76@outlook.com>
parents:
diff changeset
364 Gtk.STOCK_CANCEL,
prymula <prymula76@outlook.com>
parents:
diff changeset
365 Gtk.ResponseType.CANCEL,
prymula <prymula76@outlook.com>
parents:
diff changeset
366 Gtk.STOCK_SAVE,
prymula <prymula76@outlook.com>
parents:
diff changeset
367 Gtk.ResponseType.OK,
prymula <prymula76@outlook.com>
parents:
diff changeset
368 )
prymula <prymula76@outlook.com>
parents:
diff changeset
369
prymula <prymula76@outlook.com>
parents:
diff changeset
370 self.add_filters(dialog)
prymula <prymula76@outlook.com>
parents:
diff changeset
371
prymula <prymula76@outlook.com>
parents:
diff changeset
372 response = dialog.run()
prymula <prymula76@outlook.com>
parents:
diff changeset
373 if response == Gtk.ResponseType.OK:
prymula <prymula76@outlook.com>
parents:
diff changeset
374 print("Open clicked")
prymula <prymula76@outlook.com>
parents:
diff changeset
375 print("File selected: " + dialog.get_filename())
prymula <prymula76@outlook.com>
parents:
diff changeset
376 file_label_save=dialog.get_filename()
prymula <prymula76@outlook.com>
parents:
diff changeset
377 pixbuf2 = new_pixbuf.scale_simple(1134, 496, GdkPixbuf.InterpType.BILINEAR)
prymula <prymula76@outlook.com>
parents:
diff changeset
378 pixbuf2.savev(file_label_save,"png", ["quality"], ["100"])
prymula <prymula76@outlook.com>
parents:
diff changeset
379 this.available_labels(file_label_save)
prymula <prymula76@outlook.com>
parents:
diff changeset
380
prymula <prymula76@outlook.com>
parents:
diff changeset
381
prymula <prymula76@outlook.com>
parents:
diff changeset
382 elif response == Gtk.ResponseType.CANCEL:
prymula <prymula76@outlook.com>
parents:
diff changeset
383 print("Cancel clicked")
prymula <prymula76@outlook.com>
parents:
diff changeset
384
prymula <prymula76@outlook.com>
parents:
diff changeset
385 dialog.destroy()
prymula <prymula76@outlook.com>
parents:
diff changeset
386
prymula <prymula76@outlook.com>
parents:
diff changeset
387 def add_filters(self, dialog):
prymula <prymula76@outlook.com>
parents:
diff changeset
388 filter_png = Gtk.FileFilter()
prymula <prymula76@outlook.com>
parents:
diff changeset
389 filter_png.set_name("Pliki PNG")
prymula <prymula76@outlook.com>
parents:
diff changeset
390 filter_png.add_mime_type("image/png")
prymula <prymula76@outlook.com>
parents:
diff changeset
391 dialog.add_filter(filter_png)
prymula <prymula76@outlook.com>
parents:
diff changeset
392 """
prymula <prymula76@outlook.com>
parents:
diff changeset
393 filter_jpeg = Gtk.FileFilter()
prymula <prymula76@outlook.com>
parents:
diff changeset
394 filter_jpeg.set_name("Pliki JPEG")
prymula <prymula76@outlook.com>
parents:
diff changeset
395 filter_jpeg.add_mime_type("image/jpeg")
prymula <prymula76@outlook.com>
parents:
diff changeset
396 dialog.add_filter(filter_jpeg)
prymula <prymula76@outlook.com>
parents:
diff changeset
397 """
prymula <prymula76@outlook.com>
parents:
diff changeset
398
prymula <prymula76@outlook.com>
parents:
diff changeset
399
prymula <prymula76@outlook.com>
parents:
diff changeset
400
prymula <prymula76@outlook.com>
parents:
diff changeset
401
prymula <prymula76@outlook.com>
parents:
diff changeset
402
prymula <prymula76@outlook.com>
parents:
diff changeset
403
prymula <prymula76@outlook.com>
parents:
diff changeset
404
prymula <prymula76@outlook.com>
parents:
diff changeset
405 class MyWindow(Gtk.Window):
prymula <prymula76@outlook.com>
parents:
diff changeset
406
prymula <prymula76@outlook.com>
parents:
diff changeset
407 def __init__(self):
prymula <prymula76@outlook.com>
parents:
diff changeset
408 super().__init__()
prymula <prymula76@outlook.com>
parents:
diff changeset
409
prymula <prymula76@outlook.com>
parents:
diff changeset
410 self.init_ui()
prymula <prymula76@outlook.com>
parents:
diff changeset
411
prymula <prymula76@outlook.com>
parents:
diff changeset
412
prymula <prymula76@outlook.com>
parents:
diff changeset
413 def refresh_label_view(self):
prymula <prymula76@outlook.com>
parents:
diff changeset
414
prymula <prymula76@outlook.com>
parents:
diff changeset
415 if self.image2 != None:
prymula <prymula76@outlook.com>
parents:
diff changeset
416 grid.remove(self.image2)
prymula <prymula76@outlook.com>
parents:
diff changeset
417 self.image2=None
prymula <prymula76@outlook.com>
parents:
diff changeset
418 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
419 grid.remove(self.image_new)
prymula <prymula76@outlook.com>
parents:
diff changeset
420
prymula <prymula76@outlook.com>
parents:
diff changeset
421
prymula <prymula76@outlook.com>
parents:
diff changeset
422 pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
prymula <prymula76@outlook.com>
parents:
diff changeset
423 filename=self.label_selected,
prymula <prymula76@outlook.com>
parents:
diff changeset
424 width=500,
prymula <prymula76@outlook.com>
parents:
diff changeset
425 height=250,
prymula <prymula76@outlook.com>
parents:
diff changeset
426 preserve_aspect_ratio=True)
prymula <prymula76@outlook.com>
parents:
diff changeset
427
prymula <prymula76@outlook.com>
parents:
diff changeset
428 self.image_new = Gtk.Image.new_from_pixbuf(pixbuf)
prymula <prymula76@outlook.com>
parents:
diff changeset
429 grid.attach(self.image_new,0,1,1,1)
prymula <prymula76@outlook.com>
parents:
diff changeset
430
prymula <prymula76@outlook.com>
parents:
diff changeset
431 self.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
432
prymula <prymula76@outlook.com>
parents:
diff changeset
433 def on_menu_file_new_template(self, widget):
prymula <prymula76@outlook.com>
parents:
diff changeset
434
prymula <prymula76@outlook.com>
parents:
diff changeset
435 n = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
436 file_img_selected=get_resource_path("/usr/share/postagelabels/blank_small.png")
prymula <prymula76@outlook.com>
parents:
diff changeset
437 pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
prymula <prymula76@outlook.com>
parents:
diff changeset
438 filename=file_img_selected,
prymula <prymula76@outlook.com>
parents:
diff changeset
439 width=250,
prymula <prymula76@outlook.com>
parents:
diff changeset
440 height=117, #125,
prymula <prymula76@outlook.com>
parents:
diff changeset
441 preserve_aspect_ratio=True)
prymula <prymula76@outlook.com>
parents:
diff changeset
442
prymula <prymula76@outlook.com>
parents:
diff changeset
443
prymula <prymula76@outlook.com>
parents:
diff changeset
444 for l in label_limits:
prymula <prymula76@outlook.com>
parents:
diff changeset
445
prymula <prymula76@outlook.com>
parents:
diff changeset
446 print ("IMAGE2: "+str(pixbuf))
prymula <prymula76@outlook.com>
parents:
diff changeset
447 if pixbuf is not None:
prymula <prymula76@outlook.com>
parents:
diff changeset
448 self.image_template[n].set_from_pixbuf(pixbuf)
prymula <prymula76@outlook.com>
parents:
diff changeset
449 print_limits[n][2] = None
prymula <prymula76@outlook.com>
parents:
diff changeset
450
prymula <prymula76@outlook.com>
parents:
diff changeset
451
prymula <prymula76@outlook.com>
parents:
diff changeset
452
prymula <prymula76@outlook.com>
parents:
diff changeset
453 n += 1
prymula <prymula76@outlook.com>
parents:
diff changeset
454 self.show_all() # najprawdopodobnie wymagane po pakietowaniu
prymula <prymula76@outlook.com>
parents:
diff changeset
455
prymula <prymula76@outlook.com>
parents:
diff changeset
456 def on_menu_file_load_img_generic(self, widget):
prymula <prymula76@outlook.com>
parents:
diff changeset
457 global grid
prymula <prymula76@outlook.com>
parents:
diff changeset
458 filename=FileChooserIMG()
prymula <prymula76@outlook.com>
parents:
diff changeset
459
prymula <prymula76@outlook.com>
parents:
diff changeset
460 if len(file_img_selected) != 0:
prymula <prymula76@outlook.com>
parents:
diff changeset
461
prymula <prymula76@outlook.com>
parents:
diff changeset
462 if self.image2 != None:
prymula <prymula76@outlook.com>
parents:
diff changeset
463 grid.remove(self.image2)
prymula <prymula76@outlook.com>
parents:
diff changeset
464 self.image2=None
prymula <prymula76@outlook.com>
parents:
diff changeset
465 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
466 grid.remove(self.image_new)
prymula <prymula76@outlook.com>
parents:
diff changeset
467
prymula <prymula76@outlook.com>
parents:
diff changeset
468
prymula <prymula76@outlook.com>
parents:
diff changeset
469 pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
prymula <prymula76@outlook.com>
parents:
diff changeset
470 filename=file_img_selected,
prymula <prymula76@outlook.com>
parents:
diff changeset
471 width=500,
prymula <prymula76@outlook.com>
parents:
diff changeset
472 height=250,
prymula <prymula76@outlook.com>
parents:
diff changeset
473 preserve_aspect_ratio=True)
prymula <prymula76@outlook.com>
parents:
diff changeset
474
prymula <prymula76@outlook.com>
parents:
diff changeset
475 self.image_new = Gtk.Image.new_from_pixbuf(pixbuf)
prymula <prymula76@outlook.com>
parents:
diff changeset
476
prymula <prymula76@outlook.com>
parents:
diff changeset
477 grid.attach(self.image_new,0,1,1,1)
prymula <prymula76@outlook.com>
parents:
diff changeset
478
prymula <prymula76@outlook.com>
parents:
diff changeset
479
prymula <prymula76@outlook.com>
parents:
diff changeset
480 self.scrolled_window.remove(self.treeview)
prymula <prymula76@outlook.com>
parents:
diff changeset
481 grid.remove(self.scrolled_window)
prymula <prymula76@outlook.com>
parents:
diff changeset
482 self.liststore = Gtk.ListStore(str, str)
prymula <prymula76@outlook.com>
parents:
diff changeset
483
prymula <prymula76@outlook.com>
parents:
diff changeset
484 self.treeview.remove_column(self.column_text)
prymula <prymula76@outlook.com>
parents:
diff changeset
485
prymula <prymula76@outlook.com>
parents:
diff changeset
486 for o in list_labels:
prymula <prymula76@outlook.com>
parents:
diff changeset
487 self.liststore.append([o,""])
prymula <prymula76@outlook.com>
parents:
diff changeset
488
prymula <prymula76@outlook.com>
parents:
diff changeset
489 self.scrolled_window = Gtk.ScrolledWindow ()
prymula <prymula76@outlook.com>
parents:
diff changeset
490 self.scrolled_window.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
prymula <prymula76@outlook.com>
parents:
diff changeset
491
prymula <prymula76@outlook.com>
parents:
diff changeset
492 self.treeview = Gtk.TreeView(model=self.liststore)
prymula <prymula76@outlook.com>
parents:
diff changeset
493
prymula <prymula76@outlook.com>
parents:
diff changeset
494 self.renderer_text = Gtk.CellRendererText()
prymula <prymula76@outlook.com>
parents:
diff changeset
495 self.column_text = Gtk.TreeViewColumn("Dostępne etykiety", self.renderer_text, text=0)
prymula <prymula76@outlook.com>
parents:
diff changeset
496 self.treeview.append_column(self.column_text)
prymula <prymula76@outlook.com>
parents:
diff changeset
497
prymula <prymula76@outlook.com>
parents:
diff changeset
498 self.treeview.connect("button_release_event", self.mouse_selected)
prymula <prymula76@outlook.com>
parents:
diff changeset
499
prymula <prymula76@outlook.com>
parents:
diff changeset
500 self.scrolled_window.add (self.treeview)
prymula <prymula76@outlook.com>
parents:
diff changeset
501 grid.attach(self.scrolled_window,0,2,1,6)
prymula <prymula76@outlook.com>
parents:
diff changeset
502
prymula <prymula76@outlook.com>
parents:
diff changeset
503 self.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
504
prymula <prymula76@outlook.com>
parents:
diff changeset
505 def on_menu_composite_generic(self, widget):
prymula <prymula76@outlook.com>
parents:
diff changeset
506 dialog = DialogCompositor(self)
prymula <prymula76@outlook.com>
parents:
diff changeset
507 response = dialog.run()
prymula <prymula76@outlook.com>
parents:
diff changeset
508
prymula <prymula76@outlook.com>
parents:
diff changeset
509 if response == Gtk.ResponseType.OK:
prymula <prymula76@outlook.com>
parents:
diff changeset
510 print("Save clicked")
prymula <prymula76@outlook.com>
parents:
diff changeset
511 dialog_file_label=FileChooserLabel(self)
prymula <prymula76@outlook.com>
parents:
diff changeset
512 elif response == Gtk.ResponseType.CANCEL:
prymula <prymula76@outlook.com>
parents:
diff changeset
513 print("Cancel clicked")
prymula <prymula76@outlook.com>
parents:
diff changeset
514
prymula <prymula76@outlook.com>
parents:
diff changeset
515 dialog.destroy()
prymula <prymula76@outlook.com>
parents:
diff changeset
516
prymula <prymula76@outlook.com>
parents:
diff changeset
517 def on_menu_file_quit(self, widget):
prymula <prymula76@outlook.com>
parents:
diff changeset
518 Gtk.main_quit()
prymula <prymula76@outlook.com>
parents:
diff changeset
519
prymula <prymula76@outlook.com>
parents:
diff changeset
520 def on_menu_help(self, widget):
prymula <prymula76@outlook.com>
parents:
diff changeset
521 dialog = DialogHelp(self)
prymula <prymula76@outlook.com>
parents:
diff changeset
522 response = dialog.run()
prymula <prymula76@outlook.com>
parents:
diff changeset
523
prymula <prymula76@outlook.com>
parents:
diff changeset
524 dialog.destroy()
prymula <prymula76@outlook.com>
parents:
diff changeset
525
prymula <prymula76@outlook.com>
parents:
diff changeset
526 def on_menu_about(self, widget):
prymula <prymula76@outlook.com>
parents:
diff changeset
527 dialog = DialogAbout(self)
prymula <prymula76@outlook.com>
parents:
diff changeset
528 response = dialog.run()
prymula <prymula76@outlook.com>
parents:
diff changeset
529
prymula <prymula76@outlook.com>
parents:
diff changeset
530 dialog.destroy()
prymula <prymula76@outlook.com>
parents:
diff changeset
531
prymula <prymula76@outlook.com>
parents:
diff changeset
532
prymula <prymula76@outlook.com>
parents:
diff changeset
533 def add_info_menu_actions(self, action_group):
prymula <prymula76@outlook.com>
parents:
diff changeset
534 action_info_menu = Gtk.Action(name="InfoMenu", label="Info")
prymula <prymula76@outlook.com>
parents:
diff changeset
535 action_group.add_action(action_info_menu)
prymula <prymula76@outlook.com>
parents:
diff changeset
536
prymula <prymula76@outlook.com>
parents:
diff changeset
537 action_new = Gtk.Action(
prymula <prymula76@outlook.com>
parents:
diff changeset
538 name="Help",
prymula <prymula76@outlook.com>
parents:
diff changeset
539 label="Pomoc",
prymula <prymula76@outlook.com>
parents:
diff changeset
540 tooltip="Create a new file",
prymula <prymula76@outlook.com>
parents:
diff changeset
541 )
prymula <prymula76@outlook.com>
parents:
diff changeset
542 action_new.connect("activate", self.on_menu_help)
prymula <prymula76@outlook.com>
parents:
diff changeset
543 action_group.add_action_with_accel(action_new, None)
prymula <prymula76@outlook.com>
parents:
diff changeset
544
prymula <prymula76@outlook.com>
parents:
diff changeset
545 action_new = Gtk.Action(
prymula <prymula76@outlook.com>
parents:
diff changeset
546 name="About",
prymula <prymula76@outlook.com>
parents:
diff changeset
547 label="O Programie",
prymula <prymula76@outlook.com>
parents:
diff changeset
548 tooltip="Create a new file",
prymula <prymula76@outlook.com>
parents:
diff changeset
549 )
prymula <prymula76@outlook.com>
parents:
diff changeset
550 action_new.connect("activate", self.on_menu_about)
prymula <prymula76@outlook.com>
parents:
diff changeset
551 action_group.add_action_with_accel(action_new, None)
prymula <prymula76@outlook.com>
parents:
diff changeset
552
prymula <prymula76@outlook.com>
parents:
diff changeset
553 def add_file_menu_actions(self, action_group):
prymula <prymula76@outlook.com>
parents:
diff changeset
554 action_filemenu = Gtk.Action(name="FileMenu", label="Plik")
prymula <prymula76@outlook.com>
parents:
diff changeset
555 action_group.add_action(action_filemenu)
prymula <prymula76@outlook.com>
parents:
diff changeset
556
prymula <prymula76@outlook.com>
parents:
diff changeset
557 action_fileloadmenu = Gtk.Action(name="FileLoad", stock_id=Gtk.STOCK_NEW)
prymula <prymula76@outlook.com>
parents:
diff changeset
558 action_group.add_action(action_fileloadmenu)
prymula <prymula76@outlook.com>
parents:
diff changeset
559
prymula <prymula76@outlook.com>
parents:
diff changeset
560 action_new = Gtk.Action(
prymula <prymula76@outlook.com>
parents:
diff changeset
561 name="LoadImg",
prymula <prymula76@outlook.com>
parents:
diff changeset
562 label="Załaduj etykiete",
prymula <prymula76@outlook.com>
parents:
diff changeset
563 tooltip="Wczytuje etykiete",
prymula <prymula76@outlook.com>
parents:
diff changeset
564 )
prymula <prymula76@outlook.com>
parents:
diff changeset
565 action_new.connect("activate", self.on_menu_file_load_img_generic)
prymula <prymula76@outlook.com>
parents:
diff changeset
566 action_group.add_action_with_accel(action_new, None)
prymula <prymula76@outlook.com>
parents:
diff changeset
567
prymula <prymula76@outlook.com>
parents:
diff changeset
568
prymula <prymula76@outlook.com>
parents:
diff changeset
569 action_new = Gtk.Action(
prymula <prymula76@outlook.com>
parents:
diff changeset
570 name="NewTemplate",
prymula <prymula76@outlook.com>
parents:
diff changeset
571 label="Nowy szablon",
prymula <prymula76@outlook.com>
parents:
diff changeset
572 tooltip="Tworzy szablon na nowo",
prymula <prymula76@outlook.com>
parents:
diff changeset
573 )
prymula <prymula76@outlook.com>
parents:
diff changeset
574 action_new.connect("activate", self.on_menu_file_new_template)
prymula <prymula76@outlook.com>
parents:
diff changeset
575 action_group.add_action_with_accel(action_new, None)
prymula <prymula76@outlook.com>
parents:
diff changeset
576
prymula <prymula76@outlook.com>
parents:
diff changeset
577
prymula <prymula76@outlook.com>
parents:
diff changeset
578 action_new = Gtk.Action(
prymula <prymula76@outlook.com>
parents:
diff changeset
579 name="Composite",
prymula <prymula76@outlook.com>
parents:
diff changeset
580 label="Kompozytor",
prymula <prymula76@outlook.com>
parents:
diff changeset
581 tooltip="Tworzy nową etykiete",
prymula <prymula76@outlook.com>
parents:
diff changeset
582 )
prymula <prymula76@outlook.com>
parents:
diff changeset
583 action_new.connect("activate", self.on_menu_composite_generic)
prymula <prymula76@outlook.com>
parents:
diff changeset
584 action_group.add_action_with_accel(action_new, None)
prymula <prymula76@outlook.com>
parents:
diff changeset
585
prymula <prymula76@outlook.com>
parents:
diff changeset
586
prymula <prymula76@outlook.com>
parents:
diff changeset
587 action_print = Gtk.Action(name="FilePrint", stock_id=Gtk.STOCK_PRINT)
prymula <prymula76@outlook.com>
parents:
diff changeset
588 action_print.connect("activate", self.print_image)
prymula <prymula76@outlook.com>
parents:
diff changeset
589 action_group.add_action(action_print)
prymula <prymula76@outlook.com>
parents:
diff changeset
590
prymula <prymula76@outlook.com>
parents:
diff changeset
591
prymula <prymula76@outlook.com>
parents:
diff changeset
592 action_filequit = Gtk.Action(name="FileQuit", stock_id=Gtk.STOCK_QUIT)
prymula <prymula76@outlook.com>
parents:
diff changeset
593 action_filequit.connect("activate", self.on_menu_file_quit)
prymula <prymula76@outlook.com>
parents:
diff changeset
594 action_group.add_action(action_filequit)
prymula <prymula76@outlook.com>
parents:
diff changeset
595
prymula <prymula76@outlook.com>
parents:
diff changeset
596
prymula <prymula76@outlook.com>
parents:
diff changeset
597
prymula <prymula76@outlook.com>
parents:
diff changeset
598 # tworzy menu bar
prymula <prymula76@outlook.com>
parents:
diff changeset
599 def create_ui_manager(self):
prymula <prymula76@outlook.com>
parents:
diff changeset
600 uimanager = Gtk.UIManager()
prymula <prymula76@outlook.com>
parents:
diff changeset
601
prymula <prymula76@outlook.com>
parents:
diff changeset
602 # Throws exception if something went wrong
prymula <prymula76@outlook.com>
parents:
diff changeset
603 uimanager.add_ui_from_string(UI_INFO)
prymula <prymula76@outlook.com>
parents:
diff changeset
604
prymula <prymula76@outlook.com>
parents:
diff changeset
605 # Add the accelerator group to the toplevel window
prymula <prymula76@outlook.com>
parents:
diff changeset
606 accelgroup = uimanager.get_accel_group()
prymula <prymula76@outlook.com>
parents:
diff changeset
607 self.add_accel_group(accelgroup)
prymula <prymula76@outlook.com>
parents:
diff changeset
608 return uimanager
prymula <prymula76@outlook.com>
parents:
diff changeset
609
prymula <prymula76@outlook.com>
parents:
diff changeset
610
prymula <prymula76@outlook.com>
parents:
diff changeset
611
prymula <prymula76@outlook.com>
parents:
diff changeset
612 def mouse_selected(self, tv, event):
prymula <prymula76@outlook.com>
parents:
diff changeset
613
prymula <prymula76@outlook.com>
parents:
diff changeset
614 if event.button == 1:
prymula <prymula76@outlook.com>
parents:
diff changeset
615
prymula <prymula76@outlook.com>
parents:
diff changeset
616 # Begin added code
prymula <prymula76@outlook.com>
parents:
diff changeset
617 pthinfo = self.treeview.get_path_at_pos(event.x, event.y)
prymula <prymula76@outlook.com>
parents:
diff changeset
618 if pthinfo != None:
prymula <prymula76@outlook.com>
parents:
diff changeset
619 path,col,cellx,celly = pthinfo
prymula <prymula76@outlook.com>
parents:
diff changeset
620 self.treeview.grab_focus()
prymula <prymula76@outlook.com>
parents:
diff changeset
621 self.treeview.set_cursor(path,col,0)
prymula <prymula76@outlook.com>
parents:
diff changeset
622 # End added code
prymula <prymula76@outlook.com>
parents:
diff changeset
623
prymula <prymula76@outlook.com>
parents:
diff changeset
624 selection = self.treeview.get_selection()
prymula <prymula76@outlook.com>
parents:
diff changeset
625 (model, iter) = selection.get_selected()
prymula <prymula76@outlook.com>
parents:
diff changeset
626 print(model[iter][0])
prymula <prymula76@outlook.com>
parents:
diff changeset
627 self.label_selected = model[iter][0]
prymula <prymula76@outlook.com>
parents:
diff changeset
628
prymula <prymula76@outlook.com>
parents:
diff changeset
629 self.refresh_label_view()
prymula <prymula76@outlook.com>
parents:
diff changeset
630
prymula <prymula76@outlook.com>
parents:
diff changeset
631
prymula <prymula76@outlook.com>
parents:
diff changeset
632 def onclick_in_pixbuf (self, box, event):
prymula <prymula76@outlook.com>
parents:
diff changeset
633 if event.button == 1:
prymula <prymula76@outlook.com>
parents:
diff changeset
634 try:
prymula <prymula76@outlook.com>
parents:
diff changeset
635 print ("\nKliknieto na pozycji")
prymula <prymula76@outlook.com>
parents:
diff changeset
636 print (event.x, event.y)
prymula <prymula76@outlook.com>
parents:
diff changeset
637 print ("\n")
prymula <prymula76@outlook.com>
parents:
diff changeset
638 e = [int(event.x), int(event.y)]
prymula <prymula76@outlook.com>
parents:
diff changeset
639 n = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
640
prymula <prymula76@outlook.com>
parents:
diff changeset
641 pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
prymula <prymula76@outlook.com>
parents:
diff changeset
642 filename=self.label_selected,
prymula <prymula76@outlook.com>
parents:
diff changeset
643 width=250,
prymula <prymula76@outlook.com>
parents:
diff changeset
644 height=117, #125,
prymula <prymula76@outlook.com>
parents:
diff changeset
645 preserve_aspect_ratio=True)
prymula <prymula76@outlook.com>
parents:
diff changeset
646
prymula <prymula76@outlook.com>
parents:
diff changeset
647
prymula <prymula76@outlook.com>
parents:
diff changeset
648 for l in label_limits:
prymula <prymula76@outlook.com>
parents:
diff changeset
649
prymula <prymula76@outlook.com>
parents:
diff changeset
650 x, y = l[:]
prymula <prymula76@outlook.com>
parents:
diff changeset
651 e_x, e_y = e[:]
prymula <prymula76@outlook.com>
parents:
diff changeset
652
prymula <prymula76@outlook.com>
parents:
diff changeset
653 if e_x >= x and e_y >= y and e_x <= x+250 and e_y <= y+117:
prymula <prymula76@outlook.com>
parents:
diff changeset
654 if pixbuf is not None:
prymula <prymula76@outlook.com>
parents:
diff changeset
655 self.image_template[n].set_from_pixbuf(pixbuf)
prymula <prymula76@outlook.com>
parents:
diff changeset
656 print_limits[n][2] = self.label_selected
prymula <prymula76@outlook.com>
parents:
diff changeset
657
prymula <prymula76@outlook.com>
parents:
diff changeset
658 break
prymula <prymula76@outlook.com>
parents:
diff changeset
659 n += 1
prymula <prymula76@outlook.com>
parents:
diff changeset
660 except AttributeError:
prymula <prymula76@outlook.com>
parents:
diff changeset
661
prymula <prymula76@outlook.com>
parents:
diff changeset
662 dialog = DialogMessage(self)
prymula <prymula76@outlook.com>
parents:
diff changeset
663 response = dialog.run()
prymula <prymula76@outlook.com>
parents:
diff changeset
664
prymula <prymula76@outlook.com>
parents:
diff changeset
665
prymula <prymula76@outlook.com>
parents:
diff changeset
666 dialog.destroy()
prymula <prymula76@outlook.com>
parents:
diff changeset
667 if event.button == 3:
prymula <prymula76@outlook.com>
parents:
diff changeset
668
prymula <prymula76@outlook.com>
parents:
diff changeset
669
prymula <prymula76@outlook.com>
parents:
diff changeset
670 e = [int(event.x), int(event.y)]
prymula <prymula76@outlook.com>
parents:
diff changeset
671 n = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
672
prymula <prymula76@outlook.com>
parents:
diff changeset
673 file_img_selected=get_resource_path("/usr/share/postagelabels/blank_small.png")
prymula <prymula76@outlook.com>
parents:
diff changeset
674 pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
prymula <prymula76@outlook.com>
parents:
diff changeset
675 filename=file_img_selected,
prymula <prymula76@outlook.com>
parents:
diff changeset
676 width=250,
prymula <prymula76@outlook.com>
parents:
diff changeset
677 height=117, #125,
prymula <prymula76@outlook.com>
parents:
diff changeset
678 preserve_aspect_ratio=True)
prymula <prymula76@outlook.com>
parents:
diff changeset
679
prymula <prymula76@outlook.com>
parents:
diff changeset
680
prymula <prymula76@outlook.com>
parents:
diff changeset
681 for l in label_limits:
prymula <prymula76@outlook.com>
parents:
diff changeset
682
prymula <prymula76@outlook.com>
parents:
diff changeset
683 x, y = l[:]
prymula <prymula76@outlook.com>
parents:
diff changeset
684 e_x, e_y = e[:]
prymula <prymula76@outlook.com>
parents:
diff changeset
685
prymula <prymula76@outlook.com>
parents:
diff changeset
686 if e_x >= x and e_y >= y and e_x <= x+250 and e_y <= y+117:
prymula <prymula76@outlook.com>
parents:
diff changeset
687 print ("IMAGE2: "+str(pixbuf))
prymula <prymula76@outlook.com>
parents:
diff changeset
688 if pixbuf is not None:
prymula <prymula76@outlook.com>
parents:
diff changeset
689 self.image_template[n].set_from_pixbuf(pixbuf)
prymula <prymula76@outlook.com>
parents:
diff changeset
690 print_limits[n][2] = None
prymula <prymula76@outlook.com>
parents:
diff changeset
691
prymula <prymula76@outlook.com>
parents:
diff changeset
692
prymula <prymula76@outlook.com>
parents:
diff changeset
693 break
prymula <prymula76@outlook.com>
parents:
diff changeset
694 n += 1
prymula <prymula76@outlook.com>
parents:
diff changeset
695 self.show_all() # najprawdopodobnie wymagane po pakietowaniu
prymula <prymula76@outlook.com>
parents:
diff changeset
696
prymula <prymula76@outlook.com>
parents:
diff changeset
697 def on_mouse_move_in_pixbuf (self, box, event):
prymula <prymula76@outlook.com>
parents:
diff changeset
698 e = [int(event.x), int(event.y)]
prymula <prymula76@outlook.com>
parents:
diff changeset
699 n = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
700 for l in label_limits:
prymula <prymula76@outlook.com>
parents:
diff changeset
701
prymula <prymula76@outlook.com>
parents:
diff changeset
702 x, y = l[:]
prymula <prymula76@outlook.com>
parents:
diff changeset
703 e_x, e_y = e[:]
prymula <prymula76@outlook.com>
parents:
diff changeset
704
prymula <prymula76@outlook.com>
parents:
diff changeset
705 if e_x >= x and e_y >= y and e_x <= x+200 and e_y <= y+92:
prymula <prymula76@outlook.com>
parents:
diff changeset
706 pass
prymula <prymula76@outlook.com>
parents:
diff changeset
707
prymula <prymula76@outlook.com>
parents:
diff changeset
708 # dnae dla wydruku
prymula <prymula76@outlook.com>
parents:
diff changeset
709 def set_print_limits(self):
prymula <prymula76@outlook.com>
parents:
diff changeset
710 start_x = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
711 start_y = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
712 end_x = BLANK_W * 2 #1234*2
prymula <prymula76@outlook.com>
parents:
diff changeset
713 end_y = BLANK_H * 6 #3508
prymula <prymula76@outlook.com>
parents:
diff changeset
714 cols = 2
prymula <prymula76@outlook.com>
parents:
diff changeset
715 rows = 6
prymula <prymula76@outlook.com>
parents:
diff changeset
716 width = BLANK_W #1234
prymula <prymula76@outlook.com>
parents:
diff changeset
717 height = BLANK_H #585
prymula <prymula76@outlook.com>
parents:
diff changeset
718
prymula <prymula76@outlook.com>
parents:
diff changeset
719 for j in range (start_y, end_y, height):
prymula <prymula76@outlook.com>
parents:
diff changeset
720 for i in range (start_x, end_x, width):
prymula <prymula76@outlook.com>
parents:
diff changeset
721 print_limits.append([i, j, None])
prymula <prymula76@outlook.com>
parents:
diff changeset
722
prymula <prymula76@outlook.com>
parents:
diff changeset
723 print ("PRINT LIMIST")
prymula <prymula76@outlook.com>
parents:
diff changeset
724 print (print_limits)
prymula <prymula76@outlook.com>
parents:
diff changeset
725
prymula <prymula76@outlook.com>
parents:
diff changeset
726
prymula <prymula76@outlook.com>
parents:
diff changeset
727 # dane dla siatki
prymula <prymula76@outlook.com>
parents:
diff changeset
728 def set_label_limits(self):
prymula <prymula76@outlook.com>
parents:
diff changeset
729 start_x = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
730 start_y = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
731 end_x = 500
prymula <prymula76@outlook.com>
parents:
diff changeset
732 end_y = 104 * 6 #117 * 6 #700
prymula <prymula76@outlook.com>
parents:
diff changeset
733 cols = 2
prymula <prymula76@outlook.com>
parents:
diff changeset
734 rows = 6
prymula <prymula76@outlook.com>
parents:
diff changeset
735 width = 250
prymula <prymula76@outlook.com>
parents:
diff changeset
736 height = 104 #117
prymula <prymula76@outlook.com>
parents:
diff changeset
737
prymula <prymula76@outlook.com>
parents:
diff changeset
738 for j in range (start_y, end_y, height):
prymula <prymula76@outlook.com>
parents:
diff changeset
739 for i in range (start_x, end_x, width):
prymula <prymula76@outlook.com>
parents:
diff changeset
740 label_limits.append([i, j])
prymula <prymula76@outlook.com>
parents:
diff changeset
741
prymula <prymula76@outlook.com>
parents:
diff changeset
742
prymula <prymula76@outlook.com>
parents:
diff changeset
743 def print_page(self, operation=None, context=None, page_nr=None):
prymula <prymula76@outlook.com>
parents:
diff changeset
744
prymula <prymula76@outlook.com>
parents:
diff changeset
745 ctx = context.get_cairo_context()
prymula <prymula76@outlook.com>
parents:
diff changeset
746
prymula <prymula76@outlook.com>
parents:
diff changeset
747 # make cairo ImageSurface from the png file
prymula <prymula76@outlook.com>
parents:
diff changeset
748 surface = cairo.ImageSurface.create_from_png('/tmp/postagelabels.png')
prymula <prymula76@outlook.com>
parents:
diff changeset
749
prymula <prymula76@outlook.com>
parents:
diff changeset
750 #ctx.set_operator(cairo.OPERATOR_SOURCE)
prymula <prymula76@outlook.com>
parents:
diff changeset
751 ctx.set_source_surface(surface)
prymula <prymula76@outlook.com>
parents:
diff changeset
752 ctx.paint ()
prymula <prymula76@outlook.com>
parents:
diff changeset
753 #ctx.set_operator(cairo.OPERATOR_OVER)
prymula <prymula76@outlook.com>
parents:
diff changeset
754 os.remove("/tmp/postagelabels.png");
prymula <prymula76@outlook.com>
parents:
diff changeset
755
prymula <prymula76@outlook.com>
parents:
diff changeset
756
prymula <prymula76@outlook.com>
parents:
diff changeset
757
prymula <prymula76@outlook.com>
parents:
diff changeset
758 #page = self.doc.get_page(page_nr)
prymula <prymula76@outlook.com>
parents:
diff changeset
759 #page.render(ctx)
prymula <prymula76@outlook.com>
parents:
diff changeset
760
prymula <prymula76@outlook.com>
parents:
diff changeset
761
prymula <prymula76@outlook.com>
parents:
diff changeset
762
prymula <prymula76@outlook.com>
parents:
diff changeset
763
prymula <prymula76@outlook.com>
parents:
diff changeset
764
prymula <prymula76@outlook.com>
parents:
diff changeset
765 def print_image(self, widget):
prymula <prymula76@outlook.com>
parents:
diff changeset
766 print ("PRINT LIMITS")
prymula <prymula76@outlook.com>
parents:
diff changeset
767 print (print_limits)
prymula <prymula76@outlook.com>
parents:
diff changeset
768
prymula <prymula76@outlook.com>
parents:
diff changeset
769 page_width = 210
prymula <prymula76@outlook.com>
parents:
diff changeset
770 page_height = 297
prymula <prymula76@outlook.com>
parents:
diff changeset
771 #page_margin_top = 20
prymula <prymula76@outlook.com>
parents:
diff changeset
772 dpi = 600
prymula <prymula76@outlook.com>
parents:
diff changeset
773 #_mm_dpi = 72 / 25.4
prymula <prymula76@outlook.com>
parents:
diff changeset
774
prymula <prymula76@outlook.com>
parents:
diff changeset
775
prymula <prymula76@outlook.com>
parents:
diff changeset
776
prymula <prymula76@outlook.com>
parents:
diff changeset
777
prymula <prymula76@outlook.com>
parents:
diff changeset
778 pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size('/usr/share/postagelabels/szablon.png', 2480, 3508)
prymula <prymula76@outlook.com>
parents:
diff changeset
779
prymula <prymula76@outlook.com>
parents:
diff changeset
780 for i in range (12):
prymula <prymula76@outlook.com>
parents:
diff changeset
781 if print_limits[i][2] != None:
prymula <prymula76@outlook.com>
parents:
diff changeset
782
prymula <prymula76@outlook.com>
parents:
diff changeset
783 if i%2 == 1:
prymula <prymula76@outlook.com>
parents:
diff changeset
784 center_beam = 24
prymula <prymula76@outlook.com>
parents:
diff changeset
785 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
786 center_beam = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
787
prymula <prymula76@outlook.com>
parents:
diff changeset
788 label = GdkPixbuf.Pixbuf.new_from_file_at_size(print_limits[i][2], BLANK_W, BLANK_H)
prymula <prymula76@outlook.com>
parents:
diff changeset
789 #self.freeze_child_notify()
prymula <prymula76@outlook.com>
parents:
diff changeset
790 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)
prymula <prymula76@outlook.com>
parents:
diff changeset
791 #self.thaw_child_notify()
prymula <prymula76@outlook.com>
parents:
diff changeset
792
prymula <prymula76@outlook.com>
parents:
diff changeset
793 # z orginalnymi wielkościami nie chce drukowac
prymula <prymula76@outlook.com>
parents:
diff changeset
794 pixbuf2 = pixbuf.scale_simple(600, 855, GdkPixbuf.InterpType.BILINEAR)
prymula <prymula76@outlook.com>
parents:
diff changeset
795
prymula <prymula76@outlook.com>
parents:
diff changeset
796 pixbuf2.savev("/tmp/postagelabels.png","png", ["quality"], ["100"])
prymula <prymula76@outlook.com>
parents:
diff changeset
797 """
prymula <prymula76@outlook.com>
parents:
diff changeset
798 paper_size = Gtk.PaperSize.new_custom("1.0x", "2480 x 3508", 2480, 3508, Gtk.Unit.POINTS)
prymula <prymula76@outlook.com>
parents:
diff changeset
799
prymula <prymula76@outlook.com>
parents:
diff changeset
800 page_setup = Gtk.PageSetup()
prymula <prymula76@outlook.com>
parents:
diff changeset
801 page_setup.set_paper_size(paper_size)
prymula <prymula76@outlook.com>
parents:
diff changeset
802 pd = Gtk.PrintOperation()
prymula <prymula76@outlook.com>
parents:
diff changeset
803 #pd.set_embed_page_setup(True)
prymula <prymula76@outlook.com>
parents:
diff changeset
804 pd.set_default_page_setup(page_setup)
prymula <prymula76@outlook.com>
parents:
diff changeset
805 #pd.set_unit(Gtk.Unit.POINTS)
prymula <prymula76@outlook.com>
parents:
diff changeset
806 pd.set_n_pages(1)
prymula <prymula76@outlook.com>
parents:
diff changeset
807 pd.connect("draw_page", self.print_page)
prymula <prymula76@outlook.com>
parents:
diff changeset
808 result = pd.run(Gtk.PrintOperationAction.PRINT_DIALOG, None) # window zamisat None
prymula <prymula76@outlook.com>
parents:
diff changeset
809 print(result) # handle errors etc.
prymula <prymula76@outlook.com>
parents:
diff changeset
810 """
prymula <prymula76@outlook.com>
parents:
diff changeset
811
prymula <prymula76@outlook.com>
parents:
diff changeset
812
prymula <prymula76@outlook.com>
parents:
diff changeset
813 #ps= Gtk.PaperSize.new_custom("1.0x", "2480 x 3508", 2480, 3508, Gtk.Unit.POINTS)
prymula <prymula76@outlook.com>
parents:
diff changeset
814
prymula <prymula76@outlook.com>
parents:
diff changeset
815 ps = Gtk.PaperSize.new_custom("1.0x", "cc", page_width, page_height, Gtk.Unit.MM)
prymula <prymula76@outlook.com>
parents:
diff changeset
816 print_settings = Gtk.PrintSettings()
prymula <prymula76@outlook.com>
parents:
diff changeset
817 print_settings.set_resolution(dpi)
prymula <prymula76@outlook.com>
parents:
diff changeset
818
prymula <prymula76@outlook.com>
parents:
diff changeset
819 page_setup = Gtk.PageSetup()
prymula <prymula76@outlook.com>
parents:
diff changeset
820 page_setup.set_paper_size(ps)
prymula <prymula76@outlook.com>
parents:
diff changeset
821 page_setup.set_bottom_margin(0.0, Gtk.Unit.MM)
prymula <prymula76@outlook.com>
parents:
diff changeset
822 page_setup.set_left_margin(0.0, Gtk.Unit.MM)
prymula <prymula76@outlook.com>
parents:
diff changeset
823 page_setup.set_right_margin(0.0, Gtk.Unit.MM)
prymula <prymula76@outlook.com>
parents:
diff changeset
824 page_setup.set_top_margin(0.0, Gtk.Unit.MM)
prymula <prymula76@outlook.com>
parents:
diff changeset
825 page_setup.set_orientation(Gtk.PageOrientation.PORTRAIT)
prymula <prymula76@outlook.com>
parents:
diff changeset
826
prymula <prymula76@outlook.com>
parents:
diff changeset
827
prymula <prymula76@outlook.com>
parents:
diff changeset
828 print_operation = Gtk.PrintOperation()
prymula <prymula76@outlook.com>
parents:
diff changeset
829 print_operation.set_n_pages(1)
prymula <prymula76@outlook.com>
parents:
diff changeset
830 print_operation.set_default_page_setup(page_setup)
prymula <prymula76@outlook.com>
parents:
diff changeset
831 print_operation.set_print_settings(print_settings)
prymula <prymula76@outlook.com>
parents:
diff changeset
832 print_operation.connect("draw_page", self.print_page)
prymula <prymula76@outlook.com>
parents:
diff changeset
833 #print_operation.set_export_filename("example.pdf")
prymula <prymula76@outlook.com>
parents:
diff changeset
834
prymula <prymula76@outlook.com>
parents:
diff changeset
835 result = print_operation.run(Gtk.PrintOperationAction.PRINT_DIALOG, None) # window zamisat None
prymula <prymula76@outlook.com>
parents:
diff changeset
836
prymula <prymula76@outlook.com>
parents:
diff changeset
837 #result = print_operation.run(Gtk.PrintOperationAction.PREVIEW, None)
prymula <prymula76@outlook.com>
parents:
diff changeset
838 print(result)
prymula <prymula76@outlook.com>
parents:
diff changeset
839
prymula <prymula76@outlook.com>
parents:
diff changeset
840 def available_labels(self, name):
prymula <prymula76@outlook.com>
parents:
diff changeset
841
prymula <prymula76@outlook.com>
parents:
diff changeset
842 self.scrolled_window.remove(self.treeview)
prymula <prymula76@outlook.com>
parents:
diff changeset
843 grid.remove(self.scrolled_window)
prymula <prymula76@outlook.com>
parents:
diff changeset
844 self.liststore = Gtk.ListStore(str, str)
prymula <prymula76@outlook.com>
parents:
diff changeset
845
prymula <prymula76@outlook.com>
parents:
diff changeset
846 self.treeview.remove_column(self.column_text)
prymula <prymula76@outlook.com>
parents:
diff changeset
847
prymula <prymula76@outlook.com>
parents:
diff changeset
848 list_labels.append(name)
prymula <prymula76@outlook.com>
parents:
diff changeset
849 for o in list_labels:
prymula <prymula76@outlook.com>
parents:
diff changeset
850 self.liststore.append([o,""])
prymula <prymula76@outlook.com>
parents:
diff changeset
851
prymula <prymula76@outlook.com>
parents:
diff changeset
852 self.scrolled_window = Gtk.ScrolledWindow ()
prymula <prymula76@outlook.com>
parents:
diff changeset
853 self.scrolled_window.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
prymula <prymula76@outlook.com>
parents:
diff changeset
854
prymula <prymula76@outlook.com>
parents:
diff changeset
855 self.treeview = Gtk.TreeView(model=self.liststore)
prymula <prymula76@outlook.com>
parents:
diff changeset
856
prymula <prymula76@outlook.com>
parents:
diff changeset
857 self.renderer_text = Gtk.CellRendererText()
prymula <prymula76@outlook.com>
parents:
diff changeset
858 self.column_text = Gtk.TreeViewColumn("Dostępne etykiety", self.renderer_text, text=0)
prymula <prymula76@outlook.com>
parents:
diff changeset
859 self.treeview.append_column(self.column_text)
prymula <prymula76@outlook.com>
parents:
diff changeset
860
prymula <prymula76@outlook.com>
parents:
diff changeset
861 self.treeview.connect("button_release_event", self.mouse_selected)
prymula <prymula76@outlook.com>
parents:
diff changeset
862
prymula <prymula76@outlook.com>
parents:
diff changeset
863 self.scrolled_window.add (self.treeview)
prymula <prymula76@outlook.com>
parents:
diff changeset
864 grid.attach(self.scrolled_window,0,2,1,6)
prymula <prymula76@outlook.com>
parents:
diff changeset
865
prymula <prymula76@outlook.com>
parents:
diff changeset
866 self.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
867
prymula <prymula76@outlook.com>
parents:
diff changeset
868
prymula <prymula76@outlook.com>
parents:
diff changeset
869 def init_ui(self):
prymula <prymula76@outlook.com>
parents:
diff changeset
870 global grid
prymula <prymula76@outlook.com>
parents:
diff changeset
871
prymula <prymula76@outlook.com>
parents:
diff changeset
872
prymula <prymula76@outlook.com>
parents:
diff changeset
873
prymula <prymula76@outlook.com>
parents:
diff changeset
874 self.image_new=None
prymula <prymula76@outlook.com>
parents:
diff changeset
875 self.props.border_width = 20
prymula <prymula76@outlook.com>
parents:
diff changeset
876
prymula <prymula76@outlook.com>
parents:
diff changeset
877 self.add(grid)
prymula <prymula76@outlook.com>
parents:
diff changeset
878
prymula <prymula76@outlook.com>
parents:
diff changeset
879 grid.set_row_spacing(10)
prymula <prymula76@outlook.com>
parents:
diff changeset
880 grid.set_column_spacing(10)
prymula <prymula76@outlook.com>
parents:
diff changeset
881 grid.set_column_homogeneous(True) # rozszerza kontrolke z utworami na resztę okna
prymula <prymula76@outlook.com>
parents:
diff changeset
882
prymula <prymula76@outlook.com>
parents:
diff changeset
883 action_group = Gtk.ActionGroup(name="my_actions")
prymula <prymula76@outlook.com>
parents:
diff changeset
884
prymula <prymula76@outlook.com>
parents:
diff changeset
885 self.add_file_menu_actions(action_group)
prymula <prymula76@outlook.com>
parents:
diff changeset
886 self.add_info_menu_actions(action_group)
prymula <prymula76@outlook.com>
parents:
diff changeset
887
prymula <prymula76@outlook.com>
parents:
diff changeset
888 uimanager = self.create_ui_manager()
prymula <prymula76@outlook.com>
parents:
diff changeset
889 uimanager.insert_action_group(action_group)
prymula <prymula76@outlook.com>
parents:
diff changeset
890
prymula <prymula76@outlook.com>
parents:
diff changeset
891 menubar = uimanager.get_widget("/MenuBar")
prymula <prymula76@outlook.com>
parents:
diff changeset
892 box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
prymula <prymula76@outlook.com>
parents:
diff changeset
893 box.pack_start(menubar, False, False, 0)
prymula <prymula76@outlook.com>
parents:
diff changeset
894
prymula <prymula76@outlook.com>
parents:
diff changeset
895
prymula <prymula76@outlook.com>
parents:
diff changeset
896 grid.attach(box, 0, 0, 2, 1)
prymula <prymula76@outlook.com>
parents:
diff changeset
897
prymula <prymula76@outlook.com>
parents:
diff changeset
898
prymula <prymula76@outlook.com>
parents:
diff changeset
899
prymula <prymula76@outlook.com>
parents:
diff changeset
900 event_box = Gtk.EventBox ()
prymula <prymula76@outlook.com>
parents:
diff changeset
901 event_box.connect ('button-press-event', self.onclick_in_pixbuf)
prymula <prymula76@outlook.com>
parents:
diff changeset
902 event_box.connect("motion-notify-event", self.on_mouse_move_in_pixbuf)
prymula <prymula76@outlook.com>
parents:
diff changeset
903 event_box.add_events(Gdk.EventMask.POINTER_MOTION_MASK)
prymula <prymula76@outlook.com>
parents:
diff changeset
904
prymula <prymula76@outlook.com>
parents:
diff changeset
905 self.set_label_limits()
prymula <prymula76@outlook.com>
parents:
diff changeset
906 self.set_print_limits()
prymula <prymula76@outlook.com>
parents:
diff changeset
907 frame = Gtk.Frame()
prymula <prymula76@outlook.com>
parents:
diff changeset
908
prymula <prymula76@outlook.com>
parents:
diff changeset
909
prymula <prymula76@outlook.com>
parents:
diff changeset
910 file_img_selected=get_resource_path("/usr/share/postagelabels/blank_small.png")
prymula <prymula76@outlook.com>
parents:
diff changeset
911 pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
prymula <prymula76@outlook.com>
parents:
diff changeset
912 filename=file_img_selected,
prymula <prymula76@outlook.com>
parents:
diff changeset
913 width=250,
prymula <prymula76@outlook.com>
parents:
diff changeset
914 height=117, #125
prymula <prymula76@outlook.com>
parents:
diff changeset
915 preserve_aspect_ratio=True)
prymula <prymula76@outlook.com>
parents:
diff changeset
916
prymula <prymula76@outlook.com>
parents:
diff changeset
917
prymula <prymula76@outlook.com>
parents:
diff changeset
918 self.all_img_template = Gtk.Grid()
prymula <prymula76@outlook.com>
parents:
diff changeset
919
prymula <prymula76@outlook.com>
parents:
diff changeset
920 self.image_template = []
prymula <prymula76@outlook.com>
parents:
diff changeset
921 self.image_template= [0 for i in range(12)]
prymula <prymula76@outlook.com>
parents:
diff changeset
922
prymula <prymula76@outlook.com>
parents:
diff changeset
923
prymula <prymula76@outlook.com>
parents:
diff changeset
924 left = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
925 top = 1
prymula <prymula76@outlook.com>
parents:
diff changeset
926 top_next=False
prymula <prymula76@outlook.com>
parents:
diff changeset
927 multiplier = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
928 n_multi = 1;
prymula <prymula76@outlook.com>
parents:
diff changeset
929 first = False
prymula <prymula76@outlook.com>
parents:
diff changeset
930 n = 2
prymula <prymula76@outlook.com>
parents:
diff changeset
931 for i in range(12):
prymula <prymula76@outlook.com>
parents:
diff changeset
932 print ("left: "+str(left)+" top: "+str(top))
prymula <prymula76@outlook.com>
parents:
diff changeset
933
prymula <prymula76@outlook.com>
parents:
diff changeset
934 if left == 2:
prymula <prymula76@outlook.com>
parents:
diff changeset
935 left = 0;
prymula <prymula76@outlook.com>
parents:
diff changeset
936 n_multi += 1
prymula <prymula76@outlook.com>
parents:
diff changeset
937 print ("multi: " +str(n_multi)+" %"+ str(n_multi%4))
prymula <prymula76@outlook.com>
parents:
diff changeset
938 if n_multi%2== 0:
prymula <prymula76@outlook.com>
parents:
diff changeset
939 if first == False:
prymula <prymula76@outlook.com>
parents:
diff changeset
940 multiplier = 1
prymula <prymula76@outlook.com>
parents:
diff changeset
941 first = True
prymula <prymula76@outlook.com>
parents:
diff changeset
942 multiplier += n
prymula <prymula76@outlook.com>
parents:
diff changeset
943 n *= 2
prymula <prymula76@outlook.com>
parents:
diff changeset
944 self.image_template[i] = Gtk.Image.new_from_pixbuf(pixbuf)
prymula <prymula76@outlook.com>
parents:
diff changeset
945 self.all_img_template.attach(self.image_template[i], left, top+multiplier, 1 , top+multiplier)
prymula <prymula76@outlook.com>
parents:
diff changeset
946 left += 1
prymula <prymula76@outlook.com>
parents:
diff changeset
947 if top_next == False:
prymula <prymula76@outlook.com>
parents:
diff changeset
948 top_next = True
prymula <prymula76@outlook.com>
parents:
diff changeset
949 pass
prymula <prymula76@outlook.com>
parents:
diff changeset
950 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
951 top_next = False
prymula <prymula76@outlook.com>
parents:
diff changeset
952 top +=1
prymula <prymula76@outlook.com>
parents:
diff changeset
953
prymula <prymula76@outlook.com>
parents:
diff changeset
954 event_box.add(self.all_img_template)
prymula <prymula76@outlook.com>
parents:
diff changeset
955
prymula <prymula76@outlook.com>
parents:
diff changeset
956
prymula <prymula76@outlook.com>
parents:
diff changeset
957 frame.add(event_box)
prymula <prymula76@outlook.com>
parents:
diff changeset
958 grid.attach(frame,1,1,1,6)
prymula <prymula76@outlook.com>
parents:
diff changeset
959
prymula <prymula76@outlook.com>
parents:
diff changeset
960
prymula <prymula76@outlook.com>
parents:
diff changeset
961
prymula <prymula76@outlook.com>
parents:
diff changeset
962 # powiększenie etykiety po lewej stronie
prymula <prymula76@outlook.com>
parents:
diff changeset
963 file_img_selected=get_resource_path("/usr/share/postagelabels/blank_small.png")
prymula <prymula76@outlook.com>
parents:
diff changeset
964 pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
prymula <prymula76@outlook.com>
parents:
diff changeset
965 filename=file_img_selected,
prymula <prymula76@outlook.com>
parents:
diff changeset
966 width=500,
prymula <prymula76@outlook.com>
parents:
diff changeset
967 height=250,
prymula <prymula76@outlook.com>
parents:
diff changeset
968 preserve_aspect_ratio=True)
prymula <prymula76@outlook.com>
parents:
diff changeset
969
prymula <prymula76@outlook.com>
parents:
diff changeset
970 self.image2 = Gtk.Image.new_from_pixbuf(pixbuf)
prymula <prymula76@outlook.com>
parents:
diff changeset
971
prymula <prymula76@outlook.com>
parents:
diff changeset
972 grid.attach(self.image2,0,1,1,1)
prymula <prymula76@outlook.com>
parents:
diff changeset
973
prymula <prymula76@outlook.com>
parents:
diff changeset
974
prymula <prymula76@outlook.com>
parents:
diff changeset
975
prymula <prymula76@outlook.com>
parents:
diff changeset
976 self.liststore = Gtk.ListStore(str, str)
prymula <prymula76@outlook.com>
parents:
diff changeset
977 self.treeview = Gtk.TreeView(model=self.liststore)
prymula <prymula76@outlook.com>
parents:
diff changeset
978 self.treeview.connect("button_release_event", self.mouse_selected)
prymula <prymula76@outlook.com>
parents:
diff changeset
979
prymula <prymula76@outlook.com>
parents:
diff changeset
980
prymula <prymula76@outlook.com>
parents:
diff changeset
981
prymula <prymula76@outlook.com>
parents:
diff changeset
982 self.renderer_text = Gtk.CellRendererText()
prymula <prymula76@outlook.com>
parents:
diff changeset
983 self.column_text = Gtk.TreeViewColumn("Dostępne etykiety", self.renderer_text, text=0)
prymula <prymula76@outlook.com>
parents:
diff changeset
984 self.treeview.append_column(self.column_text)
prymula <prymula76@outlook.com>
parents:
diff changeset
985
prymula <prymula76@outlook.com>
parents:
diff changeset
986 self.scrolled_window = Gtk.ScrolledWindow ()
prymula <prymula76@outlook.com>
parents:
diff changeset
987 self.scrolled_window.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
prymula <prymula76@outlook.com>
parents:
diff changeset
988
prymula <prymula76@outlook.com>
parents:
diff changeset
989 self.scrolled_window.add (self.treeview)
prymula <prymula76@outlook.com>
parents:
diff changeset
990 grid.attach(self.scrolled_window,0,2,1,6)
prymula <prymula76@outlook.com>
parents:
diff changeset
991
prymula <prymula76@outlook.com>
parents:
diff changeset
992
prymula <prymula76@outlook.com>
parents:
diff changeset
993
prymula <prymula76@outlook.com>
parents:
diff changeset
994
prymula <prymula76@outlook.com>
parents:
diff changeset
995 self.set_border_width(10)
prymula <prymula76@outlook.com>
parents:
diff changeset
996 self.set_title("Naklejki Pocztowe")
prymula <prymula76@outlook.com>
parents:
diff changeset
997 self.set_default_size(1000, 655)
prymula <prymula76@outlook.com>
parents:
diff changeset
998 self.connect("destroy", Gtk.main_quit)
prymula <prymula76@outlook.com>
parents:
diff changeset
999
prymula <prymula76@outlook.com>
parents:
diff changeset
1000
prymula <prymula76@outlook.com>
parents:
diff changeset
1001
prymula <prymula76@outlook.com>
parents:
diff changeset
1002 win = MyWindow()
prymula <prymula76@outlook.com>
parents:
diff changeset
1003 win.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
1004 Gtk.main()
prymula <prymula76@outlook.com>
parents:
diff changeset
1005
prymula <prymula76@outlook.com>
parents:
diff changeset
1006
prymula <prymula76@outlook.com>
parents:
diff changeset
1007
prymula <prymula76@outlook.com>
parents:
diff changeset
1008
prymula <prymula76@outlook.com>
parents:
diff changeset
1009
prymula <prymula76@outlook.com>
parents:
diff changeset
1010
prymula <prymula76@outlook.com>
parents:
diff changeset
1011
prymula <prymula76@outlook.com>
parents:
diff changeset
1012