Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 133 lines (112 sloc) 5.37 KB
#!/usr/bin/python3 -u
# -*- coding: utf-8 -*-
## Copyright (C) 2014 troubadour <trobador@riseup.net>
## Copyright (C) 2014 - 2018 ENCRYPTED SUPPORT LP <adrelanos@riseup.net>
from PyQt5.QtGui import QIcon, QPixmap
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QObject, pyqtSignal
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_Dialog(object):
def setupUi(self, Dialog):
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHeightForWidth(Dialog.sizePolicy().hasHeightForWidth())
Dialog.setSizePolicy(sizePolicy)
Dialog.setWindowIcon(QIcon(icon))
if pos == "1":
Dialog.move(0, 0)
self.gridLayout = QtWidgets.QGridLayout(Dialog)
self.Info_Icon = QtWidgets.QLabel(Dialog)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHeightForWidth(self.Info_Icon.sizePolicy().hasHeightForWidth())
self.Info_Icon.setSizePolicy(sizePolicy)
image = QtGui.QImage(itype)
self.Info_Icon.setPixmap(QPixmap.fromImage(image))
self.Info_Icon.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
self.gridLayout.addWidget(self.Info_Icon, 0, 0, 1, 1)
self.Message = QtWidgets.QTextBrowser(Dialog)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHeightForWidth(self.Message.sizePolicy().hasHeightForWidth())
self.Message.setSizePolicy(sizePolicy)
self.Message.setMinimumSize(QtCore.QSize(715, 0))
self.Message.setFrameShape(QtWidgets.QFrame.StyledPanel)
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(244, 244, 244))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
self.Message.setPalette(palette)
self.Message.setTextInteractionFlags(QtCore.Qt.LinksAccessibleByMouse | QtCore.Qt.TextSelectableByMouse)
self.Message.setOpenExternalLinks(True)
self.Message.setFrameShape(QtWidgets.QFrame.NoFrame)
self.gridLayout.addWidget(self.Message, 0, 1, 1, 2)
self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Ok)
self.gridLayout.addWidget(self.buttonBox, 1, 1, 1, 1)
self.retranslateUi(Dialog)
self.buttonBox.accepted.connect(Dialog.accept)
self.buttonBox.rejected.connect(Dialog.reject)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(QtWidgets.QApplication.translate("Dialog", title, None))
self.Message.setHtml(QtWidgets.QApplication.translate("Dialog", msg, None))
## Size is not readily available, so, create a signal
QtCore.QTimer.singleShot(0, self.setSize)
def setSize(self):
## Size is returned
messageHeight = self.Message.document().size().height()
maximumHeight = QtWidgets.QDesktopWidget().availableGeometry().height() - 25
if messageHeight <= maximumHeight:
Dialog.resize(830, messageHeight + 55)
self.center()
else:
Dialog.resize(830, maximumHeight)
self.center()
def center(self):
frameGm = Dialog.frameGeometry()
centerPoint = QtWidgets.QDesktopWidget().availableGeometry().center()
frameGm.moveCenter(centerPoint)
Dialog.move(frameGm.topLeft())
if __name__ == "__main__":
import sys
import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)
syntax_details = """
msgdispatcher_dispatch_x requires 4 mandatory and 1 optional arguments
1) Message Type = info|warning|error
2) Title of the message box
3) Message in the message box
4) Position of the message (Value 0 or more)
5) Icon to be used (optional)
"""
if len(sys.argv) < 5:
sys.exit("'msgdispatcher_dispatch_x'. Invalid number of options {}".format(syntax_details))
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
if str(sys.argv[1]) == "info":
itype = "/usr/share/icons/oxygen/base/64x64/status/dialog-information.png"
elif str(sys.argv[1]) == "warning":
itype = "/usr/share/icons/oxygen/base/128x128/status/dialog-warning.png"
elif str(sys.argv[1]) == "error":
itype = "/usr/share/icons/oxygen/base/128x128/status/dialog-error.png"
else:
itype =""
sys.exit("'msgdispatcher_dispatch_x'. Information type not recognized: %s" % str(sys.argv[1]))
title = str(sys.argv[2])
msg = str(sys.argv[3])
pos = str(sys.argv[4])
icon = "/usr/share/icons/anon-icon-pack/whonix.ico"
if len(sys.argv) == 6:
icon = str(sys.argv[5])
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())