Scribusoid

Author Topic: Some questions about my Typographic_grid_wizard script  (Read 684 times)

rafferty

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
  • Scribus User
Some questions about my Typographic_grid_wizard script
« on: February 21, 2019, 05:40:01 pm »
Hello,

I made the the typographic_grid_wizard script in annex. The python script is working, but I have the following questions:
1) In line 100 I use the command scribus.setMargins(). It updates the margin values on the active page, but does not change the displayed margin guides on that page (only after manually clicking 'Apply changes to all pages' in the Document Setup-menu it changes). Can this be done by scripting or have I missed something (I am a beginner in programming)?
2) Is there a way to perform the menu command View -> Text frames -> Show baseline grid by scripting?

Rafferty

a.l.e

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1854
  • Karma: 26
    • the graphics lab
Re: Some questions about my Typographic_grid_wizard script
« Reply #1 on: February 21, 2019, 07:02:21 pm »
a couple of weeks ago i've also written a typographic grid script ... i will be glad to review yours very soon : - )

rafferty

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
  • Scribus User
Re: Some questions about my Typographic_grid_wizard script
« Reply #2 on: February 21, 2019, 10:28:03 pm »
After some other testing I found a mistake in my script (nothing to do with my question above):
line 87 shoud be "previousGuide = marginLeft*columnUnitPt" in stead of "previousGuide = marginTop*columnUnitPt".

a.l.e

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1854
  • Karma: 26
    • the graphics lab
Re: Some questions about my Typographic_grid_wizard script
« Reply #3 on: February 22, 2019, 11:26:07 am »
first a review of the solution i know of... just for fun : - )

1.

there is a script by ugajin that sets one guide per baseline (if i read it correctly):

https://github.com/aoloe/scribus-script-repository/blob/master/typographic-grid/tmp/setBaselineGuides.py

2.

there is an older script of mine asking for the number of columns and the text size and calculates the number of rows and the line height::

https://github.com/aoloe/scribus-script-repository/tree/master/typographic-grid

i have not touched it for some times now, and i don't know if it really works. but, at the end, you will see some notes that hint to the fact that it's not possible yet to create row and column guides from the scripter.

3.

i have a newer script i wrote more recently, and which runs outside of scribus

  - it does not use (yet) the scribus scripter. plain python.
  - it needs to know
    - the size inside of the margins
    - the number of rows
    - the baseline height you'd like to have
  - the result is two values for for the baseline height: one bigger and one smaller than the one given by the user.
  - the goal is to extend the scripter to allow the script to run without asking (almost) any question to the user.
  - i'll paste the script in a further post in here, since it's not published yet.

4.

now, i'll try to understand the script you've submitted : - )


- it has a rather complex tcl/tk UI
  - it can remove the current guides
  - it asks for the margins
  - it asks for the number of rows and columns
  - it asks for the h and v gutter
  - it asks for a desired line height and cell ratio
- it suggests to modify by a calculated value the top/bottom or inner/outer margins if it cannot fit the lines in the rows.
- it everything fits, it creates multiple single guides

in a follow up i'll have a look at your line 100... but the anser to 2/ is "probably no"...

a.l.e

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1854
  • Karma: 26
    • the graphics lab
Re: Some questions about my Typographic_grid_wizard script
« Reply #4 on: February 22, 2019, 11:28:02 am »
here is my python-only script:

Code: [Select]
"""
give a two line heights that is are as close as possible to
the given one. one will be smaller, other bigger.

todo: create a second script that suggests new margins
"""
import math

def get_pt_from_mm(mm):
    return mm * 2.83465

def get_mm_from_pt(pt):
    return pt * 0.35278

page_width = 210
page_height = 297
inner_margin = 13
outer_margin = 20
top_margin = 10
bottom_margin = 10

font_size = 12 # pt
line_height = 16 # pt

columns = 8
rows = 8

inner_width = page_width - inner_margin - outer_margin
inner_height = page_height - top_margin - bottom_margin

cell_height = inner_height / rows # 34.625
print(cell_height)


lines_in_cell = get_pt_from_mm(cell_height) / line_height
print(lines_in_cell) # 6.134

page_height_pt = get_pt_from_mm(page_height)
inner_height_pt = get_pt_from_mm(inner_height)

page_lines_maximum = math.ceil(inner_height_pt / line_height)
cell_lines_maximum = math.ceil(page_lines_maximum / rows)
print('max', cell_lines_maximum) # 7


high = 0
low = 0
for i in range(cell_lines_maximum, -1, -1):
    n_lines_inner_page = (i * rows + rows - 1)
    height = n_lines_inner_page * line_height
    high = low
    low = i
    print(height)
    if height < inner_height_pt:
        break

def get_measurements(i, page):
    result = {
       'line_height': 0,
       'lines_per_cell': i,
       'overflow': 0
    }
    lines_per_page =  i * page['rows'] +  page['rows'] - 1

    result['line_height'] = round(page['inner_height_pt'] / lines_per_page, 2)
    result['overflow'] = get_mm_from_pt(page['inner_height_pt'] - result['line_height'] * lines_per_page)
    return result

page = {
    'rows': rows,
    'inner_height_pt': inner_height_pt
}

high_measurements = get_measurements(high, page)
print('smaller lines', high_measurements)
low_measurements = get_measurements(low, page)
print('larger lines', low_measurements)

i think it would be good to enhance to suggest margin changes. on the other side, i'm not sure that using the ratio is a practical idea... i have the feeling that most people have a clear idea of how many rows and columns they want...
« Last Edit: February 22, 2019, 11:30:58 am by a.l.e »

a.l.e

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1854
  • Karma: 26
    • the graphics lab
Re: Some questions about my Typographic_grid_wizard script
« Reply #5 on: February 22, 2019, 11:44:47 am »
line 100 of your script:

i had to check the documentation: setMargins() sets the margins of the document, which will be used... in a way nobody would think of: when you create a new master page...

the scripter does have a getPageMargins(), but no setPageMargins().

i think it should not be that hard to add that function (c++ code is needed) but i would first list all functions that are needed to make it easy to calculate a typographic grid.

from my point of view it almost needs a way to get set the row and column guides and their gutter...

what else is needed?

p.s.: of course, the commands will only be added to the development version 1.5.x not the stable one 1.4...

rafferty

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
  • Scribus User
Re: Some questions about my Typographic_grid_wizard script
« Reply #6 on: February 22, 2019, 06:43:34 pm »
Thank you for taking the time to review my script and answering my questions!
It seems more people are trying to get a typographic grid script within Scribus, all with different methods, and mine is a complicated one. I will wait for the setPageMargins() function to be added to the scripter api to publish a new version (and also think about the necessity of the ratio).

One last question: When I do several "recalculations", the tkinter window hangs. Could this be a program or a memory issue? (I am using Windows 10 and Scribus portable 1.5.4).

a.l.e

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1854
  • Karma: 26
    • the graphics lab
Re: Some questions about my Typographic_grid_wizard script
« Reply #7 on: February 22, 2019, 07:54:24 pm »
i would say that if it hangs, it's because you have a "wrong" loop...

rafferty

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
  • Scribus User
Re: Some questions about my Typographic_grid_wizard script
« Reply #8 on: March 08, 2019, 02:39:45 pm »
Hello all,

I have adapted my script with the remarks of the posts above and want to share it. Now it works fine for me (with the python version 2.7 which was bundled with my Scribus version). A guide with an example of how to use this script is included in the zip file.