Commit da269a7480213f5280dae59fa1ccdfe8bc0159b7
1 parent
15f7e46cc0
Exists in
master
Update to Python3 and PyQt5
Showing 1 changed file with 58 additions and 54 deletions Side-by-side Diff
license-dialog
1 | -#!/usr/bin/python | |
2 | -# -*- coding: utf-8 -*- | |
1 | +#!/usr/bin/python3 | |
2 | +# openmamba license-dialog | |
3 | +# Copyright (C) 2011 by michiamophil | |
4 | +# Copyright (C) 2011-2020 by Silvan Calarco | |
5 | +# Distributed under the terms of the GPL version 3 FLOSS License | |
3 | 6 | |
4 | -import os #--Uscite possibili: | |
5 | -import sys #---: 0 -> licenza accettata | |
6 | -import gettext #---: 1 -> licenza rifiutata | |
7 | -from PyQt4 import QtGui, QtCore #---: 2 -> percorso licenza sbagliato o non presente o se l'argomento digitato è -h o --help | |
8 | 7 | |
8 | +#--Uscite possibili: | |
9 | +#---: 0 -> licenza accettata | |
10 | +#---: 1 -> licenza rifiutata | |
11 | +#---: 2 -> percorso licenza sbagliato o non presente o se l'argomento digitato è -h o --help | |
9 | 12 | |
13 | +import os | |
14 | +import sys | |
15 | +import gettext | |
16 | +from PyQt5.QtWidgets import QDesktopWidget, QWidget, QApplication, QToolTip, QPushButton,\ | |
17 | + QTextEdit, QGridLayout | |
18 | +from PyQt5.QtGui import QIcon, QFont | |
19 | +from PyQt5.QtCore import pyqtSignal | |
20 | + | |
21 | + | |
10 | 22 | # Decisione presa in run-time |
11 | 23 | imgAccetto = "object-select-symbolic" |
12 | 24 | imgRifiuto = "window-close-symbolic" |
13 | 25 | imgForm = "document" |
26 | + | |
14 | 27 | if (os.getenv('DESKTOP_SESSION')): |
15 | - desktop_session = QtCore.QString(os.getenv('DESKTOP_SESSION')) # Codice preso da mambatray | |
16 | - if (desktop_session == 'default') or (desktop_session.left(3) == 'kde'): # Scelgo le icone di kde | |
28 | + desktop_session = os.getenv('DESKTOP_SESSION') # Codice preso da mambatray | |
29 | + if desktop_session == 'default' or desktop_session[:3] == 'kde': # Scelgo le icone di kde | |
17 | 30 | imgAccetto = "dialog-ok-apply" |
18 | 31 | imgRifiuto = "dialog-close" |
19 | 32 | imgForm = "text-rtf" |
20 | 33 | |
21 | 34 | def usage(): |
22 | - print _("Usage: license-dialog /license/path") | |
23 | - print _("License-dialog is a simple PyQt4 based license accept/refuse dialog") | |
35 | + print(_("Usage: license-dialog /license/path")) | |
36 | + print(_("License-dialog is a simple PyQt5 based license accept/refuse dialog")) | |
24 | 37 | |
25 | 38 | |
26 | -gettext.install('license-dialog', '/usr/share/locale', unicode=1) | |
39 | +gettext.install('license-dialog', '/usr/share/locale') | |
27 | 40 | |
28 | 41 | try: |
29 | 42 | path = sys.argv[1] |
30 | -#si verifica se non si fornisce alcun argomento | |
31 | 43 | except: |
44 | + # si verifica se non si fornisce alcun argomento | |
32 | 45 | usage() |
33 | - print _("Error: path not defined") | |
46 | + print(_("Error: path not defined")) | |
34 | 47 | sys.exit(2) |
35 | 48 | |
36 | 49 | |
37 | - | |
38 | -#controlla se la licenza esiste e la assegna a txt | |
50 | +# controlla se la licenza esiste e la assegna a txt | |
39 | 51 | if path == "-h" or path == "--help": |
40 | 52 | usage() |
41 | 53 | sys.exit(2) |
42 | -#esce con 2 se è una cartella | |
43 | 54 | elif not os.path.exists(path): |
55 | + # esce con 2 se è una cartella | |
44 | 56 | usage() |
45 | - print _("Error: Wrong path") | |
57 | + print(_("Error: Wrong path")) | |
46 | 58 | sys.exit(2) |
47 | 59 | elif os.path.isdir(path): |
48 | 60 | usage() |
49 | - print _("Error: path cannot be a directory") | |
61 | + print(_("Error: path cannot be a directory")) | |
50 | 62 | sys.exit(2) |
51 | 63 | |
52 | 64 | licenza = open(path, "r") |
53 | -txtTp = licenza.read() | |
54 | -#così vanno i caratteri accentati sulla QTextEdit | |
55 | -txt= txtTp.decode("utf-8") | |
65 | +txt = licenza.read() | |
56 | 66 | licenza.close() |
57 | 67 | |
58 | - | |
59 | 68 | #centra il form sullo schermo |
60 | 69 | def center(self): |
61 | - screen = QtGui.QDesktopWidget().screenGeometry() | |
62 | - size = self.geometry() | |
63 | - self.move((screen.width()-size.width())/2, (screen.height()-size.height())/2) | |
70 | + screen = QDesktopWidget().screenGeometry() | |
71 | + size = self.geometry() | |
72 | + self.move((screen.width()-size.width())/2, (screen.height()-size.height())/2) | |
64 | 73 | |
65 | - | |
66 | -class Form(QtGui.QWidget): | |
74 | +class Form(QWidget): | |
67 | 75 | def __init__(self, parent=None): |
68 | - QtGui.QWidget.__init__(self, parent) | |
76 | + QWidget.__init__(self, parent) | |
69 | 77 | |
70 | 78 | self.setWindowTitle(_("Licenze")) |
71 | - self.setWindowIcon(QtGui.QIcon.fromTheme(imgForm)) | |
79 | + self.setWindowIcon(QIcon.fromTheme(imgForm)) | |
72 | 80 | self.resize(500, 400) |
73 | 81 | center(self) |
74 | - QtGui.QToolTip.setFont(QtGui.QFont('sans', 10)) | |
75 | - | |
76 | - btnAccetto = QtGui.QPushButton(QtGui.QIcon.fromTheme(imgAccetto), _("I agree")) | |
82 | + QToolTip.setFont(QFont('sans', 10)) | |
83 | + | |
84 | + btnAccetto = QPushButton(QIcon.fromTheme(imgAccetto), _("I agree")) | |
77 | 85 | btnAccetto.setToolTip(_("Click here if you want to accept the license")) |
78 | - self.connect(btnAccetto, QtCore.SIGNAL('clicked()'), evtAccetto) | |
86 | + btnAccetto.clicked.connect(self.evtAccetto) | |
79 | 87 | |
80 | - btnRifiuto = QtGui.QPushButton(QtGui.QIcon.fromTheme(imgRifiuto), _("I do not agree")) | |
88 | + btnRifiuto = QPushButton(QIcon.fromTheme(imgRifiuto), _("I do not agree")) | |
81 | 89 | btnRifiuto.setToolTip(_("Click here if you do <b>not</b> want to accept the license")) |
82 | - self.connect(btnRifiuto, QtCore.SIGNAL('clicked()'), evtRifiuto) | |
83 | - | |
84 | - licenza = QtGui.QTextEdit() | |
90 | + btnRifiuto.clicked.connect(self.evtRifiuto) | |
91 | + | |
92 | + licenza = QTextEdit() | |
85 | 93 | licenza.setReadOnly(True) |
86 | 94 | licenza.setPlainText(txt) |
87 | 95 | |
88 | - grid = QtGui.QGridLayout() | |
89 | - grid.setSpacing(10) | |
90 | - | |
96 | + grid = QGridLayout() | |
97 | + grid.setSpacing(10) | |
98 | + | |
91 | 99 | grid.addWidget(licenza, 1, 0, 1, 2) |
92 | 100 | grid.addWidget(btnRifiuto, 2, 0) |
93 | 101 | grid.addWidget(btnAccetto, 2, 1) |
94 | - | |
95 | - | |
102 | + | |
96 | 103 | self.setLayout(grid) |
97 | 104 | |
98 | - #annulla la chiusura con la x del window manager | |
105 | + # annulla la chiusura con la x del window manager | |
99 | 106 | def closeEvent(form, event): |
100 | 107 | event.ignore() |
101 | - | |
102 | 108 | |
109 | + def evtAccetto(self): | |
110 | + sys.exit(0) | |
103 | 111 | |
104 | -def evtAccetto(): | |
105 | - sys.exit(0) | |
112 | + def evtRifiuto(self): | |
113 | + #mostra un messaggio: | |
114 | + #msg = QtGui.QMessageBox.question(form, _("Message"), _("Are you sure to refuse?"), QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No) | |
115 | + #if msg == QtGui.QMessageBox.Yes: | |
116 | + sys.exit(1) | |
106 | 117 | |
107 | 118 | |
108 | -def evtRifiuto(): | |
109 | - #mostra un messaggio: | |
110 | - #msg = QtGui.QMessageBox.question(form, _("Message"), _("Are you sure to refuse?"), QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No) | |
111 | - #if msg == QtGui.QMessageBox.Yes: | |
112 | - sys.exit(1) | |
113 | - | |
114 | - | |
115 | 119 | #crea la finestra di dialogo |
116 | -app = QtGui.QApplication(sys.argv) | |
120 | +app = QApplication(sys.argv) | |
117 | 121 | form = Form() |
118 | 122 | form.show() |
119 | 123 | sys.exit(app.exec_()) |