This commit is contained in:
Stephen Dranger 2011-01-22 03:36:24 -06:00
parent 93df12a446
commit 088e6f0a58
10 changed files with 156 additions and 45 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -2,5 +2,6 @@
"chums": ["gamblingGenocider",
"grimAuxiliatrix",
"gardenGnostic"
]
],
"theme": "pesterchum"
}

View file

@ -9,12 +9,25 @@ from PyQt4 import QtGui, QtCore
logging.basicConfig(level=logging.INFO)
class Mood(object):
moods = ["chummy", "rancorous", "offline"]
def __init__(self, mood):
if type(mood) is int:
self.mood = mood
else:
self.mood = self.moods.index(mood)
def value(self):
return self.mood
def name(self):
return self.moods[self.mood]
class PesterIRC(QtCore.QObject):
def __init__(self, window):
QtCore.QObject.__init__(self)
self.window = window
def IRCConnect(self):
self.cli = IRCClient(PesterHandler, host="irc.tymoon.eu", port=6667, nick="superGhost")
self.cli = IRCClient(PesterHandler, host="irc.tymoon.eu", port=6667, nick=self.window.currentHandle)
self.cli.command_handler.window = self.window
self.conn = self.cli.connect()
@ -25,65 +38,110 @@ class PesterIRC(QtCore.QObject):
class PesterHandler(DefaultCommandHandler):
def privmsg(self, nick, chan, msg):
# display msg, do other stuff
print "%s: %s" % (nick, msg)
handle = nick[0:nick.find("!")]
if chan == "#pesterchum":
# follow instructions
self.window.newMessage()
pass
if msg[0:6] == "MOOD >":
try:
mood = Mood(int(msg[6:]))
except ValueError:
mood = Mood(0)
self.window.updateMood(handle, mood)
elif msg[0:7] == "GETMOOD":
mychumhandle = self.window.currentHandle
mymood = self.window.currentMood.value()
if msg.find(mychumhandle, 8) != -1:
helpers.msg(self.client, "#pesterchum",
"MOOD >%d" % (mymood))
else:
# private message
pass
def welcome(self, server, nick, msg):
helpers.join(self.client, "#pesterchum")
mychumhandle = self.window.currentHandle
mymood = self.window.currentMood.value()
helpers.msg(self.client, "#pesterchum", "MOOD >%d" % (mymood))
chums = self.window.chumList.chums
chumglob = "GETMOOD "
for c in chums:
if len(chumglob+c) >= 510:
helpers.msg(self.client, "#pesterchum", chumglob)
chumglob = "GETMOOD "
chumglob += c
if chumglob != "GETMOOD ":
helpers.msg(self.client, "#pesterchum", chumglob)
class pesterTheme(object):
def __init__(self, name):
self.path = "themes/%s" % (name)
fp = open(self.path+"/style.js")
self.theme = json.load(fp, object_hook=self.pathHook)
fp.close()
def getSection(self, section):
return self.theme[section]
def pathHook(self, d):
from string import Template
for (k, v) in d.iteritems():
if type(v) is unicode:
s = Template(v)
d[k] = s.substitute(path=self.path)
return d
class userConfig(object):
def __init__(self):
fp = open("pesterchum.js")
def __init__(self, handle="pesterchum"):
fp = open("%s.js" % (handle))
self.config = json.load(fp)
fp.close()
self.theme = pesterTheme(self.config["theme"])
def chums(self):
return self.config['chums']
def getTheme(self):
return self.theme
class exitButton(QtGui.QPushButton):
def __init__(self, icon, parent=None):
QtGui.QPushButton.__init__(self, icon, "", parent)
self.setFlat(True)
self.setStyleSheet("QPushButton { padding: 0px; }")
self.setAutoDefault(False)
class chumListing(QtGui.QListWidgetItem):
def __init__(self, chumhandle, moodtheme):
QtGui.QListWidgetItem.__init__(self, chumhandle)
self.theme = moodtheme
self.handle = chumhandle
self.setMood(Mood("offline"))
def setMood(self, mood):
self.mood = mood
self.setIcon(QtGui.QIcon(self.theme[self.mood.name()]["icon"]))
self.setTextColor(QtGui.QColor(self.theme[self.mood.name()]["color"]))
def __lt__(self, cl):
h1 = self.handle.lower()
h2 = cl.handle.lower()
return (h1 < h2)
class chumArea(QtGui.QListWidget):
def __init__(self, chums, parent=None):
def __init__(self, chums, theme, parent=None):
QtGui.QListWidget.__init__(self, parent)
self.setGeometry(75, 100, 350, 500)
self.setStyleSheet("""
background-color: black;
color: white;
font: bold;
font-family: "Courier New";
""")
geometry = theme["loc"] + theme["size"]
self.setGeometry(*geometry)
self.setStyleSheet(theme["style"])
self.chums = chums
for c in self.chums:
chumLabel = QtGui.QListWidgetItem(c)
# chumLabel.setFont(QtGui.QFont("Courier New", pointSize=12,
# weight=75))
self.addItem(chumLabel)
class PesterWindow(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent,
flags=QtCore.Qt.CustomizeWindowHint)
self.config = userConfig()
self.setGeometry(100,100, 500, 700)
self.setWindowIcon(QtGui.QIcon('themes/pesterchum/trayicon.gif'))
self.setStyleSheet("""
background-color: #fdb302;
""")
self.closeButton = exitButton(QtGui.QIcon('themes/pesterchum/x.gif'), self)
s = self.size() - self.closeButton.icon().availableSizes()[0]
self.closeButton.move(s.width(), 0)
self.connect(self.closeButton, QtCore.SIGNAL('clicked()'),
self, QtCore.SLOT('close()'))
self.chumList = chumArea(self.config.chums(), self)
if not self.findItems(c, QtCore.Qt.MatchFlags(0)):
chumLabel = chumListing(c, theme["moods"])
self.addItem(chumLabel)
self.sortItems()
def updateMood(self, nick, mood):
chums = self.findItems(nick, QtCore.Qt.MatchFlags(0))
for c in chums:
c.setMood(mood)
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):
@ -101,8 +159,37 @@ background-color: #fdb302;
if event.button() == 1:
self.update()
self.moving = None
def newMessage(self):
pass
class PesterWindow(MovingWindow):
def __init__(self, parent=None):
MovingWindow.__init__(self, parent,
flags=QtCore.Qt.CustomizeWindowHint)
self.setObjectName("main")
self.config = userConfig()
theme = self.config.getTheme()
main = theme.getSection("main")
width = int(main['width'])
height = int(main['height'])
self.setGeometry(100, 100, width, height)
self.setWindowIcon(QtGui.QIcon(main["icon"]))
self.setStyleSheet("QFrame#main { "+main["style"]+" }")
closestyle = main["close"]
self.closeButton = exitButton(QtGui.QIcon(closestyle["image"]), self)
self.closeButton.move(*closestyle["loc"])
self.connect(self.closeButton, QtCore.SIGNAL('clicked()'),
self, QtCore.SLOT('close()'))
self.chumList = chumArea(self.config.chums(), main["chums"], self)
self.currentHandle = "superGhost"
self.currentMood = Mood(0)
self.convos = {}
def updateMood(self, nick, mood):
self.chumList.updateMood(nick, mood)
def newConversation(self, nick):
convoWindow = PesterConvo(nick, self.theme)
self.convos[nick] = convoWindow
def main():
@ -116,12 +203,12 @@ def main():
trayicon.setContextMenu(traymenu)
trayicon.show()
#irc = PesterIRC(widget)
#irc.IRCConnect()
#irctimer = QtCore.QTimer(widget)
#widget.connect(irctimer, QtCore.SIGNAL('timeout()'),
# irc, QtCore.SLOT('updateIRC()'))
#irctimer.start()
irc = PesterIRC(widget)
irc.IRCConnect()
irctimer = QtCore.QTimer(widget)
widget.connect(irctimer, QtCore.SIGNAL('timeout()'),
irc, QtCore.SLOT('updateIRC()'))
irctimer.start()
sys.exit(app.exec_())
main()

View file

@ -0,0 +1,23 @@
{"main":
{"style": "background-image:url($path/pcbg.png);",
"width": 300,
"height": 620,
"icon": "$path/trayicon.gif",
"close": { "image": "$path/x.gif",
"loc": [275, 0]},
"chums": { "style": "background-color: black;color: white;font: bold;font-family: 'Courier New';selection-background-color:#919191; ",
"loc": [20, 65],
"size": [265, 400],
"moods": { "chummy": { "icon": "$path/chummy.gif",
"color": "white" },
"offline": { "icon": "$path/offline.gif",
"color": "#919191"},
"rancorous": { "icon": "$path/rancorous.gif",
"color": "red" }
}
},
"elements": [
{ "style": "" }
]
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 105 B

After

Width:  |  Height:  |  Size: 61 B