Code refactoring. Move simple classes (MovingWindow, NoneSound, WMButton) into generic

This commit is contained in:
Kiooeht 2011-09-15 00:08:16 -07:00
parent fa7a504ac7
commit 66e233351f
2 changed files with 38 additions and 36 deletions

View file

@ -20,6 +20,7 @@ class CaseInsensitiveDict(dict):
return super(CaseInsensitiveDict, self).has_key(key.lower())
def __delitem__(self, key):
super(CaseInsensitiveDict, self).__delitem__(key.lower())
class PesterList(list):
def __init__(self, l):
self.extend(l)
@ -100,3 +101,37 @@ class MultiTextDialog(QtGui.QDialog):
return retval
else:
return None
class MovingWindow(QtGui.QFrame):
def __init__(self, *x, **y):
QtGui.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 set_volume(self, v): pass
class WMButton(QtGui.QPushButton):
def __init__(self, icon, parent=None):
QtGui.QPushButton.__init__(self, icon, "", parent)
self.setIconSize(icon.realsize())
self.resize(icon.realsize())
self.setFlat(True)
self.setStyleSheet("QPushButton { padding: 0px; }")
self.setAutoDefault(False)

View file

@ -60,7 +60,9 @@ from menus import PesterChooseQuirks, PesterChooseTheme, \
PesterChooseProfile, PesterOptions, PesterUserlist, PesterMemoList, \
LoadingScreen, AboutPesterchum, UpdatePesterchum
from dataobjs import PesterProfile, Mood, pesterQuirk, pesterQuirks
from generic import PesterIcon, RightClickList, RightClickTree, MultiTextDialog, PesterList, CaseInsensitiveDict
from generic import PesterIcon, RightClickList, RightClickTree, \
MultiTextDialog, PesterList, CaseInsensitiveDict, MovingWindow, \
NoneSound, WMButton
from convo import PesterTabWindow, PesterText, PesterInput, PesterConvo
from parsetools import convertTags, addTimeInitial, themeChecker, ThemeException
from memos import PesterMemo, MemoTabWindow, TimeTracker
@ -107,19 +109,6 @@ class waitingMessageHolder(object):
def __len__(self):
return len(self.queue)
class NoneSound(object):
def play(self): pass
def set_volume(self, v): pass
class WMButton(QtGui.QPushButton):
def __init__(self, icon, parent=None):
QtGui.QPushButton.__init__(self, icon, "", parent)
self.setIconSize(icon.realsize())
self.resize(icon.realsize())
self.setFlat(True)
self.setStyleSheet("QPushButton { padding: 0px; }")
self.setAutoDefault(False)
class chumListing(QtGui.QTreeWidgetItem):
def __init__(self, chum, window):
QtGui.QTreeWidgetItem.__init__(self, [chum.handle])
@ -977,28 +966,6 @@ class PesterMoodButton(QtGui.QPushButton):
moodUpdated = QtCore.pyqtSignal(int)
class MovingWindow(QtGui.QFrame):
def __init__(self, *x, **y):
QtGui.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 PesterWindow(MovingWindow):
def __init__(self, options, parent=None):
MovingWindow.__init__(self, parent,