usbinstall.py: switch to PyQt6 and major code refactoring
This commit is contained in:
parent
5135626ca1
commit
972ecbcdf9
@ -2,233 +2,245 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright 2011 michiamophil (openmamba user :-)
|
# Copyright 2011 michiamophil (openmamba user :-)
|
||||||
# Copyright 2011-2020 Silvan Calarco
|
# Copyright 2011-2024 Silvan Calarco
|
||||||
# ChangeLog:
|
|
||||||
# (michiamophil on 11/11/11) Rewritten all the graphic code and removed gui.py
|
|
||||||
|
|
||||||
|
|
||||||
from PyQt4 import QtGui, QtCore
|
|
||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
import signal
|
import gettext
|
||||||
import gettext # To translate
|
from PyQt6 import QtCore
|
||||||
|
from PyQt6.QtCore import QRect
|
||||||
|
from PyQt6.QtGui import QIcon, QPixmap
|
||||||
|
from PyQt6.QtWidgets import QApplication, QComboBox, QDialog,\
|
||||||
|
QFileDialog, QFrame, QLabel,\
|
||||||
|
QLineEdit, QMessageBox, QProgressBar, QPushButton
|
||||||
from gi.repository import GLib
|
from gi.repository import GLib
|
||||||
import dbus
|
import dbus
|
||||||
import dbus.service
|
import dbus.service
|
||||||
from dbus.mainloop.glib import DBusGMainLoop
|
from dbus.mainloop.glib import DBusGMainLoop
|
||||||
DBusGMainLoop(set_as_default=True)
|
DBusGMainLoop(set_as_default=True)
|
||||||
#import dbus.glib
|
|
||||||
|
|
||||||
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
|
translator = gettext.translation('usbinstall', '/usr/share/locale')
|
||||||
#1)-------------------------------(VARIABILI)----------------------------------------
|
_ = translator.gettext
|
||||||
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
|
|
||||||
# Icons
|
|
||||||
img_help = "/usr/share/icons/gnome/24x24/status/dialog-question.png"
|
|
||||||
img_fOpen = "/usr/share/icons/gnome/32x32/actions/document-open.png"
|
|
||||||
img_refresh = "/usr/share/icons/gnome/24x24/actions/view-refresh.png"
|
|
||||||
img_pach1 = "/usr/share/openmamba/usbinstall/img/pach1.png"
|
|
||||||
img_cloud = "/usr/share/openmamba/usbinstall/img/nuvola.png"
|
|
||||||
img_exit = "/usr/share/openmamba/usbinstall/img/exit.png"
|
|
||||||
window_icon = "/usr/share/icons/hicolor/32x32/apps/mamba.png"
|
|
||||||
# Global path
|
|
||||||
path_cpio = ""
|
|
||||||
path_iso = ""
|
|
||||||
path_dev = ""
|
|
||||||
# General vars
|
|
||||||
dev_model = ""
|
|
||||||
a_path_dev = [] # Array of choosen devices
|
|
||||||
a_dev_model = [] # Their models.
|
|
||||||
step = 1
|
|
||||||
choose_type = "" # Type of dialog in choose_file()
|
|
||||||
#1)###############################(VARIABILI)########################################
|
|
||||||
|
|
||||||
|
|
||||||
|
# Class for dbus_start()
|
||||||
|
class set_dbus(dbus.service.Object):
|
||||||
|
window = None
|
||||||
|
|
||||||
|
def __init__(self, bus_name, window, object_path='/org/openmamba/usbinstall'):
|
||||||
|
dbus.service.Object.__init__(self, bus_name, object_path)
|
||||||
|
self.window = window
|
||||||
|
|
||||||
|
@dbus.service.method('org.openmamba.usbinstall')
|
||||||
|
def Set_progressBar(self, p):
|
||||||
|
window.p_install.setProperty("value", int(p))
|
||||||
|
return 0
|
||||||
|
|
||||||
|
@dbus.service.method('org.openmamba.usbinstall')
|
||||||
|
def Exit(self, errMsg):
|
||||||
|
if errMsg == "":
|
||||||
|
window.end_with_success()
|
||||||
|
else:
|
||||||
|
window.msg = QMessageBox.critical(window, _("Script Error"), _(errMsg))
|
||||||
|
window.end_forced()
|
||||||
|
return 0
|
||||||
|
|
||||||
|
@dbus.service.method('org.openmamba.usbinstall')
|
||||||
|
def Set_description(self, descr):
|
||||||
|
window.l_descr.setText(descr)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
|
|
||||||
#2)-------------------------------(WINDOW CODE)--------------------------------------
|
|
||||||
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
|
|
||||||
# Contains program's graphic
|
# Contains program's graphic
|
||||||
class create_window(QtGui.QDialog):
|
class MainWindow(QDialog):
|
||||||
|
# Icons
|
||||||
|
img_help = "/usr/share/icons/gnome/24x24/status/dialog-question.png"
|
||||||
|
img_fOpen = "/usr/share/icons/gnome/32x32/actions/document-open.png"
|
||||||
|
img_refresh = "/usr/share/icons/gnome/24x24/actions/view-refresh.png"
|
||||||
|
img_pach1 = "/usr/share/openmamba/usbinstall/img/pach1.png"
|
||||||
|
img_cloud = "/usr/share/openmamba/usbinstall/img/nuvola.png"
|
||||||
|
img_exit = "/usr/share/openmamba/usbinstall/img/exit.png"
|
||||||
|
# Background images
|
||||||
|
img_background1 = "/usr/share/openmamba/usbinstall/img/back1.png"
|
||||||
|
img_background2 = "/usr/share/openmamba/usbinstall/img/back2.png"
|
||||||
|
img_background3 = "/usr/share/openmamba/usbinstall/img/back3.png"
|
||||||
|
# Global path
|
||||||
|
path_iso = ""
|
||||||
|
path_dev = ""
|
||||||
|
# General vars
|
||||||
|
dev_model = ""
|
||||||
|
a_path_dev = [] # Array of choosen devices
|
||||||
|
a_dev_model = [] # Their models.
|
||||||
|
step = 1
|
||||||
|
choose_type = "" # Type of dialog in choose_file()
|
||||||
|
|
||||||
# Call when is called create_window()
|
# Call when is called create_window()
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(create_window, self).__init__() # Register eventClose()
|
super().__init__()
|
||||||
self.add_elements()
|
self.add_elements()
|
||||||
|
self.add_events()
|
||||||
|
|
||||||
# Write window and objects
|
# Write window and objects
|
||||||
def add_elements(self):
|
def add_elements(self):
|
||||||
# Window proprieties
|
# Window proprieties
|
||||||
self.resize(500, 405)
|
self.resize(500, 405)
|
||||||
self.setWindowIcon(QtGui.QIcon(window_icon))
|
self.setWindowIcon(QIcon.fromTheme("openmamba"))
|
||||||
# Background image
|
# Background image
|
||||||
self.i_back = QtGui.QLabel(self)
|
self.i_back = QLabel(self)
|
||||||
self.i_back.setGeometry(QtCore.QRect(10, 10, 480, 300))
|
self.i_back.setGeometry(QRect(10, 10, 480, 300))
|
||||||
# Description label
|
# Description label
|
||||||
self.l_descr = QtGui.QLabel(self)
|
self.l_descr = QLabel(self)
|
||||||
self.l_descr.setGeometry(QtCore.QRect(10, 317, 351, 31))
|
self.l_descr.setGeometry(QRect(10, 317, 351, 31))
|
||||||
# Orizontal line
|
# Orizontal line
|
||||||
self.line = QtGui.QFrame(self)
|
self.line = QFrame(self)
|
||||||
self.line.setGeometry(QtCore.QRect(10, 350, 481, 20))
|
self.line.setGeometry(QRect(10, 350, 481, 20))
|
||||||
self.line.setFrameShape(QtGui.QFrame.HLine)
|
self.line.setFrameShape(QFrame.Shape.HLine)
|
||||||
self.line.setFrameShadow(QtGui.QFrame.Sunken)
|
self.line.setFrameShadow(QFrame.Shadow.Sunken)
|
||||||
# "Next" button
|
# "Next" button
|
||||||
self.b_next = QtGui.QPushButton(self)
|
self.b_next = QPushButton(self)
|
||||||
self.b_next.setGeometry(QtCore.QRect(400, 370, 90, 29))
|
self.b_next.setGeometry(QRect(400, 370, 90, 29))
|
||||||
self.b_next.setText(_("Go on"))
|
self.b_next.setText(_("Go on"))
|
||||||
# "Go Back" button
|
# "Go Back" button
|
||||||
self.b_back = QtGui.QPushButton(self)
|
self.b_back = QPushButton(self)
|
||||||
self.b_back.setGeometry(QtCore.QRect(300, 370, 90, 29))
|
self.b_back.setGeometry(QRect(300, 370, 90, 29))
|
||||||
# "Help" button
|
# "Help" button
|
||||||
self.b_help = QtGui.QPushButton(QtGui.QIcon(img_help), "", self)
|
self.b_help = QPushButton(QIcon(self.img_help), "", self)
|
||||||
self.b_help.setGeometry(QtCore.QRect(464, 320, 26, 26))
|
self.b_help.setGeometry(QRect(464, 320, 26, 26))
|
||||||
self.b_help.setIconSize(QtCore.QSize(24, 24))
|
self.b_help.setIconSize(QtCore.QSize(24, 24))
|
||||||
self.b_help.setFlat(True)
|
self.b_help.setFlat(True)
|
||||||
# Path line edit
|
# Path line edit
|
||||||
self.t_file = QtGui.QLineEdit(self)
|
self.t_file = QLineEdit(self)
|
||||||
self.t_file.setGeometry(QtCore.QRect(212, 321, 222, 25))
|
self.t_file.setGeometry(QRect(212, 321, 222, 25))
|
||||||
# Pach line edit
|
# Pach line edit
|
||||||
self.pach1 = QtGui.QLabel(self)
|
self.pach1 = QLabel(self)
|
||||||
self.pach1.setGeometry(QtCore.QRect(430, 320, 32, 27))
|
self.pach1.setGeometry(QRect(430, 320, 32, 27))
|
||||||
self.pach1.setPixmap(QtGui.QPixmap(img_pach1))
|
self.pach1.setPixmap(QPixmap(self.img_pach1))
|
||||||
# Open file button
|
# Open file button
|
||||||
self.b_open_file = QtGui.QPushButton(QtGui.QIcon(img_fOpen), "", self)
|
self.b_open_file = QPushButton(QIcon(self.img_fOpen), "", self)
|
||||||
self.b_open_file.setGeometry(QtCore.QRect(431, 320, 31, 27))
|
self.b_open_file.setGeometry(QRect(431, 320, 31, 27))
|
||||||
self.b_open_file.setFlat(True)
|
self.b_open_file.setFlat(True)
|
||||||
# Help dialog image
|
# Help dialog image
|
||||||
self.i_cloud = QtGui.QLabel(self)
|
self.i_cloud = QLabel(self)
|
||||||
self.i_cloud.setGeometry(QtCore.QRect(289, 200, 211, 121))
|
self.i_cloud.setGeometry(QRect(289, 200, 211, 121))
|
||||||
self.i_cloud.setPixmap(QtGui.QPixmap(img_cloud))
|
self.i_cloud.setPixmap(QPixmap(self.img_cloud))
|
||||||
self.i_cloud.hide()
|
self.i_cloud.hide()
|
||||||
# Help dialog text
|
# Help dialog text
|
||||||
self.l_cloud = QtGui.QLabel(self)
|
self.l_cloud = QLabel(self)
|
||||||
self.l_cloud.setGeometry(QtCore.QRect(298, 200, 181, 101))
|
self.l_cloud.setStyleSheet("QLabel { color : blue; }");
|
||||||
|
self.l_cloud.setGeometry(QRect(298, 200, 181, 101))
|
||||||
self.l_cloud.setOpenExternalLinks(True)
|
self.l_cloud.setOpenExternalLinks(True)
|
||||||
self.l_cloud.setWordWrap(True)
|
self.l_cloud.setWordWrap(True)
|
||||||
self.l_cloud.hide()
|
self.l_cloud.hide()
|
||||||
# Help dialog exit
|
# Help dialog exit
|
||||||
self.b_cloud = QtGui.QPushButton(QtGui.QIcon(img_exit), "", self)
|
self.b_cloud = QPushButton(QIcon(self.img_exit), "", self)
|
||||||
self.b_cloud.setGeometry(QtCore.QRect(471, 202, 14, 14))
|
self.b_cloud.setGeometry(QRect(471, 202, 14, 14))
|
||||||
self.b_cloud.setFlat(True)
|
self.b_cloud.setFlat(True)
|
||||||
self.b_cloud.hide()
|
self.b_cloud.hide()
|
||||||
# Refresh button
|
# Refresh button
|
||||||
self.b_refresh = QtGui.QPushButton(QtGui.QIcon(img_refresh), "", self)
|
self.b_refresh = QPushButton(QIcon(self.img_refresh), "", self)
|
||||||
self.b_refresh.setGeometry(QtCore.QRect(435, 320, 26, 26))
|
self.b_refresh.setGeometry(QRect(435, 320, 26, 26))
|
||||||
self.b_refresh.setIconSize(QtCore.QSize(24, 24))
|
self.b_refresh.setIconSize(QtCore.QSize(24, 24))
|
||||||
self.b_refresh.setFlat(True)
|
self.b_refresh.setFlat(True)
|
||||||
# List of usb (combobox)
|
# List of usb (combobox)
|
||||||
self.c_usb = QtGui.QComboBox(self)
|
self.c_usb = QComboBox(self)
|
||||||
self.c_usb.setGeometry(QtCore.QRect(158, 320, 271, 25))
|
self.c_usb.setGeometry(QRect(158, 320, 271, 25))
|
||||||
# Progressbar
|
# Progressbar
|
||||||
self.p_install = QtGui.QProgressBar(self)
|
self.p_install = QProgressBar(self)
|
||||||
self.p_install.setGeometry(QtCore.QRect(10, 354, 480, 36))
|
self.p_install.setGeometry(QRect(10, 354, 480, 36))
|
||||||
self.p_install.hide()
|
self.p_install.hide()
|
||||||
# Show the window
|
# Show the window
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
# Intercept close event
|
# Intercept close event
|
||||||
def closeEvent(self, event):
|
def closeEvent(self, event):
|
||||||
msg = QtGui.QMessageBox.question(window, _("Attention"), _("Are you sure to abort?"), QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No)
|
msg = QMessageBox.question(window, _("Attention"), _("Are you sure to abort?"),
|
||||||
|
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No, QMessageBox.StandardButton.No)
|
||||||
# Exit if was pressed yes button
|
# Exit if was pressed yes button
|
||||||
if msg == QtGui.QMessageBox.Yes:
|
if msg == QMessageBox.StandardButton.Yes:
|
||||||
end_forced()
|
self.end_forced()
|
||||||
else:
|
else:
|
||||||
event.ignore()
|
event.ignore()
|
||||||
|
|
||||||
#2)###############################(WINDOW CODE)######################################
|
# Events handler
|
||||||
|
def add_events(self):
|
||||||
|
self.b_next.clicked.connect(self.go_on)
|
||||||
|
self.b_back.clicked.connect(self.go_back)
|
||||||
|
self.b_open_file.clicked.connect(self.choose_file)
|
||||||
|
self.b_help.clicked.connect(self.manage_cloud)
|
||||||
|
self.b_cloud.clicked.connect(self.close_cloud)
|
||||||
|
self.b_refresh.clicked.connect(self.get_list)
|
||||||
|
self.c_usb.activated.connect(self.set_usb)
|
||||||
|
|
||||||
|
# Event n°1
|
||||||
|
def go_on(self):
|
||||||
|
self.cloud_hide()
|
||||||
|
|
||||||
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
|
|
||||||
#3)-----------------------------(EVENTS HANDLER)-------------------------------------
|
|
||||||
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
|
|
||||||
# Add SIGNINT event
|
|
||||||
#signal.signal(signal.SIGINT, zz)
|
|
||||||
|
|
||||||
def add_events():
|
|
||||||
app.connect(window.b_next, QtCore.SIGNAL('clicked()'), go_on) # Event n°1
|
|
||||||
app.connect(window.b_back, QtCore.SIGNAL('clicked()'), go_back) # Event n°2
|
|
||||||
app.connect(window.b_open_file, QtCore.SIGNAL('clicked()'), choose_file) # Event n°3
|
|
||||||
app.connect(window.b_help, QtCore.SIGNAL('clicked()'), manage_cloud) # Event n°4
|
|
||||||
app.connect(window.b_cloud, QtCore.SIGNAL('clicked()'), close_cloud) # Event n°5
|
|
||||||
app.connect(window.b_refresh, QtCore.SIGNAL('clicked()'), get_list) # Event n°6
|
|
||||||
app.connect(window.c_usb, QtCore.SIGNAL("activated(int)"), set_usb) # Event n°7
|
|
||||||
|
|
||||||
# Event n°1
|
|
||||||
def go_on():
|
|
||||||
global step, path_cpio, path_iso, path_dev, dev_model
|
|
||||||
cloud_hide()
|
|
||||||
# Step 1 to 2
|
# Step 1 to 2
|
||||||
if step == 1:
|
if self.step == 1:
|
||||||
if path_iso == "":
|
if self.path_iso == "":
|
||||||
msg_warn(_("An openmamba's iso is required"))
|
self.msg_warn(_("An openmamba's iso is required"))
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
step += 1
|
self.step += 1
|
||||||
step2()
|
self.step2()
|
||||||
# Step 2 to 3
|
# Step 2 to 3
|
||||||
elif step == 2:
|
elif self.step == 2:
|
||||||
if path_dev == "":
|
if self.path_dev == "":
|
||||||
msg_warn(_("You must choose a usb key"))
|
self.msg_warn(_("You must choose a usb key"))
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
msg = QtGui.QMessageBox.question(window, _("Attention"), _("All data on the key ") + dev_model + _(" will be lost. \n")+ _("Are you sure to continue?"),
|
msg = QMessageBox.question(window, _("Attention"), _("All data on the key ") +
|
||||||
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No)
|
self.dev_model + _(" will be lost. \n")+ _("Are you sure to continue?"),
|
||||||
|
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
|
||||||
|
QMessageBox.StandardButton.No)
|
||||||
# Go on only if was pressed yes button
|
# Go on only if was pressed yes button
|
||||||
if msg == QtGui.QMessageBox.Yes:
|
if msg == QMessageBox.StandardButton.Yes:
|
||||||
step += 1
|
self.step += 1
|
||||||
step3()
|
self.step3()
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Event n°2
|
# Event n°2
|
||||||
def go_back():
|
def go_back(self):
|
||||||
global step
|
self.step -= 1
|
||||||
step -= 1
|
self.cloud_hide()
|
||||||
cloud_hide()
|
self.obj_chang_hide()
|
||||||
obj_chang_hide()
|
|
||||||
# Step 1 to 0 -> exit
|
# Step 1 to 0 -> exit
|
||||||
if step == 0:
|
if self.step == 0:
|
||||||
app.exit(1)
|
app.exit(1)
|
||||||
print (_("Application terminated by pressing \"cancel\" button"))
|
print (_("Application terminated by pressing \"cancel\" button"))
|
||||||
# Step 2 to 1
|
# Step 2 to 1
|
||||||
elif step == 1:
|
elif self.step == 1:
|
||||||
step1()
|
self.step1()
|
||||||
# Step 3 to 2
|
# Step 3 to 2
|
||||||
elif step == 2:
|
elif self.step == 2:
|
||||||
step2()
|
self.step2()
|
||||||
|
|
||||||
# Event n°3
|
# Event n°3
|
||||||
def choose_file():
|
def choose_file(self):
|
||||||
global path_cpio, path_iso, choose_type
|
|
||||||
# if step is 1
|
# if step is 1
|
||||||
if choose_type == "iso":
|
if self.choose_type == "iso":
|
||||||
nfileName = QtGui.QFileDialog.getOpenFileName(window, _("Choose the iso file"), "/home", "File .iso (*.iso)")
|
nfileName = QFileDialog.getOpenFileName(window, _("Choose the iso file"), "/home", "File .iso (*.iso)")
|
||||||
path_iso = nfileName
|
self.path_iso = nfileName[0]
|
||||||
window.t_file.setText(nfileName)
|
self.t_file.setText(nfileName[0])
|
||||||
|
|
||||||
# Event n°4
|
# Event n°4
|
||||||
def manage_cloud():
|
def manage_cloud(self):
|
||||||
global step
|
if self.step == 1:
|
||||||
if step == 1:
|
|
||||||
aiuto = _("The file .iso contains the operating system. You can download it from <a style=\"color: green; \"href=\"http://www.openmamba.org/distribution/download.html?lang=en\">here</a>")
|
aiuto = _("The file .iso contains the operating system. You can download it from <a style=\"color: green; \"href=\"http://www.openmamba.org/distribution/download.html?lang=en\">here</a>")
|
||||||
elif step == 2:
|
elif self.step == 2:
|
||||||
aiuto = _("Choose an usb key for the installation. <span style=\"color:red;\">All data will be lost</span>")
|
aiuto = _("Choose an usb key for the installation. <span style=\"color:red;\">All data will be lost</span>")
|
||||||
window.l_cloud.setText(aiuto)
|
self.l_cloud.setText(aiuto)
|
||||||
cloud_show()
|
self.cloud_show()
|
||||||
|
|
||||||
# Event n°5
|
# Event n°5
|
||||||
def close_cloud():
|
def close_cloud(self):
|
||||||
cloud_hide()
|
self.cloud_hide()
|
||||||
|
|
||||||
# Event n°6
|
|
||||||
def get_list():
|
|
||||||
global a_path_dev, a_dev_model
|
|
||||||
|
|
||||||
|
# Event n°6
|
||||||
|
def get_list(self):
|
||||||
# Clear array and comboBox
|
# Clear array and comboBox
|
||||||
a_path_dev = []
|
self.a_path_dev.clear()
|
||||||
a_dev_model = []
|
self.a_dev_model.clear()
|
||||||
window.c_usb.clear()
|
self.c_usb.clear()
|
||||||
i = 0
|
i = 0
|
||||||
|
|
||||||
# Get list form dbus
|
# Get list form dbus
|
||||||
@ -245,172 +257,132 @@ def get_list():
|
|||||||
device = bytearray(device).replace(b'\x00', b'').decode('utf-8')
|
device = bytearray(device).replace(b'\x00', b'').decode('utf-8')
|
||||||
device_drive = bus.get_object('org.freedesktop.UDisks2', drive)
|
device_drive = bus.get_object('org.freedesktop.UDisks2', drive)
|
||||||
try:
|
try:
|
||||||
removable = device_drive.Get('org.freedesktop.UDisks2.Drive', 'Removable', dbus_interface='org.freedesktop.DBus.Properties')
|
removable = device_drive.Get('org.freedesktop.UDisks2.Drive', 'Removable',
|
||||||
|
dbus_interface='org.freedesktop.DBus.Properties')
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
size = device_drive.Get('org.freedesktop.UDisks2.Drive', 'Size', dbus_interface='org.freedesktop.DBus.Properties')
|
size = device_drive.Get('org.freedesktop.UDisks2.Drive', 'Size',
|
||||||
|
dbus_interface='org.freedesktop.DBus.Properties')
|
||||||
if removable and size > 891289600 and not device_block.get('ReadOnly') and \
|
if removable and size > 891289600 and not device_block.get('ReadOnly') and \
|
||||||
not device_block.get('HintSystem') and device_block.get('HintPartitionable'):
|
not device_block.get('HintSystem') and device_block.get('HintPartitionable'):
|
||||||
connectionbus = device_drive.Get('org.freedesktop.UDisks2.Drive', 'ConnectionBus', dbus_interface='org.freedesktop.DBus.Properties')
|
model = device_drive.Get('org.freedesktop.UDisks2.Drive', 'Model',
|
||||||
model = device_drive.Get('org.freedesktop.UDisks2.Drive', 'Model', dbus_interface='org.freedesktop.DBus.Properties')
|
dbus_interface='org.freedesktop.DBus.Properties')
|
||||||
vendor = device_drive.Get('org.freedesktop.UDisks2.Drive', 'Vendor', dbus_interface='org.freedesktop.DBus.Properties')
|
vendor = device_drive.Get('org.freedesktop.UDisks2.Drive', 'Vendor',
|
||||||
|
dbus_interface='org.freedesktop.DBus.Properties')
|
||||||
if removable:
|
if removable:
|
||||||
a_path_dev.append(device)
|
self.a_path_dev.append(device)
|
||||||
a_dev_model.append(vendor + " " + model)
|
self.a_dev_model.append(vendor + " " + model)
|
||||||
# And add element to comboBox
|
# And add element to comboBox
|
||||||
window.c_usb.addItem(a_dev_model[i] + " (" + "{0:.2f}".format(size / 1024.0 / 1024.0 / 1024.0) + " GiB)")
|
self.c_usb.addItem(self.a_dev_model[i] + " (" +
|
||||||
|
"{0:.2f}".format(size / 1024.0 / 1024.0 / 1024.0) + " GiB)")
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
# First dev is default
|
# First dev is default
|
||||||
if len(a_path_dev) != 0:
|
if len(self.a_path_dev) != 0:
|
||||||
set_usb(0)
|
self.set_usb(0)
|
||||||
else:
|
else:
|
||||||
print (_("No usb available > 1 Gb"))
|
print (_("No usb available > 1 Gb"))
|
||||||
|
|
||||||
# Event n°7
|
# Event n°7
|
||||||
def set_usb(i):
|
def set_usb(self, i):
|
||||||
global path_dev, dev_model, a_path_dev, a_dev_model
|
self.path_dev = self.a_path_dev[i]
|
||||||
path_dev = a_path_dev[i]
|
dev_model = self.a_dev_model[i]
|
||||||
dev_model = a_dev_model[i]
|
|
||||||
#3)#############################(EVENTS HANDLER)#####################################
|
|
||||||
|
|
||||||
|
# Show all cloud objects
|
||||||
|
def cloud_show(self):
|
||||||
|
self.i_cloud.show()
|
||||||
|
self.b_cloud.show()
|
||||||
|
self.l_cloud.show()
|
||||||
|
|
||||||
|
# Hide all cloud objects
|
||||||
|
def cloud_hide(self):
|
||||||
|
self.i_cloud.hide()
|
||||||
|
self.b_cloud.hide()
|
||||||
|
self.l_cloud.hide()
|
||||||
|
|
||||||
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
|
# Warning dialog abbreviation
|
||||||
#4)-------------------------------(DBUS CODE)----------------------------------------
|
def msg_warn(self, txt):
|
||||||
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
|
self.msg = QMessageBox.warning(window, _("Attention"), txt)
|
||||||
# Class for dbus_start()
|
|
||||||
class set_dbus(dbus.service.Object):
|
|
||||||
def __init__(self, bus_name, object_path='/org/openmamba/usbinstall'):
|
|
||||||
dbus.service.Object.__init__(self, bus_name, object_path)
|
|
||||||
|
|
||||||
@dbus.service.method('org.openmamba.usbinstall')
|
# Called when b_next was pressed
|
||||||
def Set_progressBar(self, p):
|
def set_objs(self, i_back, title, descr):
|
||||||
window.p_install.setProperty("value", int(p))
|
self.i_back.setPixmap(QPixmap(i_back))
|
||||||
return 0
|
self.setWindowTitle(title)
|
||||||
|
self.l_descr.setText(descr)
|
||||||
|
|
||||||
@dbus.service.method('org.openmamba.usbinstall')
|
def step1(self):
|
||||||
def Exit(self, errMsg):
|
self.choose_type = "iso"
|
||||||
if errMsg == "":
|
self.t_file.setText(self.path_iso) # Clean path box
|
||||||
end_with_success()
|
self.b_back.setText(_("Cancel"))
|
||||||
else:
|
self.set_objs(self.img_background1,
|
||||||
msg = QtGui.QMessageBox.critical(window, _("Script Error"), _(errMsg))
|
_("Step 1/3 - choice of ISO file"), _("Choose the openmamba ISO file")+":")
|
||||||
end_forced()
|
self.obj_chang_hide()
|
||||||
return 0
|
self.list_obj1() # Show a set of object
|
||||||
|
|
||||||
@dbus.service.method('org.openmamba.usbinstall')
|
def step2(self):
|
||||||
def Set_description(self, descr):
|
self.set_objs(self.img_background2,
|
||||||
window.l_descr.setText(descr)
|
_("Step 2/3 - choice of USB key"), _("Choose the USB key")+":")
|
||||||
return 0
|
self.b_back.setText(_("Back"))
|
||||||
|
self.obj_chang_hide()
|
||||||
|
self.list_obj2()
|
||||||
|
self.get_list() # Get available devices
|
||||||
|
|
||||||
def dbus_start():
|
def step3(self):
|
||||||
bus_name = dbus.service.BusName('org.openmamba.usbinstall', bus=dbus.SystemBus())
|
self.set_objs(self.img_background3,
|
||||||
dbus_loop = set_dbus(bus_name)
|
_("Step 3/3 - installation of openmamba to USB"),
|
||||||
bus = dbus.SystemBus(mainloop=dbus_loop)
|
_("Installation in progress..."))
|
||||||
#4)###############################(DBUS CODE)########################################
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
|
|
||||||
#5)------------------------------(PROGRAM CODE)--------------------------------------
|
|
||||||
#=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
|
|
||||||
# Show all cloud objects
|
|
||||||
def cloud_show():
|
|
||||||
window.i_cloud.show()
|
|
||||||
window.b_cloud.show()
|
|
||||||
window.l_cloud.show()
|
|
||||||
|
|
||||||
# Hide all cloud objects
|
|
||||||
def cloud_hide():
|
|
||||||
window.i_cloud.hide()
|
|
||||||
window.b_cloud.hide()
|
|
||||||
window.l_cloud.hide()
|
|
||||||
|
|
||||||
# Warning dialog abbreviation
|
|
||||||
def msg_warn(txt):
|
|
||||||
msg = QtGui.QMessageBox.warning(window, _("Attention"), txt)
|
|
||||||
|
|
||||||
# Called when b_next was pressed
|
|
||||||
def set_objs(i_back, title, descr):
|
|
||||||
|
|
||||||
window.i_back.setPixmap(QtGui.QPixmap(i_back))
|
|
||||||
window.setWindowTitle(title)
|
|
||||||
window.l_descr.setText(descr)
|
|
||||||
|
|
||||||
|
|
||||||
def step1():
|
|
||||||
global choose_type, path_iso
|
|
||||||
choose_type = "iso"
|
|
||||||
path_iso = ""
|
|
||||||
window.t_file.setText(path_iso) # Clean path box
|
|
||||||
window.b_back.setText(_("Cancel"))
|
|
||||||
set_objs("/usr/share/openmamba/usbinstall/img/back1.png", _("Step 1/3 - choice of ISO file"), _("Choose the openmamba ISO file")+":")
|
|
||||||
obj_chang_hide()
|
|
||||||
list_obj1() # Show a set of object
|
|
||||||
|
|
||||||
def step2():
|
|
||||||
set_objs("/usr/share/openmamba/usbinstall/img/back2.png", _("Step 2/3 - choice of USB key"), _("Choose the USB key")+":")
|
|
||||||
obj_chang_hide()
|
|
||||||
list_obj2()
|
|
||||||
get_list() # Get available devices
|
|
||||||
|
|
||||||
def step3():
|
|
||||||
global process_sh
|
|
||||||
set_objs("/usr/share/openmamba/usbinstall/img/back3.png", _("Step 3/3 - installation of openmamba to USB"), _("Installation in progress..."))
|
|
||||||
# Hide all unnecessary objects
|
# Hide all unnecessary objects
|
||||||
obj_chang_hide()
|
self.obj_chang_hide()
|
||||||
window.b_help.hide()
|
self.b_help.hide()
|
||||||
window.line.hide()
|
self.line.hide()
|
||||||
window.b_back.hide()
|
self.b_back.hide()
|
||||||
window.b_next.hide()
|
self.b_next.hide()
|
||||||
# Show the progressBar
|
# Show the progressBar
|
||||||
window.p_install.show()
|
self.p_install.show()
|
||||||
dbus_start()
|
bus_name = dbus.service.BusName('org.openmamba.usbinstall', bus=dbus.SystemBus())
|
||||||
process_sh = Popen(["pkexec", "/usr/sbin/usbinstall", path_dev, path_iso, "-d"])
|
self.dbus_loop = set_dbus(bus_name, self)
|
||||||
|
self.bus = dbus.SystemBus(mainloop=self.dbus_loop)
|
||||||
|
|
||||||
# Show a list of object (step 1)
|
print("calling pkexec /usr/sbin/usbinstall " + self.path_dev + " " + self.path_iso + " -d")
|
||||||
def list_obj1():
|
self.process_sh = Popen(["pkexec", "/usr/sbin/usbinstall",
|
||||||
window.t_file.show()
|
self.path_dev, self.path_iso, "-d"])
|
||||||
window.pach1.show()
|
|
||||||
window.b_open_file.show()
|
|
||||||
|
|
||||||
# Show a list of object (step 2)
|
# Show a list of object (step 1)
|
||||||
def list_obj2():
|
def list_obj1(self):
|
||||||
window.c_usb.show()
|
self.t_file.show()
|
||||||
window.b_refresh.show()
|
self.pach1.show()
|
||||||
|
self.b_open_file.show()
|
||||||
|
|
||||||
# Hide all object that when b_next or b_back was pressed are changing
|
# Show a list of object (step 2)
|
||||||
def obj_chang_hide():
|
def list_obj2(self):
|
||||||
window.t_file.hide()
|
self.c_usb.show()
|
||||||
window.pach1.hide()
|
self.b_refresh.show()
|
||||||
window.b_open_file.hide()
|
|
||||||
window.c_usb.hide()
|
|
||||||
window.b_refresh.hide()
|
|
||||||
|
|
||||||
def end_with_success():
|
# Hide all object that when b_next or b_back was pressed are changing
|
||||||
global process_sh, mainloop
|
def obj_chang_hide(self):
|
||||||
msg = QtGui.QMessageBox.information(window, _("Information"), _("Installation process completed"))
|
self.t_file.hide()
|
||||||
|
self.pach1.hide()
|
||||||
|
self.b_open_file.hide()
|
||||||
|
self.c_usb.hide()
|
||||||
|
self.b_refresh.hide()
|
||||||
|
|
||||||
|
def end_with_success(self):
|
||||||
|
self.msg = QMessageBox.information(window, _("Information"),
|
||||||
|
_("Installation process completed"))
|
||||||
mainloop.quit()
|
mainloop.quit()
|
||||||
app.exit(0)
|
app.exit(0)
|
||||||
print (_("Installation process completed"))
|
print (_("Installation process completed"))
|
||||||
|
|
||||||
def end_forced():
|
def end_forced(self):
|
||||||
global process_sh, mainloop
|
|
||||||
mainloop.quit()
|
mainloop.quit()
|
||||||
#print _("Installation aborted")
|
#print _("Installation aborted")
|
||||||
app.exit(1)
|
app.exit(1)
|
||||||
|
|
||||||
# Program start
|
|
||||||
app = QtGui.QApplication(['usbinstall'])
|
|
||||||
gettext.install('usbinstall', '/usr/share/locale')
|
|
||||||
window = create_window()
|
|
||||||
mainloop = GLib.MainLoop()
|
|
||||||
|
|
||||||
def run():
|
# Program start
|
||||||
add_events()
|
|
||||||
step1()
|
|
||||||
return app.exec_()
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
run()
|
app = QApplication(['usbinstall'])
|
||||||
#5)##############################(PROGRAM CODE)######################################
|
window = MainWindow()
|
||||||
|
mainloop = GLib.MainLoop()
|
||||||
|
window.step1()
|
||||||
|
app.exec()
|
||||||
|
Loading…
Reference in New Issue
Block a user