diff options
Diffstat (limited to 'bin/kun-tips')
| -rwxr-xr-x | bin/kun-tips | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/bin/kun-tips b/bin/kun-tips new file mode 100755 index 0000000..a279856 --- /dev/null +++ b/bin/kun-tips @@ -0,0 +1,111 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +# Copyright 2009-2011 Linnea Skogtvedt <linnea@linuxavdelingen.no> +# Copyright 2016 Mike Gabriel <mike.gabriel@das-netzwerkteam.de> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the +# Free Software Foundation, Inc., +# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + + +# Example /etc/tips.cfg: +# [tips] +# title = Tips +# user message = Click <a href="/usr/share/applications/putty.desktop">here</a> to launch the PuTTY application. +# open urls with = kfmclient exec + + +import sys +import locale +import configparser +from PyQt5.QtCore import * +from PyQt5.QtGui import * +from PyQt5.QtWidgets import QApplication, QDialog, QLabel, QVBoxLayout + +class ConfigException(BaseException): + pass + +class Form(QDialog): + + clicked = pyqtSignal() + + def __init__(self): + super().__init__() + + lang, encoding = locale.getlocale() + lang, region = lang.split("_") + + cfg = configparser.RawConfigParser() + if sys.argv[1:]: + cfgFile = sys.argv[1] + else: + cfgFile = '/etc/tips.cfg' + cfg.readfp(open(cfgFile, 'r')) + + # check if the tips.cfg file has valid sections... + section = 'tips' + if not cfg.has_section(section): + section = 'rapporter-fail' + if not cfg.has_section(section): + raise ConfigException + + title_options = [ + 'title[{lang}_{region}]'.format(lang=lang, region=region), + 'title[{lang}]'.format(lang=lang), + 'title', + ] + for option in title_options: + if cfg.has_option(section, option): + title = cfg.get(section, option) + break + else: + raise ConfigException + + try: + urlOpener = cfg.get(section, 'open urls with') + except configparser.NoOptionError: + urlOpener = "xdg-open" + + msg_options = [ + 'msg[{lang}_{region}]'.format(lang=lang, region=region), + 'msg[{lang}]'.format(lang=lang), + 'msg', + ] + for option in msg_options: + if cfg.has_option(section, option): + msg = cfg.get(section, option) + break + else: + raise ConfigException + + def openLink(link): + import shlex + argv = shlex.split(urlOpener) + [link] + QProcess.startDetached(argv[0], argv[1:]) + + msgLabel = QLabel(msg) + msgLabel.setTextFormat(Qt.RichText) + msgLabel.linkActivated.connect(openLink) + + layout = QVBoxLayout() + layout.addWidget(msgLabel) + self.setLayout(layout) + self.setWindowTitle(title) + + +app = QApplication(sys.argv) +form = Form() +form.show() +app.exec_() |
