summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPapoteur <papoteur@mageia.org>2023-01-20 14:54:41 +0100
committerPapoteur <papoteur@mageia.org>2023-01-20 14:54:41 +0100
commita9486d0297dc7beb816173494cfa28e8ac74a761 (patch)
tree4151a1ba349ceee060044406af5ee06941b6b96f
parent0e8dadef2d95c7cd9eb86345c5dcfa7399bc896b (diff)
downloadmageiawelcome-a9486d0297dc7beb816173494cfa28e8ac74a761.tar
mageiawelcome-a9486d0297dc7beb816173494cfa28e8ac74a761.tar.gz
mageiawelcome-a9486d0297dc7beb816173494cfa28e8ac74a761.tar.bz2
mageiawelcome-a9486d0297dc7beb816173494cfa28e8ac74a761.tar.xz
mageiawelcome-a9486d0297dc7beb816173494cfa28e8ac74a761.zip
format code with black
-rw-r--r--qml/mageiawelcome.py211
1 files changed, 135 insertions, 76 deletions
diff --git a/qml/mageiawelcome.py b/qml/mageiawelcome.py
index f768df3..fa1ed46 100644
--- a/qml/mageiawelcome.py
+++ b/qml/mageiawelcome.py
@@ -2,21 +2,36 @@
# -*- coding: utf-8 -*-
from PyQt5.QtGui import QGuiApplication, QIcon, QScreen
from PyQt5.QtQuick import QQuickView
-from PyQt5.QtCore import QUrl, QLocale, QTranslator, QLibraryInfo, QVariant, QAbstractListModel, \
- QModelIndex, Qt, QObject, pyqtSlot, pyqtSignal, QCoreApplication
+from PyQt5.QtCore import (
+ QUrl,
+ QLocale,
+ QTranslator,
+ QLibraryInfo,
+ QVariant,
+ QAbstractListModel,
+ QModelIndex,
+ Qt,
+ QObject,
+ pyqtSlot,
+ pyqtSignal,
+ QCoreApplication,
+)
from PyQt5.QtNetwork import QNetworkConfigurationManager, QNetworkConfiguration
import sys
import os
import subprocess
from helpers import get_desktop_name, get_desktop_name2, is_installed
import pwd
+
# Workaround for opengl lib selection
from OpenGL import GL
translate = QCoreApplication.translate
+
class ConfList(QAbstractListModel):
NameRole = Qt.UserRole + 1
+
def __init__(self, parent=None):
super().__init__(parent)
# Changing working directory
@@ -24,66 +39,92 @@ class ConfList(QAbstractListModel):
dname = os.path.dirname(abspath)
os.chdir(dname)
- #collect sys info
- release = subprocess.getoutput('lsb_release -sd')
+ # collect sys info
+ release = subprocess.getoutput("lsb_release -sd")
release = release[1:-1]
- release_nb = subprocess.getoutput('lsb_release -sr')
+ release_nb = subprocess.getoutput("lsb_release -sr")
release_nb = release_nb.strip()
- kernel = subprocess.getoutput('uname -r')
- if os.uname()[4] == 'x86_64':
- arch = '64-bit'
- elif os.uname()[4] == 'i586':
- arch = '32-bit'
+ kernel = subprocess.getoutput("uname -r")
+ if os.uname()[4] == "x86_64":
+ arch = "64-bit"
+ elif os.uname()[4] == "i586":
+ arch = "32-bit"
else:
arch = os.uname()[4]
try:
desktop = get_desktop_name(os.path.basename(os.getenv("DESKTOP_SESSION")))
except:
- desktop = 'Other'
+ desktop = "Other"
- if desktop == 'Other':
- desktop = get_desktop_name2(os.getenv("XDG_CURRENT_DESKTOP"))
- if desktop == 'unknown':
- desktop = os.getenv("XDG_CURRENT_DESKTOP")
+ if desktop == "Other":
+ desktop = get_desktop_name2(os.getenv("XDG_CURRENT_DESKTOP"))
+ if desktop == "unknown":
+ desktop = os.getenv("XDG_CURRENT_DESKTOP")
self.screen_factor = 0.0
- if desktop == 'Gnome Wayland':
+ if desktop == "Gnome Wayland":
import gi
- gi.require_version('Gdk', '3.0')
+
+ gi.require_version("Gdk", "3.0")
from gi.repository.Gdk import Display
+
# pre-3.22, otherwise deprecated
- #factor = Gdk.Screen.get_default().get_monitor_scale_factor(0)
+ # factor = Gdk.Screen.get_default().get_monitor_scale_factor(0)
self.screen_factor = Display.get_default().get_monitor(0).get_scale_factor()
# Search active network connections
net = QNetworkConfigurationManager()
first = True
if net.isOnline():
- confs = net.allConfigurations(QNetworkConfiguration.Active)
- for conf in confs:
- if first:
- netconfs = conf.name()
- first = False
- else:
- netconfs += ", " + conf.name()
+ confs = net.allConfigurations(QNetworkConfiguration.Active)
+ for conf in confs:
+ if first:
+ netconfs = conf.name()
+ first = False
+ else:
+ netconfs += ", " + conf.name()
self.configuration = [
- {'name': translate('ConfList',"<b>Congratulations!</b><BR />You are now running {}").format(release)},
- {'name': translate('ConfList',"You are using linux kernel: {}").format(kernel)},
- {'name': translate('ConfList',"Your system architecture is: {}").format(arch)},
- {'name': translate('ConfList',"You are now using the Desktop: {}").format(desktop)},
- {'name': translate('ConfList',"Your user id is: {}").format(os.getuid())},
+ {
+ "name": translate(
+ "ConfList", "<b>Congratulations!</b><BR />You are now running {}"
+ ).format(release)
+ },
+ {
+ "name": translate("ConfList", "You are using linux kernel: {}").format(
+ kernel
+ )
+ },
+ {
+ "name": translate("ConfList", "Your system architecture is: {}").format(
+ arch
+ )
+ },
+ {
+ "name": translate(
+ "ConfList", "You are now using the Desktop: {}"
+ ).format(desktop)
+ },
+ {"name": translate("ConfList", "Your user id is: {}").format(os.getuid())},
]
if net.isOnline():
- self.configuration.append({'name': translate('ConfList',"You are connected to a network through {}").format(netconfs)})
+ self.configuration.append(
+ {
+ "name": translate(
+ "ConfList", "You are connected to a network through {}"
+ ).format(netconfs)
+ }
+ )
else:
- self.configuration.append({'name': translate('ConfList',"You have no network connection")})
+ self.configuration.append(
+ {"name": translate("ConfList", "You have no network connection")}
+ )
def factor(self, app):
- '''
+ """
Determine screen factor
Can be specific for Gnome Wayland
- '''
- if self.screen_factor == 0 :
+ """
+ if self.screen_factor == 0:
screen = app.primaryScreen()
self.screen_factor = screen.devicePixelRatio()
return self.screen_factor
@@ -97,9 +138,10 @@ class ConfList(QAbstractListModel):
def roleNames(self):
return {
- ConfList.NameRole: b'name',
+ ConfList.NameRole: b"name",
}
+
class Callbrowser(QObject):
def __init__(self):
QObject.__init__(self)
@@ -108,9 +150,10 @@ class Callbrowser(QObject):
def weblink(self, link):
subprocess.Popen(["xdg-open", link])
+
class Launcher(QObject):
installed = pyqtSignal()
- needed = pyqtSignal(str, arguments=['repo'])
+ needed = pyqtSignal(str, arguments=["repo"])
repo = pyqtSignal()
noprogram = pyqtSignal()
@@ -121,12 +164,12 @@ class Launcher(QObject):
def command(self, app):
if app.isArray():
cmd = []
- for i in range(0,app.property("length").toInt()):
+ for i in range(0, app.property("length").toInt()):
cmd.append(app.property(i).toString())
try:
subprocess.Popen(cmd)
except:
- print(f"Exception running {cmd[0]}" )
+ print(f"Exception running {cmd[0]}")
self.noprogram.emit()
return
@@ -135,7 +178,7 @@ class Launcher(QObject):
if app.isArray():
cmd = []
# app should contain package, repository
- for i in range(0,app.property("length").toInt()):
+ for i in range(0, app.property("length").toInt()):
cmd.append(app.property(i).toString())
repo = cmd[1]
# Check if repositories are enabled
@@ -148,50 +191,55 @@ class Launcher(QObject):
core32 = False
core32_updates = False
try:
- active = subprocess.run(['urpmq','--list-media','active'], capture_output=True, text=True)
- active.check_returncode()
+ active = subprocess.run(
+ ["urpmq", "--list-media", "active"], capture_output=True, text=True
+ )
+ active.check_returncode()
except subprocess.CalledProcessError:
print("Error with urpmq")
return
for line in active.stdout.splitlines():
- if line.startswith('Core Release'):
+ if line.startswith("Core Release"):
core = True
- if line.startswith('Core Updates'):
+ if line.startswith("Core Updates"):
updates = True
- if line.startswith('Tainted Release'):
+ if line.startswith("Tainted Release"):
tainted = True
- if line.startswith('Tainted Updates'):
+ if line.startswith("Tainted Updates"):
t_updates = True
- if line.startswith('Nonfree Release'):
+ if line.startswith("Nonfree Release"):
nonfree = True
- if line.startswith('Nonfree Updates'):
+ if line.startswith("Nonfree Updates"):
nf_updates = True
- if line.startswith('Core 32bit Release'):
+ if line.startswith("Core 32bit Release"):
core32 = True
- if line.startswith('Core 32bit Updates'):
+ if line.startswith("Core 32bit Updates"):
core32_updates = True
- if repo == 'tainted' and not (tainted and t_updates) :
+ if repo == "tainted" and not (tainted and t_updates):
# repo tainted not enabled
self.needed.emit(repo)
return
- if repo == 'non-free' and not (nonfree and nf_updates) :
+ if repo == "non-free" and not (nonfree and nf_updates):
# repo nonfree not enabled
self.needed.emit(repo)
return
- if repo == 'steam' and not (core32 and core32_updates and nonfree and nf_updates) :
+ if repo == "steam" and not (
+ core32 and core32_updates and nonfree and nf_updates
+ ):
# repo not enabled
self.needed.emit(repo)
return
- if repo == '' and not (core and updates) :
+ if repo == "" and not (core and updates):
# repo not enabled
self.repo.emit()
return
- proc = subprocess.Popen(['/usr/bin/gurpmi',cmd[0]])
+ proc = subprocess.Popen(["/usr/bin/gurpmi", cmd[0]])
proc.wait()
# Give the signal to reload the applist
self.installed.emit()
return
+
class Norun(QObject):
def __init__(self):
QObject.__init__(self)
@@ -200,25 +248,26 @@ class Norun(QObject):
@pyqtSlot(bool)
def setRunAtLaunch(self, checked):
- print("Setting",checked)
+ print("Setting", checked)
if checked:
if os.path.exists(self.conffile):
- os.remove( self.conffile)
+ os.remove(self.conffile)
else:
os.makedirs(self.home + "/.config/mageiawelcome", exist_ok=True)
- with open( self.conffile, 'w') :
+ with open(self.conffile, "w"):
pass
@pyqtSlot(result=bool)
def startupcheck(self):
return not os.path.exists(self.conffile)
+
class Installable(QObject):
def __init__(self):
QObject.__init__(self)
@pyqtSlot(str, str, result=bool)
- def installable(self, app,repo):
+ def installable(self, app, repo):
is_app_installed, inst_repo = is_installed(app)
installable = (not is_app_installed) or (repo != inst_repo and inst_repo == "")
return installable
@@ -226,29 +275,34 @@ class Installable(QObject):
@pyqtSlot(str, str, result=bool)
def other(self, app, repo):
is_app_installed, inst_repo = is_installed(app)
- return (is_app_installed and repo == '' and inst_repo != "")
+ return is_app_installed and repo == "" and inst_repo != ""
def username():
user = pwd.getpwuid(os.getuid())[4] # pw_gecos, i e the real name
if user == "":
- user = pwd.getpwuid(os.getuid())[0] # login
+ user = pwd.getpwuid(os.getuid())[0] # login
return user
-if __name__ == '__main__':
+
+if __name__ == "__main__":
app = QGuiApplication(sys.argv)
locale = QLocale.system().name()
qtTranslator = QTranslator()
- if qtTranslator.load("qt_" + locale,QLibraryInfo.location(QLibraryInfo.TranslationsPath)):
+ if qtTranslator.load(
+ "qt_" + locale, QLibraryInfo.location(QLibraryInfo.TranslationsPath)
+ ):
app.installTranslator(qtTranslator)
appTranslator = QTranslator()
- if appTranslator.load(QLocale(),"mageiawelcome","_", '/usr/share/mageiawelcome/translations'):
+ if appTranslator.load(
+ QLocale(), "mageiawelcome", "_", "/usr/share/mageiawelcome/translations"
+ ):
app.installTranslator(appTranslator)
app.setOrganizationName("Mageia")
app.setApplicationName("Mageiawelcome")
view = QQuickView()
view.setResizeMode(QQuickView.SizeRootObjectToView)
- view.setTitle(app.translate('app',"Welcome to Mageia"))
+ view.setTitle(app.translate("app", "Welcome to Mageia"))
app.setWindowIcon(QIcon("/usr/share/icons/hicolor/32x32/apps/mageiawelcome.png"))
cb = Callbrowser()
la = Launcher()
@@ -256,25 +310,30 @@ if __name__ == '__main__':
ins = Installable()
cl = ConfList()
nr = Norun()
- sc = nr.startupcheck()
+ sc = nr.startupcheck()
factor = cl.factor(app)
screen = app.primaryScreen()
# if density is high, use at least factor 2 to scale the initial window. Considering high is more than 190 px/inches.
- if screen.logicalDotsPerInch() > 190 :
+ if screen.logicalDotsPerInch() > 190:
factor = max(2.0, factor)
defaultHeight = min(int(700 * factor), screen.availableGeometry().height())
defaultWidth = min(int(1000 * factor), screen.availableGeometry().width())
centerPoint = screen.availableGeometry().center()
- view.setGeometry(centerPoint.x() -defaultWidth//2, centerPoint.y() - defaultHeight//2, defaultWidth,defaultHeight)
- view.rootContext().setContextProperty('link', cb)
- view.rootContext().setContextProperty('launch', la)
- view.rootContext().setContextProperty('user', us)
- view.rootContext().setContextProperty('ConfList', cl)
- view.rootContext().setContextProperty('pyinstallable', ins)
- view.rootContext().setContextProperty('startupcheck', sc)
- view.rootContext().setContextProperty('norun', nr)
+ view.setGeometry(
+ centerPoint.x() - defaultWidth // 2,
+ centerPoint.y() - defaultHeight // 2,
+ defaultWidth,
+ defaultHeight,
+ )
+ view.rootContext().setContextProperty("link", cb)
+ view.rootContext().setContextProperty("launch", la)
+ view.rootContext().setContextProperty("user", us)
+ view.rootContext().setContextProperty("ConfList", cl)
+ view.rootContext().setContextProperty("pyinstallable", ins)
+ view.rootContext().setContextProperty("startupcheck", sc)
+ view.rootContext().setContextProperty("norun", nr)
current_path = os.path.abspath(os.path.dirname(__file__))
- qml_file = os.path.join(current_path, 'mw-ui.qml')
+ qml_file = os.path.join(current_path, "mw-ui.qml")
view.setSource(QUrl.fromLocalFile(qml_file))
if view.status() == QQuickView.Error:
for error in view.errors():