annotate photocrop/src/photocrop.py @ 29:61c9889ed899

bing4desktop-0.240208-1
author prymula <prymula76@outlook.com>
date Thu, 08 Feb 2024 16:03:15 +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 # Photo Crop - photo crop to size app to print in the most popular photo paper sizes
prymula <prymula76@outlook.com>
parents:
diff changeset
3 # author: Przemysław R. Pietraszczyk
prymula <prymula76@outlook.com>
parents:
diff changeset
4 # license: GPL v.2
prymula <prymula76@outlook.com>
parents:
diff changeset
5 # date 21-01-2022
prymula <prymula76@outlook.com>
parents:
diff changeset
6 # editor: 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 import time
prymula <prymula76@outlook.com>
parents:
diff changeset
12 gi.require_version("Gtk", "3.0")
prymula <prymula76@outlook.com>
parents:
diff changeset
13 from gi.repository import Gtk, GdkPixbuf, Gdk
prymula <prymula76@outlook.com>
parents:
diff changeset
14 from gi.repository.GdkPixbuf import Pixbuf
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 <menuitem action='FileLoad' />
prymula <prymula76@outlook.com>
parents:
diff changeset
21 <menuitem action='FileSave' />
prymula <prymula76@outlook.com>
parents:
diff changeset
22 <menuitem action='FilePrint' />
prymula <prymula76@outlook.com>
parents:
diff changeset
23 <separator />
prymula <prymula76@outlook.com>
parents:
diff changeset
24 <menuitem action='FileQuit' />
prymula <prymula76@outlook.com>
parents:
diff changeset
25 </menu>
prymula <prymula76@outlook.com>
parents:
diff changeset
26 <menu action='EditMenu'>
prymula <prymula76@outlook.com>
parents:
diff changeset
27 <menuitem action='Rotate'/>
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 <separator />
prymula <prymula76@outlook.com>
parents:
diff changeset
33 <menuitem action='License'/>
prymula <prymula76@outlook.com>
parents:
diff changeset
34 </menu>
prymula <prymula76@outlook.com>
parents:
diff changeset
35 </menubar>
prymula <prymula76@outlook.com>
parents:
diff changeset
36
prymula <prymula76@outlook.com>
parents:
diff changeset
37 </ui>
prymula <prymula76@outlook.com>
parents:
diff changeset
38 """
prymula <prymula76@outlook.com>
parents:
diff changeset
39
prymula <prymula76@outlook.com>
parents:
diff changeset
40 """
prymula <prymula76@outlook.com>
parents:
diff changeset
41 # szkielet z podmenu
prymula <prymula76@outlook.com>
parents:
diff changeset
42 <ui>
prymula <prymula76@outlook.com>
parents:
diff changeset
43 <menubar name='MenuBar'>
prymula <prymula76@outlook.com>
parents:
diff changeset
44 <menu action='FileMenu'>
prymula <prymula76@outlook.com>
parents:
diff changeset
45 <menu action='FileLoad'>
prymula <prymula76@outlook.com>
parents:
diff changeset
46 <menuitem action='LoadImg' />
prymula <prymula76@outlook.com>
parents:
diff changeset
47 </menu>
prymula <prymula76@outlook.com>
parents:
diff changeset
48 <menuitem action='FilePrint' />
prymula <prymula76@outlook.com>
parents:
diff changeset
49 <separator />
prymula <prymula76@outlook.com>
parents:
diff changeset
50 <menuitem action='FileQuit' />
prymula <prymula76@outlook.com>
parents:
diff changeset
51 </menu>
prymula <prymula76@outlook.com>
parents:
diff changeset
52 <menu action='InfoMenu'>
prymula <prymula76@outlook.com>
parents:
diff changeset
53 <menuitem action='Help'/>
prymula <prymula76@outlook.com>
parents:
diff changeset
54 <menuitem action='About'/>
prymula <prymula76@outlook.com>
parents:
diff changeset
55 </menu>
prymula <prymula76@outlook.com>
parents:
diff changeset
56 </menubar>
prymula <prymula76@outlook.com>
parents:
diff changeset
57 </ui>
prymula <prymula76@outlook.com>
parents:
diff changeset
58 """
prymula <prymula76@outlook.com>
parents:
diff changeset
59
prymula <prymula76@outlook.com>
parents:
diff changeset
60 grid = Gtk.Grid()
prymula <prymula76@outlook.com>
parents:
diff changeset
61 rotate = False
prymula <prymula76@outlook.com>
parents:
diff changeset
62 file_img_selected = ""
prymula <prymula76@outlook.com>
parents:
diff changeset
63
prymula <prymula76@outlook.com>
parents:
diff changeset
64 def get_resource_path(rel_path):
prymula <prymula76@outlook.com>
parents:
diff changeset
65 dir_of_py_file = os.path.dirname(__file__)
prymula <prymula76@outlook.com>
parents:
diff changeset
66 rel_path_to_resource = os.path.join(dir_of_py_file, rel_path)
prymula <prymula76@outlook.com>
parents:
diff changeset
67 abs_path_to_resource = os.path.abspath(rel_path_to_resource)
prymula <prymula76@outlook.com>
parents:
diff changeset
68 return abs_path_to_resource
prymula <prymula76@outlook.com>
parents:
diff changeset
69
prymula <prymula76@outlook.com>
parents:
diff changeset
70 class FileChooserIMGLoad(Gtk.Window):
prymula <prymula76@outlook.com>
parents:
diff changeset
71 def __init__(self):
prymula <prymula76@outlook.com>
parents:
diff changeset
72 Gtk.Window.__init__(self, title="Selection of graphic files")
prymula <prymula76@outlook.com>
parents:
diff changeset
73 global file_img_selected
prymula <prymula76@outlook.com>
parents:
diff changeset
74
prymula <prymula76@outlook.com>
parents:
diff changeset
75 dialog = Gtk.FileChooserDialog(title="Selection of graphic files", parent=self, action=Gtk.FileChooserAction.OPEN)
prymula <prymula76@outlook.com>
parents:
diff changeset
76 dialog.add_buttons(
prymula <prymula76@outlook.com>
parents:
diff changeset
77 Gtk.STOCK_CANCEL,
prymula <prymula76@outlook.com>
parents:
diff changeset
78 Gtk.ResponseType.CANCEL,
prymula <prymula76@outlook.com>
parents:
diff changeset
79 Gtk.STOCK_OPEN,
prymula <prymula76@outlook.com>
parents:
diff changeset
80 Gtk.ResponseType.OK,
prymula <prymula76@outlook.com>
parents:
diff changeset
81 )
prymula <prymula76@outlook.com>
parents:
diff changeset
82
prymula <prymula76@outlook.com>
parents:
diff changeset
83 self.add_filters(dialog)
prymula <prymula76@outlook.com>
parents:
diff changeset
84
prymula <prymula76@outlook.com>
parents:
diff changeset
85 response = dialog.run()
prymula <prymula76@outlook.com>
parents:
diff changeset
86 if response == Gtk.ResponseType.OK:
prymula <prymula76@outlook.com>
parents:
diff changeset
87 print("Open clicked")
prymula <prymula76@outlook.com>
parents:
diff changeset
88 print("File selected: " + dialog.get_filename())
prymula <prymula76@outlook.com>
parents:
diff changeset
89 file_img_selected=dialog.get_filename()
prymula <prymula76@outlook.com>
parents:
diff changeset
90 elif response == Gtk.ResponseType.CANCEL:
prymula <prymula76@outlook.com>
parents:
diff changeset
91 print("Cancel clicked")
prymula <prymula76@outlook.com>
parents:
diff changeset
92
prymula <prymula76@outlook.com>
parents:
diff changeset
93 dialog.destroy()
prymula <prymula76@outlook.com>
parents:
diff changeset
94
prymula <prymula76@outlook.com>
parents:
diff changeset
95 def add_filters(self, dialog):
prymula <prymula76@outlook.com>
parents:
diff changeset
96
prymula <prymula76@outlook.com>
parents:
diff changeset
97 filter_jpeg = Gtk.FileFilter()
prymula <prymula76@outlook.com>
parents:
diff changeset
98 filter_jpeg.set_name("Files JPEG")
prymula <prymula76@outlook.com>
parents:
diff changeset
99 filter_jpeg.add_mime_type("image/jpeg")
prymula <prymula76@outlook.com>
parents:
diff changeset
100 dialog.add_filter(filter_jpeg)
prymula <prymula76@outlook.com>
parents:
diff changeset
101
prymula <prymula76@outlook.com>
parents:
diff changeset
102 filter_png = Gtk.FileFilter()
prymula <prymula76@outlook.com>
parents:
diff changeset
103 filter_png.set_name("Files PNG")
prymula <prymula76@outlook.com>
parents:
diff changeset
104 filter_png.add_mime_type("image/png")
prymula <prymula76@outlook.com>
parents:
diff changeset
105 dialog.add_filter(filter_png)
prymula <prymula76@outlook.com>
parents:
diff changeset
106 """
prymula <prymula76@outlook.com>
parents:
diff changeset
107 filter_png = Gtk.FileFilter()
prymula <prymula76@outlook.com>
parents:
diff changeset
108 filter_png.set_name("Files TIFF")
prymula <prymula76@outlook.com>
parents:
diff changeset
109 filter_png.add_mime_type("image/tiff")
prymula <prymula76@outlook.com>
parents:
diff changeset
110 dialog.add_filter(filter_png)
prymula <prymula76@outlook.com>
parents:
diff changeset
111 """
prymula <prymula76@outlook.com>
parents:
diff changeset
112
prymula <prymula76@outlook.com>
parents:
diff changeset
113 class FileChooserIMGSave(Gtk.Window):
prymula <prymula76@outlook.com>
parents:
diff changeset
114 def __init__(self):
prymula <prymula76@outlook.com>
parents:
diff changeset
115 Gtk.Window.__init__(self, title="Save the cropped photo")
prymula <prymula76@outlook.com>
parents:
diff changeset
116 global file_img_selected
prymula <prymula76@outlook.com>
parents:
diff changeset
117
prymula <prymula76@outlook.com>
parents:
diff changeset
118 dialog = Gtk.FileChooserDialog(title="Save the cropped photo", parent=self, action=Gtk.FileChooserAction.SAVE)
prymula <prymula76@outlook.com>
parents:
diff changeset
119 dialog.add_buttons(
prymula <prymula76@outlook.com>
parents:
diff changeset
120 Gtk.STOCK_CANCEL,
prymula <prymula76@outlook.com>
parents:
diff changeset
121 Gtk.ResponseType.CANCEL,
prymula <prymula76@outlook.com>
parents:
diff changeset
122 Gtk.STOCK_SAVE,
prymula <prymula76@outlook.com>
parents:
diff changeset
123 Gtk.ResponseType.OK,
prymula <prymula76@outlook.com>
parents:
diff changeset
124 )
prymula <prymula76@outlook.com>
parents:
diff changeset
125
prymula <prymula76@outlook.com>
parents:
diff changeset
126 self.add_filters(dialog)
prymula <prymula76@outlook.com>
parents:
diff changeset
127
prymula <prymula76@outlook.com>
parents:
diff changeset
128 response = dialog.run()
prymula <prymula76@outlook.com>
parents:
diff changeset
129 if response == Gtk.ResponseType.OK:
prymula <prymula76@outlook.com>
parents:
diff changeset
130 print("Open clicked")
prymula <prymula76@outlook.com>
parents:
diff changeset
131 print("File selected: " + dialog.get_filename())
prymula <prymula76@outlook.com>
parents:
diff changeset
132 file_img_selected=dialog.get_filename()
prymula <prymula76@outlook.com>
parents:
diff changeset
133 elif response == Gtk.ResponseType.CANCEL:
prymula <prymula76@outlook.com>
parents:
diff changeset
134 print("Cancel clicked")
prymula <prymula76@outlook.com>
parents:
diff changeset
135
prymula <prymula76@outlook.com>
parents:
diff changeset
136 dialog.destroy()
prymula <prymula76@outlook.com>
parents:
diff changeset
137
prymula <prymula76@outlook.com>
parents:
diff changeset
138 def add_filters(self, dialog):
prymula <prymula76@outlook.com>
parents:
diff changeset
139
prymula <prymula76@outlook.com>
parents:
diff changeset
140 filter_jpeg = Gtk.FileFilter()
prymula <prymula76@outlook.com>
parents:
diff changeset
141 filter_jpeg.set_name("Files JPEG")
prymula <prymula76@outlook.com>
parents:
diff changeset
142 filter_jpeg.add_mime_type("image/jpeg")
prymula <prymula76@outlook.com>
parents:
diff changeset
143 dialog.add_filter(filter_jpeg)
prymula <prymula76@outlook.com>
parents:
diff changeset
144
prymula <prymula76@outlook.com>
parents:
diff changeset
145 filter_png = Gtk.FileFilter()
prymula <prymula76@outlook.com>
parents:
diff changeset
146 filter_png.set_name("Files PNG")
prymula <prymula76@outlook.com>
parents:
diff changeset
147 filter_png.add_mime_type("image/png")
prymula <prymula76@outlook.com>
parents:
diff changeset
148 dialog.add_filter(filter_png)
prymula <prymula76@outlook.com>
parents:
diff changeset
149 """
prymula <prymula76@outlook.com>
parents:
diff changeset
150 filter_png = Gtk.FileFilter()
prymula <prymula76@outlook.com>
parents:
diff changeset
151 filter_png.set_name("Files TIFF")
prymula <prymula76@outlook.com>
parents:
diff changeset
152 filter_png.add_mime_type("image/tiff")
prymula <prymula76@outlook.com>
parents:
diff changeset
153 dialog.add_filter(filter_png)
prymula <prymula76@outlook.com>
parents:
diff changeset
154 """
prymula <prymula76@outlook.com>
parents:
diff changeset
155
prymula <prymula76@outlook.com>
parents:
diff changeset
156
prymula <prymula76@outlook.com>
parents:
diff changeset
157 class DialogWarning(Gtk.Dialog):
prymula <prymula76@outlook.com>
parents:
diff changeset
158 def __init__(self, parent):
prymula <prymula76@outlook.com>
parents:
diff changeset
159 Gtk.Dialog.__init__(self, title="Attention!", transient_for=parent, flags=0)
prymula <prymula76@outlook.com>
parents:
diff changeset
160 self.props.border_width = 20
prymula <prymula76@outlook.com>
parents:
diff changeset
161 self.add_buttons(
prymula <prymula76@outlook.com>
parents:
diff changeset
162 Gtk.STOCK_OK, Gtk.ResponseType.OK
prymula <prymula76@outlook.com>
parents:
diff changeset
163 )
prymula <prymula76@outlook.com>
parents:
diff changeset
164 self.set_default_size(150, 100)
prymula <prymula76@outlook.com>
parents:
diff changeset
165 label1 = Gtk.Label(label="The frame is outside the canvas!\n")
prymula <prymula76@outlook.com>
parents:
diff changeset
166 box = self.get_content_area()
prymula <prymula76@outlook.com>
parents:
diff changeset
167 box.add(label1)
prymula <prymula76@outlook.com>
parents:
diff changeset
168 self.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
169
prymula <prymula76@outlook.com>
parents:
diff changeset
170 class DialogCropWarning(Gtk.Dialog):
prymula <prymula76@outlook.com>
parents:
diff changeset
171 def __init__(self, parent):
prymula <prymula76@outlook.com>
parents:
diff changeset
172 Gtk.Dialog.__init__(self, title="Attention!", transient_for=parent, flags=0)
prymula <prymula76@outlook.com>
parents:
diff changeset
173 self.props.border_width = 20
prymula <prymula76@outlook.com>
parents:
diff changeset
174 self.add_buttons(
prymula <prymula76@outlook.com>
parents:
diff changeset
175 Gtk.STOCK_OK, Gtk.ResponseType.OK
prymula <prymula76@outlook.com>
parents:
diff changeset
176 )
prymula <prymula76@outlook.com>
parents:
diff changeset
177 self.set_default_size(150, 100)
prymula <prymula76@outlook.com>
parents:
diff changeset
178 label1 = Gtk.Label(label="Crop the photo first!\n")
prymula <prymula76@outlook.com>
parents:
diff changeset
179 box = self.get_content_area()
prymula <prymula76@outlook.com>
parents:
diff changeset
180 box.add(label1)
prymula <prymula76@outlook.com>
parents:
diff changeset
181 self.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
182
prymula <prymula76@outlook.com>
parents:
diff changeset
183 class DialogHelp(Gtk.Dialog):
prymula <prymula76@outlook.com>
parents:
diff changeset
184 def __init__(self, parent):
prymula <prymula76@outlook.com>
parents:
diff changeset
185 Gtk.Dialog.__init__(self, title="Help", transient_for=parent, flags=0)
prymula <prymula76@outlook.com>
parents:
diff changeset
186 self.props.border_width = 20
prymula <prymula76@outlook.com>
parents:
diff changeset
187 self.add_buttons(
prymula <prymula76@outlook.com>
parents:
diff changeset
188 Gtk.STOCK_OK, Gtk.ResponseType.OK
prymula <prymula76@outlook.com>
parents:
diff changeset
189 )
prymula <prymula76@outlook.com>
parents:
diff changeset
190
prymula <prymula76@outlook.com>
parents:
diff changeset
191 self.set_default_size(150, 100)
prymula <prymula76@outlook.com>
parents:
diff changeset
192 label1 = Gtk.Label(label="An application for cropping photos to the most popular\nformats [13x18, 10x15, A4]\n\nScaling the size of the frame - mouse wheel with the CTRL key pressed\nMoving the frame - pressed LMB and moving the mouse\nin the desired direction.")
prymula <prymula76@outlook.com>
parents:
diff changeset
193 #label2 = Gtk.Label(lanel="")
prymula <prymula76@outlook.com>
parents:
diff changeset
194 box = self.get_content_area()
prymula <prymula76@outlook.com>
parents:
diff changeset
195 box.add(label1)
prymula <prymula76@outlook.com>
parents:
diff changeset
196 #box.add(label2)
prymula <prymula76@outlook.com>
parents:
diff changeset
197 self.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
198
prymula <prymula76@outlook.com>
parents:
diff changeset
199 class DialogAbout(Gtk.Dialog):
prymula <prymula76@outlook.com>
parents:
diff changeset
200 def __init__(self, parent):
prymula <prymula76@outlook.com>
parents:
diff changeset
201 Gtk.Dialog.__init__(self, title="About", transient_for=parent, flags=0)
prymula <prymula76@outlook.com>
parents:
diff changeset
202 self.props.border_width = 20
prymula <prymula76@outlook.com>
parents:
diff changeset
203 self.add_buttons(
prymula <prymula76@outlook.com>
parents:
diff changeset
204 Gtk.STOCK_OK, Gtk.ResponseType.OK
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.set_default_size(150, 100)
prymula <prymula76@outlook.com>
parents:
diff changeset
208
prymula <prymula76@outlook.com>
parents:
diff changeset
209 label = Gtk.Label(label="\tThe application is based on:")
prymula <prymula76@outlook.com>
parents:
diff changeset
210 box = self.get_content_area()
prymula <prymula76@outlook.com>
parents:
diff changeset
211 box.add(label)
prymula <prymula76@outlook.com>
parents:
diff changeset
212
prymula <prymula76@outlook.com>
parents:
diff changeset
213 button = Gtk.LinkButton("https://python-gtk-3-tutorial.readthedocs.io/", label="https://python-gtk-3-tutorial.readthedocs.io/")
prymula <prymula76@outlook.com>
parents:
diff changeset
214 box.add(button)
prymula <prymula76@outlook.com>
parents:
diff changeset
215
prymula <prymula76@outlook.com>
parents:
diff changeset
216 label2 = Gtk.Label(label="\n\tVersion: 0.230112-1~alpha\n\n\tPrzemysław R. Pietraszczyk\n\n\t\t January 2022\n\n\n")
prymula <prymula76@outlook.com>
parents:
diff changeset
217 box.add(label2)
prymula <prymula76@outlook.com>
parents:
diff changeset
218
prymula <prymula76@outlook.com>
parents:
diff changeset
219
prymula <prymula76@outlook.com>
parents:
diff changeset
220 button = Gtk.LinkButton("https://prymula.ct8.pl", label="Site")
prymula <prymula76@outlook.com>
parents:
diff changeset
221 box.add(button)
prymula <prymula76@outlook.com>
parents:
diff changeset
222
prymula <prymula76@outlook.com>
parents:
diff changeset
223 self.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
224
prymula <prymula76@outlook.com>
parents:
diff changeset
225 class DialogLicense(Gtk.Dialog):
prymula <prymula76@outlook.com>
parents:
diff changeset
226 def __init__(self, parent):
prymula <prymula76@outlook.com>
parents:
diff changeset
227 Gtk.Dialog.__init__(self, title="License", transient_for=parent, flags=0)
prymula <prymula76@outlook.com>
parents:
diff changeset
228 self.props.border_width = 20
prymula <prymula76@outlook.com>
parents:
diff changeset
229 self.add_buttons(
prymula <prymula76@outlook.com>
parents:
diff changeset
230 Gtk.STOCK_OK, Gtk.ResponseType.OK
prymula <prymula76@outlook.com>
parents:
diff changeset
231 )
prymula <prymula76@outlook.com>
parents:
diff changeset
232
prymula <prymula76@outlook.com>
parents:
diff changeset
233 self.set_default_size(150, 100)
prymula <prymula76@outlook.com>
parents:
diff changeset
234
prymula <prymula76@outlook.com>
parents:
diff changeset
235 label = Gtk.Label(label="This program is distributed without any warranty. More information:\n")
prymula <prymula76@outlook.com>
parents:
diff changeset
236
prymula <prymula76@outlook.com>
parents:
diff changeset
237 box = self.get_content_area()
prymula <prymula76@outlook.com>
parents:
diff changeset
238 box.add(label)
prymula <prymula76@outlook.com>
parents:
diff changeset
239
prymula <prymula76@outlook.com>
parents:
diff changeset
240 button = Gtk.LinkButton("https://www.gnu.org/licenses/old-licenses/gpl-2.0.html", label="GNU General License version => 2")
prymula <prymula76@outlook.com>
parents:
diff changeset
241 box.add(button)
prymula <prymula76@outlook.com>
parents:
diff changeset
242
prymula <prymula76@outlook.com>
parents:
diff changeset
243 self.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
244
prymula <prymula76@outlook.com>
parents:
diff changeset
245 class Brush(object):
prymula <prymula76@outlook.com>
parents:
diff changeset
246
prymula <prymula76@outlook.com>
parents:
diff changeset
247 default_rgba_color = (0, 0, 0, 1)
prymula <prymula76@outlook.com>
parents:
diff changeset
248
prymula <prymula76@outlook.com>
parents:
diff changeset
249 def __init__(self, width=None, rgba_color=None):
prymula <prymula76@outlook.com>
parents:
diff changeset
250
prymula <prymula76@outlook.com>
parents:
diff changeset
251 if rgba_color is None:
prymula <prymula76@outlook.com>
parents:
diff changeset
252 rgba_color = self.default_rgba_color
prymula <prymula76@outlook.com>
parents:
diff changeset
253
prymula <prymula76@outlook.com>
parents:
diff changeset
254 if width is None:
prymula <prymula76@outlook.com>
parents:
diff changeset
255 width = 3
prymula <prymula76@outlook.com>
parents:
diff changeset
256
prymula <prymula76@outlook.com>
parents:
diff changeset
257 self.__width = width
prymula <prymula76@outlook.com>
parents:
diff changeset
258 self.__rgba_color = rgba_color
prymula <prymula76@outlook.com>
parents:
diff changeset
259 self.__stroke = []
prymula <prymula76@outlook.com>
parents:
diff changeset
260 self.__current_line = []
prymula <prymula76@outlook.com>
parents:
diff changeset
261
prymula <prymula76@outlook.com>
parents:
diff changeset
262 def _line_ended(self):
prymula <prymula76@outlook.com>
parents:
diff changeset
263 self.__stroke.append(self.__current_line.copy())
prymula <prymula76@outlook.com>
parents:
diff changeset
264 self.__current_line = []
prymula <prymula76@outlook.com>
parents:
diff changeset
265
prymula <prymula76@outlook.com>
parents:
diff changeset
266 def _add_point(self, point):
prymula <prymula76@outlook.com>
parents:
diff changeset
267 self.__current_line.append(point)
prymula <prymula76@outlook.com>
parents:
diff changeset
268
prymula <prymula76@outlook.com>
parents:
diff changeset
269 def _draw(self, cairo_context):
prymula <prymula76@outlook.com>
parents:
diff changeset
270
prymula <prymula76@outlook.com>
parents:
diff changeset
271 cairo_context.set_source_rgba(*self.__rgba_color)
prymula <prymula76@outlook.com>
parents:
diff changeset
272 cairo_context.set_line_width(self.__width)
prymula <prymula76@outlook.com>
parents:
diff changeset
273 cairo_context.set_line_cap(cairo.LINE_CAP_ROUND)
prymula <prymula76@outlook.com>
parents:
diff changeset
274
prymula <prymula76@outlook.com>
parents:
diff changeset
275 cairo_context.new_path()
prymula <prymula76@outlook.com>
parents:
diff changeset
276 for line in self.__stroke:
prymula <prymula76@outlook.com>
parents:
diff changeset
277 for x, y in line:
prymula <prymula76@outlook.com>
parents:
diff changeset
278 cairo_context.line_to(x, y)
prymula <prymula76@outlook.com>
parents:
diff changeset
279 cairo_context.new_sub_path()
prymula <prymula76@outlook.com>
parents:
diff changeset
280
prymula <prymula76@outlook.com>
parents:
diff changeset
281 for x, y in self.__current_line:
prymula <prymula76@outlook.com>
parents:
diff changeset
282 cairo_context.line_to(x, y)
prymula <prymula76@outlook.com>
parents:
diff changeset
283
prymula <prymula76@outlook.com>
parents:
diff changeset
284 cairo_context.stroke()
prymula <prymula76@outlook.com>
parents:
diff changeset
285
prymula <prymula76@outlook.com>
parents:
diff changeset
286
prymula <prymula76@outlook.com>
parents:
diff changeset
287 # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
prymula <prymula76@outlook.com>
parents:
diff changeset
288 # ~ Getters & Setters ~ #
prymula <prymula76@outlook.com>
parents:
diff changeset
289 # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
prymula <prymula76@outlook.com>
parents:
diff changeset
290
prymula <prymula76@outlook.com>
parents:
diff changeset
291 def _get_width(self):
prymula <prymula76@outlook.com>
parents:
diff changeset
292 return self.__width
prymula <prymula76@outlook.com>
parents:
diff changeset
293
prymula <prymula76@outlook.com>
parents:
diff changeset
294 def _set_width(self, width):
prymula <prymula76@outlook.com>
parents:
diff changeset
295 self.__width = width
prymula <prymula76@outlook.com>
parents:
diff changeset
296
prymula <prymula76@outlook.com>
parents:
diff changeset
297 def _get_rgba_color(self):
prymula <prymula76@outlook.com>
parents:
diff changeset
298 return self.__rgba_color
prymula <prymula76@outlook.com>
parents:
diff changeset
299
prymula <prymula76@outlook.com>
parents:
diff changeset
300 def _set_rgba_color(self, rgba_color):
prymula <prymula76@outlook.com>
parents:
diff changeset
301 self.__rgba_color = rgba_color
prymula <prymula76@outlook.com>
parents:
diff changeset
302
prymula <prymula76@outlook.com>
parents:
diff changeset
303 def _get_stroke(self):
prymula <prymula76@outlook.com>
parents:
diff changeset
304 return self.__stroke
prymula <prymula76@outlook.com>
parents:
diff changeset
305
prymula <prymula76@outlook.com>
parents:
diff changeset
306 def _get_current_line(self):
prymula <prymula76@outlook.com>
parents:
diff changeset
307 return self.__current_line
prymula <prymula76@outlook.com>
parents:
diff changeset
308
prymula <prymula76@outlook.com>
parents:
diff changeset
309 class MyWindow(Gtk.Window):
prymula <prymula76@outlook.com>
parents:
diff changeset
310
prymula <prymula76@outlook.com>
parents:
diff changeset
311 def __init__(self):
prymula <prymula76@outlook.com>
parents:
diff changeset
312 super().__init__()
prymula <prymula76@outlook.com>
parents:
diff changeset
313
prymula <prymula76@outlook.com>
parents:
diff changeset
314 self.init_ui()
prymula <prymula76@outlook.com>
parents:
diff changeset
315
prymula <prymula76@outlook.com>
parents:
diff changeset
316 def on_drawing_area_draw(self, drawable, cairo_context):
prymula <prymula76@outlook.com>
parents:
diff changeset
317 global rotate
prymula <prymula76@outlook.com>
parents:
diff changeset
318
prymula <prymula76@outlook.com>
parents:
diff changeset
319 start = time.time()
prymula <prymula76@outlook.com>
parents:
diff changeset
320 self.brush = Brush()
prymula <prymula76@outlook.com>
parents:
diff changeset
321
prymula <prymula76@outlook.com>
parents:
diff changeset
322 # DrawingArea size depends on Pixbuf size
prymula <prymula76@outlook.com>
parents:
diff changeset
323 #self.drawing_area.get_window().resize(self.displayed_pixbuf.get_width(),
prymula <prymula76@outlook.com>
parents:
diff changeset
324 # self.displayed_pixbuf .get_height())
prymula <prymula76@outlook.com>
parents:
diff changeset
325 #self.drawing_area.set_size_request(self.displayed_pixbuf.get_width(),
prymula <prymula76@outlook.com>
parents:
diff changeset
326 # self.displayed_pixbuf.get_height())
prymula <prymula76@outlook.com>
parents:
diff changeset
327
prymula <prymula76@outlook.com>
parents:
diff changeset
328
prymula <prymula76@outlook.com>
parents:
diff changeset
329 # (x, y) offsets
prymula <prymula76@outlook.com>
parents:
diff changeset
330 pixbuf_x = 0 #int(self.viewport.get_hadjustment().get_value())
prymula <prymula76@outlook.com>
parents:
diff changeset
331 pixbuf_y = 0 # int(self.viewport.get_vadjustment().get_value())
prymula <prymula76@outlook.com>
parents:
diff changeset
332
prymula <prymula76@outlook.com>
parents:
diff changeset
333 # Width and height of the image's clip
prymula <prymula76@outlook.com>
parents:
diff changeset
334 width = cairo_context.get_target().get_width()
prymula <prymula76@outlook.com>
parents:
diff changeset
335 height = cairo_context.get_target().get_height()
prymula <prymula76@outlook.com>
parents:
diff changeset
336
prymula <prymula76@outlook.com>
parents:
diff changeset
337 if width > 0 and height > 0:
prymula <prymula76@outlook.com>
parents:
diff changeset
338
prymula <prymula76@outlook.com>
parents:
diff changeset
339 # Draw created area of the Sample's Pixbuf
prymula <prymula76@outlook.com>
parents:
diff changeset
340 Gdk.cairo_set_source_pixbuf(cairo_context, self.pixbuf_view, pixbuf_x, pixbuf_y)
prymula <prymula76@outlook.com>
parents:
diff changeset
341
prymula <prymula76@outlook.com>
parents:
diff changeset
342 cairo_context.paint()
prymula <prymula76@outlook.com>
parents:
diff changeset
343
prymula <prymula76@outlook.com>
parents:
diff changeset
344 if self.border_visible == True:
prymula <prymula76@outlook.com>
parents:
diff changeset
345 # Draw brush strokes
prymula <prymula76@outlook.com>
parents:
diff changeset
346 self.brush._add_point((self.border_x, self.border_y))
prymula <prymula76@outlook.com>
parents:
diff changeset
347 self.brush._add_point((self.border_width, self.border_y))
prymula <prymula76@outlook.com>
parents:
diff changeset
348 self.brush._add_point((self.border_width, self.border_y+self.border_height))
prymula <prymula76@outlook.com>
parents:
diff changeset
349 self.brush._add_point((self.border_x, self.border_y+self.border_height))
prymula <prymula76@outlook.com>
parents:
diff changeset
350 self.brush._add_point((self.border_x, self.border_y)) # nie działa ?
prymula <prymula76@outlook.com>
parents:
diff changeset
351
prymula <prymula76@outlook.com>
parents:
diff changeset
352 self.brush._draw(cairo_context)
prymula <prymula76@outlook.com>
parents:
diff changeset
353
prymula <prymula76@outlook.com>
parents:
diff changeset
354 end = time.time()
prymula <prymula76@outlook.com>
parents:
diff changeset
355 #print(f"Runtime of the program is {end - start}")
prymula <prymula76@outlook.com>
parents:
diff changeset
356
prymula <prymula76@outlook.com>
parents:
diff changeset
357
prymula <prymula76@outlook.com>
parents:
diff changeset
358 def set_ratio_border_size(self):
prymula <prymula76@outlook.com>
parents:
diff changeset
359
prymula <prymula76@outlook.com>
parents:
diff changeset
360 self.border_x = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
361 self.border_y = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
362
prymula <prymula76@outlook.com>
parents:
diff changeset
363 if self.format_size == "10x15":
prymula <prymula76@outlook.com>
parents:
diff changeset
364 if self.horizontal == True and self.vertical == False:
prymula <prymula76@outlook.com>
parents:
diff changeset
365 single = self.picture_view_height*0.5
prymula <prymula76@outlook.com>
parents:
diff changeset
366 self.border_height = single
prymula <prymula76@outlook.com>
parents:
diff changeset
367 self.border_width = single*1.4
prymula <prymula76@outlook.com>
parents:
diff changeset
368 #self.look = "horizontal"
prymula <prymula76@outlook.com>
parents:
diff changeset
369 #self.border_type = "horizontal"
prymula <prymula76@outlook.com>
parents:
diff changeset
370 elif self.horizontal == False and self.vertical == True:
prymula <prymula76@outlook.com>
parents:
diff changeset
371 single = self.picture_view_width*0.5
prymula <prymula76@outlook.com>
parents:
diff changeset
372 self.border_width = single
prymula <prymula76@outlook.com>
parents:
diff changeset
373 self.border_height = single*1.4
prymula <prymula76@outlook.com>
parents:
diff changeset
374 #self.look = "vertical"
prymula <prymula76@outlook.com>
parents:
diff changeset
375 #self.border_type = "vertical"
prymula <prymula76@outlook.com>
parents:
diff changeset
376 elif self.horizontal == False and self.vertical == False:
prymula <prymula76@outlook.com>
parents:
diff changeset
377 self.border_height = self.picture_view_height
prymula <prymula76@outlook.com>
parents:
diff changeset
378 self.border_width = self.picture_view_width
prymula <prymula76@outlook.com>
parents:
diff changeset
379
prymula <prymula76@outlook.com>
parents:
diff changeset
380 elif self.format_size == "13x18":
prymula <prymula76@outlook.com>
parents:
diff changeset
381 if self.horizontal == True and self.vertical == False:
prymula <prymula76@outlook.com>
parents:
diff changeset
382 single = self.picture_view_height*0.5
prymula <prymula76@outlook.com>
parents:
diff changeset
383 self.border_height = single
prymula <prymula76@outlook.com>
parents:
diff changeset
384 self.border_width = single*1.42
prymula <prymula76@outlook.com>
parents:
diff changeset
385 elif self.horizontal == False and self.vertical == True:
prymula <prymula76@outlook.com>
parents:
diff changeset
386 single = self.picture_view_width*0.5
prymula <prymula76@outlook.com>
parents:
diff changeset
387 self.border_width = single
prymula <prymula76@outlook.com>
parents:
diff changeset
388 self.border_height = single*1.42
prymula <prymula76@outlook.com>
parents:
diff changeset
389 elif self.horizontal == False and self.vertical == False:
prymula <prymula76@outlook.com>
parents:
diff changeset
390 self.border_height = self.picture_view_height
prymula <prymula76@outlook.com>
parents:
diff changeset
391 self.border_width = self.picture_view_width
prymula <prymula76@outlook.com>
parents:
diff changeset
392
prymula <prymula76@outlook.com>
parents:
diff changeset
393 elif self.format_size == "A4":
prymula <prymula76@outlook.com>
parents:
diff changeset
394 if self.horizontal == True and self.vertical == False:
prymula <prymula76@outlook.com>
parents:
diff changeset
395 single = self.picture_view_height*0.5
prymula <prymula76@outlook.com>
parents:
diff changeset
396 self.border_height = single
prymula <prymula76@outlook.com>
parents:
diff changeset
397 self.border_width = single*1.4
prymula <prymula76@outlook.com>
parents:
diff changeset
398 elif self.horizontal == False and self.vertical == True:
prymula <prymula76@outlook.com>
parents:
diff changeset
399 single = self.picture_view_width*0.5
prymula <prymula76@outlook.com>
parents:
diff changeset
400 self.border_width = single
prymula <prymula76@outlook.com>
parents:
diff changeset
401 self.border_height = single*1.4
prymula <prymula76@outlook.com>
parents:
diff changeset
402 elif self.horizontal == False and self.vertical == False:
prymula <prymula76@outlook.com>
parents:
diff changeset
403 self.border_height = self.picture_view_height
prymula <prymula76@outlook.com>
parents:
diff changeset
404 self.border_width = self.picture_view_width
prymula <prymula76@outlook.com>
parents:
diff changeset
405
prymula <prymula76@outlook.com>
parents:
diff changeset
406
prymula <prymula76@outlook.com>
parents:
diff changeset
407
prymula <prymula76@outlook.com>
parents:
diff changeset
408 # ustaw proporcje dla obrazu w kontrolce
prymula <prymula76@outlook.com>
parents:
diff changeset
409 def set_ratio_picture_view(self):
prymula <prymula76@outlook.com>
parents:
diff changeset
410 self.picture_orig_width = float(self.pixbuf_orig.get_width())
prymula <prymula76@outlook.com>
parents:
diff changeset
411 self.picture_orig_height = float(self.pixbuf_orig.get_height())
prymula <prymula76@outlook.com>
parents:
diff changeset
412 #if self.format_size == "10x15":
prymula <prymula76@outlook.com>
parents:
diff changeset
413 #self.picture_orig_x = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
414 #self.picture_orig_y = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
415
prymula <prymula76@outlook.com>
parents:
diff changeset
416 if self.picture_orig_width > self.picture_orig_height:
prymula <prymula76@outlook.com>
parents:
diff changeset
417 self.picture_view_width = 586.66 #600
prymula <prymula76@outlook.com>
parents:
diff changeset
418 m = self.picture_orig_width / 586.66 #600
prymula <prymula76@outlook.com>
parents:
diff changeset
419 self.picture_view_height = self.picture_orig_height/m
prymula <prymula76@outlook.com>
parents:
diff changeset
420 if self.picture_orig_height > self.picture_orig_width:
prymula <prymula76@outlook.com>
parents:
diff changeset
421 self.picture_view_height = 586.66 #600
prymula <prymula76@outlook.com>
parents:
diff changeset
422 m = self.picture_orig_height / 586.66 #600
prymula <prymula76@outlook.com>
parents:
diff changeset
423 self.picture_view_width = self.picture_orig_width/m
prymula <prymula76@outlook.com>
parents:
diff changeset
424
prymula <prymula76@outlook.com>
parents:
diff changeset
425 # Zapamiętanie rozmiaru obrazka dla kontrolki
prymula <prymula76@outlook.com>
parents:
diff changeset
426 self.orig_ratio_width = self.picture_view_width
prymula <prymula76@outlook.com>
parents:
diff changeset
427 self.orig_ratio_height = self.picture_view_height
prymula <prymula76@outlook.com>
parents:
diff changeset
428
prymula <prymula76@outlook.com>
parents:
diff changeset
429
prymula <prymula76@outlook.com>
parents:
diff changeset
430
prymula <prymula76@outlook.com>
parents:
diff changeset
431 # ustaw proporcje dla obrazu w kontrolce ppo rotacji
prymula <prymula76@outlook.com>
parents:
diff changeset
432 def set_ratio_picture_view_after_rotation(self):
prymula <prymula76@outlook.com>
parents:
diff changeset
433
prymula <prymula76@outlook.com>
parents:
diff changeset
434 self.picture_tmp_width = self.border_width - self.border_x
prymula <prymula76@outlook.com>
parents:
diff changeset
435 self.picture_tmp_height = self.border_height - self.border_y
prymula <prymula76@outlook.com>
parents:
diff changeset
436
prymula <prymula76@outlook.com>
parents:
diff changeset
437 if self.border_x != 0 :
prymula <prymula76@outlook.com>
parents:
diff changeset
438 bx = self.picture_orig_width / self.border_x
prymula <prymula76@outlook.com>
parents:
diff changeset
439 crop_x = self.picture_tmp_width / bx
prymula <prymula76@outlook.com>
parents:
diff changeset
440 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
441 crop_x = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
442
prymula <prymula76@outlook.com>
parents:
diff changeset
443 if self.border_y != 0:
prymula <prymula76@outlook.com>
parents:
diff changeset
444 by = self.picture_orig_height / self.border_y
prymula <prymula76@outlook.com>
parents:
diff changeset
445 crop_y = self.picture_tmp_height / by
prymula <prymula76@outlook.com>
parents:
diff changeset
446 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
447 crop_y = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
448
prymula <prymula76@outlook.com>
parents:
diff changeset
449
prymula <prymula76@outlook.com>
parents:
diff changeset
450 self.picture_orig_x = crop_x
prymula <prymula76@outlook.com>
parents:
diff changeset
451 self.picture_orig_y = crop_y
prymula <prymula76@outlook.com>
parents:
diff changeset
452 """
prymula <prymula76@outlook.com>
parents:
diff changeset
453 W zależności jaka była pierwotnie orientacja zdjęcia, po obrocie
prymula <prymula76@outlook.com>
parents:
diff changeset
454 jest ono odpowiedio przycinane
prymula <prymula76@outlook.com>
parents:
diff changeset
455 """
prymula <prymula76@outlook.com>
parents:
diff changeset
456 print ("ORIG: "+self.look)
prymula <prymula76@outlook.com>
parents:
diff changeset
457 if self.look == "vertical":
prymula <prymula76@outlook.com>
parents:
diff changeset
458 if self.border_type == "horizontal":
prymula <prymula76@outlook.com>
parents:
diff changeset
459 bw = self.picture_orig_width / (self.border_width - self.border_x)
prymula <prymula76@outlook.com>
parents:
diff changeset
460 self.picture_tmp_width = self.picture_orig_width / bw - crop_x
prymula <prymula76@outlook.com>
parents:
diff changeset
461 # w tym wypadku 'y' bez odejmowania gdyż skróciło by to fotografie w pione
prymula <prymula76@outlook.com>
parents:
diff changeset
462 bh = self.picture_orig_height / self.border_height
prymula <prymula76@outlook.com>
parents:
diff changeset
463 self.picture_tmp_height = self.picture_orig_height / bh
prymula <prymula76@outlook.com>
parents:
diff changeset
464
prymula <prymula76@outlook.com>
parents:
diff changeset
465 elif self.border_type == "vertical":
prymula <prymula76@outlook.com>
parents:
diff changeset
466 bw = self.picture_orig_width / (self.border_width - self.border_x)
prymula <prymula76@outlook.com>
parents:
diff changeset
467 self.picture_tmp_width = self.picture_orig_width / bw - crop_x
prymula <prymula76@outlook.com>
parents:
diff changeset
468
prymula <prymula76@outlook.com>
parents:
diff changeset
469 bh = self.picture_orig_height / (self.border_height - self.border_y)
prymula <prymula76@outlook.com>
parents:
diff changeset
470 self.picture_tmp_height = self.picture_orig_height / bh
prymula <prymula76@outlook.com>
parents:
diff changeset
471
prymula <prymula76@outlook.com>
parents:
diff changeset
472 elif self.look == "horizontal":
prymula <prymula76@outlook.com>
parents:
diff changeset
473 if self.border_type == "horizontal":
prymula <prymula76@outlook.com>
parents:
diff changeset
474 bw = self.picture_orig_width / (self.border_width - self.border_x)
prymula <prymula76@outlook.com>
parents:
diff changeset
475 self.picture_tmp_width = self.picture_orig_width / bw - crop_x
prymula <prymula76@outlook.com>
parents:
diff changeset
476
prymula <prymula76@outlook.com>
parents:
diff changeset
477 bh = self.picture_orig_height / (self.border_height - self.border_y)
prymula <prymula76@outlook.com>
parents:
diff changeset
478 self.picture_tmp_height = self.picture_orig_height / bh
prymula <prymula76@outlook.com>
parents:
diff changeset
479
prymula <prymula76@outlook.com>
parents:
diff changeset
480 elif self.border_type == "vertical":
prymula <prymula76@outlook.com>
parents:
diff changeset
481 bw = self.picture_orig_width / (self.border_width - self.border_x)
prymula <prymula76@outlook.com>
parents:
diff changeset
482 self.picture_tmp_width = self.picture_orig_width / bw - crop_x
prymula <prymula76@outlook.com>
parents:
diff changeset
483
prymula <prymula76@outlook.com>
parents:
diff changeset
484 bh = self.picture_orig_height / (self.border_height - self.border_y)
prymula <prymula76@outlook.com>
parents:
diff changeset
485 self.picture_tmp_height = self.picture_orig_height / bh
prymula <prymula76@outlook.com>
parents:
diff changeset
486
prymula <prymula76@outlook.com>
parents:
diff changeset
487
prymula <prymula76@outlook.com>
parents:
diff changeset
488 if self.picture_tmp_width > self.picture_tmp_height:
prymula <prymula76@outlook.com>
parents:
diff changeset
489 self.picture_view_width = 586.66
prymula <prymula76@outlook.com>
parents:
diff changeset
490 m = self.picture_tmp_width / 586.66
prymula <prymula76@outlook.com>
parents:
diff changeset
491 self.picture_view_height = self.picture_tmp_height/m
prymula <prymula76@outlook.com>
parents:
diff changeset
492 if self.picture_tmp_height > self.picture_tmp_width:
prymula <prymula76@outlook.com>
parents:
diff changeset
493 self.picture_view_height = 586.66
prymula <prymula76@outlook.com>
parents:
diff changeset
494 m = self.picture_tmp_height / 586.66
prymula <prymula76@outlook.com>
parents:
diff changeset
495 self.picture_view_width = self.picture_tmp_width/m
prymula <prymula76@outlook.com>
parents:
diff changeset
496
prymula <prymula76@outlook.com>
parents:
diff changeset
497 # Zapamiętanie rozmiaru obrazka dla kontrolki
prymula <prymula76@outlook.com>
parents:
diff changeset
498 self.orig_ratio_width = self.picture_view_width
prymula <prymula76@outlook.com>
parents:
diff changeset
499 self.orig_ratio_height = self.picture_view_height
prymula <prymula76@outlook.com>
parents:
diff changeset
500
prymula <prymula76@outlook.com>
parents:
diff changeset
501 def on_menu_file_load_img_generic(self, widget):
prymula <prymula76@outlook.com>
parents:
diff changeset
502 global grid, file_img_selected
prymula <prymula76@outlook.com>
parents:
diff changeset
503
prymula <prymula76@outlook.com>
parents:
diff changeset
504 filename=FileChooserIMGLoad()
prymula <prymula76@outlook.com>
parents:
diff changeset
505
prymula <prymula76@outlook.com>
parents:
diff changeset
506 if len(file_img_selected) != 0:
prymula <prymula76@outlook.com>
parents:
diff changeset
507
prymula <prymula76@outlook.com>
parents:
diff changeset
508 self.pixbuf_orig = GdkPixbuf.Pixbuf.new_from_file(filename=file_img_selected)
prymula <prymula76@outlook.com>
parents:
diff changeset
509
prymula <prymula76@outlook.com>
parents:
diff changeset
510 self.set_ratio_picture_view()
prymula <prymula76@outlook.com>
parents:
diff changeset
511 self.pixbuf_view = self.pixbuf_orig.scale_simple(self.picture_view_width, self.picture_view_height, GdkPixbuf.InterpType.HYPER)
prymula <prymula76@outlook.com>
parents:
diff changeset
512
prymula <prymula76@outlook.com>
parents:
diff changeset
513 if self.picture_view_width > self.picture_view_height:
prymula <prymula76@outlook.com>
parents:
diff changeset
514 self.horizontal = True
prymula <prymula76@outlook.com>
parents:
diff changeset
515 self.vertical = False
prymula <prymula76@outlook.com>
parents:
diff changeset
516 self.resize(582.66,413.34)
prymula <prymula76@outlook.com>
parents:
diff changeset
517 self.look = "horizontal"
prymula <prymula76@outlook.com>
parents:
diff changeset
518 self.border_type = "horizontal"
prymula <prymula76@outlook.com>
parents:
diff changeset
519 elif self.picture_view_height > self.picture_view_width:
prymula <prymula76@outlook.com>
parents:
diff changeset
520 self.vertical = True
prymula <prymula76@outlook.com>
parents:
diff changeset
521 self.horizontal = False
prymula <prymula76@outlook.com>
parents:
diff changeset
522 self.resize(413.34,582.66)
prymula <prymula76@outlook.com>
parents:
diff changeset
523 self.look = "vertical"
prymula <prymula76@outlook.com>
parents:
diff changeset
524 self.border_type = "vertical"
prymula <prymula76@outlook.com>
parents:
diff changeset
525 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
526 self.horizontal = False
prymula <prymula76@outlook.com>
parents:
diff changeset
527 self.vertical = False
prymula <prymula76@outlook.com>
parents:
diff changeset
528
prymula <prymula76@outlook.com>
parents:
diff changeset
529
prymula <prymula76@outlook.com>
parents:
diff changeset
530 self.set_ratio_border_size()
prymula <prymula76@outlook.com>
parents:
diff changeset
531
prymula <prymula76@outlook.com>
parents:
diff changeset
532
prymula <prymula76@outlook.com>
parents:
diff changeset
533
prymula <prymula76@outlook.com>
parents:
diff changeset
534 self.border_visible = True
prymula <prymula76@outlook.com>
parents:
diff changeset
535
prymula <prymula76@outlook.com>
parents:
diff changeset
536 # nie rysujemy na orginale ale na kopii z okna
prymula <prymula76@outlook.com>
parents:
diff changeset
537 self.drawing_area.set_size_request(self.pixbuf_view.get_width(), self.pixbuf_view.get_height())
prymula <prymula76@outlook.com>
parents:
diff changeset
538 self.drawing_area.set_events(Gdk.EventMask.ALL_EVENTS_MASK)
prymula <prymula76@outlook.com>
parents:
diff changeset
539
prymula <prymula76@outlook.com>
parents:
diff changeset
540 self.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
541
prymula <prymula76@outlook.com>
parents:
diff changeset
542 def add_edit_menu_actions(self, action_group):
prymula <prymula76@outlook.com>
parents:
diff changeset
543 action_info_menu = Gtk.Action(name="EditMenu", label="Edit")
prymula <prymula76@outlook.com>
parents:
diff changeset
544 action_group.add_action(action_info_menu)
prymula <prymula76@outlook.com>
parents:
diff changeset
545
prymula <prymula76@outlook.com>
parents:
diff changeset
546 action_new = Gtk.Action(
prymula <prymula76@outlook.com>
parents:
diff changeset
547 name="Rotate",
prymula <prymula76@outlook.com>
parents:
diff changeset
548 label="Frame rotation",
prymula <prymula76@outlook.com>
parents:
diff changeset
549 tooltip="Rotate border",
prymula <prymula76@outlook.com>
parents:
diff changeset
550 )
prymula <prymula76@outlook.com>
parents:
diff changeset
551 action_new.connect("activate", self.on_menu_rotate)
prymula <prymula76@outlook.com>
parents:
diff changeset
552 action_group.add_action_with_accel(action_new, None)
prymula <prymula76@outlook.com>
parents:
diff changeset
553
prymula <prymula76@outlook.com>
parents:
diff changeset
554
prymula <prymula76@outlook.com>
parents:
diff changeset
555 def add_info_menu_actions(self, action_group):
prymula <prymula76@outlook.com>
parents:
diff changeset
556 action_info_menu = Gtk.Action(name="InfoMenu", label="Info")
prymula <prymula76@outlook.com>
parents:
diff changeset
557 action_group.add_action(action_info_menu)
prymula <prymula76@outlook.com>
parents:
diff changeset
558
prymula <prymula76@outlook.com>
parents:
diff changeset
559 action_new = Gtk.Action(
prymula <prymula76@outlook.com>
parents:
diff changeset
560 name="Help",
prymula <prymula76@outlook.com>
parents:
diff changeset
561 label="Help",
prymula <prymula76@outlook.com>
parents:
diff changeset
562 tooltip="Help",
prymula <prymula76@outlook.com>
parents:
diff changeset
563 )
prymula <prymula76@outlook.com>
parents:
diff changeset
564 action_new.connect("activate", self.on_menu_help)
prymula <prymula76@outlook.com>
parents:
diff changeset
565 action_group.add_action_with_accel(action_new, None)
prymula <prymula76@outlook.com>
parents:
diff changeset
566
prymula <prymula76@outlook.com>
parents:
diff changeset
567 action_new = Gtk.Action(
prymula <prymula76@outlook.com>
parents:
diff changeset
568 name="About",
prymula <prymula76@outlook.com>
parents:
diff changeset
569 label="About",
prymula <prymula76@outlook.com>
parents:
diff changeset
570 tooltip="About",
prymula <prymula76@outlook.com>
parents:
diff changeset
571 )
prymula <prymula76@outlook.com>
parents:
diff changeset
572 action_new.connect("activate", self.on_menu_about)
prymula <prymula76@outlook.com>
parents:
diff changeset
573 action_group.add_action_with_accel(action_new, None)
prymula <prymula76@outlook.com>
parents:
diff changeset
574
prymula <prymula76@outlook.com>
parents:
diff changeset
575 action_new = Gtk.Action(
prymula <prymula76@outlook.com>
parents:
diff changeset
576 name="License",
prymula <prymula76@outlook.com>
parents:
diff changeset
577 label="License",
prymula <prymula76@outlook.com>
parents:
diff changeset
578 tooltip="License",
prymula <prymula76@outlook.com>
parents:
diff changeset
579 )
prymula <prymula76@outlook.com>
parents:
diff changeset
580 action_new.connect("activate", self.on_menu_license)
prymula <prymula76@outlook.com>
parents:
diff changeset
581 action_group.add_action_with_accel(action_new, None)
prymula <prymula76@outlook.com>
parents:
diff changeset
582
prymula <prymula76@outlook.com>
parents:
diff changeset
583
prymula <prymula76@outlook.com>
parents:
diff changeset
584
prymula <prymula76@outlook.com>
parents:
diff changeset
585 def add_file_menu_actions(self, action_group):
prymula <prymula76@outlook.com>
parents:
diff changeset
586 action_filemenu = Gtk.Action(name="FileMenu", label="File")
prymula <prymula76@outlook.com>
parents:
diff changeset
587 action_group.add_action(action_filemenu)
prymula <prymula76@outlook.com>
parents:
diff changeset
588
prymula <prymula76@outlook.com>
parents:
diff changeset
589 """
prymula <prymula76@outlook.com>
parents:
diff changeset
590 # sposób dodawania podmenu
prymula <prymula76@outlook.com>
parents:
diff changeset
591 action_fileloadmenu = Gtk.Action(name="FileLoad", stock_id=Gtk.STOCK_OPEN)
prymula <prymula76@outlook.com>
parents:
diff changeset
592 action_group.add_action(action_fileloadmenu)
prymula <prymula76@outlook.com>
parents:
diff changeset
593
prymula <prymula76@outlook.com>
parents:
diff changeset
594 action_new = Gtk.Action(
prymula <prymula76@outlook.com>
parents:
diff changeset
595 name="LoadImg",
prymula <prymula76@outlook.com>
parents:
diff changeset
596 label="Wczytaj Obrazek",
prymula <prymula76@outlook.com>
parents:
diff changeset
597 tooltip="Wczytuje obrazek",
prymula <prymula76@outlook.com>
parents:
diff changeset
598 )
prymula <prymula76@outlook.com>
parents:
diff changeset
599 action_new.connect("activate", self.on_menu_file_load_img_generic)
prymula <prymula76@outlook.com>
parents:
diff changeset
600 action_group.add_action_with_accel(action_new, None)
prymula <prymula76@outlook.com>
parents:
diff changeset
601 """
prymula <prymula76@outlook.com>
parents:
diff changeset
602
prymula <prymula76@outlook.com>
parents:
diff changeset
603 action_fileload = Gtk.Action(name="FileLoad", stock_id=Gtk.STOCK_OPEN)
prymula <prymula76@outlook.com>
parents:
diff changeset
604 action_fileload.connect("activate", self.on_menu_file_load_img_generic)
prymula <prymula76@outlook.com>
parents:
diff changeset
605 action_group.add_action(action_fileload)
prymula <prymula76@outlook.com>
parents:
diff changeset
606
prymula <prymula76@outlook.com>
parents:
diff changeset
607 action_filesave = Gtk.Action(name="FileSave", stock_id=Gtk.STOCK_SAVE)
prymula <prymula76@outlook.com>
parents:
diff changeset
608 action_filesave.connect("activate", self.on_menu_file_save_img)
prymula <prymula76@outlook.com>
parents:
diff changeset
609 action_group.add_action(action_filesave)
prymula <prymula76@outlook.com>
parents:
diff changeset
610
prymula <prymula76@outlook.com>
parents:
diff changeset
611
prymula <prymula76@outlook.com>
parents:
diff changeset
612 action_print = Gtk.Action(name="FilePrint", stock_id=Gtk.STOCK_PRINT)
prymula <prymula76@outlook.com>
parents:
diff changeset
613 action_print.connect("activate", self.print_image)
prymula <prymula76@outlook.com>
parents:
diff changeset
614 action_group.add_action(action_print)
prymula <prymula76@outlook.com>
parents:
diff changeset
615
prymula <prymula76@outlook.com>
parents:
diff changeset
616
prymula <prymula76@outlook.com>
parents:
diff changeset
617 action_filequit = Gtk.Action(name="FileQuit", stock_id=Gtk.STOCK_QUIT)
prymula <prymula76@outlook.com>
parents:
diff changeset
618 action_filequit.connect("activate", self.on_menu_file_quit)
prymula <prymula76@outlook.com>
parents:
diff changeset
619 action_group.add_action(action_filequit)
prymula <prymula76@outlook.com>
parents:
diff changeset
620
prymula <prymula76@outlook.com>
parents:
diff changeset
621
prymula <prymula76@outlook.com>
parents:
diff changeset
622
prymula <prymula76@outlook.com>
parents:
diff changeset
623 # tworzy menu bar
prymula <prymula76@outlook.com>
parents:
diff changeset
624 def create_ui_manager(self):
prymula <prymula76@outlook.com>
parents:
diff changeset
625 uimanager = Gtk.UIManager()
prymula <prymula76@outlook.com>
parents:
diff changeset
626
prymula <prymula76@outlook.com>
parents:
diff changeset
627 # Throws exception if something went wrong
prymula <prymula76@outlook.com>
parents:
diff changeset
628 uimanager.add_ui_from_string(UI_INFO)
prymula <prymula76@outlook.com>
parents:
diff changeset
629
prymula <prymula76@outlook.com>
parents:
diff changeset
630 # Add the accelerator group to the toplevel window
prymula <prymula76@outlook.com>
parents:
diff changeset
631 accelgroup = uimanager.get_accel_group()
prymula <prymula76@outlook.com>
parents:
diff changeset
632 self.add_accel_group(accelgroup)
prymula <prymula76@outlook.com>
parents:
diff changeset
633 return uimanager
prymula <prymula76@outlook.com>
parents:
diff changeset
634
prymula <prymula76@outlook.com>
parents:
diff changeset
635 def on_menu_about(self, widget):
prymula <prymula76@outlook.com>
parents:
diff changeset
636 dialog = DialogAbout(self)
prymula <prymula76@outlook.com>
parents:
diff changeset
637 response = dialog.run()
prymula <prymula76@outlook.com>
parents:
diff changeset
638
prymula <prymula76@outlook.com>
parents:
diff changeset
639 dialog.destroy()
prymula <prymula76@outlook.com>
parents:
diff changeset
640
prymula <prymula76@outlook.com>
parents:
diff changeset
641 def on_menu_license(self, widget):
prymula <prymula76@outlook.com>
parents:
diff changeset
642 dialog = DialogLicense(self)
prymula <prymula76@outlook.com>
parents:
diff changeset
643 response = dialog.run()
prymula <prymula76@outlook.com>
parents:
diff changeset
644
prymula <prymula76@outlook.com>
parents:
diff changeset
645 dialog.destroy()
prymula <prymula76@outlook.com>
parents:
diff changeset
646
prymula <prymula76@outlook.com>
parents:
diff changeset
647
prymula <prymula76@outlook.com>
parents:
diff changeset
648 def on_menu_help(self, widget):
prymula <prymula76@outlook.com>
parents:
diff changeset
649 dialog = DialogHelp(self)
prymula <prymula76@outlook.com>
parents:
diff changeset
650 response = dialog.run()
prymula <prymula76@outlook.com>
parents:
diff changeset
651
prymula <prymula76@outlook.com>
parents:
diff changeset
652 dialog.destroy()
prymula <prymula76@outlook.com>
parents:
diff changeset
653
prymula <prymula76@outlook.com>
parents:
diff changeset
654 def on_menu_rotate(self, widget):
prymula <prymula76@outlook.com>
parents:
diff changeset
655 global rotate
prymula <prymula76@outlook.com>
parents:
diff changeset
656
prymula <prymula76@outlook.com>
parents:
diff changeset
657
prymula <prymula76@outlook.com>
parents:
diff changeset
658 if self.border_type == "horizontal":
prymula <prymula76@outlook.com>
parents:
diff changeset
659 self.border_type = "vertical"
prymula <prymula76@outlook.com>
parents:
diff changeset
660 self.horizontal = False
prymula <prymula76@outlook.com>
parents:
diff changeset
661 self.vertical = True
prymula <prymula76@outlook.com>
parents:
diff changeset
662
prymula <prymula76@outlook.com>
parents:
diff changeset
663 single = self.picture_view_width*0.3
prymula <prymula76@outlook.com>
parents:
diff changeset
664 self.border_width = single
prymula <prymula76@outlook.com>
parents:
diff changeset
665 self.border_height = single*1.4
prymula <prymula76@outlook.com>
parents:
diff changeset
666 self.border_x = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
667 self.border_y = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
668
prymula <prymula76@outlook.com>
parents:
diff changeset
669 rotate = True
prymula <prymula76@outlook.com>
parents:
diff changeset
670
prymula <prymula76@outlook.com>
parents:
diff changeset
671 elif self.border_type == "vertical":
prymula <prymula76@outlook.com>
parents:
diff changeset
672 self.border_type = "horizontal"
prymula <prymula76@outlook.com>
parents:
diff changeset
673 self.horizontal = True
prymula <prymula76@outlook.com>
parents:
diff changeset
674 self.vertical = False
prymula <prymula76@outlook.com>
parents:
diff changeset
675
prymula <prymula76@outlook.com>
parents:
diff changeset
676 single = self.picture_view_height*0.3
prymula <prymula76@outlook.com>
parents:
diff changeset
677 self.border_height = single
prymula <prymula76@outlook.com>
parents:
diff changeset
678 self.border_width = single*1.4
prymula <prymula76@outlook.com>
parents:
diff changeset
679 self.border_x = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
680 self.border_y = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
681
prymula <prymula76@outlook.com>
parents:
diff changeset
682 rotate = True
prymula <prymula76@outlook.com>
parents:
diff changeset
683 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
684 pass
prymula <prymula76@outlook.com>
parents:
diff changeset
685
prymula <prymula76@outlook.com>
parents:
diff changeset
686 print ("ASPECT: "+self.border_type)
prymula <prymula76@outlook.com>
parents:
diff changeset
687 print ("BORDER-WIDTH :"+str(self.border_width))
prymula <prymula76@outlook.com>
parents:
diff changeset
688 print ("BORDER-HEIGHT:"+str(self.border_height))
prymula <prymula76@outlook.com>
parents:
diff changeset
689
prymula <prymula76@outlook.com>
parents:
diff changeset
690 self.drawing_area.queue_draw()
prymula <prymula76@outlook.com>
parents:
diff changeset
691
prymula <prymula76@outlook.com>
parents:
diff changeset
692 def on_menu_file_save_img(self, widget):
prymula <prymula76@outlook.com>
parents:
diff changeset
693 global file_img_selected
prymula <prymula76@outlook.com>
parents:
diff changeset
694
prymula <prymula76@outlook.com>
parents:
diff changeset
695 if self.pixbuf_tmp != None:
prymula <prymula76@outlook.com>
parents:
diff changeset
696 filename=FileChooserIMGSave()
prymula <prymula76@outlook.com>
parents:
diff changeset
697 if len(file_img_selected) != 0:
prymula <prymula76@outlook.com>
parents:
diff changeset
698 self.pixbuf_view.savev(file_img_selected, "jpeg", ["quality"], ["100"])
prymula <prymula76@outlook.com>
parents:
diff changeset
699 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
700 dialog = DialogCropWarning(self)
prymula <prymula76@outlook.com>
parents:
diff changeset
701 response = dialog.run()
prymula <prymula76@outlook.com>
parents:
diff changeset
702
prymula <prymula76@outlook.com>
parents:
diff changeset
703 dialog.destroy()
prymula <prymula76@outlook.com>
parents:
diff changeset
704
prymula <prymula76@outlook.com>
parents:
diff changeset
705 def on_menu_file_quit(self, widget):
prymula <prymula76@outlook.com>
parents:
diff changeset
706 Gtk.main_quit()
prymula <prymula76@outlook.com>
parents:
diff changeset
707
prymula <prymula76@outlook.com>
parents:
diff changeset
708 def print_page(self, operation=None, context=None, page_nr=None):
prymula <prymula76@outlook.com>
parents:
diff changeset
709
prymula <prymula76@outlook.com>
parents:
diff changeset
710 ctx = context.get_cairo_context()
prymula <prymula76@outlook.com>
parents:
diff changeset
711
prymula <prymula76@outlook.com>
parents:
diff changeset
712 # make cairo ImageSurface from the png file
prymula <prymula76@outlook.com>
parents:
diff changeset
713 surface = cairo.ImageSurface.create_from_png('/tmp/photocrop.png')
prymula <prymula76@outlook.com>
parents:
diff changeset
714 #ctx.rectangle(50,50,100,100)
prymula <prymula76@outlook.com>
parents:
diff changeset
715 ctx.set_source_surface(surface)
prymula <prymula76@outlook.com>
parents:
diff changeset
716 ctx.paint ()
prymula <prymula76@outlook.com>
parents:
diff changeset
717 os.remove("/tmp/photocrop.png");
prymula <prymula76@outlook.com>
parents:
diff changeset
718
prymula <prymula76@outlook.com>
parents:
diff changeset
719
prymula <prymula76@outlook.com>
parents:
diff changeset
720 def print_image(self, widget):
prymula <prymula76@outlook.com>
parents:
diff changeset
721
prymula <prymula76@outlook.com>
parents:
diff changeset
722 if self.pixbuf_tmp == None:
prymula <prymula76@outlook.com>
parents:
diff changeset
723 self.pixbuf_tmp = self.pixbuf_orig
prymula <prymula76@outlook.com>
parents:
diff changeset
724
prymula <prymula76@outlook.com>
parents:
diff changeset
725
prymula <prymula76@outlook.com>
parents:
diff changeset
726 # źle obraca
prymula <prymula76@outlook.com>
parents:
diff changeset
727 #if self.border_type == "horizontal":
prymula <prymula76@outlook.com>
parents:
diff changeset
728 # self.pixbuf_tmp.rotate_simple(GdkPixbuf.PixbufRotation.COUNTERCLOCKWISE)
prymula <prymula76@outlook.com>
parents:
diff changeset
729 # #pixbuf2.rotate_simple(GdkPixbuf.PixbufRotation.CLOCKWISE)
prymula <prymula76@outlook.com>
parents:
diff changeset
730 # self.border_type = "vertical"
prymula <prymula76@outlook.com>
parents:
diff changeset
731
prymula <prymula76@outlook.com>
parents:
diff changeset
732 FACTOR_MM_TO_PIXEL = 2.834645669
prymula <prymula76@outlook.com>
parents:
diff changeset
733
prymula <prymula76@outlook.com>
parents:
diff changeset
734
prymula <prymula76@outlook.com>
parents:
diff changeset
735 if self.format_size == "10x15":
prymula <prymula76@outlook.com>
parents:
diff changeset
736 #if self.horizontal == True and self.vertical == False:
prymula <prymula76@outlook.com>
parents:
diff changeset
737 if self.border_type == "horizontal":
prymula <prymula76@outlook.com>
parents:
diff changeset
738 page_width = 148
prymula <prymula76@outlook.com>
parents:
diff changeset
739 page_height = 104.99
prymula <prymula76@outlook.com>
parents:
diff changeset
740
prymula <prymula76@outlook.com>
parents:
diff changeset
741 img_height =104.99 * FACTOR_MM_TO_PIXEL
prymula <prymula76@outlook.com>
parents:
diff changeset
742 img_width = 148 * FACTOR_MM_TO_PIXEL
prymula <prymula76@outlook.com>
parents:
diff changeset
743 #elif self.horizontal == False and self.vertical == True:
prymula <prymula76@outlook.com>
parents:
diff changeset
744 elif self.border_type == "vertical":
prymula <prymula76@outlook.com>
parents:
diff changeset
745
prymula <prymula76@outlook.com>
parents:
diff changeset
746 page_width = 104.99
prymula <prymula76@outlook.com>
parents:
diff changeset
747 page_height = 148
prymula <prymula76@outlook.com>
parents:
diff changeset
748
prymula <prymula76@outlook.com>
parents:
diff changeset
749 img_width =104.99 * FACTOR_MM_TO_PIXEL
prymula <prymula76@outlook.com>
parents:
diff changeset
750 img_height = 148 * FACTOR_MM_TO_PIXEL
prymula <prymula76@outlook.com>
parents:
diff changeset
751
prymula <prymula76@outlook.com>
parents:
diff changeset
752 size = "10x15"
prymula <prymula76@outlook.com>
parents:
diff changeset
753 elif self.format_size == "13x18":
prymula <prymula76@outlook.com>
parents:
diff changeset
754 #if self.horizontal == True and self.vertical == False:
prymula <prymula76@outlook.com>
parents:
diff changeset
755 if self.border_type == "horizontal":
prymula <prymula76@outlook.com>
parents:
diff changeset
756
prymula <prymula76@outlook.com>
parents:
diff changeset
757 page_width = 178
prymula <prymula76@outlook.com>
parents:
diff changeset
758 page_height = 127
prymula <prymula76@outlook.com>
parents:
diff changeset
759
prymula <prymula76@outlook.com>
parents:
diff changeset
760 img_height = 127 * FACTOR_MM_TO_PIXEL
prymula <prymula76@outlook.com>
parents:
diff changeset
761 img_width = 178 * FACTOR_MM_TO_PIXEL
prymula <prymula76@outlook.com>
parents:
diff changeset
762 #elif self.horizontal == False and self.vertical == True:
prymula <prymula76@outlook.com>
parents:
diff changeset
763 elif self.border_type == "vertical":
prymula <prymula76@outlook.com>
parents:
diff changeset
764
prymula <prymula76@outlook.com>
parents:
diff changeset
765 page_width = 127
prymula <prymula76@outlook.com>
parents:
diff changeset
766 page_height = 178
prymula <prymula76@outlook.com>
parents:
diff changeset
767
prymula <prymula76@outlook.com>
parents:
diff changeset
768 img_width = 127 * FACTOR_MM_TO_PIXEL
prymula <prymula76@outlook.com>
parents:
diff changeset
769 img_height = 178 * FACTOR_MM_TO_PIXEL
prymula <prymula76@outlook.com>
parents:
diff changeset
770 size = "5x7"
prymula <prymula76@outlook.com>
parents:
diff changeset
771 elif self.format_size == "A4":
prymula <prymula76@outlook.com>
parents:
diff changeset
772 #if self.horizontal == True and self.vertical == False:
prymula <prymula76@outlook.com>
parents:
diff changeset
773 if self.border_type == "horizontal":
prymula <prymula76@outlook.com>
parents:
diff changeset
774 page_width = 297
prymula <prymula76@outlook.com>
parents:
diff changeset
775 page_height = 207
prymula <prymula76@outlook.com>
parents:
diff changeset
776
prymula <prymula76@outlook.com>
parents:
diff changeset
777 img_height = 207 * FACTOR_MM_TO_PIXEL
prymula <prymula76@outlook.com>
parents:
diff changeset
778 img_width = 297 * FACTOR_MM_TO_PIXEL
prymula <prymula76@outlook.com>
parents:
diff changeset
779 #elif self.horizontal == False and self.vertical == True:
prymula <prymula76@outlook.com>
parents:
diff changeset
780 elif self.border_type == "vertical":
prymula <prymula76@outlook.com>
parents:
diff changeset
781
prymula <prymula76@outlook.com>
parents:
diff changeset
782 page_width = 207
prymula <prymula76@outlook.com>
parents:
diff changeset
783 page_height = 297
prymula <prymula76@outlook.com>
parents:
diff changeset
784
prymula <prymula76@outlook.com>
parents:
diff changeset
785 img_width = 207 * FACTOR_MM_TO_PIXEL
prymula <prymula76@outlook.com>
parents:
diff changeset
786 img_height = 297 * FACTOR_MM_TO_PIXEL
prymula <prymula76@outlook.com>
parents:
diff changeset
787
prymula <prymula76@outlook.com>
parents:
diff changeset
788 size = "A4"
prymula <prymula76@outlook.com>
parents:
diff changeset
789
prymula <prymula76@outlook.com>
parents:
diff changeset
790 dpi = 600
prymula <prymula76@outlook.com>
parents:
diff changeset
791
prymula <prymula76@outlook.com>
parents:
diff changeset
792 # z orginalnymi wielkościami nie chce drukowac
prymula <prymula76@outlook.com>
parents:
diff changeset
793 pixbuf2 = self.pixbuf_tmp.scale_simple(img_width, img_height, GdkPixbuf.InterpType.HYPER)
prymula <prymula76@outlook.com>
parents:
diff changeset
794
prymula <prymula76@outlook.com>
parents:
diff changeset
795 pixbuf2.savev("/tmp/photocrop.png","png", ["quailty"], ["100"])
prymula <prymula76@outlook.com>
parents:
diff changeset
796
prymula <prymula76@outlook.com>
parents:
diff changeset
797 #ps = Gtk.PaperSize.new_custom(size, size, self.pixbuf_tmp.get_width(), self.pixbuf_tmp.get_height(), Gtk.Unit.POINTS)
prymula <prymula76@outlook.com>
parents:
diff changeset
798 ps = Gtk.PaperSize.new_custom(size, size, page_width, page_height, Gtk.Unit.MM)
prymula <prymula76@outlook.com>
parents:
diff changeset
799
prymula <prymula76@outlook.com>
parents:
diff changeset
800 print_settings = Gtk.PrintSettings()
prymula <prymula76@outlook.com>
parents:
diff changeset
801 print_settings.set_resolution(dpi)
prymula <prymula76@outlook.com>
parents:
diff changeset
802
prymula <prymula76@outlook.com>
parents:
diff changeset
803 page_setup = Gtk.PageSetup()
prymula <prymula76@outlook.com>
parents:
diff changeset
804 page_setup.set_paper_size(ps)
prymula <prymula76@outlook.com>
parents:
diff changeset
805 page_setup.set_bottom_margin(0.0, Gtk.Unit.MM)
prymula <prymula76@outlook.com>
parents:
diff changeset
806 page_setup.set_left_margin(0.0, Gtk.Unit.MM)
prymula <prymula76@outlook.com>
parents:
diff changeset
807 page_setup.set_right_margin(0.0, Gtk.Unit.MM)
prymula <prymula76@outlook.com>
parents:
diff changeset
808 page_setup.set_top_margin(0.0, Gtk.Unit.MM)
prymula <prymula76@outlook.com>
parents:
diff changeset
809
prymula <prymula76@outlook.com>
parents:
diff changeset
810 #if self.border_type == "horizontal":
prymula <prymula76@outlook.com>
parents:
diff changeset
811 # page_setup.set_orientation(Gtk.PageOrientation.LANDSCAPE)
prymula <prymula76@outlook.com>
parents:
diff changeset
812 #elif self.border_type == "vertical":
prymula <prymula76@outlook.com>
parents:
diff changeset
813 # page_setup.set_orientation(Gtk.PageOrientation.PORTRAIT)
prymula <prymula76@outlook.com>
parents:
diff changeset
814
prymula <prymula76@outlook.com>
parents:
diff changeset
815
prymula <prymula76@outlook.com>
parents:
diff changeset
816 print_operation = Gtk.PrintOperation()
prymula <prymula76@outlook.com>
parents:
diff changeset
817 print_operation.set_unit(Gtk.Unit.POINTS)
prymula <prymula76@outlook.com>
parents:
diff changeset
818 print_operation.set_n_pages(1)
prymula <prymula76@outlook.com>
parents:
diff changeset
819 print_operation.set_default_page_setup(page_setup)
prymula <prymula76@outlook.com>
parents:
diff changeset
820 print_operation.set_print_settings(print_settings)
prymula <prymula76@outlook.com>
parents:
diff changeset
821 print_operation.connect("draw_page", self.print_page)
prymula <prymula76@outlook.com>
parents:
diff changeset
822 #print_operation.set_export_filename("example.pdf")
prymula <prymula76@outlook.com>
parents:
diff changeset
823
prymula <prymula76@outlook.com>
parents:
diff changeset
824 result = print_operation.run(Gtk.PrintOperationAction.PRINT_DIALOG, None) # window zamisat None
prymula <prymula76@outlook.com>
parents:
diff changeset
825
prymula <prymula76@outlook.com>
parents:
diff changeset
826 #result = print_operation.run(Gtk.PrintOperationAction.PREVIEW, None)
prymula <prymula76@outlook.com>
parents:
diff changeset
827 print(result)
prymula <prymula76@outlook.com>
parents:
diff changeset
828
prymula <prymula76@outlook.com>
parents:
diff changeset
829 # przycinamy !
prymula <prymula76@outlook.com>
parents:
diff changeset
830 def photo_crop(self, button):
prymula <prymula76@outlook.com>
parents:
diff changeset
831
prymula <prymula76@outlook.com>
parents:
diff changeset
832 if self.border_x < 0:
prymula <prymula76@outlook.com>
parents:
diff changeset
833 dialog = DialogWarning(self)
prymula <prymula76@outlook.com>
parents:
diff changeset
834 response = dialog.run()
prymula <prymula76@outlook.com>
parents:
diff changeset
835 dialog.destroy()
prymula <prymula76@outlook.com>
parents:
diff changeset
836 return
prymula <prymula76@outlook.com>
parents:
diff changeset
837 if self.border_y < 0:
prymula <prymula76@outlook.com>
parents:
diff changeset
838 dialog = DialogWarning(self)
prymula <prymula76@outlook.com>
parents:
diff changeset
839 response = dialog.run()
prymula <prymula76@outlook.com>
parents:
diff changeset
840 dialog.destroy()
prymula <prymula76@outlook.com>
parents:
diff changeset
841 return
prymula <prymula76@outlook.com>
parents:
diff changeset
842 if self.border_width > self.picture_view_width:
prymula <prymula76@outlook.com>
parents:
diff changeset
843 dialog = DialogWarning(self)
prymula <prymula76@outlook.com>
parents:
diff changeset
844 response = dialog.run()
prymula <prymula76@outlook.com>
parents:
diff changeset
845 dialog.destroy()
prymula <prymula76@outlook.com>
parents:
diff changeset
846 return
prymula <prymula76@outlook.com>
parents:
diff changeset
847 # FIXME - w sumie to jest zastanawiające !?
prymula <prymula76@outlook.com>
parents:
diff changeset
848 if self.border_height + self.border_y > self.picture_view_height:
prymula <prymula76@outlook.com>
parents:
diff changeset
849 dialog = DialogWarning(self)
prymula <prymula76@outlook.com>
parents:
diff changeset
850 response = dialog.run()
prymula <prymula76@outlook.com>
parents:
diff changeset
851 dialog.destroy()
prymula <prymula76@outlook.com>
parents:
diff changeset
852 return
prymula <prymula76@outlook.com>
parents:
diff changeset
853
prymula <prymula76@outlook.com>
parents:
diff changeset
854
prymula <prymula76@outlook.com>
parents:
diff changeset
855 if self.border_x != 0 :
prymula <prymula76@outlook.com>
parents:
diff changeset
856 bx = self.picture_view_width / self.border_x
prymula <prymula76@outlook.com>
parents:
diff changeset
857 crop_x = self.picture_orig_width / bx
prymula <prymula76@outlook.com>
parents:
diff changeset
858 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
859 crop_x = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
860
prymula <prymula76@outlook.com>
parents:
diff changeset
861 if self.border_y != 0:
prymula <prymula76@outlook.com>
parents:
diff changeset
862 by = self.picture_view_height / self.border_y
prymula <prymula76@outlook.com>
parents:
diff changeset
863 crop_y = self.picture_orig_height / by
prymula <prymula76@outlook.com>
parents:
diff changeset
864 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
865 crop_y = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
866
prymula <prymula76@outlook.com>
parents:
diff changeset
867 bw = self.picture_view_width / self.border_width
prymula <prymula76@outlook.com>
parents:
diff changeset
868 crop_width = self.picture_orig_width / bw - crop_x
prymula <prymula76@outlook.com>
parents:
diff changeset
869
prymula <prymula76@outlook.com>
parents:
diff changeset
870 bh = self.picture_view_height / self.border_height
prymula <prymula76@outlook.com>
parents:
diff changeset
871 crop_height = self.picture_orig_height / bh
prymula <prymula76@outlook.com>
parents:
diff changeset
872
prymula <prymula76@outlook.com>
parents:
diff changeset
873
prymula <prymula76@outlook.com>
parents:
diff changeset
874 # False - kanał Alpha
prymula <prymula76@outlook.com>
parents:
diff changeset
875 self.pixbuf_tmp = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, False, 8, crop_width, crop_height)
prymula <prymula76@outlook.com>
parents:
diff changeset
876
prymula <prymula76@outlook.com>
parents:
diff changeset
877 # zera na koncu to dest_x i dest_y
prymula <prymula76@outlook.com>
parents:
diff changeset
878 self.pixbuf_orig.copy_area(crop_x, crop_y, crop_width, crop_height, self.pixbuf_tmp, 0, 0)
prymula <prymula76@outlook.com>
parents:
diff changeset
879
prymula <prymula76@outlook.com>
parents:
diff changeset
880 if rotate == False:
prymula <prymula76@outlook.com>
parents:
diff changeset
881
prymula <prymula76@outlook.com>
parents:
diff changeset
882 self.picture_tmp_width = float(self.pixbuf_tmp.get_width())
prymula <prymula76@outlook.com>
parents:
diff changeset
883 self.picture_tmp_height = float(self.pixbuf_tmp.get_height())
prymula <prymula76@outlook.com>
parents:
diff changeset
884
prymula <prymula76@outlook.com>
parents:
diff changeset
885 # tym razem przeliczamy z uwzględnieniem bufora tymczasowego
prymula <prymula76@outlook.com>
parents:
diff changeset
886 if self.picture_tmp_width > self.picture_tmp_height:
prymula <prymula76@outlook.com>
parents:
diff changeset
887 self.picture_view_width = 586.66
prymula <prymula76@outlook.com>
parents:
diff changeset
888 m = self.picture_tmp_width / 586.66
prymula <prymula76@outlook.com>
parents:
diff changeset
889 self.picture_view_height = self.picture_tmp_height/m
prymula <prymula76@outlook.com>
parents:
diff changeset
890 if self.picture_tmp_height > self.picture_tmp_width:
prymula <prymula76@outlook.com>
parents:
diff changeset
891 self.picture_view_height = 586.66
prymula <prymula76@outlook.com>
parents:
diff changeset
892 m = self.picture_tmp_height / 586.66
prymula <prymula76@outlook.com>
parents:
diff changeset
893 self.picture_view_width = self.picture_tmp_width/m
prymula <prymula76@outlook.com>
parents:
diff changeset
894
prymula <prymula76@outlook.com>
parents:
diff changeset
895
prymula <prymula76@outlook.com>
parents:
diff changeset
896
prymula <prymula76@outlook.com>
parents:
diff changeset
897 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
898 self.set_ratio_picture_view_after_rotation()
prymula <prymula76@outlook.com>
parents:
diff changeset
899
prymula <prymula76@outlook.com>
parents:
diff changeset
900 self.drawing_area.set_size_request(self.picture_view_width, self.picture_view_height)
prymula <prymula76@outlook.com>
parents:
diff changeset
901 self.drawing_area.set_events(Gdk.EventMask.ALL_EVENTS_MASK)
prymula <prymula76@outlook.com>
parents:
diff changeset
902
prymula <prymula76@outlook.com>
parents:
diff changeset
903 self.pixbuf_view = self.pixbuf_tmp.scale_simple(self.picture_view_width, self.picture_view_height, GdkPixbuf.InterpType.HYPER)
prymula <prymula76@outlook.com>
parents:
diff changeset
904
prymula <prymula76@outlook.com>
parents:
diff changeset
905 self.picture_view_x = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
906 self.picture_view_y = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
907
prymula <prymula76@outlook.com>
parents:
diff changeset
908 self.border_visible = False
prymula <prymula76@outlook.com>
parents:
diff changeset
909
prymula <prymula76@outlook.com>
parents:
diff changeset
910 self.drawing_area.queue_draw()
prymula <prymula76@outlook.com>
parents:
diff changeset
911
prymula <prymula76@outlook.com>
parents:
diff changeset
912 # przywracamy
prymula <prymula76@outlook.com>
parents:
diff changeset
913 def photo_restore(self, button):
prymula <prymula76@outlook.com>
parents:
diff changeset
914
prymula <prymula76@outlook.com>
parents:
diff changeset
915 self.border_visible = True
prymula <prymula76@outlook.com>
parents:
diff changeset
916
prymula <prymula76@outlook.com>
parents:
diff changeset
917 self.set_ratio_picture_view()
prymula <prymula76@outlook.com>
parents:
diff changeset
918 self.pixbuf_view = self.pixbuf_orig.scale_simple(self.orig_ratio_width, self.orig_ratio_height, GdkPixbuf.InterpType.BILINEAR)
prymula <prymula76@outlook.com>
parents:
diff changeset
919
prymula <prymula76@outlook.com>
parents:
diff changeset
920 self.drawing_area.set_size_request(self.orig_ratio_width, self.orig_ratio_height)
prymula <prymula76@outlook.com>
parents:
diff changeset
921 self.drawing_area.set_events(Gdk.EventMask.ALL_EVENTS_MASK)
prymula <prymula76@outlook.com>
parents:
diff changeset
922 self.pixbuf_tmp = None # uniemożliwiamy zapis
prymula <prymula76@outlook.com>
parents:
diff changeset
923 self.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
924
prymula <prymula76@outlook.com>
parents:
diff changeset
925 self.drawing_area.queue_draw()
prymula <prymula76@outlook.com>
parents:
diff changeset
926
prymula <prymula76@outlook.com>
parents:
diff changeset
927
prymula <prymula76@outlook.com>
parents:
diff changeset
928 def on_format_combo_changed(self, combo):
prymula <prymula76@outlook.com>
parents:
diff changeset
929 tree_iter = combo.get_active_iter()
prymula <prymula76@outlook.com>
parents:
diff changeset
930 if tree_iter is not None:
prymula <prymula76@outlook.com>
parents:
diff changeset
931 model = combo.get_model()
prymula <prymula76@outlook.com>
parents:
diff changeset
932 self.format_size = model[tree_iter][0]
prymula <prymula76@outlook.com>
parents:
diff changeset
933 print("Selected: format=%s" % self.format_size)
prymula <prymula76@outlook.com>
parents:
diff changeset
934
prymula <prymula76@outlook.com>
parents:
diff changeset
935 self.set_ratio_border_size()
prymula <prymula76@outlook.com>
parents:
diff changeset
936
prymula <prymula76@outlook.com>
parents:
diff changeset
937 self.drawing_area.queue_draw()
prymula <prymula76@outlook.com>
parents:
diff changeset
938
prymula <prymula76@outlook.com>
parents:
diff changeset
939 def on_scroll(self, widget, event):
prymula <prymula76@outlook.com>
parents:
diff changeset
940 """ handles on scroll event"""
prymula <prymula76@outlook.com>
parents:
diff changeset
941 # Handles zoom in / zoom out on Ctrl+mouse wheel
prymula <prymula76@outlook.com>
parents:
diff changeset
942 accel_mask = Gtk.accelerator_get_default_mod_mask()
prymula <prymula76@outlook.com>
parents:
diff changeset
943 if event.state & accel_mask == Gdk.ModifierType.CONTROL_MASK:
prymula <prymula76@outlook.com>
parents:
diff changeset
944 direction = event.get_scroll_deltas()[2]
prymula <prymula76@outlook.com>
parents:
diff changeset
945
prymula <prymula76@outlook.com>
parents:
diff changeset
946 if direction > 0:
prymula <prymula76@outlook.com>
parents:
diff changeset
947 scrolling = "zoom_out"
prymula <prymula76@outlook.com>
parents:
diff changeset
948 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
949 scrolling = "zoom_in"
prymula <prymula76@outlook.com>
parents:
diff changeset
950
prymula <prymula76@outlook.com>
parents:
diff changeset
951 self.border_height += self.border_properties[self.format_size][self.border_type][scrolling]["height"]
prymula <prymula76@outlook.com>
parents:
diff changeset
952 self.border_width += self.border_properties[self.format_size][self.border_type][scrolling]["width"]
prymula <prymula76@outlook.com>
parents:
diff changeset
953 """
prymula <prymula76@outlook.com>
parents:
diff changeset
954 # tu jest jakiś błąd
prymula <prymula76@outlook.com>
parents:
diff changeset
955 if self.border_width > self.picture_view_width:
prymula <prymula76@outlook.com>
parents:
diff changeset
956 self.border_width -= 1
prymula <prymula76@outlook.com>
parents:
diff changeset
957 if self.border_height+self.border_y > self.picture_view_height:
prymula <prymula76@outlook.com>
parents:
diff changeset
958 self.border_height -= 1
prymula <prymula76@outlook.com>
parents:
diff changeset
959 """
prymula <prymula76@outlook.com>
parents:
diff changeset
960 self.drawing_area.queue_draw()
prymula <prymula76@outlook.com>
parents:
diff changeset
961
prymula <prymula76@outlook.com>
parents:
diff changeset
962 def unclick_in_drawing_area (self, box, event):
prymula <prymula76@outlook.com>
parents:
diff changeset
963 self.button_press = False
prymula <prymula76@outlook.com>
parents:
diff changeset
964 print ("Przycisk myszki puszczony")
prymula <prymula76@outlook.com>
parents:
diff changeset
965
prymula <prymula76@outlook.com>
parents:
diff changeset
966
prymula <prymula76@outlook.com>
parents:
diff changeset
967 def onclick_in_drawing_area (self, box, event):
prymula <prymula76@outlook.com>
parents:
diff changeset
968 if event.button == 1:
prymula <prymula76@outlook.com>
parents:
diff changeset
969 self.button_press = True
prymula <prymula76@outlook.com>
parents:
diff changeset
970 print ("Lewy przyciski myszki naciśnięty")
prymula <prymula76@outlook.com>
parents:
diff changeset
971
prymula <prymula76@outlook.com>
parents:
diff changeset
972 def on_mouse_move_in_drawing_area(self, box, event):
prymula <prymula76@outlook.com>
parents:
diff changeset
973
prymula <prymula76@outlook.com>
parents:
diff changeset
974
prymula <prymula76@outlook.com>
parents:
diff changeset
975 if self.button_press == True:
prymula <prymula76@outlook.com>
parents:
diff changeset
976
prymula <prymula76@outlook.com>
parents:
diff changeset
977 if self.border_type == "vertical":
prymula <prymula76@outlook.com>
parents:
diff changeset
978
prymula <prymula76@outlook.com>
parents:
diff changeset
979 #print ("VERTICAL %%")
prymula <prymula76@outlook.com>
parents:
diff changeset
980
prymula <prymula76@outlook.com>
parents:
diff changeset
981 if self.last_x < event.x:
prymula <prymula76@outlook.com>
parents:
diff changeset
982 self.border_x += 1
prymula <prymula76@outlook.com>
parents:
diff changeset
983 self.border_width += 1
prymula <prymula76@outlook.com>
parents:
diff changeset
984 if event.x < self.last_x:
prymula <prymula76@outlook.com>
parents:
diff changeset
985 self.border_x -= 1
prymula <prymula76@outlook.com>
parents:
diff changeset
986 self.border_width -= 1
prymula <prymula76@outlook.com>
parents:
diff changeset
987 if self.last_y < event.y:
prymula <prymula76@outlook.com>
parents:
diff changeset
988 self.border_y += 1
prymula <prymula76@outlook.com>
parents:
diff changeset
989 self.border_height += 0.0
prymula <prymula76@outlook.com>
parents:
diff changeset
990 if event.y < self.last_y:
prymula <prymula76@outlook.com>
parents:
diff changeset
991 self.border_y -= 1
prymula <prymula76@outlook.com>
parents:
diff changeset
992 self.border_height -= 0.0
prymula <prymula76@outlook.com>
parents:
diff changeset
993
prymula <prymula76@outlook.com>
parents:
diff changeset
994 elif self.border_type == "horizontal":
prymula <prymula76@outlook.com>
parents:
diff changeset
995 #print ("Horizontal %%")
prymula <prymula76@outlook.com>
parents:
diff changeset
996 if self.last_x < event.x:
prymula <prymula76@outlook.com>
parents:
diff changeset
997 self.border_x += 1
prymula <prymula76@outlook.com>
parents:
diff changeset
998 self.border_width += 1
prymula <prymula76@outlook.com>
parents:
diff changeset
999 if event.x < self.last_x:
prymula <prymula76@outlook.com>
parents:
diff changeset
1000 self.border_x -= 1.
prymula <prymula76@outlook.com>
parents:
diff changeset
1001 self.border_width -= 1
prymula <prymula76@outlook.com>
parents:
diff changeset
1002 if self.last_y < event.y:
prymula <prymula76@outlook.com>
parents:
diff changeset
1003 self.border_y += 1
prymula <prymula76@outlook.com>
parents:
diff changeset
1004 self.border_height += 0.0
prymula <prymula76@outlook.com>
parents:
diff changeset
1005 if event.y < self.last_y:
prymula <prymula76@outlook.com>
parents:
diff changeset
1006 self.border_y -= 1
prymula <prymula76@outlook.com>
parents:
diff changeset
1007 self.border_height -= 0.0
prymula <prymula76@outlook.com>
parents:
diff changeset
1008
prymula <prymula76@outlook.com>
parents:
diff changeset
1009 self.last_y = event.y
prymula <prymula76@outlook.com>
parents:
diff changeset
1010 self.last_x = event.x
prymula <prymula76@outlook.com>
parents:
diff changeset
1011 """
prymula <prymula76@outlook.com>
parents:
diff changeset
1012 # jeśli będzie się napierać na skraj krawędzi wówczas powiększa ramkę
prymula <prymula76@outlook.com>
parents:
diff changeset
1013 if self.border_x < 0:
prymula <prymula76@outlook.com>
parents:
diff changeset
1014 self.border_x += 1
prymula <prymula76@outlook.com>
parents:
diff changeset
1015 self.border_width += 1
prymula <prymula76@outlook.com>
parents:
diff changeset
1016 if self.border_y < 0:
prymula <prymula76@outlook.com>
parents:
diff changeset
1017 self.border_y += 1
prymula <prymula76@outlook.com>
parents:
diff changeset
1018 self.border_height +=1
prymula <prymula76@outlook.com>
parents:
diff changeset
1019 # tu jest jakiś błąd
prymula <prymula76@outlook.com>
parents:
diff changeset
1020
prymula <prymula76@outlook.com>
parents:
diff changeset
1021 # powoduje błędne zachowanie ramki
prymula <prymula76@outlook.com>
parents:
diff changeset
1022 if self.border_type == "vertical":
prymula <prymula76@outlook.com>
parents:
diff changeset
1023 if self.border_width > self.picture_view_width:
prymula <prymula76@outlook.com>
parents:
diff changeset
1024 self.border_width -= 1
prymula <prymula76@outlook.com>
parents:
diff changeset
1025 self.border_x -= 1
prymula <prymula76@outlook.com>
parents:
diff changeset
1026 if self.border_height+self.border_y > self.picture_view_height:
prymula <prymula76@outlook.com>
parents:
diff changeset
1027 self.border_height -= 1
prymula <prymula76@outlook.com>
parents:
diff changeset
1028 self.border_y -= 1
prymula <prymula76@outlook.com>
parents:
diff changeset
1029 elif self.border_type == "horizontal":
prymula <prymula76@outlook.com>
parents:
diff changeset
1030 if self.border_height+self.border_y> self.picture_view_width:
prymula <prymula76@outlook.com>
parents:
diff changeset
1031 self.border_width -= 1
prymula <prymula76@outlook.com>
parents:
diff changeset
1032 self.border_x -= 1
prymula <prymula76@outlook.com>
parents:
diff changeset
1033 if self.border_width > self.picture_view_height:
prymula <prymula76@outlook.com>
parents:
diff changeset
1034 self.border_height -= 1
prymula <prymula76@outlook.com>
parents:
diff changeset
1035 self.border_y -= 1
prymula <prymula76@outlook.com>
parents:
diff changeset
1036 """
prymula <prymula76@outlook.com>
parents:
diff changeset
1037
prymula <prymula76@outlook.com>
parents:
diff changeset
1038 self.drawing_area.queue_draw()
prymula <prymula76@outlook.com>
parents:
diff changeset
1039
prymula <prymula76@outlook.com>
parents:
diff changeset
1040 def init_ui(self):
prymula <prymula76@outlook.com>
parents:
diff changeset
1041 # JPG akceptuje jedynie z GIMPa
prymula <prymula76@outlook.com>
parents:
diff changeset
1042 self.border_properties = { "10x15" : { "horizontal" : { "zoom_out" : {"width" : -1.48, "height" : -0.92}, "zoom_in" : {"width" : 1.48, "height" : 0.92}},
prymula <prymula76@outlook.com>
parents:
diff changeset
1043 "vertical" : { "zoom_out": { "width" : -0.92, "height" : -1.48}, "zoom_in": { "width" : 0.92, "height" : 1.48}},
prymula <prymula76@outlook.com>
parents:
diff changeset
1044 "square" : { "zoom_out" : { "width" : -1, "height" : -1}, "zoom_out" : { "width" : 1, "height" : 1}}},
prymula <prymula76@outlook.com>
parents:
diff changeset
1045
prymula <prymula76@outlook.com>
parents:
diff changeset
1046 "13x18" : { "horizontal" : { "zoom_out" : {"width" : -1.82, "height" : -1.30}, "zoom_in" : {"width" : 1.82, "height" : 1.30}},
prymula <prymula76@outlook.com>
parents:
diff changeset
1047 "vertical" : { "zoom_out": { "width" : -1.30, "height" : -1.78}, "zoom_in": { "width" : 1.30, "height" : 1.78}},
prymula <prymula76@outlook.com>
parents:
diff changeset
1048 "square" : { "zoom_out" : { "width" : -1, "height" : -1}, "zoom_out" : { "width" : 1, "height" : 1}}},
prymula <prymula76@outlook.com>
parents:
diff changeset
1049
prymula <prymula76@outlook.com>
parents:
diff changeset
1050 "A4" : { "horizontal" : { "zoom_out" : {"width" : -2.97, "height" : -1.84}, "zoom_in" : {"width" : 2.97, "height" : 1.84}},
prymula <prymula76@outlook.com>
parents:
diff changeset
1051 "vertical" : { "zoom_out": { "width" : -1.84, "height" : -2.97}, "zoom_in": { "width" : 1.84, "height" : 2.97}},
prymula <prymula76@outlook.com>
parents:
diff changeset
1052 "square" : { "zoom_out" : { "width" : -1, "height" : -1}, "zoom_out" : { "width" : 1, "height" : 1}}}}
prymula <prymula76@outlook.com>
parents:
diff changeset
1053
prymula <prymula76@outlook.com>
parents:
diff changeset
1054
prymula <prymula76@outlook.com>
parents:
diff changeset
1055 #self.props.border_width = 20
prymula <prymula76@outlook.com>
parents:
diff changeset
1056 self.add(grid)
prymula <prymula76@outlook.com>
parents:
diff changeset
1057 self.pixbuf_tmp = None
prymula <prymula76@outlook.com>
parents:
diff changeset
1058 grid.set_row_spacing(10)
prymula <prymula76@outlook.com>
parents:
diff changeset
1059 grid.set_column_spacing(10)
prymula <prymula76@outlook.com>
parents:
diff changeset
1060 grid.set_column_homogeneous(True) # rozszerza kontrolki na resztę okna
prymula <prymula76@outlook.com>
parents:
diff changeset
1061
prymula <prymula76@outlook.com>
parents:
diff changeset
1062 action_group = Gtk.ActionGroup(name="my_actions")
prymula <prymula76@outlook.com>
parents:
diff changeset
1063
prymula <prymula76@outlook.com>
parents:
diff changeset
1064 self.add_file_menu_actions(action_group)
prymula <prymula76@outlook.com>
parents:
diff changeset
1065 self.add_edit_menu_actions(action_group)
prymula <prymula76@outlook.com>
parents:
diff changeset
1066 self.add_info_menu_actions(action_group)
prymula <prymula76@outlook.com>
parents:
diff changeset
1067
prymula <prymula76@outlook.com>
parents:
diff changeset
1068 uimanager = self.create_ui_manager()
prymula <prymula76@outlook.com>
parents:
diff changeset
1069 uimanager.insert_action_group(action_group)
prymula <prymula76@outlook.com>
parents:
diff changeset
1070
prymula <prymula76@outlook.com>
parents:
diff changeset
1071 menubar = uimanager.get_widget("/MenuBar")
prymula <prymula76@outlook.com>
parents:
diff changeset
1072 box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
prymula <prymula76@outlook.com>
parents:
diff changeset
1073 box.pack_start(menubar, False, False, 0)
prymula <prymula76@outlook.com>
parents:
diff changeset
1074
prymula <prymula76@outlook.com>
parents:
diff changeset
1075 grid.attach(box, 0, 0, 3, 1)
prymula <prymula76@outlook.com>
parents:
diff changeset
1076
prymula <prymula76@outlook.com>
parents:
diff changeset
1077
prymula <prymula76@outlook.com>
parents:
diff changeset
1078 file_img_selected=get_resource_path("/usr/share/photocrop/IMG_6854.JPG") #img/blank.png
prymula <prymula76@outlook.com>
parents:
diff changeset
1079 self.pixbuf_orig = GdkPixbuf.Pixbuf.new_from_file(filename=file_img_selected)
prymula <prymula76@outlook.com>
parents:
diff changeset
1080
prymula <prymula76@outlook.com>
parents:
diff changeset
1081 self.format_size = "10x15"
prymula <prymula76@outlook.com>
parents:
diff changeset
1082 self.set_ratio_picture_view()
prymula <prymula76@outlook.com>
parents:
diff changeset
1083 self.pixbuf_view = self.pixbuf_orig.scale_simple(self.picture_view_width, self.picture_view_height, GdkPixbuf.InterpType.HYPER)
prymula <prymula76@outlook.com>
parents:
diff changeset
1084
prymula <prymula76@outlook.com>
parents:
diff changeset
1085 self.border_visible = True
prymula <prymula76@outlook.com>
parents:
diff changeset
1086
prymula <prymula76@outlook.com>
parents:
diff changeset
1087 if self.picture_view_width > self.picture_view_height:
prymula <prymula76@outlook.com>
parents:
diff changeset
1088 self.horizontal = True
prymula <prymula76@outlook.com>
parents:
diff changeset
1089 self.vertical = False
prymula <prymula76@outlook.com>
parents:
diff changeset
1090 self.look = "horizontal"
prymula <prymula76@outlook.com>
parents:
diff changeset
1091 self.border_type = "horizontal"
prymula <prymula76@outlook.com>
parents:
diff changeset
1092 elif self.picture_view_height > self.picture_view_width:
prymula <prymula76@outlook.com>
parents:
diff changeset
1093 self.vertical = True
prymula <prymula76@outlook.com>
parents:
diff changeset
1094 self.horizontal = False
prymula <prymula76@outlook.com>
parents:
diff changeset
1095 self.look = "vertical"
prymula <prymula76@outlook.com>
parents:
diff changeset
1096 self.border_type = "vertical"
prymula <prymula76@outlook.com>
parents:
diff changeset
1097 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
1098 self.horizontal = False
prymula <prymula76@outlook.com>
parents:
diff changeset
1099 self.vertical = False
prymula <prymula76@outlook.com>
parents:
diff changeset
1100 self.look = "square"
prymula <prymula76@outlook.com>
parents:
diff changeset
1101
prymula <prymula76@outlook.com>
parents:
diff changeset
1102 self.drawing_area = Gtk.DrawingArea()
prymula <prymula76@outlook.com>
parents:
diff changeset
1103
prymula <prymula76@outlook.com>
parents:
diff changeset
1104 self.drawing_area.set_size_request(self.pixbuf_view.get_width(), self.pixbuf_view.get_height())
prymula <prymula76@outlook.com>
parents:
diff changeset
1105 self.drawing_area.set_events(Gdk.EventMask.ALL_EVENTS_MASK)
prymula <prymula76@outlook.com>
parents:
diff changeset
1106
prymula <prymula76@outlook.com>
parents:
diff changeset
1107 self.drawing_area.connect("draw", self.on_drawing_area_draw)
prymula <prymula76@outlook.com>
parents:
diff changeset
1108
prymula <prymula76@outlook.com>
parents:
diff changeset
1109 frame = Gtk.Frame()
prymula <prymula76@outlook.com>
parents:
diff changeset
1110 event_box = Gtk.EventBox ()
prymula <prymula76@outlook.com>
parents:
diff changeset
1111 self.last_x = 1
prymula <prymula76@outlook.com>
parents:
diff changeset
1112 self.last_y = 1
prymula <prymula76@outlook.com>
parents:
diff changeset
1113 self.border_x = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
1114 self.border_y = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
1115 self.button_press = False
prymula <prymula76@outlook.com>
parents:
diff changeset
1116 self.pixbuf_tmp = None
prymula <prymula76@outlook.com>
parents:
diff changeset
1117 event_box.connect ('button-press-event', self.onclick_in_drawing_area)
prymula <prymula76@outlook.com>
parents:
diff changeset
1118 event_box.connect ('button-release-event', self.unclick_in_drawing_area)
prymula <prymula76@outlook.com>
parents:
diff changeset
1119 event_box.connect("motion-notify-event", self.on_mouse_move_in_drawing_area)
prymula <prymula76@outlook.com>
parents:
diff changeset
1120 event_box.add_events(Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.BUTTON_PRESS_MASK)
prymula <prymula76@outlook.com>
parents:
diff changeset
1121
prymula <prymula76@outlook.com>
parents:
diff changeset
1122 event_box.add(self.drawing_area)
prymula <prymula76@outlook.com>
parents:
diff changeset
1123 frame.add(event_box)
prymula <prymula76@outlook.com>
parents:
diff changeset
1124 grid.attach(frame,0,1,3,1)
prymula <prymula76@outlook.com>
parents:
diff changeset
1125
prymula <prymula76@outlook.com>
parents:
diff changeset
1126 button1 = Gtk.Button.new_with_label("Crop")
prymula <prymula76@outlook.com>
parents:
diff changeset
1127 button1.connect("clicked", self.photo_crop)
prymula <prymula76@outlook.com>
parents:
diff changeset
1128 grid.attach(button1,0,4,1,1)
prymula <prymula76@outlook.com>
parents:
diff changeset
1129
prymula <prymula76@outlook.com>
parents:
diff changeset
1130 button2 = Gtk.Button.new_with_label("Restore")
prymula <prymula76@outlook.com>
parents:
diff changeset
1131 button2.connect("clicked", self.photo_restore)
prymula <prymula76@outlook.com>
parents:
diff changeset
1132 grid.attach(button2,1,4,1,1)
prymula <prymula76@outlook.com>
parents:
diff changeset
1133
prymula <prymula76@outlook.com>
parents:
diff changeset
1134 format_store = Gtk.ListStore(str)
prymula <prymula76@outlook.com>
parents:
diff changeset
1135 format_photo = [
prymula <prymula76@outlook.com>
parents:
diff changeset
1136 "10x15",
prymula <prymula76@outlook.com>
parents:
diff changeset
1137 "13x18",
prymula <prymula76@outlook.com>
parents:
diff changeset
1138 "A4",
prymula <prymula76@outlook.com>
parents:
diff changeset
1139 ]
prymula <prymula76@outlook.com>
parents:
diff changeset
1140 for fp in format_photo:
prymula <prymula76@outlook.com>
parents:
diff changeset
1141 format_store.append([fp])
prymula <prymula76@outlook.com>
parents:
diff changeset
1142
prymula <prymula76@outlook.com>
parents:
diff changeset
1143 format_combo = Gtk.ComboBox.new_with_model(format_store)
prymula <prymula76@outlook.com>
parents:
diff changeset
1144 format_combo.connect("changed", self.on_format_combo_changed)
prymula <prymula76@outlook.com>
parents:
diff changeset
1145 renderer_text = Gtk.CellRendererText()
prymula <prymula76@outlook.com>
parents:
diff changeset
1146 format_combo.pack_start(renderer_text, True)
prymula <prymula76@outlook.com>
parents:
diff changeset
1147 format_combo.add_attribute(renderer_text, "text", 0)
prymula <prymula76@outlook.com>
parents:
diff changeset
1148 format_combo.set_active(0)
prymula <prymula76@outlook.com>
parents:
diff changeset
1149 grid.attach(format_combo,2,4,1,1)
prymula <prymula76@outlook.com>
parents:
diff changeset
1150
prymula <prymula76@outlook.com>
parents:
diff changeset
1151 self.drawing_area.connect('scroll-event', self.on_scroll)
prymula <prymula76@outlook.com>
parents:
diff changeset
1152
prymula <prymula76@outlook.com>
parents:
diff changeset
1153 self.set_border_width(10)
prymula <prymula76@outlook.com>
parents:
diff changeset
1154 self.set_title("Photo Crop (alpha)")
prymula <prymula76@outlook.com>
parents:
diff changeset
1155 #self.set_default_size(700, 600)
prymula <prymula76@outlook.com>
parents:
diff changeset
1156 #self.resize(700, 600)
prymula <prymula76@outlook.com>
parents:
diff changeset
1157 self.set_resizable(False)
prymula <prymula76@outlook.com>
parents:
diff changeset
1158 self.connect("destroy", Gtk.main_quit)
prymula <prymula76@outlook.com>
parents:
diff changeset
1159
prymula <prymula76@outlook.com>
parents:
diff changeset
1160
prymula <prymula76@outlook.com>
parents:
diff changeset
1161
prymula <prymula76@outlook.com>
parents:
diff changeset
1162 win = MyWindow()
prymula <prymula76@outlook.com>
parents:
diff changeset
1163 win.show_all()
prymula <prymula76@outlook.com>
parents:
diff changeset
1164 Gtk.main()