eric6/WebBrowser/ZoomManager/ZoomValuesDialog.py

Sat, 27 Feb 2021 12:08:23 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 Feb 2021 12:08:23 +0100
changeset 8138
169e65a6787c
parent 7923
91e843545d9a
child 8218
7c09585bd960
permissions
-rw-r--r--

Shell: added functionality to show a prompt when the main client process has exited (e.g. a script ended).

# -*- coding: utf-8 -*-

# Copyright (c) 2015 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a dialog to show all saved zoom values.
"""

from PyQt5.QtCore import QSortFilterProxyModel
from PyQt5.QtGui import QFont, QFontMetrics
from PyQt5.QtWidgets import QDialog

from .Ui_ZoomValuesDialog import Ui_ZoomValuesDialog


class ZoomValuesDialog(QDialog, Ui_ZoomValuesDialog):
    """
    Class implementing a dialog to show all saved zoom values.
    """
    def __init__(self, parent=None):
        """
        Constructor
        
        @param parent reference to the parent widget (QWidget)
        """
        super(ZoomValuesDialog, self).__init__(parent)
        self.setupUi(self)
        
        self.removeButton.clicked.connect(
            self.zoomValuesTable.removeSelected)
        self.removeAllButton.clicked.connect(self.zoomValuesTable.removeAll)
        
        from . import ZoomManager
        from .ZoomValuesModel import ZoomValuesModel
        
        self.zoomValuesTable.verticalHeader().hide()
        self.__zoomValuesModel = ZoomValuesModel(
            ZoomManager.instance(), self)
        self.__proxyModel = QSortFilterProxyModel(self)
        self.__proxyModel.setSourceModel(self.__zoomValuesModel)
        self.searchEdit.textChanged.connect(
            self.__proxyModel.setFilterFixedString)
        self.zoomValuesTable.setModel(self.__proxyModel)
        
        fm = QFontMetrics(QFont())
        height = fm.height() + fm.height() // 3
        self.zoomValuesTable.verticalHeader().setDefaultSectionSize(height)
        self.zoomValuesTable.verticalHeader().setMinimumSectionSize(-1)
        
        self.__calculateHeaderSizes()
    
    def __calculateHeaderSizes(self):
        """
        Private method to calculate the section sizes of the horizontal header.
        """
        fm = QFontMetrics(QFont())
        for section in range(self.__zoomValuesModel.columnCount()):
            header = self.zoomValuesTable.horizontalHeader().sectionSizeHint(
                section)
            if section == 0:
                try:
                    header = fm.horizontalAdvance(
                        "extraveryveryverylongsitename")
                except AttributeError:
                    header = fm.width(
                        "extraveryveryverylongsitename")
            elif section == 1:
                try:
                    header = fm.horizontalAdvance("averagelongzoomvalue")
                except AttributeError:
                    header = fm.width("averagelongzoomvalue")
            try:
                buffer = fm.width("mm")
            except AttributeError:
                buffer = fm.width("mm")
            header += buffer
            self.zoomValuesTable.horizontalHeader().resizeSection(
                section, header)
        self.zoomValuesTable.horizontalHeader().setStretchLastSection(True)

eric ide

mercurial