comparison plugins/xxchatnotify.py @ 0:4385a7d0efd1 grumpy-goblin

Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author sirebral
date Tue, 14 Jul 2009 16:41:58 -0500
parents
children c54768cffbd4
comparison
equal deleted inserted replaced
-1:000000000000 0:4385a7d0efd1
1 import os
2 import orpg.pluginhandler
3 import wx
4 from orpg.orpgCore import *
5
6 class Plugin(orpg.pluginhandler.PluginHandler): #Attempting to pass the orpgFrame so that we can Bind events, not working.
7 def __init__(self, plugindb, parent):
8 orpg.pluginhandler.PluginHandler.__init__(self, plugindb, parent)
9
10 # The Following code should be edited to contain the proper information
11 self.name = 'Chat Notification'
12 self.author = 'Dj Gilcrease'
13 self.help = 'This plugin with either play a sound when a new chat message comes in, flash the taskbar or both'
14
15 def plugin_menu(self):
16 #Plugin Menu
17 self.menu = wx.Menu()
18 self.notifyToggle = self.menu.AppendCheckItem(wx.ID_ANY, 'On')
19 self.topframe.Bind(wx.EVT_MENU, self.on_settings, self.notifyToggle)
20
21 notify = wx.Menu()
22 self.notifyBeep = notify.AppendRadioItem(wx.ID_ANY, 'Beep')
23 self.notifyFlash = notify.AppendRadioItem(wx.ID_ANY, 'Flash')
24 self.notifyBoth = notify.AppendRadioItem(wx.ID_ANY, 'Both')
25 self.menu.AppendMenu(wx.ID_ANY, 'Notify', notify)
26 self.topframe.Bind(wx.EVT_MENU, self.on_settings, self.notifyBeep)
27 self.topframe.Bind(wx.EVT_MENU, self.on_settings, self.notifyFlash)
28 self.topframe.Bind(wx.EVT_MENU, self.on_settings, self.notifyBoth)
29
30 notifyType = wx.Menu()
31 self.notifyAll = notifyType.AppendRadioItem(wx.ID_ANY, 'All')
32 self.notifyWhisper = notifyType.AppendRadioItem(wx.ID_ANY, 'Whisper')
33 self.menu.AppendMenu(wx.ID_ANY, 'Type', notifyType)
34 self.topframe.Bind(wx.EVT_MENU, self.on_settings, self.notifyAll)
35 self.topframe.Bind(wx.EVT_MENU, self.on_settings, self.notifyWhisper)
36
37
38 def on_settings(self, evt):
39 if self.notifyToggle.IsChecked() == False:
40 self.notify = 'Off'
41 return
42 if self.notifyBeep.IsChecked() == True:
43 self.notify ='beep'
44 elif self.notifyFlash.IsChecked() == True:
45 self.notify = 'flash'
46 elif self.notifyBoth.IsChecked() == True:
47 self.notify = 'both'
48 if self.notifyAll.IsChecked() == True:
49 self.type = 'all'
50 elif self.notifyWhisper.IsChecked() == True:
51 self.type = 'whisper'
52
53
54 def plugin_enabled(self):
55 self.plugin_addcommand('/notify', self.on_notify, 'beep | flash | both | off | type all|whisper | clearsound | lsound soundfile [Local Sound Files only] | rsound http://to.sound.file [Remote Sound Files only] - This command turns on the chat notification. You can use sound files and flash by issuing /notify both')
56 self.notify = self.plugindb.GetString('xxchatnotify', 'notify', 'off')
57 self.type = self.plugindb.GetString('xxchatnotify', 'type', 'all')
58 self.mainframe = open_rpg.get_component('frame')
59 self.sound_player = open_rpg.get_component('sound')
60 self.soundloc = self.plugindb.GetString('xxchatnotify', 'soundloc', 'local')
61 self.soundfile = self.plugindb.GetString('xxchatnotify', 'soundfile', 'None')
62 self.chat_settings()
63
64 def chat_settings(self):
65 self.notifyToggle.Check(True)
66 if self.notify == 'beep':
67 self.notifyBeep.Check(True)
68 elif self.notify == 'flash':
69 self.notifyFlash.Check(True)
70 elif self.notify == 'both':
71 self.notifyBoth.Check(True)
72 else:
73 self.notifyToggle.Check(False)
74 if self.type == 'all':
75 self.notifyAll.Check(True)
76 elif self.type == 'whisper':
77 self.notifyWhisper.Check(True)
78
79 def plugin_disabled(self):
80 self.plugin_removecmd('/notify')
81
82 def on_notify(self, cmdargs):
83 args = cmdargs.split(None, 2)
84
85 if len(args) == 0:
86 self.chat.InfoPost('You must specify if you want it to beep, flash, both or be turned off or specify if you want to be notified for all messages or just whispers')
87
88 if args[0] == 'type':
89 self.type = args[1]
90 self.plugindb.SetString('xxchatnotify', 'type', self.type)
91 self.chat.InfoPost('Setting Notification on Message type to ' + args[1])
92 self.chat_settings()
93 return
94 elif args[0] == 'lsound':
95 self.soundloc = 'local'
96 self.soundfile = orpg.dirpath.dir_struct['plugins'] + args[1]
97 self.plugindb.SetString('xxchatnotify', 'soundfile', self.soundfile)
98 self.plugindb.GetString('xxchatnotify', 'soundloc', self.soundloc)
99 self.chat.InfoPost('Setting Sound file to ' + self.soundfile)
100 self.notify = 'beep'
101 return
102 elif args[0] == 'rsound':
103 self.soundloc = 'remote'
104 self.soundfile = args[1]
105 self.plugindb.SetString('xxchatnotify', 'soundfile', self.soundfile)
106 self.plugindb.GetString('xxchatnotify', 'soundloc', self.soundloc)
107 self.chat.InfoPost('Setting Sound file to ' + self.soundfile)
108 self.notify = 'beep'
109 return
110 elif args[0] == 'clearsound':
111 self.soundloc = 'local'
112 self.soundfile = 'None'
113 self.plugindb.SetString('xxchatnotify', 'soundfile', self.soundfile)
114 self.plugindb.GetString('xxchatnotify', 'soundloc', self.soundloc)
115 self.chat.InfoPost('Clearing Sound file')
116 self.notify = 'off'
117 return
118
119
120 self.notify = args[0]
121 self.plugindb.SetString('xxchatnotify', 'notify', self.notify)
122 self.chat.InfoPost('Setting Notification type to ' + args[0])
123 self.chat_settings()
124
125
126 def plugin_incoming_msg(self, text, type, name, player):
127 if (self.notify == 'beep' or self.notify == 'both') and (self.type == 'all' or type == 2):
128 if self.soundfile == 'None':
129 wx.CallAfter(wx.Bell)
130 wx.CallAfter(wx.Bell)
131 else:
132 wx.CallAfter(self.sound_player.play, self.soundfile, self.soundloc)
133 if (self.notify == 'flash' or self.notify == 'both') and (self.type == 'all' or type == 2):
134 wx.CallAfter(self.mainframe.RequestUserAttention)
135 return text, type, name
136
137