File: hidpi.py

package info (click to toggle)
git-cola 4.13.0-1
  • links: PTS
  • area: main
  • in suites: sid
  • size: 6,480 kB
  • sloc: python: 36,938; sh: 304; makefile: 223; xml: 100; tcl: 62
file content (47 lines) | stat: -rw-r--r-- 1,233 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""Provides High DPI support by wrapping Qt options"""

from qtpy import QtCore

from .i18n import N_
from . import core
from . import compat
from . import version


class Option:
    AUTO = '0'
    DISABLE = 'disable'
    TIMES_1 = '1'
    TIMES_1_25 = '1.25'
    TIMES_1_5 = '1.5'
    TIMES_2 = '2'


def is_supported():
    return version.check('qt-hidpi-scale', QtCore.__version__)


def apply_choice(value):
    value = compat.ustr(value)
    if value == Option.AUTO:
        # Do not override the configuration when either of these
        # two environment variables are defined.
        if not core.getenv('QT_AUTO_SCREEN_SCALE_FACTOR') and not core.getenv(
            'QT_SCALE_FACTOR'
        ):
            compat.setenv('QT_AUTO_SCREEN_SCALE_FACTOR', '1')
            compat.unsetenv('QT_SCALE_FACTOR')
    elif value and value != Option.DISABLE:
        compat.unsetenv('QT_AUTO_SCREEN_SCALE_FACTOR')
        compat.setenv('QT_SCALE_FACTOR', value)


def options():
    return (
        (N_('Auto'), Option.AUTO),
        (N_('Disable'), Option.DISABLE),
        (N_('x 1'), Option.TIMES_1),
        (N_('x 1.25'), Option.TIMES_1_25),
        (N_('x 1.5'), Option.TIMES_1_5),
        (N_('x 2'), Option.TIMES_2),
    )