aboutpanel.py 2.46 KB
Newer Older
Dan Pascu's avatar
Dan Pascu committed
1

Dan Pascu's avatar
Dan Pascu committed
2
from PyQt5 import uic
Dan Pascu's avatar
Dan Pascu committed
3

4
from blink import __date__, __version__
Dan Pascu's avatar
Dan Pascu committed
5 6 7 8
from blink.resources import Resources
from blink.util import QSingleton


9 10 11
__all__ = ['AboutPanel']


Dan Pascu's avatar
Dan Pascu committed
12 13 14 15 16 17 18 19 20 21 22 23 24
credits_text = """
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html>
<head>
<meta name="qrichtext" content="1" />
<style type="text/css">
 td.name { text-align: right; padding-right: 6px; }
 a:link  { text-decoration: none; color: #1f487f; }
</style>
</head>
<body>
<table width="100%" cellspacing="2" cellpadding="0" border="0">
 <tr><td class="name" align="right">AG Projects</td><td align="left"><a href="http://ag-projects.com/">http://ag-projects.com/</a></td></tr>
25
 <tr><td class="name" align="right">NLnet Foundation</td><td align="left"><a href="http://nlnet.nl/">http://nlnet.nl/</a></td></tr>
Dan Pascu's avatar
Dan Pascu committed
26
 <tr><td class="name" align="right">IETF Community</td><td align="left"><a href="http://ietf.org/">http://ietf.org/</a></td></tr>
27
 <tr><td class="name" align="right">SIP Simple Client</td><td align="left"><a href="http://sipsimpleclient.org/">http://sipsimpleclient.org/</a></td></tr>
Dan Pascu's avatar
Dan Pascu committed
28 29 30 31 32 33 34 35
</table>
</body>
</html>
"""


ui_class, base_class = uic.loadUiType(Resources.get('about_panel.ui'))

36

Adrian Georgescu's avatar
Adrian Georgescu committed
37
class AboutPanel(base_class, ui_class, metaclass=QSingleton):
Dan Pascu's avatar
Dan Pascu committed
38 39 40 41 42 43
    def __init__(self, parent=None):
        super(AboutPanel, self).__init__(parent)

        with Resources.directory:
            self.setupUi(self)

Adrian Georgescu's avatar
Adrian Georgescu committed
44
        self.version.setText('Version %s\n%s' % (__version__, __date__))
45

46
        credits_width = self.credits_text.fontMetrics().width("NLnet Foundation" + "http://sipsimpleclient.org") + 40
47
        self.credits_text.setFixedWidth(credits_width)
Dan Pascu's avatar
Dan Pascu committed
48 49 50 51 52
        self.credits_text.document().documentLayout().documentSizeChanged.connect(self._credits_size_changed)
        self.credits_text.setHtml(credits_text)

    def _credits_size_changed(self, size):
        self.credits_text.document().documentLayout().documentSizeChanged.disconnect(self._credits_size_changed)
Tijmen de Mes's avatar
Tijmen de Mes committed
53
        self.setFixedSize(self.minimumSize().width(), int(self.minimumSize().width() * 1.40))  # set a fixed aspect ratio
54
        row_height = self.credits_text.fontMetrics().height() + 2  # +2 for cellspacing
Tijmen de Mes's avatar
Tijmen de Mes committed
55
        max_credits_height = 8 * row_height + 2 + 14  # allow for maximum 8 rows; +2 for cellspacing and +14 for top/bottom margins
56 57
        if self.credits_text.height() > max_credits_height:
            self.setFixedHeight(self.height() - (self.credits_text.height() - max_credits_height))
Dan Pascu's avatar
Dan Pascu committed
58 59


Tijmen de Mes's avatar
Tijmen de Mes committed
60
del ui_class, base_class