From a4b92d4e3fda5209c03389aff6cf35c537b88ab9 Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Tue, 13 Dec 2016 17:55:37 +0100 Subject: Port Linnea Skogtvedt's kun-tips script to PyQt5 / Python3 and add i18n support. --- bin/kun-tips | 111 ++++++++++++++++++++++++++++++++++++++++++ tips.cfg | 157 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 268 insertions(+) create mode 100755 bin/kun-tips create mode 100644 tips.cfg 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 +# Copyright 2016 Mike Gabriel +# +# 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 here 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_() diff --git a/tips.cfg b/tips.cfg new file mode 100644 index 0000000..bf3dace --- /dev/null +++ b/tips.cfg @@ -0,0 +1,157 @@ +[tips] +open urls with = xdg-open +title = Hints +msg = You may have encoutered one of these common problems: + +
    +
  1. + If your Firefox webbrowser shows the following message: + Firefox is
    already running, but is not responding ...
    , + then click here
    + and answer with "Yes". + You can also go directly to
    System->Settings->Fix Firefox Startup. + You can also use another
    web browser, for example + Chromium. +
  2. + +
  3. + Reset profile settings. If you have the problem that your + desktop looks
    strange
    , you are missing some icons and menus, click + here and + answer
    with "Yes". You can also go directly to + System->Settings->Reset Desktop
    Settings. +
  4. + +
  5. + If you have problems with LibreOffice, click + here + and answer with "Yes".
    You can also go directly to + System->Settings->Reset LibreOffice Settings. +
  6. + +
  7. + If you have a reason for changing your password, then use
    + System->Settings->Change Password, or click this link + Change Password. +
  8. + +
  9. + If you want to add application shortcuts to your desktop, then click +
    Application Finder + and drag shortcuts from there to your desktop. +
  10. + +
  11. + If you need to make a screenshot for reporting an error message
    + then press the PrintScreen key on your keyboard or click here to + start the
    + screenshot utility. +
  12. +
+ + +### localized messages + +title[de_DE] = Hinweise +msg[de_DE] = Eventuell ist eines der folgenden häufigen Probleme bei Ihnen aufgetreten: + +
    +
  1. + Wenn der Firefox Webbrowser die folgende Meldung anzeigt: Firefox is already running,
    + but is not responding ...
    , dann klicken Sie hier + und antworten mit "Ja".
    + Sie können das Programm auch direkt ausführen: System->Einstellungen->Firefox Startproblem beheben.
    + Sie können auch einen anderen Webbrowser verwenden, z.Bsp. Chromium. +
  2. + +
  3. + Profileinstellungen zurücksetzen. + Sollte Ihre Arbeitsoberfläche komisch aussehen,
    + fehlen Symbole und Menüs, dann klicken Sie + hier und + antworten mit "Ja".
    Sie können das Programm auch direkt ausführen: + System->Einstellungen->Einstellungen der Arbeitsoberfläche
    zurücksetzen. +
  4. + +
  5. + Sollten Sie Probleme mit LibreOffice haben, dann klicken Sie + hier + und antworten mit "Ja".
    Sie können das Programm auch direkt ausführen: + System->Einstellungen->LibreOffice Einstellungen
    zurücksetzen. +
  6. + +
  7. + Sollten Sie Gründe haben, Ihr Kennwort ändern zu müssen, dann verwenden Sie
    + System->Einstellungen->Kennwort ändern, oder klicken Sie einfach diesen Link: + Kennwort ändern. +
  8. + +
  9. + Wenn Sie eine Anwendungsverknüpfung auf der Arbeitsfläche erstellen wollen, dann klicken Sie hier: +
    Anwendungssuche. + Aus der Anwendungssuche können Sie Verknüpfungen auf die Arbeitsfläche ziehen. +
  10. + +
  11. + Sollten Sie einmal ein Bildschirmfoto für eine Fehlermeldungerstellen müssen,
    + dann drücken Sie die Drucken-Taste auf der Tastatur oder klicken Sie folgenden Link,
    + um das Bildschirmfoto Hilfsprogramm zu starten. +
  12. +
+ +title[nb_NO] = Tips +msg[nb_NO] = Her er de vanligste feilene: + +
    +
  1. + + Hvis du har problem med at nettleseren Firefox ikke vil starte, .. + is already running,
    så klikk + her og svar "Ja". + Du kan også gå rett til System->Innstillinger->Fiks Firefox.
    + Du kan også bruke en annen nettleser, som f.eks + Chromium. + +
  2. +
  3. + + Tilbakestill profil. Hvis du har problem med at Skrivebordet ser + rart ut,
    du mangler kanskje ikoner og menyer, klikk + her og + svar "Ja".
    Du kan også gå rett til + System->Innstillinger->Nullstill skrivebord. + +
  4. +
  5. + + Hvis du har problemer med LibreOffice, klikk her + og svar "Ja".
    Du kan også gå rett til + System->Innstillinger->Nullstill LibreOffice innstillinger. + +
  6. +
  7. + + Hvis du trenger å bytte passord, så bruk
    + System->Innstillinger->Bytt Passord, eller trykk her på + Bytt + Passord. + +
  8. +
  9. + + Hvis du vil legge snarveier til program, på Skrivebordet så + klikker du her på
    + Programvarekatalog + og drar snarveien ut på Skrivebordet. + +
  10. +
  11. + + Hvis du trenger å ta et skjermbilde av en feilmelding,
    så + trykk på PrintScreen-knappen på tastaturet, eller klikk her for å + starte + skjermbilde. + +
  12. +
-- cgit v1.2.3