Skip to content
This repository has been archived by the owner on May 28, 2022. It is now read-only.

High/Low DPI Adapting #640

Merged
merged 1 commit into from Dec 3, 2014
Merged

High/Low DPI Adapting #640

merged 1 commit into from Dec 3, 2014

Conversation

Cryspia
Copy link
Contributor

@Cryspia Cryspia commented Oct 26, 2014

The Qt UI would change the size according to the logical DPI of the computer
Only Windows and Linux have been tested. (Should also work on Mac but have not tested).
The function is unfinished.

Fixes #576

@Cryspia
Copy link
Contributor Author

Cryspia commented Oct 26, 2014

Plan:

  • Build framework for this function.
  • Implement the framework on every UI.
  • Fix the logo problem.
  • Finish the mixin for the class.
  • Write unit test
  • Set column width for talkeditor

@Cryspia
Copy link
Contributor Author

Cryspia commented Oct 26, 2014

Problems/Questions:

  • The Logo on About Page is broken. I cannot find where to move it.
    default
  • Not very sure about how to construct the framework. Presently, I plan to write a mid layer class of all the classes that been used in QtGui. The Widget class will inherit from those classes instead of directly from QtGui classes. So that after I rewrite the methods like 'setFixedSize' and 'setMinimumSize', the Widgets do not need big changes. But personally, I think it not good idea because a lot classes and methods need to be rewrite, it is no better than change the Widgets one by one.

@Cryspia
Copy link
Contributor Author

Cryspia commented Oct 26, 2014

#576

@dideler dideler added this to the 2014 Fall - UCOSP milestone Oct 26, 2014
@dideler
Copy link
Member

dideler commented Oct 27, 2014

The logo was recently modified in #603 and it was a pain to get right. Let's worry about that later.

Looking at your current code, I see the following repeated for every widget:

STANDARD_DPI = 96.0
X_SIZE = self.logicalDpiX() / STANDARD_DPI
Y_SIZE = self.logicalDpiY() / STANDARD_DPI

Is that the part you plan on putting in the new parent class?

@Cryspia
Copy link
Contributor Author

Cryspia commented Oct 27, 2014

@dideler Yes. And I want to build the new class so that I do not need to repeat it every time.

@Cryspia
Copy link
Contributor Author

Cryspia commented Oct 31, 2014

Add the interlayer QT classes for the widget classes that transmit fixed width and height value to DPI dependent ones.

Personal, I feel like the method a bit ugly. So I need suggestions on how to improve it.

@zxiiro
Copy link
Member

zxiiro commented Oct 31, 2014

Please follow our guidelines on how to do proper docstrings.

'''
freeseer - vga/presentation capture software

Copyright (C) 2011 Free and Open Source Software Learning Centre
Copy link
Member

Choose a reason for hiding this comment

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

This is a new file so the year should be updated.

@zxiiro
Copy link
Member

zxiiro commented Oct 31, 2014

I'm not an expert on DPI but I'm a bit surprised Qt isn't aware of it. Anyway the method looks fine for me but maybe other mentors have better ideas.

@Cryspia
Copy link
Contributor Author

Cryspia commented Oct 31, 2014

@zxiiro
I am not very sure whether the docstrings you mentioned is the file docstring or the class/method docstring, so I changed the file docstring only in the update.

It seems that QtCore.Qt.WindowFlags cannot be import by using

from PyQt4.QtCore.Qt import WindowFlags

The error message says that QtCore has not Qt component
But I can correctly use it by using

QtCore.Qt.WindowsFlags


# freeseer - vga/presentation capture software
#
# Copyright (C) 2011, 2014 Free and Open Source Software Learning Centre
Copy link
Member

Choose a reason for hiding this comment

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

This is a new file so only 2014 is enough

@zxiiro
Copy link
Member

zxiiro commented Oct 31, 2014

I mean the class and method docstrings. A bunch of

'''
Constructor
'''

Does not explain anything and also doesn't follow the standard style of:

'''Short summary
Followed by
possibly many lines
to describe the function
'''

@zxiiro
Copy link
Member

zxiiro commented Oct 31, 2014

For the Qt file we only need to go as far as:

from PyQt4.QtCore import Qt

We do not need to go any deeper than 1 level after the QtCore/QtGui module.

Edit: if you need an example of the import style I want take a look at some of our new Qt GUI files such as https://github.com/Freeseer/freeseer/blob/master/src/freeseer/frontend/qtcommon/FreeseerApp.py

@Cryspia
Copy link
Contributor Author

Cryspia commented Nov 1, 2014

I found that for some methods, the input arguments can be either (width, height) or (QSize). So I add a new method to deal with the two situations.

the input value DPI adatping using LOGICAL_DPI. The output will
all be transfered to (QSize) type
'''
global LOGICAL_DPI
Copy link
Member

Choose a reason for hiding this comment

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

Global variables are typically frowned upon. Can you find a way to accomplish what you want without using them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only method that I can come up with is to generate a dummy QWidget class in other classes. But that could be low efficient. How do you think of that?

Copy link
Member

Choose a reason for hiding this comment

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

What about just computing this LOGICAL_DPI in each widget? There's no sense in preemptively optimizing before there's any 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.

What about make it a class member for QWidgetWithDpi and pass it as additional arguments to the QGroupBoxWithDpi and QSpacerItemWithDpi constructors?

@Cryspia
Copy link
Contributor Author

Cryspia commented Nov 4, 2014

@mtomwing I replace the global variable with a class. Does that fit the style now?

@mtomwing
Copy link
Member

mtomwing commented Nov 4, 2014

No.

@Cryspia
Copy link
Contributor Author

Cryspia commented Nov 6, 2014

@mtomwing
I have two plans to solve the global dpi problem.

  • make the classes that do not have logicialDpi as methods of QWidget (for example QWidget.QSpaceItemWithDpi()). So they can using the inherited logicialDpi.
  • Simply pass logicialDpi as arguments into those methods.
    Which one do you think is better.

@Cryspia
Copy link
Contributor Author

Cryspia commented Nov 7, 2014

The new version has been pushed. In order to remove the global variable, I load the QSpacerItem and QRect into QWidget and QMainWindow as methods. Not sure whether it is OK.
I think I have included all the widgets and windows which are relevant to this change, but there still could be something missing. I anyone find some, please tell me.

'''
super(QToolButtonWithDpi, self).__init__(*args, **kwargs)

STANDARD_DPI = 96.0
Copy link
Member

Choose a reason for hiding this comment

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

How do we know that the standard DPI is 96? Is there a source somewhere that says this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. But both Windows and Ubuntu consider the standard DPI as 96 (I do not test mac because I do not have a mac). And quite a lot resources on the Internet also says that.

@dideler
Copy link
Member

dideler commented Nov 26, 2014

@promm what's the status of this PR? Is it good to merge on your end?

@Cryspia
Copy link
Contributor Author

Cryspia commented Nov 27, 2014

@dideler
Not yet. I want to make some changes with the talkeditor to define column width of the table. So that the problem I mentioned under the screen shots can be solved.

@Cryspia
Copy link
Contributor Author

Cryspia commented Nov 28, 2014

OK. The column setting for talk editor is also finished. The branch is ready to merge.
Here is the screenshot for the talk editor now:
image
The titles in the table can be show in completely.

@dideler
Copy link
Member

dideler commented Nov 28, 2014

Thanks. I'll review soon and merge if it's all good.


def test_set_width_with_dpi(self):
''' The test cases to test set_height_with_dpi method '''
assert self.tested_cls.set_width_with_dpi(300) == 450
Copy link
Member

Choose a reason for hiding this comment

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

I think the tests would be more robust if they calculate the expected value using the ratio instead of hardcoding it.

@Cryspia
Copy link
Contributor Author

Cryspia commented Nov 30, 2014

@dideler
I have rewritten the comments you mentioned in the code review, but I am not sure they meet your requirement. If some of them still have problems, just comment them again.



class QtGuiWithDpi(QWidget):
'''The base class uses for the mixin for other Dpi adapt QtGui classes.
Copy link
Member

Choose a reason for hiding this comment

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

This sentence is confusing, can you try to rewrite it?

The Qt UI would change the size according to the logical DPI of the computer.
Only Windows and Linux have been tested. (Should also work on Mac but have not tested).
The unit test for the new file is also added.
@Cryspia
Copy link
Contributor Author

Cryspia commented Dec 2, 2014

@dideler
Comments updated

@dideler dideler merged commit c03a73b into Freeseer:master Dec 3, 2014
dideler added a commit that referenced this pull request Dec 3, 2014
Make them more readable and informative.
Also fix punctuation, spelling, and grammar mistakes.

Related to #640
@dideler
Copy link
Member

dideler commented Dec 3, 2014

Thanks for the contribution @promm!

@dideler dideler mentioned this pull request Dec 9, 2014
@Cryspia Cryspia deleted the 576-dpi-adapt branch December 14, 2014 02:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Font in Configuration can be broken under Windows
4 participants