pesterchum/generic.py

72 lines
2.4 KiB
Python
Raw Normal View History

2011-02-03 01:20:37 -05:00
from PyQt4 import QtGui, QtCore
class PesterList(list):
def __init__(self, l):
self.extend(l)
2011-02-03 01:20:37 -05:00
class PesterIcon(QtGui.QIcon):
def __init__(self, *x, **y):
QtGui.QIcon.__init__(self, *x, **y)
if type(x[0]) in [str, unicode]:
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
2011-02-02 19:32:35 -05:00
class RightClickList(QtGui.QListWidget):
def contextMenuEvent(self, event):
#fuckin Qt
if event.reason() == QtGui.QContextMenuEvent.Mouse:
listing = self.itemAt(event.pos())
self.setCurrentItem(listing)
self.optionsMenu.popup(event.globalPos())
2011-02-03 01:20:37 -05:00
class MultiTextDialog(QtGui.QDialog):
def __init__(self, title, parent, *queries):
QtGui.QDialog.__init__(self, parent)
self.setWindowTitle(title)
if len(queries) == 0:
return
self.inputs = {}
layout_1 = QtGui.QHBoxLayout()
for d in queries:
label = d["label"]
inputname = d["inputname"]
value = d.get("value", "")
l = QtGui.QLabel(label, self)
layout_1.addWidget(l)
self.inputs[inputname] = QtGui.QLineEdit(value, self)
layout_1.addWidget(self.inputs[inputname])
self.ok = QtGui.QPushButton("OK", self)
self.ok.setDefault(True)
self.connect(self.ok, QtCore.SIGNAL('clicked()'),
self, QtCore.SLOT('accept()'))
self.cancel = QtGui.QPushButton("CANCEL", self)
self.connect(self.cancel, QtCore.SIGNAL('clicked()'),
self, QtCore.SLOT('reject()'))
layout_ok = QtGui.QHBoxLayout()
layout_ok.addWidget(self.cancel)
layout_ok.addWidget(self.ok)
layout_0 = QtGui.QVBoxLayout()
layout_0.addLayout(layout_1)
layout_0.addLayout(layout_ok)
self.setLayout(layout_0)
def getText(self):
r = self.exec_()
if r == QtGui.QDialog.Accepted:
retval = {}
for (name, widget) in self.inputs.iteritems():
retval[name] = unicode(widget.text())
return retval
else:
return None