Window manager compliant window moving (required for Wayland) + hardcoded logging.ini file

This commit is contained in:
unknown 2022-05-04 22:36:42 +02:00
parent 345e358be8
commit 8a3ebd1d3f
6 changed files with 90 additions and 60 deletions

View file

@ -1,15 +1,19 @@
# Changelog
(This document uses YYYY-MM-DD)
## [v2.2.3] - 2022-04-11
## [v2.2.3] - 2022-05-04
### Changed
- Excluded some more modules in build files, hopefully shouldn't cause any issues.
- Added empty 'package' option to 'setup' in setup.py, setuptools v61.0.0 doesn't seem to like our project layout anymore.
- Qt's startSystemMove() is used to move Pesterchum's main window now. (system-specific move operation)
- This fixes click-and-drag on Wayland, which doesn't support setting window position via setPosition().
- Assuming this works on all systems we need to support, we can probably depreciate the MovingWindow class.
### Fixed
- Unreadable input on MacOS and certain linux distros for themes which didn't explicitly set input color (incl. pesterchum), input color is now black by default instead of being platform-dependent.
- Logging related crash.
## [v2.2.2] - 2022-04-11
### Changed

View file

@ -105,6 +105,9 @@ class MultiTextDialog(QtWidgets.QDialog):
return None
class MovingWindow(QtWidgets.QFrame):
# Qt supports starting a system-specific move operation since 5.15, so we shouldn't need to manually set position like this anymore.
# https://doc.qt.io/qt-5/qwindow.html#startSystemMove
# This is also the only method that works on Wayland, which doesn't support setting position.
def __init__(self, *x, **y):
super(MovingWindow, self).__init__(*x, **y)
self.moving = None
@ -118,8 +121,17 @@ class MovingWindow(QtWidgets.QFrame):
self.moveupdate = 0
self.update()
def mousePressEvent(self, event):
if event.button() == 1:
self.moving = event.globalPos() - self.pos()
# Assuming everything is supported, we only need this function to call "self.windowHandle().startSystemMove()".
# If not supported, startSystemMove() returns False and the legacy code runs anyway.
try:
if self.windowHandle().startSystemMove() != True:
if event.button() == 1:
self.moving = event.globalPos() - self.pos()
except AttributeError as e:
print("PyQt5 <= 5.14?")
print(str(e))
if event.button() == 1:
self.moving = event.globalPos() - self.pos()
def mouseReleaseEvent(self, event):
if event.button() == 1:
self.update()

View file

@ -1,28 +0,0 @@
[loggers]
keys=root,pchumLogger
[handlers]
keys=consoleHandler
[formatters]
keys=simpleFormatter
[logger_root]
level=WARNING
handlers=consoleHandler
[logger_pchumLogger]
level=WARNING
handlers=consoleHandler
qualname=pchumLogger
propagate=0
[handler_consoleHandler]
class=StreamHandler
level=WARNING
formatter=simpleFormatter
args=(sys.stdout,)
[formatter_simpleFormatter]
format=%(asctime)s - %(levelname)s - %(module)s - %(threadName)s - %(message)s
datefmt=

92
pesterchum.py Executable file → Normal file
View file

@ -15,18 +15,19 @@ print("Use -h/--help to see the available options.\nLogging is configured in log
# Help
if ('--help' in sys.argv[1:]) or ('-h' in sys.argv[1:]):
print("Possible arguments:")
help_arguments = " -l, --logging\n Specify level of logging, possible values are:\n" + \
" CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET.\n" + \
" The default value is WARNING.\n" + \
" (See https://docs.python.org/3/library/logging.html)\n\n" + \
" -s, --server\n Specify server override. (legacy)\n\n" + \
" -p, --port\n Specify port override. (legacy)\n\n" + \
" --advanced\n Enable advanced.\n\n" + \
" --no-honk\n Disable honking.\n"
help_arguments = (" -l, --logging\n Specify level of logging, possible values are:\n"
+ " CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET.\n"
+ " The default value is WARNING.\n"
+ " (See https://docs.python.org/3/library/logging.html)\n\n"
+ " -s, --server\n Specify server override. (legacy)\n\n"
+ " -p, --port\n Specify port override. (legacy)\n\n"
+ " --advanced\n Enable advanced.\n\n"
+ " --no-honk\n Disable honking.\n")
print(help_arguments)
sys.exit()
import logging
import logging.config
from datetime import timedelta
import random
import re
@ -95,14 +96,41 @@ if not os.path.isdir(_datadir):
# data (profiles, logs, etc) from old location to new data directory.
config = configparser.ConfigParser()
# Create logging.conf
if os.path.exists(_datadir + "logging.ini") == False:
config.read('logging.ini.example')
# Create logging.ini
#if os.path.exists(_datadir + "logging.ini") == False:
try:
config.read(_datadir + 'logging.ini')
# Test load
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger')
except:
#config.read('logging.ini.example')
config = configparser.ConfigParser()
# Default setup
config['loggers'] = {'keys': 'root,pchumLogger'}
config['handlers'] = {'keys': 'consoleHandler,FileHandler'}
config['formatters'] = {'keys': 'simpleFormatter'}
config['logger_root'] = {'level': 'WARNING',
'handlers': 'consoleHandler'}
config['handler_consoleHandler'] = {'class': 'StreamHandler',
'level': 'WARNING',
'formatter': 'simpleFormatter',
'args': '(sys.stdout,)'}
config['handler_FileHandler'] = {'class': 'FileHandler',
'level': 'WARNING',
'formatter': 'simpleFormatter'}
config['logger_pchumLogger'] = {'level': 'WARNING',
'handlers': 'consoleHandler,FileHandler',
'qualname': 'pchumLogger',
'propagate': '0'}
config['formatter_simpleFormatter'] = {'format': '%(levelname)s - %(module)s - %(message)s',
'datefmt': ''}
# Enable file logging
config['handlers']['keys'] = 'consoleHandler,FileHandler'
config['logger_pchumLogger']['handlers'] = 'consoleHandler,FileHandler'
#(r'C:\Users\X\AppData\Local\pesterchum\pesterchum.log', 'a')
config['handler_FileHandler'] = {'class': 'FileHandler',
'level': 'WARNING',
@ -110,8 +138,7 @@ if os.path.exists(_datadir + "logging.ini") == False:
'args': (_datadir + 'pesterchum.log', 'a')}
print(config.sections())
else:
config.read(_datadir + 'logging.ini')
loglevel = "30"# Warning (Default)
if ('--logging' in sys.argv[1:]) or ('-l' in sys.argv[1:]) & (False == ('--logging' in sys.argv[1:]) and ('-l' in sys.argv[1:])):
@ -170,7 +197,6 @@ with open(_datadir + "logging.ini", 'w') as configfile:
config.write(configfile)
# Load logging.ini
import logging.config
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger')
@ -1165,7 +1191,7 @@ class PesterWindow(MovingWindow):
self.tabmemo = None
self.shortcuts = AttrDict()
self.setAutoFillBackground(True)
self.setAutoFillBackground(False)
self.setObjectName("main")
self.config = userConfig(self)
# Trying to fix:
@ -1534,7 +1560,8 @@ class PesterWindow(MovingWindow):
pass
else:
palette = QtGui.QPalette()
palette.setBrush(QtGui.QPalette.Window, QtGui.QBrush(self.backgroundImage))
brush = QtGui.QBrush(self.backgroundImage)
palette.setBrush(QtGui.QPalette.Window, brush)
self.setPalette(palette)
@QtCore.pyqtSlot()
@ -1843,10 +1870,23 @@ class PesterWindow(MovingWindow):
self.setWindowIcon(PesterIcon(theme["main/icon"]))
self.setWindowTitle(theme["main/windowtitle"])
self.setStyleSheet("QtWidgets.QFrame#main { %s }" % (theme["main/style"]))
self.backgroundImage = QtGui.QPixmap(theme["main/background-image"])
self.backgroundMask = self.backgroundImage.mask()
# QPixmap::mask and setMask are legacy and should probably be replaced;
# https://doc.qt.io/qt-5/qpixmap.html#pixmap-information
# It's slow and this way we don't use antialiasing, leaving us with very ugly borders.
# + It breaks transparency on Wayland: https://bugreports-test.qt.io/browse/QTBUG-69906
self.backgroundImage = QtGui.QImage(theme["main/background-image"])
self.backgroundPixmap = QtGui.QPixmap.fromImage(self.backgroundImage)
self.backgroundMask = self.backgroundPixmap.mask()
self.setMask(self.backgroundMask)
self.menu.setStyleSheet("QMenuBar { background: transparent; %s } QMenuBar::item { background: transparent; %s } " % (theme["main/menubar/style"], theme["main/menu/menuitem"]) + "QMenu { background: transparent; %s } QMenu::item::selected { %s } QMenu::item::disabled { %s }" % (theme["main/menu/style"], theme["main/menu/selected"], theme["main/menu/disabled"]))
self.menu.setStyleSheet("QMenuBar { background: transparent; %s } QMenuBar::item { background: transparent; %s } "
% (theme["main/menubar/style"],
theme["main/menu/menuitem"])
+ "QMenu { background: transparent; %s } QMenu::item::selected { %s } QMenu::item::disabled { %s }"
% (theme["main/menu/style"],
theme["main/menu/selected"],
theme["main/menu/disabled"]))
newcloseicon = PesterIcon(theme["main/close/image"])
self.closeButton.setIcon(newcloseicon)
self.closeButton.setIconSize(newcloseicon.realsize())
@ -3165,11 +3205,15 @@ class PesterWindow(MovingWindow):
try:
self.irc.quit_dc() # Actually send QUIT to server
except Exception as e:
# Not connected.
# Not connected?
PchumLog.warning("QUIT failed: " + str(e))
self.parent.trayicon.hide() #
self.app.quit() #
try:
self.parent.trayicon.hide() #
self.app.quit()
except AttributeError as e:
# Called from outside main Window?
PchumLog.warning("Unelegant quit: " + str(e))
sys.exit()
def passIRC(self, irc):
self.irc = irc

View file

@ -102,8 +102,7 @@ add_data = ['quirks;quirks',
'LICENSE;.',
'CHANGELOG.md;.',
'PCskins.png;.',
'Pesterchum.png;.',
'logging.ini.example;.']
'Pesterchum.png;.']
upx_exclude = ["qwindows.dll",
"Qt5Core.dll",

View file

@ -33,8 +33,7 @@ includefiles = ["quirks",
"LICENSE",
"CHANGELOG.md",
"PCskins.png",
"Pesterchum.png",
"logging.ini.example"]
"Pesterchum.png"]
build_exe_options = {
"includes": ['PyQt5.QtCore',
'PyQt5.QtGui',