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

ENH: Add paperSize global setting #335

Merged
merged 3 commits into from
Oct 21, 2017
Merged

ENH: Add paperSize global setting #335

merged 3 commits into from
Oct 21, 2017

Conversation

mray271
Copy link
Contributor

@mray271 mray271 commented Oct 17, 2017

Adds paperSize global setting which sets both the default paper size for both the quick PDF export and the more interactive print dialog.

Reference issue #205

Copy link
Member

@mitya57 mitya57 left a comment

Choose a reason for hiding this comment

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

Thank you for your pull request!

Please document the new setting in configuration.md and, if possible, address my comments.

Also I prefer camelCase to underscored_names as that is what Qt uses.

ReText/window.py Outdated
printer.setPaperSize(page_size)
else:
QMessageBox.warning(self, '',
'Unrecognized PaperSize setting "{0}".'.format(
Copy link
Member

Choose a reason for hiding this comment

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

Please make the string translatable (using self.tr), and also use percent formatting (%s) as that is what Qt Linguist understands.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

ReText/window.py Outdated

def availablePageSizes(self):
""" List available page sizes.
"""
Copy link
Member

@mitya57 mitya57 Oct 17, 2017

Choose a reason for hiding this comment

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

Maybe use QPrinterInfo::supportedPageSizes() instead of this function? You will need to pass printer info to getPageSizeByName, but that should not be a problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm. supportedPageSizes (possibly same as availablePageSizes ?) consistently returns empty array in my set-up. Perhaps this feature is not quite working on my system or there are some version differences. I'm using python-qt5-5.7-7.fc25.x86_64 on Fedora Linux 4.13.5-100.fc25.x86_64. Leaving as is for now as this seems compatible/working. Feel free to modify/

ReText/window.py Outdated
match = list(filter(lambda y:y.lower()==page_size_name.lower(),
self.availablePageSizes()))
if match:
page_size = getattr(QPagedPaintDevice, match[0])
Copy link
Member

@mitya57 mitya57 Oct 17, 2017

Choose a reason for hiding this comment

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

I would use a dict here. Something like:

sizes = {size.name().lower(): size for size in printerInfo.supportedPageSizes()}
requestedSize = sizes.get(pageSizeName.lower())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm. supportedPageSizes (possibly same as availablePageSizes ?) consistently returns empty array in my set-up. Perhaps this feature is not quite working on my system or there are some version differences. I'm using python-qt5-5.7-7.fc25.x86_64 on Fedora Linux 4.13.5-100.fc25.x86_64. Leaving as is for now as this seems compatible/working. Feel free to modify/

@@ -98,6 +98,7 @@ def getBundledIcon(iconName):
'useWebEngine': False,
'useWebKit': False,
'windowGeometry': QByteArray(),
'paperSize': 'A4',
Copy link
Member

Choose a reason for hiding this comment

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

Why default explicitly to A4? Maybe leave the default empty and use Qt’s defaults?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

…r unspecified, and made warning message translatable
Copy link
Member

@mitya57 mitya57 left a comment

Choose a reason for hiding this comment

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

QPrinterInfo(printer).supportedPageSizes() in standardPrinter works here, returns a non-empty array. How did you try to use it?

ReText/window.py Outdated
printer.setPaperSize(pageSize)
else:
QMessageBox.warning(self, '',
self.tr('Unrecognized PaperSize setting "%s".' %
Copy link
Member

Choose a reason for hiding this comment

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

The closing ) is in wrong place, this won’t work. The translators need to translate the string with literal %s, not with the substituted value.

It should be self.tr('Unrecognized PaperSize setting "%s".') % globalSettings.paperSize.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

ReText/window.py Outdated
self.availablePageSizes()))
if match:
pageSize = getattr(QPagedPaintDevice, match[0])
return pageSize
Copy link
Member

Choose a reason for hiding this comment

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

Can you please still use a dictionary? Then this function will be just 3 lines instead of current 8.

lowerCaseNames = {pageSize.lower(): pageSize for pageSize in self.availablePageSizes()}
if pageSizeName.lower() in lowerCaseNames:
    return getattr(QPagedPaintDevice, lowerCaseNames[pageSizeName])

(And it will still return None if there is no match.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

ReText/window.py Outdated
""" Returns a validated PageSize instance
corresponding to the given name. Returns
None if the name is not a valid PageSize.
"""
Copy link
Member

Choose a reason for hiding this comment

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

Any reason why the docstring lines are so short?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed those so they wrap at longer length.

…ixed format of translatable warning message.
@mray271
Copy link
Contributor Author

mray271 commented Oct 21, 2017

Yeah, I agree it's super weird that an empty array is being returned. I tried exactly this QPrinterInfo(printer).supportedPageSizes() both inside standardPrinter with the printer there as input and a couple of other places and in an ipython session, but strangely it's still returning [] (an empty array). I'm equally surprised. I can try to dig a bit further, but I'm guessing something strange about python-qt5 (PyQt5) or some other Fedora-specific issue.

@mitya57 mitya57 merged commit b0daeae into retext-project:master Oct 21, 2017
@mitya57
Copy link
Member

mitya57 commented Oct 21, 2017

Congratulations with your first PR merged! There were minor problems with whitespace, but I fixed them myself in a follow-up commit.

mitya57 added a commit that referenced this pull request Oct 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants