def showLicense(self): app = Application.instance() licenseFilename = app.findResource('LICENSE.html') if not licenseFilename: return # QDesktopServices.openUrl(QUrl.fromLocalFile(licenseFilename)) textDialog = TextDialog(parent=self, title=self.tr('Subtitles License'), html_filename=licenseFilename) textDialog.exec_()
def showAcknowledgements(self): app = Application.instance() ackFilename = app.findResource('ACKNOWLEDGEMENTS.html') if not ackFilename: return # QDesktopServices.openUrl(QUrl.fromLocalFile(ackFilename)) textDialog = TextDialog(parent=self, title=self.tr("Acknowledgements"), html_filename=ackFilename) textDialog.exec_()
def _readFile(filename): app = Application.instance() if not filename: return None filename = app.findResource(filename) if not filename: return None try: with open(filename, 'rb') as f: return str(f.read(), encoding='utf-8').strip() except e: logger.warn("Error reading file '{}': {}".format(filename, e)) return None
def _initUi(self): app = Application.instance() icon = QIcon(app.findResource('Subtitles.png')) iconLabel = QLabel() iconLabel.setPixmap(icon.pixmap(128)) iconLabel.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) appNameLabel = QLabel(self) appNameLabel.setText(app.applicationName()) appNameLabel.setAlignment(Qt.AlignHCenter | Qt.AlignTop) appNameLabel.setStyleSheet('font-weight: bold; font-size: 18pt') appNameLabel.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Maximum) version_labels = self._createVersionLabels() licenseLabel = self._createSelectableLabel( 'Copyright © 2018–2019 Philip Belemezov<br>' 'Licensed under the <a href="about:blank">' 'GNU General Public License, version 3</a>.') licenseLabel.setStyleSheet('color: gray; font-size: 8pt') licenseLabel.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) licenseLabel.setTextFormat(Qt.RichText) licenseLabel.setTextInteractionFlags(Qt.TextBrowserInteraction) licenseLabel.linkActivated.connect(self.showLicense) homepageLabel = self._createLinkLabel( text=self.tr("Homepage"), href="https://github.io/philipbel/subtitles") homepageLabel.setAlignment(Qt.AlignCenter) ackLabel = self._createLinkLabel(text=self.tr("Acknowledgements")) ackLabel.setAlignment(Qt.AlignCenter) ackLabel.linkActivated.connect(self.showAcknowledgements) linksLayout = QVBoxLayout() linksLayout.addWidget(homepageLabel) linksLayout.addSpacing(5) linksLayout.addWidget(ackLabel) versionInfoLayout = QFormLayout() versionInfoLayout.setFormAlignment(Qt.AlignHCenter) versionInfoLayout.setHorizontalSpacing(4) for name, value in version_labels: name.setText(name.text() + ':') versionInfoLayout.addRow(name, value) mainLayout = QVBoxLayout(self) mainLayout.setSpacing(0) mainLayout.addWidget(iconLabel) mainLayout.addWidget(appNameLabel) mainLayout.addSpacing(5) mainLayout.addLayout(versionInfoLayout) mainLayout.addSpacing(20) mainLayout.addLayout(linksLayout) mainLayout.addSpacing(20) mainLayout.addWidget(licenseLabel) if sys.platform != 'darwin': buttonBox = QDialogButtonBox(QDialogButtonBox.Close) buttonBox.setCenterButtons(True) buttonBox.button(QDialogButtonBox.Close).clicked.connect( self.reject) line = QFrame() line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) mainLayout.addSpacing(8) mainLayout.addWidget(line) mainLayout.addSpacing(8) mainLayout.addWidget(buttonBox)