Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Column number override #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 38 additions & 13 deletions photocollage/gtkgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,25 @@ 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)
Expand All @@ -168,6 +175,7 @@ def __init__(self):
self.border_c = "black"
self.out_w = 800
self.out_h = 600
self.cols = 0

self.opts = Options()

Expand Down Expand Up @@ -385,7 +393,7 @@ def set_settings(self, button):
dialog.apply_opts(self.opts)
dialog.destroy()
if self.history:
self.render_preview()
self.regenerate_layout()
Copy link
Owner

@adrienverge adrienverge Sep 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please regenerate layout only if the number of cols changed. Users don't want their collage to change if they just chose a different border color.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adrienverge, I see that it has not been decided for a long time. I can reopen this PR with line self.regenerate_layout() instead of self.render_preview(). Ok?

Copy link
Owner

@adrienverge adrienverge Jul 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andreynovikov95 I'm not sure it's a good idea, as this PR would bring more complexity to the tool, which is not needed here. But thanks for proposing!

else:
dialog.destroy()

Expand Down Expand Up @@ -708,6 +716,22 @@ def apply_template(combo):

vbox.pack_start(Gtk.SeparatorToolItem(), True, True, 0)

label = Gtk.Label(xalign=0)
label.set_markup("<big><b>%s</b></big>" % _("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):
Expand All @@ -731,6 +755,7 @@ 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):
Expand Down