-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathgeneric.py
139 lines (127 loc) · 4.71 KB
/
generic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
from PyQt5 import QtGui, QtCore, QtWidgets
from datetime import timedelta
class mysteryTime(timedelta):
def __sub__(self, other):
return self
def __eq__(self, other):
return (type(other) is mysteryTime)
def __neq__(self, other):
return (type(other) is not mysteryTime)
def __hash__(self):
return 0
class CaseInsensitiveDict(dict):
def __setitem__(self, key, value):
super(CaseInsensitiveDict, self).__setitem__(key.lower(), value)
def __getitem__(self, key):
return super(CaseInsensitiveDict, self).__getitem__(key.lower())
def __contains__(self, key):
return super(CaseInsensitiveDict, self).__contains__(key.lower())
def has_key(self, key):
return key.lower() in super(CaseInsensitiveDict, self)
def __delitem__(self, key):
super(CaseInsensitiveDict, self).__delitem__(key.lower())
class PesterList(list):
def __init__(self, l):
self.extend(l)
class PesterIcon(QtGui.QIcon):
def __init__(self, *x):
QtGui.QIcon.__init__(self, x[0])
if type(x[0]) in [str]:
self.icon_pixmap = QtGui.QPixmap(x[0])
else:
self.icon_pixmap = None
def realsize(self):
if self.icon_pixmap:
return self.icon_pixmap.size()
else:
try:
return self.availableSizes()[0]
except IndexError:
return None
class RightClickList(QtWidgets.QListWidget):
def contextMenuEvent(self, event):
#fuckin Qt
if event.reason() == QtGui.QContextMenuEvent.Mouse:
listing = self.itemAt(event.pos())
self.setCurrentItem(listing)
optionsMenu = self.getOptionsMenu()
if optionsMenu:
optionsMenu.popup(event.globalPos())
def getOptionsMenu(self):
return self.optionsMenu
class RightClickTree(QtWidgets.QTreeWidget):
def contextMenuEvent(self, event):
if event.reason() == QtGui.QContextMenuEvent.Mouse:
listing = self.itemAt(event.pos())
self.setCurrentItem(listing)
optionsMenu = self.getOptionsMenu()
if optionsMenu:
optionsMenu.popup(event.globalPos())
def getOptionsMenu(self):
return self.optionsMenu
class MultiTextDialog(QtWidgets.QDialog):
def __init__(self, title, parent, *queries):
QtWidgets.QDialog.__init__(self, parent)
self.setWindowTitle(title)
if len(queries) == 0:
return
self.inputs = {}
layout_1 = QtWidgets.QHBoxLayout()
for d in queries:
label = d["label"]
inputname = d["inputname"]
value = d.get("value", "")
l = QtWidgets.QLabel(label, self)
layout_1.addWidget(l)
self.inputs[inputname] = QtWidgets.QLineEdit(value, self)
layout_1.addWidget(self.inputs[inputname])
self.ok = QtWidgets.QPushButton("OK", self, clicked=self.accept)
self.ok.setDefault(True)
self.cancel = QtWidgets.QPushButton("CANCEL", self, clicked=self.reject)
layout_ok = QtWidgets.QHBoxLayout()
layout_ok.addWidget(self.cancel)
layout_ok.addWidget(self.ok)
layout_0 = QtWidgets.QVBoxLayout()
layout_0.addLayout(layout_1)
layout_0.addLayout(layout_ok)
self.setLayout(layout_0)
def getText(self):
r = self.exec_()
if r == QtWidgets.QDialog.Accepted:
retval = {}
for (name, widget) in self.inputs.items():
retval[name] = str(widget.text())
return retval
else:
return None
class MovingWindow(QtWidgets.QFrame):
def __init__(self, *x, **y):
QtWidgets.QFrame.__init__(self, *x, **y)
self.moving = None
self.moveupdate = 0
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()
def mousePressEvent(self, event):
if event.button() == 1:
self.moving = event.globalPos() - self.pos()
def mouseReleaseEvent(self, event):
if event.button() == 1:
self.update()
self.moving = None
class NoneSound(object):
def play(self): pass
def setVolume(self, v): pass
class WMButton(QtWidgets.QPushButton):
def __init__(self, icon, parent=None):
QtWidgets.QPushButton.__init__(self, icon, "", parent)
self.setIconSize(icon.realsize())
self.resize(icon.realsize())
self.setFlat(True)
self.setStyleSheet("QPushButton { padding: 0px; }")
self.setAutoDefault(False)