2022-08-19 07:12:58 -04:00
|
|
|
try:
|
|
|
|
from PyQt6 import QtGui, QtWidgets
|
|
|
|
except ImportError:
|
|
|
|
print("PyQt5 fallback (generic.py)")
|
|
|
|
from PyQt5 import QtGui, QtWidgets
|
2011-02-13 20:32:02 -05:00
|
|
|
from datetime import timedelta
|
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-13 20:32:02 -05:00
|
|
|
class mysteryTime(timedelta):
|
|
|
|
def __sub__(self, other):
|
|
|
|
return self
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-13 20:32:02 -05:00
|
|
|
def __eq__(self, other):
|
2023-02-15 11:01:27 -05:00
|
|
|
return isinstance(other, mysteryTime)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-13 20:32:02 -05:00
|
|
|
def __neq__(self, other):
|
2023-02-15 11:01:27 -05:00
|
|
|
return not isinstance(other, mysteryTime)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-03 01:20:37 -05:00
|
|
|
|
2011-04-14 05:50:55 -04:00
|
|
|
class CaseInsensitiveDict(dict):
|
|
|
|
def __setitem__(self, key, value):
|
2023-01-14 16:59:59 -05:00
|
|
|
super().__setitem__(key.lower(), value)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-04-14 05:50:55 -04:00
|
|
|
def __getitem__(self, key):
|
2023-01-14 16:59:59 -05:00
|
|
|
return super().__getitem__(key.lower())
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-04-14 05:50:55 -04:00
|
|
|
def __contains__(self, key):
|
2023-01-14 16:59:59 -05:00
|
|
|
return super().__contains__(key.lower())
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-04-14 05:50:55 -04:00
|
|
|
def __delitem__(self, key):
|
2023-01-14 16:59:59 -05:00
|
|
|
super().__delitem__(key.lower())
|
2011-09-15 03:08:16 -04:00
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-05 12:17:33 -05:00
|
|
|
class PesterList(list):
|
|
|
|
def __init__(self, l):
|
|
|
|
self.extend(l)
|
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-03 01:20:37 -05:00
|
|
|
class PesterIcon(QtGui.QIcon):
|
2012-01-20 15:47:53 -05:00
|
|
|
def __init__(self, *x):
|
2023-01-14 16:59:59 -05:00
|
|
|
super().__init__(x[0])
|
2023-02-19 15:10:35 -05:00
|
|
|
if isinstance(x[0], str):
|
2011-02-03 01:20:37 -05:00
|
|
|
self.icon_pixmap = QtGui.QPixmap(x[0])
|
|
|
|
else:
|
|
|
|
self.icon_pixmap = None
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-03 01:20:37 -05:00
|
|
|
def realsize(self):
|
|
|
|
if self.icon_pixmap:
|
|
|
|
return self.icon_pixmap.size()
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
return self.availableSizes()[0]
|
|
|
|
except IndexError:
|
|
|
|
return None
|
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
class RightClickList(QtWidgets.QListWidget):
|
2011-02-02 19:32:35 -05:00
|
|
|
def contextMenuEvent(self, event):
|
2022-10-07 16:51:40 -04:00
|
|
|
# fuckin Qt <--- I feel that </3
|
2022-06-26 22:18:37 -04:00
|
|
|
if event.reason() == QtGui.QContextMenuEvent.Reason.Mouse:
|
2022-07-08 16:36:23 -04:00
|
|
|
listing = self.itemAt(event.pos())
|
2011-02-02 19:32:35 -05:00
|
|
|
self.setCurrentItem(listing)
|
2011-10-24 20:24:40 -04:00
|
|
|
optionsMenu = self.getOptionsMenu()
|
|
|
|
if optionsMenu:
|
|
|
|
optionsMenu.popup(event.globalPos())
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-04-13 02:12:19 -04:00
|
|
|
def getOptionsMenu(self):
|
|
|
|
return self.optionsMenu
|
2011-02-02 19:32:35 -05:00
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
class RightClickTree(QtWidgets.QTreeWidget):
|
2011-04-14 03:04:33 -04:00
|
|
|
def contextMenuEvent(self, event):
|
2022-06-26 22:18:37 -04:00
|
|
|
if event.reason() == QtGui.QContextMenuEvent.Reason.Mouse:
|
2022-07-08 16:36:23 -04:00
|
|
|
listing = self.itemAt(event.pos())
|
2011-04-14 03:04:33 -04:00
|
|
|
self.setCurrentItem(listing)
|
2011-10-24 20:24:40 -04:00
|
|
|
optionsMenu = self.getOptionsMenu()
|
|
|
|
if optionsMenu:
|
|
|
|
optionsMenu.popup(event.globalPos())
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-04-14 03:13:20 -04:00
|
|
|
def getOptionsMenu(self):
|
|
|
|
return self.optionsMenu
|
2011-04-14 03:04:33 -04:00
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
class MultiTextDialog(QtWidgets.QDialog):
|
2011-02-03 01:20:37 -05:00
|
|
|
def __init__(self, title, parent, *queries):
|
2023-01-14 16:59:59 -05:00
|
|
|
super().__init__(parent)
|
2011-02-03 01:20:37 -05:00
|
|
|
self.setWindowTitle(title)
|
|
|
|
if len(queries) == 0:
|
|
|
|
return
|
|
|
|
self.inputs = {}
|
2021-03-23 17:36:43 -04:00
|
|
|
layout_1 = QtWidgets.QHBoxLayout()
|
2011-02-03 01:20:37 -05:00
|
|
|
for d in queries:
|
|
|
|
label = d["label"]
|
|
|
|
inputname = d["inputname"]
|
|
|
|
value = d.get("value", "")
|
2021-03-23 17:36:43 -04:00
|
|
|
l = QtWidgets.QLabel(label, self)
|
2011-02-03 01:20:37 -05:00
|
|
|
layout_1.addWidget(l)
|
2021-03-23 17:36:43 -04:00
|
|
|
self.inputs[inputname] = QtWidgets.QLineEdit(value, self)
|
2011-02-03 01:20:37 -05:00
|
|
|
layout_1.addWidget(self.inputs[inputname])
|
2021-03-23 17:36:43 -04:00
|
|
|
self.ok = QtWidgets.QPushButton("OK", self)
|
2011-02-03 01:20:37 -05:00
|
|
|
self.ok.setDefault(True)
|
2021-03-23 17:36:43 -04:00
|
|
|
self.ok.clicked.connect(self.accept)
|
|
|
|
self.cancel = QtWidgets.QPushButton("CANCEL", self)
|
|
|
|
self.cancel.clicked.connect(self.reject)
|
|
|
|
layout_ok = QtWidgets.QHBoxLayout()
|
2011-02-03 01:20:37 -05:00
|
|
|
layout_ok.addWidget(self.cancel)
|
|
|
|
layout_ok.addWidget(self.ok)
|
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
layout_0 = QtWidgets.QVBoxLayout()
|
2011-02-03 01:20:37 -05:00
|
|
|
layout_0.addLayout(layout_1)
|
|
|
|
layout_0.addLayout(layout_ok)
|
|
|
|
|
|
|
|
self.setLayout(layout_0)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-03 01:20:37 -05:00
|
|
|
def getText(self):
|
2022-06-26 22:18:37 -04:00
|
|
|
r = self.exec()
|
|
|
|
if r == QtWidgets.QDialog.DialogCode.Accepted:
|
2011-02-03 01:20:37 -05:00
|
|
|
retval = {}
|
2023-02-09 14:52:26 -05:00
|
|
|
for name, widget in self.inputs.items():
|
2023-02-19 15:10:35 -05:00
|
|
|
retval[name] = widget.text()
|
2011-02-03 01:20:37 -05:00
|
|
|
return retval
|
|
|
|
else:
|
|
|
|
return None
|
2011-09-15 03:08:16 -04:00
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
class MovingWindow(QtWidgets.QFrame):
|
2022-05-04 16:36:42 -04:00
|
|
|
# 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.
|
2011-09-15 03:08:16 -04:00
|
|
|
def __init__(self, *x, **y):
|
2023-01-14 16:59:59 -05:00
|
|
|
super().__init__(*x, **y)
|
2011-09-15 03:08:16 -04:00
|
|
|
self.moving = None
|
|
|
|
self.moveupdate = 0
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-15 03:08:16 -04:00
|
|
|
def mouseMoveEvent(self, event):
|
|
|
|
if self.moving:
|
|
|
|
move = event.globalPos() - self.moving
|
|
|
|
self.move(move)
|
|
|
|
self.moveupdate += 1
|
|
|
|
if self.moveupdate > 5:
|
|
|
|
self.moveupdate = 0
|
|
|
|
self.update()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-15 03:08:16 -04:00
|
|
|
def mousePressEvent(self, event):
|
2022-05-04 16:36:42 -04:00
|
|
|
# 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:
|
2023-02-13 14:26:05 -05:00
|
|
|
if not self.windowHandle().startSystemMove():
|
2022-05-04 16:36:42 -04:00
|
|
|
if event.button() == 1:
|
|
|
|
self.moving = event.globalPos() - self.pos()
|
|
|
|
except AttributeError as e:
|
2022-08-19 07:12:58 -04:00
|
|
|
print("PyQt <= 5.14?")
|
2023-02-19 15:10:35 -05:00
|
|
|
print(e)
|
2022-05-04 16:36:42 -04:00
|
|
|
if event.button() == 1:
|
2022-10-07 16:51:40 -04:00
|
|
|
self.moving = event.globalPos() - self.pos()
|
|
|
|
|
2011-09-15 03:08:16 -04:00
|
|
|
def mouseReleaseEvent(self, event):
|
|
|
|
if event.button() == 1:
|
|
|
|
self.update()
|
|
|
|
self.moving = None
|
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2023-01-14 16:59:59 -05:00
|
|
|
class NoneSound:
|
2016-11-19 14:55:00 -05:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
pass
|
2022-10-07 16:51:40 -04:00
|
|
|
|
|
|
|
def play(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def setVolume(self, v):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def set_volume(self, v):
|
|
|
|
pass
|
|
|
|
|
2011-09-15 03:08:16 -04:00
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
class WMButton(QtWidgets.QPushButton):
|
2011-09-15 03:08:16 -04:00
|
|
|
def __init__(self, icon, parent=None):
|
2023-01-14 16:59:59 -05:00
|
|
|
super().__init__(icon, "", parent)
|
2011-09-15 03:08:16 -04:00
|
|
|
self.setIconSize(icon.realsize())
|
|
|
|
self.resize(icon.realsize())
|
|
|
|
self.setFlat(True)
|
|
|
|
self.setStyleSheet("QPushButton { padding: 0px; }")
|
|
|
|
self.setAutoDefault(False)
|