Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
openmamba
license-dialog
Commits
da269a74
Commit
da269a74
authored
Jul 18, 2020
by
Silvan Calarco
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update to Python3 and PyQt5
parent
15f7e46c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
54 deletions
+58
-54
license-dialog
license-dialog
+58
-54
No files found.
license-dialog
View file @
da269a74
#!/usr/bin/python
# -*- coding: utf-8 -*-
#!/usr/bin/python3
# openmamba license-dialog
# Copyright (C) 2011 by michiamophil
# Copyright (C) 2011-2020 by Silvan Calarco
# Distributed under the terms of the GPL version 3 FLOSS License
import
os
#--Uscite possibili:
import
sys
#---: 0 -> licenza accettata
import
gettext
#---: 1 -> licenza rifiutata
from
PyQt4
import
QtGui
,
QtCore
#---: 2 -> percorso licenza sbagliato o non presente o se l'argomento digitato è -h o --help
#--Uscite possibili:
#---: 0 -> licenza accettata
#---: 1 -> licenza rifiutata
#---: 2 -> percorso licenza sbagliato o non presente o se l'argomento digitato è -h o --help
import
os
import
sys
import
gettext
from
PyQt5.QtWidgets
import
QDesktopWidget
,
QWidget
,
QApplication
,
QToolTip
,
QPushButton
,
\
QTextEdit
,
QGridLayout
from
PyQt5.QtGui
import
QIcon
,
QFont
from
PyQt5.QtCore
import
pyqtSignal
# Decisione presa in run-time
imgAccetto
=
"object-select-symbolic"
imgRifiuto
=
"window-close-symbolic"
imgForm
=
"document"
if
(
os
.
getenv
(
'DESKTOP_SESSION'
)):
desktop_session
=
QtCore
.
QString
(
os
.
getenv
(
'DESKTOP_SESSION'
)
)
# Codice preso da mambatray
if
(
desktop_session
==
'default'
)
or
(
desktop_session
.
left
(
3
)
==
'kde'
)
:
# Scelgo le icone di kde
desktop_session
=
os
.
getenv
(
'DESKTOP_SESSION'
)
# Codice preso da mambatray
if
desktop_session
==
'default'
or
desktop_session
[:
3
]
==
'kde'
:
# Scelgo le icone di kde
imgAccetto
=
"dialog-ok-apply"
imgRifiuto
=
"dialog-close"
imgForm
=
"text-rtf"
def
usage
():
print
_
(
"Usage: license-dialog /license/path"
)
print
_
(
"License-dialog is a simple PyQt
4
based license accept/refuse dialog"
)
print
(
_
(
"Usage: license-dialog /license/path"
)
)
print
(
_
(
"License-dialog is a simple PyQt
5
based license accept/refuse dialog"
)
)
gettext
.
install
(
'license-dialog'
,
'/usr/share/locale'
,
unicode
=
1
)
gettext
.
install
(
'license-dialog'
,
'/usr/share/locale'
)
try
:
path
=
sys
.
argv
[
1
]
#si verifica se non si fornisce alcun argomento
except
:
# si verifica se non si fornisce alcun argomento
usage
()
print
_
(
"Error: path not defined"
)
print
(
_
(
"Error: path not defined"
)
)
sys
.
exit
(
2
)
#controlla se la licenza esiste e la assegna a txt
# controlla se la licenza esiste e la assegna a txt
if
path
==
"-h"
or
path
==
"--help"
:
usage
()
sys
.
exit
(
2
)
#esce con 2 se è una cartella
elif
not
os
.
path
.
exists
(
path
):
# esce con 2 se è una cartella
usage
()
print
_
(
"Error: Wrong path"
)
print
(
_
(
"Error: Wrong path"
)
)
sys
.
exit
(
2
)
elif
os
.
path
.
isdir
(
path
):
usage
()
print
_
(
"Error: path cannot be a directory"
)
print
(
_
(
"Error: path cannot be a directory"
)
)
sys
.
exit
(
2
)
licenza
=
open
(
path
,
"r"
)
txtTp
=
licenza
.
read
()
#così vanno i caratteri accentati sulla QTextEdit
txt
=
txtTp
.
decode
(
"utf-8"
)
txt
=
licenza
.
read
()
licenza
.
close
()
#centra il form sullo schermo
def
center
(
self
):
screen
=
QtGui
.
QDesktopWidget
().
screenGeometry
()
size
=
self
.
geometry
()
self
.
move
((
screen
.
width
()
-
size
.
width
())
/
2
,
(
screen
.
height
()
-
size
.
height
())
/
2
)
screen
=
QDesktopWidget
().
screenGeometry
()
size
=
self
.
geometry
()
self
.
move
((
screen
.
width
()
-
size
.
width
())
/
2
,
(
screen
.
height
()
-
size
.
height
())
/
2
)
class
Form
(
QtGui
.
QWidget
):
class
Form
(
QWidget
):
def
__init__
(
self
,
parent
=
None
):
QtGui
.
QWidget
.
__init__
(
self
,
parent
)
QWidget
.
__init__
(
self
,
parent
)
self
.
setWindowTitle
(
_
(
"Licenze"
))
self
.
setWindowIcon
(
QtGui
.
QIcon
.
fromTheme
(
imgForm
))
self
.
setWindowIcon
(
QIcon
.
fromTheme
(
imgForm
))
self
.
resize
(
500
,
400
)
center
(
self
)
QtGui
.
QToolTip
.
setFont
(
QtGui
.
QFont
(
'sans'
,
10
))
btnAccetto
=
QtGui
.
QPushButton
(
QtGui
.
QIcon
.
fromTheme
(
imgAccetto
),
_
(
"I agree"
))
QToolTip
.
setFont
(
QFont
(
'sans'
,
10
))
btnAccetto
=
QPushButton
(
QIcon
.
fromTheme
(
imgAccetto
),
_
(
"I agree"
))
btnAccetto
.
setToolTip
(
_
(
"Click here if you want to accept the license"
))
self
.
connect
(
btnAccetto
,
QtCore
.
SIGNAL
(
'clicked()'
),
evtAccetto
)
btnAccetto
.
clicked
.
connect
(
self
.
evtAccetto
)
btnRifiuto
=
QtGui
.
QPushButton
(
QtGui
.
QIcon
.
fromTheme
(
imgRifiuto
),
_
(
"I do not agree"
))
btnRifiuto
=
QPushButton
(
QIcon
.
fromTheme
(
imgRifiuto
),
_
(
"I do not agree"
))
btnRifiuto
.
setToolTip
(
_
(
"Click here if you do <b>not</b> want to accept the license"
))
self
.
connect
(
btnRifiuto
,
QtCore
.
SIGNAL
(
'clicked()'
),
evtRifiuto
)
licenza
=
QtGui
.
QTextEdit
()
btnRifiuto
.
clicked
.
connect
(
self
.
evtRifiuto
)
licenza
=
QTextEdit
()
licenza
.
setReadOnly
(
True
)
licenza
.
setPlainText
(
txt
)
grid
=
QtGui
.
QGridLayout
()
grid
.
setSpacing
(
10
)
grid
=
QGridLayout
()
grid
.
setSpacing
(
10
)
grid
.
addWidget
(
licenza
,
1
,
0
,
1
,
2
)
grid
.
addWidget
(
btnRifiuto
,
2
,
0
)
grid
.
addWidget
(
btnAccetto
,
2
,
1
)
self
.
setLayout
(
grid
)
#annulla la chiusura con la x del window manager
#
annulla la chiusura con la x del window manager
def
closeEvent
(
form
,
event
):
event
.
ignore
()
def
evtAccetto
():
sys
.
exit
(
0
)
def
evtAccetto
(
self
):
sys
.
exit
(
0
)
def
evtRifiuto
():
#mostra un messaggio:
#msg = QtGui.QMessageBox.question(form, _("Message"), _("Are you sure to refuse?"), QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No)
#if msg == QtGui.QMessageBox.Yes:
sys
.
exit
(
1
)
def
evtRifiuto
(
self
):
#mostra un messaggio:
#msg = QtGui.QMessageBox.question(form, _("Message"), _("Are you sure to refuse?"), QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No)
#if msg == QtGui.QMessageBox.Yes:
sys
.
exit
(
1
)
#crea la finestra di dialogo
app
=
QtGui
.
QApplication
(
sys
.
argv
)
app
=
QApplication
(
sys
.
argv
)
form
=
Form
()
form
.
show
()
sys
.
exit
(
app
.
exec_
())
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment