From 27cae9ed099f8f3921c67dccae8cceade12e3556 Mon Sep 17 00:00:00 2001 From: Stefano Tribioli Date: Sat, 24 Sep 2016 14:29:45 +0200 Subject: [PATCH 1/2] Column number override Introduces a new option to manually set the number of columns in the layout. If 0, the usual autosensing applies. Layout is now regenerated every time the SettingsDialog is closed with ok. This might be unwanted. --- photocollage/gtkgui.py | 48 ++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/photocollage/gtkgui.py b/photocollage/gtkgui.py index f25746c..b238be4 100644 --- a/photocollage/gtkgui.py +++ b/photocollage/gtkgui.py @@ -130,18 +130,21 @@ def make_page(self, opts): # Define the output image height / width ratio ratio = 1.0 * opts.out_h / opts.out_w - # Compute a good number of columns. It depends on the ratio, the number - # of images and the average ratio of these images. According to my - # calculations, the number of column should be inversely proportional - # to the square root of the output image ratio, and proportional to the - # square root of the average input images ratio. - avg_ratio = (sum(1.0 * photo.h / photo.w for photo in self.photolist) / - len(self.photolist)) - # Virtual number of images: since ~ 1 image over 3 is in a multi-cell - # (i.e. takes two columns), it takes the space of 4 images. - # So it's equivalent to 1/3 * 4 + 2/3 = 2 times the number of images. - virtual_no_imgs = 2 * len(self.photolist) - no_cols = int(round(math.sqrt(avg_ratio / ratio * virtual_no_imgs))) + if opts.cols == 0: + # Compute a good number of columns. It depends on the ratio, the number + # of images and the average ratio of these images. According to my + # calculations, the number of column should be inversely proportional + # to the square root of the output image ratio, and proportional to the + # square root of the average input images ratio. + avg_ratio = (sum(1.0 * photo.h / photo.w for photo in self.photolist) / + len(self.photolist)) + # Virtual number of images: since ~ 1 image over 3 is in a multi-cell + # (i.e. takes two columns), it takes the space of 4 images. + # So it's equivalent to 1/3 * 4 + 2/3 = 2 times the number of images. + virtual_no_imgs = 2 * len(self.photolist) + no_cols = int(round(math.sqrt(avg_ratio / ratio * virtual_no_imgs))) + else: + no_cols = opts.cols self.page = collage.Page(1.0, ratio, no_cols) random.shuffle(self.photolist) @@ -168,6 +171,7 @@ def __init__(self): self.border_c = "black" self.out_w = 800 self.out_h = 600 + self.cols = 0 self.opts = Options() @@ -385,7 +389,7 @@ def set_settings(self, button): dialog.apply_opts(self.opts) dialog.destroy() if self.history: - self.render_preview() + self.regenerate_layout() else: dialog.destroy() @@ -708,6 +712,22 @@ def apply_template(combo): vbox.pack_start(Gtk.SeparatorToolItem(), True, True, 0) + label = Gtk.Label(xalign=0) + label.set_markup("%s" % _("Layout")) + vbox.pack_start(label, False, False, 0) + + box = Gtk.Box(spacing=6) + vbox.pack_start(box, False, False, 0) + label = Gtk.Label(_("Columns:"), xalign=0) + box.pack_start(label, False, False, 0) + self.etr_cols = Gtk.Entry(text=str(parent.opts.cols)) + self.etr_cols.connect("changed", self.validate_int) + self.etr_cols.last_valid_text = self.etr_cols.get_text() + self.etr_cols.set_width_chars(2) + box.pack_start(self.etr_cols, False, False, 0) + + vbox.pack_start(Gtk.SeparatorToolItem(), True, True, 0) + self.show_all() def validate_int(self, entry): @@ -731,6 +751,8 @@ def apply_opts(self, opts): opts.out_h = int(self.etr_outh.get_text() or '1') opts.border_w = float(self.etr_border.get_text() or '0') / 100.0 opts.border_c = self.colorbutton.get_rgba().to_string() + opts.cols = int(self.etr_cols.get_text() or '0') + class ComputingDialog(Gtk.Dialog): From 1e48adb628f781e97453b90f5b5b56c9063d75dd Mon Sep 17 00:00:00 2001 From: Stefano Tribioli Date: Sat, 24 Sep 2016 15:06:18 +0200 Subject: [PATCH 2/2] Reflowing for PEP8 compliance --- photocollage/gtkgui.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/photocollage/gtkgui.py b/photocollage/gtkgui.py index b238be4..95bad2a 100644 --- a/photocollage/gtkgui.py +++ b/photocollage/gtkgui.py @@ -131,18 +131,22 @@ def make_page(self, opts): ratio = 1.0 * opts.out_h / opts.out_w if opts.cols == 0: - # Compute a good number of columns. It depends on the ratio, the number - # of images and the average ratio of these images. According to my - # calculations, the number of column should be inversely proportional - # to the square root of the output image ratio, and proportional to the - # square root of the average input images ratio. - avg_ratio = (sum(1.0 * photo.h / photo.w for photo in self.photolist) / - len(self.photolist)) - # Virtual number of images: since ~ 1 image over 3 is in a multi-cell - # (i.e. takes two columns), it takes the space of 4 images. - # So it's equivalent to 1/3 * 4 + 2/3 = 2 times the number of images. + # Compute a good number of columns. It depends on the ratio, the + # number of images and the average ratio of these images. According + # to my calculations, the number of column should be inversely + # proportional to the square root of the output image ratio, and + # proportional to the square root of the average input images + # ratio. + avg_ratio = (sum(1.0 * photo.h / photo.w for photo in + self.photolist) / len(self.photolist)) + # Virtual number of images: since ~ 1 image over 3 is in a + # multi-cell (i.e. takes two columns), it takes the space of 4 + # images. + # So it's equivalent to 1/3 * 4 + 2/3 = 2 times the number of + # images. virtual_no_imgs = 2 * len(self.photolist) - no_cols = int(round(math.sqrt(avg_ratio / ratio * virtual_no_imgs))) + no_cols = int(round(math.sqrt(avg_ratio / ratio * + virtual_no_imgs))) else: no_cols = opts.cols @@ -754,7 +758,6 @@ def apply_opts(self, opts): opts.cols = int(self.etr_cols.get_text() or '0') - class ComputingDialog(Gtk.Dialog): """Simple "please wait" dialog, with a "cancel" button""" def __init__(self, parent):