Skip to content

Commit

Permalink
Window manager compliant window moving (required for Wayland) + hardc…
Browse files Browse the repository at this point in the history
…oded logging.ini file
  • Loading branch information
Dpeta committed May 4, 2022
1 parent 345e358 commit 8a3ebd1
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 60 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 14 additions & 2 deletions generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ def getText(self):
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
Expand All @@ -118,8 +121,17 @@ def mouseMoveEvent(self, event):
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()
Expand Down
28 changes: 0 additions & 28 deletions logging.ini.example

This file was deleted.

92 changes: 68 additions & 24 deletions pesterchum.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@
# 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
Expand Down Expand Up @@ -95,23 +96,49 @@
# 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',
'formatter': 'simpleFormatter',
'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:])):
Expand Down Expand Up @@ -170,7 +197,6 @@
config.write(configfile)

# Load logging.ini
import logging.config
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger')

Expand Down Expand Up @@ -1165,7 +1191,7 @@ def __init__(self, options, parent=None, app=None):
self.tabmemo = None
self.shortcuts = AttrDict()

self.setAutoFillBackground(True)
self.setAutoFillBackground(False)
self.setObjectName("main")
self.config = userConfig(self)
# Trying to fix:
Expand Down Expand Up @@ -1534,7 +1560,8 @@ def paintEvent(self, event):
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()
Expand Down Expand Up @@ -1843,10 +1870,23 @@ def initTheme(self, theme):
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())
Expand Down Expand Up @@ -3165,11 +3205,15 @@ def quit(self):
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
Expand Down
3 changes: 1 addition & 2 deletions pyinstaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ def is_64bit() -> bool:
'LICENSE;.',
'CHANGELOG.md;.',
'PCskins.png;.',
'Pesterchum.png;.',
'logging.ini.example;.']
'Pesterchum.png;.']

upx_exclude = ["qwindows.dll",
"Qt5Core.dll",
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ def is_64bit() -> bool:
"LICENSE",
"CHANGELOG.md",
"PCskins.png",
"Pesterchum.png",
"logging.ini.example"]
"Pesterchum.png"]
build_exe_options = {
"includes": ['PyQt5.QtCore',
'PyQt5.QtGui',
Expand Down

0 comments on commit 8a3ebd1

Please sign in to comment.